diff --git "a/Corpus/TEST_java_A2.csv" "b/Corpus/TEST_java_A2.csv" new file mode 100644--- /dev/null +++ "b/Corpus/TEST_java_A2.csv" @@ -0,0 +1,252515 @@ +A20934,"import java.util.*; + +public class B { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + B th = new B(); + for (int i = 0; i < T; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[n]; + for (int j = 0; j < n; j++) { + t[j] = sc.nextInt(); + } + int c = th.getAnswer(s,p,t); + System.out.println(""Case #"" + (i+1) + "": "" + c); + } + } + public int getAnswer(int s, int p, int[] t) { + int A1 = p + p-1+p-1; + int A2 = p + p-2+p-2; + if (A1 < 0) + A1 = 0; + if (A2 < 0) + A2 = 1; + int remain = s; + int count = 0; + int n = t.length; + for (int i = 0; i < n; i++) { + if (t[i] >= A1) { + count++; + } else if (t[i] < A1 && t[i] >= A2) { + if (remain > 0) { + remain--; + count++; + } + } + } + return count; + } +} + +" +A20382,"package dancinggooglers; + +import java.io.File; +import java.util.Scanner; + +public class DanceScoreCalculator { + + + public static void main(String[] args) { + if(args.length <= 0 || args[0] == null) { + System.out.println(""You must enter a file to read""); + System.out.println(""Usage: blah ""); + System.exit(0); + } + + File argFile = new File(args[0]); + try { + Scanner googleSpeakScanner = new Scanner(argFile); + String firstLine = googleSpeakScanner.nextLine(); + Integer linesToScan = new Integer(firstLine); + for(int i = 1; i <= linesToScan; i++) { + String googleDancerLine = googleSpeakScanner.nextLine(); + DanceScoreCase danceCase = new DanceScoreCase(googleDancerLine); + System.out.println(String.format(""Case #%d: %d"", i, danceCase.maxDancersThatCouldPass())); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A20261,"package com.gcj.parser; + +public class MaxPoints { + + public static int normal(int value){ + int toReturn = 0; + switch (value) { + case 0 : toReturn = 0 ; break; + case 1 : toReturn = 1 ; break; + case 2 : toReturn = 1 ; break; + case 3 : toReturn = 1 ; break; + case 4 : toReturn = 2 ; break; + case 5 : toReturn = 2 ; break; + case 6 : toReturn = 2 ; break; + case 7 : toReturn = 3 ; break; + case 8 : toReturn = 3 ; break; + case 9 : toReturn = 3 ; break; + case 10 : toReturn = 4 ; break; + case 11 : toReturn = 4 ; break; + case 12 : toReturn = 4 ; break; + case 13 : toReturn = 5 ; break; + case 14 : toReturn = 5 ; break; + case 15 : toReturn = 5 ; break; + case 16 : toReturn = 6 ; break; + case 17 : toReturn = 6 ; break; + case 18 : toReturn = 6 ; break; + case 19 : toReturn = 7 ; break; + case 20 : toReturn = 7 ; break; + case 21 : toReturn = 7 ; break; + case 22 : toReturn = 8 ; break; + case 23 : toReturn = 8 ; break; + case 24 : toReturn = 8 ; break; + case 25 : toReturn = 9 ; break; + case 26 : toReturn = 9 ; break; + case 27 : toReturn = 9 ; break; + case 28 : toReturn = 10 ; break; + case 29 : toReturn = 10 ; break; + case 30 : toReturn = 10 ; break; + + } + + return toReturn; + } + + public static int surprising(int value){ + int toReturn = 0; + switch (value) { + case 0 : toReturn = 0 ; break; + case 1 : toReturn = 1 ; break; + case 2 : toReturn = 2 ; break; + case 3 : toReturn = 2 ; break; + case 4 : toReturn = 2 ; break; + case 5 : toReturn = 3 ; break; + case 6 : toReturn = 3 ; break; + case 7 : toReturn = 3 ; break; + case 8 : toReturn = 4 ; break; + case 9 : toReturn = 4 ; break; + case 10 : toReturn = 4 ; break; + case 11 : toReturn = 5 ; break; + case 12 : toReturn = 5 ; break; + case 13 : toReturn = 5 ; break; + case 14 : toReturn = 6 ; break; + case 15 : toReturn = 6 ; break; + case 16 : toReturn = 6 ; break; + case 17 : toReturn = 7 ; break; + case 18 : toReturn = 7 ; break; + case 19 : toReturn = 7 ; break; + case 20 : toReturn = 8 ; break; + case 21 : toReturn = 8 ; break; + case 22 : toReturn = 8 ; break; + case 23 : toReturn = 9 ; break; + case 24 : toReturn = 9 ; break; + case 25 : toReturn = 9 ; break; + case 26 : toReturn = 10 ; break; + case 27 : toReturn = 10 ; break; + case 28 : toReturn = 10 ; break; + case 29 : toReturn = 10 ; break; + case 30 : toReturn = 10 ; break; + + } + return toReturn; + } + +} +" +A22360,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Dancing_With_the_Googlers { + + + /** + * The first line of the input gives the number of test cases, T. + * T test cases follow. + * Each test case consists of a single line containing integers separated by single spaces. + * The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. + * The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + // Reading the input file + Scanner in = new Scanner(new File(""B-large.in"")); + // writting the input file + FileOutputStream fos = new FileOutputStream(""B-large.out""); + PrintStream out = new PrintStream(fos); + //Close the output stream + int testCase=Integer.parseInt(in.nextLine()); + for(int i=0;i scores= new ArrayList(); + int BestResults=0; + int Surprising=0; + for(int j=0;j= atLeastP)) { + BestResults++; + } else { + if (((((temp / 3) + 1) >= atLeastP) && ((temp / 3) >= 1)) + && (Surprising < NoOfSurprisingResults)) { + BestResults++; + Surprising++; + + } + System.out.println(""Case 0""+""itr:""+i+"" surprising:""+temp); + } + + break; + case 1: + if ((temp / 3) + 1 >= atLeastP) { + BestResults++; + continue; + } + + break; + case 2: + if ((temp / 3) + 1 >= atLeastP) { + BestResults++; + } else { + if (((temp / 3) + 2 >= atLeastP) + && (Surprising < NoOfSurprisingResults)) { + BestResults++; + Surprising++; + } + System.out.println(""Case 2""+""itr:""+i+"" surprising:""+temp); + } + break; + default: + System.out.println(""Error""); + } + + }// Internal for + out.println(BestResults); + // System.out.println(BestResults); + System.out.println(Surprising); + BestResults = 0; + }// for + in.close(); + out.close(); + fos.close(); + + } +} +" +A22642,"import java.util.*; +import java.io.*; + +public class DancingWithTheGooglers +{ + public DancingWithTheGooglers() + { + Scanner inFile = null; + try + { + inFile = new Scanner(new File(""inputB.txt"")); + } + catch(Exception e) + { + System.out.println(""Problem opening input file. Exiting...""); + System.exit(0); + } + int t = inFile.nextInt(); + + int [] results = new int [t]; + DancingWithTheGooglersMax [] rnc = new DancingWithTheGooglersMax[t]; + + int i, j; + int [] scores; + int s, p; + for(i = 0; i < t; i++) + { + scores = new int [inFile.nextInt()]; + s = inFile.nextInt(); + p = inFile.nextInt(); + for(j = 0; j < scores.length; j++) + scores[j] = inFile.nextInt(); + + rnc[i] = new DancingWithTheGooglersMax(i, scores, s, p, results); + rnc[i].start(); + } + inFile.close(); + + boolean done = false; + + while(!done) + { + done = true; + for(i = 0; i < t; i++) + if(rnc[i].isAlive()) + { + done = false; + break; + } + } + + PrintWriter outFile = null; + try + { + outFile = new PrintWriter(new File(""outputB.txt"")); + } + catch(Exception e) + { + System.out.println(""Problem opening output file. Exiting...""); + System.exit(0); + } + + for(i = 0; i < results.length; i++) + outFile.printf(""Case #%d: %d\n"", i+1, results[i]); + outFile.close(); + } + + public static void main(String [] args) + { + new DancingWithTheGooglers(); + } + + private class DancingWithTheGooglersMax extends Thread + { + int id; + int s, p; + int [] results, scores; + + public DancingWithTheGooglersMax(int i, int [] aScores, int aS, int aP,int [] res) + { + id = i; + s = aS; + p = aP; + results = res; + scores = aScores; + } + + public void run() + { + int a = 0, b = 0; + + if(p == 0) + results[id] = scores.length; + else if(p == 1) + { + int y; + y = 3*p - 3; + + for(int i = 0; i < scores.length; i++) + if(scores[i] > y) + a++; + else if(scores[i] > 0) + b++; + + b = Math.min(b, s); + results[id] = a+b; + } + else + { + int y, z; + y = 3*p - 3; + z = 3*p - 5; + + for(int i = 0; i < scores.length; i++) + if(scores[i] > y) + a++; + else if(scores[i] > z) + b++; + + b = Math.min(b, s); + results[id] = a+b; + } + } + } +}" +A22191,"package com.example; + +import java.io.IOException; +import java.util.List; + +public class ProblemB { + + enum Result { + INSUFFICIENT, + SUFFICIENT, + SUFFICIENT_WHEN_SURPRISING + } + + public static void main(String[] a) throws IOException { + + List lines = FileUtil.getLines(""/B-large.in""); + + int cases = Integer.valueOf(lines.get(0)); + + for(int c=0; c ""+ result); + } + + System.out.println(""Case #""+ (c+1) +"": ""+ (sumSufficient + Math.min(s, sumSufficientSurprising))); + +// System.out.println(); +// System.out.println(""N=""+ n +"", S=""+ s +"", P=""+ p); +// System.out.println(); + } + } + + private static Result test(int n, int p) { + int fac = n / 3; + int rem = n % 3; + + if(rem == 0) { + +// int triplet0[] = { fac, fac, fac }; +// print(n, triplet0); + + if(fac >= p) { + return Result.SUFFICIENT; + } + + if(fac > 0 && fac < 10) { + + if(fac+1 >= p) { + return Result.SUFFICIENT_WHEN_SURPRISING; + } + +// int triplet1[] = { fac+1, fac, fac-1 }; // surprising +// print(n, triplet1); + } + + + } else if(rem == 1) { + +// int triplet0[] = { fac+1, fac, fac }; +// print(n, triplet0); + + if(fac+1 >= p) { + return Result.SUFFICIENT; + } + +// if(fac > 0 && fac < 10) { +// int triplet1[] = { fac+1, fac+1, fac-1 }; +// print(n, triplet1); +// } + + } else if(rem == 2) { + +// int triplet0[] = { fac+1, fac+1, fac }; +// print(n, triplet0); + + if(fac+1 >= p) { + return Result.SUFFICIENT; + } + + if(fac < 9) { +// int triplet1[] = { fac+2, fac, fac }; // surprising +// print(n, triplet1); + + if(fac+2 >= p) { + return Result.SUFFICIENT_WHEN_SURPRISING; + } + } + + } else { + throw new RuntimeException(""error""); + } + + return Result.INSUFFICIENT; +// System.out.println(); +// System.out.println(n +"" => ""+ div3 +"" (""+ rem +"")""); + } + +// private static void print(int n, int[] triplet) { +// System.out.println(""n=""+ n +"" (""+ (n/3) +"",""+ (n%3) +"") => [""+ triplet[0] +"",""+ triplet[1] +"",""+ triplet[2] +""]"" + (triplet[0]-triplet[2] > 1 ? "" *"" : """")); +// } + +} +" +A22378,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +public class CodeJam { + +// public static final String INPUT_FILE_PATH = ""D://CodeJamInput.txt""; + public static final String INPUT_FILE_PATH = ""D://B-large.in""; + public static final String OUTPUT_FILE_PATH = ""D://CodeJamOutput.txt""; + + public static List readInput() { + List list = new ArrayList(); + try { + BufferedReader input = new BufferedReader(new FileReader( + INPUT_FILE_PATH)); + try { + String line = null; + + while ((line = input.readLine()) != null) { + list.add(line); + } + } finally { + input.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + return list; + } + + public static void writeOutput(List output) { + PrintWriter writer = null; + try { + writer = new PrintWriter(new FileWriter(OUTPUT_FILE_PATH)); + for (String line : output) { + writer.println(line); + } + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (writer != null) + writer.close(); + } + } + + public static void main(String[] args) { + List danceFloors = DanceFloor.parseFromFile(CodeJam.readInput()); + List output = new ArrayList(); + + for(int i = 0; i < danceFloors.size(); i++) { + System.out.println(danceFloors.get(i)); + String line = """"; + line += ""Case #"" + (i + 1) + "": "" + danceFloors.get(i).calculate(); + output.add(line); + } + + CodeJam.writeOutput(output); + } +} + +class DanceFloor { + + private List tripletsTotalCounts; + private int surpriseCount; + private int targetScore; + private int dancersCount; + + public DanceFloor(List tripletsTotalCounts, int surpriseCount, + int targetScore, int dancersCount) { + this.tripletsTotalCounts = tripletsTotalCounts; + this.surpriseCount = surpriseCount; + this.targetScore = targetScore; + this.dancersCount = dancersCount; + } + + public int calculate() { + int result = 0; + + if (targetScore == 0) return dancersCount; + + for (int i = 0; i < tripletsTotalCounts.size(); i++) { + int total = tripletsTotalCounts.get(i); + + if (total < (targetScore * 3 - 4)) { + tripletsTotalCounts.remove(i--); + } else if (total == 0) { + tripletsTotalCounts.remove(i--); + } + } + + for (int i = 0; i < tripletsTotalCounts.size(); i++) { + int total = tripletsTotalCounts.get(i); + + if ((surpriseCount > 0) && (total == targetScore * 3 - 4)) { + result++; + surpriseCount--; + tripletsTotalCounts.remove(i--); + } else if ((surpriseCount == 0) && (total == targetScore * 3 - 4)) { + tripletsTotalCounts.remove(i--); + } + } + + for (int i = 0; i < tripletsTotalCounts.size(); i++) { + int total = tripletsTotalCounts.get(i); + + if ((surpriseCount > 0) && (total == targetScore * 3 - 3)) { + result++; + surpriseCount--; + tripletsTotalCounts.remove(i--); + } else if ((surpriseCount == 0) && (total == targetScore * 3 - 3)) { + tripletsTotalCounts.remove(i--); + } + } + + result += tripletsTotalCounts.size(); + + return result; + } + + public static List parseFromFile(List readInput) { + List result = new ArrayList(); + int testCaseCount = Integer.parseInt(readInput.get(0)); + + for (int i = 0; i < testCaseCount; i++) { + String line[] = readInput.get(i + 1).split("" ""); + + List totalCounts = new ArrayList(); + for (int j = 0; j < Integer.parseInt(line[0]); j++) { + totalCounts.add(Integer.parseInt(line[3 + j])); + } + + result.add(new DanceFloor(totalCounts, Integer.parseInt(line[1]), + Integer.parseInt(line[2]), Integer.parseInt(line[0]))); + } + + return result; + } + + @Override + public String toString() { + return ""dancersCount = "" + dancersCount + ""; surpriseCount = "" + surpriseCount + + ""; targetScore = "" + targetScore + ""; tripletsTotalCounts"" + + tripletsTotalCounts.toString(); + } +} + +" +A20119,"package code12.qualification; + +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +public class B { + public static String solve(int N, int S, int p, int[] t) { + + // 3a -> (a, a, a), *(a - 1, a, a + 1) + // 3a + 1 -> (a, a, a + 1), *(a - 1, a + 1, a + 1) + // 3a + 2 -> (a, a + 1, a + 1), *(a, a, a + 2) + + int numPNoS = 0; + int numPWithS = 0; + + for (int i = 0; i < N; i++) { + int a = (int)Math.floor(t[i] / 3); + int r = t[i] % 3; + + switch (r) { + case 0: + if (a >= p) { + numPNoS++; + } else if (a + 1 >= p && a - 1 >= 0) { + numPWithS++; + } + break; + case 1: + if (a >= p || a + 1 >= p) { + numPNoS++; + } + break; + case 2: + if (a >= p || a + 1 >= p) { + numPNoS++; + } else if (a + 2 >= p) { + numPWithS++; + } + break; + } + } + + return """" + (numPNoS + Math.min(S, numPWithS)); + } + + public static void main(String[] args) throws Exception { + // file name + //String fileName = ""Sample""; + //String fileName = ""B-small""; + String fileName = ""B-large""; + + // file variable + File inputFile = new File(fileName + "".in""); + File outputFile = new File(fileName + "".out""); + Scanner scanner = new Scanner(inputFile); + FileWriter writer = new FileWriter(outputFile); + + // problem variable + int totalCase; + int N, S, p; + int[] t; + + // get total case + totalCase = scanner.nextInt(); + + for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) { + // get input + N = scanner.nextInt(); + S = scanner.nextInt(); + p = scanner.nextInt(); + t = new int[N]; + + for (int i = 0; i < N; i++) { + t[i] = scanner.nextInt(); + } + + String output = ""Case #"" + caseIndex + "": "" + solve(N, S, p, t); + System.out.println(output); + writer.write(output + ""\n""); + } + scanner.close(); + writer.close(); + } +} +" +A21010,"package codejam; + +import fixjava.Pair; + +public class Utils { + + public static long minLong(long firstVal, long... otherVals) { + long minVal = firstVal; + for (int i = 0; i < otherVals.length; i++) + minVal = Math.min(firstVal, otherVals[i]); + return minVal; + } + + public static int minInt(int firstVal, int... otherVals) { + int minVal = firstVal; + for (int i = 0; i < otherVals.length; i++) + minVal = Math.min(firstVal, otherVals[i]); + return minVal; + } + + public static float minFloat(float firstVal, float... otherVals) { + float minVal = firstVal; + for (int i = 0; i < otherVals.length; i++) + minVal = Math.min(firstVal, otherVals[i]); + return minVal; + } + + /** + * ArgMin returned as a Pair(index, value). Array must + * have at least one value. + */ + public static Pair argMin(int[] arr) { + int min = arr[0]; + int argMin = 0; + for (int i = 1; i < arr.length; i++) { + if (arr[i] < min) { + min = arr[i]; + argMin = i; + } + } + return new Pair(argMin, min); + } + + /** + * ArgMax returned as a Pair(index, value). Array must + * have at least one value. + */ + public static Pair argMax(int[] arr) { + int max = arr[0]; + int argMax = 0; + for (int i = 1; i < arr.length; i++) { + if (arr[i] > max) { + max = arr[i]; + argMax = i; + } + } + return new Pair(argMax, max); + } + +} +" +A22078,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; + + +public class GooglersDancer { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + InputStreamReader converter = new InputStreamReader(System.in); + BufferedReader in = new BufferedReader(converter); + if (in == null) { + return; + } + String numTest = in.readLine(); + int maxCases = Integer.valueOf(numTest); + for(int i=1;i<= maxCases;i++){ + String linea = in.readLine(); + String[] datos = linea.split("" ""); + Integer googlers = Integer.valueOf(datos[0]); + Integer sospechosos = Integer.valueOf(datos[1]); + Integer p = Integer.valueOf(datos[2]); + Integer puntuacion; + Integer personas = 0; + ArrayList puntuaciones = new ArrayList(); + for(int j=0;j=0;j--){ + if(pOrdenado[j] >= p*3-2){ + personas += 1; + }else{ + break; + } + } + int posibles = j+1-sospechosos; + for(;j>=posibles && j>= 0;j--){ + if(pOrdenado[j] >= p*3-4 && pOrdenado[j] > p){ + personas += 1; + }else{ + break; + } + } + System.out.println(""Case #""+i+"": ""+personas); + } + } + +} +" +A21557,"import java.io.*; +import java.util.*; + +public class DancingWithGooglers { + + public static class Googlers { + + public int T; + public int surp; + public boolean surprising; + public boolean pSurprising; + public boolean antiSurprising; + public boolean pAntiSurprising; + + public Googlers(int T, int surp) { + this.T = T; + this.surp = surp; + } + + public void set(int a, int b, int c) { + if (c >= 0 && (a + b + c) == T) { + int diff = (Math.max(a, Math.max(b, c)) - Math.min(a, Math.min(b, c))); + if (diff <= 2) { + if (diff == 2) { + if (a >= surp || b >= surp || c >= surp) { + pSurprising = true; + } else { + surprising = true; + } + } else { + if (a >= surp || b >= surp || c >= surp) { + pAntiSurprising = true; + } else { + antiSurprising = true; + } + } + } + } + } + } + + public static void main(String... args) throws IOException { +// BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); +// PrintWriter writer = new PrintWriter(System.out); + PrintWriter writer = new PrintWriter(""B-large.out""); + + int len, cases = Integer.parseInt(reader.readLine()); + List satisfied = new ArrayList(); + List unsatisfied = new ArrayList(); + String[] inputs; + int N, S, p; + for (int i = 1; i <= cases; i++) { + inputs = reader.readLine().split("" ""); + p = Integer.parseInt(inputs[1]); + S = Integer.parseInt(inputs[2]); + satisfied.clear(); + unsatisfied.clear(); + for (int j = 3; j < inputs.length; j++) { + int t = Integer.parseInt(inputs[j]); + Googlers googlers = new Googlers(t, S); + + for (int k = 0; k <= 10; k++) { + int till = k + 2 > 10 ? 10 : k + 2; + for (int l = k; l <= till; l++) { + googlers.set(k, l, (t - (k + l))); + } + } + if (googlers.pAntiSurprising) { + satisfied.add(googlers); + } else { + unsatisfied.add(googlers); + } + } + int pSurprising = 0; + if (p > 0) { + for (Iterator iter = unsatisfied.iterator(); iter.hasNext(); ) { + Googlers googlers = iter.next(); + if (googlers.pSurprising) { + pSurprising++; + iter.remove(); + p--; + if (p <= 0) break; + } + } + } + if(p > 0){ + for (Iterator iter = unsatisfied.iterator(); iter.hasNext(); ) { + Googlers googlers = iter.next(); + if (googlers.surprising) { + iter.remove(); + p--; + if (p <= 0) break; + } + } + } + if(p > 0){ + for (Iterator iter = satisfied.iterator(); iter.hasNext(); ) { + Googlers googlers = iter.next(); + if (googlers.pSurprising) { + iter.remove(); + pSurprising++; + p--; + if (p <= 0) break; + } + } + } + if(p > 0){ + for (Iterator iter = satisfied.iterator(); iter.hasNext(); ) { + Googlers googlers = iter.next(); + if (googlers.surprising) { + iter.remove(); + p--; + if (p <= 0) break; + } + } + } + + if(p > 0){ + writer.print(""Case #"" + i + "": 0""); + }else { + writer.print(""Case #"" + i + "": "" + (satisfied.size() + pSurprising)); + } + writer.println(); + } + writer.flush(); + } + + +} +" +A22992,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package IO; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author dannocz + */ +public class InputReader { + + public static Input readFile(String filename){ + try { + + /* Sets up a file reader to read the file passed on the command + 77 line one character at a time */ + FileReader input = new FileReader(filename); + + /* Filter FileReader through a Buffered read to read a line at a + time */ + BufferedReader bufRead = new BufferedReader(input); + + String line; // String that holds current file line + int count = 0; // Line number of count + ArrayList cases= new ArrayList(); + + // Read first line + line = bufRead.readLine(); + int noTestCases=Integer.parseInt(line); + count++; + + // Read through file one line at time. Print line # and line + while (count<=noTestCases){ + //System.out.println(""Reading. ""+count+"": ""+line); + line = bufRead.readLine(); + cases.add(line); + count++; + } + + bufRead.close(); + + return new Input(noTestCases,cases); + + }catch (ArrayIndexOutOfBoundsException e){ + /* If no file was passed on the command line, this expception is + generated. A message indicating how to the class should be + called is displayed */ + e.printStackTrace(); + + }catch (IOException e){ + // If another exception is generated, print a stack trace + e.printStackTrace(); + } + + return null; + + }// end main + } +" +A22771,"package com.menzus.gcj._2012.qualification.b; + +import com.menzus.gcj.common.InputBlockParser; +import com.menzus.gcj.common.OutputProducer; +import com.menzus.gcj.common.impl.AbstractProcessorFactory; + +public class BProcessorFactory extends AbstractProcessorFactory { + public BProcessorFactory(String inputFileName) { + super(inputFileName); + } + + @Override + protected InputBlockParser createInputBlockParser() { + return new BInputBlockParser(); + } + + @Override + protected OutputProducer createOutputProducer() { + return new BOutputProducer(); + } +} +" +A21396,"import java.util.*; +public class Test { + public static void main(String[] args){ + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + + for(int i = 1; i<=T; i++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int result = 0; + for(int j = 0; j 0) { + result++; + s--; + } + } + System.out.println(""Case #""+i+"": ""+result); + } + } + + public static int canAddUp(int sum, int limit) { + boolean flag = false; + for(int i = 0; i<=sum; i++) { + for(int j = 0; i+j <= sum; j++) { + int k = sum-(i+j); + int a = Math.abs(i-j); + int b = Math.abs(i-k); + int c = Math.abs(j-k); + if(a > 2 || b > 2 || c> 2){ + continue; + } + + if (i>=limit || j>=limit || k>=limit) { + if(a < 2 && b < 2 && c < 2) { + return 0; + }else{ + flag = true; + } + } + } + } + return (flag) ? 1 : 2; + } +} +" +A20490,"/** + * + */ +package hu.herba.codejam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; + +/** + * Base functionality, helper functions for CodeJam problem solver utilities. + * + * @author csorbazoli + */ +public abstract class AbstractCodeJamBase { + private static final String EXT_OUT = "".out""; + protected static final int STREAM_TYPE = 0; + protected static final int FILE_TYPE = 1; + protected static final int READER_TYPE = 2; + private static final String DEFAULT_INPUT = ""test_input""; + private static final String DEFAULT_OUTPUT = ""test_output""; + + private final File inputFolder; + private final File outputFolder; + + public AbstractCodeJamBase(String[] args, int type) { + String inputFolderName = AbstractCodeJamBase.DEFAULT_INPUT; + String outputFolderName = AbstractCodeJamBase.DEFAULT_OUTPUT; + if (args.length > 0) { + inputFolderName = args[0]; + } + this.inputFolder = new File(inputFolderName); + if (!this.inputFolder.exists()) { + this.showUsage(""Input folder '"" + this.inputFolder.getAbsolutePath() + ""' not exists!""); + } + if (args.length > 1) { + outputFolderName = args[1]; + } + this.outputFolder = new File(outputFolderName); + if (this.outputFolder.exists() && !this.outputFolder.canWrite()) { + this.showUsage(""Output folder '"" + this.outputFolder.getAbsolutePath() + ""' not writeable!""); + } else if (!this.outputFolder.exists() && !this.outputFolder.mkdirs()) { + this.showUsage(""Could not create output folder '"" + this.outputFolder.getAbsolutePath() + ""'!""); + } + File[] inputFiles = this.inputFolder.listFiles(); + for (File inputFile : inputFiles) { + this.processInputFile(inputFile, type); + } + } + + /** + * @return the inputFolder + */ + public File getInputFolder() { + return this.inputFolder; + } + + /** + * @return the outputFolder + */ + public File getOutputFolder() { + return this.outputFolder; + } + + /** + * @param input + * input reader + * @param output + * output writer + * @throws IOException + * in case input or output fails + * @throws IllegalArgumentException + * in case the given input is invalid + */ + @SuppressWarnings(""unused"") + protected void process(BufferedReader reader, PrintWriter pw) throws IOException, IllegalArgumentException { + System.out.println(""NEED TO IMPLEMENT (reader/writer)!!!""); + System.exit(-2); + } + + /** + * @param input + * input file + * @param output + * output file (will be overwritten) + * @throws IOException + * in case input or output fails + * @throws IllegalArgumentException + * in case the given input is invalid + */ + protected void process(File input, File output) throws IOException, IllegalArgumentException { + System.out.println(""NEED TO IMPLEMENT (file/file)!!!""); + System.exit(-2); + } + + /** + * @param input + * input stream + * @param output + * output stream + * @throws IOException + * in case input or output fails + * @throws IllegalArgumentException + * in case the given input is invalid + */ + protected void process(InputStream input, OutputStream output) throws IOException, IllegalArgumentException { + System.out.println(""NEED TO IMPLEMENT (stream/stream)!!!""); + System.exit(-2); + } + + /** + * @param type + * @param input + * @param output + */ + private void processInputFile(File input, int type) { + long starttime = System.currentTimeMillis(); + System.out.println(""Processing '"" + input.getAbsolutePath() + ""'...""); + File output = new File(this.outputFolder, input.getName() + AbstractCodeJamBase.EXT_OUT); + if (type == AbstractCodeJamBase.STREAM_TYPE) { + InputStream is = null; + OutputStream os = null; + try { + is = new FileInputStream(input); + os = new FileOutputStream(output); + this.process(is, os); + } catch (FileNotFoundException e) { + this.showUsage(""FileNotFound: "" + e.getLocalizedMessage()); + } catch (IllegalArgumentException excIA) { + this.showUsage(excIA.getLocalizedMessage()); + } catch (Exception exc) { + System.out.println(""Program failed: "" + exc.getLocalizedMessage()); + exc.printStackTrace(System.out); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + System.out.println(""Failed to close input: "" + e.getLocalizedMessage()); + } + } + if (os != null) { + try { + os.close(); + } catch (IOException e) { + System.out.println(""Failed to close output: "" + e.getLocalizedMessage()); + } + } + } + } else if (type == AbstractCodeJamBase.READER_TYPE) { + BufferedReader reader = null; + PrintWriter pw = null; + try { + reader = new BufferedReader(new FileReader(input)); + pw = new PrintWriter(output); + this.process(reader, pw); + } catch (FileNotFoundException e) { + this.showUsage(""FileNotFound: "" + e.getLocalizedMessage()); + } catch (IllegalArgumentException excIA) { + this.showUsage(excIA.getLocalizedMessage()); + } catch (Exception exc) { + System.out.println(""Program failed: "" + exc.getLocalizedMessage()); + exc.printStackTrace(System.out); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + System.out.println(""Failed to close input: "" + e.getLocalizedMessage()); + } + } + if (pw != null) { + pw.close(); + } + } + } else if (type == AbstractCodeJamBase.FILE_TYPE) { + try { + this.process(input, output); + } catch (IllegalArgumentException excIA) { + this.showUsage(excIA.getLocalizedMessage()); + } catch (Exception exc) { + System.out.println(""Program failed: "" + exc.getLocalizedMessage()); + exc.printStackTrace(System.out); + } + } else { + this.showUsage(""Unknown type given: "" + type + "" (accepted values: 0,1)""); + } + System.out.println("" READY ("" + (System.currentTimeMillis() - starttime) + "" ms)""); + } + + /** + * Read a single number from input + * + * @param reader + * @param purpose + * What is the purpose of given data + * @return + * @throws IOException + * @throws IllegalArgumentException + */ + protected int readInt(BufferedReader reader, String purpose) throws IOException, IllegalArgumentException { + int ret = 0; + String line = reader.readLine(); + if (line == null) { + throw new IllegalArgumentException(""Invalid input: line is empty, it should be an integer ("" + purpose + "")!""); + } + try { + ret = Integer.parseInt(line); + } catch (NumberFormatException excNF) { + throw new IllegalArgumentException(""Invalid input: the first line '"" + line + ""' should be an integer ("" + purpose + "")!""); + } + return ret; + } + + /** + * Read array of integers + * + * @param reader + * @param purpose + * @return + */ + protected int[] readIntArray(BufferedReader reader, String purpose) throws IOException { + int[] ret = null; + String line = reader.readLine(); + if (line == null) { + throw new IllegalArgumentException(""Invalid input: line is empty, it should be an integer list ("" + purpose + "")!""); + } + String[] strArr = line.split(""\\s""); + int len = strArr.length; + ret = new int[len]; + for (int i = 0; i < len; i++) { + try { + ret[i] = Integer.parseInt(strArr[i]); + } catch (NumberFormatException excNF) { + throw new IllegalArgumentException(""Invalid input: line '"" + line + ""' should be an integer list ("" + purpose + "")!""); + } + } + return ret; + } + + /** + * Read array of strings + * + * @param reader + * @param purpose + * @return + */ + protected String[] readStringArray(BufferedReader reader, String purpose) throws IOException { + String[] ret = null; + String line = reader.readLine(); + if (line == null) { + throw new IllegalArgumentException(""Invalid input: line is empty, it should be a string list ("" + purpose + "")!""); + } + ret = line.split(""\\s""); + return ret == null ? new String[0] : ret; + } + + /** + * Basic usage pattern. Can be overwritten by current implementation + * + * @param message + * Short message, describing the problem with given program + * arguments + */ + protected void showUsage(String message) { + if (message != null) { + System.out.println(message); + } + System.out.println(""Usage:""); + System.out.println(""\t"" + this.getClass().getName() + "" program""); + System.out.println(""\tArguments:""); + System.out.println(""\t\t:\tpath of input folder (default: "" + AbstractCodeJamBase.DEFAULT_INPUT + "").""); + System.out.println(""\t\t \tAll files will be processed in the folder""); + System.out.println(""\t\t:\tpath of output folder (default: "" + AbstractCodeJamBase.DEFAULT_OUTPUT + "")""); + System.out.println(""\t\t \tOutput file name will be the same as input""); + System.out.println(""\t\t \tinput with extension '.out'""); + System.exit(-1); + } +} +" +A20730,"import java.util.Scanner; +public class B { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int zz = 1; zz <= T;zz++){ + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int x = 0; + for(int i = 0; i < N;i++){ + int score = in.nextInt(); + int best = score/3; + int mod = score%3; + int diff = p-best; + if(diff<1){ + x++; + }else if(diff<2){ + if(mod==0 && score !=0){ + if(S!=0){ + S--;x++; + } + }else if(score!=0){ + x++; + } + }else if(diff<3){ + if(mod==2){ + if(S!=0){ + S--;x++; + } + } + } + } + System.out.format(""Case #%d: %d\n"", zz, x); + } + } +} +" +A20066,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Scanner; + + +public class Dancers +{ + public static void main(String[] args) + { + try + { + BufferedReader input = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter output = new BufferedWriter(new FileWriter(""output.txt"")); + + Integer numCases = Integer.parseInt(input.readLine()); + + + for(int i=0; i=0; --j) + { + if(bestScoreWithoutSuprise(scores[j])>=P) + ++n; + else if(S!=0 && bestScoreWithSuprise(scores[j])>=P) + { + ++n; + --S; + } + } + + output.write(n.toString()); + + if(i != numCases-1) + output.write('\n'); + } + + input.close(); + output.close(); + } catch (NumberFormatException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static int bestScoreWithoutSuprise(int totalScore) + { + if(totalScore%3==0) return totalScore/3; + else return totalScore/3 + 1; + } + + public static int bestScoreWithSuprise(int totalScore) + { + if(totalScore == 0) return 0; + else if(totalScore%3==0) return totalScore/3 + 1; + else if(totalScore%3==1) return totalScore/3 + 1; + else return totalScore/3 + 2; + } +} +" +A20000,"import java.io.*; + +class goodance +{ + +static int wc; +static int best; + +public static void main(String args[]) +throws IOException +{ + +FileReader fin=new FileReader(""B-large.in""); +BufferedReader bin=new BufferedReader(fin); + +FileWriter fout=new FileWriter(""Output.txt""); +BufferedWriter bout=new BufferedWriter(fout); +PrintWriter pout=new PrintWriter(bout); + + +int T=Integer.parseInt(bin.readLine()); +String s[]=new String[T]; + +int omk1,omk2=3,parsm=4; +int i=0,dummy=10,r=0,test=0; +boolean flag,count; + +while(iomk1) + omk2=omk1; + + } + } + } + } + } + } + + r+=pav(parsm); + + omk2=3; + parsm=-1; + } + + pout.println(""Case #""+(i+1)+"": ""+r); + r=0; + i++; + omk2=3; + +} + +bin.close(); +pout.close(); +bout.close(); +fout.close(); + +} + + + static boolean minmax(int n1,int n3,int n2) + { + + int max,min; + max=(n1>n2?(n1>n3?n1:n3):(n2>n3?n2:n3)); + min=(n12) + return false; + else + return true; + } + + static boolean f(int z,int m,int o) + { + if(z>=best||m>=best||o>=best) + return true; + else + return false; + } + + static int def(int n1,int n2,int n3) + { + int max,min; + max=(n1>n2?(n1>n3?n1:n3):(n2>n3?n2:n3)); + min=(n10) + {royal=1; + wc--; + } + } + + else if(t==1||t==0) + royal=1; + + else + {royal=0; + + } + + return royal; + } + }" +A20630,"package qual; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + +public class B { + static int rec(int[][] memo , List tlist , int supprize , int pos , int point){ + int N = tlist.size(); + if(pos == N){ + return 0; + } + if(memo[pos][supprize] >= 0){ + return memo[pos][supprize]; + } + int left = tlist.size() - pos; + int ti = tlist.get(pos); + int tave = ti / 3; + int smax = ti % 3 == 2 ? tave + 2 : tave + 1; + int nmax = ti % 3 == 0 ? tave : tave + 1; + if(supprize == left){ + int ret = rec(memo , tlist , supprize - 1 , pos + 1, point) + (smax >= point ? 1 : 0); + return memo[pos][supprize] = ret; + }else if(supprize == 0){ + int ret = rec(memo , tlist , supprize, pos + 1, point) + (nmax >= point ? 1 : 0); + return memo[pos][supprize] = ret; + }else{ + int ret = rec(memo , tlist , supprize - 1 , pos + 1, point) + (smax >= point ? 1 : 0); + ret = Math.max(ret, rec(memo , tlist , supprize, pos + 1, point) + (nmax >= point ? 1 : 0)); + return memo[pos][supprize] = ret; + } + } + + static int solve(int ts[] , int S , int p){ + List tlist = new ArrayList(); + int offset = 0; + for(int t : ts){ + if(t == 0){ + if(p == 0)++offset; + }else if(t == 1){ + if(p <= 1)++offset; + }else if(t >= 29){ + ++offset; + }else{ + tlist.add(t); + } + } + int N = tlist.size(); + int dp[][] = new int[N][S + 1]; + for(int i = 0 ; i < N ; ++i){ + Arrays.fill(dp[i], -1); + } + return offset + rec(dp, tlist, S, 0 , p); + } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for(int cn = 1 ; cn <= T ; ++cn){ + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int ts[] = new int[N]; + for(int i = 0 ; i < N ; ++i){ + ts[i] = sc.nextInt(); + } + System.out.printf(""Case #%d: %d\n"", cn , solve(ts , S , p)); + } + } +} +" +A20898,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class ProblemB{ + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + int count = Integer.parseInt(br.readLine()); + for (int i = 0; i(p-0.7)){ + result++; + }else if (t>0 && (ti/3.0)>(p-1.4) && ti>=t ){ + t--; + result++; + } + } + return result; + } +}" +A22558,"import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class CodeJamQ2 { + + public static String[] read(final String name) throws IOException { + final InputStreamReader reader = new FileReader(new File(name)); + final char[] buf = new char[1024]; + int count = 0; + final StringBuilder res = new StringBuilder(); + do { + count = reader.read(buf); + if (count > 0) + res.append(buf, 0, count); + } while (count != -1); + return res.toString().trim().split(""(\\r?\\n)+""); + } + + public static void main(final String[] args) throws Exception { + final String[] input = read(""B-large.in""); + final FileWriter out = new FileWriter(""out""); + + final int casesCount = Integer.parseInt(input[0]); + for (int caseN = 1; caseN <= casesCount; caseN++) { + final String[] data = input[caseN].split(""\\s+""); + final int n = Integer.parseInt(data[0]); + final int s = Integer.parseInt(data[1]); + final int p = Integer.parseInt(data[2]); + final int[] totals = new int[n]; + for (int i = 0; i < totals.length; i++) { + totals[i] = Integer.parseInt(data[i + 3]); + } + + out.write(""Case #"" + caseN + "": "" + solve(s, p, totals) + ""\n""); + + } + + out.close(); + } + + private static int solve(final int s, final int p, final int[] totals) { + int count = 0; + int reserv = s; + for (int i = 0; i < totals.length; i++) { + final int t = totals[i]; + if (t < p) { continue; } + final int k = p * 3 - t; + if (k <= 2) { count++; continue; } + if (k <= 4 && reserv > 0) { + count++; + --reserv; + } + } + return count; + } + +} +" +A20877,"package problemB.dancingwithgooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +public class Dancers { + + private static final String INPUT_FILE = ""/Users/sbhadour/dev/googlecodejam/test/B-large.in""; + + private static final String OUTPUT_FILE = ""/Users/sbhadour/dev/googlecodejam/test/dancers-output.txt""; + + class Triplet { + + private int googlerId; + + private int valueA; + private int valueB; + private int valueC; + + public Triplet(int googlerId) { + this.googlerId = googlerId; + } + } + + /** + * Writes the results to the output file + * + * @param results + */ + public void writeResults(String results) { + try { + Writer writer = new BufferedWriter(new FileWriter(OUTPUT_FILE)); + try { + writer.write(results); + } + catch (IOException ex) { + ex.printStackTrace(); + } + finally { + writer.close(); + } + } + catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Reads the input file and returns result. + * + * @return + */ + public String getResultsForInputFile() { + StringBuilder result = new StringBuilder(); + + try { + BufferedReader input = new BufferedReader(new FileReader(INPUT_FILE)); + try { + // first line is the number of test cases + int numTestCases = Integer.parseInt(input.readLine()); + + for (int i = 1; i <= numTestCases; i++) { + result.append(""Case #"" + i + "": ""); + StringTokenizer words = new StringTokenizer(input.readLine(), "" ""); + int totalGooglers = Integer.parseInt(words.nextToken()); + int surprisingTriplets = Integer.parseInt(words.nextToken()); + int minIndivScore = Integer.parseInt(words.nextToken()); + + List allTriplets = new ArrayList(); + for (int j = 1; j <= totalGooglers; j++) { + List googlerTriplets = findAllTriplets(j,Integer.parseInt(words.nextToken())); + allTriplets.addAll(googlerTriplets); + } + + //printTriplets(allTriplets); + result.append(findMaxGooglersWithIndivScore(allTriplets, surprisingTriplets, minIndivScore, totalGooglers)); + + result.append(System.getProperty(""line.separator"")); + } + + } + catch (NumberFormatException nex) { + nex.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + finally { + + } + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + return result.toString(); + } + + /** + * Returns unique triplets assuming individual score can differ by at most 2 + * + * @param totalScore + * @return + */ + private List findAllTriplets (int googlerId, int totalScore) { + List triplets = new ArrayList(); + + // first triplet is the easiest + // since there are 3 judges, divide by 3 and make the result as first 2 values and 3rd as the difference of total - sum of val1+2 + int baseVal = totalScore/3; + Triplet triplet = new Triplet(googlerId); + triplet.valueA = baseVal; + triplet.valueB = baseVal; + triplet.valueC = totalScore - baseVal - baseVal; + + if (triplet.valueC > 10) { + triplet.valueA += 1; + triplet.valueC -= 1; + } + + triplets.add(triplet); + + // a <= c always + if (triplet.valueA == triplet.valueC && triplet.valueA != 10 && triplet.valueA != 0) { + Triplet triplet2 = new Triplet(googlerId); + triplet2.valueA = triplet.valueA + 1; + triplet2.valueB = baseVal; + triplet2.valueC = triplet.valueC - 1; + + triplets.add(triplet2); + } + // this is the case when a < c since a !> c + else if (triplet.valueC - triplet.valueA == 2) { + Triplet triplet3 = new Triplet(googlerId); + triplet3.valueB = baseVal; + triplet3.valueA = triplet.valueA + 1; + triplet3.valueC = triplet.valueC -1; + + triplets.add(triplet3); + } + + return triplets; + } + + private int findMaxGooglersWithIndivScore (List allTriplets, int allowedSurprises, int minIndivScore, int totalGooglers) { + + Set googlersWithTripletMatch = new HashSet(); + + List surprisingTripletsWithMatch = new ArrayList(); + + for (Triplet triplet : allTriplets) { + // filter all non matched triplets + // only add googlers with non surprising match first + if (triplet.valueA >= minIndivScore || triplet.valueB >= minIndivScore || triplet.valueC >= minIndivScore) { + if (Math.abs(triplet.valueA - triplet.valueC) == 2) { + surprisingTripletsWithMatch.add(triplet); + } + else { + googlersWithTripletMatch.add(triplet.googlerId); + } + } + } + + // first drop triplets of googlers already counted. + List tempList = new ArrayList(surprisingTripletsWithMatch); + + for (int i = 0; i < tempList.size(); i++) { + Triplet trip = tempList.get(i); + + if (googlersWithTripletMatch.contains(trip.googlerId)) { + surprisingTripletsWithMatch.remove(trip); + } + } + + // if the surprising triplet still bigger than allowed + if (surprisingTripletsWithMatch.size() > allowedSurprises) { + // filter remaining till size match restriction achieved. + tempList = new ArrayList(surprisingTripletsWithMatch); + for (int i = 0, prevGooglerId = 0; surprisingTripletsWithMatch.size() > allowedSurprises && i < tempList.size(); i++) { + Triplet trip = tempList.get(i); + + // don't remove triplets of the same googler. + if (prevGooglerId != trip.googlerId) { + surprisingTripletsWithMatch.remove(trip); + } + prevGooglerId = trip.googlerId; + } + } + + // add the remaning guys back to the list + for (Triplet matchedTrip : surprisingTripletsWithMatch) { + googlersWithTripletMatch.add(matchedTrip.googlerId); + } + + return googlersWithTripletMatch.size(); + } + + public void printTriplets (List triplets) { + System.out.println(""Triplet size: "" + triplets.size()); + for (Triplet triplet : triplets) { + System.out.println(""Tripplet for googler id: "" + triplet.googlerId + "" -> {"" + triplet.valueA + "","" + triplet.valueB + "","" + triplet.valueC + ""}""); + } + } + + + /** + * @param args + */ + public static void main(String[] args) { + Dancers probB = new Dancers(); + long startTime = System.currentTimeMillis(); + String results = probB.getResultsForInputFile(); + probB.writeResults(results); + long endTime = System.currentTimeMillis(); + + System.out.println(""Compute Time: "" + (endTime - startTime) + "" milliseconds""); + } + +} +" +A20136,"import java.io.*; +import java.util.*; + +public class taskB { + + PrintWriter out; + BufferedReader br; + StringTokenizer st; + + String nextToken() throws IOException { + while ((st == null) || (!st.hasMoreTokens())) + st = new StringTokenizer(br.readLine()); + return st.nextToken(); + } + + public int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + public long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + public double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + public void solve() throws IOException { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int ans = 0; + for (int i = 0; i < n; i++) { + int a = nextInt(); + if (p > a) + continue; + if (p * 3 - 2 <= a) { + ans++; + continue; + } + if (s == 0) + continue; + if (p * 3 - 4 <= a) { + s--; + ans++; + } + } + out.println(ans); + } + + public void run() { + try { + br = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(System.out); + + br = new BufferedReader(new FileReader(""taskB.in"")); + out = new PrintWriter(""taskB.out""); + int n = nextInt(); + for (int i = 0; i < n; i++) { + out.print(""Case #"" + (i + 1) + "": ""); + + solve(); + } + + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new taskB().run(); + } +} +" +A20017,"package googlejam2; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class Main2 +{ + static int surprising = 0; + + public static String resolveTestCase(String line) + { + // Read input parameters + String tokens [] = line.split("" ""); + + int N = Integer.parseInt(tokens[0]); + int S = Integer.parseInt(tokens[1]); + int P = Integer.parseInt(tokens[2]); + + surprising = 0; + + System.out.println(""N = "" + N + "", S = "" + S + "", P = "" + P); + + int [] scores = new int[N]; + + for ( int i = 0; i < N; i++) + { + scores[i] = Integer.parseInt(tokens[3+i]); + } + + // calculate result + int result = 0; + + for ( int i = 0; i < N; i++ ) + { + System.out.print(""Dancer "" + i + "" score "" + scores[i]); + + if ( scores[i] >= Math.max(3 * P - 2, P) ) + { + result++; + + System.out.println("" ok ""); + } + else if ( surprising < S ) + { + if ( scores[i] >= Math.max( 3 * P - 4, P ) ) + { + result++; + surprising++; + + System.out.println("" surprising ""); + } + } + } + + return """" + result; + } + + public static void main (String [] args) throws IOException + { + String inputFile = args[0]; + + File f = new File(inputFile); + FileReader fr = new FileReader(f); + BufferedReader br = new BufferedReader(fr); + + File f2 = new File(inputFile + "".out""); + FileWriter fw = new FileWriter(f2); + + String line = br.readLine(); + + int count = Integer.parseInt(line); + + // resolve test cases + int testcase = 1; + + for(int tests = 0; tests < count; tests++) + { + line = br.readLine(); + + System.out.println(line); + + String output = ""Case #""+testcase+"": ""; + + output += resolveTestCase(line); + + System.out.println(output+""\n""); + fw.write(output+""\r\n""); + + testcase++; + } + + fw.close(); + + } +} +" +A20090,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package a; + +import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; +import java.io.IOException; + +/** + * + * @author KazakhPride + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + // TODO code application logic here + Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new File(""output.txt"")); + + int n = in.nextInt(); + int t = 0; + int s = 0; + int p = 0; + + for (int j = 1; j <= n; j++) { + out.print(""Case #"" + j + "": ""); + t = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + int count = 0; + int ar[] = new int[t]; + for (int i = 0; i < ar.length; i++) { + ar[i] = in.nextInt(); + } + + for( int i = 0; i < ar.length; i++ ){ + if(ar[i]%3 == 0){ + int base = ar[i]/3; + //int second = first; + //int third = second; + if(base >= p){ + count++; + } + else{ + if(s > 0 && base > 0 && base + 1 >= p){ + count++; + s--; + } + } + } + else if(ar[i]%3==1){ + int base = ar[i]/3; + + if(base >= p || base + 1 >= p){ + count++; + } + else{ + if(s > 0 && base + 1 >= p){ + count++; + s--; + } + } + } + if( ar[i]%3 == 2 ){ + int base = ar[i]/3; + + if(base + 1 >= p || base >= p){ + count++; + } + else{ + if( s > 0 && base + 2 >= p ){ + count++; + s--; + } + } + } + } + out.println(count); + } + in.close(); + out.close(); + } +}" +A21596," +public class testCase { + + public testCase(int n){ + T = n; + cases = new String[T]; + count=0; + } + public void addCase(String s){ + if(count > T-1){ + System.out.println(""STOP ! too many test cases !!""); + return; + } + cases[count++] = s; + } + + int count; + + int T; + String[] cases; +} +" +A21992,"import java.util.Scanner; + +public class Main +{ + public static void main(String[] args) + { + Scanner oku = new Scanner(System.in); + + int test = oku.nextInt(), n, s, p; + + int surp_siniri; + int enAzindan, kesin_surp, toplam; + + for (int i = 0; i < test; i++, oku.nextLine()) + { + n = oku.nextInt(); + s = oku.nextInt(); + p = oku.nextInt(); + + if (p == 0 || p == 1) + { + surp_siniri = s; + } + else + { + surp_siniri = 3 * p - 4; + } + + enAzindan = 0; + kesin_surp = 0; + + for (int j = 0; j < n; j++) + { + toplam = oku.nextInt(); + + if (toplam >= 2) + { + if (toplam >= surp_siniri && toplam <= surp_siniri + 1) + { + kesin_surp++; + } + else if (toplam > surp_siniri + 1) + { + enAzindan++; + } + } + else + { + if (surp_siniri == 0 && toplam >= p) + { + enAzindan++; + } + } + } + + if (kesin_surp >= s) + { + System.out.println(""Case #"" + (i + 1) + "": "" + (enAzindan + s)); + } + else + { + System.out.println(""Case #"" + (i + 1) + "": "" + (enAzindan + kesin_surp)); + } + } + } +} +" +A21688,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam.qualification.googlersdance; + +import java.util.List; +import util.BaseResolver; +import util.Util; + +/** + * + * @author bohmd + */ +public class GooglersDance extends BaseResolver { + + int cases; + + public static void main(String[] args) throws Exception { + if (args.length == 0 || args[0].equals("""")) { + throw new Exception(""The first parameter must be the input file name without extension.""); + } else { + new GooglersDance(args[0]).resolve(); + } + } + + public GooglersDance(String file) { + super(file); + } + + @Override + protected void executeLine(String line) throws Exception { + if (getLineNum() == 0) { + cases = Util.getInt(line); + } else { + List lineCase = Util.getIntList(line); + write(resolveCase(lineCase.get(0), lineCase.get(1), lineCase.get(2), lineCase.subList(3, lineCase.size()))); + } + } + + protected String resolveCase(int dancersCount, int supricesCount, int p, List points) { + int count=0; + for(Integer point: points) + { + if(point+3>3*p) + { + count++; + } + else if(point+5>3*p && supricesCount>0 && point>0) + { + supricesCount--; + count++; + } + } + return "" ""+count; + } +} +" +A22949,"package org.resec; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +public class Dancing_With_the_Googlers { + + public static void main(String[] args) { + String filename = ""B-small-attempt5""; + String sep = java.io.File.separator; + try { + FileInputStream input = new FileInputStream(""c:"" + sep + filename + + "".in""); + FileOutputStream output = new FileOutputStream(""c:"" + sep + + filename + "".out""); + int T = Integer.parseInt(readLine(input)); + for (int i = 1; i <= T; i++) { + String G = readLine(input); + String outLine = ""Case #"" + i + "": ""; + Go(input, output, G, outLine); + } + input.close(); + output.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String readLine(FileInputStream FIS) { + boolean EOL = true; + String S = """"; + int in = 0; + try { + do { + in = FIS.read(); + if (in == -1 || in == '\n') + EOL = false; + else + S += (char) in; + } while (EOL); + } catch (IOException e) { + e.printStackTrace(); + } + return S; + } + + public static int writeLine(FileOutputStream FOS, String S) { + int i = 0; + try { + for (; i < S.length(); i++) + FOS.write(S.charAt(i)); + } catch (IOException e) { + e.printStackTrace(); + } + return i; + } + + public static void Go(FileInputStream FIS, FileOutputStream FOS, String G, + String outLine) { + String[] data = G.split("" ""); + int N = Integer.parseInt(data[0]); + int S = Integer.parseInt(data[1]); + int p = Integer.parseInt(data[2]); + int cases = 0; + for (int i = 0; i < N; i++) { + int score = Integer.parseInt(data[i + 3]); + int base = (int) (score / 3); + + switch (score % 3) { + case 0: { + if (base >= p) + cases++; + else { + if (S > 0 && base > 0 && base + 1 >= p) { + cases++; + S--; + } + } + break; + } + case 1: { + if (base >= p || base + 1 >= p) + cases++; + else { + if (S > 0 && base + 1 >= p) { + cases++; + S--; + } + } + break; + } + case 2: { + if (base + 1 >= p || base >= p) + cases++; + else { + if (S > 0 && base + 2 >= p) { + cases++; + S--; + } + } + break; + } + } + } + writeLine(FOS, outLine + cases + '\n'); + } +} +" +A22195," +import java.io.*; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Main2 { + + public static void main(String[] args) { + try { + Scanner in = new Scanner(new BufferedReader(new FileReader(""in.txt""))); + BufferedWriter out = new BufferedWriter(new FileWriter(""out.txt"")); + int t; + t = in.nextInt(); + in.nextLine(); + for (int i = 1; i <= t; i++) { + int n, s, p; + n = in.nextInt(); + int g[] = new int[n]; + s = in.nextInt(); + p = in.nextInt(); + for (int j = 0; j < n; j++) { + g[j] = in.nextInt(); + } + in.nextLine(); + int count = 0; + for (int k = 0; k < g.length; k++) { + if (g[k] != 0 || p == 0) { + int div = g[k] / 3; + int mod = g[k] % 3; + if (mod == 0) { + if (div >= p) { + count++; + } else if (div + 1 >= p && s > 0) { + count++; + s--; + } + } else if (mod == 1) { + if (div + 1 >= p) { + count++; + } + } else { + if (div + 1 >= p) { + count++; + } else if (div + 2 >= p && s > 0) { + count++; + s--; + } + } + } + } + + String toPrint = ""Case #"" + i + "": "" + count; + if (i != t) { + toPrint += ""\n""; + } + out.write(toPrint); + } + in.close(); + out.close(); + } catch (Exception ex) { + Logger.getLogger(Main2.class.getName()).log(Level.SEVERE, null, ex); + } + } +} +" +A22219,"package com.google.codejam; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import com.google.common.base.CharMatcher; +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.common.io.Files; +import com.google.gdata.util.common.base.Charsets; + +public class ProblemB { + + public static void main (String [] args) throws IOException { + if (args.length != 1) { + System.err.println(""Usage: ProblemB inputfile""); + return; + } + String filename = args[0]; + List inputLines = Files.readLines(new File(filename), Charsets.US_ASCII); + int T = Integer.parseInt(inputLines.get(0)); + List testCases = inputLines.subList(1, inputLines.size()); + assert(T == testCases.size()); + for (int i = 0; i < testCases.size(); i++) { + processLine(testCases, i); + } + } + + private static void processLine(List testCases, int i) { + String line = testCases.get(i); + List lineContents = Lists.newArrayList(Iterables.transform(Splitter.on(CharMatcher.WHITESPACE).split(line), new Function() { + @Override + public Integer apply(String input) { + return Integer.parseInt(input); + } + })); + + int numGooglers = lineContents.get(0); + int numSurprising = lineContents.get(1); + int targetBestResult = lineContents.get(2); + List scores = lineContents.subList(3, lineContents.size()); + assert(numGooglers == scores.size()); + int maxNumGooglers = 0; + int numGooglersWithSurprise = 0; + for (int score : scores) { + if (((score + 2) / 3) >= targetBestResult) { // This is equivalent to ciel(score/3) >= targetBestResult + maxNumGooglers++; + } else if ((score + 4) / 3 >= targetBestResult && score > 0) { + numGooglersWithSurprise++; + } + } + + maxNumGooglers += Math.min(numGooglersWithSurprise, numSurprising); + System.out.println(""Case #"" + (i+1) + "": "" + maxNumGooglers); + } + +} +" +A20756,"import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Scanner; + + +public class Task2 { + + private int parseLine(Scanner scanner) throws IOException { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int[] table = new int[31]; + for (int i = 0; i < N; i++) { + table[scanner.nextInt()]++; + } + int retval = 0; + if (p >= 2) { + int e = table[3 * p - 4] + table[3 * p - 3]; + if (S > e) { + retval += e; + } else { + retval += S; + } + } + for (int i = 3 * p - 2; i <= 30; i++) { + if (i >= 0) { + retval += table[i]; + } + } + return retval; + } + + public void run(Scanner scanner, Writer bw) throws IOException { + int rowCnt = Integer.parseInt(scanner.next()); + for (int i = 0; i < rowCnt; i++) { + bw.write(""Case #"" + (i + 1) + "": "" + parseLine(scanner) + '\n'); + } + bw.flush(); + bw.close(); + } + + /** + * @param args + */ + public static void main(String[] args) { + try { + Scanner scanner = new Scanner(System.in); + scanner.useDelimiter("" |\r\n|\n|\r""); + new Task2().run(new Scanner(System.in), + new FileWriter(""task2Large.out"")); + } catch (IOException e) { + return; + } + } +} +" +A20853,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + + +public class FileReader { + + /** + * @param args + */ + public static void main(String[] args) { + long casos = 0; //cantidad de casos a leer + long lineasporcaso = 1; //lineas que tiene cada caso + boolean numlineasvar = false; //si cada vez cambia el nœmero de lineas + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""c:\\fichero.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + strLine = br.readLine(); + casos = Long.parseLong(strLine); + for (int i=0; i lineas = new ArrayList(); + for(int j=0; j al = new ArrayList(); + for(int i = 10; i >= 0; i--){ + for(int j = 10; j >= 0; j--){ + for(int k = 10; k >= 0; k--){ + if(i+j+k == N && Math.max(Math.max(i,j), k) >= P && isValid(i, j, k)){ + + //System.out.println(i + "" "" + j +"" "" + k); + al.add(i+"",""+j+"",""+k); + //break here; + } + } + } + } + + if(al.size() > 0 && !isSurprizeTrue(al)){ + ans++; + } else if (al.size() > 0 && isSurprizeTrue(al) && S > 0) { + ans++; + S--; + } + //System.out.println(); + } + return ans; + } + + private static boolean isSurprizeTrue(ArrayList al){ + for(int i = 0; i < al.size();i++){ + String[] s = al.get(i).split("",""); + if(!isSurprize(Integer.parseInt(s[0]),Integer.parseInt(s[1]),Integer.parseInt(s[2]))) return false; + } + return true; + } + + private static boolean isValid(int i,int j, int k){ + if(Math.abs(i-j) > 2) return false; + if(Math.abs(i-k) > 2) return false; + if(Math.abs(j-k) > 2) return false; + return true; + } + + private static boolean isSurprize(int i,int j, int k){ + if(Math.abs(i-j) == 2) return true; + if(Math.abs(i-k) == 2) return true; + if(Math.abs(j-k) == 2) return true; + return false; + } +} +" +A22197,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.io.BufferedReader; +import java.io.IOException; + +import java.io.InputStreamReader; + + +/** + * + * @author harit + */ +public class Main { + + /** + * @param args the command line arguments + */ + + public static void main(String[] args) throws IOException { + + + int normal[][]= {{0,0,0}, + {0,0,1}, + {0,1,1}, + {1,1,1}, + {1,1,2}, + {1,2,2}, + {2,2,2}, + {2,2,3}, + {2,3,3}, + {3,3,3}, + {3,3,4}, + {3,4,4}, + {4,4,4}, + {4,4,5}, + {4,5,5}, + {5,5,5}, + {5,5,6}, + {5,6,6}, + {6,6,6}, + {6,6,7}, + {6,7,7}, + {7,7,7}, + {7,7,8}, + {7,8,8}, + {8,8,8}, + {8,8,9}, + {8,9,9}, + {9,9,9}, + {9,9,10}, + {9,10,10}, + {10,10,10} + }; + int surp[][]={ {-1,-1,-1}, + {-1,-1,-1}, + {0,0,2}, + {0,1,2}, + {0,2,2}, + {1,1,3}, + {1,2,3}, + {1,3,3}, + {2,2,4}, + {2,3,4}, + {2,4,4}, + {3,3,5}, + {3,4,5}, + {3,5,5}, + {4,4,6}, + {4,5,6}, + {4,6,6}, + {5,5,7}, + {5,6,7}, + {5,7,7}, + {6,6,8}, + {6,7,8}, + {6,8,8}, + {7,7,9}, + {7,8,9}, + {7,9,9}, + {8,8,10}, + {8,9,10}, + {8,10,10}, + {-1,-1,-1}, + {-1,-1,-1} + }; + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + int t=Integer.parseInt(br.readLine()); + int t1=1; + while(t1<=t){ + String st=br.readLine(); + //System.out.println(st); + if(st!=null){ + //System.out.println(""null""); + String s[]=st.split("" ""); + //int n=Integer.parseInt(s[0]); + int sp=Integer.parseInt(s[1]); + int p=Integer.parseInt(s[2]); + int maxcount=0; + for(int i=3;i=p) maxcount++; + else if(sp>0){ + p1=surp[ttl][2]; + if(p1>=p) {maxcount++; sp--;} + } + } + System.out.println(""Case #""+t1+"": ""+maxcount); + + } + t1++; + + } + + } + +} +" +A20758,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing.with.the.googlers; + +/** + * + * @author Optee + */ +public class ScoreCounter { + + int numberOfGooglers; + int surpriseCount; + int minScore; + int[] scores; + + public ScoreCounter(String line) { + String[] numbers = line.split("" ""); + this.numberOfGooglers = Integer.valueOf(numbers[0]); + this.surpriseCount = Integer.valueOf(numbers[1]); + this.minScore = Integer.valueOf(numbers[2]); + this.scores = new int[numbers.length-3]; + int j = 0; + for (int i = 3; i < numbers.length; i++) { + scores[j++] = Integer.valueOf(numbers[i]); + } + } + + int Count2() { + int winners = 0; + Integer surprise = surpriseCount; + + for (int i = 0; i < numberOfGooglers; i++) { + int score = this.scores[i]; + int minCount = minScore * 3; + if(score == 0 && minScore > 0) continue; + if (score + 2 >= minCount) { + winners++; + } + else if (score + 4 >= minCount && surprise > 0) { + surprise--; + winners++; + } + } + return winners; + } + + int Count() throws Exception { + int winners = 0; + Integer surprise = surpriseCount; + Integer possibleSurprises = 0; + + for (int i = 0; i < numberOfGooglers; i++) { + int score = this.scores[i]; + int tail = score - minScore; + + if (tail <= 0) continue; + + int divTileOne = tail/2; + int divTileTwo = tail - divTileOne; + + if (Math.max(divTileOne, divTileTwo) >= minScore){ + if (Math.max(divTileOne, divTileTwo) - minScore >=2) + possibleSurprises++; + winners++; + } + else if (minScore - Math.min(divTileOne, divTileTwo) < 2) { + winners++; + } + else if (minScore - Math.min(divTileOne, divTileTwo) == 2) { + if (surprise > 0) { + surprise--; + winners++; + } + } + } + return winners; + } + +} +" +A20551,"import java.io.*; +import java.util.*; + +class dancing +{ + public static void main(String[] args) throws Exception + { + BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); + String inp; + int i,j; + + int T=Integer.valueOf(r.readLine()); + for(int a=0;a= (p*3)-2) y++; + else if ((ti >= (p*3)-4) && ((p*3)-4>0) && S>0) { + S--; y++; + } + } + + + System.out.println(""Case #""+(a+1)+"": ""+y); + } + } +} + +" +A21957,"import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Scanner; + + +public class dancer { + public static Scanner setFileIn(){ + try{ + Scanner input = new Scanner(new FileInputStream(new File (""test.txt""))); + return input; + }catch(Exception e){ + return null; + } + } + public static Scanner setSysIn(){ + Scanner input = new Scanner(new BufferedInputStream(System.in)); + return input; + } + + + public static int dancer(int n, int s, int p,Scanner input){ + int ans = 0; + int noSur = 3*p-2; + int sur = 3*p-4; + if (p==1){ + noSur = 1; + sur = 1; + + } + + if(p==0){ + noSur = 0; + sur = 0; + + } + // + //System.out.println("" ""+s+"" ""+p); + //System.out.println("" ""+noSur+"" ""+sur); + while(n>0){ + int score = input.nextInt(); + //System.out.print("" ""+ score+"" ""); + if (score>=noSur){ + ans++; + }else{ + if ((score >= sur)&&(s>0)){ + s--; + ans++; + } + } + n--; + } + return ans; + } + + public static void main(String args[]){ + Scanner input = setFileIn(); + long counter = input.nextInt(); + int ans = 0; + int count = 1; + while(count<=counter){ + System.out.print(""Case #""+count+"": ""); + int n = input.nextInt(); + int s = input.nextInt(); + int p = input.nextInt(); + ans = dancer(n,s,p,input); + System.out.println(ans); + count++; + } + + } +} +" +A22167,"package com.mademoisellegeek.googlecodejam.y2012.qualround; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; + +public class DancingWithTheGooglers implements Runnable { + + BufferedReader in; + BufferedWriter out; + static String inputFile = ""2012-qualround-B-large.in""; + static String outputFile = ""2012-qualround-B-large.out""; + + public void run() { + + try { + in = new BufferedReader(new FileReader(inputFile)); + out = new BufferedWriter(new FileWriter(outputFile)); + try { + String line = in.readLine(); + int nbCases = Integer.parseInt(line); + for (int i=1; i<=nbCases; i++) { + line = in.readLine(); + String [] lineArray = line.split("" ""); + int nbDancers = Integer.parseInt(lineArray[0]); + int nbSurprises = Integer.parseInt(lineArray[1]); + int bestResultAtLeast = Integer.parseInt(lineArray[2]); + int[] dancerScores = new int[nbDancers]; + for (int j=0; j= atLeast) { + resultat++; + } + else if (quotient == atLeast-1 && quotient >0) { + potSurpr++; + } + } + else if (reste == 1) { + //t-1 t+1 t+1 (*) t+1 * + //t t t+1 t+1 + if (quotient >= atLeast - 1) { + resultat++; + } + } + else { + //t t t+2 (*) t+2 * + //t t+1 t+1 t+1 + if (quotient >= atLeast-1) { + resultat++; + } + else if (quotient == atLeast-2) { + potSurpr++; + } + } + } + resultat+=Math.min(nbSurprises,potSurpr); + return resultat; + } +} +" +A20935,"package contests.GoogleCodejam.GCJ2012.qualification; + +import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +/** + * Created with IntelliJ IDEA. + * User: addepar + * Date: 4/14/12 + * Time: 2:27 PM + * To change this template use File | Settings | File Templates. + */ +public class ProblemB { + public static void main(String args[]) throws FileNotFoundException { + Scanner scanner = new Scanner(ProblemB.class.getResourceAsStream(""b_small.in"")); + + int tests = scanner.nextInt(); + + + for (int test = 1; test <= tests; test++) { + int result = 0; + + int numGooglers = scanner.nextInt(); + int surprises = scanner.nextInt(); + int minscore = scanner.nextInt(); + + int potential = 0; + for(int i = 0; i < numGooglers; i++){ + //555 645 + //566 557 + //556 466 + + int score = scanner.nextInt(); + int maxscore = score/3; + + if(score %3 >0){ + maxscore++; + } + + if(maxscore >= minscore){ + result++; + } else if((maxscore +1) == minscore){ + if(score > 0 && (score %3 == 0 || score%3 == 2)){ + potential++; + } + } + } + + + result += Math.min(potential,surprises); + + + System.out.println(""Case #"" + test + "": "" + result); + } + + } +} + + +" +A22693,"package google.codejam; + +public class DanceGoogler implements GoogleSolver { + + @Override + public String solve(String str) { + String[] input = str.split("" ""); + int dancerNumber = Integer.parseInt(input[0]); + int surprisingCount = Integer.parseInt(input[1]); + int bestResult = Integer.parseInt(input[2]); + + int surpriseingScore = (bestResult*3-4)>0?(bestResult*3-4):0; + int minScore = bestResult*3-2>0?((bestResult*3-2)):0; + + //int[] scores = new int[dancerNumber]; + + int bestCount = 0; + for(int i=0; i=minScore){ + bestCount++; + continue; + } + if(scores>=surpriseingScore && surprisingCount>0){ + bestCount++; + surprisingCount--; + continue; + } + + } + + return bestCount+""""; + } + +} +" +A23079,"import java.io.File; +import java.util.Scanner; + + +public class surprising { + + public static int solve(String input) + { + String[] inputs = input.split("" ""); + int count = Integer.parseInt(inputs[0]); + int surprises = Integer.parseInt(inputs[1]); + int best = Integer.parseInt(inputs[2]); + int[] scores = new int[inputs.length - 3]; + + for (int i = 3; i < inputs.length; i++) { + scores[i-3] = Integer.parseInt(inputs[i]); + } + + int bestCount = 0; + int surprisesCount = 0; + + for (int i = 0; i < scores.length; i++) { + int num = scores[i]; + if (best == 0) bestCount++; + else if (num == 0) continue; + else if (isBest(num, best)) bestCount++; + else if (isSuprising(num, best)) surprisesCount++; + } + + return bestCount + Math.min(surprisesCount, surprises); + } + + public static boolean isBest(int n, int best) + { + int start = n / 3; + if (start >= best) return true; + + // have two remaining, and is only less by one. + // We can get a non-surprising result this way + int remain = n % 3; + if (start == best - 1 && (remain == 2 || remain == 1)) return true; + return false; + } + + public static boolean isSuprising(int n, int best) + { + int start = n / 3; + int remain = n % 3; + if (start == best - 1 && remain == 0) return true; + if (start == best - 2 && remain == 2) return true; + return false; + } + + public static void main(String[] args) { + Scanner scanner = null; + try { + scanner = new Scanner(new File(""A-small-attempt0.in"")); + }catch (Exception e){ + System.out.println(e.getMessage()); + } + + String c = scanner.nextLine(); + int i = 1; + while (scanner.hasNextLine()) { + String input = scanner.nextLine(); + System.out.println(""Case #"" + i + "": "" + solve(input)); + i++; + } + } +} +" +A22482,"import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class P02 { + + public static void main(String[] args) { + init(); + Scanner inp = new Scanner(System.in); + int t = inp.nextInt(); + inp.nextLine(); + int i = 1; + while (t > 0) { + int n = inp.nextInt(); + int s = inp.nextInt(); + int p = inp.nextInt(); + int ret = 0; + for (int j = 0; j < n; j++) { + int x = inp.nextInt(); + int v = x / 3; + int mo = x % 3; + if (v >= p) + ret++; + else if (mo > 0 && (v + 1) >= p) + ret++; + else if (s > 0 && (v + 2) >= p && mo == 2) { + s--; + ret++; + } else if (s > 0 && (v + 1) >= p && (mo == 1 || v > 0)) { + s--; + ret++; + } + } + + System.out.println(""Case #"" + i + "": "" + ret); + + --t; + ++i; + } + + } + + static String[] coded = { ""ejp mysljylc kd kxveddknmc re jsicpdrysi"", + ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"", + ""de kr kd eoya kw aej tysr re ujdr lkgc jvqz"" }; + static String[] uncoded = { ""our language is impossible to understand"", + ""there are twenty six factorial possibilities"", + ""so it is okay if you want to just give upzq"" }; + + static Map mapping = new HashMap(); + + private static void init() { + for (int i = 0; i < coded.length; i++) { + for (int j = 0; j < coded[i].length(); j++) { + mapping.put(coded[i].charAt(j), uncoded[i].charAt(j)); + } + } + } + + private static String translate(String line) { + String ret = """"; + for (int i = 0; i < line.length(); i++) { + if (mapping.containsKey(line.charAt(i))) { + ret = ret + mapping.get(line.charAt(i)); + } else if (line.charAt(i) == ' ') { + ret = ret + line.charAt(i); + } else { + System.out.println(""NOT "" + line.charAt(i)); + } + } + return ret; + + } +} +" +A21291,"package googlejam.qualification2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public class Dancing { + + + public static void main(String[] args) throws FileNotFoundException { + List input = readSourceLinePerLine(new FileReader(new File(""/Users/bronzi/Desktop/input.txt""))); + + StringBuilder result = new StringBuilder(); + int testSize = Integer.valueOf(input.get(0)); + int index = 1; + for (int i = 0; i < testSize; i++) { + List l = toInteger(input.get(index++).split("" "")); + result.append(""Case #"" + (i+1) + "": "" + + solveIt(l) + ""\n""); + System.out.println(""done "" + i + "" of "" + testSize); + } + // System.out.println(result.toString()); + writeFile(result.toString(), new File(""/Users/bronzi/Desktop/output.txt"")); + } + + + + + + + +// The first integer will be N, the number of Googlers, +// and the second integer will be S, the number of surprising triplets of scores. +// The third integer will be p, as described above. +// Next will be N integers ti: the total points of the Googlers. + + public static int solveIt(List l) { + + int N = l.get(0); + int S = l.get(1); + int p = l.get(2); + + List scores = l.subList(3, l.size()); + assert scores.size() == N; + + int candidateHighScore = 0; + + Iterator i = scores.iterator(); + while (i.hasNext()) { + int score = i.next(); +// System.out.println(""doing "" + score); + + if (score == 0) { + if (p == 0) { + candidateHighScore++; + } + continue; + } + + if (score % 3 == 0) { +// System.out.println(""\t% 3 == 0""); + int avg = score / 3; + if (avg >= p) { +// System.out.println(""\talready more than "" + p); + candidateHighScore++; + continue; + } + if (S > 0 && avg >= (p - 1)) { +// System.out.println(""\tsurprising ("" + S + "") left""); + S--; + candidateHighScore++; + continue; + } + } + + if (score % 3 == 1) { +// System.out.println(""\t% 3 == 1""); + int avg = score / 3; + if (avg >= (p - 1)) { +// System.out.println(""\talready more than "" + p); + candidateHighScore++; + continue; + } + } + + //redundant check + if (score % 3 == 2) { +// System.out.println(""\t% 3 == 2""); + int avg = score / 3; + if (avg >= (p - 1)) { +// System.out.println(""\talready more than "" + p); + candidateHighScore++; + continue; + } + if (S > 0 && avg >= (p - 2)) { +// System.out.println(""\tsurprising ("" + S + "") left""); + S--; + candidateHighScore++; + continue; + } + } + +// if (score >= (p - 1)) { +// //score is already ok +// candidateHighScore++; +// continue; +// } +// if (S > 0 && score >= (p - 2)) { +// //score is surprising +// candidateHighScore++; +// S--; +// } + } + + + return candidateHighScore; + + } + + + + + + + + + + + + public static List readSourceLinePerLine(Reader fileReader) { + try { + List result = new ArrayList(); + BufferedReader in = new BufferedReader(fileReader); + String line; + while ((line = in.readLine()) != null) { + result.add(line); + } + in.close(); + return result; + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + public static List toInteger(List l) { + List result = new ArrayList(); + for (String string : l) { + result.add(string != null ? Integer.valueOf(string) : null); + } + return result; + } + public static List toInteger(String...ss) { + return toInteger(Arrays.asList(ss)); + } + + private static void writeFile(String content, File file) { + try { + writeFile(content,new FileWriter(file)); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + private static void writeFile(String content, FileWriter fstream) { + try { + BufferedWriter out = new BufferedWriter(fstream); + out.write(content); + out.close(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + +} +" +A21091,"/** + * DancingWithTheGooglers.java + * + * Either use command line or first argument must be path of input file. + */ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +/** + * @author bsanghvi + */ +public class DancingWithTheGooglers { + + private static final Map scopesMap = new HashMap(); + private static final Map surprisingScoresMap = new HashMap(); + + static { + scopesMap.put(30, 10); // 10, 10, 10 + + scopesMap.put(29, 10); // 10, 10, 9 + + scopesMap.put(28, 10); // 10, 9, 9 + surprisingScoresMap.put(28, 10); // 10, 10, 8 + + scopesMap.put(27, 9); // 9, 9, 9 + surprisingScoresMap.put(27, 10); // 10, 9, 8 + + scopesMap.put(26, 9); // 9, 9, 8 + surprisingScoresMap.put(26, 10); // 10, 8, 8 + + scopesMap.put(25, 9); // 9, 8, 8 + surprisingScoresMap.put(25, 9); // 9, 9, 7 + + scopesMap.put(24, 8); // 8, 8, 8 + surprisingScoresMap.put(24, 9); // 9, 8, 7 + + scopesMap.put(23, 8); // 8, 8, 7 + surprisingScoresMap.put(23, 9); // 9, 7, 7 + + scopesMap.put(22, 8); // 8, 7, 7 + surprisingScoresMap.put(22, 8); // 8, 8, 6 + + scopesMap.put(21, 7); // 7, 7, 7 + surprisingScoresMap.put(21, 8); // 8, 7, 6 + + scopesMap.put(20, 7); // 7, 7, 6 + surprisingScoresMap.put(20, 8); // 8, 6, 6 + + scopesMap.put(19, 7); // 7, 6, 6 + surprisingScoresMap.put(19, 7); // 7, 7, 5 + + scopesMap.put(18, 6); // 6, 6, 6 + surprisingScoresMap.put(18, 7); // 7, 6, 5 + + scopesMap.put(17, 6); // 6, 6, 5 + surprisingScoresMap.put(17, 7); // 7, 5, 5 + + scopesMap.put(16, 6); // 6, 5, 5 + surprisingScoresMap.put(16, 6); // 6, 6, 4 + + scopesMap.put(15, 5); // 5, 5, 5 + surprisingScoresMap.put(15, 6); // 6, 5, 4 + + scopesMap.put(14, 5); // 5, 5, 4 + surprisingScoresMap.put(14, 6); // 6, 4, 4 + + scopesMap.put(13, 5); // 5, 4, 4 + surprisingScoresMap.put(13, 5); // 5, 5, 3 + + scopesMap.put(12, 4); // 4, 4, 4 + surprisingScoresMap.put(12, 5); // 5, 4, 3 + + scopesMap.put(11, 4); // 4, 4, 3 + surprisingScoresMap.put(11, 5); // 5, 3, 3 + + scopesMap.put(10, 4); // 4, 3, 3 + surprisingScoresMap.put(10, 4); // 4, 4, 2 + + scopesMap.put(9, 3); // 3, 3, 3 + surprisingScoresMap.put(9, 4); // 4, 3, 2 + + scopesMap.put(8, 3); // 3, 3, 2 + surprisingScoresMap.put(8, 4); // 4, 2, 2 + + scopesMap.put(7, 3); // 3, 2, 2 + surprisingScoresMap.put(7, 3); // 3, 3, 2 + + scopesMap.put(6, 2); // 2, 2, 2 + surprisingScoresMap.put(6, 3); // 3, 2, 1 + + scopesMap.put(5, 2); // 2, 2, 1 + surprisingScoresMap.put(5, 3); // 3, 1, 1 + + scopesMap.put(4, 2); // 2, 1, 1 + surprisingScoresMap.put(4, 2); // 2, 2, 0 + + scopesMap.put(3, 1); // 1, 1, 1 + surprisingScoresMap.put(3, 2); // 2, 1, 0 + + scopesMap.put(2, 1); // 1, 1, 0 + surprisingScoresMap.put(2, 2); // 2, 0, 0 + + scopesMap.put(1, 1); // 1, 0, 0 + + scopesMap.put(0, 0); // 0, 0, 0 + } + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(final String[] args) { + try { + final Scanner in; + if (args.length >= 1) { + in = new Scanner(new File(args[0])); + } else { + in = new Scanner(System.in); + } + + final int T = in.nextInt(); + + for (int test = 1; test <= T; test++) { + final int result = processCase(in); + System.out.println(""Case #"" + test + "": "" + result); + } + } catch (final FileNotFoundException e) { + e.printStackTrace(); + } + } + + private static int processCase(final Scanner in) { + int result = 0; + + final int N = in.nextInt(); // number of Googlers + int S = in.nextInt(); // number of surprising triplets of scores + final int p = in.nextInt(); // best result + final int[] t = new int[N]; + for (int i = 0; i < t.length; i++) { + t[i] = in.nextInt(); + } + + for (final int ti : t) { + if (scopesMap.containsKey(ti) && scopesMap.get(ti) >= p) { + ++result; + } else if (S > 0 && surprisingScoresMap.containsKey(ti) && surprisingScoresMap.get(ti) >= p) { + ++result; + --S; + } + } + + return result; + } +} +" +A22744,"import java.util.*; +public class q2 { + + public static void main(String args[]){ + new q2().run(); + } + Scanner input = new Scanner(System.in); + + + + void run(){ + int N = input.nextInt(); + for(int i=1;i<=N;i++){ + System.out.print(""Case #""+i+"": ""); + solve(); + } + } + void solve(){ + int i,j,k; + int T = input.nextInt(); + int s = input.nextInt(); + int p = input.nextInt(); + int x,m,ans = 0; + double y; + Integer [] a = new Integer [T]; + boolean [] used = new boolean[T]; + for(i=0;i= p)ans++; + else if(s > 0 && x > 0 && x + 1 >= p){ + ans++; + s--; + } + } + else if(a[i]%3==1){ + if(x>=p || x+1>=p) + ans++; + else if (s > 0 && x + 1 >= p){ + ans++; + s--; + } + } + else if(a[i]%3==2){ + if(x+1 >= p || x>= p) + ans++; + else if(s>0 && x+2 >= p){ + ans++; + s--; + } + } + } + System.out.println(ans); + } + + +} +" +A22557,"import java.util.Scanner; + + +public class B { + + static int[][] dp; // dp[i][j]: i人目まで終わった・あとj個surprize + static void solve(int casee, Scanner sc) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = sc.nextInt(); + } + dp = new int[n+1][s+1]; + for (int i = 0; i < n; i++) { + boolean alwaysGood = (t[i] + 2) / 3 >= p; + boolean goodWhenSurprizing = p == 0 || t[i] >= 2 && (t[i] + 4) / 3 >= p; + if (alwaysGood) { + for (int j = s; j >= 0; j--) { + dp[i+1][j] = dp[i][j] + 1; + } + } + else if (goodWhenSurprizing) { + for (int j = s; j >= 0; j--) { + dp[i+1][j] = dp[i][j]; + } + for (int j = s; j >= 1; j--) { + dp[i+1][j-1] = Math.max(dp[i+1][j-1], dp[i][j] + 1); + } + } + else { + for (int j = s; j >= 0; j--) { + dp[i+1][j] = dp[i][j]; + } + } + } + int max = 0; + for (int i = 0; i <= s; i++) { + max = Math.max(max, dp[n][i]); + } + System.out.println(""Case #"" + (casee+1) + "": "" + max); + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int i = 0; i < t; i++) { + solve(i, sc); + } + + } + +} +" +A20734,"public class MalformedInputFileException extends Throwable { + + private static final long serialVersionUID = -6714074599343669185L; + + public MalformedInputFileException() { + super(); + } + + public MalformedInputFileException(String message) { + super(message); + } + + public MalformedInputFileException(String message, Throwable cause) { + super(message, cause); + } + + public MalformedInputFileException(Throwable cause) { + super(cause); + } +} +" +A21977,"package com.renoux.gael.codejam.fwk; + +import com.renoux.gael.codejam.utils.Input; +import com.renoux.gael.codejam.utils.Output; + + +public class Model extends Solver { + + public static void main(String... args) throws Exception { + new Model().run(); + } + + @Override + protected void solveCase(Input in, Output out) { + // TODO + } + + @Override + protected String getProblemName() { + return ""hey2012/Model""; + } +} +" +A20641,"import java.io.PrintWriter; +import java.util.Scanner; + +public class ProblemB { + + public static void main(String[] args) { + final Scanner in = new Scanner(System.in); + final PrintWriter out = new PrintWriter(System.out); + + final int t = in.nextInt(); + + for (int tt = 0; tt < t; tt++) { + final int n = in.nextInt(); + final int s = in.nextInt(); + final int p = in.nextInt(); + + int surprisesLeft = s; + int googlersCount = 0; + for (int nn = 0; nn < n; nn++) { + final int totalScore = in.nextInt(); + if (canAchieveScoreIfNormal(totalScore, p)) { + googlersCount++; + } else if (surprisesLeft > 0 && canAchieveScoreIfSurprising(totalScore, p)) { + googlersCount++; + surprisesLeft--; + } + } + + out.write(""Case #"" + (tt + 1) + "": "" + googlersCount + ""\n""); + } + + out.flush(); + } + + private static boolean canAchieveScoreIfNormal(int totalScore, int score) { + return totalScore >= (3 * score - 2); + } + + private static boolean canAchieveScoreIfSurprising(int totalScore, int score) { + if (score == 1) + return totalScore >= 1; + else + return totalScore >= (3 * score - 4); + } + +} +" +A20065,"import java.util.*; +import java.io.*; +public class dancing { + + public static void main(String[] args) throws Exception { + Scanner sc=new Scanner(new File(""input"")); + int size=sc.nextInt(); + int[] gogo=new int[31]; + int[] cap=new int[31]; + for(int x=3;x<31;x++)cap[x]=x-2; + gogo[0]=0; + int best=1; + int c=0; + for(int x=1;x<31;x++) + { + gogo[x]=best; + c++; + if(c==3) + { + c=0; + best++; + } + } + //System.out.println(Arrays.toString(gogo)); + + for(int w=0;w=p)ans++; + else if(S>0) + { + boolean pos=arr[x]==0 || (gogo[arr[x]]-1==gogo[arr[x]-1]); + + if(sto[x]+1==p && !pos) + { + S--; + ans++; + } + } + } + System.out.println(""Case #""+(w+1)+"": ""+ans); + + + } + } +} +" +A22856,"package qualification.q2; + +import qualification.common.InputReader; +import qualification.common.OutputWriter; +import qualification.q1.Q1Solver; + +/** + * Created by IntelliJ IDEA. + * User: ofer + * Date: 14/04/12 + * Time: 18:55 + * To change this template use File | Settings | File Templates. + */ +public class Q2Sim { + + public static void main(String[] args){ + String inputFile = ""input.txt""; + String outPutFile = ""output.txt""; + String[] lines = InputReader.getInputLines(inputFile); + Q2Solver solver = new Q2Solver(); + int numOfTests = Integer.parseInt(lines[0]); + String[] output = new String[numOfTests]; + for (int i = 0 ; i < numOfTests ; i++){ + String[] splited = lines[i+1].split("" ""); + int n = Integer.parseInt(splited[0]); + int s = Integer.parseInt(splited[1]); + int p = Integer.parseInt(splited[2]); + int[] sums = new int[n]; + for (int j = 0 ; j < n ; j++){ + int sum = Integer.parseInt(splited[j+3]); + sums[j] = sum; + } + int res = solver.solve(n,s,p,sums); + output[i] = ""Case #"" + (i+1) + "": "" + res; + } + OutputWriter.writeOutput(outPutFile, output); + } +} +" +A22979,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +class IOSystem { + private String filePath; + private List inputList = new ArrayList(); + private StringBuilder sb = new StringBuilder(); + private int readSize = 0; + private int appendedSize = 0; + public IOSystem(String filePath) + { + this(filePath,"" ""); + } + public IOSystem(String filePath,String sep) + { + this.filePath = filePath; + try { + BufferedReader br = new BufferedReader(new FileReader(filePath+"".in"")); + String line = null; + while((line=br.readLine())!=null) + { + inputList.addAll(Arrays.asList(line.split(sep))); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + public int size(){return inputList.size();} + public boolean hasNext(){return readSize < size();} + public int nextInt(){return Integer.parseInt(inputList.get(readSize++));} + public long nextLong(){return Long.parseLong(inputList.get(readSize++));} + public double nextDouble(){return Double.parseDouble(inputList.get(readSize++));} + public String nextString(){return new String(inputList.get(readSize++));} + public void appendAnswer(T answer){sb.append(""Case #""+(++appendedSize)+"": ""+answer.toString()+""\n"");}; + public void output(){ + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(filePath+"".ou"")); + bw.write(sb.toString()); + bw.flush(); + System.out.println(""output ->""+filePath+"".ou""); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A20434,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + + +public class ProblemUtils { + + public static String[] readInput(String path) throws Exception { + FileInputStream in = new FileInputStream(path); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + int nlines = Integer.parseInt(reader.readLine()); + String[] lines = new String[nlines]; + for (int i = 0; i < nlines; i++) { + lines[i] = reader.readLine(); + } + return lines; + } + + public static void writeOutput(String path, String[] lines) throws Exception { + FileOutputStream out = new FileOutputStream(path); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); + for (int i = 0; i < lines.length; i++) { + writer.write(""Case #"" + (i + 1) + "": "" + lines[i]); + if (i + 1 < lines.length) { + writer.write(""\n""); + } + } + writer.flush(); + out.close(); + } + +} +" +A22674,"import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.*; + +import static java.lang.Math.*; +import static java.util.Arrays.*; +import static java.lang.Integer.*; +import static java.lang.Character.*; + + + +public class B { + + Scanner scan; + InputStream in; + + int intLine(){ + return parseInt(scan.nextLine()); + } + + long solve(){ + long res=0; + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int[]A = new int[n]; + for(int i=0;i=0;i--){ + + int x = (A[i]+2)/3; + if(x>=p)res++; + else { + x = (A[i]+4)/3; + if(x>=p && s>0 && A[i]>0){ + res++;s--; + } + } + } + + return res; + } + + void solveAll(){ + int N = parseInt(scan.nextLine()); + for(int i=0;i0) { + boolean ok = false; + for(int i=0;i 0) { + div[i][2]++; + div[i][0]--; + ok = true; + } + break; + case 1: + break; + case 2: + if(div[i][2] == p-1 && div[i][1] > 0) { + div[i][2]++; + div[i][1]--; + ok = true; + } + break; + } + } + if(ok) { + // out.println(Arrays.toString(div[i])); + break; + } + } + // if(!ok) { + // for(int i=0;i= p) count++; + // out.println(div[i][0]+"" ""+div[i][1]+"" ""+div[i][2]); + } + out.println(""Case #""+z+"": ""+count); + } + } + + static boolean isSup(int[] div) { + return (div[2] - div[0] == 2); + } + + static boolean canBeSup(int[] div) { + return div[0] != 0; + } + + static int[] sup(int[] div) { + if(div[0] == div[2]) return new int[]{div[0]-1,div[1],div[2]+1}; + else if(div[1] == div[2]) return new int[]{div[0],div[1]-1,div[2]+1}; + else return new int[]{div[0]-1,div[1]+1,div[2]}; + } +}" +A21775,"import java.util.ArrayList; +import java.util.Arrays; + + +public class ProbB { + + /** + * @param args + */ + public static void main(String[] args) { + ArrayList in=Utils.readFile(""B-large.in.in""); + ArrayList out =new ArrayList(); + for (int i = 1; i < in.size(); i++) { + String[] str=in.get(i).split("" ""); + int n= Integer.parseInt(str[0]); + int surprise=Integer.parseInt(str[1]); + int p=Integer.parseInt(str[2]); + int[] elem=new int[n]; + for (int j = 0; j < n; j++) { + elem[j]=Integer.parseInt(str[j+3]); + } + Arrays.sort(elem); + int count=0; + for (int j = elem.length-1; j >=0 ; j--) { + if(elem[j]>=(3*p-2)){ + count++; + }else if(elem[j]>=(3*p-4)){ + if(surprise==0||p==1){ + break; + }else{ + count++; + surprise--; + } + }else{ + break; + } + } + out.add(""Case #""+i+"": ""+count); + Utils.writeFile(out, ""B-large""); + } + + + } + +} +" +A20826,"package com.google.codejam; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class ProblemC { + + public ProblemC() { + super(); + // TODO Auto-generated constructor stub + } + + + public void calculate(int numTestCase , int part , int suprise , int max , List a){ + int count = 0 ; + int possible = 0 ; + for(int i = 0 ; i suprise) + count = count +suprise ; + System.out.println(""Case #""+(numTestCase)+"": ""+(count)); + } + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + ProblemC c = new ProblemC(); + c.fileRead(c) ; +// List l = new ArrayList(); +// l.add(29); +// l.add(20); +// l.add(8); +// l.add(18); +// l.add(18); +// l.add(21); +// c.calculate(1,6,2,8,l); + } + + + + public void fileRead(ProblemC cc){ + FileInputStream fstream; + try { + fstream = new FileInputStream(""D:\\1.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + int testCase =0 ; + while ((strLine = br.readLine()) != null) { + // Print the content on the console + testCase = Integer.parseInt(strLine); + + for(int i = 0 ; i < testCase ; i++){ + String line = br.readLine() ; + String[]array = line.split("" ""); + int numpart = Integer.parseInt(array[0]); + int suprise = Integer.parseInt(array[1]); + int max = Integer.parseInt(array[2]); + List l = new ArrayList(); + for(int ii = 0; ii= p) + count++; + else + { + score = (dancers[k]-p)/2; + if (!(p-score > 2) //Necessary? + { + if (p-score == 2) + { + if (surp != 0) + { + surp--; + count++; + } + } + else count++; + } + } + } + else + { + if (p == 0) + count++; + } + } + + System.out.println(""Case #""+(i+1)+"": ""+count); + } + } + +}" +A20378,"package googleCodeJam; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class ProblemB { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""input.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + br.readLine(); + int counter = 1; + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + String values[] = strLine.split("" ""); + + int surprisingScores = Integer.parseInt(values[1]); + + int pValue = Integer.parseInt(values[2]); + + int nearP = 0; + int aboveP = 0; + + for (int i = 3; i < values.length; i++) + { + int score = Integer.parseInt(values[i]); + + int maxScore = 0; + int maxSurprisingScore = 0; + + if (score > 0) + { + maxScore = (score - 1) / 3 + 1; + maxSurprisingScore = (score + 1) / 3 + 1; + } + + if (maxScore > 10) + { + maxScore = 10; + } + + if (maxSurprisingScore > 10) + { + maxSurprisingScore = 10; + } + + if (maxScore >= pValue) + { + aboveP ++; + } + else if (maxSurprisingScore >= pValue) + { + nearP ++; + } + } + + int result = aboveP; + + if (nearP < surprisingScores) + { + result += nearP; + } + else + { + result += surprisingScores; + } + + System.out.println(""Case #"" + counter + "": "" + result); + + counter ++; + } + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A22686,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + + +public class Triplets { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try { + List out=new ArrayList(); + BufferedReader br=new BufferedReader(new FileReader(""C:\\Users\\partha\\Desktop\\test.txt"")); + int tests=Integer.parseInt(br.readLine()); + String line=null; + while((line=br.readLine())!=null) + { + String[] tokens=line.split("" ""); + int n=Integer.parseInt(tokens[0]); + int s=Integer.parseInt(tokens[1]); + int min=Integer.parseInt(tokens[2]); + int num[]=new int[n]; + for(int i=0;i0) + { + if(min<=p-1 || min<=p+1) + { + cnt++; + posCnt--; + } + } + } + else if(((3*p-2)== sc[i])) + { + + if(surCnt0) + { + if(min<=p-2 || min<=p) + { + cnt++; + posCnt--; + } + + } + + } + else if((3*p-3)== sc[i]) + { + + if(surCnt0) + { + if(min<=p-2 || min<=p-1 || min<=p) + { + cnt++; + posCnt--; + } + + } + + } + + + + } + + + + + return cnt; + } + + +} +" +A20590,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class B{ + public static void main(String[] args) throws FileNotFoundException + { + Scanner sc = new Scanner(new File(""B.txt"")); + int testCase = Integer.parseInt(sc.nextLine()); + for(int Case=1; Case<=testCase; Case++) + { + int n = sc.nextInt(); + int sup = sc.nextInt(); + int p = sc.nextInt(); + p=3*p; + int[] X=new int[n]; + int ans=0; + for(int i=0; i=(p-2)){ans++;} + else + {if(X[i]>0 && X[i]>=(p-4) && sup>0){ans++;sup--;}} + } + System.out.println(""Case #""+Case+"": ""+ans); + } + } +}" +A20998,"package fixjava; + +import java.awt.Adjustable; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.RenderingHints; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollBar; + +@SuppressWarnings(""serial"") +public class ZoomPanel extends JPanel { + + public static abstract class ZoomContent extends JPanel { + // Width and height of canvas contents, in canvas coordinates + private float contentWCanv, contentHCanv; + + // Width and height of canvas contents, in screen coordinates + private int contentWScr, contentHScr; + + // Canvas scroll position, in screen coordinates + private int contentXScr, contentYScr; + + // Current zoom + protected float scale = 1.0f; + + // Initialize zoom etc. the first time canvas is painted + private boolean firstPaint = true; + + // The scrollbar components in the parent ZoomPanel + private JScrollBar hScrollBar; + private JScrollBar vScrollBar; + + // --------------------------------------------------------------------------------------------------- + + public ZoomContent(float contentWidth, float contentHeight) { + this.contentWCanv = contentWidth; + this.contentHCanv = contentHeight; + final ZoomContent canvas = this; + final float[] mouseXY = new float[2]; + + this.addMouseWheelListener(new MouseWheelListener() { + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + canvas.mouseWheelMoved(e); + } + }); + this.addMouseMotionListener(new MouseMotionListener() { + @Override + public void mouseMoved(MouseEvent e) { + canvas.mouseMoved(e, toCanvasCoords(e, mouseXY)); + } + + @Override + public void mouseDragged(MouseEvent e) { + canvas.mouseDragged(e, toCanvasCoords(e, mouseXY)); + } + }); + this.addMouseListener(new MouseListener() { + @Override + public void mouseReleased(MouseEvent e) { + canvas.mouseReleased(e, toCanvasCoords(e, mouseXY)); + } + + @Override + public void mousePressed(MouseEvent e) { + canvas.mousePressed(e, toCanvasCoords(e, mouseXY)); + } + + @Override + public void mouseExited(MouseEvent e) { + canvas.mouseExited(e, toCanvasCoords(e, mouseXY)); + } + + @Override + public void mouseEntered(MouseEvent e) { + canvas.mouseEntered(e, toCanvasCoords(e, mouseXY)); + } + + @Override + public void mouseClicked(MouseEvent e) { + canvas.mouseClicked(e, toCanvasCoords(e, mouseXY)); + } + }); + } + + // --------------------------------------------------------------------------------------------------- + + /** Called first time paint() is called, to set up zoom etc. */ + private void zoomToFit() { + int w = getWidth(), h = getHeight(); + + // Scale to fit + scale = Math.min(w / (float) contentWCanv, h / (float) contentHCanv); + + // Center in window + zoomBy(1.0, 0, 0); + } + + private void resized() { + // Center in window if needed + zoomBy(1.0, 0, 0); + } + + // --------------------------------------------------------------------------------------------------- + + /** Called by ZoomPanel after setting up scrollbars */ + protected void addScrollBars(final JScrollBar hScrollBar, final JScrollBar vScrollBar) { + this.hScrollBar = hScrollBar; + this.vScrollBar = vScrollBar; + + hScrollBar.addAdjustmentListener(new AdjustmentListener() { + @Override + public void adjustmentValueChanged(AdjustmentEvent e) { + int hMax = hScrollBar.getMaximum(); + float hScale = hMax == 0 ? 0.0f : 1.0f / hMax; + scrollToX((hScrollBar.getValue() + hScrollBar.getVisibleAmount() / 2) * hScale); + } + }); + vScrollBar.addAdjustmentListener(new AdjustmentListener() { + @Override + public void adjustmentValueChanged(AdjustmentEvent e) { + int vMax = vScrollBar.getMaximum(); + float vScale = vMax == 0 ? 0.0f : 1.0f / vMax; + scrollToY((vScrollBar.getValue() + vScrollBar.getVisibleAmount() / 2) * vScale); + } + }); + } + + // --------------------------------------------------------------------------------------------------- + + // Override these methods as needed in subclasses. canvasXY is the x/y canvas coords of the mouse point. + + public void mouseMoved(MouseEvent e, float[] canvasXY) { + } + + public void mouseDragged(MouseEvent e, float[] canvasXY) { + } + + public void mouseClicked(MouseEvent e, float[] canvasXY) { + } + + public void mousePressed(MouseEvent e, float[] canvasXY) { + } + + public void mouseReleased(MouseEvent e, float[] canvasXY) { + } + + public void mouseEntered(MouseEvent e, float[] canvasXY) { + } + + public void mouseExited(MouseEvent e, float[] canvasXY) { + } + + public void keyTyped(KeyEvent e) { + if (e.getKeyChar() == '1') + zoomToFit(); + } + + public void mouseWheelMoved(MouseWheelEvent e) { + double scrollAmt = e.getPreciseWheelRotation(); + zoomBy(Math.pow(e.isControlDown() ? 1.2 : 1.05, -scrollAmt), e.getX(), e.getY()); + } + + // ------------------------------------------------------------------------------------------------ + + protected void scrollToX(float scrollbarFracX) { + int viewportWScr = getWidth(); + contentXScr = (int) (viewportWScr / 2 - contentWScr * scrollbarFracX); + repaint(); + } + + protected void scrollToY(float scrollbarFracY) { + int viewportHScr = getHeight(); + contentYScr = (int) (viewportHScr / 2 - contentHScr * scrollbarFracY); + repaint(); + } + + // ------------------------------------------------------------------------------------------------ + + protected void zoomBy(double zoomFactor, int centerXScr, int centerYScr) { + // Change scale + scale *= zoomFactor; + + // Update size of contents in screen coordinates + contentWScr = (int) Math.ceil(contentWCanv * scale); + contentHScr = (int) Math.ceil(contentHCanv * scale); + + // Update scroll position in screen coordinates + contentXScr = (int) Math.round((contentXScr - centerXScr) * zoomFactor + centerXScr); + contentYScr = (int) Math.round((contentYScr - centerYScr) * zoomFactor + centerYScr); + + // Figure out size and position of scrollbars + if (hScrollBar != null && vScrollBar != null) { + int viewportWScr = getWidth(), viewportHScr = getHeight(); + + // Snap view to beginning or end of scroll region if we zoom off the end + int viewPosX = -contentXScr, viewPosMaxX = contentWScr - viewportWScr; + viewPosX = Math.max(Math.min(viewPosX, viewPosMaxX), 0); + int viewPosY = -contentYScr, viewPosMaxY = contentHScr - viewportHScr; + viewPosY = Math.max(Math.min(viewPosY, viewPosMaxY), 0); + + if (viewPosMaxX > 0) { + // Canvas wider than viewport + hScrollBar.setMaximum(contentWScr); + hScrollBar.setValue(viewPosX); + hScrollBar.setVisibleAmount(viewportWScr); + hScrollBar.setBlockIncrement((int) Math.ceil(viewportWScr * 0.8f)); + hScrollBar.setUnitIncrement((int) Math.ceil(viewportWScr * 0.08f)); + hScrollBar.setEnabled(true); + } else { + // Canvas narrower than viewport, center it horizontally + hScrollBar.setEnabled(false); + contentXScr = (viewportWScr - contentWScr) / 2; + } + if (viewPosMaxY > 0) { + // Canvas taller than viewport + vScrollBar.setMaximum(contentHScr); + vScrollBar.setValue(viewPosY); + vScrollBar.setVisibleAmount(viewportHScr); + vScrollBar.setBlockIncrement((int) Math.ceil(viewportHScr * 0.8f)); + vScrollBar.setUnitIncrement((int) Math.ceil(viewportHScr * 0.08f)); + vScrollBar.setEnabled(true); + } else { + // Canvas shorter than viewport, center it vertically + vScrollBar.setEnabled(false); + contentYScr = (viewportHScr - contentHScr) / 2; + } + } + + repaint(); + } + + // ------------------------------------------------------------------------------------------------ + + protected float[] toCanvasCoords(int screenX, int screenY, float[] outXY) { + outXY[0] = (screenX - contentXScr) / scale; + outXY[1] = (screenY - contentYScr) / scale; + return outXY; + } + + protected float[] toCanvasCoords(int screenX, int screenY) { + float[] outXY = new float[2]; + toCanvasCoords(screenX, screenY, outXY); + return outXY; + } + + protected float[] toCanvasCoords(MouseEvent e) { + return toCanvasCoords(e.getX(), e.getY()); + } + + protected float[] toCanvasCoords(MouseEvent e, float[] outXY) { + toCanvasCoords(e.getX(), e.getY(), outXY); + return outXY; + } + + // ------------------------------------------------------------------------------------------------ + + @Override + public void paint(Graphics g) { + super.paint(g); + Graphics2D g2 = (Graphics2D) g; + + if (firstPaint) { + zoomToFit(); + firstPaint = false; + } + + g2.drawRect(contentXScr, contentYScr, contentWScr, contentHScr); + + AffineTransform orig = g2.getTransform(); + + // Correctly center scaled canvas in viewport + g2.translate(contentXScr, contentYScr); + g2.scale(scale, scale); + + // Run user-provided code + paintCanvas(g2); + + // Restore old transform + g2.setTransform(orig); + } + + /** Override this to draw your content */ + public abstract void paintCanvas(Graphics2D g); + } + + // ------------------------------------------------------------------------------------------------ + + /** A zoomable image */ + public static class ZoomImageContent extends ZoomContent { + protected BufferedImage img; + + public ZoomImageContent(BufferedImage img) { + super(img.getWidth(), img.getHeight()); + this.img = img; + } + + @Override + public void paintCanvas(Graphics2D g) { + g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g.drawImage(img, 0, 0, null); + } + } + + // ------------------------------------------------------------------------------------------------ + + public ZoomPanel(final ZoomContent content) { + // Set up layout + this.setLayout(new GridBagLayout()); + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + + // Add content panel + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 0; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.fill = GridBagConstraints.BOTH; + this.add(content, gridBagConstraints); + + JScrollBar hScrollBar = new JScrollBar(Adjustable.HORIZONTAL); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 0.0; + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + //hScrollBar.addAdjustmentListener(scrollBarListener); + this.add(hScrollBar, gridBagConstraints); + + JScrollBar vScrollBar = new JScrollBar(Adjustable.VERTICAL); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.weightx = 0.0; + gridBagConstraints.weighty = 1.0; + gridBagConstraints.fill = GridBagConstraints.VERTICAL; + //vScrollBar.addAdjustmentListener(scrollBarListener); + this.add(vScrollBar, gridBagConstraints); + + // Create small spacer panel in corner between scrollbars + JPanel cornerPanel = new JPanel(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 1; + gridBagConstraints.fill = GridBagConstraints.BOTH; + gridBagConstraints.weightx = 0.0; + gridBagConstraints.weighty = 0.0; + this.add(cornerPanel, gridBagConstraints); + + // Add scrollbar refs to ZoomContent + content.addScrollBars(hScrollBar, vScrollBar); + + // Update scrollbar block increments when window size changes + content.addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent evt) { + content.resized(); + } + }); + } + + // ------------------------------------------------------------------------------------------------ + + /** Create new ZoomFrame. Calls System.exit(0) on window close. */ + public static class ZoomFrame extends JFrame { + protected ZoomContent content; + + @SuppressWarnings(""unused"") + private ZoomFrame() { + } + + public ZoomFrame(String title, int windowWidth, int windowHeight, final ZoomContent content) { + // Set window title + super(title); + + // Keep ref to content in case subclasses need it + this.content = content; + + // Exit on window close + this.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + + // Catch keystrokes + this.addKeyListener(new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + content.keyTyped(e); + } + }); + + this.setSize(windowWidth, windowHeight); + + // Add ZoomPanel to ZoomFrame, and add ZoomContent to ZoomPanel + this.add(new ZoomPanel(content)); + + this.setVisible(true); + } + } + + // ------------------------------------------------------------------------------------------------ + + // Demo usage + public static void main(String[] args) { + new ZoomFrame(""Zoom Panel"", 1024, 768, new ZoomContent(800, 600) { + int x = 100, y = 100; + + @Override + public void paintCanvas(Graphics2D g) { + g.fillOval(x, y, 50, 50); + } + + @Override + public void mousePressed(MouseEvent e, float[] coords) { + x = (int) coords[0] - 25; + y = (int) coords[1] - 25; + repaint(); + } + }); + } +} +" +A20164,"import java.io.*; +import java.util.*; + + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + Scanner sc = null; + PrintWriter fout = null; + int t = 0; + + try { + sc = new Scanner(new File(args[0])); + fout = new PrintWriter(new BufferedWriter(new FileWriter(""result.txt""))); + t = sc.nextInt(); + } catch(Exception e) { + System.out.println(e); + } + + for( int i = 0; i < t; i++ ) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] total = new int[n]; + + for( int j = 0; j < n; j++ ) { + total[j] = sc.nextInt(); + } + + int ret = 0; + for( int j = 0; j < n; j++ ) { + if( total[j] >= p * 3 - 2 * Math.min( p, 1 ) ) { + ret++; + } + else if( total[j] >= p * 3 - 2 * Math.min( p, 2 ) && s > 0 ) { + ret++; + s--; + } + } + //System.out.println(""Case #"" + (i+1) + "": "" + ret); + fout.println(""Case #"" + (i+1) + "": "" + ret); + } + + fout.close(); + sc.close(); + } + +} +" +A20180," +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + public void solve( Scanner sc, PrintWriter pw ) { + int tests = sc.nextInt( ); sc.nextLine( ); + for ( int i = 0 ; i < tests; i++ ) { + int googlers = sc.nextInt( ); + int suprises = sc.nextInt( ); + int minScore = sc.nextInt( ); + + int minimumNsFoundIn = (((3*minScore)-2) > 0 ) ? ((3*minScore)-2) : 0; + int minimumSFoundIn = (((3*minScore)-4) > 0 ) ? ((3*minScore)-4) : 2; + int out = 0; + + int[]scores = new int[googlers]; + for ( int j = 0 ; j < googlers; j++ ) { + scores[j] = sc.nextInt( ); + } + Arrays.sort( scores ); + for ( int j = 0 ; j < scores.length; j++ ) { + int score = scores[j]; + if ( score >= minimumNsFoundIn ) { + out++; + } else if ( suprises > 0 && score >= minimumSFoundIn ) { + out++; + suprises--; + } + } + pw.println( ""Case #"" + (i+1) + "": "" + out ); + pw.flush( ); + } + } + + public static void main ( String[] args ) throws IOException { + Scanner sc = new Scanner(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""B-large.out"")); + new B( ).solve( sc, pw ); + pw.close( ); + sc.close( ); + } + +// public final static HashMap NON_SUPRISING = new HashMap( ); +// public final static HashMap SUPRISING = new HashMap( ); +// static { +// //target = ( 3k-2 > 0 ) ? 3k-2 : 0; +// //0 = +// //0 = 0 +// //1 = 1 +// //2 = 4 +// //3 = 7 +// //4 = 10 +// //5 = 13 +// //6 = 16 +// //7 = 19 +// //8 = 22 +// //9 = 25 +// //10 = 28 +// NON_SUPRISING.put( 0, ""0 0 0"" ); +// NON_SUPRISING.put( 1, ""0 0 1"" ); +// NON_SUPRISING.put( 2, ""0 1 1"" ); +// NON_SUPRISING.put( 3, ""1 1 1"" ); +// NON_SUPRISING.put( 4, ""1 1 2"" ); +// NON_SUPRISING.put( 5, ""1 2 2"" ); +// NON_SUPRISING.put( 6, ""2 2 2"" ); +// NON_SUPRISING.put( 7, ""2 2 3"" ); +// NON_SUPRISING.put( 8, ""2 3 3"" ); +// NON_SUPRISING.put( 9, ""3 3 3"" ); +// NON_SUPRISING.put( 10, ""3 3 4"" ); +// NON_SUPRISING.put( 11, ""3 4 4"" ); +// NON_SUPRISING.put( 12, ""4 4 4"" ); +// NON_SUPRISING.put( 13, ""4 4 5"" ); +// NON_SUPRISING.put( 14, ""4 5 5"" ); +// NON_SUPRISING.put( 15, ""5 5 5"" ); +// NON_SUPRISING.put( 16, ""5 5 6"" ); +// NON_SUPRISING.put( 17, ""5 6 6"" ); +// NON_SUPRISING.put( 18, ""6 6 6"" ); +// NON_SUPRISING.put( 19, ""6 6 7"" ); +// NON_SUPRISING.put( 20, ""6 7 7"" ); +// NON_SUPRISING.put( 21, ""7 7 7"" ); +// NON_SUPRISING.put( 22, ""7 7 8"" ); +// NON_SUPRISING.put( 23, ""7 8 8"" ); +// NON_SUPRISING.put( 24, ""8 8 8"" ); +// NON_SUPRISING.put( 25, ""8 8 9"" ); +// NON_SUPRISING.put( 26, ""8 9 9"" ); +// NON_SUPRISING.put( 27, ""9 9 9"" ); +// NON_SUPRISING.put( 28, ""9 9 10"" ); +// NON_SUPRISING.put( 29, ""9 10 10"" ); +// NON_SUPRISING.put( 30, ""10 10 10"" ); +// +// //target = +// //target = (3k - 4) > 0 ? 3k - 4 : 2 +// //0 = 2 +// //1 = 2 +// //2 = 2 +// //3 = 5 +// //4 = 8 +// //5 = 11 +// //6 = 14 +// //7 = 17 +// //8 = 20 +// //9 = 23 +// //10 = 26 +// SUPRISING.put( 2, ""0 0 2"" ); +// SUPRISING.put( 3, ""0 1 2"" ); +// SUPRISING.put( 4, ""0 2 2"" ); +// SUPRISING.put( 5, ""1 1 3"" ); +// SUPRISING.put( 6, ""1 2 3"" ); +// SUPRISING.put( 7, ""1 3 3"" ); +// SUPRISING.put( 8, ""2 2 4"" ); +// SUPRISING.put( 9, ""2 3 4"" ); +// SUPRISING.put( 10, ""2 4 4"" ); +// SUPRISING.put( 11, ""3 3 5"" ); +// SUPRISING.put( 12, ""3 4 5"" ); +// SUPRISING.put( 13, ""3 5 5"" ); +// SUPRISING.put( 14, ""4 4 6"" ); +// SUPRISING.put( 15, ""4 5 6"" ); +// SUPRISING.put( 16, ""4 6 6"" ); +// SUPRISING.put( 17, ""5 5 7"" ); +// SUPRISING.put( 18, ""5 6 7"" ); +// SUPRISING.put( 19, ""5 7 7"" ); +// SUPRISING.put( 20, ""6 6 8"" ); +// SUPRISING.put( 21, ""6 7 8"" ); +// SUPRISING.put( 22, ""6 8 8"" ); +// SUPRISING.put( 23, ""7 7 9"" ); +// SUPRISING.put( 24, ""7 8 9"" ); +// SUPRISING.put( 25, ""7 9 9"" ); +// SUPRISING.put( 26, ""8 8 10"" ); +// SUPRISING.put( 27, ""8 9 10"" ); +// SUPRISING.put( 28, ""8 10 10"" ); +// } +}" +A22772,"package com.menzus.gcj._2012.qualification.b; + +import java.util.Iterator; + +import com.menzus.gcj.common.InputBlockParser; + +public class BInputBlockParser implements InputBlockParser { + @Override + public BInput parseLineIterator(Iterator lineIterator) { + String[] inputLineParts = lineIterator.next().split("" ""); + int googlersNumber = Integer.parseInt(inputLineParts[0]); + int surprisingTripletsNumber = Integer.parseInt(inputLineParts[1]); + int limit = Integer.parseInt(inputLineParts[2]); + int[] googlerScores = new int[googlersNumber]; + for (int i = 0; i < googlerScores.length; i++) { + googlerScores[i] = Integer.parseInt(inputLineParts[i + 3]); + } + BInput input = new BInput(); + input.setGooglerScores(googlerScores); + input.setLimit(limit); + input.setSurprisingTripletsNumber(surprisingTripletsNumber); + return input; + } +} +" +A20091,"package com.codejam2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class FileUtils { + + + public static String readFile(String fileName){ + FileReader reader = null; + String temp = null; + try { + reader = new FileReader(fileName); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + StringBuffer strContent = new StringBuffer(""""); + + try + { + + BufferedReader bufferedReader = new BufferedReader(reader); + temp =bufferedReader.readLine(); + while (temp != null) + { + strContent.append(temp + ""\n""); + temp =bufferedReader.readLine(); + } + + } + catch (Exception e) + { + System.out.println(e); + } + + return strContent.toString(); + } + + public static void appendToFile(String outputFileName, String dataToPrint) { + + File file =new File(outputFileName); + if(!file.exists()){ + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + FileWriter fileWritter; + try { + fileWritter = new FileWriter(outputFileName,true); + BufferedWriter bufferWritter = new BufferedWriter(fileWritter); + bufferWritter.write(dataToPrint); + bufferWritter.close(); + fileWritter.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + + + + } + + public static void deleteFile(String outputFileName) { + File file =new File(outputFileName); + if(file.exists()){ + file.delete(); + } + + } + + +} +" +A21608,"package com.google.codejam._2012; + +import java.io.File; +import java.util.Scanner; + +public class DancingWithGooglers +{ + + int[][] maxScores; + + + private void setup() + { + maxScores = new int[31][2]; + + for(int i = 0; i <= 30; i++) + maxScores[i][1] = -1; + + for(int score = 0; score <= 30; score++) + { + for(int s1 = 0; s1 <= 10; s1++) + for(int s2 = 0; s2 <= 10; s2++) + for(int s3 = 0; s3 <= 10; s3++) + { + if (s1 + s2 + s3 != score) + continue; + + if (s1 > s2 || s1 > s3 || s2 > s3) + continue; + + if (Math.abs(s1 - s2) > 2 || Math.abs(s1 - s3) > 2 || Math.abs(s2 - s3) > 2) + continue; + + if (Math.abs(s1 - s2) == 2 || Math.abs(s1 - s3) == 2 || Math.abs(s2 - s3) == 2) + maxScores[score][1] = s3; + else + maxScores[score][0] = s3; + } + } + + } + + + + public void solveCases() throws Exception + { + setup(); + + Scanner s = new Scanner(new File(""./input/B-large.in"")); + + + int t = s.nextInt(); + s.nextLine(); + + for(int i = 0; i < t; i++) + solveProblem(s, i + 1); + } + + + + + + private void solveProblem(Scanner s, int num) + { + System.out.print(""Case #"" + num + "": ""); + + int n = s.nextInt(); + int sur = s.nextInt(); + int p = s.nextInt(); + + int totSurprising = 0; + int totalBest = 0; + + for(int i = 0; i < n; i++) + { + int score = s.nextInt(); + + if (maxScores[score][0] >= p) + { + totalBest++; + continue; + } + + if (maxScores[score][1] != -1 && maxScores[score][1] >= p && totSurprising < sur) + { + totalBest++; + totSurprising++; + } + } + + + System.out.println(totalBest); + } + + + + + + public static void main(String[] args) + { + DancingWithGooglers dwg = new DancingWithGooglers(); + + try + { + dwg.solveCases(); + } + catch (Exception e) + { + e.printStackTrace(); + } + + } +} +" +A21230,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingGooglers +{ + public static void main(String[] args) + { + try + { + BufferedReader reader = new BufferedReader(new FileReader(args[0])); + FileWriter fileWriter = new FileWriter(args[1]); + + String casesNo = reader.readLine(); + + for (int t = 0; t < Integer.parseInt(casesNo); t++) + { + String[] params = reader.readLine().split("" ""); + + int y = 0; + int s = Integer.parseInt(params[1]); + int p = Integer.parseInt(params[2]); + + int normalLimit = (3 * p) - 2; + int suprisingLimit = normalLimit - 2; + + for (int n = 0; n < Integer.parseInt(params[0]); n++) + { + int ti = Integer.parseInt(params[n + 3]); + + if (ti >= normalLimit) + y++; + else if (suprisingLimit>0 && s>0 && ti >= suprisingLimit) + { + y++; + s--; + } + + +// int pi = ti%3 > 0 ? (ti/3)+1 : ti/3; +// +// if (pi >= p) +// y++; +// else if (ti > 1 && ti < 29 && s > 0 && pi + 1 == p) +// { +// y++; +// s--; +// } + } + fileWriter.write(""Case #"" + (t + 1) + "": "" + Integer.toString(y) + ""\n""); + } + + fileWriter.flush(); + fileWriter.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } +} +" +A21730,"import java.util.ArrayList; +import java.util.Scanner; + +public class GooglerDancing { + + /** + * @param args + */ + public static void main(String[] args) { + new GooglerDancing().run(); + + } + + public void run(){ + + int numDancers, targetScore, numSurprising, score, numWins; + ArrayList dancers; + Scanner input = new Scanner(System.in); + int numCases = input.nextInt(); + input.nextLine(); + int caseNum = 1; + + while(caseNum <= numCases){ + + numWins = 0; + dancers = new ArrayList(); + numDancers = input.nextInt(); + numSurprising = input.nextInt(); + targetScore = input.nextInt(); + for(int dancer = 0; dancer < numDancers; dancer++){ + score = input.nextInt(); + dancers.add(new Dancer(score)); + } + + for(Dancer d : dancers){ + if(d.DefiniteWin(targetScore)){ + numWins++; + } else if(d.score == 0 || d.DefiniteLoss(targetScore)){ + + // Do nothing + } else if (numSurprising > 0 && d.WinningSurprise(targetScore)){ + numWins++; + numSurprising--; + } + } + System.out.printf(""Case #%d: %d%n"", caseNum, numWins); + caseNum++; + } + } + +} + +class Dancer { + + public int score; + + public Dancer(int score){ + this.score = score; + } + + public boolean WinningSurprise(int targetScore){ + + int firstScore = score - targetScore; + int remainder = firstScore - (targetScore - 2); + if(remainder >= (targetScore - 2)){ + return true; + } + return false; + } + + public boolean DefiniteWin(int targetScore){ + int border = targetScore - 1; + double avg = score / 3.0; + if(avg > border){ + return true; + } + return false; + } + + public boolean DefiniteLoss(int targetScore){ + int border = targetScore - 2; + double avg = score / 3.0; + if(avg >= border){ + return false; + } + return true; + } + +} +" +A20367,"package B; + +import java.io.*; + +public class B { + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(""B.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B.out""))); + + int n = Integer.parseInt(in.readLine()); + for (int i = 0; i < n; ++ i) { + String st = in.readLine(); + String[] input = st.split("" ""); + + int T = Integer.parseInt(input[0]); + int S = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + + int ans = 0; + for (int j = 3; j < T + 3; ++ j) { + int t = Integer.parseInt(input[j]); + if (t / 3 >= p) + ++ ans; + else + if (t % 3 == 0) + if (t / 3 >= 1 && t / 3 + 1 >= p && S > 0) { + -- S; + ++ ans; + } + else {} + else + if (t % 3 == 1) + if (t / 3 + 1 >= p) + ++ ans; + else {} + else + if (t / 3 + 1 >= p) + ++ ans; + else + if (t / 3 + 2 >= p && S > 0) { + -- S; + ++ ans; + } + } + out.println(""Case #"" + (i + 1) + "": "" + ans); + } + + out.close(); + } + +} +" +A21005,"package fixjava; + +/** Adapted from http://www.johndcook.com/standard_deviation.html */ +public class RunningStats { + + int n = 0; + double oldM, newM, oldS, newS, min, max; + + public void clear() { + n = 0; + } + + public void add(double x) { + n++; + + // See Knuth TAOCP vol 2, 3rd edition, page 232 + if (n == 1) { + oldM = newM = min = max = x; + oldS = 0.0; + } else { + newM = oldM + (x - oldM) / n; + newS = oldS + (x - oldM) * (x - newM); + min = Math.min(min, x); + max = Math.max(max, x); + + // set up for next iteration + oldM = newM; + oldS = newS; + } + } + + public int numValues() { + return n; + } + + public double mean() { + return (n > 0) ? newM : 0.0; + } + + public double variance() { + return ((n > 1) ? newS / (n - 1) : 0.0); + } + + public double stdDev() { + return Math.sqrt(variance()); + } + + public double min() { + return (n > 0) ? min : 0.0; + } + + public double max() { + return (n > 0) ? max : 0.0; + } +} +" +A21481,"import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // BufferedReader read = new BufferedReader(new InputStreamReader( + // new FileInputStream( + // ""C:/Users/Ortiga/Downloads/B-small-attempt0.in""))); + + BufferedWriter write = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream( + ""C:/Users/Ortiga/Downloads/outputBlarg.txt""))); + Scanner sc = new Scanner(new InputStreamReader(new FileInputStream( + ""C:/Users/Ortiga/Downloads/B-large.in""))); + byte length = sc.nextByte(); + for (byte i = 0; i < length; i++) { + byte t = sc.nextByte(), s = sc.nextByte(), p = sc.nextByte(), max = 0, getDuringSurp = 0; + String rit = ""Case #"" + (i + 1) + "": ""; + byte[] t_i = new byte[t]; + for (byte j = 0; j < t; j++) + t_i[j] = sc.nextByte(); + Arrays.sort(t_i); + int sCounter = 0; + for (byte j = 0; j < t; j++) { + byte currT_i = t_i[j]; + if (currT_i == 0 && p > 0) + continue; + if (sCounter < s) { + if ((currT_i - 2) % 3 == 0) { + if ((((currT_i - 2) / 3) + 2 >= p)) { + max++; + getDuringSurp++; + } + sCounter++; + continue; + } else if ((currT_i - 3) % 3 == 0) { + if ((((currT_i - 3) / 3) + 2 >= p)) { + max++; + getDuringSurp++; + } + sCounter++; + continue; + } + } + if ((currT_i - 1) % 3 == 0) { + if ((((currT_i - 1) / 3) + 1 >= p)) + max++; + else if (currT_i + 4 / 3 >= p && getDuringSurp < sCounter) { + sCounter--; + j--; + } + } else if ((currT_i - 2) % 3 == 0) { + if ((((currT_i - 2) / 3) + 1 >= p)) + max++; + else if (currT_i + 4 / 3 >= p && getDuringSurp < sCounter) { + sCounter--; + j--; + } + } else { + if (currT_i / 3 >= p) + max++; + else if (currT_i + 4 / 3 >= p && getDuringSurp < sCounter) { + sCounter--; + j--; + } + } + } + rit += max; + write.write(rit); + if (i < length - 1) + write.newLine(); + } + sc.close(); + write.close(); + } +} +" +A21777,"import java.io.*; +import java.math.*; +import java.util.*; + +class Main{ + + static BufferedReader br; + static PrintWriter pw; + static File in; + static File out; + static String name=""B-large""; + + + public static void main(String[] args){ + try{ + in=new File(name+"".in""); + out=new File(name+"".out""); + br=new BufferedReader(new FileReader(in)); + pw=new PrintWriter(new BufferedWriter(new FileWriter(out))); + + int nbCase = Integer.parseInt(br.readLine()); + + + for (int n=1;n<=nbCase;n++){ + String line=br.readLine(); + + int googlers=Integer.parseInt(line.substring(0,line.indexOf("" ""))); + line=line.substring(line.indexOf("" "")+1); + + int surprise=Integer.parseInt(line.substring(0,line.indexOf("" ""))); + line=line.substring(line.indexOf("" "")+1); + + int min=Integer.parseInt(line.substring(0,line.indexOf("" ""))); + line=line.substring(line.indexOf("" "")+1); + + int scoreSurprise=min+Math.max(0,min-2)*2; + int score=min+Math.max(0,min-1)*2; + + int count=0; + for (int i=0;i=score) count++; + else{ + if (surprise!=0){ + if (point>=scoreSurprise){ + surprise--; + count++; + } + } + } + } + + pw.println(""Case #""+n+"": ""+count); + } + + + pw.flush(); + pw.close(); + br.close(); + }catch(Exception e){ + e.printStackTrace(); + } + } + + + + +} +" +A22612,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +public class Puzzle2 { + + + public static int countGooglersByTarget(int target, int numberOfSurprising, List googlerScores) { + int count = 0; + + int totalTarget = 3*target; + + for (int i = 0; i < googlerScores.size(); i++) { + int totalGooglerSum = googlerScores.get(i); + if(totalGooglerSum >= totalTarget -2) { + count ++; + } else if(totalGooglerSum >0 && totalGooglerSum +2 >= totalTarget -2 && numberOfSurprising >0) { + count ++; + numberOfSurprising--; + } + } + + return count; + } + + public static void main(String[] args) { + + String input = ""100\n"" + + ""6 2 8 29 20 8 18 18 21\n"" + + ""57 12 6 14 14 26 14 20 14 15 15 14 20 20 17 18 13 8 3 11 24 29 15 14 10 15 27 25 30 15 14 25 14 0 3 29 24 14 15 23 17 14 10 14 27 2 14 14 14 15 14 15 14 18 0 16 15 29 14 7\n"" + + ""40 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n"" + + ""50 1 7 17 18 17 17 17 18 17 17 18 17 18 18 20 18 18 20 17 18 17 17 2 17 18 28 17 18 17 18 17 18 17 19 18 3 17 17 14 18 17 17 28 24 20 7 18 22 16 17 18 14\n"" + + ""40 31 6 2 23 26 1 13 2 27 10 2 11 10 10 24 10 1 30 14 5 29 22 8 3 12 21 2 12 28 3 13 23 10 24 13 20 1 7 6 2 16 26\n"" + + ""79 8 6 5 17 15 30 22 14 0 20 28 18 14 14 30 18 6 14 14 15 14 14 29 15 20 22 6 11 14 15 15 14 15 14 19 14 14 15 15 14 14 24 30 11 20 28 14 14 15 26 14 14 14 25 9 14 14 3 8 15 15 14 15 21 6 14 15 2 7 9 13 30 7 15 4 27 15 8 17 6 11\n"" + + ""17 3 1 23 15 14 3 26 4 18 16 29 6 16 9 27 17 27 6 30\n"" + + ""55 55 1 16 20 21 17 17 6 12 12 26 24 24 16 24 12 5 28 21 27 24 14 8 12 24 7 6 19 17 18 14 24 22 21 10 3 19 8 14 14 14 5 18 6 10 17 2 7 2 2 17 2 28 12 26 6 23\n"" + + ""99 21 10 9 2 11 27 7 14 11 2 0 21 14 13 17 9 16 11 10 6 19 14 13 3 14 20 28 19 2 21 22 15 2 5 25 21 25 29 21 28 4 25 19 24 6 10 1 17 20 3 9 4 27 1 20 29 26 21 17 14 30 29 6 10 9 28 10 28 12 13 0 17 21 17 29 21 17 26 10 27 13 8 7 4 12 15 22 19 18 18 4 18 12 3 12 17 7 4 16 15 3\n"" + + ""34 0 8 5 18 1 5 14 6 18 27 13 21 10 26 9 28 4 23 17 26 30 0 18 14 1 12 16 26 18 8 1 5 12 4 16 11\n"" + + ""49 13 4 9 8 8 8 9 8 10 9 12 10 4 0 9 16 0 9 9 2 12 2 30 9 9 8 9 2 13 19 8 8 27 9 7 2 8 5 25 4 8 8 14 6 9 13 4 8 8 20 14\n"" + + ""60 60 6 7 15 27 16 23 9 13 2 9 19 26 12 24 20 27 5 27 2 19 26 26 2 12 12 2 20 9 20 13 28 7 14 18 6 28 19 19 18 15 23 2 27 25 23 7 13 10 6 17 6 18 14 19 19 3 24 20 16 9 19\n"" + + ""61 46 5 4 1 4 26 6 19 1 7 16 23 18 0 28 28 10 14 20 7 14 26 9 13 13 23 7 16 6 17 15 16 28 20 9 5 1 16 11 13 23 23 1 4 5 29 0 28 8 0 7 16 21 25 10 6 16 1 4 25 16 21 27\n"" + + ""31 12 2 21 22 3 24 3 13 5 1 30 13 2 3 4 2 3 3 10 2 2 3 2 18 2 15 3 2 20 9 25 11 3\n"" + + ""2 2 3 7 25\n"" + + ""14 1 2 3 0 0 14 3 3 2 30 27 3 3 24 12 13\n"" + + ""97 68 0 30 9 5 26 4 19 25 3 14 29 0 0 14 24 25 11 28 2 15 16 20 14 13 18 26 21 11 13 30 3 2 16 11 3 27 7 20 22 15 12 4 8 3 0 5 11 19 4 8 14 17 11 12 18 7 1 17 4 18 12 5 30 28 8 11 23 13 20 5 4 14 24 23 7 0 8 21 23 24 11 19 25 30 10 7 27 9 0 6 3 0 9 8 27 6 19 29\n"" + + ""55 1 5 12 11 12 12 12 12 11 12 12 1 12 11 12 12 12 11 8 22 11 26 11 23 30 19 24 12 24 12 7 11 12 6 26 12 11 11 14 12 12 14 18 11 11 8 19 3 12 11 5 12 26 11 11 5 11\n"" + + ""64 10 1 29 27 3 26 10 18 12 14 3 5 25 8 25 5 19 24 0 24 27 18 5 8 1 18 18 14 11 12 4 17 0 4 4 29 17 3 27 24 23 23 3 23 23 12 21 18 23 7 21 19 28 0 17 6 4 1 14 27 20 2 4 18 6 26\n"" + + ""55 10 6 14 24 14 15 14 10 14 27 15 14 30 15 12 23 15 14 23 15 8 14 6 15 15 25 5 19 25 15 23 15 1 30 14 11 19 3 14 14 27 15 5 15 21 22 14 15 15 15 25 14 14 15 2 15 14\n"" + + ""92 92 5 5 21 7 4 10 12 17 16 6 6 8 14 16 21 10 11 5 21 11 21 14 5 18 28 17 9 12 15 3 16 2 3 20 7 8 4 27 5 25 20 23 6 12 6 11 2 16 2 12 23 27 25 10 9 27 15 18 7 22 5 3 15 11 26 21 7 16 5 8 24 20 13 8 3 4 4 9 11 13 28 19 14 20 4 23 25 22 16 28 2 13 4\n"" + + ""80 80 5 18 5 11 28 18 16 7 7 15 15 15 13 4 9 23 7 16 8 23 18 6 23 14 12 11 25 25 22 13 11 20 23 18 13 6 25 18 15 10 14 23 27 28 17 24 20 11 14 7 14 11 4 19 25 28 21 5 2 23 13 16 6 4 11 27 21 27 5 3 3 15 23 18 11 4 16 7 22 9 15\n"" + + ""81 0 10 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n"" + + ""64 16 8 20 21 11 6 21 20 20 4 21 20 21 22 17 18 21 26 19 21 1 21 2 21 20 25 21 25 18 21 21 20 27 20 21 28 4 7 17 20 21 22 21 14 14 16 21 21 20 21 21 19 16 16 21 20 21 15 20 20 21 21 4 21 20 7\n"" + + ""29 29 9 27 5 13 10 12 5 4 19 18 14 12 3 4 6 5 13 9 24 18 5 13 7 25 4 17 8 5 5 26\n"" + + ""59 5 9 10 22 9 24 29 3 24 23 23 8 23 23 7 0 25 22 23 24 23 24 18 23 20 17 23 25 23 23 23 1 30 20 24 23 24 20 24 23 17 23 25 10 7 1 7 23 19 24 23 23 4 13 15 24 23 24 9 24 24\n"" + + ""31 20 0 4 29 10 15 7 7 18 28 9 23 9 5 28 6 25 22 24 6 26 5 1 13 22 6 24 4 19 8 13 18 0\n"" + + ""72 10 0 19 8 20 24 19 29 5 11 14 15 25 8 6 17 7 29 2 22 13 1 0 25 17 14 7 12 24 30 1 28 1 27 16 22 1 27 8 22 10 12 17 11 6 27 7 11 30 29 22 24 21 21 3 5 9 13 1 3 11 16 8 17 23 11 9 29 30 29 10 24 14 29\n"" + + ""89 41 8 26 9 18 10 15 9 9 12 4 19 20 1 24 17 15 6 26 13 15 11 8 0 30 14 29 12 5 20 26 17 26 15 0 18 29 2 13 17 6 24 1 16 11 17 25 26 29 2 10 5 4 22 19 16 10 13 8 12 25 1 26 18 19 30 8 26 22 1 3 16 9 20 1 1 15 28 7 11 25 17 2 17 2 18 24 6 12 6 2\n"" + + ""5 0 2 24 9 14 13 29\n"" + + ""63 16 4 19 6 20 11 27 23 18 30 1 29 0 0 3 27 25 28 8 7 21 17 22 21 25 23 26 8 0 21 28 11 10 28 9 6 21 17 28 27 12 7 13 27 14 18 7 29 7 17 29 2 16 0 4 15 7 5 6 13 21 27 30 20 18\n"" + + ""48 6 10 27 30 27 27 16 27 26 1 7 27 27 24 3 12 26 13 26 24 26 18 13 13 16 26 2 26 27 28 26 18 26 27 27 26 22 9 27 27 0 27 27 27 26 27 26 16 6 27\n"" + + ""74 16 2 2 3 3 3 3 3 2 3 3 3 20 2 22 11 3 3 3 3 26 3 3 3 3 3 2 2 3 2 2 6 3 3 2 29 18 2 2 14 3 26 2 3 22 3 2 2 26 26 3 1 30 3 2 6 26 3 10 3 3 30 2 2 6 8 2 2 3 4 2 2 3 9 23 3\n"" + + ""66 38 1 9 16 6 7 9 10 5 20 3 15 8 2 23 9 3 7 23 19 25 6 13 9 28 26 11 28 5 4 21 20 18 4 4 27 2 5 30 21 7 10 30 30 1 12 28 6 15 15 30 6 15 6 20 3 27 14 13 27 13 20 7 4 15 17 17 18\n"" + + ""16 9 0 25 2 26 4 26 8 23 30 28 23 14 11 20 19 9 11\n"" + + ""66 8 5 2 12 11 12 12 21 22 11 13 18 7 8 12 12 22 14 11 11 11 8 29 14 22 20 12 12 9 13 12 28 23 11 12 12 18 12 12 27 19 11 12 6 25 11 11 11 16 15 11 19 12 0 12 19 13 2 20 12 19 2 11 11 19 28 1 12\n"" + + ""61 60 1 8 13 24 4 10 22 22 12 12 23 17 15 3 23 18 12 6 8 19 6 22 13 15 19 23 17 3 11 9 9 5 22 26 16 15 24 11 19 11 5 9 9 13 13 25 17 11 24 6 0 18 16 22 21 6 23 15 10 10 2 17\n"" + + ""4 4 3 6 20 7 19\n"" + + ""30 21 9 19 1 19 12 5 27 14 9 14 13 5 17 25 12 16 29 20 14 28 16 17 21 19 5 30 24 8 11 3 14\n"" + + ""4 2 7 15 4 7 19\n"" + + ""57 36 4 17 25 2 22 3 21 27 30 16 5 20 29 1 22 19 29 17 0 29 4 26 16 18 22 24 23 29 8 27 20 7 12 1 4 2 24 17 21 1 20 23 20 1 16 11 6 11 16 3 23 27 8 25 22 26 25 10\n"" + + ""25 11 2 2 21 2 20 3 26 3 3 0 2 3 12 23 2 3 2 7 2 3 2 26 25 3 2 3\n"" + + ""21 5 4 27 19 3 23 29 3 0 13 4 16 29 22 13 13 27 3 25 29 27 16 21\n"" + + ""87 25 4 24 13 23 8 22 30 18 11 2 17 23 15 0 21 23 4 7 20 17 12 9 7 14 7 14 17 19 3 15 17 11 20 17 23 4 3 1 24 17 12 18 11 28 17 2 26 16 8 4 1 5 3 2 15 6 17 30 16 9 3 20 17 12 16 6 10 22 2 10 5 23 10 8 0 10 29 17 14 4 9 10 9 15 21 0 30 28\n"" + + ""92 26 0 5 1 9 25 5 22 30 3 23 12 12 12 6 10 11 0 21 5 28 6 18 20 22 28 23 22 10 26 25 30 19 10 23 29 22 11 10 6 12 21 16 7 8 28 17 19 18 19 26 25 30 25 3 18 13 24 12 28 15 12 17 16 3 13 9 28 8 12 0 26 22 9 17 17 10 11 22 9 15 25 19 25 18 16 5 6 22 8 22 29 7 19\n"" + + ""54 35 10 29 18 8 0 3 20 16 20 6 14 15 12 8 15 13 7 15 13 7 28 2 9 17 3 0 12 27 6 23 4 0 4 2 4 11 6 21 24 2 8 2 4 22 8 15 10 21 23 16 29 13 19 15 3\n"" + + ""35 6 2 3 16 3 1 3 3 2 4 13 3 3 3 17 3 27 13 2 3 2 3 29 3 6 3 3 8 18 26 11 17 15 27 8 2 20\n"" + + ""50 11 6 2 14 14 15 14 15 22 14 14 14 14 15 10 15 15 8 9 6 26 15 14 15 14 20 15 10 18 15 11 14 1 14 29 14 14 30 6 10 6 18 6 15 30 14 15 14 15 26 19 15\n"" + + ""54 37 5 30 14 2 25 10 10 9 0 10 29 9 5 7 14 22 28 27 20 17 8 16 4 12 3 17 29 19 19 6 15 19 22 17 20 14 7 29 10 2 17 5 29 9 28 23 0 2 7 20 11 5 16 17 22\n"" + + ""92 63 2 16 23 30 15 21 5 28 8 28 18 4 21 21 7 25 30 9 19 13 7 8 15 9 5 22 26 22 16 18 29 18 23 11 7 18 6 11 3 14 1 29 2 4 4 24 19 2 28 26 0 13 27 12 17 22 0 12 15 21 22 6 20 11 4 20 16 1 23 24 3 1 4 30 21 12 23 19 15 16 25 17 23 8 19 8 16 2 13 4 22 25 16\n"" + + ""66 35 4 30 9 8 9 9 8 24 9 8 2 27 18 15 8 27 18 8 9 27 19 13 8 8 8 27 12 8 5 9 9 9 16 21 9 8 8 6 9 10 0 28 8 8 5 8 8 9 14 9 1 8 8 8 9 9 15 8 9 8 8 1 8 8 18 3 8\n"" + + ""64 24 2 22 9 7 2 28 3 3 3 14 28 2 29 3 4 6 3 3 3 2 23 30 3 3 3 2 14 2 13 5 30 2 3 10 3 2 2 13 3 21 3 20 3 10 13 3 3 8 3 26 3 3 29 2 5 24 3 3 2 8 3 5 3 27 3\n"" + + ""65 41 5 0 8 21 1 19 27 21 27 0 15 28 29 25 15 15 4 17 20 27 29 15 17 21 16 18 14 23 24 20 22 15 13 10 27 10 15 27 8 4 0 17 24 18 0 30 17 29 24 15 17 14 2 21 0 4 16 13 22 24 12 12 1 6 13 14\n"" + + ""38 12 6 13 9 19 26 15 18 28 2 1 7 4 4 30 10 13 27 17 23 0 22 4 30 17 22 17 27 26 24 6 13 29 9 30 11 5 9 22 0\n"" + + ""54 4 1 15 12 11 0 28 22 24 14 30 26 25 1 10 23 21 16 24 6 13 12 1 24 2 17 22 27 18 14 3 4 13 23 7 23 22 30 12 19 14 10 2 13 5 2 12 27 17 21 22 20 23 4 13 25\n"" + + ""5 1 5 12 8 11 5 23\n"" + + ""69 23 10 13 10 0 7 19 16 23 16 1 2 17 23 8 23 1 28 3 0 24 13 23 20 28 30 30 26 9 27 10 13 27 6 6 30 19 13 9 22 16 0 10 12 17 24 15 3 24 15 20 3 17 2 28 15 11 15 25 5 21 19 0 0 18 13 5 9 24 20 14\n"" + + ""95 32 5 6 12 18 25 11 12 21 12 11 13 11 24 23 10 30 21 2 12 0 11 11 12 12 11 28 12 29 4 26 12 0 11 25 24 12 12 22 12 6 6 12 28 6 28 12 12 21 11 12 19 11 11 11 12 7 11 11 8 16 11 11 11 11 15 18 12 12 3 2 2 11 12 24 11 6 11 3 11 11 12 12 12 12 11 12 14 1 14 30 12 11 2 11 28 29\n"" + + ""79 42 5 20 3 13 1 5 21 4 0 25 25 19 23 24 18 26 7 24 15 8 0 3 5 7 13 30 18 5 16 28 11 25 16 16 28 8 5 18 23 1 29 7 0 14 7 10 14 12 26 17 11 23 21 11 19 30 5 21 18 9 1 30 4 11 18 25 10 11 27 17 27 11 20 24 20 29 10 11 8 20\n"" + + ""8 5 2 0 6 26 20 27 6 15 29\n"" + + ""80 80 4 28 28 4 10 28 26 4 3 17 24 7 11 15 3 27 6 26 22 8 2 4 25 7 9 17 24 25 12 8 17 20 12 20 12 16 19 2 22 16 14 16 26 15 21 17 27 20 12 9 17 3 26 28 27 4 11 25 8 24 3 15 15 15 17 21 8 23 6 15 3 21 7 6 2 11 21 9 10 18 16\n"" + + ""72 58 9 30 0 27 26 13 2 10 14 25 6 23 13 23 5 18 26 27 1 16 4 18 7 8 13 25 12 11 23 5 16 5 5 30 13 24 22 22 14 15 28 11 21 3 12 19 8 21 21 23 13 30 5 11 29 16 12 28 23 28 8 10 26 21 15 16 22 22 13 30 30 28 9\n"" + + ""72 5 3 24 27 19 5 5 7 6 28 6 26 8 5 5 23 6 25 10 29 7 5 25 15 5 5 5 6 5 5 5 5 5 5 5 5 6 6 29 6 22 5 29 6 25 9 12 6 6 6 6 30 5 12 6 16 5 6 5 0 14 5 5 6 1 5 1 8 5 14 12 6 4 27\n"" + + ""41 41 5 28 7 25 27 27 24 19 26 20 14 9 9 27 6 16 20 26 10 19 26 20 14 18 19 16 27 24 22 21 5 5 10 10 10 2 10 17 5 13 7 17\n"" + + ""33 0 2 0 14 12 16 29 11 23 2 30 29 28 16 15 3 18 17 11 20 24 17 23 7 12 26 2 22 13 2 7 19 21 18 11\n"" + + ""82 82 4 5 22 2 28 6 6 25 28 10 13 25 4 26 2 14 17 19 14 16 24 19 27 8 27 15 5 11 14 28 28 27 5 9 15 3 7 22 12 27 24 25 18 4 23 28 13 26 19 19 18 10 11 3 17 13 2 14 22 8 16 11 2 22 26 27 6 4 26 13 13 9 13 18 24 17 16 16 2 27 6 10 19\n"" + + ""34 0 7 6 8 10 12 26 21 14 21 15 25 29 5 20 22 17 7 9 14 4 30 25 11 17 28 0 28 1 19 3 13 20 25 7 16\n"" + + ""100 33 0 16 27 2 27 28 20 1 7 11 7 14 25 4 10 20 28 13 27 26 23 17 27 21 1 2 7 23 11 12 12 7 11 18 29 17 3 27 28 11 28 24 26 20 28 18 2 23 13 18 25 29 24 0 25 21 8 0 20 16 10 23 15 2 1 22 23 6 1 26 22 10 20 13 26 22 30 16 15 16 11 7 28 29 13 8 22 28 17 5 7 12 22 10 20 30 26 23 24 5 7\n"" + + ""17 0 8 21 20 21 20 21 20 20 21 21 20 20 20 20 13 29 11 21\n"" + + ""58 0 4 3 1 19 28 19 6 5 19 24 13 7 12 2 29 24 10 6 28 19 3 10 0 16 29 1 4 12 5 11 10 14 8 22 20 1 5 14 3 0 0 12 6 5 14 13 12 3 23 13 4 15 13 20 1 23 9 21 2\n"" + + ""8 6 8 22 18 14 29 10 17 16 13\n"" + + ""18 8 8 27 6 18 21 26 27 6 21 20 20 20 20 20 4 21 21 16 20\n"" + + ""38 0 7 17 16 25 16 23 22 26 26 28 22 18 27 17 17 12 14 25 22 12 8 28 4 15 24 11 15 6 12 17 29 18 9 27 15 4 2 0 9\n"" + + ""97 0 7 11 20 2 13 7 30 30 21 8 20 0 5 11 24 4 27 29 30 25 7 21 15 2 8 26 22 17 17 1 24 9 20 24 10 14 10 4 29 18 19 25 4 13 7 16 16 11 22 17 4 16 25 3 22 10 15 5 27 25 10 18 21 11 23 21 24 16 10 15 15 22 7 5 1 10 3 25 17 29 15 11 26 2 2 8 15 7 23 27 16 24 19 6 24 18 1 15\n"" + + ""77 0 1 12 17 27 13 9 19 9 3 11 8 18 19 4 28 26 1 7 15 0 6 11 3 7 1 4 16 25 19 1 7 11 9 26 6 6 3 23 30 4 7 28 20 22 5 19 9 25 15 23 7 29 20 7 29 27 30 23 18 17 17 1 28 0 21 24 17 0 9 17 25 1 13 1 29 10 25 24\n"" + + ""88 64 8 17 1 3 1 3 1 9 26 27 3 3 9 30 10 23 10 15 26 7 7 21 22 0 4 29 0 16 8 28 1 9 7 3 23 25 17 7 30 23 30 11 15 1 1 7 0 26 14 11 3 20 8 12 24 24 0 13 27 27 12 1 6 3 18 12 26 6 15 30 15 2 25 19 3 11 16 9 2 8 22 16 26 10 0 9 23 23 2\n"" + + ""68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"" + + ""70 23 4 13 30 2 9 30 9 22 9 8 8 14 27 8 13 9 8 8 28 22 8 0 8 8 18 9 18 9 8 9 22 8 20 8 30 8 19 8 9 20 8 9 2 15 9 7 14 17 17 25 8 9 13 18 9 9 9 8 24 8 8 6 7 3 9 9 8 10 4 8 9\n"" + + ""48 15 1 3 1 12 7 4 5 27 30 8 5 11 8 10 20 14 25 28 13 20 1 14 25 11 30 12 4 14 27 4 9 0 22 30 4 19 0 24 11 8 3 1 12 30 17 20 2 23 12\n"" + + ""84 84 10 12 23 12 20 28 6 16 5 28 21 13 13 15 14 25 17 23 28 12 13 27 15 14 7 5 15 16 5 13 17 23 10 23 12 9 6 21 3 21 6 17 17 15 2 27 5 19 12 10 18 15 20 2 25 15 10 9 5 13 13 18 9 19 9 2 14 6 26 22 10 25 4 27 28 16 13 6 6 27 23 12 17 10 23\n"" + + ""78 78 1 10 3 4 10 3 2 8 3 11 15 12 19 9 28 4 7 22 19 16 26 18 12 16 26 21 4 23 20 18 26 20 16 23 7 17 14 13 26 9 13 19 26 15 13 26 25 26 23 23 9 28 8 28 16 18 23 17 11 8 28 20 4 13 10 6 5 27 17 11 26 6 21 10 28 13 7 8 11\n"" + + ""26 26 7 4 6 9 15 4 21 18 6 4 3 10 15 7 3 13 8 10 21 11 12 10 4 16 3 11 6\n"" + + ""95 0 6 4 5 30 28 18 26 13 15 20 14 18 16 21 6 29 17 1 0 9 25 11 30 28 27 5 27 8 15 1 17 11 28 20 5 2 27 6 24 13 28 13 21 23 14 13 30 9 12 26 13 15 12 29 28 24 26 3 27 15 20 3 18 2 22 23 16 3 23 14 24 18 0 8 0 26 2 14 26 15 19 28 26 0 22 25 19 13 28 27 5 21 30 22 18 13\n"" + + ""39 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"" + + ""65 6 2 2 2 11 3 3 2 2 2 22 16 23 6 2 23 2 3 2 2 2 25 14 3 21 2 3 28 2 2 21 3 30 2 2 4 2 10 20 2 28 11 15 3 14 9 14 3 6 3 2 12 3 2 6 2 20 17 2 2 1 3 9 3 12 14 3\n"" + + ""12 1 7 18 18 15 17 17 18 17 13 17 17 15 17\n"" + + ""55 34 6 3 27 20 27 14 15 14 22 5 5 1 12 30 12 20 19 6 6 20 21 11 28 0 23 8 28 11 27 19 26 13 1 19 0 9 14 17 12 2 4 13 11 29 25 0 23 22 9 24 27 16 26 10 17 14\n"" + + ""32 8 6 14 15 18 2 14 14 26 14 18 8 23 13 9 26 7 15 15 15 15 15 15 14 24 14 17 14 16 14 27 15 14 21\n"" + + ""1 0 9 17\n"" + + ""51 8 8 30 15 7 26 0 5 1 20 5 10 5 18 14 1 27 29 20 13 23 25 7 11 18 6 9 19 14 18 14 28 18 20 3 18 20 20 6 5 21 17 24 28 27 17 14 15 7 3 15 22 25\n"" + + ""82 0 0 6 0 18 22 5 19 0 28 3 11 6 23 15 9 19 24 3 29 25 0 4 3 19 29 24 6 21 2 14 23 5 6 15 23 3 24 13 4 4 17 30 25 12 7 9 27 11 10 2 8 0 21 29 25 21 3 0 20 15 4 2 14 15 1 9 24 1 9 13 30 23 22 14 11 21 5 1 25 4 7 27 15\n"" + + ""93 4 3 18 5 0 5 22 19 6 17 5 6 5 5 15 6 6 6 26 6 9 6 12 6 5 6 6 25 5 14 5 30 5 5 21 28 19 26 6 5 5 5 21 6 5 23 10 6 5 5 17 16 5 11 6 5 6 25 14 23 5 2 6 6 6 6 6 11 13 6 6 5 23 5 5 5 5 5 6 5 21 6 6 6 5 9 21 8 6 21 2 18 5 6 27\n"" + + ""98 11 8 24 1 3 13 17 1 15 2 0 30 2 13 12 5 12 6 17 10 19 30 1 2 19 24 5 21 26 26 26 1 2 10 9 19 7 17 19 20 18 4 3 13 12 30 8 27 22 26 16 17 30 11 9 7 16 27 0 18 22 22 19 2 10 24 30 28 27 30 24 14 11 21 19 0 3 1 3 14 18 19 26 10 14 29 8 11 23 9 28 23 16 29 16 3 7 22 17 14\n"" + + ""9 9 3 16 5 2 20 13 27 12 10 14\n"" + + ""49 8 10 21 2 19 26 26 30 18 21 27 11 5 17 1 26 22 27 22 2 27 27 26 10 29 11 16 26 27 12 23 27 21 27 27 27 27 13 17 15 27 2 13 27 26 2 9 26 27 21 26\n"" + + ""43 24 3 26 25 19 28 11 10 15 25 20 17 24 4 8 26 0 23 12 10 29 12 6 14 6 21 6 19 19 27 30 5 24 10 13 12 23 21 16 30 13 20 15 11 11\n"" + + ""21 2 2 2 14 18 12 2 3 3 3 2 3 3 1 29 0 14 7 2 3 10 21 3\n"" + + ""22 2 2 2 2 2 19 2 28 10 14 3 2 8 3 23 3 14 2 2 3 2 17 2 20\n"" + + ""1 1 3 13\n"" + + ""64 16 3 6 5 5 7 13 6 20 22 7 17 6 30 6 16 5 19 5 6 6 25 23 6 18 5 11 3 6 6 8 5 22 5 6 5 20 10 29 30 6 5 5 27 22 29 5 5 27 5 0 30 16 18 28 7 14 8 6 10 5 16 18 25 13 5\n""; + + System.out.println(executeTestCase(input)); + + + + } + + private static String executeTestCase(String input) { + + String strOutput = """"; + BufferedReader in = new BufferedReader(new StringReader(input)); + int testCases = 0; + try { + testCases = Integer.valueOf(in.readLine()); + } catch (IOException e) { + return ""Invalid test case input at line 1""; + } + + try { + if (testCases > 0) { + for (int i = 1; i <= testCases; i++) { + String lines[] = in.readLine().split("" ""); + int numberOfGooglers = Integer.valueOf(lines[0]); + int numberOfSurprising = Integer.valueOf(lines[1]); + int target = Integer.valueOf(lines[2]); + List lst = new ArrayList(); + if(numberOfGooglers > 0) { + for(int j=0; j< numberOfGooglers; j++) { + lst.add(Integer.valueOf(lines[j+3])); + } + } + strOutput+=""Case #"" + i + "": "" + countGooglersByTarget(target, numberOfSurprising, lst) + ""\n""; + } + } + } catch (Exception e) { + return ""Invalid test case input""; + } + + return strOutput.toString(); + + } + +} +" +A22390,"import java.io.File; +import java.lang.StringBuilder; +import java.util.Scanner; +import java.io.FileWriter; +import java.util.ArrayList; +import java.lang.Math; +import java.util.Collections; + +public class DWTG { + + public static void main(String[] args) throws Exception{ + File input = new File(""B-large.in""); + File output = new File(""output.out""); + FileWriter fw = new FileWriter(output); + Scanner s = new Scanner(input); + + int numloops = s.nextInt(); + StringBuilder sb = new StringBuilder(); + + for(int n=0; n al = new ArrayList(); + + for(int i=0; i= minscore){ + //System.out.println(""Added ""+Math.ceil(((float)curnum)/3)+"" ""+minscore); + maxwithscore++; + continue; + } + + if(curnum == 0) + continue; + + if((int) Math.ceil(((float)curnum)/3) == curnum/3){ + al.add( (int) Math.ceil(((float)curnum)/3) +1); + //System.out.println((int) Math.ceil(((float)curnum)/3) +1); + } else{ + al.add( (int) Math.ceil(((float)curnum)/3)); + //System.out.println( Math.ceil(((float)curnum)/3)); + } + } + + Collections.sort(al); + Collections.reverse(al); + + int i=numSurprises; + + while(i>0 && !al.isEmpty()){ + int curnum = al.get(0); + + curnum++; + + //System.out.println(curnum + "" "" +minscore); + + if(curnum >= minscore){ + maxwithscore++; + } + + al.remove(0); + i--; + } + + sb.append(maxwithscore + ""\n""); + } + + fw.write(sb.toString()); + //System.out.println(sb.toString()); + fw.close(); + } +} +" +A22372,"package Solutions; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; + +public class problemB { + public static void main(String[] args) throws IOException { + + BufferedReader in = new BufferedReader(new FileReader(new File(""smallB.in""))); + BufferedWriter out = new BufferedWriter(new FileWriter(new File(""outputB.txt""))); + + int numCases = Integer.parseInt(in.readLine()); + for (int i = 0; i < numCases; i++) { + String google = in.readLine(); + String output = ""Case #"" + (i + 1) + "": ""; + + String[] googlers = google.split("" ""); + int numGooglers = Integer.valueOf(googlers[0]); + int numSurprising = Integer.valueOf(googlers[1]); + int best = Integer.valueOf(googlers[2]); + + ArrayList scores = new ArrayList(numGooglers); + for (int j = 3; j < googlers.length; j++) { + scores.add(Integer.valueOf(googlers[j])); + } + Collections.sort(scores); + int count_a = 0; + int count_b = numSurprising; + for (int j = scores.size() - 1; j >= 0; j--) { + int thisscore = scores.get(j); + if (thisscore>=best && thisscore >= 3 * best - 2) { + count_a++; + } else if (thisscore>=best && thisscore >= 3 * best - 4 && count_b > 0) { + count_a++; + count_b--; + } else { + break; + } + } + + output += count_a + ""\n""; + out.write(output); + + } + out.close(); + } +} +" +A22451,"package util.graph; + +import java.util.HashSet; +import java.util.Set; + +public class Node implements Comparable{ + public static int seq = 0; + public int id = (seq++); + public Set edges = new HashSet<>(); + public State last; + + @Override + public int compareTo(Node o) { + + return last.compareTo(o.last); + } + + @Override + public boolean equals(Object obj) { + return id == ((Node) obj).id; + } + + @Override + public int hashCode() { + return Integer.valueOf(id).hashCode(); + } +} +" +A21521,"package ru.sidorkevich.google.jam.qualification.b; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class Main { + + public static void main(String[] args) throws IOException { + List tasks = parseInputFile(""B-large.in""); + + List results = new ArrayList(); + + for (Task task : tasks) { + results.add(solve(task)); + } + + writeOutputFile(""b_output.txt"", results); + } + + private static void writeOutputFile(String fileName, List results) throws IOException { + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(fileName)); + + int i = 1; + for (Integer result : results) { + bw.write(""Case #"" + i++ + "": "" + result + ""\n""); + } + } finally { + if (bw != null) { + bw.close(); + } + } + } + + private static List parseInputFile(String fileName) throws IOException { + List result = new ArrayList(); + + BufferedReader bf = null; + + try { + bf = new BufferedReader(new FileReader(fileName)); + + int numberOfStrings = Integer.parseInt(bf.readLine()); + + String line = bf.readLine(); + + while (line != null) { + String[] tokens = line.split(""\\s""); + + int n = Integer.valueOf(tokens[0]); + int s = Integer.valueOf(tokens[1]); + int p = Integer.valueOf(tokens[2]); + + List t = new ArrayList(); + + for (int i = 3; i < tokens.length; i++) { + t.add(Integer.valueOf(tokens[i])); + } + + result.add(new Task(n, s, p, t)); + + line = bf.readLine(); + } + + if (result.size() != numberOfStrings) { + throw new RuntimeException(""Incorrect input file. Expected number of strings = "" + numberOfStrings + "", actual number of strings = "" + result.size()); + } + } finally { + if (bf != null) { + bf.close(); + } + } + + return result; + } + + private static int solve(Task task) { + List> listOfPossibleTriplets = new ArrayList>(); + + for (Integer ti : task.getT()) { + listOfPossibleTriplets.add(TripletGenerator.generateTriples(ti)); + } + + int s = 0; + int result = 0; + + for (List possibleTriplets : listOfPossibleTriplets) { + if (possibleTriplets.size() > 1) { + if (possibleTriplets.get(1).bestScore() >= task.getP()) { + result++; + } else if (possibleTriplets.get(0).bestScore() >= task.getP() && s < task.getS()) { + result++; + s++; + } + } else { + if (possibleTriplets.get(0).bestScore() >= task.getP()) { + result++; + } + } + } + + return result; + } +} +" +A22018,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.File; + +import java.util.List; +import java.util.ArrayList; + +public class GCJ_qr_b { + + public static void main(String[] args) { + + GCJReader in = new GCJReader(args[0]); + GCJWriter out = new GCJWriter(args[1]); + + int numTestCases = Integer.parseInt(in.readLine()); + + for(int i = 1; i <= numTestCases; i+=1) { + String[] input = in.readLine().split("" ""); + + //always >= 1 + final int googlers = Integer.parseInt(input[0]); + final int surprisingScores = Integer.parseInt(input[1]); + final int p = Integer.parseInt(input[2]); + + int maxGooglers = 0; + int rSurprisingScores = surprisingScores; + + System.out.println(""Googlers="" + googlers + "", surprisingScores="" + surprisingScores + "", p=""+ p); + + for(int j = 3; j < 3 + googlers; j += 1) { + int totalScore = Integer.parseInt(input[j]); + int[] scores = getOrderedScores(totalScore); + + System.out.print("" From "" + totalScore + "" , got ("" + scores[0] + "","" + scores[1] + "","" + scores[2] + "")""); + + boolean gotMax = false; + + //The score in the final sorted position is >= p, so no more checks required. + if (scores[2] >= p) { + maxGooglers += 1; + System.out.println("" | not surprising, satisfied""); + continue; + } + + //the largest score does not satisfy the maximum, but we might still have a chance if + //we have some surprising scores remaining + if(rSurprisingScores == 0) { + System.out.println("" | no surprising scores left""); + continue; + } + + //We have at least one surprising score to work with, which means that the scores as is + //do not satisfy p, but if they are surprising they may + //This scenario now breaks down into 3 cases, in general seeming to correspond to the situation where + //Algorithm could be greatly improved if we analyzed the properties of the score for 3-divisibily but who has time for that + + if(scores[0] == scores[1] && scores[0] == scores[2]) { + //Case 1: The scores are equal + + if(scores[0] == 0) { + //edge case, if all scores are 0, then we can do nothing + gotMax = false; + + } else if((scores[2] + 1) >= p) { + //if the scores are equal and >=1, then we can make these scores surprising by increasing + //one score and decreasing another. For example (1,1,1) can become (1,0,2) + gotMax = true; + } + + } else if (scores[0] == scores[1]) { + //Case 2: We have a triplet of two smaller scores and a larger score, as (1, 1, 2) + // in this case we cannot adjust for a surprising score, as the gap between the largest score (i.e. 2) and the smaller score (i.e. 1) + // will become too large (i.e. 1, 0, 3), and adjusting the smaller numbers is irrelevant (i.e. (0, 2, 2) ) + // So, just continue on + + gotMax = false; + + } else if (scores[1] == scores[2]) { + //Case 3: We have a triplet of two larger scores and a smaller score, as (1, 2, 2) + // We can adjust this number to be a surprising score in pretty much every case, i.e. (1, 1, 3) + + if((scores[2] + 1) >= p) { + gotMax = true; + } + } + + //made the score surprising and see if we can satisfy p + if (gotMax) { + rSurprisingScores--; + maxGooglers++; + System.out.println("" | surprising, satisfied, remaining surprising="" + rSurprisingScores); + } else { + System.out.println("" | can't be satisfied, remaining surprising="" + rSurprisingScores); + } + } + + String outLine = """" + maxGooglers; + out.writeLine(String.format(""Case #%d: %s"", i, outLine)); + } + } + + //the neat part of this breakdown is that scores[3] will always contain the largest number regardless + private static int[] getOrderedScores(int total) { + int[] scores = new int[3]; + + scores[0] = total / 3; + scores[1] = (total - scores[0]) / 2; + scores[2] = (total - scores[0] - scores[1]); + + return scores; + } + + private static class GCJWriter { + private String outFile = null; + private BufferedWriter out = null; + + public GCJWriter(String outFile) { + this.outFile = outFile; + + try { + out = new BufferedWriter(new FileWriter(outFile)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void writeLine(String output) { + try { + out.write(output + ""\n""); + out.flush(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + private static class GCJReader { + private String inFile = null; + private BufferedReader in = null; + + public GCJReader(String inFile) { + this.inFile = inFile; + + try { + in = new BufferedReader(new FileReader(inFile)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public String readLine() { + try { + return in.readLine(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } +}" +A22137,"/** + * + */ +package asem.googe.codejam.qround; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * @author A.Alathwari + * + * Problem A : + * + */ +public class ProblemA implements Runnable { + + asem.core.util.InputReader fin; + java.io.PrintWriter fout; + + /** + * @param fin + * @param fout + */ + public ProblemA(asem.core.util.InputReader fin, PrintWriter fout) { + this.fin = fin; + this.fout = fout; + } + + /** + * @param fin + * @param fout + * @throws IOException + * @throws FileNotFoundException + */ + public ProblemA(String fin, String fout) throws FileNotFoundException, IOException { + this.fin = new asem.core.util.InputReader(new FileReader(fin)); + this.fout = new PrintWriter(System.out); + } + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // TODO Auto-generated method stub + try { + + String ciphertext1 = new String(""ejp mysljylc kd kxveddknmc re jsicpdrysi""); + String ciphertext2 = new String(""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd""); + String ciphertext3 = new String(""de kr kd eoya kw aej tysr re ujdr lkgc jv qz""); + String plaintext1 = new String(""our language is impossible to understand""); + String plaintext2 = new String(""there are twenty six factorial possibilities""); + String plaintext3 = new String(""so it is okay if you want to just give up zq""); + + String code = new String(""abcdefghijklmnopqrstuvwxyz""); + String code2 = new String(); + + char ch = ' '; + for (int i = 0; i < 26; i++) { + ch = code.charAt(i); + + if (plaintext1.indexOf(ch) >= 0) + code2 += ciphertext1.charAt(plaintext1.indexOf(ch)); + else if (plaintext2.indexOf(ch) >= 0) + code2 += ciphertext2.charAt(plaintext2.indexOf(ch)); + else if (plaintext3.indexOf(ch) >= 0) + code2 += ciphertext3.charAt(plaintext3.indexOf(ch)); + else + code2 += ch; + } + + + for (int tNum = 1, inT = fin.readInt(); tNum <= inT; tNum++) { + + String ciphertext = fin.readLine(true); + String plaintext = new String(); + + for (int i = 0; i < ciphertext.length(); i++) + if (code2.indexOf(ciphertext.charAt(i)) >= 0) + plaintext += code.charAt(code2.indexOf(ciphertext.charAt(i))); + else if (ciphertext.charAt(i) == ' ') + plaintext += ciphertext.charAt(i); + + System.out.println(""Case #"" + tNum + "": "" + plaintext); + + } + + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +}" +A23032,"import java.util.*; +public class codejam { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc=new Scanner(System.in); + int m=sc.nextInt(); + int i; + int j; + for(i=1;i<=m;i++) { + int n=sc.nextInt(); + int s=sc.nextInt(); + int p=sc.nextInt(); + int count=0; + for(j=0;j0) { + s--; + count++; + } + } + System.out.println(""Case #""+i+"": ""+count); + } + } + +} +" +A21240,"import java.util.Scanner; +public class B { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + int T = scanner.nextInt(); + for(int j = 1; j2? (p-2)*2+p : p; + int min = p>1? (p-1)*2+p : p; + int total = 0; + for(int i = 0; i= min) total++; + else { + if(t >= minS && S > 0) { + total++; S--; + } + } + } + System.out.println(""Case #"" + j + "": "" + total); + scanner.nextLine(); + } + } +} +" +A21106,"package dance_comp; + +import java.io.*; + +public class Dance_Comp { + int N,count=0; + String s="""",temp[]; + public Dance_Comp() { + try { + FileInputStream fis=new FileInputStream(""B-large.in""); + DataInputStream dis=new DataInputStream(fis); + FileOutputStream fos = new FileOutputStream(""B-large.out""); + DataOutputStream dos=new DataOutputStream(fos); + N=Integer.parseInt(dis.readLine()); + for(int i=1;i<=N;i++) + { + s=dis.readLine(); + count=0; + temp=s.split("" ""); + int dancer=Integer.valueOf(temp[0]),surp=Integer.valueOf(temp[1]),cut_of=Integer.valueOf(temp[2]); + int mrk; + for(int j=0;j=cut_of || (mrk==(cut_of-1) && r>0)) + { + count++; + } + else if(surp>0 && ((mrk==(cut_of-2) && r==2) || (mrk==(cut_of-1) && mrk>0))) + { + count++; + surp--; + } + } + + s=""Case #""+i+"": ""+count; + if(i!=N) + { + s=s+""\n""; + } +// System.out.println(s); + dos.writeBytes(s); + } + fis.close(); + fos.close(); + }catch(Exception e){ + System.out.println(""Error: ""+e); + } + } + + public static void main(String[] args) { + new Dance_Comp(); + } +} +" +A21976,"package com.renoux.gael.codejam.fwk; + +import java.io.File; + +import com.renoux.gael.codejam.utils.FluxUtils; +import com.renoux.gael.codejam.utils.Input; +import com.renoux.gael.codejam.utils.Output; + +public abstract class Solver { + + public void run() { + if (!disableSample()) + runOnce(getSampleInput(), getSampleOutput()); + if (!disableSmall()) + runOnce(getSmallInput(), getSmallOutput()); + if (!disableLarge()) + runOnce(getLargeInput(), getLargeOutput()); + } + + public void runOnce(String pathIn, String pathOut) { + Input in = null; + Output out = null; + try { + + in = Input.open(getFile(pathIn)); + out = Output.open(getFile(pathOut)); + + int countCases = Integer.parseInt(in.readLine()); + for (int k = 1; k <= countCases; k++) { + out.write(""Case #"", k, "": ""); + solveCase(in, out); + } + } catch (RuntimeException e) { + e.printStackTrace(); + } finally { + FluxUtils.closeCloseables(in, out); + } + } + + private File getFile(String path) { + return new File(path); + } + + protected abstract void solveCase(Input in, Output out); + + private String getFullPath(boolean input, String type) { + if (input) + return ""D:\\Downloads\\CodeJam\\"" + getProblemName() + ""\\"" + + getProblemName() + ""_input_"" + type + "".txt""; + else + return ""D:\\Downloads\\CodeJam\\"" + getProblemName() + ""\\"" + + getProblemName() + ""_output_"" + type + "".txt""; + } + + protected String getSampleInput() { + return getFullPath(true, ""sample""); + } + + protected String getSmallInput() { + return getFullPath(true, ""small""); + } + + protected String getLargeInput() { + return getFullPath(true, ""large""); + } + + protected String getSampleOutput() { + return getFullPath(false, ""sample""); + } + + protected String getSmallOutput() { + return getFullPath(false, ""small""); + } + + protected String getLargeOutput() { + return getFullPath(false, ""large""); + } + + protected boolean disableSample() { + return disable()[0]; + } + + protected boolean disableSmall() { + return disable()[1]; + } + + protected boolean disableLarge() { + return disable()[2]; + } + + protected boolean[] disable() { + return new boolean[] { false, false, false }; + } + + protected abstract String getProblemName(); +} +" +A20742,"public class Main { + public static void main(String[] args) throws java.io.FileNotFoundException,java.io.IOException{ + java.io.BufferedReader bRead=new java.io.BufferedReader(new java.io.FileReader(""F:\\B-large.in"")); + java.io.BufferedWriter bWrite=new java.io.BufferedWriter(new java.io.FileWriter(""F:\\B-large.out"")); + StringBuffer output=new StringBuffer(); + int noCases=Integer.parseInt(bRead.readLine()); + for(int i=0;i=baseVal)maxGooglers++; + else if((s>0)&&(cur>=p)&&(cur>=(3*p-4))){ + maxGooglers++;s--; + } + } + output.append(""Case #""+(i+1)+"": ""+maxGooglers+""\n""); + } + bWrite.write(output.toString()); + bWrite.close();bRead.close(); + } +} +" +A22905,"package Q2; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + + +public class Main { + + private static BufferedReader input; + private static BufferedWriter output; + public Main(String inputSetName) throws Exception { + if(getClass().getResource(""."") == null){ + System.err.println(""Switch constructors man""); + System.exit(-1); + } + String path = getClass().getResource(""."").getPath(); + System.out.println(path); + input = new BufferedReader(new FileReader(path+inputSetName+"".in"")); + output = new BufferedWriter(new FileWriter(path+inputSetName+"".out"")); + } + + public Main(String[] args) throws Exception{ + input = new BufferedReader(new FileReader(args[0])); + output = new BufferedWriter(new FileWriter(args[1])); + } + + public void run(Solver model, boolean resultNewLine) throws Exception{ + int cases = Integer.parseInt(input.readLine()); + model.setInput(input); + for(int i=1;i<=cases;i++){ + System.out.println(""Working on case ""+i+""...""); + String $ = model.solve(); + if(resultNewLine) + outputln(""Case #""+i+"":""); + else + output(""Case #""+i+"": ""); + outputln($); + System.out.println(""Case ""+i+"" finished! Result: ""+$); + } + input.close(); + output.close(); + } + + public static void outputln(String s){ + try { + output.write(s); + output.newLine(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void output(String s){ + try { + output.write(s); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A20343,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class B { + + public static void main(String[] args) throws IOException { + int nCases; + String filename=""B-large""; + //String filename=""B-small-attempt0""; + //String filename=""TestB""; + Scanner reader = new Scanner (new FileReader(filename + "".in"")); + PrintWriter writer = new PrintWriter(new FileWriter(filename + "".out"")); + + nCases = reader.nextInt(); + for (int i=0; i 3*p-3) + out++; + else if (S>0 && (temp == 3*p-3 || temp == 3*p-4) && p!=1){ + out ++; + S--; + } + } + + writer.println(out); + } + writer.flush(); + + } + +} +" +A20101,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +public class Second { + + public static void main(String[] args) throws Exception { + BufferedReader reader = new BufferedReader(new FileReader(new File( + ""/Users/narok119/Desktop/B-large.in""))); + + String txt = reader.readLine(); + int caseCount = 1; + + while ((txt = reader.readLine()) != null) { + // Form the inputs + String[] info = txt.split("" "", 4); + int n = Integer.parseInt(info[0]); + int s = Integer.parseInt(info[1]); + int p = Integer.parseInt(info[2]); + String[] input = info[3].split("" ""); + int[] number = new int[n]; + int output = 0; + for (int i = 0; i < n; i++) { + number[i] = Integer.parseInt(input[i]); + } + + // Start calculating output + for (int i = 0; i < n; i++) { + if (p * 3 <= number[i]) { + output++; + } else if (2 * p + (p - 1) == number[i]) { + output++; + } else if (2 * (p - 1) + p == number[i]) { + output++; + } else if (s > 0 && p - 2 >= 0 + && (p - 2) + (p - 1) + p == number[i]) { + output++; + s--; + } else if (s > 0 && p - 2 >= 0 && (p - 2) + 2 * p == number[i]) { + output++; + s--; + } else if (s > 0 && p - 2 >= 0 && 2 * (p - 2) + p == number[i]) { + output++; + s--; + } + } + System.out.println(""Case #"" + caseCount++ + "": "" + output); + } + } + +} +" +A21093,"package CodeJam2; + +import java.io.*; +import java.util.HashMap; +import java.util.Scanner; + +/** + * + * @author Ivan du Toit + */ +public class CodeJam2 { + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + BufferedReader fIn = null; + PrintWriter fOut = null; + try { + fIn = new BufferedReader(new FileReader(""in.txt"")); + fOut = new PrintWriter(new FileWriter(""out.txt"")); + + } catch (IOException e) { + System.out.println(""Invalid file given for output.""); + System.exit(200); + } + + Scanner in = new Scanner(fIn); + int numberOfCases = Integer.parseInt(in.nextLine()); + + for (int c=0; c 1) ? 1 : res; + //boolean resBiggerThan1 = (res > 1); + boolean resLessThan1 = (res < 1); + if (num >= bestScore) + result++; + else if ((!resLessThan1) && (num + 1 >= bestScore)) + result++; + else if ((numSuprises > 0) && (num > 0) && ((resLessThan1 && (num + 1 >= bestScore)) || (!resLessThan1 && (num + res >= bestScore)))) { + numSuprises--; + result++; + } + else if ((numSuprises > 0) && (!resLessThan1 && (num + res >= bestScore))) { + numSuprises--; + result++; + } + } + in.nextLine(); + fOut.println(result); + } + fOut.flush(); + } + + +} +" +A20194,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.StringTokenizer; + + +public class JamInputReader { + int numItem; + String thisLine = null; + BufferedReader in; + StringTokenizer tokenizer; + + public JamInputReader(String fileName) { + try { + in = new BufferedReader(new FileReader(fileName)); +/* String text = in.readLine(); + numItem = Integer.parseInt(text);*/ + + readNextLine(); + tokenizer = new StringTokenizer(thisLine, "" ""); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + void readNextLine() { + try { + thisLine = in.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + int getNumItems() { + numItem = Integer.parseInt(tokenizer.nextToken()); + return numItem; + } + + String getNextItem() { + if(false == tokenizer.hasMoreTokens()) { + readNextLine(); + tokenizer = new StringTokenizer(thisLine, "" ""); + } + return tokenizer.nextToken(); + } + + String getNextLine() { + readNextLine(); + return thisLine; + } + + int getNextInt() { + return Integer.parseInt(getNextItem()); + } + + long getNextLong() { + return Long.parseLong(getNextItem()); + } + + byte[] getNextLineByte() { + readNextLine(); + return thisLine.getBytes(); + } +} +" +A21535,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class BDanceScores { + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(""blarge.in"")); + //Scanner in = new Scanner(System.in); + PrintWriter out = new PrintWriter(""blarge.out""); + int T = in.nextInt(); + for (int t = 1; t <= T; ++t) { + int N = in.nextInt(), S = in.nextInt(), p = in.nextInt(); + int bigScores = 0, okScores = 0; + for (int i = 0; i < N; ++i) { + int sumScore = in.nextInt(); + int bestScore = (sumScore + 2) / 3; + if (bestScore >= p) { + bigScores++; + } else if (bestScore == p-1 && sumScore >= 2 && sumScore <= 28 && (sumScore % 3 != 1)) { + okScores++; + } + } + int result = Math.min(okScores, S) + bigScores; + out.println(""Case #"" + t + "": "" + result); + } + out.close(); + } +} +" +A20391,"package codejam2012; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +/** + * + * @author devashish + */ +public class ProblemB { + + public static void main(String[] args) { + StringTokenizer st = null; + BufferedReader in; + PrintWriter out = null; + try { + in = new BufferedReader(new FileReader(new File(""E:/b.in""))); + out = new PrintWriter(new FileWriter(new File(""E:/b.out""))); + + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(in.readLine()); + } + int t = Integer.parseInt(st.nextToken()); + for (int i = 1; i <= t; i++) { + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(in.readLine()); + } + + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] T = new int[N]; + for (int j = 0; j < N; j++) { + T[j] = Integer.parseInt(st.nextToken()); + } + + int outputLine = maxGooglers(N, S, p, T); + + out.print(""Case #"" + i + "": "" + outputLine + ""\n""); + } + } catch (IOException e) { + } + out.flush(); + } + + private static int maxGooglers(int N, int S, int p, int[] T) { + int output = 0; + + int surprisingMinScore = Math.max(3 * p - 4, 0) ; + int nonSurprisingMinScore = Math.max(3 * p - 2, 0); + int countSurprise = 0; + + // System.out.println(surprisingMinScore); + // System.out.println(nonSurprisingMinScore); + + for (int i = 0; i < T.length; i++) { + // System.out.println(T[i]); + // System.out.println(""T[i]: "" + T[i]); + if (T[i] < surprisingMinScore) { + continue; + } else if (T[i] >= surprisingMinScore && T[i] < nonSurprisingMinScore) { + //either surprising or low scores + //countSurprise += findPossibleSurprisingScoresWithBestResult(T[i], p); + if (S > 0 && T[i] >= 2) { + countSurprise += findPossibleSurprisingScoresWithBestResult(T[i], p); + // System.out.println(""#countSurprise: "" + countSurprise); + //output += findPossibleSurprisingScoresWithBestResult(T[i], p); + } + } else if (T[i] >= nonSurprisingMinScore) { + //Non surprising score + //System.out.println(""non surprising score.""); + output++; + } + } + + //System.out.println(""#output: "" + output); + //System.out.println((countSurprise < S ? countSurprise : S)); + return output + (countSurprise < S ? countSurprise : S); + } + + private static int findPossibleSurprisingScoresWithBestResult(int t, int p) { + int count = 0; + int a = t/3; + int b = ((t + 4)/3); + + if (p >= a && p <=b) { + count++; + } + //System.out.println(""#count:"" + count); + return count; + } +} +" +A20098,"import java.util.Scanner; + +public class B { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int k = 0; k < t; k++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int smin = p + (p - 2) + (p - 2); + int smax = p + (p - 2) + (p - 1); + + smin = smin < 0 ? 0 : smin; + smax = smax < 0 ? 0 : smax; + + int count = 0; + int allow = s; + for (int i = 0; i < n; i++) { + int v = sc.nextInt(); + if (p == 0) { + count++; + continue; + } + + if (v < p) + continue; + + else if (smin == v || smax == v) { + if (allow > 0) { + count++; + allow--; + } + } else if (v > smax) { + count++; + } + } + System.out.println(""Case #"" + (k + 1) + "": "" + count); + } + + } +} +" +A21133,"import java.util.*; + + +public class DancingWithGooglers { + + private static final Scanner sc = new Scanner(System.in); + + /** + * @param args + */ + public static void main(String[] args) { + + int T = sc.nextInt(); //number of button presses + + for (int i = 0; i < T; i++){ + + int N = sc.nextInt(); //number of contestants + int S = sc.nextInt(); //number of suprises + int p = sc.nextInt(); //possible maximum score + + int result = 0; + + for (int j = 0; j < N; j++){ + + int t = sc.nextInt(); + + if (t >= (3 * p - 2)) + result++; + + else if (p == 1); + + + else if ((t >= (3 * p - 4)) && (S != 0)){ + result++; + S--; + } + + } + + System.out.println(""Case #"" + (i + 1) + "": "" + result); + + } + + + + } + +} +" +A22743," +import java.io.FileNotFoundException; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + +/** + * + * @author utp + */ +public class B { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException + { + //System.setIn(new FileInputStream(""B.in"")); + Scanner sc = new Scanner(System.in); + int nCasos = sc.nextInt(); + for(int caso = 1; caso <= nCasos; caso++) + { + int n = sc.nextInt(); + int sor = sc.nextInt(); + int p = sc.nextInt(); + int buenos = 0; + int nSor = 0; + for(int i = 0; i < n; i++) + { + int valor = sc.nextInt(); + int media = valor / 3; + if(valor % 3 == 0 && (p == 0 || valor != 0)) + { + if(p <= media) + buenos++; + else if(p <= media + 1 && nSor != sor) + { + buenos++; + nSor++; + } + } + else if(valor % 3 == 1) + { + if(p <= media + 1) + buenos++; + } + else if(valor % 3 == 2) + { + if(p <= media + 1) + buenos++; + else if(p <= media + 2 && nSor != sor) + { + buenos++; + nSor++; + } + } + } + System.out.println(""Case #"" + caso + "": "" + buenos); + } + } +} +" +A20862,"package utils; + +/** + * + * @author Fabien Renaud + */ +public abstract class JamCase implements Runnable, JamCaseSolver { + + protected final int number; + protected String result; + private final StopWatch timer; + private final Jam parent; + + protected JamCase(Jam parent, int number) { + this.parent = parent; + this.number = number; + this.timer = new StopWatch(); + } + + public final int getNumber() { + return number; + } + + public final String getResult() { + return result; + } + + public final StopWatch getTimer() { + return timer; + } + + @Override + public final void run() { + timer.start(); + + parse(); + solve(); + + if (parent != null) { + parent.appendOutput(number, result); + } + + timer.stop(); + } +}" +A22035,"/** + * + */ +package qualification; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * @author armin + * + */ +public class DancingWithTheGooglers { + + static int maxscore(int points, boolean surp){ + if(points >= 29) return 10; + if(points == 0) return 0; + int div = points / 3; + int mod = points % 3; + + if(surp){ + switch(mod){ + case 0: return div+1; + case 1: return div+1; + case 2: return div+2; + default: return -1; + } + }else{ + return mod==0?div:div+1; + } + } + + static int min(int a, int b){ + return a=p) ct1+=1; + if(ms

myScores = new ArrayList(); + for (int i = 3; i < lineArray.length; i++) { + Scores myScore = new Scores(); + myScore.total = Integer.valueOf(lineArray[i]); + int defaultScore = (myScore.total / 3); //already rounded down + + myScore.setDefaultScore(defaultScore); + + myScore.scoreToEqual = maximumBestResultOfAtLeast; + + if (!myScore.correct()) { + myScore.score1Added = true; + myScore.score1++; + } + if (!myScore.correct()) { + myScore.score2Added = true; + myScore.score2++; + } + if (!myScore.correct()) { + System.out.println(""Should not ever happen""); + outputLine += ""Should not ever happen""; + } + + myScores.add(myScore); + } + + for (int i = myScores.size() - 1; i >= 0; i--) { + if (myScores.get(i).bestScore()) { + totalOfBestScorers++; + myScores.remove(i); + } + } + + for (int i = 0; i < myScores.size(); i++) { +// if (((myScores.get(i).score2 > 0) && (myScores.get(i).score2Added) && (myScores.get(i).score1Added)) || ((myScores.get(i).score2 > 0) && (!myScores.get(i).score1Added) && (!myScores.get(i).score2Added))) { +// myScores.get(i).score1++; +// myScores.get(i).score2--; +// } + if ((myScores.get(i).score2 > 0) && (myScores.get(i).score2Added) && (myScores.get(i).score1Added)) { + myScores.get(i).score1++; + myScores.get(i).score2--; + } else if ((myScores.get(i).score1 > 0) && (myScores.get(i).score2 > 0) && (!myScores.get(i).score1Added) && (!myScores.get(i).score2Added)) { + myScores.get(i).score1++; + myScores.get(i).score2--; + } + } + + for (int i = myScores.size() - 1; i >= 0; i--) { + if (myScores.get(i).bestScore()) { + if (numberOfSurprisingTripletScores <= 0) { + break; + } + totalOfBestScorers++; + myScores.remove(i); + numberOfSurprisingTripletScores--; + } + } + + outputLine += String.valueOf(totalOfBestScorers); + + + writeFile(outputLine); + } + + private static class Scores { + int total = 0; + int score1 = 0; + int score2 = 0; + int score3 = 0; + int scoreToEqual = 0; + boolean score2Added = false; + boolean score1Added = false; + + + public int getTotal() { + return score1 + score2 + score3; + } + + public boolean correct() { + if (getTotal() == total) { + return true; + } else { + return false; + } + } + + public void setDefaultScore (int defaultScore) { + score1 = defaultScore; + score2 = defaultScore; + score3 = defaultScore; + } + + public boolean bestScore() { + if ((score1 >= scoreToEqual) || (score2 >= scoreToEqual) || (score3 >= scoreToEqual)) { + return true; + } else { + return false; + } + } + + } + + + public static void main(String[] args) { + try{ + FileInputStream fstream = new FileInputStream(""input.txt""); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + int lineNumber = 0; + while ((strLine = br.readLine()) != null) { + lineNumber++; + processLine(strLine, lineNumber); + } + in.close(); + }catch (Exception e){ + System.err.println(""Error Main: "" + e.getMessage()); + e.printStackTrace(); + } + } + + + private static void writeFile(String line) { + try{ + System.out.println(line); + FileWriter fstream = new FileWriter(""out.txt"",true); + BufferedWriter out = new BufferedWriter(fstream); + out.write(line + ""\n""); + out.close(); + }catch (Exception e){ + System.err.println(""Error writeFile: "" + e.getMessage()); + } + } + +} +" +A21245,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package qualb; + +import java.util.Scanner; + +/** + * + * @author marcin + */ +public class QualB { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = Integer.parseInt(in.nextLine()); + for (int ci = 1; ci <= T; ++ci) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int certains = 0; + int possibles = 0; + for (int i = 0; i < N; ++i) { + int total = in.nextInt(); + int temp = total - (3 * p); + if (temp >= 0) { + ++certains; + } + else { + if ((p - 1 >= 0) && (temp >= -2)) { + ++certains; + } + else if ((p - 2 >= 0) && (temp >= -4)) { + ++possibles; + } + } + } + int optional = S > possibles ? possibles : S; + int answer = certains + optional; + System.out.println(""Case #"" + ci + "": "" + answer); + } + } +} +" +A22269,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class Solution2 { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub +// System.out.println(Solution2.calculteBestNum(""6 2 8 29 20 8 18 18 21"")); + BufferedReader bReader = null; + FileWriter fWriter = null; + try { + bReader = new BufferedReader(new FileReader(new File(""B-large.in""))); + fWriter = new FileWriter(new File(""Output-large"")); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + int num = 0; + try { + num = Integer.parseInt(bReader.readLine()); + } catch (NumberFormatException | IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + for(int i = 1; i < num + 1; i ++){ + String ssString = """"; + try { + ssString = bReader.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(ssString == null){ + break; + } + else if(ssString.trim() == """"){ + continue; + } + try { + fWriter.write(""Case #""+ i +"": "" + Solution2.calculteBestNum(ssString)); + fWriter.write(""\n""); + fWriter.flush(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public static int calculteBestNum(String scores){ + String[] tmp = scores.split("" ""); + int num = Integer.parseInt(tmp[0].trim()); + int surprising = Integer.parseInt(tmp[1].trim()); + int p = Integer.parseInt(tmp[2].trim()); + int key = 0; + int finalnum = 0; + for(int i = 0; i < num; i ++){ + int score = Integer.parseInt(tmp[i + 3].trim()); + if(score > 3 * (p - 1)){ + finalnum++; + } + else if(key < surprising){ + if(score >= p && score>= 3*p -4){ + finalnum++; + key++; + } + } + } + return finalnum; + } + +} +" +A20213,"// no.of users +// no. of sets +// minimum best +// scores + +import java.io.*; +import java.util.Scanner; +public class abc +{ +public static void main(String args[]) +{ + try{ + FileWriter fstream = new FileWriter(""outB.out""); +FileInputStream fstream1=new FileInputStream(""B-large.in""); +DataInputStream in=new DataInputStream(fstream1); +BufferedReader input=new BufferedReader(new InputStreamReader(in)); +BufferedWriter out = new BufferedWriter(fstream); + +String strLine; +strLine=input.readLine(); +int T=Integer.parseInt(strLine); +int j=1; +while(j<=T) +{ +int N,S,P; +strLine=input.readLine(); +String[] numbers=strLine.split("" ""); +int nums[]=new int[numbers.length]; +N=Integer.parseInt(numbers[0]); +S=Integer.parseInt(numbers[1]); +P=Integer.parseInt(numbers[2]); +int Score[]=new int[N]; +int i=0; +for( i=0;i0&&avg!=0) +{ +S=S-1; +Flag=Flag+1;} +break; +} +case 1: +{ +if(P<=avg+1) +Flag=Flag+1; +break; +} +case 2: +{ +if(P<=avg+1) +Flag=Flag+1; +if(P==avg+2&&S>0) +{ +S=S-1; +Flag=Flag+1; +} +break; +} + +} //switch close +//System.out.println(Flag); +} +//System.out.println(Flag); +out.write(""Case #""+j+"": ""+Flag+""\r\n""); +j=j+1; +} + +out.close(); +input.close();}catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } +} +} +" +A22527,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2012; + +import java.util.Scanner; + +/** + * + * @author Matt + */ +public class ProbB { + public static void main(String[] args){ + Scanner scan = new Scanner(System.in); + Integer cases = scan.nextInt(); + for(int i = 0; i < cases; i++){ + Integer contestants = scan.nextInt(); + Integer surprising = scan.nextInt(); + Integer num = scan.nextInt(); + Integer count = 0; + //System.out.print(surprising); + for(int j = 0; j < contestants; j++){ + Integer current = scan.nextInt(); + Double average = current/3.0; + if(average >= num){ + count++; + }else if(average == 0 || average == 10){ + + }else if(average.intValue() == average.doubleValue()){ + if(surprising > 0 && (average+1) >= num){ + count++; + surprising--; + //System.out.print(surprising); + } + }else if(average.intValue()+1 >= num) { + count++; + }else if(average > 0.5 && surprising > 0 && average.intValue()+2 >= num) { + count++; + surprising--; + //System.out.print(surprising); + } + } + //System.out.print(surprising); + System.out.println(""Case #""+(i+1)+"": ""+count); + } + } +} +" +A20638," +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class Dancers { + + public static void main(String args[]) throws IOException { + Scanner s = new Scanner(new File(""D:\\input2.txt"")); + FileWriter fo = new FileWriter(new File(""D:\\workspace\\GC12\\src\\output2.txt"")); + int num = s.nextInt(); + for(int i = 1; i<= num; i++) { + fo.write(""Case #"" + i + "": ""); + int nd = s.nextInt(); + int ns = s.nextInt(); + //System.out.println(""\n""+ i + "" - "" + nd + "" , ""+ ns); + + int p = s.nextInt(); + int aHigh = Math.max(p, 0) + Math.max(p-1, 0) + Math.max(p-1, 0); + int surpScore = Math.max(p, 0) + Math.max(p-2, 0) + Math.max(p-2, 0); + int bScore = 0; + int canSurprise = 0; + for(int j = 1; j<=nd; j++) { + int score = s.nextInt(); + //System.out.print(score + "" - ""); + if (score == 0) { + continue; + } + if (score >= aHigh) { + bScore ++; + } else if(score >= surpScore) { + canSurprise ++; + } + } + if (canSurprise < ns) { + bScore += canSurprise; + } else { + bScore += ns; + } + if(p==0) { + fo.write(nd + ""\n""); + } else { + fo.write(bScore + ""\n""); + } + } + fo.close(); + s.close(); + } +} +" +A21524,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.*; + +public class Dancers { + + /** + * @param args + */ + private static Hashtable ns = new Hashtable(); + private static Hashtable s = new Hashtable(); + + public static void main(String[] args) { + // TODO Auto-generated method stub + int tests; + try{ + BufferedReader stdin = new BufferedReader(new FileReader(args[0])); + tests = Integer.parseInt(stdin.readLine()); + for(int i = 0; i < tests; i++){ + System.out.print(""Case #""+(i+1) + "": ""); + solve(stdin.readLine()); + System.out.println(); + } + }catch(IOException e){ + e.printStackTrace(); + } + System.exit(0); + + } + + private static void solve(String in){ + String[] det = in.split("" ""); + int googlers = Integer.parseInt(det[0]); + int surprises = Integer.parseInt(det[1]); + int p = Integer.parseInt(det[2]); + int max = 0; + for(int i = 3; i < 3+googlers; i++){ + ns.clear(); + s.clear(); + analyze(i, Integer.parseInt(det[i])); + switch(inclusion(i, p)){ + case 2: max +=1; break; + case 1: if(surprises>=1) { max += 1; surprises -= 1;} break; + default: break; + } + } + System.out.print(max); + } + + public static void analyze(int googler, int n){ + HashSet h = new HashSet(); + for(int i = Math.max(0, n/3 - 1); i <= Math.min(n/3 + 1, 10); i++){ + for(int j = Math.max(0, (n-i)/2 - 1); j <= Math.min((n-i)/2 + 1, 10); j++){ + for(int k = Math.max(0, (n-i-j) - 1); k <= Math.min(n-i-j + 1, 10); k++){ + if(n == i + j + k && !h.contains(new Integer(i*100 + j*10 + k))){ + //System.out.println(i + "","" + j + "","" + k); + if(categorize(googler,i,j,k)) + addPerms(i,j,k,h); + + } + } + } + } + } + + private static void addPerms(int i, int j, int k, HashSet h){ + h.add(new Integer(100*i + 10*j + k)); + h.add(new Integer(100*i +10*k + j)); + h.add(new Integer(100*j + 10*i + k)); + h.add(new Integer(100*j + 10*k + i)); + h.add(new Integer(100*k + 10*i + j)); + h.add(new Integer(100*k + 10*j + i)); + } + + public static boolean categorize(int googler, int i, int j, int k){ + if(Math.abs(i-j)<2 && Math.abs(i-k)<2 && Math.abs(j-k)<2){ + int[] arr = {i,j,k}; + ns.put(new Integer(googler),arr); + return true; + } else if((Math.abs(i-j)==2 && Math.abs(i-k)<=2 && Math.abs(j-k)<=2) || (Math.abs(i-k)==2 && Math.abs(i-j)<=2 && Math.abs(j-k)<=2) || (Math.abs(j-k)==2 && Math.abs(i-j)<=2 && Math.abs(i-k)<=2)){ + int[] arr = {i,j,k}; + s.put(new Integer(googler), arr); + return true; + } + return false; + } + + private static byte inclusion(int googler, int p){ + int[] sur = s.get(new Integer(googler)); + int[] nsur = ns.get(new Integer(googler)); + + boolean withSur = false; + boolean withoutSur = false; + + for(int i = 0; i < 3; i++){ + if(sur != null && sur[i] >= p) + withSur = true; + if(nsur[i] >= p) + withoutSur = true; + } + + if(withoutSur) + return 2; + else if(withSur) + return 1; + else + return 0; + } + +} +" +A20426,"import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class DWTG { + + static void log(String fs, Object... args) { + System.err.println(String.format(fs, args)); + } + + public static void main(String[] args) throws FileNotFoundException { + String filename = ""src/data/B-large.in""; + Scanner sc = + new Scanner( + new FileInputStream( + new File(filename))); + PrintWriter pw = + new PrintWriter( + new FileOutputStream( + new File(filename + "".result""))); + + int[] usually = new int[31]; + int[] surprise = new int[31]; + + for (int a = 0; a <= 10; a++) { + for (int b = 0; b <= 10; b++) { + for (int c = 0; c <= 10; c++) { + int sum = a+b+c; + int m = Math.max(c, Math.max(a, b)); + if (Math.abs(a-b) <= 1 && Math.abs(b-c) <= 1 && Math.abs(a-c) <= 1) { + usually[sum] = Math.max(usually[sum], m); + } else if (Math.abs(a-b) <= 2 && Math.abs(b-c) <= 2 && Math.abs(a-c) <= 2) { + surprise[sum] = Math.max(surprise[sum], m); + } + } + } + } + + int T = sc.nextInt(); + sc.nextLine(); + for (int task = 1; task <= T; task++) { + + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + int count_usually = 0; + int count_surprise = 0; + for (int i=0; i= p) + count_usually++; + else if (surprise[d] >= p) + count_surprise++; + } + + int result = count_usually + Math.min(S, count_surprise); + pw.println(String.format(""Case #%d: %d"", task, result)); + log(""Case #%d: %d"", task, result); + } + pw.close(); + } +} +" +A22397,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class B { + + private class OutputDelegate { + + BufferedWriter out; + + private OutputDelegate(String fileName) { + try { + out = new BufferedWriter(new FileWriter(fileName)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void writeLine(String output) { + try { + out.write(output); + out.newLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void close() { + try { + if (out != null) + { + out.close(); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + private class InputDelegate { + + BufferedReader in; + + private InputDelegate(String fileName){ + try { + in = new BufferedReader(new FileReader(fileName)); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private int[] readIntLine() { + String line; + String income[] = null; + try { + if ((line = in.readLine()) != null) { + income = line.split("" ""); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + int array[] = new int[income.length]; + for (int i = 0; i < array.length; i++) { + array[i] = (Integer.parseInt(income[i])); + } + return array; + } + + private void close() { + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } + + public void process(String[] args) { + InputDelegate in = new InputDelegate(args[0]); + OutputDelegate out = new OutputDelegate(args[1]); + int cases = in.readIntLine()[0]; + for (int i = 1; i <= cases; i++) { + int[] line = in.readIntLine(); + int contnum = line[0]; + int surpr = line[1]; + int p = line[2]; + int[] contestants = new int[contnum]; + for (int j = 3; j < line.length; j++) { + contestants[j-3] = line[j]; + } + int[] triplets = new int[2]; + triplets[0] = p*3-4; + triplets[1] = p*3-3; + int output = 0; + for (int j = 0; j < contnum; j++) { + if(contestants[j] == 0) { + if(p == 0) { + output++; + continue; + } + else continue; + } + if(contestants[j] > triplets[1]) { + output++; + } else if(contestants[j] == triplets[0] || contestants[j] == triplets[1]) { + if(surpr > 0) { + surpr--; + output++; + } + } + } + out.writeLine(""Case #"" + i + "": "" + output); + } + in.close(); + out.close(); + } + + public static void main(String[] args) { + B m = new B(); + m.process(args); + } + +} +" +A21602,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package jam_b; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author dkozyrev + */ +public class Jam_B { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + List cases = readFile(""C:\\tmp\\testA.txt""); + + int counter = 1; + String delimiter = "" ""; + + for (Map caseItem : cases) + { + List lines = Arrays.asList(caseItem.get(""str"").split(delimiter)); + + int res = findMax(lines); + + System.out.println(""Case #""+counter+"":"" + res); + + counter++; + } + } + + public static int findMax(List lines) + { + int max = 0; + + int peaopleNum = Integer.parseInt(lines.get(0)); + int surprising = Integer.parseInt(lines.get(1)); + int find = Integer.parseInt(lines.get(2)); + + //System.out.println(find); + + int counter = 0; + for(String score : lines) + { + if(counter > 2) + { + //find potential + Double scoreD = Double.parseDouble(score); + if(scoreD/3 >= (find-0.75)) + { + max++; + //System.out.println(""1: "" + scoreD/3); + } + else if (surprising>=1 && (scoreD/3 > (find-1.5)) && (find-1.5) > 0 ) + { + max++; + surprising--; + //System.out.println(""2: "" + scoreD/3); + } + } + counter++; + //System.out.println(max); + } + return max; + } + + public static List readFile(String fname) { + List casesList = new ArrayList(); + { + FileReader input = null; + try { + input = new FileReader(fname); + BufferedReader bufRead = new BufferedReader(input); + String line; + int count = 0; + line = bufRead.readLine(); + Integer cases = Integer.parseInt(line); + count++; + while (line != null) + { + if (count == 1) + { + line = bufRead.readLine(); + count++; + continue; + } + + Map params = new HashMap(); + params.put(""str"", line); + line = bufRead.readLine(); + + casesList.add(params); + count++; + } + bufRead.close(); + } catch (FileNotFoundException ex) { + Logger.getLogger(Jam_B.class.getName()).log(Level.SEVERE, null, ex); + }catch (ArrayIndexOutOfBoundsException e){ + System.out.println(""Usage: java ReadFile filename\n""); + }catch (IOException e){ + System.out.println(e.getMessage()); + } finally { + try { + input.close(); + } catch (IOException ex) { + Logger.getLogger(Jam_B.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + return casesList; + } +}" +A20321,"package QR_2012; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import Utils.IOStreams; + +public class B_Dancing_With_The_Googlers { + + public static void main(String[] args) throws IOException { + + IOStreams streams = new IOStreams(args[0]); + System.setIn(new FileInputStream(args[0])); + Scanner sc = new Scanner(System.in); + + sc.nextLine(); // Skip number of cases + int caseNumber = 1; + while (sc.hasNextInt()) { + + int numberOfGooglers = sc.nextInt(); + int surprisingTriplets = sc.nextInt(); + int minimumScore = sc.nextInt(); + List totalPoints = new ArrayList(); + for(int i=0 ; i totalPoints) { + + int solution = 0; + + for (Integer integer : totalPoints) { + + if(integer==0){ + if(minimumScore==0) solution++; + continue; + } + + if(integer%3!=0){ + if((integer/3+1)>=minimumScore) + solution++; + else if(integer/3+1=minimumScore && surprisingTriplets>0){ + solution++; + surprisingTriplets--; + } + } + else if (integer%3==0){ + if(integer/3>=minimumScore) + solution++; + else if(integer/3=minimumScore && surprisingTriplets>0){ + solution++; + surprisingTriplets--; + } + } + } + + return solution; + } + +} +" +A21520,"package ru.sidorkevich.google.jam.qualification.b; + +import java.util.List; + +public class Task { + int n; + int s; + int p; + List t; + + public Task(int n, int s, int p, List t) { + this.n = n; + this.s = s; + this.p = p; + this.t = t; + } + + public int getN() { + return n; + } + + public int getS() { + return s; + } + + public int getP() { + return p; + } + + public List getT() { + return t; + } + + @Override + public String toString() { + return ""Task{"" + + ""n="" + n + + "", s="" + s + + "", p="" + p + + "", t="" + t + + '}'; + } +} +" +A23075,"package com.first; + +public class MainClass { + + /** + * @Author Nimitz + */ + public static void main(String[] args) { +// CodeJamSolution solution = new CodeJamSolution(); +// ASpeakingInTongues solution = new ASpeakingInTongues(); + BDancingWiththeGooglers solution = new BDancingWiththeGooglers(); + } + +} +" +A20016,"import java.util.*; +import java.io.*; +public class B { + public static void main (String[] args)throws Exception + { + String inputfilename = args[0]; + String outputfilename = args[1]; + BufferedReader br = new BufferedReader(new FileReader(inputfilename)); + BufferedWriter bw = new BufferedWriter(new FileWriter(outputfilename)); + int cases = Integer.valueOf(br.readLine()); + for(int i = 0; i < cases; i++) { + String[] ele = br.readLine().split("" ""); + int n = Integer.valueOf(ele[0]); + int s = Integer.valueOf(ele[1]); + int p = Integer.valueOf(ele[2]); + List total = new ArrayList(); + for(int j = 0; j < n; j++) { + total.add(Integer.valueOf(ele[3 + j])); + } + int result = B.solve(n,s,p,total); + bw.write(""Case #"" + (i + 1) + "": "" + result + ""\n""); + } + + + br.close(); + bw.close(); + } + public static int solve(int n,int s,int p,List total) + { + int cnt = 0; + for(Integer t : total) { + int divide = t / 3; + int left = t - divide * 3; + if(divide >= p) { + cnt++; + continue; + } + if(left == 1) { + if(divide + 1 >= p) cnt++; + } else if(left == 2) { + if(divide + 1 >= p) cnt++; + else if(divide + 2 >= p && s > 0) {cnt++;s--;} + } else if(divide > 0){ + if(divide + 1 >= p && s > 0) {cnt++;s--;} + } + + } + return cnt; + } +} +" +A20191,"package gcj2012.qual; + + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +import common.AbstractRunner; +import common.AbstractRunner.SIZE; + +public class B extends AbstractRunner { + + public void handleCase(int caseNumber) throws Exception { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + + //if (p == 0) + + int res = 0; + for (int i=0; i= 0) { + if (2*(p-1) <= x) res++; + else if (s > 0 && 2*(p-2) <= x) { + s--; + res++; + } + } + } + out.write(Integer.toString(res)+""\n""); + } + + public static void main(String[] args) throws Exception { + new B().init(SIZE.large).execute(); + } + +} +" +A20847,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +//package testtc; + +import java.util.Scanner; + +/** + * + * @author root + */ +public class TestTc { + + + public static void main(String[] args) { +// String a = ""yhesocvxduiglbkrztnwjpfmaq""; + Scanner in = new Scanner(System.in); + int d = 1; +// while(in.hasNext()) +// { + int t = in.nextInt(); + + while(t-- > 0 ) + { + int res = 0; + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + +// int pp[] = new int[n]; + for(int i=0;i=p) + { + res++; + continue; + } + else if(s>0 && k!=0 && k+1>=p) + { + s--; + res++; + continue; + } + } + else if(ti%3 == 1) + { + int k = ti/3; +// if(k==0) continue; +// System.out.println(k); + int mx = k+1; + if(mx>=p) + { + res++; + continue; + } + } + else if(ti%3 == 2) + { + int k = ti/3; + if(k==0) continue; +// System.out.println(k); + int mx = k+1; + if(mx>=p) + { + res++; + continue; + } + if(s>0 && k!=0 && mx+1>=p) + { + s--; + res++; + continue; + } + } + } + + System.out.println(""Case #""+ (d++) +"": "" + res); + } +// } + } +} +" +A21068,"package com.googlecode.codejam.model; + +import java.util.Iterator; +import java.util.concurrent.Callable; + + +public abstract class JamCaseResolverFactory { + + public abstract Callable newJamCaseResolver(int caseNumber, Iterator lineIterator); + +} +" +A22908,"import java.io.BufferedReader; +import java.io.InputStreamReader; + + +public class B { + + void run() { + try { + BufferedReader bfd = new BufferedReader(new InputStreamReader( + System.in)); + int tc = Integer.parseInt(bfd.readLine()), i, j, k, s, p, goo[], surp[], + res[], t, r, cnt; + boolean[] taken; + String[] sp; + for(r=0; r=p){ + if(k-i==2){ + ++surp[t]; + } else if(k-i < 2) { + ++res[t]; + } + } + } + } + } + } + taken = new boolean[goo.length]; + cnt = 0; + for(i=0; i0 && res[i]==0 && surp[i]==1){ + taken[i] = true; + --s; + } + } + for(i=0; i surprise = new HashSet(); + Set standard = new HashSet(); + + for (int i = 0; i <= 10; i++) { + for (int j = i; j <= 10; j++) { + for (int k = j; k <= 10; k++) { + if (k - i > 2) { + break; + } + + if (k < p) { + continue; + } + + if (k - i == 2) { + surprise.add(i + j + k); + } else { + standard.add(i + j + k); + } + } + } + } + + int[][] dyn = new int[n + 1][s + 1]; + for (int i = 1; i <= n; i++) { + for (int j = 0; j <= s; j++) { + if (surprise.contains(a[i - 1]) && j > 0) { + dyn[i][j] = Math.max(dyn[i][j], dyn[i - 1][j - 1] + 1); + } + if (standard.contains(a[i - 1])) { + dyn[i][j] = Math.max(dyn[i][j], dyn[i - 1][j] + 1); + } + dyn[i][j] = Math.max(dyn[i][j], dyn[i - 1][j]); + } + } + out.println(dyn[n][s]); + } + + out.close(); + in.close(); + } +} +" +A23036,"import java.io.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader bf = new BufferedReader(new FileReader(new File(""B-large.in""))); + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""B-large.out""))); + + int T = Integer.parseInt(bf.readLine()); + + for (int c = 0; c < T; c++) { + String tokens[] = bf.readLine().split("" ""); + int N = Integer.parseInt(tokens[0]), S = Integer.parseInt(tokens[1]), p = Integer.parseInt(tokens[2]), t[] = new int[N], ans =0; + for (int i = 0; i < N; i++) { + t[i] = Integer.parseInt(tokens[i + 3]); + int base = t[i] / 3, mod = t[i] % 3; + if (base >= p || (mod > 0 && base + 1 >= p)) + ans++; + else if(S>0 && base >0 && base + Math.max(1, mod) >= p) { + ans++; + S--; + } + } + bw.write(String.format(""Case #%d: %d\n"", c+1, ans)); + } + bw.close(); + } +} +" +A22671,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +public class DancingWithTheGooglers { + String filename; + BufferedReader br; + PrintWriter pw; + + public DancingWithTheGooglers(String filename) throws FileNotFoundException { + this.filename = filename; + br = new BufferedReader(new FileReader(filename)); + pw = new PrintWriter(""output-2.txt""); + } + + public void processInput() throws NumberFormatException, IOException { + StringBuffer sb = new StringBuffer(); + int numCases = Integer.parseInt(br.readLine()); + for(int i=0; i0) { S--; count++; } + else if(total > 3*p-3) count++; + } + return count; + } +} + +class Main2 { + public static void main(String args[]) throws NumberFormatException, IOException { + DancingWithTheGooglers d = new DancingWithTheGooglers(""B-large.in.txt""); + d.processInput(); + } +} +" +A20481,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class B { + + int N = 0; + int S = 0; + int P = 0; + + ArrayList nrs; + + public B(BufferedReader reader) throws IOException { + String line = reader.readLine(); + StringTokenizer token = new StringTokenizer(line, "" ""); + N = Integer.parseInt(token.nextToken()); + S = Integer.parseInt(token.nextToken()); + P = Integer.parseInt(token.nextToken()); + + nrs = new ArrayList(); + + for (int i = 0; i= P3) { + result++; + continue; + } + + if (((nr + 4) >= P3) && (S > 0)) { + result++; + S--; + continue; + } + } + + return result; + } + + public static void main(String[] args) throws IOException { + String inputFile = args[0]; + BufferedReader reader = new BufferedReader(new FileReader(inputFile + + "".in"")); + FileWriter outFile = new FileWriter(inputFile + "".out""); + PrintWriter out = new PrintWriter(outFile); + String strNrLines = reader.readLine(); + int nrLines = Integer.parseInt(strNrLines); + for (int i = 1; i <= nrLines; i++) { + B b = new B(reader); + out.println(""Case #"" + i + "": "" + b.solve()); + } + reader.close(); + out.close(); + } + +} +" +A22793,"package Dancing; + +import java.io.*; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: kevin + * Date: 4/13/12 + * Time: 8:00 PM + * To change this template use File | Settings | File Templates. + */ +public class Dancing { + + public static Iterator parseSets(String filename) throws IOException { + File file = new File(filename); + final BufferedReader reader = new BufferedReader(new FileReader(filename)); + reader.readLine(); + //ehhh unclosed reader =P + + Iterator itr = new Iterator() { + + String line=null; + @Override + public boolean hasNext() { + try{ + + line=reader.readLine(); + } catch (Exception e){ + throw new RuntimeException(e); + } + return line!=null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public DanceSet next() { + if(line==null) + return null; + String[] split = line.split(""\\s""); + + int[] numbers = new int[split.length]; + for(int i =0;i smin && score <= min) + if (!hasSuprisesLeft) { + continue; + } else { + ++used; + hasSuprisesLeft = used < set.sunrises; + } + ++answer; + + } + + return answer; + } + + public static void main(String[] argv) throws IOException { + FileWriter output = new FileWriter(""output.dance.txt""); + BufferedWriter writer = new BufferedWriter(output); + Iterator itr = parseSets(argv[0]); + + int cnum = 1; + while(itr.hasNext()){ + int ans= findMinimumWithLowScore(itr.next()); + output.write(String.format(""Case #%d: %d\n"",cnum++,ans)); + + } + output.close(); + + } + +} +" +A21003,"package fixjava; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +public abstract class Filter { + + abstract boolean accept(T item); + + public static ArrayList list(Iterable collection, Filter filter) { + ArrayList filtered = new ArrayList(); + for (U item : collection) + if (filter.accept(item)) + filtered.add(item); + return filtered; + } + + public static HashSet set(Set set, Filter filter) { + HashSet filtered = new HashSet(); + for (U item : set) + if (filter.accept(item)) + filtered.add(item); + return filtered; + } + + public static HashMap mapKeys(Map map, Filter keyFilter) { + HashMap filtered = new HashMap(); + for (Entry ent : map.entrySet()) + if (keyFilter.accept(ent.getKey())) + filtered.put(ent.getKey(), ent.getValue()); + return filtered; + } + + public static HashMap mapValues(Map map, Filter valueFilter) { + HashMap filtered = new HashMap(); + for (Entry ent : map.entrySet()) + if (valueFilter.accept(ent.getValue())) + filtered.put(ent.getKey(), ent.getValue()); + return filtered; + } +} +" +A20363,"package bsmall; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Vector; + +public class Bsmall { + + /** + * @param args + */ + public static void main(String[] args) { + + int numLinhas = -1; + Vector linhas = new Vector(); + + try { + + BufferedReader input = new BufferedReader(new FileReader(""./src/bsmall/B-large.in"")); + + String linha; + + while((linha = input.readLine()) != null){ + if(numLinhas == -1) numLinhas = Integer.parseInt(linha); + else linhas.add(linha + "" ""); + } + + input.close(); + + BufferedWriter output = new BufferedWriter(new FileWriter(new File(""output.txt""))); + + for(int i = 0; i < numLinhas; i++){ + + int numCase = i+1; + + output.write(""Case #"" + numCase + "": ""); + + char[] letras = linhas.get(i).toCharArray(); + + String tmp = null; + + int N = -1; + int S = -1; + int p = -1; + Vector notes = new Vector(); + + for(int j=0; j bom = new Vector(); + Vector surprising = new Vector(); + + for( int k = 0; k < notes.size(); k++){ + + if(notes.get(k) >= p*3 - 2) bom.add(notes.get(k)); + else if( notes.get(k) >= p*3 - 4 && notes.get(k) > 1) surprising.add(notes.get(k)); + + } + +// System.out.println(bom.size() + "" "" + surprising.size()); + + int result = bom.size() + Math.min(surprising.size(), S); + + output.write(String.valueOf(result)); + output.newLine(); + + } + + + + output.close(); + + + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} +" +A22086,"import java.io.*; +public class Dancing { + public static void main(String[] args) { + try{ + BufferedWriter output = new BufferedWriter(new FileWriter(""output.txt"")); + BufferedReader input = new BufferedReader(new FileReader(""B-large.in"")); + int i = 0; + int j = Integer.parseInt(input.readLine()); + while(i < j) { + //get the line + String line = input.readLine(); + //split into data + String[] splitLine = line.split("" ""); + //get the useful data out of the line + int n = Integer.parseInt(splitLine[0]); + int s = Integer.parseInt(splitLine[1]); + int p = Integer.parseInt(splitLine[2]); + int[] scores = new int[n]; + //get out the total score + for(int foo = 0; foo < n; foo++) { + scores[foo] = Integer.parseInt(splitLine[foo + 3]); + } + //setup the output value + int caseValue = 0; + for(int score: scores) { + //if total score is less then value needed there is no chance + if(score >= p){ + int average = score / 3; + //if the average is higher then the scores are then 1 value is definately higher then p + if (average >= p) { + caseValue++; + //if average is 1 less then scores are there is a possibilty of a hit + } else if(average+1 == p) { + //if it's scores are not divisible by 3 at least one is higher then average + if(score % 3 != 0) { + caseValue++; + //if the total score is divisible by 3 then only a surprising score can make up difference + } else { + if(s>0){ + caseValue++; + s--; + } + } + //there is also a very specific case when the average is 2 less that you can use a surprising case to make up the difference + } else if (average+2 == p && score % 3 == 2 && s >0) { + caseValue++; + s--; + } + } + } + System.out.println(); + output.write(""Case #"" + (i+1) +"": "" + caseValue); + output.newLine(); + i++; + } + output.close(); + input.close(); + } catch(Exception e) {System.out.println(e);} + } +} +" +A22837,"import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.ArrayList; + + +public class GJ_QR_B { + + public static int solve(int N, int S, int p, int[] t){ + int[][] s = new int[31][2]; + for (int i=0; i<31; i++){ + if(i%3 == 0){ + if (3*p <= i) s[i][0] = 1; + if ( (p>=2 && 3*(p-1) == i) || 3*(p-1) < i) s[i][1] = 1; + } + if(i%3 == 1){ + if ( (p>=1 && 3*p-2 == i) || 3*p-2 < i) s[i][0] = 1; + if ( (p>=2 && 3*p-2 == i) || 3*p-2 < i) s[i][1] = 1; + } + if(i%3 == 2){ + if ( (p>=1 && 3*p-1 == i) || 3*p-1 < i) s[i][0] = 1; + if ( (p>=2 && 3*p-4 == i) || 3*p-4 < i) s[i][1] = 1; + } + //System.out.println(i+"":""+s[i][0]+""+""+s[i][1]); + } + ArrayList a01 = new ArrayList(); + ArrayList a11 = new ArrayList(); + ArrayList a10 = new ArrayList(); + ArrayList a00 = new ArrayList(); + for (int i=0; i ""+ res); + + return res; + } + + + public static void main(String[] args) throws NumberFormatException, IOException { + java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(new FileInputStream(""B-large.in""))); + java.io.BufferedWriter stdout = new java.io.BufferedWriter(new OutputStreamWriter(new FileOutputStream(""B-large.out""))); + int T = Integer.parseInt(stdin.readLine()); + //T = 1; + for (int ii=0; ii= P) + { + count++; + continue; + } + if(curr/3+1 >= P && S>0) + { + S--; + count++; + continue; + } + } + else if(curr%3 == 1) + { + if((curr+2)/3 >= P) + { + count++; + continue; + } + } + else if(curr%3 == 2) + { + if((curr+1)/3 >= P) + { + count++; + continue; + } + if((curr+1)/3+1 >= P && S>0) + { + S--; + count++; + continue; + } + } + } + + out.write(""Case #"" + casenum + "": ""+count+""\n""); + } + in.close(); + out.close(); + } +}" +A21349,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +/********************************************************************* + * FileUtils class of static constants and basic file checking routines. + * This is the header file of constants and methods that might be + * used in any and all contexts. + * + * Methods: + * public static void CheckArgs(int countArgs,String [] args,String usage) + * public static void CloseFile(PrintWriter theFile) + * public static void CloseFile(Scanner theFile) + * public static void CloseLogFile() + * public static PrintWriter PrintWriterOpen(String outFileName) + * public static PrintWriter PrintWriterOpen(String outFileName) + * public static Scanner ScannerOpen(String inFileName) + * public static void SetLogFile(String logFileName) + * public static void SetLogFile(PrintWriter logFile) + * + * @author Duncan Buell + * @version 1.00 Copyright Duncan A. Buell 1 May 2011 +**/ +public class FileUtils +{ + private static final String TAG = ""FileUtils: ""; + + public static PrintWriter logFile = null; + +/********************************************************************* + * Accessor methods +**/ +/********************************************************************* + * Mutator methods +**/ + +/********************************************************************* + * General methods +**/ +/********************************************************************* + * Method to check the number of arguments to the main. + * + * @param countArgs the number of required arguments + * @param args the argument list at the time the class is invoked + * @param usage descriptions of the required arguments +**/ + public static void CheckArgs(int countArgs,String [] args,String usage) + { + String message; + if(countArgs > args.length) + { + if(1 == countArgs) + { + message = ""ERROR: required "" + countArgs + + "" ("" + usage + "") arg not present""; + } + else + { + message = ""ERROR: required "" + countArgs + + "" ("" + usage + "") args not present""; + } + FileUtils.logFile.printf(""%s%n"",message); + FileUtils.logFile.flush(); + System.exit(1); + } + } // public static void checkArgs(int countArgs,String [] args,String usage) + +/********************************************************************* + * Method to close a PrintWriter file. + * @param theFile the PrintWriter file to close. +**/ + public static void CloseFile(PrintWriter theFile) + { +// FileUtils.logFile.printf(""%s enter (PrintWriter) CloseFile%n"",TAG); + theFile.flush(); + theFile.close(); +// FileUtils.logFile.printf(""%s leave (PrintWriter) CloseFile%n"",TAG); + } // public static void CloseFile(PrintWriter theFile) + +/********************************************************************* + * Method to close a Scanner file. + * @param theFile The Scanner file to close. +**/ + public static void CloseFile(Scanner theFile) + { +// FileUtils.logFile.printf(""%s enter (Scanner) CloseFile%n"",TAG); + theFile.close(); +// FileUtils.logFile.printf(""%s leave (Scanner) CloseFile%n"",TAG); + } // public static void CloseFile(Scanner theFile) + +/********************************************************************* + * Method to close the PrintWriter class log file. +**/ + public static void CloseLogFile() + { +// FileUtils.logFile.printf(""%s enter (PrintWriter) CloseLogFile%n"",TAG); + FileUtils.logFile.flush(); + FileUtils.logFile.close(); +// FileUtils.logFile.printf(""%s leave (PrintWriter) CloseLogFile%n"",TAG); + } // public static void CloseLogFile() + +/********************************************************************* + * PrintWriterOpen method to open a file as a PrintWriter. + * + * The main purpose of this method is to do the error checking in + * a subordinate method so as not to clutter up the code flow + * in methods that have to open files. + * + * @param outFileName the String name of the file to open + * @return The opened PrintWriter known to be not null +**/ + public static PrintWriter PrintWriterOpen(String outFileName) + { + PrintWriter localPrintWriter = null; + +// FileUtils.logFile.printf(""%s enter PrintWriterOpen%n"",TAG); + + if(outFileName.equals(""System.out"")) + { + localPrintWriter = new PrintWriter(System.out); + } + else + { + try + { + localPrintWriter = new PrintWriter(new File(outFileName)); + } + catch (FileNotFoundException fileException) + { + FileUtils.logFile.println(TAG + ""FILE ERROR opening outFile "" + + outFileName); + FileUtils.logFile.println(fileException.getMessage()); + FileUtils.logFile.println(""in"" + System.getProperty(""user.dir"")); + FileUtils.logFile.flush(); + System.exit(1); + } + catch (SecurityException secException) + { + FileUtils.logFile.println(TAG + ""SECURITY ERROR opening outFile "" + + outFileName); + FileUtils.logFile.println(secException.getMessage()); + FileUtils.logFile.println(""in"" + System.getProperty(""user.dir"")); + FileUtils.logFile.flush(); + System.exit(1); + } + } + +// FileUtils.logFile.printf(""%s leave PrintWriterOpen%n"",TAG); + return localPrintWriter; + } // public static PrintWriter PrintWriterOpen(String outFileName) + +/********************************************************************* + * ScannerOpen method to open a file as a Scanner. + * + * The main purpose of this method is to do the error checking in + * a subordinate method so as not to clutter up the code flow + * in methods that have to open files. + * + * @param inFileName the String name of the file to open + * @return The opened Scanner known to be not null +**/ + public static Scanner ScannerOpen(String inFileName) + { + Scanner localScanner = null; + +// FileUtils.logFile.printf(""%s enter ScannerOpen%n"",TAG); + if(inFileName.equals(""System.in"")) + { + localScanner = new Scanner(System.in); + } + else + { + try + { + localScanner = new Scanner(new File(inFileName)); + } + catch (FileNotFoundException ex) + { + FileUtils.logFile.println(""TAG + ERROR opening inFile "" + inFileName); + FileUtils.logFile.println(ex.getMessage()); + FileUtils.logFile.println(""in"" + System.getProperty(""user.dir"")); + FileUtils.logFile.flush(); + System.exit(1); + } + } + +// FileUtils.logFile.printf(""%s leave ScannerOpen%n"",TAG); + return localScanner; + } // public static Scanner ScannerOpen(String inFileName) + +/********************************************************************* + * Method to set the logFile given the name of the file. + * + * @param logFileName the String name of the log file. +**/ + public static void SetLogFile(String logFileName) + { + FileUtils.logFile = FileUtils.PrintWriterOpen(logFileName); + } + +/********************************************************************* + * Method to set the logFile given the PrintWriter file. + * + * @param logFile the PrintWriter log file. +**/ + public static void SetLogFile(PrintWriter logFile) + { + FileUtils.logFile = logFile; + } + +/********************************************************************* + * Method to convert a string to a double with error checking. + * + * @param ss the String value to convert. + * @param value the default value for an empty string. + * @return the converted value as a Double. +**/ + static public Double StringToDouble(String ss, Double value) + { + Double returnValue; + + returnValue = value; + ss = ss.trim(); + if(0 != ss.length()) + { +// FileUtils.logFile.printf(""nonempty string %s%n"", ss); + returnValue = Double.valueOf(ss); + } + + return returnValue; + } // static public Double stringToDouble(String s, Double value) + +/********************************************************************* + * Method to convert a string to an integer with error checking. + * + * @param ss the String value to convert. + * @param value the default value for an empty string. + * @return the converted value as an Integer. +**/ + static public Integer StringToInteger(String ss, Integer value) + { + Integer returnValue; + + returnValue = value; + ss = ss.trim(); + if(0 != ss.length()) + { +// FileUtils.logFile.printf(""nonempty string %s%n"", ss); + returnValue = Integer.valueOf(ss); + } + + return returnValue; + } // static public Integer stringToInteger(String s, Integer value) + +} // public class FileUtils +" +A21196,"package codeJam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class Dance { + + public static void main(String[] args) { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + try { + FileWriter fstream = new FileWriter(""Dance.txt""); + BufferedWriter out = new BufferedWriter(fstream); + int noTestCases = Integer.parseInt(in.readLine()); + for (int i = 1; i <= noTestCases; i++) { + out.write(""\nCase #"" + i + "": ""); + String[] inputs = in.readLine().split("" ""); + int surprise = Integer.parseInt(inputs[1]); + int minMark = Integer.parseInt(inputs[2]); + int result = 0; + List lessmarks = new ArrayList(); + for (int j = 3; j < inputs.length; j++) { + int div = Integer.parseInt(inputs[j]) / 3; + int mod = Integer.parseInt(inputs[j]) % 3; + if (mod > 0) { + div++; + } + if (div >= minMark) { + result++; + } else if (Integer.parseInt(inputs[j]) > 0) { + lessmarks.add(Integer.parseInt(inputs[j])); + } + } + if (surprise > 0 && !lessmarks.isEmpty()) { + int ite = 0; + for (int z = 0; z < lessmarks.size() && surprise > 0; z++) { + ite++; + if (ite > lessmarks.size() * 3 && surprise == Integer.parseInt(inputs[1])) { + break; + } + int mark = lessmarks.get(z); + int div = mark / 3; + int mod = mark % 3; + if (mod > 0) div++; + if (minMark - div > 2) continue; + div++; + if (div >= minMark) { + result++; + lessmarks.remove(z); + } + surprise--; + if (z + 1 == lessmarks.size() && surprise > 0) { + z = 0; + } + } + } + out.write(Integer.toString(result)); + } + out.close(); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} +" +A20355,"package br.com.feasoft.jam; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * User: Homer + * Date: 4/13/12 + * Time: 9:15 PM + */ +public class Dance { + + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(System.in); + int numberOfCases = scanner.nextInt(); + + for (int i = 0; i < numberOfCases; i++) { + int numberOfGooglers = scanner.nextInt(); + int surprisingScore = scanner.nextInt(); + int floorScore = scanner.nextInt(); + + List scores = new ArrayList(); + for (int j = 0; j < numberOfGooglers; j++) { + scores.add(scanner.nextInt()); + } + + int answer = solve(surprisingScore, floorScore, scores); + System.out.printf(""Case #%d: %d\n"", i + 1, answer); + } + } + + private static int solve(int surprisingScoresMaxQuantity, int floorScore, List scores) { + int surprisingFound = 0; + int surprisingMinScore = floorScore + 2*(floorScore-2); + int nonSurprisingMinScore = floorScore + 2*(floorScore-1); + + if (surprisingMinScore < 0) { + surprisingMinScore = floorScore; + } + if (nonSurprisingMinScore < 0) { + nonSurprisingMinScore = floorScore; + } + + int count = 0; + + for (Integer totalScore : scores) { + if (totalScore >= nonSurprisingMinScore) { + count++; + } else if (totalScore >= surprisingMinScore && surprisingScoresMaxQuantity > surprisingFound) { + count++; + surprisingFound++; + } + } + return count; + } + + +} +" +A21739,"package com.bertramtruong.utils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; + +/** + * This class provides advanced reading capabilities to files. + * @author Bertram + */ +public class DataReader { + + /** + * Character codes that define whitespace characters. + */ + private final int[] WHITESPACE_CODES = new int[]{-1, 10, 13, 32}; + /** + * Stores the working file. + */ + private File file; + /** + * Stores the active reader for the file. + */ + private BufferedReader br; + + /** + * Instantiate a new DataReader object. + * @param fileName - the string containing the file path to the input file. + */ + public DataReader(String fileName) { + File f = new File(fileName); + if (!f.exists()) { + System.err.println(""'"" + fileName + ""' does not exist.""); + return; + } + file = f; + + try { + // create the bufferedreader + br = new BufferedReader(new FileReader(file)); + } catch (FileNotFoundException x) { + System.err.println(""File was not found...""); + } + } + + /** + * Reads a line from the file. + * @param skipWS - whether to skip whitespace characters + * @return - a string containing a line from the file + * @throws IOException + */ + public String readLine(boolean skipWS) throws IOException { + if (br != null) { + if (skipWS) { + this.skipWhitespace(); + } + return br.readLine(); + } else { + System.err.println(""BufferedReader not initialized...""); + return """"; + } + } + + public String readLine() throws IOException { + return readLine(true); + } + + /** + * Reads the next integer from a file. + * @param skipWS - whether to skip whitespace characters + * @return - the next integer in the file + * @throws IOException + */ + public int readInt(boolean skipWS) throws IOException { + if (br != null) { + if (skipWS) { + this.skipWhitespace(); + } + StringBuilder sb = new StringBuilder(); + int code = br.read(); + while (Arrays.binarySearch(WHITESPACE_CODES, code) < 0) { + sb.append((char) code); + code = br.read(); + } + return Integer.parseInt(sb.toString()); + } else { + System.err.println(""BufferedReader not initialized...""); + return -1; + } + } + + public int readInt() throws IOException { + return readInt(true); + } + + /** + * Reads the next character from the file. + * @param skipWS - whether to skip whitespace characters + * @return - the next character in the file + * @throws IOException + */ + public char readChar(boolean skipWS) throws IOException { + if (br != null) { + if (skipWS) { + this.skipWhitespace(); + } + int code = br.read(); + char c = (char) code; + return c; + } else { + System.err.println(""BufferedReader not initialized...""); + return ' '; + } + } + + public char readChar() throws IOException { + return readChar(true); + } + + /** + * Reads the next boolean in the file. + * @param skipWS - whether to skip whitespace characters + * @return - the next boolean in the file + * @throws IOException + */ + public boolean readBoolean(boolean skipWS) throws IOException { + if (br != null) { + int n = readInt(skipWS); + return (n >= 1 ? true : false); + } else { + System.err.println(""BufferedReader not initialized...""); + return false; + } + } + + public boolean readBoolean() throws IOException { + return readBoolean(true); + } + + /** + * Reads the next string from the file. + * @param skipWS - whether to skip whitespace characters + * @return - the next string from the file + * @throws IOException + */ + public String readString(boolean skipWS) throws IOException { + if (br != null) { + if (skipWS) { + skipWhitespace(); + } + + // holds the string + StringBuilder sb = new StringBuilder(); + + // read a char + char c; + while ((c = readChar(false)) != ' ') { + sb.append(c); + } + + // return + return sb.toString(); + } else { + System.err.println(""BufferedReader not initialized...""); + return """"; + } + } + + public String readString() throws IOException { + return readString(true); + } + + /** + * Skip the following whitespace characters so that the pointer/caret goes to the next non-whitespace character. + * @throws IOException + */ + public void skipWhitespace() throws IOException { + if (br != null) { + int counter = 0; + br.mark(16); // marker so we can reset + int code = br.read(); + while (Arrays.binarySearch(WHITESPACE_CODES, code) >= 0) { + counter++; + code = br.read(); + } + // we know how many to skip now, so reset and skip + br.reset(); + br.skip(counter); + } else { + System.err.println(""BufferedReader not initialized...""); + return; + } + } +} +" +A20767,"import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.util.HashMap; +import java.util.Map; + + +public class main { + + /** + * @param args + */ + @SuppressWarnings(""deprecation"") + public static void main(String[] args) { + long now = System.currentTimeMillis(); + // TODO Auto-generated method stub + File file = new File(""./input.txt""); + FileInputStream fis = null; + BufferedInputStream bis = null; + DataInputStream dis = null; + try + { + fis = new FileInputStream(file); + bis = new BufferedInputStream(fis); + dis = new DataInputStream(bis); + int testCaseCount = Integer.parseInt(dis.readLine()), testCase; + for(testCase = 0; testCase < testCaseCount; testCase ++) + { + String[] line = dis.readLine().split("" ""); + int N = Integer.parseInt(line[0]) + , S = Integer.parseInt(line[1]) + , p = Integer.parseInt(line[2]) + , i; + int[] g = new int[N]; + for(i = 0; i < N; i ++) + { + g[i] = Integer.parseInt(line[i+3]); + } + // Program + int found = 0, similar = p + ( 2 * (p-1)), surprise = p + (2 * (p-2)); + if(similar < 0) + { + if(p > 0 ) + { + similar = 1; + } + else + { + similar = 0; + } + } + if(surprise < 0) + { + if(p > 0 ) + { + surprise = 1; + } + else + { + surprise = 0; + } + } + for(i = 0; i < N; i ++) + { + // Not surprising + if(g[i] >= similar) + { + found ++; + } + else if(g[i] >= surprise && S > 0) + { + found ++; + S --; + } + } + System.out.println(""Case #"" + (testCase + 1) + "": "" + found); + } + fis.close(); + bis.close(); + dis.close(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + +} +" +A20392,"import java.util.Scanner; + +public class Solution { + public static void main(String[] args){ + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + in.nextLine(); + int N, S, p, sure, av, note, result; + + for(int zz = 1; zz <= T;zz++){ + result=0; + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + sure = p + (p-1) + (p-1); + if (sure < p) + sure =p; + av = p + (p-2) + (p-2); + if (av < p) + av = p; + for (int i = 1; i <= N; i++){ + note = in.nextInt(); + if (note >= sure){ + result++; + } else if (( note < sure ) && (note >= av)){ + if (S > 0){ + S--; + result++; + } + } + } + in.nextLine(); + System.out.format(""Case #%d: %d\n"",zz, result); + } + } +} +" +A20812,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class ProblemB { + private String line = """"; + private String fileContents = """"; + private String delim = ""\r\n""; + private String fileName = ""B-small-attempt3.in""; + +// private String fileName = ""B-small-practice.in""; + + public void solve() { + StringTokenizer st = new StringTokenizer(fileContents, delim); + StringTokenizer lineToken = null; + int count = 1; + int testCases = 0; + int googlers = 0; + int surTripler = 0; + int p = 0; + int y = 0; + + ArrayList numbersList = new ArrayList(); + + testCases = Integer.parseInt(st.nextToken()); + + while (st.hasMoreTokens()) { + + line = st.nextToken(); + + System.out.print(""Case #""); + System.out.print(count++); + System.out.print("": ""); + + lineToken = new StringTokenizer(line, "" ""); + + googlers = Integer.parseInt(lineToken.nextToken()); + surTripler = Integer.parseInt(lineToken.nextToken()); + p = Integer.parseInt(lineToken.nextToken()); + + numbersList.clear(); + for (int i = 0; i < googlers; i++) { + numbersList.add(Integer.parseInt(lineToken.nextToken())); + } + + y = 0; + for (Integer number : numbersList) { +// +// if (number == 0) +// continue; +// +// if (p == 0) { +// y++; +// continue; +// } + + int mid = number / 3; + int rem = number % 3; +// int prem = number % p; + + switch (rem) { + case 0: + if (mid >= p) { + y++; + } else { + if (surTripler > 0 && mid > 0 && mid + 1 >= p) { + y++; + surTripler--; + } + } + break; + case 1: + if (mid >= p || mid + 1 >= p) { + y++; + } else { + if (surTripler > 0 && mid + 1 >= p) { + y++; + surTripler--; + } + } + break; + case 2: + if (mid + 1 >= p || mid >= p) { + y++; + } else { + if (surTripler > 0 && mid + 2 >= p) { + y++; + surTripler--; + } + } + break; + } + // if(prem == 0 && p*3 >= number) { + // y++; + // } + // else if(mid >= p) { + // y++; + // } + // else if(mid + rem >= p) { + // y++; + // } + // else if(rem == 1) { + // if(mid + rem >= p) { + // y++; + // } + // } + // else if(rem == 2) { + // if(mid + rem >= p) { + // y++; + // } + // } + // else if(mid + rem + 2 >= p && surTripler > 0 && mid > 2 && + // rem != 0) { + // y++; + // } + // else if((prem + 1 >= (p - 1)) && surTripler == 0) { + // y++; + // } + // else if((mid + 2 >= (p - 1) && surTripler > 0)) { + // y++; + // surTripler--; + // } + // else if((mid + 2 >= (p - 2) && surTripler > 0)) { + // y++; + // surTripler--; + // } + // else if(mid + 2 >= p && surTripler-- > 0 ) { + // y++; + // } + // else if(rem == 2) { + // System.out.print(mid + 1); + // System.out.print(mid + 1); + // System.out.print(mid); + // } + // else { + // System.out.print(mid+rem); + // System.out.print(mid); + // System.out.print(mid); + // } + } + System.out.println(y); + } + } + + public void readFile() { + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(fileName); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + StringBuilder sb = new StringBuilder(); + // Read File Line By Line + while ((strLine = br.readLine()) != null) { + // Print the content on the console + sb.append(strLine); + sb.append(delim); + } + // Close the input stream + in.close(); + + fileContents = sb.toString(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A22799,"package dancing.with.the.googlers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.URISyntaxException; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + private static String INPUT_FILE = ""B-large.in""; + private static String OUTPUT_FILE = ""B-large.out""; + + private static BufferedReader getInput() { + return new BufferedReader(new InputStreamReader(DancingWithTheGooglers.class.getResourceAsStream(INPUT_FILE))); + } + + private static PrintWriter getOutput() throws URISyntaxException, FileNotFoundException { + File inputFile = new File(DancingWithTheGooglers.class.getResource(INPUT_FILE).toURI()); + File packageDirectory = inputFile.getParentFile(); + File outputFile = new File(packageDirectory, OUTPUT_FILE); + return new PrintWriter(outputFile); + } + + + public static void main(String[] args) throws Throwable { + BufferedReader br = getInput(); + PrintWriter pw = getOutput(); + + int numTestCases = new Integer(br.readLine().trim()); + + for (int testCase = 1; testCase <= numTestCases; testCase++) { + String line = br.readLine(); + Scanner read = new Scanner(line); + + int numGooglers = read.nextInt(); + int numSurprisingTriplets = read.nextInt(); + int bestResult = read.nextInt(); + + int doesNotRequireSurprising = 0; + int requiresSurprising = 0; + int neverMeetsBestResult = 0; + + for (int googler = 0; googler < numGooglers; googler++) { + int total = read.nextInt(); + int avg = total / 3; + int diff = total - (avg * 3); + + if (total == 0 && bestResult > 0) { + neverMeetsBestResult++; + } + else if (bestResult <= avg) { + doesNotRequireSurprising++; + } + else if (bestResult == (avg + 1)) { + + switch (diff) { + case 0: + requiresSurprising++; + break; + case 1: + doesNotRequireSurprising++; + break; + case -1: + requiresSurprising++; + break; + case 2: + doesNotRequireSurprising++; + break; + case -2: + requiresSurprising++; + break; + default: + neverMeetsBestResult++; + break; + } + + } + else if (bestResult == (avg + 2)) { + + switch (diff) { + case 2: + requiresSurprising++; + break; + default: + neverMeetsBestResult++; + break; + } + + } + else { + neverMeetsBestResult++; + } + } + + //System.out.println(""does not requires: "" + doesNotRequireSurprising); + //System.out.println(""requires: "" + requiresSurprising); + //System.out.println(""never: "" + neverMeetsBestResult); + + int maxGooglersWithBestResult = doesNotRequireSurprising; + if (numSurprisingTriplets < requiresSurprising) { + maxGooglersWithBestResult += numSurprisingTriplets; + } + else { + maxGooglersWithBestResult += requiresSurprising; + } + + pw.println(""Case #"" + testCase + "": "" + maxGooglersWithBestResult); + + } + + pw.close(); + br.close(); + } + +} +" +A21668,"package codejam.dancing; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + static int suprising, minScore; + public static void main(String[] args){ + try { + // open input file + BufferedReader in = new BufferedReader ( new InputStreamReader (System.in)); + BufferedReader file = new BufferedReader (new FileReader(in.readLine())); + // create output file + FileWriter fstream = new FileWriter(""output.out""); + BufferedWriter out = new BufferedWriter(fstream); + + // Variables + StringTokenizer strtok; + String str, tok; + int entries, count, googlers, res, g_count,temp; + + // retrieve number of entries + entries = new Integer(file.readLine()); + System.out.println(""Entries : "" + entries); + + count = 0; + // read lines + while (((str = file.readLine())!=null) & (count <= entries)) + { + res = 0; + strtok = new StringTokenizer(str); + // number of googlers + googlers = Integer.parseInt(strtok.nextToken()); + System.out.println(""Googlers : ""+ googlers); + // number of suprising entries + suprising = Integer.parseInt(strtok.nextToken()); + System.out.println(""Suprising Scores : "" + suprising); + // minimum score + minScore = Integer.parseInt(strtok.nextToken()); + System.out.println(""Minimum Score : "" + minScore); + + g_count = 0; + while (g_count < googlers) + { + //temp = Integer.parseInt(strtok.nextToken()); + //System.out.println(temp); + res += evalScore(Integer.parseInt(strtok.nextToken())); + g_count++; + } + System.out.println(""finished?""); + count++; + out.write(""Case #""+count+"": ""+res+""\n""); + } + out.close(); + } + catch(Exception e){ + + } + } + + public static int evalScore(int score) + { + // check for non suprising results + System.out.print(""[""+ minScore + ""|"" + score+""]""); + if (score >= (3*minScore - 2)) + { + System.out.print("" : 1\n""); + return 1; + } else if (score == 0){ + System.out.print("" : 0\n""); + return 0; + } else { + // check for suprising results + if (suprising > 0){ + if ((score < (3*minScore - 2))&(score >= (3*minScore - 4))) + { + suprising--; + System.out.print("" : 1\n""); + return 1; + } + } + } + System.out.print("" : 0\n""); + return 0; + } +} +" +A22893,"package dance; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.Arrays; + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + + FileInputStream fstream; + try { + + FileOutputStream fos = new FileOutputStream(""dance.out""); + System.setOut(new PrintStream(fos, true)); + fstream = new FileInputStream(""B-large.in""); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + int num = Integer.parseInt(br.readLine()); + int i = 0; + while ((strLine = br.readLine()) != null) { + i++; + System.err.println(strLine); + String[] splits= strLine.split("" ""); + int googlers =Integer.parseInt(splits[0]); + int surprising =Integer.parseInt(splits[1]); + int min_score =Integer.parseInt(splits[2]); + int[] score_for_googler = new int[googlers]; + for (int j = 0; j < googlers; j++) { + score_for_googler[j]=Integer.parseInt(splits[j+3]); + } +// System.err.println(""Googlers:""+googlers); +// System.err.println(""surprising: ""+surprising); +// System.err.println(""min score ""+min_score); +// System.err.println(""scores""+Arrays.toString(score_for_googler)); + int result=0; + + + int num_surprised=0; + int min_unsurprised=3*min_score-2; + int min_surprised=3*min_score-4; + if(min_surprised<0) + min_surprised=0; + for (int current_score : score_for_googler) { + + if(current_score==0) + continue; + if(current_score>=min_unsurprised) + result++; + else if (current_score>=min_surprised) { + if(num_surprised in = null; + try { + in = readFile(""input.txt""); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + String result = doit(Integer.parseInt(in.remove(0)), in); + + try { + writeFile(result, ""output.txt""); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static ArrayList readFile(String filename) throws IOException{ + + ArrayList out = new ArrayList(); + + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(filename); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + while ((strLine = br.readLine()) != null){ + // Print the content on the console + out.add(strLine); + } + + //Close the input stream + in.close(); + + return out; + } + + public static String doit(int c, ArrayList cases){ + // Main logic + + StringBuilder out = new StringBuilder(); + + for(int i = 0; i < c; i++){ + String s = cases.get(i); + + int for_sure = 0; + int if_surprise = 0; + + ArrayList sa = new ArrayList(); + for(String l : s.split("" "")){ + sa.add(Integer.parseInt(l)); + } + int N = sa.get(0); + int S = sa.get(1); + int P = sa.get(2); + + for(int ii = 3; ii <= N+2; ii++){ + int v = sa.get(ii); + if(Math.ceil((double)v/3) >= P){ + for_sure++; + continue; + } + + double d = v-2*Math.floor((double)v/3); + if(d == Math.ceil((double)v/3) && d != 0){ + d++; + } + if(d >= P){ + if_surprise++; + } + } + + out.append(""Case #""+(i+1)+"": ""+(for_sure+Math.min(S, if_surprise))); + + if(i != c-1){ + out.append(""\n""); + } + } + + return out.toString(); + } + + public static void writeFile(String output, String file) throws IOException{ + FileWriter fstream = new FileWriter(file); + BufferedWriter out = new BufferedWriter(fstream); + out.write(output); + out.close(); + } + +} +" +A21050,"import java.util.*; + +class b +{ + public static void main(String [] args) + { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int t=1;t<=T;++t) + { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int max = 0; + int trips [] = new int[N]; + for(int i=0;i= p) + { + max++; + } + else + { + if(S > 0 && div3+1 >= p && div3+1 <= 10 && div3-1 >= 0) + { + max++; + S--; + } + } + } + else if(diff == 1) + { + //Still need to allocate 1 more + if(div3 >= p) + { + ++max; + } + else if(div3+1 >= p && div3+1 <= 10) + { + ++max; + } + } + else if(diff == 2) + { + //Still need to allocate 2 more + if(div3 >= p) + { + max++; + } + else + { + if(div3+1 >= p && div3+1 <= 10) + { + max++; + } + else if(S > 0 && div3+2 >= p && div3+2 <= 10) + { + max++; + S--; + } + } + } + } + System.out.println(""Case #""+t+"": "" + max); + } + } +} +" +A21249,"import java.util.*; +import java.io.*; + +public class q2 { + + /** + * @param args + */ + public static void main(String[] args) { + File file = new File(""C:/Users/Raja/workspace/GCJ/src/in.txt""); + + + int N,S,p; + int[] sums; + int norm,surp,ans; + + try{ + Scanner s = new Scanner(file); + int num = Integer.parseInt(s.nextLine()); + for (int i = 0;i= 3*p-2) + norm++; + else if (sums[j] >= 3*p-4 && sums[j] > 1) + surp++; + } + if (surp > S) + ans = norm + S; + else + ans = norm + surp; + + System.out.println(""Case #""+(i+1)+"": ""+ans); + } + } + catch (FileNotFoundException e){ + e.printStackTrace(); + } + + } + +} +" +A20314," +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +/** + * + * @author dafferianto + */ +public class DancingWithTheGooglers { + private static Scanner inputStream; + private static PrintWriter outputStream; + private static int T, N, S, p, div, mod, counter; + private static int[] t; + private static ArrayList aList; + public static void main(String[] args) throws FileNotFoundException, IOException { + try { + inputStream = new Scanner(new FileReader(args[0])); + outputStream = new PrintWriter(new FileWriter(""OutputDancingWithTheGooglers.txt"")); + + T = inputStream.nextInt(); + //T = Integer.parseInt(inputStream.nextLine()); + + for (int i = 0; i < T; i++) { // For each test case + N = inputStream.nextInt(); + S = inputStream.nextInt(); + p = inputStream.nextInt(); + aList = new ArrayList(); + for (int j = 0; j < N; j++) { + aList.add(inputStream.nextInt()); + } + + Collections.sort(aList); + + counter = 0; + + for (int j = 0; j < N; j++) { + int ti = aList.get(j); + if (ti / 3 >= p) { + counter = counter + N - j; + break; + } else { + if (ti-p < 0) { + continue; + } + int res = (ti - p) / 2; + if (S == 0){ + if (isLegal(p, res, ti-p-res) && (!isSurprising(p, res, ti-p-res))) + counter++; + continue; + } + if (isLegal(p, res, ti-p-res)){ + if (isSurprising(p, res, ti-p-res)){ + S--; + } + counter++; + } + } + + } + outputStream.println(""Case #"" + (i+1) + "": "" + counter); + //System.out.println(""Case #"" + (i+1) + "": "" + counter); + } + + } finally { + if (inputStream != null) { + inputStream.close(); + } + if (outputStream != null) { + outputStream.close(); + } + } + } + + private static boolean isLegal(int p, int res, int i) { + if ((Math.abs(p - res) <= 2) && (Math.abs(res - i) <= 2) && (Math.abs(p - i) <= 2)) { + return true; + } + return false; + } + + private static boolean isSurprising(int p, int res, int i) { + if ((Math.abs(p - res) == 2) || (Math.abs(res - i) == 2) || (Math.abs(p - i) == 2)) { + return true; + } + return false; + } +} +" +A22829,"package mgg.problems; + +import java.util.ArrayList; +import java.util.List; + +import mgg.utils.CombinatoryUtils; +import mgg.utils.FileUtil; +import mgg.utils.StringUtils; +import mgg.utils.Triplet; + +/** + * @author manolo + * @date 14/04/12 + */ +public class ProblemB { + + public final static String EXAMPLE_IN = ""B-example.in""; + public final static String EXAMPLE_OUT = ""B-example.out""; + + public final static String B_SMALL_IN = ""B-small-attempt0.in""; + public final static String B_SMALL_OUT = ""B-small-attempt0.out""; + + public final static String B_LARGE_IN = ""B-large.in""; + public final static String B_LARGE_OUT = ""B-large.out""; + + public final static String delim = "" ""; + + public static String solve(FileUtil util) { + + String line = util.getLine(); + List listOfArgs = StringUtils.stringWithIntegersToList(line, delim); + //System.out.println(""\tArgs = "" + listOfArgs); + + int googlers = listOfArgs.get(0); + System.out.println(""\tGooglers = "" + googlers); + + int surprisingScores = listOfArgs.get(1); + System.out.println(""\tSurprising scores = "" + surprisingScores); + + int leastScore = listOfArgs.get(2); + System.out.println(""\tMinimum = "" + leastScore); + + List listOfScores = listOfArgs.subList(3, listOfArgs.size()); + System.out.println(""\tScores = "" + listOfScores); + + List listOfTriplets, newListOfTriplets = new ArrayList(); + int surprisingScoresLeft = surprisingScores; +// int [] withTriplets = new int[3]; +// withTriplets[0] = 0; +// withTriplets[1] = 0; +// withTriplets[2] = 0; + + int greatGooglers = 0; + for(int score : listOfScores){ + + listOfTriplets = CombinatoryUtils.possibleTriplets(score); + //System.out.println(""\tPossible triplets: "" + listOfTriplets); + + newListOfTriplets = new ArrayList(); + for(Triplet t : listOfTriplets){ + if (t.max() >= leastScore){ + newListOfTriplets.add(t); + } + } + System.out.println(""\tNew possible triplets: "" + newListOfTriplets); + +// withTriplets[newListOfTriplets.size()]++; + + if(newListOfTriplets.size() == 2){ + greatGooglers++; + } + if(newListOfTriplets.size() == 1){ + if(newListOfTriplets.get(0).isSurprising() && surprisingScoresLeft > 0){ + greatGooglers++; + surprisingScoresLeft--; + } + if(!newListOfTriplets.get(0).isSurprising()){ + greatGooglers++; + } + } + + } + + return """" + greatGooglers; + +// System.out.println(""\t"" + withTriplets[0] + "" with 0 triples""); +// System.out.println(""\t"" + withTriplets[1] + "" with 1 triples""); +// System.out.println(""\t"" + withTriplets[2] + "" with 2 triples""); +// +// if((surprisingScores == 0) && (withTriplets[1] > 0)){ +// return ""0""; +// } +// if(surprisingScores > withTriplets[1]){ +// return ""0""; +// } +// else { +// return """" + (withTriplets[1] + withTriplets[2]); +// } + } + + private static Triplet takeMax(List listOfTriplets) { + + Triplet max_t = new Triplet(-1, -1, -1); + for(Triplet t : listOfTriplets){ + if(!max_t.isSurprising()){ + if(t.isSurprising()){ + max_t = t; + } + else if(t.max() > max_t.max()){ + max_t = t; + } + } + + + } + return max_t; + + } + +} +" +A22108,"import java.io.*; +import java.util.*; + +class q2 { + public static void main(String args[]) { + Scanner obj = new Scanner(System.in); + int T = obj.nextInt(); + try { + FileOutputStream out = new FileOutputStream(""myfile.txt""); + PrintStream p = new PrintStream(out); + + for (int i = 0; i < T; i++) { + int N = obj.nextInt(); + int S = obj.nextInt(); + int pp = obj.nextInt(); + int count2 = 0; + int count4 = 0; + for (int j = 0; j < N; j++) { + int num = obj.nextInt(); + + if (num >= (3 * pp - 2)) { + count2++;} + else if(num ==0){ + count2=count2; + } else if (num >= (3 * pp - 4)) { + count4++; + } + } + System.out.println(count4); + if (count4 > S) { + count2 = count2 + S; + } else { + count2 = count2 + count4; + } + p.print(""Case #"" + (i+1) + "": "" + count2); + p.println(); + } + p.close(); + } catch (Exception e) { + System.err.println(""Error writing to file""); + } + } +}" +A21786,"import java.util.Scanner; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.URLConnection; +import java.util.InputMismatchException; +import java.util.Locale; +import java.net.URL; +import java.io.PrintStream; +import java.net.Socket; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.File; +import java.io.BufferedInputStream; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + * @author @zhendeaini6001 + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream = System.in; + OutputStream outputStream = System.out; + Scanner in = new Scanner(inputStream); + PrintWriter out = new PrintWriter(outputStream); + TaskB solver = new TaskB(); + solver.solve(1, in, out); + out.close(); + } +} + +class TaskB { + + public void solve(int testNumber, Scanner in_t, PrintWriter out) { + In in = new In(""D:\\codeforce\\src\\B-large.in""); + Out output = new Out(""D:\\codeforce\\src\\B-large.out""); + int T = in.readInt(); + for (int k = 1; k <= T; ++k){ + int N = in.readInt(); + int S = in.readInt(); + int p = in.readInt(); + int[] input = new int[N]; + for (int i = 0; i < N; ++i){ + input[i] = in.readInt(); + } + int res = 0; + for (int i = 0; i < N; ++i){ + if (input[i] >= p * 3 - 2){ + ++res; + }else if (input[i] >= p * 3 - 4 && input[i] != 0 && S > 0){ + ++res; + --S; + } + } + output.println(""Case #"" + k + "": "" + res); + } + return; + } +} + +class In { + private Scanner scanner; + + // assume Unicode UTF-8 encoding + //private String charsetName = ""UTF-8""; + + private String charsetName = ""ISO-8859-1""; + + // assume language = English, country = US for consistency with System.out. + private Locale usLocale = new Locale(""en"", ""US""); + + /** + * Create an input stream for standard input. + */ + public In() { + scanner = new Scanner(new BufferedInputStream(System.in), charsetName); + scanner.useLocale(usLocale); + } + + /** + * Create an input stream from a socket. + */ + public In(Socket socket) { + try { + InputStream is = socket.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + socket); + } + } + + /** + * Create an input stream from a URL. + */ + public In(URL url) { + try { + URLConnection site = url.openConnection(); + InputStream is = site.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + url); + } + } + + /** + * Create an input stream from a file. + */ + public In(File file) { + + try { + scanner = new Scanner(file, charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + file); + } + } + + + /** + * Create an input stream from a filename or web page name. + */ + public In(String s) { + + try { + // first try to read file from local file system + File file = new File(s); + if (file.exists()) { + scanner = new Scanner(file, charsetName); + scanner.useLocale(usLocale); + return; + } + + // next try for files included in jar + URL url = getClass().getResource(s); + + // or URL from web + if (url == null) { url = new URL(s); } + + URLConnection site = url.openConnection(); + InputStream is = site.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + s); + } + } + + /** + * Is the input stream empty? + */ + public boolean isEmpty() { + return !scanner.hasNext(); + } + + /** + * Does the input stream have a next line? + */ + public boolean hasNextLine() { + return scanner.hasNextLine(); + } + + /** + * Read and return the next line. + */ + public String readLine() { + String line; + try { line = scanner.nextLine(); } + catch (Exception e) { line = null; } + return line; + } + + + + // return rest of input as string + /** + * Read and return the remainder of the input as a string. + */ + public String readAll() { + if (!scanner.hasNextLine()) { return null; } + + // reference: http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html + return scanner.useDelimiter(""\\A"").next(); + } + + + + /** + * Return the next string from the input stream. + */ + public String readString() { + return scanner.next(); + } + + /** + * Return the next int from the input stream. + */ + public int readInt() { + return scanner.nextInt(); + } + + /** + * Return the next double from the input stream. + */ + public double readDouble() { + return scanner.nextDouble(); + } + + + /** + * Read ints from file + */ + public static int[] readInts(String filename) { + In in = new In(filename); + String[] fields = in.readAll().trim().split(""\\s+""); + int[] vals = new int[fields.length]; + for (int i = 0; i < fields.length; i++) + vals[i] = Integer.parseInt(fields[i]); + return vals; + } + + /** + * Close the input stream. + */ + public void close() { scanner.close(); } + + + + } + +class Out { + + // force Unicode UTF-8 encoding; otherwise it's system dependent + private static final String UTF8 = ""UTF-8""; + + + private PrintWriter out; + + /** + * Create an Out object using an OutputStream. + */ + public Out(OutputStream os) { + try { + OutputStreamWriter osw = new OutputStreamWriter(os, UTF8); + out = new PrintWriter(osw, true); + } + catch (IOException e) { e.printStackTrace(); } + } + + /** + * Create an Out object using standard output. + */ + public Out() { this(System.out); } + + /** + * Create an Out object using a Socket. + */ + public Out(Socket socket) { + try { + OutputStream os = socket.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os, UTF8); + out = new PrintWriter(osw, true); + } + catch (IOException e) { e.printStackTrace(); } + } + + /** + * Create an Out object using a file specified by the given name. + */ + public Out(String s) { + try { + OutputStream os = new FileOutputStream(s); + OutputStreamWriter osw = new OutputStreamWriter(os, UTF8); + out = new PrintWriter(osw, true); + } + catch (IOException e) { e.printStackTrace(); } + } + + /** + * Close the output stream. + */ + public void close() { out.close(); } + + + + /** + * Print an object and then terminate the line. + */ + public void println(Object x) { + out.println(x); + } + + + + } + +" +A22835,"import java.util.*; +import java.io.*; +import java.math.*; + +public class Prac2 { + public static void main(String[] arg){ + try{ + Scanner in=new Scanner(new File(""sample"")); + //BufferedReader br=new BufferedReader(new FileReader(""sample"")); + //int numCases=in.nextInt();//br.readLine();br.readLine(); + // BufferedWriter bw=new BufferedWriter(new FileWriter(""output.txt"")); + int numCases=in.nextInt(); + int counter=1; + //in.nextLine(); + counter=1; + while (counter!=numCases+1){ + int N=in.nextInt(); + int S=in.nextInt(); + int p=in.nextInt(); + int count=0; + while (N!=0){ + int cur=in.nextInt(); + if (cur/3>p){ + int third=cur/3; + int pair=cur-cur/3; + if (Math.abs(third-pair/2)<=1){ + count++; + }else{ + if (Math.abs(third-pair/2)==2 && S>0){ + S=S-1; + count++; + } + } + }else{ + int pair=cur-p; + if (cur>=p && Math.abs(p-pair/2)<=1){ + count++; + }else{ + if (Math.abs(p-pair/2)==2 && S>0){ + S=S-1; + count++; + } + } + } + N=N-1; + } + + System.out.println(""Case #""+counter+"": ""+count); + + counter++; + } + + }catch (FileNotFoundException e){ + + }catch (IOException e){ + } + } +}" +A21227,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringTokenizer; + +public class C implements Runnable { + + private StringTokenizer st; + private BufferedReader in; + private PrintWriter out; + + final String file = ""B-large""; + + Map cache = new HashMap(); + + public void solve(int test) throws IOException { + out.print(""Case #"" + (test + 1) + "": ""); + if (test == 52) { + System.out.println(); + } + // ======================================================================= + int totalEmp = nextInt(); + int surprise = nextInt(); + int threshold = nextInt(); + + int ans = 0; + List scores = new ArrayList(); + + for (int i = 0; i < totalEmp; i++) + scores.add(nextInt()); + if (threshold == 0) { + out.println(String.valueOf(totalEmp)); + return; + } + Collections.sort(scores); + int min = (threshold * 3) - 4; + min = Math.max(min, 0); + for (int i : scores) { + if (threshold > i) + continue; + if (i >= (threshold) * 3 - 2) { + ans++; + continue; + } + if ((i == 1) && threshold <= i) { + ans++; + continue; + } + if (surprise > 0 && i >= (threshold * 3) - 4) { + surprise--; + ans++; + continue; + } + } + // ======================================================================= + + out.println(String.valueOf(ans)); + } + + public void run() { + try { + // in = new BufferedReader(new FileReader( + // ""C:\\Vinay\\gcj\\GCJ\\src\\C-small.in"")); + // out = new PrintWriter(""C:\\Vinay\\gcj\\GCJ\\src\\C-small.out""); + + in = new BufferedReader(new FileReader(file + "".in"")); + out = new PrintWriter(file + "".out""); + eat(""""); + int tests = nextInt(); + for (int test = 0; test < tests; ++test) { + solve(test); + } + + out.close(); + } catch (Exception e) { + e.printStackTrace(); + failed = true; + } + } + + void eat(String s) { + st = new StringTokenizer(s); + } + + String next() throws IOException { + while (!st.hasMoreTokens()) { + String line = in.readLine(); + if (line == null) { + return null; + } + eat(line); + } + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + long nextLong() throws IOException { + return Long.parseLong(next()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + static boolean failed = false; + + public static void main(String[] args) { + Locale.setDefault(Locale.US); + Thread th = new Thread(new C()); + th.start(); + try { + th.join(); + } catch (InterruptedException iex) { + } + if (failed) { + throw new RuntimeException(); + } + } + +}" +A21350," +public class Goggledance { + private boolean isSurprising=false; + private boolean isCandidate=false; + int total,p; + public Goggledance(int total,int p){ + this.total=total; + this.p=p; + determinesurprising(); + } + private void determinesurprising() { + // TODO Auto-generated method stub + if(total/3>=p){ + isSurprising=false; + isCandidate=true; + return; + } + int left=total-p; + if(left<0){ + isSurprising=false; + isCandidate=false; + return; + } + int left1=left/2; + int left2=left-left1; + + if(p-left1<=1 && p-left2<=1){ + isSurprising=false; + isCandidate=true; + return; + } + if(p-left1<=2 && p-left2<=2){ + isSurprising=true; + isCandidate=true; + return; + } + + isSurprising=false; + isCandidate=false; + } + public boolean isSurprising() { + return isSurprising; + } + + public boolean isCandidate() { + return isCandidate; + } + + +} +" +A20427,"import java.util.Scanner; +import java.io.*; + +public class Prob2 { + public static void main(String[] args) throws IOException{ + Scanner in = new Scanner(new File(""D:/B-large.in"")); + PrintStream out = new PrintStream(new File(""D:/outputProb2.txt"")); + + int lineAmount = Integer.parseInt(in.nextLine()); + + for (int n = 1; n <= lineAmount; n++) { + int m = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int y = 0, spare = 0; + for (int i = 0; i < m; i++) { + int a = in.nextInt(); + + if (a == 0) { + if (p == 0) y++; + } + + else if (a % 3 == 0) { + int k = a / 3; + if (p <= k) y++; + else if (p == k + 1) spare++; + } + + else if (a % 3 == 1) { + int k = (a - 1) / 3; + if (p <= k + 1) y++; + } + + else { + int k = (a - 2) / 3; + if (p <= k + 1) y++; + else if (p == k + 2) spare++; + } + } + + if (s <= spare) y += s; + else y += spare; + + out.println(""Case #""+n+"": ""+y); + } + + in.close(); + out.close(); + + } +} +" +A20229,"package duarte.codejam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Googlers { + + private static int caseNumber = 1; + + public static void main(String[] args) throws IOException{ + + List entradas = new ArrayList(); + BufferedReader input = new BufferedReader(new FileReader(new File(""B-large.in""))); + input.readLine(); + while(input.ready()) + entradas.add(input.readLine()); + for(String s : entradas){ + String[] argumentos = s.split("" ""); + String[] notas = Arrays.copyOfRange(argumentos, 3, argumentos.length); + System.out.println(""Case #"" + caseNumber++ + "": ""+top(Integer.valueOf(argumentos[0]),Integer.valueOf(argumentos[1]),Integer.valueOf(argumentos[2]),notas)); + } + } + + public static int top(int qtdGooglers, int surpresas, int notaMinima, String... notasMaximas){ + int[][] triplets = new int[qtdGooglers][3]; + int googler = 0; + for(String notaMax : notasMaximas){ + int notaMaxi = Integer.valueOf(notaMax); + triplets[googler][0] = notaMaxi/3; + triplets[googler][1] = notaMaxi/3; + triplets[googler][2] = notaMaxi/3; + int diff = notaMaxi - (triplets[googler][0] + triplets[googler][1] + triplets[googler][2]); + if(diff > 0){ + triplets[googler][0] += Math.min(1, diff--); + triplets[googler][1] += diff; + } + googler += 1; + } + + List tripletsTop = new ArrayList(); + for(int[] triplet : triplets){ + if(temNotaMaiorOuIgual(triplet, notaMinima)){ + tripletsTop.add(triplet); + } + } + + List tripletsAltas = new ArrayList(); + + for(int[] triplet : triplets){ + if(tripletPossivel(triplet, notaMinima - 1) && !tripletsTop.contains(triplet)){ + tripletsAltas.add(triplet); + } + } + + + + return tripletsTop.size() + Math.min(tripletsAltas.size(), surpresas); + } + + private static boolean tripletPossivel(int[] triplet, int i) { + int notasProximas = 0; + if(triplet[0] == i) notasProximas++; + if(triplet[1] == i) notasProximas++; + if(triplet[2] == i) notasProximas++; + if (notasProximas < 2) return false; + return (triplet[0] + triplet[1] + triplet[2] > i ); + } + + private static boolean temNotaMaiorOuIgual(int[] triplet, int notaMinima) { + return (triplet[0] >= notaMinima || triplet[1] >= notaMinima || triplet[2] >= notaMinima ); + } + + public static int top(int qtdGooglers, int surpresas, int notaMinima, int... i) { + String[] notas = new String[i.length]; + for(int j = 0 ; j < i.length; j++) + notas[j] = String.valueOf(i[j]); + return top(qtdGooglers, surpresas, notaMinima, notas); + } + +} +" +A20447,"package codejam.suraj.quals2012.googlerese; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import codejam.suraj.quals2012.CodeJamSkeleton; + +public class Googlerese extends CodeJamSkeleton { + + public static Map map = + new HashMap(52); + + public static void initializeCharMap(){ + map.put('e','o'); + map.put('j','u'); + map.put('p','r'); + map.put('m','l'); + map.put('y','a'); + map.put('s','n'); + map.put('l','g'); + map.put('j','u'); + map.put('y','a'); + map.put('l','g'); + map.put('c','e'); + map.put('k','i'); + map.put('d','s'); + map.put('k','i'); + map.put('x','m'); + map.put('v','p'); + map.put('e','o'); + map.put('d','s'); + map.put('d','s'); + map.put('k','i'); + map.put('n','b'); + map.put('m','l'); + map.put('c','e'); + map.put('r','t'); + map.put('e','o'); + map.put('j','u'); + map.put('s','n'); + map.put('i','d'); + map.put('c','e'); + map.put('p','r'); + map.put('d','s'); + map.put('r','t'); + map.put('y','a'); + map.put('s','n'); + map.put('i','d'); + map.put('r','t'); + map.put('b','h'); + map.put('c','e'); + map.put('p','r'); + map.put('c','e'); + map.put('y','a'); + map.put('p','r'); + map.put('c','e'); + map.put('r','t'); + map.put('t','w'); + map.put('c','e'); + map.put('s','n'); + map.put('r','t'); + map.put('a','y'); + map.put('d','s'); + map.put('k','i'); + map.put('h','x'); + map.put('w','f'); + map.put('y','a'); + map.put('f','c'); + map.put('r','t'); + map.put('e','o'); + map.put('p','r'); + map.put('k','i'); + map.put('y','a'); + map.put('m','l'); + map.put('v','p'); + map.put('e','o'); + map.put('d','s'); + map.put('d','s'); + map.put('k','i'); + map.put('n','b'); + map.put('k','i'); + map.put('m','l'); + map.put('k','i'); + map.put('r','t'); + map.put('k','i'); + map.put('c','e'); + map.put('d','s'); + map.put('d','s'); + map.put('e','o'); + map.put('k','i'); + map.put('r','t'); + map.put('k','i'); + map.put('d','s'); + map.put('e','o'); + map.put('o','k'); + map.put('y','a'); + map.put('a','y'); + map.put('k','i'); + map.put('w','f'); + map.put('a','y'); + map.put('e','o'); + map.put('j','u'); + map.put('t','w'); + map.put('y','a'); + map.put('s','n'); + map.put('r','t'); + map.put('r','t'); + map.put('e','o'); + map.put('u','j'); + map.put('j','u'); + map.put('d','s'); + map.put('r','t'); + map.put('l','g'); + map.put('k','i'); + map.put('g','v'); + map.put('c','e'); + map.put('j','u'); + map.put('v','p'); + map.put('z','q'); + map.put('q','z'); + map.put(' ',' '); + } + + + + @Override + protected void handleTestCase(int testCaseNumber) throws IOException { + + String line = readLine(); + StringBuffer text = new StringBuffer(line.length()); + for(int i = 0; i < line.length(); ++i) + { + text.append(map.get(line.charAt(i))); + } + System.out.println(text); + addOutput(testCaseNumber, text.toString()); + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + initializeCharMap(); + CodeJamSkeleton testCase = new Googlerese(); + testCase.handleAllTestCases(args[0], args[1]); + + } + +} +" +A22364,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import java.util.Scanner; + +/** + * + * @author leonardo + */ +public class Dance { + + static boolean canBeSurprising(int x1, int x2, int x3) { + if (x1 > 10 || x2 > 10 || x3 > 10) + return false ; + + return (Math.abs(x1 -x2) >= 2) || (Math.abs(x1 -x3) >= 2) || (Math.abs(x2 -x3) >= 2) ; + } + + /*static boolean canBeSurprising(int r, int x, int p) { + boolean[] res = new boolean[2] ; + + if (r == 0) { + return canBeSurprising(x, x, x) || canBeSurprising(x-1, x+1, x) ; + } + else if (r == 1) { + return canBeSurprising(x+1, x, x, p, res) || canBeSurprising(x+1, x+1, x-1) ; + } + else { + canBeSurprising(x+2, x, x, p, res); + canBeSurprising(x, x+1, x+1, p, res) ; + } + return (! res[0] && res[1]) ? 1 : 0; + }*/ + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in) ; + int inputSize = Integer.parseInt(scanner.nextLine()) ; + + for(int i = 1; i <= inputSize; i++) { + String[] numbers = scanner.nextLine().split("" "") ; + + int n = Integer.parseInt(numbers[0]) ; + int s = Integer.parseInt(numbers[1]) ; + int p = Integer.parseInt(numbers[2]) ; + + int count = 0 ; + for(int googler = 0; googler < n; googler++) { + int score = Integer.parseInt(numbers[googler + 3]) ; + + int r = score % 3 ; + int x = score / 3 ; + + if (r == 0) { + + // possible maxs: x and x + 1 + + if (x >= p) + count++ ; + else if ((score > 0) && s > 0 && (x + 1) >= p) { + s-- ; + count++ ; + } + + } + + // r == 1 -> max = x + 1 + else if (r == 1 && (x + 1 >= p)) + count++ ; + + else { + + // possible maxs: x + 1 and x + 2 + + if ((x + 1) >= p) + count++ ; + else if ((x+2 <= 10) && (x+2 >= p) && (s > 0)) { + count++ ; + s-- ; + } + } + } + System.out.println(""Case #"" + i + "": "" + count) ; + } + } +} + +" +A20313," +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ +/** + * + * @author megaterik + */ +public class B { + + public static void main(String[] args) throws FileNotFoundException { + new B().solve(); + } + + void solve() throws FileNotFoundException { + Scanner in = new Scanner(new FileReader(""src/input.txt"")); + PrintWriter out = new PrintWriter(new FileOutputStream(""src/output.txt"")); + int testCases = in.nextInt(); + for (int t = 1; t <= testCases; t++) { + int n = in.nextInt(); + int surprise = in.nextInt(); + int required = in.nextInt(); + int[] a = new int[n]; + for (int i = 0; i < n; i++) { + a[i] = in.nextInt(); + } + Arrays.sort(a); + int res = 0; + for (int i = a.length - 1; i >= 0; i--) { + if (a[i] >= required + 2 * (required - 1)) { + res++; + } else if (surprise > 0 && a[i] >= required + 2 * Math.max(0, required - 2)) { + res++; + surprise--; + } else { + break; + } + } + out.println(""Case #"" + t + "": "" + res); + } + in.close(); + out.close(); + } +} +" +A20783,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Scanner; + + +public class Scores +{ + public static void main(String[] args) throws IOException + { + Scanner scan = new Scanner(new File(""B-small-attempt0.in"")); + FileWriter strm = new FileWriter(""out2.txt""); + BufferedWriter out = new BufferedWriter(strm); + int cases = scan.nextInt(); + scan.nextLine(); + int count = 1; + while(count - 1 < cases) + { + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int[] tots = new int[n]; + for(int i = 0;i= 3.0) + return true; + if(total < max) + return false; + total -= max; + return Math.abs(total / 2.0 - max) <= 2.0; + } + private static boolean surp(int max, int total) + { + if(max == 0) + return false; + if(total / max >= 3.0) + return false; + total -= max; + return Math.abs(total / 2.0 - max) >= 1.5; + } +} +" +A23078,"package ru.bobukh.problems; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Map; +import java.util.Scanner; + +/** + * + * @author anton.bobukh + */ +public class ProblemB_DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + Map mapping = ProblemA_SpeakingInTongues.GetMapping(); + + try (Scanner input = new Scanner(new BufferedReader(new FileReader(""C:\\Users\\maggot\\Desktop\\B-large.in"")))) { + int T = input.nextInt(); + input.nextLine(); + + try(PrintWriter output = new PrintWriter(""C:\\Users\\maggot\\Desktop\\output.txt"")) { + for(int k = 0; k < T; ++k) { + output.println(String.format(""Case #%d: %d"", k + 1, processLine(input.nextLine()))); + } + } + } + } + + public static int processLine(final String line) { + int counter = 0; + try (Scanner lineReader = new Scanner(line)) { + lineReader.useDelimiter("" ""); + int N = lineReader.nextInt(); + int S = lineReader.nextInt(); + int P = lineReader.nextInt(); + + for (int i = 0; i < N; ++i) { + int value = lineReader.nextInt(); + + if(value >= P && value - P >= 2 * (P - 1)) { + ++counter; + } else if(value >= P && value - P >= 2 * (P - 2) && S > 0) { + ++counter; + --S; + } + } + } + + return counter; + } + +} +" +A21121,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package leider.ken; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.Callable; + +/** + * + * @author ken + */ +interface Parser { + + Map> parse(String fileName) throws IOException; +} +" +A21498," +import java.io.*; +import java.util.*; + +public class codejam3 { + + public static void main(String[] args) throws FileNotFoundException, IOException { + File file = new File(""B-large.in""); + FileReader fr = new FileReader(file); + Scanner ob = new Scanner(fr); + File outFile = new File(""outFile3.txt""); + FileWriter outFilew = new FileWriter(outFile); + int t, r = 1; + t = ob.nextInt(); + while (t != 0) { + int n, s, p, count = 0; + n = ob.nextInt(); + s = ob.nextInt(); + p = ob.nextInt(); + int a[] = new int[n]; + for (int i = 0; i < n; i++) { + a[i] = ob.nextInt(); + if (a[i] >= p) { + if (a[i] >= 3 * p - 2) { + count++; + } else if ((a[i] == 3 * p - 4 || a[i] == 3 * p - 3) && s != 0) { + s--; + count++; + } + } + } + System.out.println(count); + outFilew.append(""Case #""+r+"": ""+count+""\n""); + t--; + r++; + } + outFilew.close(); + } +} +" +A22171,"package com.brootdev.gcj2012.common; + +import java.io.*; + +public class Data { + + public final BufferedReader in; + public final PrintWriter out; + + public Data(String inFile, String outFile) throws IOException { + in = new BufferedReader(new FileReader(inFile)); + out = new PrintWriter(new BufferedWriter(new FileWriter(outFile))); + } + + public long readLongLine() throws IOException { + return DataUtils.readLongLine(in); + } + + public long[] readLongsArrayLine() throws IOException { + return DataUtils.readLongsArrayLine(in); + } + + public void writeCaseHeader(long case_) { + DataUtils.writeCaseHeader(out, case_); + } +} +" +A22787,"package google.contest.B; + +import google.loader.Challenge; +import google.problems.AbstractReader; + +public class BReader extends AbstractReader { + + @Override + protected Challenge createChallenge(int number) { + int theLine = getActualLine(); + String[] lines = getLines(); + BChallenge chal = new BChallenge(number, lines[theLine]); + setActualLine(theLine+1); + return chal; + } + +} +" +A22862,"import java.util.*; +class Dance { + public static void main (String args[]) { + Scanner sc = new Scanner(System.in); + int numCases = sc.nextInt(); + for (int i = 0; i < numCases; i++) { + int numScores = sc.nextInt(); + int numSuprises = sc.nextInt(); + int smallest = sc.nextInt(); + int won = 0; + for (int k = 0; k < numScores; k++) { + int score = sc.nextInt(); + if (smallest > score) + continue; + score -= smallest; + score /= 2; + if (score >= smallest - 1) + won++; + else if (score >= smallest - 2) { + if (numSuprises != 0) { + won++; + numSuprises--; + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + won); + } + } +}" +A21215,"package GooglerDancing; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +public class GooglerDancing { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + + BufferedReader br = new BufferedReader(new FileReader(""googlersInput"")); + PrintWriter pw = new PrintWriter(new File(""googlersOutput"")); + String T = br.readLine(); + String line; + int Case = 1; + while ((line = br.readLine()) != null) { + String[] strs = line.split("" ""); + int N = Integer.parseInt(strs[0]); + int surprising = Integer.parseInt(strs[1]); + int p = Integer.parseInt(strs[2]); + int[] t = new int[N]; + System.out.println(p + "" "" + surprising); + for (int i = 0; i < t.length; i++) { + t[i] = Integer.parseInt(strs[i + 3]); + } + int threshold0 = p + p - 2 + p - 2; + int threshold1 = p + p - 1 + p - 1; + if (threshold0 < 0) + threshold0 = 0; + if (threshold1 < 0) + threshold1 = 0; + int count = 0; + for (int i = 0; i < t.length; i++) { + if (t[i] > 0 && t[i] >= threshold0 && t[i] < threshold1) { + if (surprising > 0) { + count++; + surprising--; + System.out.println(t[i]); + + } + } else if (t[i] > 0 && t[i] >= threshold1) { + count++; + System.out.println(t[i]); + } + } + System.out.println(line + ""\nCase #"" + Case + "": "" + count); + pw.write(""Case #"" + Case + "": "" + count + ""\n""); + Case++; + + } + pw.flush(); + pw.close(); + + } + +} +" +A22107,"package com.google.codejam; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class GooglerDanceSolver { + + public static int getMaximumPassCount(int passScore, int surpriseCount, List scores) { + int passCount = 0; + + int lowerBound = (passScore > 1) ? 3 * passScore - 4 : passScore; + + for (int score : scores) { + if (score < lowerBound) { + continue; + } else if (score > 3 * passScore - 3) { + passCount++; + } else if (surpriseCount > 0) { + passCount++; + surpriseCount--; + } + } + + return passCount; + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scanner = new Scanner(System.in); + int totalCount = Integer.parseInt(scanner.nextLine()); + + for (int i = 0; i < totalCount; i++) { + String[] inputs = scanner.nextLine().split("" ""); + int n = Integer.parseInt(inputs[0]); + int s = Integer.parseInt(inputs[1]); + int p = Integer.parseInt(inputs[2]); + List scores = new ArrayList(n); + for (int j = 0; j < n; j++) { + scores.add(Integer.parseInt(inputs[j+3])); + } + int answer = GooglerDanceSolver.getMaximumPassCount(p, s, scores); + System.out.printf(""Case #%d: %d%n"", i+1, answer); + //System.err.printf(""[Debug Info] p=%d, s=%d, scores=%s%n"", p, s, scores.toString()); + } + } + +} +" +A22857,"package qualification.q2; + +/** + * Created by IntelliJ IDEA. + * User: ofer + * Date: 14/04/12 + * Time: 18:47 + * To change this template use File | Settings | File Templates. + */ +public class Q2Solver { + + public int solve(int n,int s,int p, int[] sums){ + + int res = 0; + int surprisesLeft = s; + for (int sum : sums){ + int div = sum / 3; + int mod = sum % 3; + if (div >= p){ + res++; + } + else if( p - div == 1){ + if (div > 0 && mod == 0 && surprisesLeft > 0){ + res++; + surprisesLeft--; + } + else if (mod > 0){ + res++; + } + } + else if (p -div ==2 && mod == 2 && surprisesLeft > 0){ + res++; + surprisesLeft--; + } + } + return res; + } +} +" +A21351,"import java.io.PrintWriter; +import java.util.Scanner; + + +public class Codejam { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner inFile = null; + PrintWriter outFile = null; + inFile = FileUtils.ScannerOpen(""zin""); + outFile = FileUtils.PrintWriterOpen(""zout""); + int numberOfTestCase=0; + //get the number of test cases + if(inFile.hasNext()){ + String s=inFile.nextLine(); + try{ + numberOfTestCase=Integer.parseInt(s); + }catch(Exception e){ + + } + } + + //for each test case get the input + for(int i=0;i lines = Files.readAllLines(pathin, Charset.forName(""UTF-8"")); + + + String str = null; + String[] split = null; + int countGooglers = 0; + int countSurprises = 0; + int bestResult = 0; + int countBestGooglers = 0; + int[] scores = null; + int total = 0; + int totalAux = 0; + int dif = 0; + boolean surprise = false; + int countLines = lines.size(); + for (int i = 1; i < countLines; i++) { + str = lines.get(i); + split = str.split("" ""); + + countGooglers = Integer.parseInt(split[0]); + countSurprises = Integer.parseInt(split[1]); + bestResult = Integer.parseInt(split[2]); + countBestGooglers = 0; + + scores = new int[3]; + total = 0; + totalAux = 0; + for(int j = 0; j< countGooglers; j++) + { + total = Integer.parseInt(split[j+3]); + totalAux = total; + scores[0] = totalAux/3; + totalAux -= scores[0]; + scores[1] = totalAux>>1; + totalAux -= scores[1]; + scores[2] = totalAux; + + if(scores[0] >= bestResult || scores[1] >= bestResult || scores[2] >= bestResult) + { + countBestGooglers++; + continue; + } + + if(countSurprises > 0 && total > 0) + { + for(int k = 0; k < scores.length; k++) + { + if(scores[k]+1 < bestResult) + { + continue; + } + + dif = 0; + for(int m = 0; m < scores.length; m++) + { + if( k == m) + { + continue; + } + + dif = Math.abs((scores[k] + 1) - (scores[m] -1)); + + if(dif == 2) + { + countSurprises--; + surprise = true; + countBestGooglers++; + break; + } + } + + if(surprise) + { + break; + } + } + } + } + + + pout.printf(""Case #%d: %d\n"", i, countBestGooglers); + } + + } catch (IOException ex) { + ex.printStackTrace(); + } + } +} +" +A20924,"package b; + +import java.io.*; +import java.lang.Math.*; +import java.util.HashMap; + +public class B { + + public static void main(String[] args) { + + try { + BufferedReader input = new BufferedReader(new FileReader(""C:/CodeJam/B-small-attempt2.in"")); + BufferedWriter output = new BufferedWriter(new FileWriter(""C:/CodeJam/B-small-attempt2.out"")); + try { + int T = Integer.parseInt(input.readLine()); + + //Process each case + for (int i = 0; i < T; i++) { + String line = input.readLine(); + + String[] data = line.split("" ""); + int N = Integer.parseInt(data[0]); + int S = Integer.parseInt(data[1]); + int p = Integer.parseInt(data[2]); + + //Count the possible surprising/unsurprising scores + int countU = 0; + int countS = 0; + for (int j = 0; j < N; j++) { + int score = Integer.parseInt(data[j + 3]); + + //Minimum score to be surprising/unsurprising + int minScoreS = 2 * (p - 2) + p; + int minScoreU = 2 * (p - 1) + p; + if (p == 0) { + countU++; + } else if (p == 1 && score > 0) { + countU++; + } else if (minScoreU >= 0 && score >= minScoreU) { + countU++; + } else if (minScoreS >= 0 && score >= minScoreS) { + countS++; + } + } + output.write(""Case #"" + (i + 1) + "": "" + (countU + Math.min(S, countS)) + ""\n""); + } + } finally { + input.close(); + output.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } +} +" +A21026,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Dancer { + + public static void main (String [] args) throws Exception { + FileInputStream fstreamIn = new FileInputStream (""B-large.in""); + DataInputStream in = new DataInputStream (fstreamIn); + BufferedReader is = new BufferedReader (new InputStreamReader(in)); + + FileWriter fstreamOut = new FileWriter (""dancer-output.out""); + BufferedWriter out = new BufferedWriter (fstreamOut); + + String line = is.readLine(); + int num = Integer.parseInt(line); + + for (int i = 0; i < num; i++) { + String str = is.readLine(); + StringTokenizer st = new StringTokenizer (str); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int max = 0; + for (int j = 0; j < n; j++) { + int totalScore = Integer.parseInt(st.nextToken()); + + if (totalScore == 0) { + if (p == 0) { + max += 1; + } + continue; + } + + if (totalScore == 1) { + if (p <= 1) { + max += 1; + } + continue; + } + + + if (totalScore / 3 >= p) { + max += 1; + } else if (totalScore / 3 < (p-2)) { + continue; + } else { + int sumOfTwo = totalScore - p; + + int rest = sumOfTwo - (p-1); + if (rest > p-2) { + max += 1; + continue; + } + + rest = sumOfTwo - (p-2); + if (rest >= p-2) { + if (s != 0) { + max += 1; + s -= 1; + } + } + } + } + out.write(""Case #"" + (i+1) + "": "" + max + ""\n""); + + } + out.close(); + + + + + } + + +}" +A20945,"package org.moriraaca.codejam.dancingwithgooglers; + +import org.moriraaca.codejam.TestCase; + +public class DancingWithTheGooglersTestCase implements TestCase { + public int S; + + public int p; + + public int[] scores; +} +" +A20377,"import java.io.File; +import java.io.FileWriter; +import java.util.*; + +/** + * Author: Andriy Gusyev + * Date: 14.04.12 + */ +public class Task3 { + + private static class Case { + + private int googlers; + + private int surprising; + + private int minScore; + + private int[] totalScores; + + @Override + public String toString() { + return ""Case{"" + + ""googlers="" + googlers + + "", surprising="" + surprising + + "", minScore="" + minScore + + "", totalScores="" + Arrays.toString(totalScores) + + ""}\n""; + } + } + + private static class Dancer { + + private Integer bestSurprisedScore; + + private Integer bestNonSuprisedScore; + + public Dancer(int totalScore) { + if (totalScore == 0) { + bestNonSuprisedScore = 0; + bestSurprisedScore = 0; + return; + } + switch (totalScore % 3) { + case 0: + bestNonSuprisedScore = totalScore / 3; + bestSurprisedScore = totalScore / 3 + 1; + if (bestSurprisedScore > 10) { + bestSurprisedScore = 10; + } + break; + case 1: + bestNonSuprisedScore = totalScore / 3 + 1; + bestSurprisedScore = totalScore / 3 + 1; + if (bestSurprisedScore > 10) { + bestSurprisedScore = 10; + } + break; + case 2: + bestNonSuprisedScore = totalScore / 3 + 1; + bestSurprisedScore = totalScore / 3 + 2; + if (bestSurprisedScore > 10) { + bestSurprisedScore = 10; + } + } + } + + @Override + public String toString() { + return ""Dancer{"" + + ""bestNonSuprisedScore="" + bestNonSuprisedScore + + "", bestSurprisedScore="" + bestSurprisedScore + + ""}\n""; + } + + @Override + public boolean equals(Object o) { + return false; + } + } + + static private int cases; + + static private Case[] objs; + + static private int[] results; + + private static void readInput(String s, int index) { + s = s.trim(); + String[] arr = s.split("" ""); + Case cas = new Case(); + cas.googlers = Integer.parseInt(arr[0]); + cas.surprising = Integer.parseInt(arr[1]); + cas.minScore = Integer.parseInt(arr[2]); + cas.totalScores = new int[cas.googlers]; + for (int i = 0; i < cas.googlers; i++) { + cas.totalScores[i] = Integer.parseInt(arr[3 + i]); + } + objs[index] = cas; + } + + public static void main(String args[]) throws Exception { + + Scanner sc = new Scanner(new File(""d:/codejam/3/large""), ""UTF-8""); + cases = Integer.parseInt(sc.nextLine()); + objs = new Case[cases]; + results = new int[cases]; + for (int i = 0; i < cases; i++) { + readInput(sc.nextLine(), i); + } + + for (int i = 0; i < cases; i++) { + results[i] = proceedCase(objs[i]); + } + System.out.println(Arrays.toString(results)); + FileWriter fw = new FileWriter(new File(""d:/codejam/3/large_out"")); + int k = 0; + for (int i : results) { + k++; + fw.write(String.format(""Case #%s: %s\n"", String.valueOf(k), String.valueOf(i))); + } + fw.close(); + } + + private static int proceedCase(Case cas) { + int result = 0; + List dancers = new ArrayList(); + for (int i = 0; i < cas.googlers; i++) { + dancers.add(new Dancer(cas.totalScores[i])); + } + Collections.sort(dancers, new Comparator() { + public int compare(Dancer o1, Dancer o2) { + if (o1.bestNonSuprisedScore == o2.bestNonSuprisedScore) { + return -o1.bestSurprisedScore.compareTo(o2.bestSurprisedScore); + } + return -o1.bestNonSuprisedScore.compareTo(o2.bestNonSuprisedScore); + } + }); + System.out.println(dancers); + int surprisedUsed = 0; + for (Dancer dancer : dancers) { + if (dancer.bestNonSuprisedScore >= cas.minScore) { + result++; + continue; + } else if (dancer.bestSurprisedScore >= cas.minScore && cas.surprising > surprisedUsed) { + result++; + surprisedUsed++; + continue; + } + } + return result; + } +} +" +A20695,"package quiz.number05; + +import java.io.*; +import java.util.Arrays; + +/** + * @author Keesun Baik + */ +public class KeesunDancingTest { + + public static void main(String[] args) throws IOException { + KeesunDancingTest dancing = new KeesunDancingTest(); + + + BufferedReader in = new BufferedReader(new FileReader(""/workspace/telepathy/test/quiz/number05/B-large.in"")); + String s; + int lineNum = 0; + int problemNum = 0; + String answer = """"; + while ((s = in.readLine()) != null) { + if (s.isEmpty()) { + return; + } + if (lineNum == 0) { + problemNum = Integer.parseInt(s); + } else { + answer += ""Case #"" + lineNum + "": "" + dancing.figureP(s) + ""\n""; + } + lineNum++; + } + in.close(); + + System.out.println(answer); + + BufferedWriter out = new BufferedWriter(new FileWriter(""/workspace/telepathy/test/quiz/number05/B-large.out"")); + out.write(answer); + out.close(); + } + + private int figureP(String s) { + String[] inputs = s.split("" ""); + int people = Integer.parseInt(inputs[0]); + int surprise = Integer.parseInt(inputs[1]); + int minScore = Integer.parseInt(inputs[2]); + + String[] scoreStrings = Arrays.copyOfRange(inputs, 3, inputs.length); + + + int[] scores = new int[scoreStrings.length]; + for (int i = 0; i < scoreStrings.length; i++) { + scores[i] = Integer.parseInt(scoreStrings[i]); + } + + int cases = 0; + + for (int score : scores) { + int base = score / 3; + switch (score % 3) { + case 0: { + System.out.println(""0""); + if (base >= minScore) { + cases++; + } else if (surprise > 0 && base > 0 && base + 1 >= minScore) { + cases++; + surprise--; + } + break; + } + case 1: { + System.out.println(""1""); + if (base >= minScore || base + 1 >= minScore) { + cases++; + } else if (surprise > 0 && base + 1 >= minScore) { + cases++; + surprise--; + } + break; + } + case 2: { + System.out.println(""2""); + if (base + 1 >= minScore || base >= minScore) { + cases++; + } else if (surprise > 0 && base + 2 >= minScore) { + cases++; + surprise--; + } + break; + } + } + } + return cases; + } + + +} +" +A22690,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + + +public class FileRW { + + + public static List readFile(String fileName) throws IOException{ + + List lines = new ArrayList<>(); + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + String line = reader.readLine(); + + while(line != null){ + lines.add(line.trim()); + line = reader.readLine(); + } + reader.close(); + lines.remove(0); + + return lines; + } + + + public static void writeOutput(String fileName, List result) throws IOException{ + + StringBuilder out = new StringBuilder(); + String prefix = ""Case #""; + for (int i = 0; i < result.size(); i++) { + out.append(prefix + (i + 1) + "": "" + result.get(i) + ""\n""); + } + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); + writer.write(out.toString()); + writer.close(); + + } + +} +" +A22059,"package client; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import java.util.StringTokenizer; +import java.math.*; + +public class DancingGoogler { + public DancingGoogler() { + super(); + } + + public static void main(String[] args) throws FileNotFoundException, + IOException { + DancingGoogler dancingGoogler = new DancingGoogler(); + FileReader fr = new FileReader(""B-large.in""); + //FileReader fr = new FileReader(""A-small-practice.in""); + BufferedReader br = new BufferedReader(fr); + String noofT = br.readLine(); + int noOfTestCases = Integer.parseInt(noofT); + BufferedWriter bw = new BufferedWriter(new FileWriter(""output.txt"")); + + for (int i=0; i < noOfTestCases; i++ ){ + StringTokenizer st = new StringTokenizer(br.readLine(),"" ""); + String nofG = st.nextToken(); + int noOfGooglers = Integer.parseInt(nofG); + String nofS = st.nextToken(); + int noOfSurprises = Integer.parseInt(nofS); + String p = st.nextToken(); + int P = Integer.parseInt(p); + int cnt = 0; + int cntS =0; + int[] cntr = new int[noOfGooglers]; + forloop: for (int j=0 ; j < noOfGooglers; j++){ + + String jG = st.nextToken(); + int totjG = Integer.parseInt(jG); + int q = totjG/3; + int r = totjG%3; + int[][] ar = new int[100][3]; + boolean flagr = false; + + if (r == 0){ + ar[0][0] = q; + ar[0][1] = q; + ar[0][2] = q; + for(int k=0;k<3;k++){ + if (ar[0][k] >= P) + cntr[j] = cntr[j] + 1; + } + + } + if (q+1 <= 10){ + if (Math.abs(totjG - q - q - 1 - q) <= 1 && Math.abs(totjG - q - q - 1 - q -1) <=1 ){ + ar[0][0] = q; + ar[0][1] = q+1; + ar[0][2] = totjG - q - q - 1; + for(int k=0;k<3;k++){ + if (ar[0][k] >= P) + cntr[j] = cntr[j] + 1; + } + + } + } + + + for (int k=0;k= 2) + flagr= true; + // System.out.println(""cntr ="" + cntr[k]); + } + if (noOfSurprises > 0 && ((cntS < noOfSurprises) || (flagr == true))){ + if (q + 1 <= 10 && q-1>=0){ + if (( Math.abs(totjG - 2*q - q + 1) <= 2) && (Math.abs(totjG-2*q - q -1) <= 2)){ + ar[1][0] = q + 1; + ar[1][1] = q-1; + ar[1][2] = totjG - 2*q; + + for(int k=0;k<3;k++){ + if (ar[1][k] >= P){ + cntr[j] = cntr[j] + 1; + cntS++; + break; + } + } + + + } + } + if (q+2 <= 10){ + if ((Math.abs(totjG - q- q -2 - q) <= 2) && (Math.abs(totjG - q- q -2 - q -2) <=2)){ + ar[1][0] = q; + ar[1][1] = q+2; + ar[1][2] = totjG- q - q -2; + + for(int k=0;k<3;k++){ + if (ar[1][k] >= P){ + cntr[j] = cntr[j] + 1; + cntS++; + break; + } + } + + } + } + } + + for (int m=0;m < 2; m++){ + for(int n = 0; n < 3;n++){ + System.out.print(ar[m][n]); + } + System.out.println(""""); + } + int val=0; + for (int m=0;m <2; m++){ + for(int n = 0; n < 3;n++){ + val = ar[m][n]; + if (ar[m][n] >= P){ + cnt++; + break; + + } + } + if (val >= P) + break; + + + } + + + } + String out = ""Case #"" + (i+1) + "": "" + cnt; + bw.write(out); + bw.newLine(); + System.out.println(""Case #"" + (i+1) + "": "" + cnt); + } + bw.close(); + } +} +" +A22648,"import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + + + Scanner sc = null; + if (args != null && args.length > 0) { + + try { + sc = new Scanner(new File(args[0])); + + if (args.length > 1) { + System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(args[1])), 128))); + } + } catch (FileNotFoundException e) { + + // e.printStackTrace(); + sc = new Scanner(System.in); + } + + } else { + + sc = new Scanner(System.in); + } + + int T = Integer.valueOf(sc.nextLine()); + + for (int i = 0; i < T; i++) { + + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = sc.nextInt(); + } + int answer = solve(S, p, t); + System.out.printf(""Case #%d: %d\n"", i + 1, answer); + + } + System.out.close(); + } + + public static int solve(int S, int p, int[] t) { + + int suprisingSuccess = 0; + int answer = 0; + for (int i = 0; i < t.length; i++) { + + if (t[i] >= 3 * p - 2) { + answer++; + + } else if (p < 3 && t[i] >= p) { + suprisingSuccess++; + + } else if ( p >= 3 && t[i] >= 3 * p - 4 ) { + suprisingSuccess++; + + } + + } + answer += (S >= suprisingSuccess) ? suprisingSuccess : S; + return answer; + } + +} +" +A20958,"package codejam2012; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Scanner; + +/** + * Created by IntelliJ IDEA. + * User: Jimmy + * Date: 4/14/12 + * Time: 10:17 PM + */ +public class DancingWithTheGooglers implements Runnable { + + Scanner scanner; + PrintWriter pw; + + public static void main(String arguments[]) { + new Thread(new DancingWithTheGooglers()).start(); + } + + public static boolean isSurprising(int points) { + return points > 1 && points < 29; + } + + public static int ms(int points) { + return (points + 4) / 3; + } + + public static int mn(int points) { + return (points + 2) / 3; + } + + public void solution() { + int t = scanner.nextInt(); + + int i, n, s, p, j; + int points; + int d; + int r = 0; + int result; + for(i = 1; i <= t; i++) { + n = scanner.nextInt(); + s = scanner.nextInt(); + p = scanner.nextInt(); + + System.out.println(n + "" "" + s + "" "" + p); + + int sum1 = 0; + int sum2 = 0; + + for(j = 0; j < n; j++) { + r = 0; + points = scanner.nextInt(); + if(isSurprising(points)) { + int ms = ms(points); + int mn = mn(points); + + if (ms >= p && mn < p) + sum1++; + + else if (mn >= p) + sum2++; + } else { + if (mn(points) >= p) + sum2++; + } + } + System.out.println(""******************************************************""); + pw.println(""Case #"" + i + "": "" + (Math.min(s, sum1) + sum2)); + } + } + + public void run() { + scanner = new Scanner(System.in); + try { + pw = new PrintWriter(new File(""output.txt"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + solution(); + + pw.close(); + scanner.close(); + } +} +" +A22111,"package codej; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class QualC { + Scanner scanner; + + public static void main(String[] args) { + QualC c = new QualC(); + c.go(); + } + + public void go() { + try { + scanner = new Scanner(new File(""input.txt"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + int N = scanner.nextInt(); + for (int i=1; i <= N; i++) { + scanner.nextLine(); + System.out.print(""Case #"" + i +"": ""); + System.out.println(doCase()); + } + } + + public int doCase() { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int maxScores = 0; + List scores = new ArrayList(); + + for (int i=0; i < N; i++) { + scores.add(scanner.nextInt()); + } + Collections.sort(scores); + + for (int n : scores) { + int spare = n - ((p-1) * 3); + if (p > n) + continue; + if (spare >= 1) { + maxScores++; + continue; + } + if (spare >= -1 && S > 0) { + S--; + maxScores++; + } + } + return maxScores; + } +} +" +A20999,"package fixjava; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * Get the index of the given key if this key has been assigned an index before, and if not, allocate a new index for it by + * incrementing a counter that starts at zero, and return the new index. + */ +public class UniqueIndexAllocator { + + private HashMap map = new HashMap(); + private ArrayList orderedKeys = new ArrayList(); + + public UniqueIndexAllocator() { + } + + /** Allocate unique indices for each item in the given collection. Read back the indices using the other methods. */ + public UniqueIndexAllocator(Iterable collection) { + for (T it : collection) + getOrAllocateIndex(it); + } + + /** Get the assigned index for a key, or assign it a new unique index if this key has not previously been assigned an index */ + public int getOrAllocateIndex(T key) { + Integer currIdx = map.get(key); + if (currIdx == null) { + map.put(key, currIdx = orderedKeys.size()); + orderedKeys.add(key); + } + return currIdx; + } + + /** Get all the keys as a list in their index order */ + public ArrayList getOrderedKeys() { + return orderedKeys; + } + + /** Get all the keys as an array in their index order */ + @SuppressWarnings(""unchecked"") + public T[] getOrderedKeysAsArray() { + return (T[]) orderedKeys.toArray(); + } + + /** Get the mapping from key to index */ + public HashMap getKeyToIndexMap() { + return map; + } + + /** Return the number of allocated indices, i.e. the number of unique keys */ + public int numIndices() { + return orderedKeys.size(); + } +} +" +A22398,"import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class mainclass { + + public static void main(String args[]) throws IOException { + + int cases; + int n; + int s; + int p; + int t; + int flag; + int counter; + int[] data; + int[] arr; + int surp; + + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + FileReader isr = new FileReader(args[0]); + Scanner src = new Scanner(isr); + + cases = src.nextInt(); + + for(int j=0;j=(p*3-2)) + counter = arr[i]+counter; + if((i==p*3-3||i==p*3-4)&&i>0) + surp = arr[i]+surp; + } + + if(surp>s) + counter = s+counter; + else + counter = surp+counter; + + try{ + out.write(""Case #""+(j+1)+"": ""+counter); + out.write(""\r\n""); + }catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + } + + out.close(); + } +} +" +A22607,"import java.util.Scanner; + + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + + for(int t=1; t<=T; t++){ + int N=sc.nextInt(); + int S=sc.nextInt(); + int P=sc.nextInt(); + int P1 = P-1<0 ? 0 : P-1; + int P2 = P-2<0 ? 0 : P-2; + + int[] sum = new int[N]; + for(int i=0; i= 2*P1+P) { + out++; + sum[i] = -1; + } + for(int i=0; i0; i++) + if(sum[i] >= 2*P2+P){ + S--; + sum[i] = -1; + out++; + } + System.out.println(""Case #""+t+"": ""+out); + } + } + +} +" +A22833,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; + +public class B { + + public static void main(String[] args) throws NumberFormatException, IOException { + File file = new File(args[0]); + BufferedReader reader = new BufferedReader(new FileReader(file)); + PrintStream printer = new PrintStream(new File(""B-large.txt"")); + + int t = Integer.parseInt(reader.readLine()); + for (int i = 0; i < t; i++) { + String sa = reader.readLine(); + String[] nums = sa.split("" ""); + // int n = Integer.parseInt(nums[0]); + int s = Integer.parseInt(nums[1]); + int p = Integer.parseInt(nums[2]); + int cs = 0; + int ans = 0; + for (int j = 3; j < nums.length; j++) { + int a = Integer.parseInt(nums[j]); + if (isP(a, p)) { + if (isSurprising(a, p)) { + // not taking care of the scenario where + // mandate surprising are less than 's' + // as the question confims there will atleast + // be s ts that can be surprising + cs++; + if (cs > s) + continue; + ans++; + } + else + ans++; + } + } + printer.println(""Case #"" + (i+1) + "": "" + ans); + } + printer.close(); + reader.close(); + } + + static boolean isSurprising(int a, int p) { + if (((a - p) / 2) >= p) + return false; + if (Math.abs(p - ((a - p) / 2)) == 2) + return true; + return false; + } + + static boolean isP(int a, int p) { + if (a < p) + return false; + if (((a - p) / 2) >= p) + return true; + if (Math.abs(p - ((a - p) / 2)) <= 2) + return true; + return false; + } +} +" +A21811,"import java.util.Scanner; + + +public class P2 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int t = Integer.parseInt(scan.nextLine()); + for (int i = 0; i < t; i++) { + String[] a = scan.nextLine().split("" ""); + int n = Integer.parseInt(a[0]); + int s = Integer.parseInt(a[1]); + int p = Integer.parseInt(a[2]); + int count = 0; + + int[] scores = new int[a.length-3]; + for (int j = 0; j < scores.length; j++) { + scores[j] = Integer.parseInt(a[j + 3]); + } + + for (int j = 0; j < scores.length; j++) { + int result = oneApart(scores[j]); + if (result >= p) { + count += 1; + } else if (scores[j] != 0 && scores[j] % 3 != 1 && result == p - 1 && s > 0) { + count += 1; + s -= 1; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } + + public static int oneApart(int a) { + if (a % 3 == 0) { + return a / 3; + } else if (a % 3 == 1) { + return (a-1)/3 + 1; + } else if (a % 3 == 2) { + return (a-2)/3 + 1; + } + return -1; + } +} +" +A22911,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + try { + // lets get the data in + FileInputStream fstream = new FileInputStream(""E:/workspace_java/DancingWiththeGooglers/src/input.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + // open file for writing + FileWriter fwstream = new FileWriter(""E:/workspace_java/DancingWiththeGooglers/src/output.out""); + BufferedWriter out = new BufferedWriter(fwstream); + + // declare variables + int i,j; + int numCases; + String[] strArr; + + // get number of cases + strLine = br.readLine(); + numCases = Integer.parseInt(strLine); + + // declare specific vars + int numGooglers; + int numSurprises; + int surprisesTaken = 0; + int bestScore; + ArrayList totalScores = new ArrayList(); + int tempScore; + int avg; + int aboveBest; + int one = 0, two = 0, three = 0; + int total; + + // loop through cases + for(i=0;i= bestScore) || (two >= bestScore) || (three >= bestScore)){ + aboveBest++; + } else if(surprisesTaken < numSurprises && tempScore != 0 && three < 10 && one > 0) { + // a surprise ultimately is just adding one to the highest and subtract one from lowest + three += 1; + one -= 1; + if(three >= bestScore) { + aboveBest++; + surprisesTaken++; + } + } + + total = one + two + three; + + if((one >= 0 && one <= 10) && (two >= 0 && two <= 10) && (three >= 0 && three <= 10)) { } + else { System.out.println(""Out of bounds on number""); } + + if(total != tempScore) { System.out.println(""Score does not add up""); } + + if(surprisesTaken > numSurprises) { System.out.println(""Too many surprises""); } + + //System.out.println(one + "" "" + two + "" "" + three); + } + System.out.print(""Case #""+(i+1)+"": ""); + out.write(""Case #""+(i+1)+"": ""); + System.out.println(aboveBest); + out.write(Integer.toString(aboveBest)); + out.newLine(); + } + + + //System.out.print(""Case #""+(i+1)+"": ""); + //out.write(""Case #""+(i+1)+"": ""); + //System.out.println(seanP2sum); + //out.write(Integer.toString(seanP2sum)); + //out.newLine(); + + + out.close(); + in.close(); + + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + + } +}" +A22673,"/* +ID: 14vikra1 +LANG: JAVA +TASK: dancescore +*/ +import java.io.*; +import java.util.*; + +class dancescore { + public static void main (String [] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""dancescore.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""dancescore.out""))); + int T = Integer.parseInt(br.readLine()); + for (int i = 0; i < T; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int surprise = 0; + int work = 0; + for (int j = 0; j < N; j++) { + int current = Integer.parseInt(st.nextToken()); + if (current%3 != 0 && current >= 2) { + if (Math.ceil(current/3) + 1 >= p) { + work++; + } else if (Math.ceil(current/3) + 2 >= p) { + surprise++; + } + } else if (current >= 2) { + if (Math.ceil(current/3) >= p) { + work++; + } else if (Math.ceil(current/3) + 1 >= p) { + surprise++; + } + } else { + if (current == 1 && p <= 1) { + work++; + } else if (current == 1 && p == 2) { + surprise++; + } else if (current == 0 && p == 0) { + work++; + } + } + } + int answer = work + Math.min(S, surprise); + out.println(""Case #"" + (i+1) + "": "" + answer); + } + out.close(); + System.exit(0); + } +} + +" +A21457,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Array; + +public class MainB { + + final static String FNAME = ""B-small-attempt0""; + + public BufferedReader in; + + public PrintWriter out; + + void open() throws IOException { + in = new BufferedReader( new FileReader( new File( FNAME+"".in"" ) ) ); + out = new PrintWriter( new File( FNAME + "".out"" ) ); + } + + void close() throws IOException { + out.close(); + } + + private boolean isBetterThanP(int num,int P) + { + int diff=num-P; + int num1=diff/2; + int num2=diff-num1; + if(num1+1=P) return true; + return false; + } + + void run() throws IOException { + + Integer T=Integer.parseInt(in.readLine()) ; + for(int i=1;i<=T;i++) + { + StringBuffer res=new StringBuffer(); + res.append(""Case #"" + i + "": ""); + + String line=in.readLine(); + String nums[]=line.split("" ""); + int N=Integer.parseInt(nums[0]); + int S=Integer.parseInt(nums[1]); + int P=Integer.parseInt(nums[2]); + int c=0; + int[] arr=new int[N]; + for(int k=0;k0&&isBetterThanPCaseSupersing(arr[k],P)) + { + S--; + c++; + } + + } + res.append(c); + out.println(res.toString()); + } + } + + public static void main( String[] args ) throws IOException { + new Thread() { + + public void run() { + try { + MainB solution = new MainB(); + solution.open(); + solution.run(); + solution.close(); + } catch ( Exception e ) { + throw new RuntimeException( e ); + } + } + }.start(); + } +} +" +A20455,"package google.codejam; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.google.common.base.Charsets; +import com.google.common.io.Closeables; +import com.google.common.io.Files; + +public class Dancing { + + public static final int MIN_SCORE = 0, MAX_SCORE = 10, COUNT_JUDGES = 3; + + private static Map> scoreCache = createScoreCache(); + + public static void main(String[] args) throws IOException { + File cwd = new File(""C:\\Users\\TaG\\workspace\\CodeJam\\""); + File inputFile = new File(cwd, ""input.txt""); + File outputFile = new File(cwd, ""output.txt""); + if (outputFile.exists()) + outputFile.delete(); + PrintStream out = null; + try { + out = new PrintStream(outputFile); + + List lines = Files.readLines(inputFile, Charsets.UTF_8); + int cases = Integer.parseInt(lines.remove(0)); + int caseNo = 1; + for (String line : lines) { + String[] tokens = line.split(""\\s""); + List list = new ArrayList(Arrays.asList(tokens)); + int nDancers = Integer.parseInt(list.remove(0)); + int surprising = Integer.parseInt(list.remove(0)); + int p = Integer.parseInt(list.remove(0)); + int max = 0; + while (!list.isEmpty()) { + int score = Integer.parseInt(list.remove(0)); + if (surprising > 0 && shouldApplySurprise(score, p)) { + surprising--; + max++; + continue; + } + + int high = calcHighestScore(score); + if (high >= p) { + max++; + } + } + + out.printf(""Case #%d: %d\n"", caseNo, max); + System.out.printf(""Case #%d: %d\n"", caseNo, max); + caseNo++; + } // end for-each lines + } finally { + Closeables.closeQuietly(out); + } + } + + private static boolean shouldApplySurprise(int total, int p) { + Set set = scoreCache.get(total); + for (Triplet triplet : set) { + if (!triplet.isSurprising() && triplet.getHigh() >= p) { + return false; + } + } + for (Triplet triplet : set) { + if (triplet.isSurprising() && triplet.getHigh() >= p) { + return true; + } + } + return false; + } + + private static int calcHighestScore(int total) { + Set set = scoreCache.get(total); + int max = 0; + for (Triplet triplet : set) { + if (!triplet.isSurprising()) { + max = Math.max(max, triplet.getHigh()); + } + } + return max; + } + + public static Map> createScoreCache() { + Map> list = new HashMap>(); + for (int score = MIN_SCORE; score <= (MAX_SCORE * COUNT_JUDGES); score++) { + Set set = calcPossibleCombos(score); + list.put(score, set); + // System.out.println(score + "":""); + // for (Triplet triplet : set) { + // System.out.println(triplet.getLow() + "", "" + triplet.getMid() + // + "", "" + triplet.getHigh() + "" ? "" + triplet.isSurprising()); + // } + } + return list; + } + + private static Set calcPossibleCombos(int score) { + // I am too tired to think this through + // so I'll brute-force it + Set set = new HashSet(); + for (int a = MIN_SCORE; a <= MAX_SCORE; a++) { + for (int b = MIN_SCORE; b <= MAX_SCORE; b++) { + for (int c = MIN_SCORE; c <= MAX_SCORE; c++) { + int total = a + b + c; + if (total == score) { + Triplet triplet = new DefaultTriplet(a, b, c); + if (triplet.isPossible()) { + set.add(triplet); + } + } + } + } + } + return set; + } + + private static interface Triplet { + + int getLow(); + + int getMid(); + + int getHigh(); + + boolean isSurprising(); + + boolean isPossible(); + + } + + private static class DefaultTriplet implements Triplet { + + private int[] ints; + private boolean isSurprising, isPossible; + + public DefaultTriplet(int score1, int score2, int score3) { + super(); + + ints = new int[] { score1, score2, score3 }; + Arrays.sort(ints); + int diff = ints[2] - ints[0]; + switch (diff) { + case 2: + isSurprising = true; + case 1: + case 0: + isPossible = true; + break; + default: + isPossible = false; + } + } + + private void validate() { + if (!isPossible()) + throw new IllegalStateException(""this should never happen""); + } + + @Override + public int getLow() { + validate(); + return ints[0]; + } + + @Override + public int getMid() { + validate(); + return ints[1]; + } + + @Override + public int getHigh() { + validate(); + return ints[2]; + } + + @Override + public boolean isSurprising() { + validate(); + return this.isSurprising; + } + + @Override + public boolean isPossible() { + return this.isPossible; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(ints); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DefaultTriplet other = (DefaultTriplet) obj; + if (!Arrays.equals(ints, other.ints)) + return false; + return true; + } + + } + +}" +A20203,"package googlecodejam2012_qualification; +/** + * @author neil + */ +import java.io.*; +import java.util.*; +public class NewMain3 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException + { + //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader in = new BufferedReader(new FileReader(""C:\\Documents and Settings\\neil\\Desktop\\B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""C:\\Documents and Settings\\neil\\Desktop\\B-large-output.txt"")); + PrintStream ps = new PrintStream(System.out,true); + StringTokenizer st;//st = new StringTokenizer(in.readLine(),"" ""); + int count=0; + int t = Integer.parseInt(in.readLine()); + while(count++=p) + { + if(a[i]%3==0) + { + if(a[i]/3>=p){ score++; selected[i] = true;} + } + else + { + if(a[i]/3+1>=p){ score++;selected[i] = true;} + } + } + + } + + for(int i=0;i=p) + { + if(s==0) break; + if(a[i]%3==2) + { + if(a[i]/3+2>=p){ score++; s--; } + } + else + { + if(a[i]/3+1>=p){ score++; s--; } + } + + } + } + + + + + ps.println(""Case #""+count+"": ""+score); + out.write(""Case #""+count+"": ""+score+""\n""); + out.flush(); + } + } +} +" +A22154,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; + +public class GoogleDancers{ + + public static void main(String[] args) throws Exception{ + FileReader fr = new FileReader(""C:\\Projects\\Learning\\src\\B-large.in""); + BufferedReader br = new BufferedReader(fr); + FileWriter fw = new FileWriter(""C:\\Projects\\Learning\\src\\BLarge.txt""); + int N = new Integer(br.readLine()); + for (int cases = 1; cases <= N; cases++) { + String str = br.readLine(); + StringTokenizer st = new StringTokenizer(str); + int numberParticipants = Integer.parseInt(st.nextToken()); + int surprise = Integer.parseInt(st.nextToken()); + int goodScore = Integer.parseInt(st.nextToken()); + int a[] = new int[numberParticipants]; + for(int i=0; i< numberParticipants; i++) { + a[i] = Integer.parseInt(st.nextToken()); + } + int count = 0; + int possibility = 0; + int minToGetGoodScore = Math.max(((3 * goodScore) - 2), 1); + System.out.println(""minToGetGoodScore"" + minToGetGoodScore); + int surpriseRange = Math.max(((3* goodScore) - 4), 1); + if (goodScore > 0 ) { + for (int i = 0; i < numberParticipants; i++) { + if (a[i] >= minToGetGoodScore) { + count++; + System.out.println(""Count"" + count); + + + } else if (a[i] >= surpriseRange + && a[i] < minToGetGoodScore) { + possibility++; + } + }System.out.println(""Count"" + count); + count = count + Math.min(possibility, surprise); + System.out.println(""Count"" + count); + } + else + { + count = numberParticipants; + } + fw.write(""Case #"" + cases + "": "" + count + ""\n""); + + } + fw.flush(); + fw.close(); + } +} +" +A22547,"import java.util.Scanner; + + +public class Surp { + + /** + * @param args + */ + public static void main(String[] args) { + int T,S,p,N=0; + String L=""""; + Scanner b = new Scanner(System.in); + T=b.nextInt(); + L=b.nextLine(); + for(int i=0;i0){ + S--; + N++; + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+N); + } + } + + +} +" +A22957,"package googleCodeJam; + +import static java.lang.System.out; + +import java.io.BufferedReader; +import java.io.FileReader; + +public class DancingWithTheGooglers { + private static final int MAXN = 128; + + private static int inc0(int num, int p) { + if (num == 0) { + return (p == 0) ? 1 : 0; + } + int t = num / 3; + int m = num % 3; + return ((m == 0 && t >= p) || (m == 1 && t+1 >= p) || (m == 2 && t+1 >= p)) ? 1 : 0; + } + + private static int inc1(int num, int p) { + if (num == 0) { + return 0; + } + int t = num / 3; + int m = num % 3; + return ((m == 0 && t+1 <= 10 && t+1 >= p) || (m == 1 && t+1 >= p) || (m == 2 && t+2 <= 10 && t+2 >= p)) ? 1 : 0; + } + + public static void main(String[] args) throws Exception { + if (args.length == 1) { + int[] g = new int[MAXN]; + int[][] f = new int[MAXN][MAXN]; + + // opening the input + BufferedReader in = new BufferedReader(new FileReader(args[0])); + + // reading the number of test cases + String line = null; + int numberOfTestCases = ((line = in.readLine()) != null) ? Integer.parseInt(line) : 0; + for (int t = 0; t < numberOfTestCases; t ++) { + line = in.readLine(); + out.print(""Case #"" + (t+1) + "": ""); + + // parsing input + String[] input = line.split("" ""); + int n = Integer.parseInt(input[0]); + int s = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + for (int i = 0; i < n; i ++) { + g[i] = Integer.parseInt(input[3 + i]); + } + + // computation + f[0][0] = inc0(g[0], p); + for (int i = 1; i < n; i ++) { + f[i][0] = f[i-1][0] + inc0(g[i], p); + } + if (s > 0) { + f[0][1] = inc1(g[0], p); + } + for (int i = 1; i < n; i ++) { + for (int j = 1; j <= i+1 && j <= s; j ++) { + f[i][j] = Math.max(f[i-1][j-1] + inc1(g[i], p), f[i-1][j] + inc0(g[i], p)); + } + } + out.println(f[n-1][s]); + } + + // closing the input + in.close(); + } else { + // show the usage + System.err.println(""Using: java googleCodeJam.DancingWithThegooglers input""); + } + } + +} +" +A20629,"import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.io.PrintWriter; + + +public class bsp2 { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + // TODO Auto-generated method stub + String inFile = ""B-large.in""; + String outFile = inFile + "".out""; + + LineNumberReader lin = new LineNumberReader(new InputStreamReader(new FileInputStream(inFile))); + PrintWriter out = new PrintWriter(new File(outFile)); + int NCASE = Integer.parseInt(lin.readLine()); + String line=""""; + int erg=0; + for(int CASE = 1; CASE <= NCASE; CASE++) { + String [] ch=lin.readLine().split("" ""); + int googlers=Integer.parseInt(ch[0]); + int sTriplets=Integer.parseInt(ch[1]); + int bResult=Integer.parseInt(ch[2]); + //System.out.println(""Case #""+CASE); + //System.out.println(googlers); + //System.out.println(sTriplets); + //System.out.println(bResult); + for(int SCORE=3;SCORE=bResult) erg++; + else{ + if(sTriplets>0 && base>0 && base+1 >=bResult){ + erg++; + sTriplets--; + } + } + break; + case 1: + if(base>=bResult||base+1>=bResult) erg++; + else{ + if(sTriplets>0 && base>0 && base+1 >=bResult){ + erg++; + sTriplets--; + } + } + break; + case 2: + if(base+1>=bResult||base>=bResult) erg++; + else{ + if(sTriplets>0 && base>0 && base+2 >=bResult){ + erg++; + sTriplets--; + } + } + break; + } + } + out.println(""Case #"" + CASE + "": ""+erg); + erg=0; + } + + lin.close(); + out.close(); + } + +} +" +A20048,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +/** + * template class for code jam Contest + * + * @author Tudor + * + */ + +public class Main +{ + public static final String INPUT_FILE = ""src/in.txt""; + public static final String OUTPUT_FILE = ""out.txt""; + java.io.BufferedWriter br; + + /* + * the number of tests + */ + int tests; + /* + * the size of the test + */ + int n; + int s; + int p; + /* + * the array + */ + int[] notes; + + public static void main(String args[]) + { + Main classMain = new Main(); + try + { + Scanner scanner = new Scanner(new File(Main.INPUT_FILE)); + classMain.br = new java.io.BufferedWriter(new FileWriter(Main.OUTPUT_FILE)); + classMain.setData(scanner); + + } catch (FileNotFoundException e) + { + e.printStackTrace(); + } catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * method to set the initial data and run the tests + * @param br the reader obtained from file + */ + + public void setData(Scanner scanner) + { + try + { + tests = scanner.nextInt(); + // System.out.println(""Tests "" + tests); + for (int i = 0; i < tests; i++) + { + n = scanner.nextInt(); + s = scanner.nextInt(); + p = scanner.nextInt(); + notes = new int[n]; + for (int j=0; j= (3 * p - 2)) + result++; + else + if (notes[i] >= (3 * p - 4)) + if (s > 0 && notes[i] > 0) + { + result++; + s--; + } + } + + + br.write(""Case #"" + testNr + "": "" + result + ""\n""); + } catch (IOException e) + { + e.printStackTrace(); + } + + } +} +" +A20334,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class B { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + int n; // # googlers + int s; // surprising + int p; // score + int scores[]; + int max; + int min; + int ret; + + BufferedReader br = new BufferedReader(new FileReader(""b.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""b.out"")); + StringTokenizer tk; + + int tests = Integer.parseInt(br.readLine().trim()); + + for (int t = 1; t <= tests; t++) { + tk = new StringTokenizer(br.readLine()); + n = Integer.parseInt(tk.nextToken()); + s = Integer.parseInt(tk.nextToken()); + p = Integer.parseInt(tk.nextToken()); + + max = 3 * p - 2; + min = 3 * p - 4; + + ret = 0; + scores = new int[n]; + for (int j = 0; j < scores.length; j++) + scores[j] = Integer.parseInt(tk.nextToken()); + + Arrays.sort(scores); + + if (p >= 2) + for (int i = scores.length - 1; i >= 0; i--) { + if (scores[i] >= max) + ret++; + else if (scores[i] < min) + break; + else { + + if (s==0)break; + ret++; + s--; + } + } + + else { + if (p == 0) + ret += scores.length; + else + for (int i = scores.length-1; i>=0; i--) { + if (scores[i] > 0) + ret++; + else + break; + } + + } + +// System.out.println(""Case #"" + t + "": "" + ret); + bw.write(""Case #"" + t + "": "" + ret); + bw.newLine(); + + } + + bw.close(); + } + +} +" +A20807,"package be.mokarea.gcj.googledancers; + +import be.mokarea.gcj.common.TestCase; + +public class GoogleDancerTestCase extends TestCase { + + private final int numberOfGooglers; + private final int numberOfSurprisingTripletsOfScores; + private final int scoreLowerBoundary; + private final int[] scores; + + protected GoogleDancerTestCase(int caseNumber, int numberOfGooglers, int numberOfSurprisingTripletsOfScores, int scoreLowerBoundary, int[] scores) { + super(caseNumber); + this.numberOfGooglers = numberOfGooglers; + this.numberOfSurprisingTripletsOfScores = numberOfSurprisingTripletsOfScores; + this.scoreLowerBoundary = scoreLowerBoundary; + this.scores = scores; + } + + public int getNumberOfGooglers() { + return numberOfGooglers; + } + + public int getMaxNumberOfSurprisingTripletsOfScores() { + return numberOfSurprisingTripletsOfScores; + } + + public int getScoreLowerBoundary() { + return scoreLowerBoundary; + } + + public int[] getScores() { + return scores; + } + +} +" +A21560,"package dancing; +import java.io.*; +import java.util.StringTokenizer; +import java.util.HashSet; + +class Solucion{ + int solucion(String datos){ + int ret = 0; + int ok = 0; + int posiblesorpresa = 0; + + StringTokenizer tk = new StringTokenizer(datos); + int jug = Integer.parseInt(tk.nextToken()); + int sorpresas = Integer.parseInt(tk.nextToken()); + int minimo = Integer.parseInt(tk.nextToken()); + + for (int i=0;i= 0) ){ + if (diferencia == 2){ + posiblesorpresa++; + //System.err.println(triple + "" SORPRESA""); + } + else{ + ok++; + //System.err.println(triple + "" SI""); + } + } + else{ + //System.err.println(triple + "" NO""); + } + } + + ret = ok + Math.min(sorpresas, posiblesorpresa); + return ret; + } +} +public class Dancing { + public static void main(String[] args) throws Exception{ + Solucion s = new Solucion(); + s.solucion(""2 1 1 8 0""); + + InputStreamReader isr = new InputStreamReader(System.in); + BufferedReader br = new BufferedReader (isr); + + String linea; + linea = br.readLine(); + int casos = Integer.parseInt(linea); + + for (int i=0;i 0) { + is = new FileInputStream(args[0]); + }else{ + is = System.in; + } + + BufferedReader inputReader = new BufferedReader(new InputStreamReader(is)); + String firstLine = inputReader.readLine(); + int count_of_cases = Integer.parseInt(firstLine); + + for (int idx_of_case = 1; idx_of_case <= count_of_cases; idx_of_case++) { + String caseLine = inputReader.readLine(); + String[] numbers = caseLine.split("" ""); + + int numbers_of_googler = Integer.parseInt(numbers[0]); + int superising_count = Integer.parseInt(numbers[1]); + int at_least = Integer.parseInt(numbers[2]); + + int[] total_scores = new int[numbers_of_googler]; + for (int idx = 0; idx < numbers_of_googler; idx++) { + total_scores[idx] = Integer.parseInt(numbers[3+idx]); + } + + int count = new Dancing(total_scores, superising_count).count_of_greater_than(at_least); + + System.out.println(String.format(""Case #%d: %d"", idx_of_case, count)); + } + + } + + public int count_of_greater_than(int at_least) { + int supersed_count = 0; + int count=0; + for (int idx = 0; idx < total_scores.length; idx++) { + int score = total_scores[idx]; + + int max_score = 0; + int average = score / 3; + if (average * 3 == score) { + max_score = average; + }else{ + max_score = average+1; + } + + if (max_score >= at_least) { + count++; + }else{ + int left = score - at_least; + if (left > 0 && supersed_count < superising_count ) { + if ((left / 2) * 2 == left && at_least - left / 2 == 2) { + supersed_count++; + count++; + } + if (left == 2 * at_least -3 ) { + supersed_count++; + count++; + } + } + } + + + } + return count; + + } +} +" +A20345,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +public class B { + public static void main(String args[]) throws Exception { + BufferedReader reader = new BufferedReader(new InputStreamReader( + new FileInputStream(args[0]))); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(args[1]))); + int T = Integer.parseInt(reader.readLine()); + for (int i = 0; i < T; i++) { + writer.write(""Case #"" + (i + 1) + "": "" + process(reader)); + writer.newLine(); + } + writer.flush(); + writer.close(); + } + + private static int process(BufferedReader reader) throws Exception { + + + String s = reader.readLine(); + int end = s.indexOf("" ""); + int N = Integer.parseInt(s.substring(0, end)); + s = s.substring(end + 1); + end = s.indexOf("" ""); + int S = Integer.parseInt(s.substring(0, end)); + s = s.substring(end + 1); + end = s.indexOf("" ""); + int P = Integer.parseInt(s.substring(0, end)); + int count = 0; + int score; + for (int i = 0; i < N; i++) { + if (i < N - 1) { + s = s.substring(end + 1); + end = s.indexOf("" ""); + score = Integer.parseInt(s.substring(0, end)); + } else { + s = s.substring(end + 1); + try { + score = Integer.parseInt(s); + } catch (Exception e) { + score = 0; + } + } + int base = score / 3; + int left = score % 3; + int max = base + (left + 1) / 2; + if(max >= P){ + count++; + }else if(S > 0 && base+left >= P){ + count++; + S--; + }else if(left == 0 && S > 0){ + if(score > P && max + 1 >= P){ + count++; + S--; + } + } + } + return count; + + } + + } + + + +" +A21669,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Collections; +import java.util.Scanner; + +import javax.swing.JFileChooser; + + +public class DancingWithTheGooglers { + + + public static void main(String[] args) { + JFileChooser chooser = new JFileChooser(); + int state = chooser.showOpenDialog(null); + + if(state == 0) { + File file = chooser.getSelectedFile(); + + try { + FileInputStream fInputStream = new FileInputStream(file); + DataInputStream dInputStream = new DataInputStream(fInputStream); + BufferedReader br = new BufferedReader(new InputStreamReader(dInputStream)); + + PrintWriter out = new PrintWriter(new FileWriter(""output"")); + + String str = br.readLine(); + int count = 1; + + while((str = br.readLine()) != null) { + out.print(""Case #"" + count + "": ""); + + Scanner scan = new Scanner(str); + + int numOfGooglers = scan.nextInt(); + int numOfSurprising = scan.nextInt(); + int atLeast = scan.nextInt(); + + int answer = 0; + + Integer[] totalPoints = new Integer[numOfGooglers]; + + for(int i=0; i= atLeast) { + answer++; + continue; + } else { + if(extra > 0) { + if(base+1 >= atLeast) { + answer++; + continue; + } + } + } + + if(numOfSurprising > 0) { + if(base == 0) { + continue; + } + + if(extra == 2) { + if(base+2 >= atLeast) { + answer++; + numOfSurprising--; + continue; + } + } else if(extra == 1) { + + } else if(extra == 0) { + if(base+1 >= atLeast) { + answer++; + numOfSurprising--; + continue; + } + } + } + } + + count++; + out.println(answer); + } + + out.close(); + dInputStream.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + +} +" +A20857,"import java.util.*; +import java.io.*; + +public class Dancing{ + public static void main(String[] args) throws IOException{ + Scanner in = new Scanner(new File(""d.in"")); + int a = Integer.parseInt(in.nextLine()); + for(int i = 1; i <= a; i++){ + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int q = 0; + for(int j = 0; j < n; j++){ + int c = in.nextInt(); + if(p*3-2 <= c){ + q++; + } + else if((s > 0) && (p*3-4 > 0) && p*3-4 <= c){ + q++; + s--; + } + } + in.nextLine(); + System.out.printf(""Case #%d: %d\n"",i,q); + } + } +} +" +A21642,"import java.util.Scanner; + +/** + * + * @author Nur Endah Safitri + */ +public class D2 { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int x = in.nextInt(); + for (int i = 1; i <= x; i++) { + int res = 0; + int a = in.nextInt(); + int b = in.nextInt(); + int c = in.nextInt(); + for (int j = 0; j < a; j++) { + int d = in.nextInt(); + if (c == 0) { + res++; + } else if (Math.ceil(d / 3.00) >= c) { + res++; + } else if (Math.ceil(d / 3.00) >= c - 1 && d != 0 && b != 0 && d % 3 != 1) { + res++; + b--; + } + } + System.out.println(""Case #"" + i + "": "" + res); + } + } +} +" +A21011,"package codejam; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import fixjava.Split; + +/** + * Put this class in a package that ends with the name of the problem, e.g. proba => problem A, with input A-large.in etc. + * + * Then save the sample problem to DirConsts.INPUT_DIR as X-test.in, where X is the problem letter. Save small and large attempt input files to that dir also. + * + * */ +public abstract class CodeJam { + + PrintWriter writer; + BufferedReader reader; + ArrayList currLineTokens = new ArrayList(); + int caseNum = 0; + + private String getStaticField(String name) { + try { + return (String) (this.getClass().getDeclaredField(name).get(null)); + } catch (Exception e) { + return null; + } + } + + public CodeJam() { + // Get package name and extract problem letter + String fullClassName = this.getClass().getName(); + int dotIdx = fullClassName.indexOf('.'); + String pkgName = fullClassName.substring(0, dotIdx).toLowerCase(); + if (!(pkgName.substring(0, pkgName.length() - 1).equals(""prob""))) + throw new RuntimeException(""Package name must be of the form 'probX'""); + final String problemLetter = pkgName.substring(pkgName.length() - 1).toUpperCase(); + + File inpDir = new File(DirConsts.INPUT_DIR); + if (!inpDir.exists()) + throw new RuntimeException(""Directory "" + DirConsts.INPUT_DIR + "" not found""); + + File outDir = new File(DirConsts.OUTPUT_DIR); + if (!outDir.exists()) + throw new RuntimeException(""Directory "" + DirConsts.OUTPUT_DIR + "" not found""); + + File srcDir = new File(new File((getClass().getProtectionDomain().getCodeSource().getLocation().toString()).substring(5)).getParentFile(), ""src""); + if (!srcDir.exists()) + throw new RuntimeException(""src directory not found""); + + // See if input file has been manually overriden by static field in Main class + String OVERRIDE_INPUT_FILE = getStaticField(""OVERRIDE_INPUT_FILE""); + + try { + // Package source into zipfile + File zipFile = new File(outDir, problemLetter + ""-source-latest.zip""); + System.out.println(""Zipping source from "" + srcDir); + ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile))); + byte data[] = new byte[1024 * 1024]; + for (String dirName : srcDir.list()) { + // Don't include probX directories for problems other than this one, but include everything else + if (!dirName.startsWith(""prob"") || dirName.equals(pkgName)) { + File dir = new File(srcDir, dirName); + for (String srcFile : dir.list()) { + String zipEntry = dirName + ""/"" + srcFile; + System.out.println("" -> Adding: "" + zipEntry); + zipOut.putNextEntry(new ZipEntry(zipEntry)); + BufferedInputStream srcFileStream = new BufferedInputStream(new FileInputStream(new File(dir, srcFile)), data.length); + for (int count; (count = srcFileStream.read(data, 0, data.length)) != -1;) + zipOut.write(data, 0, count); + srcFileStream.close(); + } + } + } + zipOut.close(); + System.out.println(""Wrote: "" + zipFile.getPath() + ""\n""); + + // Determine input file to use + String inpFileName; + if (OVERRIDE_INPUT_FILE != null) { + + // Manual override + inpFileName = problemLetter + ""-"" + OVERRIDE_INPUT_FILE + "".in""; + + } else { + + // Find latest-ordered input file to use + // Sort in order A-test.in, A-test0.in, A-test1.in, ..., A-small-attempt0.in, A-small-attempt1.in, ..., A-large.in + + String[] inpFiles = inpDir.list(new FilenameFilter() { + @Override + public boolean accept(File dir, String filename) { + boolean matches = filename.matches(problemLetter + ""-.*\\.in""); + if (matches && (filename.indexOf('(') >= 0 || filename.indexOf(')') >= 0)) { + // Don't include otherwise-valid filenames with parens in, warn the user, as + // there are probably downloads from multiple problem rounds in the same dir + System.err.println(""Filename "" + filename + "" contains parens -- skipping""); + return false; + } + return matches; + } + }); + if (inpFiles.length == 0) + throw new IOException(""No input files found for problem "" + problemLetter); + + // Sort into correct order (see above) + Arrays.sort(inpFiles, new Comparator() { + @Override + public int compare(String arg0, String arg1) { + String a = arg0.substring(2), b = arg1.substring(2); + int aType = a.startsWith(""test"") ? 0 : a.startsWith(""small"") ? 1 : a.startsWith(""large"") ? 2 : -1; + int bType = b.startsWith(""test"") ? 0 : b.startsWith(""small"") ? 1 : b.startsWith(""large"") ? 2 : -1; + int typeDiff = aType - bType; + if (typeDiff != 0) + return typeDiff; + int aDotIdx = a.lastIndexOf('.'), bDotIdx = b.lastIndexOf('.'); + if (aDotIdx < 1 || bDotIdx < 1) + return arg0.compareTo(arg1); + int aNumIdx = aDotIdx - 1; + while (aNumIdx >= 0 && Character.isDigit(a.charAt(aNumIdx))) + aNumIdx--; + String aNumStr = a.substring(aNumIdx + 1, aDotIdx); + int bNumIdx = bDotIdx - 1; + while (bNumIdx >= 0 && Character.isDigit(b.charAt(bNumIdx))) + bNumIdx--; + String bNumStr = b.substring(bNumIdx + 1, bDotIdx); + if (aNumStr.isEmpty() || bNumStr.isEmpty()) + return arg0.compareTo(arg1); + int aNum = Integer.parseInt(aNumStr); + int bNum = Integer.parseInt(bNumStr); + return aNum - bNum; + } + }); + inpFileName = inpFiles[inpFiles.length - 1]; + // for (String inpFile : inpFiles) + // System.out.println(""Input file: "" + inpFile); + } + + File inpFile = new File(inpDir, inpFileName); + File outFile = new File(outDir, inpFileName.replace("".in"", "".out"")); + + // Copy input file to output dir if it's not already there + if (!inpDir.equals(outDir)) { + System.out.println(""Copying input file to output dir""); + reader = new BufferedReader(new FileReader(inpFile)); + writer = new PrintWriter(new File(outDir, inpFileName)); + for (String line; (line = reader.readLine()) != null;) + writer.println(line); + writer.close(); + writer = null; + reader.close(); + reader = null; + } + + System.out.println(""Reading: "" + inpFile.getPath() + ""\n""); + reader = new BufferedReader(new FileReader(inpFile)); + writer = new PrintWriter(outFile); // = null; // to suppress output + + // Do the work + solve(); + + if (writer != null) + writer.close(); + System.out.println(""\nWrote: "" + outFile.getPath() + ""\n\nFinished.""); + reader.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void writeLineRaw(String outputLine) { + System.out.println(outputLine); + if (writer != null) + writer.println(outputLine); + } + + public void writeCaseNumThenLine(String outputLine) { + writeLineRaw(""Case #"" + (++caseNum) + "": "" + outputLine); + } + + public void writeCaseNumThenLine(int intLine) { + writeCaseNumThenLine("""" + intLine); + } + + public String readLine() { + try { + return reader.readLine(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + return null; + } + } + + /** Read next token, splitting on space */ + public String readTok() { + if (currLineTokens.size() > 0) { + String tok = currLineTokens.get(0); + currLineTokens.remove(0); + return tok; + } else { + currLineTokens.addAll(Split.splitAsListOfString(readLine(), "" "")); + return readTok(); + } + } + + /** Read next int, splitting on space */ + public int readInt() { + return Integer.parseInt(readTok()); + } + + public abstract void solve(); +} +" +A22952," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author ZuoZhong + */ +public class Dancer { + + public static void main(String[] args) throws IOException { + File file = new File(""B-large.in""); + BufferedReader in = new BufferedReader(new FileReader(file)); + String line = in.readLine(); + BufferedWriter out = new BufferedWriter(new FileWriter(""Dancer_big_output.txt"")); + + int T = Integer.parseInt(line); + for (int x = 1; x <= T; x++) { + line = in.readLine(); + String[] input = line.split("" ""); + int N = Integer.parseInt(input[0]); // number of googlers + int S = Integer.parseInt(input[1]); // number of surprising score + int p = Integer.parseInt(input[2]); // at least 1 score > p + int ans = 0; + int lowerBound = 0; + if (p == 0) { + lowerBound = 0; + } else if (p == 1) { + lowerBound = 1; + } else { + lowerBound = 3 * p - 4; + } + + for (int y = 3; y < N + 3; y++) { + int score = Integer.parseInt(input[y]); + if (score >= lowerBound) { + //fliter out lower bound surprising + if(score == (3*p-3) || score == (3*p-4)){ + //within the suprising bound + if(S > 0){ + S--; + ans++; + } + }else{ + ans++; + } + } + } + out.write(""Case #"" + x + "": "" + ans); + out.newLine(); + System.out.println(""Case #"" + x + "": "" + ans); + } + in.close(); + out.close(); + } +} +" +A22384," +import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author xeyyam + */ +public class DancingWiththeGooglers { + + boolean[][] ansNoS = new boolean[31][11]; + boolean[][] ansS = new boolean[31][11]; + + public static void main(String args[]) throws Exception { + new DancingWiththeGooglers().solve(); + } + + public void solve() throws Exception { + generate(); + + Scanner sc = new Scanner(new File(""B-large.in"")); + PrintWriter pw = new PrintWriter(""B-large.out""); + int t, n, s, p; + + t = sc.nextInt(); + + for (int i = 1; i <= t; i++) { + n = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + int ans = 0; + int temp = 0; + + for(int j = 1 ; j<=n ; j++ ){ + temp = sc.nextInt(); + if( check(temp , p , false) ) ans++; + else if( s>0 && check(temp , p , true ) ){ ans++ ; s--;} + + } + + pw.println(""Case #""+i+"": ""+ans); + } + + pw.flush(); + pw.close(); + + } + + public boolean check(int sum , int p , boolean surprise){ + + if( !surprise ) + for(int i = p ; i<=10 ; i++){ + if( ansNoS[sum][i] ) + return true; + } + else{ + + for(int i = p ; i<=10 ; i++){ + if( ansS[sum][i] ) + return true; + } + } + + return false; + } + + public void generate() { + for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= 10; j++) { + for (int k = 0; k <= 10; k++) { + if (Math.abs(j - i) <= 1 && Math.abs(k - j) <= 1 && Math.abs(i - k) <= 1) { + ansNoS[i + j + k][i] = true; + ansNoS[i + j + k][j] = true; + ansNoS[i + j + k][k] = true; + } else if (Math.abs(j - i) <= 2 && Math.abs(k - j) <= 2 && Math.abs(i - k) <= 2) { + ansS[i + j + k][i] = true; + ansS[i + j + k][j] = true; + ansS[i + j + k][k] = true; + } + } + } + } + } +} +" +A20301,"package com.eduardcapell.gcj2012.qualification; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.List; +import java.util.Vector; + +public class B { + + public static void main(String[] args) throws Exception { + B a = new B(); + a.run(); + } + + + public void run() throws Exception { + String fileName = ""/Users/edu/Dropbox/google_code_jam/2012/B-large.in""; + File f = new File(fileName); + List rows = getLines(f); + + for (int i=1; i < rows.size(); i++) { + String line = rows.get(i); + int result = processLine(line); + print(""Case #"" + i + "": "" + result); + } + } + + private int processLine(String line) { + String[] values = line.split("" ""); + int n = Integer.parseInt(values[0]); + int surprising = Integer.parseInt(values[1]); + int p = Integer.parseInt(values[2]); + + int[] scores = new int[n]; + for (int i=0; i < n; i++) { + scores[i] = Integer.parseInt(values[i + 3]); + } + + int could = 0; + int mustBeSurprising = 0; + + for (int i=0; i < scores.length; i++) { + int score = scores[i]; + if (score < p) { + continue; + } + int exact = p * 3; + int diff = score - exact; + if (diff >= 0) { + could++; + } else if (diff >= -2) { + could++; + } else if (diff >= -4) { + mustBeSurprising++; + could++; + } + } + + if (mustBeSurprising < surprising) { + // Set as surprising the cases that originally were not flagged as such. + mustBeSurprising = surprising; + } + could = could - (mustBeSurprising - surprising); + + return could; + } + + + private void print(Object o) { + System.out.println(o); + } + + + public List getLines(File f) throws Exception { + List lines = new Vector(); + + BufferedReader in = new BufferedReader(new FileReader(f)); + String line = null; + while ((line = in.readLine()) != null) { + lines.add(line); + } + + return lines; + } +} +" +A23022,"import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.HashMap; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream( + ""B-large.in""); + + // Convert our input stream to aw + // DataInputStream + DataInputStream in = new DataInputStream(fstream); + + FileOutputStream out = new FileOutputStream( + ""B-large.out""); + PrintStream p = new PrintStream(out); + + int lineNo = 1; + // Continue to read lines while + // there are still some left to read + while (in.available() != 0) { + if (lineNo == 1) { + cases(in.readLine(), in, p); + } + lineNo++; + } + + in.close(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private static void cases(String firstLine, DataInputStream in, + PrintStream p) throws IOException { + int casesNo = Integer.parseInt(firstLine); + for (int i = 0; i < casesNo; i++) { + // System.out.print(""Case #"" + (i + 1) + "": ""); + p.print(""Case #"" + (i + 1) + "": ""); + String line = in.readLine(); + googlers(line, p); + } + + } + + private static void googlers(String line, PrintStream p) { + + String lines[] = line.split("" ""); + int suprises = Integer.parseInt(lines[1]); + int reqP = Integer.parseInt(lines[2]); + int result = 0; + int number=0; + int quo = 0; + int rem = 0; + for(int i = 3;i=reqP || (rem+quo)>=reqP) + { + result=result+1; + continue; + } + else + { + if(suprises>=1) + { + number +=2; + quo = number/3; + rem = number%3; + rem = rem==0? 0 : 1; + if(quo>=reqP || (rem+quo)>=reqP) + { + result=result+1; + suprises=suprises-1; + continue; + } + + } + + } + } + p.println(result+""""); + } + +} +" +A21562,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + + +public class Dancing { + public static void main(String[] args){ + Dancing d = new Dancing(); + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + + int numOfTests = Integer.parseInt(br.readLine()); + int N,S,p; + + for(int i=1; i<=numOfTests; i++){ + String itemString =br.readLine(); + String[] items = itemString.split("" ""); + System.out.print(""Case #""+i+"": ""); + N=Integer.parseInt(items[0]); + S=Integer.parseInt(items[1]); + p=Integer.parseInt(items[2]); + int[] scores = new int[N]; + for(int j=3; j=p) + count++; + else{ + if(S>0 && ((div+1)>=p)){ + count++; + S--; + } + } + } + else if (rem==1){ + if(div+1>=p) + count++; + } + else if (rem==2){ + if(div+1 >=p) + count++; + else if (S>0 && ((div+2)>=p)){ + count++; + S--; + } + } + else; + } + + + System.out.print(count); + + } + +} +" +A22938,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintStream; +import java.io.PrintWriter; + +public class Dancing { + + static PrintStream O = System.out; + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try { + PrintWriter out = new PrintWriter(new FileWriter(""b.out"")); + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + int cases = Integer.parseInt(in.readLine()); + for (int kase = 0; kase < cases; kase++){ + String input = in.readLine(); + String[] arr = input.split("" ""); + int N = Integer.parseInt(arr[0]); + int S = Integer.parseInt(arr[1]); + int p = Integer.parseInt(arr[2]); + int[] t = new int [arr.length - 3]; + for (int i = 0; i < t.length; i++){ + t[i] = Integer.parseInt(arr[i + 3]); + } + + int pastMax = 0; + for (int i = 0; i < t.length; i++){ + if (findMax(t[i]) >= p){ + pastMax++; + }else if (S > 0 && findSMax(t[i]) >= p){ + pastMax++; + S--; + } + } + out.println(""Case #"" + (kase + 1) + "": "" + pastMax); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + static int findMax (int sum){ + if (sum == 0){ + return 0; + }else if (sum == 1){ + return 1; + }else if (sum == 2){ + return 1; + }else if (sum == 3){ + return 1; + }else if (sum == 4){ + return 2; + } + return (sum + 2) / 3; + } + + static int findSMax (int sum){ + if (sum == 0){ + return 0; + }else if (sum == 1){ + return 1; + }else if (sum == 2){ + return 2; + }else if (sum == 3){ + return 2; + }else if (sum == 4){ + return 2; + }else if (sum == 5){ + return 3; + } + return (sum + 4) / 3; + } + +} +" +A22458,"import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SpeakingTongues extends JamProblem { + + + Map map = new HashMap<>(); + + public static void main(String[] args) throws IOException { + SpeakingTongues p = new SpeakingTongues(); + p.prepare(); + p.go(); + } + + + void prepare() { + map.put('y', 'a'); + map.put('e', 'o'); + map.put('q', 'z'); + + String[] from = new String[3]; + String[] to = new String[3]; + + to[0] = ""ejp mysljylc kd kxveddknmc re jsicpdrysi""; + to[1] = ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd""; + to[2] = ""de kr kd eoya kw aej tysr re ujdr lkgc jv""; + from[0] = ""our language is impossible to understand""; + from[1] = ""there are twenty six factorial possibilities""; + from[2] = ""so it is okay if you want to just give up""; + for (int i = 0; i < to.length; i++) { + char[] t = to[i].toCharArray(); + char[] f = from[i].toCharArray(); + for (int j = 0; j < f.length; j++) { + char fc = f[j]; + char tc = t[j]; + map.put(tc, fc); + } + } + for (char c = 'a'; c <= 'z'; c++) { + if (map.containsKey(c)) { + continue; + } + + for (char c2 = 'a'; c2 <= 'z'; c2++) { + if (map.containsValue(c2)) { + continue; + } + map.put(c,c2); + } + + } + + } + + + @Override + String solveCase(JamCase jamCase) { + StringBuilder b = new StringBuilder(); + STCase ca = (STCase) jamCase; + char[] chars = ca.str.toCharArray(); + + for (int i = 0; i < chars.length; i++) { + char c = chars[i]; + b.append(map.get(c)); + + } + return b.toString(); + } + + @Override + JamCase parseCase(List file, int line) { + STCase ca = new STCase(); + ca.lineCount = 1; + ca.str = file.get(line); + return ca; + } +} + +class STCase extends JamCase { + String str; +}" +A21714,"package ex2; + +import java.util.Scanner; + +public class main { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int n = in.nextInt(); + + for(int i = 0; i < n; i++) { + int g = in.nextInt(); // participants + int su = in.nextInt(); // anomalies + int s = in.nextInt(); // note maximum + int ctn = 0; + for(int j = 0; j < g; j++) { + int p = in.nextInt(); // score + + if(3*s <= p || 2*(s-1)+s <= p || (s-1) + 2*s <= p) ctn++; + else if (su > 0 && p > 0 && ((s-2)+2*s <= p || 2*(s-2)+s <= p || (s-2)+(s-1)+s <= p)) { ctn++; su--;} + } + System.out.println(""Case #""+(i+1)+"": ""+ctn); + } + + } + +} +" +A20080,"package main; + +import java.io.FileReader; +import java.io.IOException; +import java.util.Vector; + +import qualificationRound.Dancing; +import qualificationRound.Googlerese; +import qualificationRound.Recycled; + +import exception.GiveUpException; + +public class Main { + + /** + * + * @param args + */ + public static void main(String[] args) { + + String inputFilename = ""B-large.in""; + String outputFilename = ""B-large.out""; + + String output = """"; + + FileHandling filesHandler = new FileHandling(); + + FileReader file = null; + + Vector inputVector = null; + + try { + + file = filesHandler.openFileForReading(inputFilename); + inputVector = filesHandler.readLinesFromFile(file); + } catch (GiveUpException e) { + System.err.println(""exiting..""); + } catch (IOException e) { + System.err.println(""error while reading..""); + } + + // ---------------| Place Code Here |------------------------- + + // output = QualificationRound_A(inputVector); + output = QualificationRound_B(inputVector); + // output = QualificationRound_C(inputVector); + + // -----------------| End of Code |--------------------------- + + try { + + filesHandler.writeToFile(outputFilename, output); + System.out.println(""\n----------------------------------\n""); + System.out.println(output); + } catch (GiveUpException e) { + System.err.println(""error while writing..""); + } + } + + private static String QualificationRound_A(Vector pInputVector) { + + String output = """"; + + int T = Integer.valueOf(pInputVector.get(0)); + + for (int i = 1; i <= T; i++) { + + String result = Googlerese.translate(pInputVector.get(i)); + + output = output + ""Case #"" + i + "": "" + result + ""\n""; + } + + return output; + } + + private static String QualificationRound_B(Vector pInputVector) { + + String output = """"; + + int T = Integer.valueOf(pInputVector.get(0)); + + for (int i = 1; i <= T; i++) { + + String line[] = pInputVector.get(i).split("" ""); + + int N = Integer.parseInt(line[0]); + int S = Integer.parseInt(line[1]); + int P = Integer.parseInt(line[2]); + + int[] Ti = new int[N]; + + for (int j = 0; j < N; j++) + Ti[j] = Integer.parseInt(line[j + 3]); + + int result = Dancing.howMany(N, S, P, Ti); + + output = output + ""Case #"" + i + "": "" + result + ""\n""; + } + + return output; + } + + private static String QualificationRound_C(Vector pInputVector) { + + String output = """"; + + int T = Integer.valueOf(pInputVector.get(0)); + + for (int i = 1; i <= T; i++) { + + String line[] = pInputVector.get(i).split("" ""); + + double A = Double.parseDouble(line[0]); + double B = Double.parseDouble(line[1]); + + double result = Recycled.howMany(A, B); + + output = output + ""Case #"" + i + "": "" + result + ""\n""; + + System.out.print(output); + System.out.flush(); + } + + return output; + } +} +" +A20921,"package codejam; + +import java.io.*; +import java.util.*; + +public class test { + + public static void main(String[] args) { + + try{ + + int googlers=0; + int surprises=0; + double bestResult=0; + double score=0; + int possible=0; + + + + BufferedReader f = new BufferedReader(new FileReader(""X:/programacion/codejam/2012/1B/B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""X:/programacion/codejam/2012/1B/B-large.out""))); + + StringTokenizer st1 = new StringTokenizer(f.readLine()); + + long numCasosDePrueba=Integer.parseInt(st1.nextToken()); + + for (int i=1;i<=numCasosDePrueba;i++){ + st1 = new StringTokenizer(f.readLine()); + googlers = Integer.parseInt(st1.nextToken()); + surprises = Integer.parseInt(st1.nextToken()); + bestResult = Double.parseDouble(st1.nextToken()); + possible=0; + + for(int j=1;j<=googlers;j++){ + score=Double.parseDouble(st1.nextToken()); + score=score-bestResult; + if(score>=0){ + if(bestResult-(score/2)<=1) possible++; + else{ + if (surprises>0){ + if(bestResult-(score/2)<=2){ + possible++; + surprises--; + } + } + } + } + } + + out.print(""Case #""+i+"": ""+possible); + if (i!=numCasosDePrueba) out.println(); + + } + out.close(); + System.exit(0); + } + catch(Exception e){ + System.out.println(e.getMessage()); + } + + } + +} +" +A20815,"import java.util.*; +import static java.lang.System.*; + +class B{ + + static public void main(String[] args){ + Scanner sc = new Scanner(System.in); + int cases = Integer.parseInt(sc.nextLine()); + for(int c = 1; c<=cases; c++){ + String[] s = sc.nextLine().split("" ""); + int n = Integer.parseInt(s[0]); + int sur = Integer.parseInt(s[1]); + int p = Integer.parseInt(s[2]); + int[] score = new int[n]; + int cz = 0; + for(int i = 0; i=p) + cnt++; + else{ + if(nsur == (p-1)){ + if(i%3 != 1) + pot++; + } + } + } + cnt += Math.min(pot, sur); + out.println(""Case #""+c+"": ""+cnt); + } + } + +}" +A21866,"import java.io.*; +import java.util.*; +import java.lang.*; + + +public class Googlers { + + + private BufferedReader br; + private int numCases; + + public Googlers(String input){ + try{ + FileInputStream fstream = new FileInputStream(input); + DataInputStream in = new DataInputStream(fstream); + br = new BufferedReader(new InputStreamReader(in)); + + numCases = Integer.parseInt(br.readLine()); + + for(int i=0;i0 && totals[i]<30){ + int temp=rem[i]; + if(temp==2){ + if(numSurprising >0){ + if(scores[i][0]+2<=10 && scores[i][0]+2>=p){ + scores[i][0]=scores[i][0]+2; + numSurprising--; + + } + else{ + scores[i][0]=scores[i][0]+1; + scores[i][1]=scores[i][1]+1; + + } + } + else{ + scores[i][0]=scores[i][0]+1; + scores[i][1]=scores[i][1]+1; + } + rem[i]=-1; + } + else if(temp==1){ + scores[i][0]=scores[i][0]+1; + rem[i]=-1; + } + } + } + + if(numSurprising >0){ + for(int i=0;i=p){ + scores[i][0]=scores[i][0]+1; + scores[i][1]=scores[i][1]-1; + numSurprising--; + rem[i]=-1; + if(numSurprising==0)break; + } + } + } + + if(numSurprising >0){ + for(int i=0;i=p){ + count++; + break; + } + } + } + + System.out.println(count); + + } + + + public static void main(String[] args) { + + Googlers g= new Googlers(""input.txt""); + + + } + +} +" +A20536,"package com.codejam; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class CodeJam1 { + char map[]; + + public static void main(String[] args) { + Scanner fileIn = null; + FileWriter fileOut = null; + + try { + fileIn = new Scanner(new File(""input.txt"")); + fileOut = new FileWriter(new File(""output.in"")); + int noOfTestCases = Integer.parseInt(fileIn.nextLine()); + + int testCase = 0; + while (fileIn.hasNextLine()) { + testCase++; + //fileIn.nextLine(); + int noOfPpl = fileIn.nextInt(); + int s = fileIn.nextInt(); + int p = fileIn.nextInt(); + int input[] = new int[noOfPpl]; + int noOfSurprise=0,count=0; + for(int i=0;iinput[i]){ + continue; + } + int remainingSum = input[i]-p; + int q = remainingSum/2; + if(q>=p){ + count++; + continue; + } + if((p-q)<2){ + count++; + } + else if((p-q)==2 && noOfSurprise0) { + S--; + num++; + } + } else if(p- min < 2){ + num ++; + } + } + + pw.println(""Case #"" + i +"": "" + num); + System.out.println(""Case #"" + i +"":"" +num); + } + pw.flush(); + pw.close(); + } + +} +" +A21446,"package DancingWithGooglers; + +public class Googler implements Comparable { + + /** + * @param args + */ + private int base; + private int remainder; + private int max; + private int total; + private boolean mayBeSurprising; + + public Googler(int score){ + total = score; + remainder = score %3 ; + base = (score - remainder) /3; + + } + + + public int getTotal(){ + return total; + } + + public int getMax(boolean canbeSur){ + if(canbeSur){ + if(remainder <= 1){ + if(base !=0){ + return base + 1; + } + else{ + return base; + } + } + else{ + return base + 2; + } + } + else{ + if(remainder <= 1){ + return base + remainder; + } + else{ + return base+1; + } + + } + } + + + @Override + public int compareTo(Object o) { + // TODO Auto-generated method stub + int otherTotal = ((Googler)o).getTotal(); + if(total < otherTotal){ + return -1; + } + else if (total == otherTotal){ + return 0; + } + else{ + return 1; + } + + } + + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} +" +A20662,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.StringTokenizer; + +/** + * + */ + +/** + * @author Manthravadi + * + */ + +class Googler{ + int surpriseValue,nonSurpriseValue; + boolean isSurprise; + +} +public class Triplets { + + static int[] nonSurprise=new int[]{0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; + static int[] surprise=new int[]{-1,-1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,-1,-1}; + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int tc=Integer.parseInt(br.readLine()); + int t = 1,len; + FileChannel rwChannel = new RandomAccessFile(""triplets.txt"", ""rw"").getChannel(); + String string = new String(); + + while(t<=tc){ + int count=0; + StringTokenizer st = new StringTokenizer(br.readLine(), "" ""); + + int[] myArr = new int[st.countTokens()]; + + //myArr[0]=n;myArr[1]=s;myAarr[2]=p; + + for(int i = 0;st.hasMoreTokens();i++){ + + myArr[i]=Integer.parseInt(st.nextToken()); + } + + ArrayList g = new ArrayList(); + int p = myArr[2]; + int myArrLength = myArr.length; + + for(int i = 3;i=p && (myArr[1]-- >0)?true:false):(ge.surpriseValue>=p && (myArr[1]-- >0)?true:false)) + count++; + + } + } + + g=null; + + if(t!=tc) + string+=""Case #""+t+"": ""+count+""\n""; + + else + string+=""Case #""+t+"": ""+count; + + t++; + count = 0; + } + + len = string.length(); + byte[] buffer = string.getBytes(); + ByteBuffer wrBuf = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, len); + wrBuf.put(buffer); + } + catch(ArrayIndexOutOfBoundsException aioobe){ + System.out.println(aioobe.getMessage()+"" ""+aioobe.getCause()); + aioobe.printStackTrace(); + } + catch(IOException ioe){ + System.out.println(""Error : ""+ioe.getMessage()); + ioe.printStackTrace(); + } + + catch(Exception e){ + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + + } + +} +" +A21553,"import java.io.*; +import java.util.*; + +public class DancingGooglers { + public static void main(String[] args) { + try { + Scanner in = new Scanner(new File(""C:/Users/Ross/Downloads/B-large.in"")); + int T = in.nextInt(); + String out = """"; + for(int i = 0; i < T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int count = 0; + for(int j = 0; j < N; j++) { + int t = in.nextInt(); + if(t > 3*p-3) count++; + else if(S > 0 && t >= 3*p-4 && t != 0) { + S--; + count++; + } + } + out += ""Case #"" + (i+1) + "": ""; + out += count + ""\n""; + } + System.out.println(out); + } + catch(Exception e) { + e.printStackTrace(); + } + } +} +" +A21751,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class BDanceWithGooglers { + + public static void solve() throws IOException { + File f = new File(""E:\\downloads\\B-large.in""); + BufferedReader reader = new BufferedReader(new FileReader(f)); + File f2 = new File(""C:\\Users\\kimo\\Desktop\\out.txt""); + BufferedWriter writer = new BufferedWriter(new FileWriter(f2)); + int x = Integer.parseInt(reader.readLine()); + int a[] = null; + String st[] = null; + for (int i = 0; i < x; i++) { + st = reader.readLine().split("" ""); + a = new int[st.length]; + for (int j = 0; j < st.length; j++) + a[j] = Integer.parseInt(st[j]); + + int s = a[1]; + int p = a[2]; + int count = 0; + int exact = p + p - 1 + p - 1; + int surp = p + p - 2 + p - 2; + for (int k = 3; k < a.length; k++) + if (a[k] / 3 >= p || a[k] >= exact&&a[k]>=p) + count++; + else + + if (a[k] >= surp && s-- > 0&&a[k]>=p) + count++; + writer.write(""Case #"" + (i + 1) + "": "" + count); + writer.newLine(); + + } + reader.close(); + writer.close(); + } + + public static void main(String[] args) throws IOException { + solve(); + + } + +} +" +A20885,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class Q2 { + public static Problem[] probs; + + static class Problem { + public int N; + public int S; + public int p; + public int[] t; + } + + public static void main(String[] args) { + String inputFile = args[0]; + parseFile(inputFile); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(inputFile + "".out"")); + for (int i=0; i0) { + count++; + } + } + } else { + int minWithS = 3*p.p-4; + int min = 3*p.p-2; + int maybe = 0; + for (int i=0; i=min) { + count++; + } else if (p.t[i]>=minWithS) { + maybe++; + } + } + count += Math.min(maybe, p.S); + } + return """" + count; + } + + public static void parseFile(String inputFile) { + BufferedReader br; + try { + br = new BufferedReader(new FileReader(inputFile)); + String line = br.readLine(); + probs = new Problem[Integer.parseInt(line)]; + line = br.readLine(); + for (int i=0; i=thres){ + counter++; + }else if((g[k]/3+1)>=thres&&(g[k]/3-1)>=0&&surpri!=0){ + surpri--; + counter++; + } + break; + case 1: + if((g[k]/3+1)>=thres){ + counter++; + } + break; + case 2: + if((g[k]/3+1)>=thres){ + counter++; + } + else if((g[k]/3+2)>=thres&&surpri!=0){ + surpri--; + counter++; + } + break; + } + } + bw.write(output.toString()+counter); + bw.newLine(); + } + bw.close(); + }catch (Exception e) { + e.printStackTrace(); + } + + } + +} +" +A21888,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class ProblemB { + + public static void main(String[] args) throws FileNotFoundException { + start(); + } + + public static void start() throws FileNotFoundException { + File file = new File(""./""); + String name = """"; + for (File f : file.listFiles()) { + if (f.getName().endsWith("".in"")) { + name = f.getName().replaceFirst(""\\.in"", """"); + break; + } + } + Scanner in = new Scanner(new File(name + "".in"")); + PrintWriter out = new PrintWriter(new File(name + "".out"")); + new Solution(in, out); + out.close(); + } + + public static class Solution { + + public Solution(Scanner in, PrintWriter out) { + int cases = in.nextInt(); + in.nextLine(); + for (int i = 1; i <= cases; i++) { + String answer = ""Case #"" + i + "": "" + compute(in.nextLine()); + out.println(answer); + System.out.println(answer); + } + } + + private int compute(String s) { + Scanner sc = new Scanner(s); + int googlers = sc.nextInt(); + int surprizing = sc.nextInt(); + int points = sc.nextInt(); + int answer = 0; + for (int i = 0; i < googlers; i++) { + int thisPoint = sc.nextInt(); + int guaranteedWin = points * 3 - 2; + int possibleWin = points * 3 - 4; + + if (thisPoint == 0) { + if (points == 0) { + answer++; + } + } else if (thisPoint == 1) { + if (points == 0 || points == 1) { + answer++; + } else if (points == 2 && surprizing > 0) { + surprizing--; + answer++; + } + } else if (thisPoint >= guaranteedWin) { + answer++; + } else if (thisPoint >= possibleWin && surprizing > 0) { + surprizing--; + answer++; + } + } + return answer; + } + } +} +" +A22094,"import java.io.*; +import java.util.*; + +public class test { + + public static void main(String[] args) throws IOException { + + // Location of file to read + + functions aa = new functions(); + File file = new File(""input.txt""); + Writer output = new BufferedWriter(new FileWriter(""output.txt"")); + int i = 1; + int answer = 0; + String A = """"; + String B = """"; + int j = 0; + int n = 0; + int N = 0; + int[] numbers = new int[101]; + int l = 0,p = 0,s=0,k=0;; + try { + + Scanner scanner = new Scanner(file); + N = Integer.parseInt((String)scanner.nextLine()); + + while (scanner.hasNextLine()) { + A = """"; + B = """"; + j = 0; + l = 0; + p = 0; + s = 0; + n = 0; + + String line = scanner.nextLine(); + while(line.charAt(j) != ' '){ + A = A + line.charAt(j); + j++; + } + n = Integer.parseInt(A); + j++; + A = """"; + for(k = 1; k <= n+1;k++){ + while(line.charAt(j) != ' '){ + A = A + line.charAt(j); + j++; + } + if(k == 1) s = Integer.parseInt(A); + else if(k == 2) p = Integer.parseInt(A); + else numbers[l++] = Integer.parseInt(A); + j++; + A = """"; + } + while(j < line.length()){ + B = B + line.charAt(j); + j++; + } + numbers[l++] = Integer.parseInt(B); + + answer = aa.solve(numbers,p,s,n); + + if(i < N) + output.write(""Case #"" + i +"": ""+ answer +""\n""); + else + output.write(""Case #"" + i +"": ""+ answer); + + i++; + } + scanner.close(); + output.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + } +" +A21065,"import java.io.*; +import java.util.*; +class DancingGooglers +{ + public static void main(String args[]) throws Exception + { + Scanner in = new Scanner(new File(""B-large.in"")); + FileWriter out = new FileWriter(new File(""B-large.out.txt"")); + int t = Integer.parseInt(in.nextLine()); + for(int x = 1; x <= t; x++) + { + String str = in.nextLine(); + Scanner sn = new Scanner(str); + int n, s, p, y; + n = sn.nextInt(); + s = sn.nextInt(); + p = sn.nextInt(); + y = 0; + int scores[] = new int[n]; + for(int a = 0; a < n; a++) + { + scores[a] = sn.nextInt(); + } + for(int score : scores) + { + int base = score/3; + switch(score % 3) + { + case 0 : + { + if(base >= p) + { + y++; + } + else if(s > 0 && base > 0 && base + 1 >= p) + { + y++; + s--; + } + } + break; + case 1 : + { + if(base >= p || base + 1 >= p) + { + y++; + } + else if(s > 0 && base + 1 >= p) + { + y++; + s--; + } + } + break; + case 2 : + { + if(base + 1 >= p || base >= p) + { + y++; + } + else if(s > 0 && base + 2 >= p) + { + y++; + s--; + } + } + } + } + System.out.println(""Case #"" + x + "": "" + y); + out.write(""Case #"" + x + "": "" + y + ""\n""); + } + out.flush(); + out.close(); + } +}" +A22047,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + + +public class _2012_QR_ProblemB { + public static void main(String[] args){ + try { + BufferedReader in = new BufferedReader(new FileReader(""C://B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""C://B-large.out"")); + + int numberOfTests = Integer.parseInt(in.readLine()); + for (int i = 0; i < numberOfTests; i++) { + + StringTokenizer st = new StringTokenizer(in.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int alto = (p-1)*3 + 1; + int baixo = (p != 1) ? (p-1)*3 - 1 : 1; + int quant = 0; + int poss = 0; + for (int j = 0; j < N; j++) { + int nota = Integer.parseInt(st.nextToken()); + if (nota >= alto){ + quant++; + }else{ + if (nota >= baixo){ + poss++; + } + } + } + quant += (poss > S) ? S : poss; + + out.append(""Case #"" + (i+1) +"": "" + quant); + if (i + 1 < numberOfTests){ + out.newLine(); + } + + + } + out.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +}" +A20571,"package ProblemSolvers; + +import CaseSolvers.GooglereseCase; +import CaseSolvers.WiresCase; + +public class Googlerese extends ProblemSolver { + + public Googlerese(String filePath) { + super(filePath); + } + + @Override + public void process() { + cases = io.readInt(); + + for (int i = 1; i <= cases; i++) { + new GooglereseCase(i, 1, io).process().printSolution(); + } + } +} +" +A22407,"import java.util.ArrayList; +import java.util.Scanner; + + +public class GooglersDancing { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int noCases = in.nextInt(); + + for(int i = 0; i < noCases; i++){ + int noGooglers = in.nextInt(); + int noSuprises = in.nextInt(); + int minBestResult = in.nextInt(); + ArrayList scores = new ArrayList(); + ArrayList possibleSurprises = new ArrayList(); + for(int j = 0; j < noGooglers; j++){ + scores.add(in.nextInt()); + possibleSurprises.add(0); + } + int counter = 0; + for(int j = 0; j < noGooglers; j++){ + int score = scores.get(j); + int others = score - minBestResult; + if(others < 0){ + possibleSurprises.set(j,-2); + continue; + } + if(score < 2){ + possibleSurprises.set(j,-1); + if(score == 0 && minBestResult == 0){ + counter++; + continue; + } + if(score == 1 && (minBestResult <= 1)){ + counter++; + continue; + } + continue; + } + if(score > 28){ + possibleSurprises.set(j,-1); + counter++; + continue; + } + if(Math.ceil(others / 2) < (minBestResult - 2)){ + possibleSurprises.set(j,-2); + continue; + } + counter++; + if((others >= minBestResult*2-2) && (others <= minBestResult*2+2)){ + possibleSurprises.set(j,1); //maybe surprise + } + else { + boolean foundMaybe = false; + for(int k = minBestResult+1; k <= 10; k++){ + others = score - k; + if((others >= k*2-2) && (others <= k*2+2)){ + possibleSurprises.set(j,1); //maybe surprise + foundMaybe = true; + break; + } + } + if(!foundMaybe){ + possibleSurprises.set(j,2); // must be surprise + } + } + } + + int must = 0; + int maybe = 0; + int noes = 0; + for(Integer surp : possibleSurprises){ + if(surp.intValue() == 1){ + maybe++; + } + if(surp.intValue() == 2){ + must++; + } + if(surp.intValue() == -1){ + noes++; + } + } + if(must > noSuprises){ + System.out.println(""Case #""+(i+1)+"": "" + (noSuprises+maybe+noes)); + } + else{ + System.out.println(""Case #""+(i+1)+"": "" + counter); + } + } + } + +} +" +A20197," + + +import java.io.*; +import java.util.*; + +public class DG { + private static String fileName = DG.class.getSimpleName().replaceFirst(""_.*"", """"); + private static String inputFileName = ""D:\\cj12\\""+fileName + "".in""; + private static String outputFileName = ""D:\\cj12\\""+fileName + "".out""; + private static Scanner in; + private static PrintWriter out; + + public static void main(String[] args) throws IOException { + Locale.setDefault(Locale.US); + if (args.length >= 2) { + inputFileName = args[0]; + outputFileName = args[1]; + } + in = new Scanner(new FileReader(inputFileName)); + out = new PrintWriter(outputFileName); + int tests = in.nextInt(); + //in.nextLine(); + for (int t = 1; t <= tests; t++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int res = 0; + for(int i=0;i= ((3*p)-2)) + res++; + else if(tot > 0 && s > 0 && (tot >= ((3*p)-4))) { + res++; + s--; + } + } + System.out.println(""Case #"" + t + "": ""+res); + out.println(""Case #"" + t + "": ""+res); + } + in.close(); + out.close(); + } +} + + +" +A20679,"package test; + +import javax.print.attribute.standard.DateTimeAtCompleted; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.sql.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Scanner; +public class A { + + public static int getDiff(int x , int y , int z , int l){ + if(y>=l && z>=l) + return 0; + ArrayList arr = new ArrayList<>(); + + + arr.add(Math.abs(x-y)); + arr.add(Math.abs(x-z)); + arr.add(Math.abs(y-z)); + + return Collections.max(arr); + + + } + + public static void main(String[] args) throws Exception { + + Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(""bout.txt""))); + int repeats=0; + int numTests; + int t; + int limit,ex,k; + repeats = in.nextInt(); + for(int j=1;j<=repeats;j++) + { + // System.out.print(""Case #""+j+"":""); + out.print(""Case #"" + (j) + "": ""); + numTests = in.nextInt(); + ex = in.nextInt(); + limit = in.nextInt(); + int res=0; + for(int i=0;i=limit){ + if(limit != 0 && t/limit==3) + res++; + else{ + int rMain =t-limit; + int r1 = rMain/2; + int r2 = t-limit-r1; + int fin = getDiff(limit,r1,r2,limit); + if(fin<2) + res++; + else if(fin==2 && ex>0){ + res++; + ex--; + } + + } + } + + + + + + } + + //System.out.println("" ""+res); + System.out.println(""Case #"" + (j) + "": "" + res); + } + + /* + try { + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(""B-small-attempt0.in""))); + // int t = Integer.parseInt(in.readLine()); + int repeats = Integer.parseInt(in.readLine()); + + PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(""bout.txt""))); + for (int i = 1; i <= repeats; i++) { + //String res = """"; + int numTests = (in.read()); + int ex = in.read(); + int limit = in.read(); + int res=0; + // String input = in.readLine(); + for(int j=0;jlimit){ + if(t%limit==0) + res++; + else{ + int rMain =t-limit; + int r1 = rMain/2; + int r2 = t-limit-r1; + + int fin = getDiff(limit,r1,r2,limit); + if(fin<2) + res++; + else if(fin==2 && ex>0){ + res++; + ex--; + } + } + } + } + out.println(""Case #"" + (i) + "": "" + res); + } + out.close(); + }catch(Exception e){ + e.printStackTrace(); + }*/ + } +} + + +" +A23007,"package proba; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +public class ProblemB { + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + + Map> map = new HashMap>(); + Map> surprises = new HashMap>(); + for (int j1 = 0; j1 <= 10; j1++) { + for (int j2 = 0; j2 <= 10; j2++) { + for (int j3 = 0; j3 <= 10; j3++) { + if (Math.abs(j1 - j2) > 2 || Math.abs(j2 - j3) > 2 + || Math.abs(j1 - j3) > 2) { + continue; + } + int sum = j1 + j2 + j3; + if (Math.abs(j1 - j2) == 2 || Math.abs(j2 - j3) == 2 + || Math.abs(j1 - j3) == 2) { + if (!surprises.containsKey(sum)) { + Set list = new HashSet(); + Score score = new Score(j1, j2, j3); + list.add(score); + surprises.put(sum, list); + } else { + Set list = surprises.get(sum); + Score score = new Score(j1, j2, j3); + list.add(score); + surprises.put(sum, list); + } + } else { + if (!map.containsKey(sum)) { + Set list = new HashSet(); + Score score = new Score(j1, j2, j3); + list.add(score); + map.put(sum, list); + } else { + Set list = map.get(sum); + Score score = new Score(j1, j2, j3); + list.add(score); + map.put(sum, list); + } + } + } + } + } + Scanner s = new Scanner(new FileInputStream(""B-large.in"")); + int cases = s.nextInt(); + s.nextLine(); + + for (int i = 0; i < cases; i++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] scores = new int[N]; + int answer = 0; + int noOfSurprises = 0; + for (int j = 0; j < N; j++) { + scores[j] = s.nextInt(); + } + if (s.hasNextLine()) + s.nextLine(); + for (int j = 0; j < N; j++) { + Set normal = map.get(scores[j]); + Set surps = surprises.get(scores[j]); + boolean foundInNormal = false; + for (Score score1 : normal) { + if (score1.isScoreAbove(p)) { + answer++; + foundInNormal = true; + } + } + if (!foundInNormal) { + if (surps != null && noOfSurprises < S ) { + for (Score score1 : surps) { + if (score1.isScoreAbove(p)) { + answer++; + noOfSurprises++; + } + } + } + } + /* + else if (surps != null && noOfSurprises < S + && surps.size() > S) { + // for() + // comb1(combstr); + + Map> best = new HashMap>(); + for (Score score1 : surps) { + int subanswer = 0; + if (score1.isScoreAbove(p)) { + answer++; + foundInNormal = true; + } + if (!best.containsKey(subanswer)) { + Set list = new HashSet(); + list.add(score1); + best.put(subanswer, list); + } else { + Set list = map.get(subanswer); + list.add(score1); + best.put(subanswer, list); + } + } + Set bests = best.keySet(); + List bestList = new ArrayList(bests); + Collections.sort(bestList); + for (int n = 0; n < S; n++) { + Integer h = bestList.get(bestList.size() - (1 + n)); + answer = answer + h; + } + for (Score score : normal) { + if (score.isScoreAbove(p)) { + answer++; + } + } + + } else { + for (Score score : normal) { + if (score.isScoreAbove(p)) { + answer++; + googlers[j] = new Googler(score, scores[j]); + } + } + }*/ + } + System.out.println(""Case #"" + (i + 1) + "": "" + answer); + } + + } + + private static class Score { + int a; + int b; + int c; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + a; + result = prime * result + b; + result = prime * result + c; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Score other = (Score) obj; + if (a != other.a) + return false; + if (b != other.b) + return false; + if (c != other.c) + return false; + return true; + } + + public Score(int a, int b, int c) { + super(); + int[] arr = { a, b, c }; + Arrays.sort(arr); + this.a = arr[0]; + this.b = arr[1]; + this.c = arr[2]; + } + + public boolean isScoreAbove(int p) { + if (a >= p || b >= p || c >= p) + return true; + return false; + } + + @Override + public String toString() { + return ""["" + a + "", "" + b + "", "" + c + ""]""; + } + + } + +} +" +A20906,"import java.io.*; +public class Googlers { + + + public static void main(String[] args) throws IOException + { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""output.txt""))); + int nc = Integer.parseInt(in.readLine().trim()); + for (int z=1; z<=nc; z++){ + String[] line = in.readLine().trim().split(""\\s+""); + int n = Integer.parseInt(line[0]); + int s = Integer.parseInt(line[1]); + int p = Integer.parseInt(line[2]); + + int count = 0; + + for (int i = 0; i < n; i++) + { + int num = Integer.parseInt(line[3+i]); + System.out.println(3*p-3); + + if (num>3*p-3) count++; + else if ((num>=2)&&(num>=3*p-4)&&(s>0)) + { + count++; + s--; + } + + } + + out.println(String.format(""Case #%d: %d"", z,count)); + } + out.close(); + } + + + + +} +" +A22369,"import java.util.Scanner; + + +public class Dancing { + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + for (int C=1;C<=N;C++) + { + System.out.printf(""Case #%d: "", C); + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int count = 0; + for (int i=0;i=p || (score/3==p-1 && score%3>0)) count ++; + else if (((score/3==p-1) || (score/3==p-2 && score%3==2 && p-2>=0)) && s>0 && score/3-1>=0) + { + s--; + count ++; + } + } + System.out.println(count); + } + } +} +" +A21941,"package jp.funnything.competition.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.BigInteger; + +import org.apache.commons.io.IOUtils; + +public class QuestionReader { + private final BufferedReader _reader; + + public QuestionReader( final File input ) { + try { + _reader = new BufferedReader( new FileReader( input ) ); + } catch ( final FileNotFoundException e ) { + throw new RuntimeException( e ); + } + } + + public void close() { + IOUtils.closeQuietly( _reader ); + } + + public String read() { + try { + return _reader.readLine(); + } catch ( final IOException e ) { + throw new RuntimeException( e ); + } + } + + public BigDecimal[] readBigDecimals() { + return readBigDecimals( "" "" ); + } + + public BigDecimal[] readBigDecimals( final String separator ) { + final String[] tokens = readTokens( separator ); + + final BigDecimal[] values = new BigDecimal[ tokens.length ]; + for ( int index = 0 ; index < tokens.length ; index++ ) { + values[ index ] = new BigDecimal( tokens[ index ] ); + } + + return values; + } + + public BigInteger[] readBigInts() { + return readBigInts( "" "" ); + } + + public BigInteger[] readBigInts( final String separator ) { + final String[] tokens = readTokens( separator ); + + final BigInteger[] values = new BigInteger[ tokens.length ]; + for ( int index = 0 ; index < tokens.length ; index++ ) { + values[ index ] = new BigInteger( tokens[ index ] ); + } + + return values; + } + + public int readInt() { + final int[] values = readInts(); + + if ( values.length != 1 ) { + throw new IllegalStateException( ""Try to read single interger, but the line contains zero or multiple values"" ); + } + + return values[ 0 ]; + } + + public int[] readInts() { + return readInts( "" "" ); + } + + public int[] readInts( final String separator ) { + final String[] tokens = readTokens( separator ); + + final int[] values = new int[ tokens.length ]; + for ( int index = 0 ; index < tokens.length ; index++ ) { + values[ index ] = Integer.parseInt( tokens[ index ] ); + } + + return values; + } + + public long readLong() { + final long[] values = readLongs(); + + if ( values.length != 1 ) { + throw new IllegalStateException( ""Try to read single interger, but the line contains zero or multiple values"" ); + } + + return values[ 0 ]; + } + + public long[] readLongs() { + return readLongs( "" "" ); + } + + public long[] readLongs( final String separator ) { + final String[] tokens = readTokens( separator ); + + final long[] values = new long[ tokens.length ]; + for ( int index = 0 ; index < tokens.length ; index++ ) { + values[ index ] = Long.parseLong( tokens[ index ] ); + } + + return values; + } + + public String[] readTokens() { + return readTokens( "" "" ); + } + + public String[] readTokens( final String separator ) { + return read().split( separator ); + } +} +" +A21314,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Scanner; + + +public class B { + private static final String INPUTFILE = ""./B-large.in""; + private static final String OUTPUTFILE = ""./B-large.out""; + private static FileReader in; + private static FileWriter out; + private static BufferedReader buffIn; + private static BufferedWriter buffOut; + private static Scanner s; + + public static String executeSingle(){ + int res = 0; + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] t= new int[N]; + for(int i=0;i=0;i--){ + if(t[i]>= minimumOKScore){ + res++; + } + else if(t[i]>= minimumPossibleScore && S > 0){ + S--; + res++; + } + } + + + return """"+res; + } + + + public static void execute() throws IOException{ + int n = s.nextInt(); + s.nextLine(); + for(int i=1;i<=n;i++){ + buffOut.append(""Case #""+i+"": ""+executeSingle()); + buffOut.newLine(); + //System.out.println(""Case #""+i+"": ""+executeSingle()); + + } + } + + + public static void main(String[] args) throws IOException { + in = new FileReader(INPUTFILE); + out = new FileWriter(OUTPUTFILE); + buffIn = new BufferedReader(in); + buffOut = new BufferedWriter(out); + s = new Scanner(buffIn); + execute(); + buffOut.flush(); + buffOut.close(); + buffIn.close(); + out.close(); + in.close(); + } + +}" +A21814,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Pb2 { + public static void main(String[] args) { + try { + PrintWriter writer = new PrintWriter(""B-large.out""); + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); + int lines = Integer.parseInt(reader.readLine()); + for(int i = 1; i <= lines; i++) { + String line = reader.readLine(); + writer.println(processLine(i, line)); + writer.flush(); + } + reader.close(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static StringBuffer processLine(int k, String str) { + StringBuffer out = new StringBuffer(""Case #"" + k + "": ""); + Scanner scanner = new Scanner(str); + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int cat0 = 0; + int cat1 = 0; + int cat2 = 0; + int cat3 = 0; + int cat4 = 0; + int cat29 = 0; + for(int i = 0; i < n; i++){ + int tmp = scanner.nextInt(); + if(tmp == 0) { + cat0++; + } else if(tmp == 1) { + cat1++; + } else if(tmp >=29) { + cat29++; + } else if(2 <= tmp && tmp < (3*p-4) && p!= 2) { + cat2++; + } else if(tmp == (3*p-4) || tmp == (3*p-3)) { + cat3++; + } else { + cat4++; + } + } + int t = cat29 + cat4 + cat3; + if(p == 0) { + t = n; + } else if(p == 1) { + t = n - cat0; + } else if(s < cat3) { + t -= cat3 - s; + } + + return out.append(t); + } + +} +" +A21209,"import java.io.InputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public abstract class AbstractCodeJam { + + public void solveProblems(InputStream in, PrintStream out) { + Scanner scan = new Scanner(in); + int nb = scan.nextInt(); + scan.nextLine(); + for (int i = 1; i <= nb; i++) { + Problem problem = readProblem(scan); + // problem.print(); + problem.solve(); + out.println(""Case #"" + i + "": "" + problem.getSolution()); + } + } + + protected abstract Problem readProblem(Scanner scan); + +} +" +A20482,"package gcj2012qr; + +import java.io.*; +import java.util.*; +import java.util.concurrent.*; + +import com.google.*; + +/** + * @author Roman Kosenko + */ +public class DancingWithTheGooglers extends SingleThreadSolution { + public static void main(String[] args) throws Exception { + solve(new SolutionFactory() { + public Callable read(BufferedReader br) throws IOException { + String[] ss = br.readLine().split("" ""); + int n = Integer.parseInt(ss[0]); + assert ss.length == n + 3; + int s = Integer.parseInt(ss[1]); + int p = Integer.parseInt(ss[2]); + int[] t = new int[n]; + for(int i = 0; i < n; i++) + t[i] = Integer.parseInt(ss[3 + i]); + return new DancingWithTheGooglers(t, s, p); + } + }, ""google/src/gcj2012qr/"" + ""B-large.in""); + } + private final int t[], s, p; + public DancingWithTheGooglers(int[] t, int s, int p) { + this.t = t; + this.s = s; + this.p = p; + } + public String call() throws Exception { + int result = 0, surprises = s; + //noinspection ForLoopReplaceableByForEach + for(int i = 0; i < t.length; i++) { + int max = (t[i] + 2) / 3; + if(max + 1 == p && surprises > 0 && (t[i] % 3 == 2 || t[i] % 3 == 0 && t[i] > 0)) { + surprises--; + result++; + } else if(max >= p) + result++; + } + return Integer.toString(result); + } +} +" +A22680,"package gcj2012.qr; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class DancingWithTheGooglers { + + public static int getMax(int s, int p, int[] scores) { + int numHigh = 0; + int numPotential = 0; + int score = 0; + int best = 0; + for (int i = 0; i < scores.length; i++) { + score = scores[i]; + best = (score + 2) / 3; + if (best >= p) { + numHigh++; + } else if ((score > 1) && (score < 29) && (best == p - 1) && + (score % 3 != 1)) { + numPotential++; + } + } + return numHigh + Math.min(numPotential, s); + } + + public static void main(String[] args) throws NumberFormatException, IOException { + DancingWithTheGooglers sit = new DancingWithTheGooglers(); + if (args.length < 1 ) { + System.out.println(""File name not given""); + System.exit(1); + } + BufferedReader br = new BufferedReader(new FileReader(args[0])); + int t = Integer.parseInt(br.readLine()); + for (int i = 1; i <= t; i++) { + String[] test = br.readLine().split("" ""); + int n = Integer.parseInt(test[0]); + int s = Integer.parseInt(test[1]); + int p = Integer.parseInt(test[2]); + int[] scores = new int[n]; + for (int j = 0; j < n; j++) { + scores[j] = Integer.parseInt(test[3 + j]); + } + System.out.printf(""Case #%d: %d\n"", i, getMax(s, p, scores)); + } + br.close(); + } + +} +" +A20743,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + + +public class Qual2 { + private static BufferedReader r; + private static PrintStream outFile; + private static PrintStream out = new PrintStream(new OutputStream() { + @Override + public void write(int b) throws IOException { + System.out.write(b); + outFile.write(b); + } + }); + + public static void main(String[] args) throws IOException { + File f = new File(""/home/blarson/input""); + r = new BufferedReader(new FileReader(f)); + outFile = new PrintStream(new FileOutputStream(new File(""/home/blarson/output""))); + final int numCases = readInt(); + + for(int i = 0; i < numCases; i++) { + out.print(""Case #"" + (i+1) + "": ""); + + solve(); + + out.println(); + } + + out.close(); + } + + private static void solve() throws IOException { + int[] nums = readIntArray(200); + int n = nums[0]; + int surprises = nums[1]; + int desiredScore = nums[2] * 3; + int numWithDesiredScore = 0; + for(int i = 0; i < n; i++) { + int score = nums[3+i]; + if (score < 2 && desiredScore > 1) { + continue; + } + if(score + 2 >= desiredScore) { + numWithDesiredScore++; + } else if (score + 4 >= desiredScore && surprises > 0) { + numWithDesiredScore++; + surprises--; + } + } + out.print(numWithDesiredScore); + } + + private static int[] readIntArray(int maxItems) throws IOException { + int[] array = new int[maxItems]; + String line = r.readLine().trim(); + String[] data = line.split("" ""); + for(int i = 0; i < data.length && i < maxItems; i++) { + array[i] = new Integer(data[i]); + } + return array; + } + + private static int readInt() throws IOException { + String line = r.readLine().trim(); + return new Integer(line); + } + +}" +A20318,"package codejam.dance; + +public class DanceSolver { + + public DanceSolver() { + } + + public String solve(String line) { + + String[] ss = line.split("" ""); + + int n = Integer.parseInt(ss[0]); + int s = Integer.parseInt(ss[1]); + int p = Integer.parseInt(ss[2]); + + int yes = 0, no = 0, surpPoss = 0; + for (int i = 0; i < n; i++) { + int t = Integer.parseInt(ss[3 + i]); + if (t >= p + 2 * Math.max(p - 1, 0)) { + yes++; + } + else if (t >= p + 2 * Math.max(p - 2, 0)) { + surpPoss++; + } + else { + no++; + } + } + + int ans = yes + Math.min(s, surpPoss); + return """" + ans; + } +} +" +A20295,"package sebastianco; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + + +public class DancingWithGooglers { + + public static void main(String[] args) throws Exception { + + BufferedReader reader = null; + BufferedWriter writer = null; + + try { + reader = new BufferedReader(new FileReader(new File(args[0]))); + writer = new BufferedWriter(new FileWriter(new File(args[1]))); + + final int nrOfTestCases = Integer.valueOf(reader.readLine()); + + String lineSepartor = """"; + for (int i = 1; i <= nrOfTestCases; i++) { + writer.write(lineSepartor); + writer.write(String.format(""Case #%d: %d"", + i, new TestCase(reader.readLine()).computeMaxGooglers())); + lineSepartor = ""\n""; + } + + } finally { + if (writer != null) { + writer.flush(); + writer.close(); + } + reader.close(); + } + + } + + public static class TestCase { + + private int n; + private int s; + private int p; + private int[] t; + + public TestCase(String caseLine) { + String[] tokens = caseLine.split("" ""); + n = Integer.parseInt(tokens[0]); + s = Integer.parseInt(tokens[1]); + p = Integer.parseInt(tokens[2]); + t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = Integer.parseInt(tokens[3 + i]); + } + } + +// p-1 p p 3p-1 +// p-1 p-1 p 3p-2 +// p-2 p-1 p 3p-3 +// p-2 p-2 p 3p-4 + public int computeMaxGooglers() { + + final int minTotalScore = 3*p - 2; + final int minSurprisingScoreA = 3*p - 3; + final int minSurprisingScoreB = 3*p - 4; + + int max = 0; + int surprising = s; + + for (int i = 0; i < n; i++) { + if (t[i] >= minTotalScore) { + max++; + } else { + if (surprising > 0 + && t[i] > 0 + && (t[i] == minSurprisingScoreA || t[i] == minSurprisingScoreB)) { + max++; + surprising--; + } + } + } + + return max; + } + + } + + +} +" +A21696,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Competitiopn; + +import java.util.Scanner; + +/** + * + * @author vidz + */ +public class DancingWithTheGooglers { + + public void solve() { + + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + int i = 0, j = 0; + int N = 0;//number of googlers + int S = 0, s = 0;//suprise + int p = 0;//limit to pass + int count = 0; + while (i < T) { + N = sc.nextInt(); + s = S = sc.nextInt(); + p = sc.nextInt(); + j = 0; + count = 0; + while (j < N) { + int temp = sc.nextInt(); + + + if (temp >= (3 * p - 2) ) { + count++; + } else if (temp == (3 * p - 3) && s > 0 && (3 * p - 3) > 0) { + count++; + s--; + } else if (temp == (3 * p - 4) && s > 0 && (3 * p - 4) > 0) { + count++; + s--; + } + + + ++j; + } + + System.out.println(""Case #"" + (i + 1) + "": "" + count); + + ++i; + } + + + } + + public static void main(String[] args) { + new DancingWithTheGooglers().solve(); + } +} +" +A22286,"import java.io.BufferedInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; + +public class Main { + + public static void solve() throws Exception{ + int T = in.readInt(),t = 0; + String format = ""Case #%d: ""; + int N,S,p,a,count; + while(t++ p) + count++; + else if(a > (p-2) && S != 0){ + count++; + S--; + } + } + } + out.println(count); + } + } + static InputReader in; + static OutputWriter out; + + public static void start(){ + in = new InputReader(System.in); + out = new OutputWriter(System.out); + } + + public static void finish() throws Exception{ + out.close(); + } + + public static void main(String[] args) throws Exception { + start(); + solve(); + finish(); + } +} + +class InputReader extends BufferedInputStream{ + + public InputReader(InputStream In){ + super(In); + } + + public char readChar() throws Exception{ + int c = read(); + while(isStringEnd(c)) + c = read(); + return (char) c; + } + + public int readInt() throws Exception { + int sign = 1; + int cur = 0; + int c = read(); + while(isStringEnd(c)) + c = read(); + if(c == '-'){ + sign = -1; + c = read(); + } + do{ + cur *= 10; + cur += c - '0'; + c = read(); + }while(!isStringEnd(c)); + return cur*sign; + } + + public long readLong() throws Exception { + long sign = 1; + long cur = 0; + int c = read(); + while(isStringEnd(c)) + c = read(); + if(c == '-'){ + sign = -1; + c = read(); + } + do{ + cur *= 10; + cur += c - '0'; + c = read(); + }while(!isStringEnd(c)); + return cur*sign; + } + + public double readDouble() throws Exception { + double sign = 1; + double cur = 0; + int c = read(); + while(isStringEnd(c)) + c = read(); + if(c == '-'){ + sign = -1; + c = read(); + } + do{ + cur *= 10; + cur += c - '0'; + c = read(); + }while(!isStringEnd(c) && c!= '.'); + if(c == '.'){ + c = read(); + double r = 0.1; + do{ + cur += r*(c - '0'); + r *= 0.1; + c = read(); + }while(!isStringEnd(c) && c!= '.'); + } + return cur*sign; + } + + public String readStr() throws Exception{ + int c = readChar(); + while(isStringEnd(c)) + c = read(); + StringBuilder res = new StringBuilder(); + do{ + res.append((char)c); + c = read(); + }while(!isStringEnd(c)); + return res.toString(); + } + + public String readLine() throws Exception{ + int c = readChar(); + while(isStringEnd(c)) + c = read(); + StringBuilder res = new StringBuilder(); + do{ + res.append((char)c); + c = read(); + }while(!isEOL(c)); + return res.toString(); + } + + public char[] readCharArray(int s) throws Exception{ + char[] a = new char[s]; + for(int i=0; i void printArray(T[] a, String del){ + for(int i=0; i void printMat(T[][] a, String delRows, String delCols){ + for(int i=0; i void printCollection(Iterable c, String del){ + boolean b = true; + for(T i : c){ + if(b) + b = false; + else + print(del); + print(i); + } + } +}" +A22846,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws IOException { + String filename = ""B-large""; + String inname = filename + "".in""; + String outname = filename + "".out""; + Scanner sc = new Scanner(new File(inname)); + PrintWriter out = new PrintWriter(new FileWriter(outname)); + + int N = sc.nextInt(); + for (int t = 1; t <= N; t++) { + int[] scores = new int[31]; + int numGooglers = sc.nextInt(); + int surprise = sc.nextInt(); + int minPoints = sc.nextInt(); + for (int i = 0; i < numGooglers; i++) { + scores[sc.nextInt()]++; + } + int triple = minPoints * 3; + int ans = 0; + int p = 30; + while (p >= 0) { + scores[p]--; + if (scores[p] >= 0) { + if(p >= triple) { + ans++; + } else if(p >= triple - 2 && minPoints >= 1) { + ans++; + } else if(p >= triple - 4 && minPoints >= 2 && surprise > 0) { + ans++; + surprise--; + } + } else { + p--; + } + } + out.println(""Case #"" + t + "": "" + ans); + System.out.println(""Case #"" + t + "": "" + ans); + } + out.close(); + } +} +" +A21861,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class DancingWiththeGooglers { + + public static void main ( String [] arg ) throws IOException{ + BufferedReader reader = new BufferedReader(new FileReader(new File(""input""))); + PrintWriter output = new PrintWriter(new File(""output"")); + int cases = Integer.valueOf( reader.readLine() ); + for ( int i=1; i<=cases; i++ ){ + StringTokenizer tkn = new StringTokenizer( reader.readLine() ); + int N = Integer.valueOf( tkn.nextToken() ); + int S = Integer.valueOf( tkn.nextToken() ); + int p = Integer.valueOf( tkn.nextToken() ); + int sol=0; + for ( int j=0; j0 && ok(points,p,4) ){ + sol++; + S--; + } + } + } + output.println(""Case #""+i+"": "" + sol ); + } + output.close(); + } + + public static boolean ok( int suma, int p, int sum_delta ){ + for ( int i=0; i<=10; i++ ){ + for ( int j=0; j<=10; j++ ){ + for ( int k=0; k<=10; k++ ){ + if ( i+j+k == suma ){ + int unu = Math.abs(i-j); + int doi = Math.abs(i-k); + int trei = Math.abs(j-k); + if ( unu+doi+trei<=sum_delta ){ + if ( Math.max( Math.max(i, j), k )>=p){ + return true; + } + } + } + } + } + } + return false; + } + +} +" +A22703,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + String li; + int tcn = Integer.parseInt(in.readLine()); + Scanner sc; + int N, S, P; + int[] scr; + for (int tc = 0; tc < tcn; tc++) { + li = in.readLine(); + sc = new Scanner(li); + N = sc.nextInt(); S = sc.nextInt(); P = sc.nextInt(); + scr = new int[N]; + for (int i = 0; i < N; i++) { + scr[i] = sc.nextInt(); + } + + Arrays.sort(scr); + + int result = 0; + for (int i = scr.length - 1; i >=0; i--) { + int tmp = scr[i] / 3; + if (P - tmp >= 3 || (scr[i] == 0 && P > 0)) break; + int r = scr[i] % 3; + if (tmp >= P) { + result++; + } else { + if (P - tmp == 1) { + if (r > 0) { + result++; + } else { + if (S > 0) { + result++; + S--; + } + } + } else { + if (P -tmp == 2) { + if (r == 2 && S > 0) { + result++; + S--; + } + } + } + } + } + + System.out.println(""Case #"" + (tc + 1) + "": "" + result); + } + in.close(); + } + +} +" +A23031,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing.with.the.googlers; + +import java.io.*; +import java.util.ArrayList; +import java.util.StringTokenizer; + +/** + * + * @author Abhishek + */ +public class DancingWithTheGooglers { + + /** + * @param args the command line arguments + */ + + static int NoOfGooglers; + static int surprisingResults; + static int pi; + static int count; + private static String inputFile = ""F:/B-large.in""; + + private static String outputFile = ""F:/Output.txt""; + + public static void main(String[] args) { + // TODO code application logic here + count = 0; + readFile(); + } + + public static void readFile() + { + int totalLines =0; + try + { + FileInputStream fis = new FileInputStream(inputFile); + DataInputStream dis = new DataInputStream(fis); + BufferedReader br = new BufferedReader(new InputStreamReader(dis)); + ArrayList scores = new ArrayList(); + String str; + StringTokenizer st; + + while( (str = br.readLine()) != null) + { + NoOfGooglers = -1; + surprisingResults = -1; + pi = -1; + scores.clear(); + st = new StringTokenizer(str, "" \n""); + scores.clear(); + while( st.hasMoreTokens()) + { + if( totalLines == 0 ) + { + totalLines = Integer.parseInt(str); + break; + } + if( NoOfGooglers == -1) + { + NoOfGooglers = Integer.parseInt(st.nextToken()); + continue; + } + if(surprisingResults == -1) + { + surprisingResults = Integer.parseInt(st.nextToken()); + continue; + } + if(pi == -1) + { + pi = Integer.parseInt(st.nextToken()); + continue; + } + scores.add(Integer.parseInt(st.nextToken())); + } + if ( pi != -1) + { + int passPi = findProbabilityPi(NoOfGooglers, surprisingResults, pi, scores); + writeFile(passPi); + } + } + } + catch(IOException e) + { + System.out.println(""error is "" +e.getMessage()); + } + } + + public static void writeFile(int passPi) + { + String line=""""; + try{ + // Create file + FileWriter fstream = new FileWriter(outputFile,true); + count++; + + BufferedWriter out = new BufferedWriter(fstream); + line = ""Case #""+count+"": ""+passPi; + out.write(line); + out.newLine(); + out.close(); + } + catch(Exception e) + { + System.out.println(""error is "" +e.getMessage()); + } + } + + public static int findProbabilityPi(int NoOfGooglers, int surprisingResults,int pi,ArrayListscores) + { + int passPi = 0; + NoOfGooglers = 3; + for(int sc : scores) + { + if( sc % NoOfGooglers == 0) + { + if( (sc/3) == 0 && pi != 0) + continue; + if( sc/NoOfGooglers >= pi) + { passPi++; + continue; + } + if( surprisingResults>0 ) + { + + if( (sc/NoOfGooglers)+1 >= pi) + { passPi++; + surprisingResults--; + continue; + } + + } + + } + else if( (sc+1) % NoOfGooglers == 0) + { + if( (sc+1)/NoOfGooglers >= pi) + { + passPi++; + continue; + } + } + else if( (sc-1) % NoOfGooglers == 0) + { + if( (((sc-1)/NoOfGooglers)+1) >= pi) + { + passPi++; + continue; + } + } + + if(surprisingResults > 0) + { + if( (sc+2) % NoOfGooglers == 0) + { + if( (sc+2)/NoOfGooglers >= pi) + { + passPi++; + surprisingResults--; + continue; + } + } + else if( (sc-2) % NoOfGooglers == 0) + { + if( (((sc-2)/NoOfGooglers)+2) >= pi) + { + passPi++; + surprisingResults--; + continue; + } + } + } + } + return passPi; + } + +} +" +A20860,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package utils; + +/** + * + * @author Fabien Renaud + */ +public interface JamParser { + + public JamCase getJamCase(int number); +}" +A22776,"package lt.kasrud.gcj.common.io; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public class Reader { + public static List readFile(String filename) throws IOException { + List results = new ArrayList(); + + BufferedReader reader = new BufferedReader(new FileReader(filename)); + String line = null; + while ((line = reader.readLine()) != null) { +// String[] tokens = line.trim().split("" ""); +// results.add(Arrays.asList(tokens)); + results.add(line); + } + + reader.close(); + return results; + } +} +" +A22699,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author Serban + */ +public class Input { + + PrintWriter out; + + public Input(String fileName) { + //C-large-practice.in + try { + out = new PrintWriter(new File(""result.txt"")); + Scanner scan = new Scanner(new File(fileName)); + int T = scan.nextInt(); + scan.nextLine(); + for (int i = 0; i < T; i++) { + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int[] marks = new int[N]; + for(int j=0;j=1) + nr++; + break; + default: + if(c >= 3*p-2) + nr++; + else + if(leftS > 0 && c >= 3*p-4) { + nr++; + leftS--; + } + } + } + System.out.println(nr); + out.print(nr); + out.println(); + out.flush(); + } +} +" +A22831,"package mgg.problems; + +import java.util.List; + +import mgg.utils.CorrespondenceUtils; +import mgg.utils.FileUtil; +import mgg.utils.StringUtils; + +/** + * @author manolo + * @date 14/04/12 + */ +public class ProblemA { + + public final static String EXAMPLE_IN = ""A-example.in""; + public final static String EXAMPLE_OUT = ""A-example.out""; + + public final static String A_SMALL_IN = ""A-small-attempt1.in""; + public final static String A_SMALL_OUT = ""A-small-attempt1.out""; + + public final static String delim = "" ""; + + public static String solve(FileUtil util) { + + String line; + List listOfCharacters; + + line = util.getLine(); + + listOfCharacters = StringUtils.allCharactersToList(line); + + char englishTranslation; + StringBuilder solutionBuilder = new StringBuilder(); + + for (char c : listOfCharacters){ + + System.out.print(""char: "" + c); + englishTranslation = CorrespondenceUtils.getGooglereseCorrespondence(c); + System.out.println(""("" + englishTranslation + "")""); + + solutionBuilder.append(englishTranslation); + + } + + return solutionBuilder.toString(); + } +}" +A20989,"package fixjava; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; + +import fixjava.ParallelWorkQueue.CallableFactory; + +public class ArrayUtils { + + // ------------------------------------------------------------------------------------------------ + + /** Convert a 2D float array into a 2D double array */ + public static double[][] toDblArray(float[][] data) { + double[][] copy = new double[data.length][data[0].length]; + for (int i = 0; i < data.length; i++) + for (int j = 0; j < data[0].length; j++) + copy[i][j] = data[i][j]; + return copy; + } + + /** Convert a 2D double array into a 2D float array */ + public static float[][] toFltArray(double[][] data) { + float[][] copy = new float[data.length][data[0].length]; + for (int i = 0; i < data.length; i++) + for (int j = 0; j < data[0].length; j++) + copy[i][j] = (float) data[i][j]; + return copy; + } + + /** Transpose an array */ + public static double[][] transpose(double[][] data) { + double[][] copy = new double[data[0].length][data.length]; + for (int i = 0; i < data.length; i++) + for (int j = 0; j < data[0].length; j++) + copy[j][i] = data[i][j]; + return copy; + } + + /** Transpose an array */ + public static float[][] transpose(float[][] data) { + float[][] copy = new float[data[0].length][data.length]; + for (int i = 0; i < data.length; i++) + for (int j = 0; j < data[0].length; j++) + copy[j][i] = data[i][j]; + return copy; + } + + // ------------------------------------------------------------------------------------------------ + + public static float[][] matMulPar(float[][] A, boolean transposeA, float[][] B, boolean transposeB, int numThreads) { + return toFltArray(matMulPar(toDblArray(A), transposeA, toDblArray(B), transposeB, numThreads)); + } + + public static double[][] matMulPar(double[][] A, boolean transposeA, double[][] B, boolean transposeB, int numThreads) { + final double[][] matA = transposeA ? transpose(A) : A; + + // Keep B transposed so that matrix multiplication is more able to exploit cache coherence (matrix is stored row-wise) + final double[][] matBT = transposeB ? B : transpose(B); + + final int p = matA.length, q = matA[0].length, q2 = matBT[0].length, r = matBT.length; + if (q != q2) + throw new IllegalArgumentException(""Array size mismatch""); + + final double[][] result = new double[p][r]; + + //final DecimalFormat formatPercent1dp = new DecimalFormat(""0.0%""); + + try { + for (Future res : new ParallelWorkQueue(numThreads, ParallelWorkQueue.makeIntRangeIterable(p), + new CallableFactory() { + //IntegerMutable counter = new IntegerMutable(); + + @Override + public Callable newInstance(final Integer ii) { + return new Callable() { + int i = ii.intValue(); + double[][] resultLocal = result; + int rLocal = r, qLocal = q; + double[][] matALocal = matA, matBTLocal = matBT; + + @Override + public Void call() { + /** + * + * TODO: try blocked matrix multiplication to see if it's faster + * + * for (int ib = 0; ib < p; ib += blockSize) + * for (int jb = 0; jb < q; jb += blockSize) + * for (int kb = 0; kb < r; kb += blockSize) + * for (int i = ib, iMax = Math.min(p, ib + blockSize); i < iMax; i++) + * for (int j = jb, jMax = Math.min(q, jb + blockSize); j < jMax; j++) + * for (int k = kb, kMax = Math.min(p, kb + blockSize); k < kMax; k++) + * prod[i][j] += matALocal[i][k] * matBTLocal[j][k]; + * + * N.B. the ""+="" operation above needs to use TLS accumulators + */ + for (int j = 0; j < rLocal; j++) { + float tot = 0.0f; + for (int k = 0; k < qLocal; k++) + tot += matALocal[i][k] * matBTLocal[j][k]; + resultLocal[i][j] = tot; + } + // int count = counter.increment(); + // if (count % 10 == 0) + // System.out.println(formatPercent1dp.format((count / (float) (pLocal - 1)))); + return null; + } + }; + } + })) + // Barricade + res.get(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + return result; + } + + // ------------------------------------------------------------------------------------------------ + + /** Multiply A by constant b */ + public static double[][] matMulByConst(double[][] A, double b) { + int p = A.length, q = A[0].length; + double[][] result = new double[p][q]; + for (int i = 0; i < p; i++) + for (int j = 0; j < q; j++) + result[i][j] = b * A[i][j]; + return result; + } + + /** Multiply A by constant b */ + public static float[][] matMulByConst(float[][] A, float b) { + int p = A.length, q = A[0].length; + float[][] result = new float[p][q]; + for (int i = 0; i < p; i++) + for (int j = 0; j < q; j++) + result[i][j] = b * A[i][j]; + return result; + } + + /** Multiply A by B transpose */ + public static float[][] matMulABT(float[][] A, float[][] BT) { + int p = A.length, q = A[0].length, q2 = BT[0].length, r = BT.length; + if (q != q2) + throw new IllegalArgumentException(""Array size mismatch""); + float[][] result = new float[p][r]; + for (int i = 0; i < p; i++) { + for (int j = 0; j < r; j++) { + float tot = 0.0f; + for (int k = 0; k < q; k++) + // This is the main matrix multiplication routine, because both operands here + // are in row-major order, so we get speedups of 3-8x due to cache coherence + // on large matrices. (Use the parallel version for really large matrices...) + tot += A[i][k] * BT[j][k]; + result[i][j] = tot; + } + } + return result; + } + + /** Multiply A by B transpose */ + public static double[][] matMulABT(double[][] A, double[][] BT) { + int p = A.length, q = A[0].length, q2 = BT[0].length, r = BT.length; + if (q != q2) + throw new IllegalArgumentException(""Array size mismatch""); + double[][] result = new double[p][r]; + for (int i = 0; i < p; i++) { + for (int j = 0; j < r; j++) { + float tot = 0.0f; + for (int k = 0; k < q; k++) + // This is the main matrix multiplication routine, because both operands here + // are in row-major order, so we get speedups of 3-8x due to cache coherence + // on large matrices. (Use the parallel version for really large matrices...) + tot += A[i][k] * BT[j][k]; + result[i][j] = tot; + } + } + return result; + } + + /** Multiply A by B */ + public static float[][] matMulAB(float[][] A, float[][] B) { + // Transpose B so it's row-major, and multiply by BTT==B + return matMulABT(A, transpose(B)); + } + + /** Multiply A by B */ + public static double[][] matMulAB(double[][] A, double[][] B) { + // Transpose B so it's row-major, and multiply by BTT==B + return matMulABT(A, transpose(B)); + } + + /** Multiply A transpose by B */ + public static float[][] matMulATB(float[][] A, float[][] B) { + // Transpose B so it's row-major, and multiply by BTT==B + return matMulABT(transpose(A), transpose(B)); + } + + /** Multiply A transpose by B */ + public static double[][] matMulATB(double[][] A, double[][] B) { + // Transpose B so it's row-major, and multiply by BTT==B + return matMulABT(transpose(A), transpose(B)); + } + + /** Multiply A transpose by B transpose */ + public static double[][] matMulATBT(double[][] A, double[][] B) { + return matMulABT(transpose(A), B); + } + + /** Multiply A transpose by B transpose */ + public static float[][] matMulATBT(float[][] A, float[][] B) { + return matMulABT(transpose(A), B); + } + + // ------------------------------------------------------------------------------------------------ + + /** Select a random subset of rows in a matrix */ + public static float[][] selectRandomRowSubset(int numRows, float[][] mat) { + int n = Math.min(numRows, mat.length); + float[][] rows = new float[mat.length][]; + for (int i = 0; i < mat.length; i++) + rows[i] = mat[i]; + Random rand = new Random(); + for (int i = 0; i < n; i++) { + int j = rand.nextInt(mat.length); + float[] tmp = rows[i]; + rows[i] = rows[j]; + rows[j] = tmp; + } + return Arrays.copyOf(rows, n); + } + + // ------------------------------------------------------------------------------------------------ + + /** Write a double[][] array to a file */ + public static void writeToFile(String filename, String arrayName, double[][] array) { + try { + System.out.println(""Writing to "" + filename); + PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(filename))); + + writeArray(writer, arrayName, array); + + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + } + + /** Write a double[][] array to a PrintWriter */ + public static void writeArray(PrintWriter writer, String name, double[][] arr) { + writer.println(name + ""\t"" + arr.length + ""\t"" + arr[0].length); + for (int i = 0; i < arr.length; i++) { + for (int j = 0; j < arr[0].length; j++) + writer.print((j == 0 ? """" : ""\t"") + arr[i][j]); + writer.println(); + } + } + + /** Write a double[] array to a PrintWriter */ + public static void writeArray(PrintWriter writer, String name, double[] arr) { + writer.println(name + ""\t1\t"" + arr.length); + for (int i = 0; i < arr.length; i++) + writer.print((i == 0 ? """" : ""\t"") + arr[i]); + writer.println(); + } + +} +" +A21774,"import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; + + +public class Utils { + public static ArrayList readFile(String filename){ + //replace local file with remote file from peerInfo address + ArrayList ret= new ArrayList(); + try { + FileInputStream fstream = new FileInputStream(filename); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + // Print the content on the console + ret.add(strLine); + } + //Close the input stream + in.close(); + + } + catch (Exception e) { e.printStackTrace(); } + return ret; + } + public static void writeFile(ArrayList input, String filename){ + //replace local file with remote file from peerInfo address + try{ + // Create file + FileWriter fstream = new FileWriter(filename); + BufferedWriter out = new BufferedWriter(fstream); + for (String string : input) { + out.write(string+""\n""); + } + //Close the output stream + out.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + public static void compare(String filename1, String filename2){ + //replace local file with remote file from peerInfo address + try { + FileInputStream fstream1 = new FileInputStream(filename1); + // Get the object of DataInputStream + DataInputStream in1 = new DataInputStream(fstream1); + BufferedReader br1 = new BufferedReader(new InputStreamReader(in1)); + String strLine1; + FileInputStream fstream2 = new FileInputStream(filename2); + // Get the object of DataInputStream + DataInputStream in2 = new DataInputStream(fstream2); + BufferedReader br2 = new BufferedReader(new InputStreamReader(in2)); + String strLine2; + boolean isDup=false; + //Read File Line By Line + while ((strLine1 = br1.readLine()) != null) { + strLine2 = br2.readLine(); + // Print the content on the console + if(!strLine1.equals(strLine2)){ + isDup=true; + System.out.println(""1=""+strLine1+"", 2=""+strLine2); + } + } + if(!isDup){ + System.out.println(""same""); + } + //Close the input stream + in1.close(); + in2.close(); + + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + public static void sort(String input, String output){ + //replace local file with remote file from peerInfo address + ArrayList l= readFile(input); + Collections.sort(l, new Comparator(){ + public int compare(Object arg0, Object arg1) { + String st1=(String)arg0; + String st2=(String)arg1; + int i1=Integer.parseInt(st1.substring(st1.indexOf('#')+1, st1.indexOf(':'))); + int i2=Integer.parseInt(st2.substring(st2.indexOf('#')+1, st2.indexOf(':'))); + return i1-i2; + } + + }); + writeFile(l, output); + } +} +" +A22320,"import java.util.Scanner; + + +public class dance { + public static void main(String... args){ + Scanner in = new Scanner(System.in); + + int cases = in.nextInt(); + int[] counts = new int[cases]; + for(int i = 0;i 0){ + scores[k][0] = div+ 1; + scores[k][1] = div; + scores[k][2] = div-1; + sUsed += 1; + }else if (mod == 2){ + scores[k][0] = div + 1; + scores[k][1] = div + 1; + scores[k][2] = div; + } else { + scores[k][0] = div + mod; + scores[k][1] = div; + scores[k][2] = div; + } + } + //count + int count = 0; + for(int k = 0;k= p){ + count++; + } + } + counts[i] = count; + + } + for(int i = 0;i p33) + cnt++; + else if(curr >= p34 && s > 0 && curr >= p) + { + --s; + cnt++; + } + } + System.out.println(""Case #""+ii+"": ""+cnt); + } + } +} +" +A22585,"package codejam02; +import java.io.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.StringTokenizer; +public class CodeJam02 +{ + public static void main(String[] args) + { + try + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T,N,S,p,score; + String input,output; + int maxGooglers,temp ; + T = Integer.parseInt(br.readLine()); + for (int i=0;i= p) maxGooglers++; + } + else + { + if(score==(3*p-4)||score==(3*p-3)) + { + temp++; + } + else if(score>(3*p-3)) + { + maxGooglers++; + } + } + } + if(temp b ? a - b : b - a; + d2 = a > p ? a - p : p - a; + d3 = b > p ? b - p : p - b; + if(d1 >= 3 || d2 >= 3 || d3 >= 3) + continue; + if(d1 == 2 || d2 == 2 || d3 == 2) { + if(s > 0) { + s--; + retValue++; + continue; + } else { + continue; + } + } + retValue ++; + } + return retValue; + } +} +" +A21700,"import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class B { + + static Scanner reader; + static BufferedWriter writer; + + static int countS; + static int S; + static int P; + static int N; + static int result; + + public static void verifiyTriple(int pi) { + int div = pi/3; + int mod = pi%3; + int dif = P - pi/3; + + if (div >= P) { + result++; + } else if (dif <= 2){ + if (mod == 0) { + if (countS < S && dif == 1) { + countS++; + result++; + } + } + } else { + if (dif==1) { + result++; + } else if ( mod == 2 && countS < S ) { + countS++; + result++; + } + } + } + + + public static void main(String[] args) throws IOException { + reader = new Scanner(new FileReader(""in.txt"")); + writer = new BufferedWriter(new FileWriter(""out.txt"")); + + int nt = reader.nextInt(); + for(int i = 1; i <= nt; i++) { + result = 0; + N = reader.nextInt(); + S = reader.nextInt(); + P = reader.nextInt(); + countS = 0; + for (int j = 0; j < N; j++) { + int pi = reader.nextInt(); + int div = pi/3; + int mod = pi%3; + int dif = P - div; + + if (pi < P) + continue; + + if (div >= P) { + result++; + } else if (dif <= 2){ + if (mod == 0) { + if (countS < S && dif == 1) { + countS++; + result++; + } + } else { + if (dif==1) { + result++; + } else if ( mod == 2 && countS < S ) { + countS++; + result++; + } + } + + } + } + + writer.write(""Case #"" + i + "": "" + result); + if (i < nt) + writer.newLine(); + } + writer.close(); + } + +} +" +A22832,"package mgg.main; + +import mgg.problems.ProblemB; +import mgg.utils.FileUtil; + + +public class Main { + +// public final static String inFileName = ProblemA.EXAMPLE_IN; +// public final static String outFileName = ProblemA.EXAMPLE_OUT; +// public final static String inFileName = ProblemA.A_SMALL_IN; +// public final static String outFileName = ProblemA.A_SMALL_OUT; + +// public final static String inFileName = ProblemB.EXAMPLE_IN; +// public final static String outFileName = ProblemB.EXAMPLE_OUT; +// public final static String inFileName = ProblemB.B_SMALL_IN; +// public final static String outFileName = ProblemB.B_SMALL_OUT; + public final static String inFileName = ProblemB.B_LARGE_IN; + public final static String outFileName = ProblemB.B_LARGE_OUT; + +// public final static String inFileName = ProblemC.EXAMPLE_IN; +// public final static String outFileName = ProblemC.EXAMPLE_OUT; +// public final static String inFileName = ProblemC.C_SMALL_IN; +// public final static String outFileName = ProblemC.C_SMALL_OUT; +// public final static String inFileName = ProblemC.C_LARGE_IN; +// public final static String outFileName = ProblemC.C_LARGE_OUT; + + + + public final static String delim = "" ""; + + public static void main(String[] args) { + + FileUtil util = new FileUtil(inFileName, outFileName); + + String firstLine = util.getLine(); + //System.out.println(""FIRST LINE: '"" + firstLine + ""'""); + + int numLines = Integer.parseInt(firstLine); + //System.out.println(""NUMBER OF LINES: "" + numLines); + + String result; + + for (int i = 1; i <= numLines; i++) { + + //System.out.println(""----------------------------------------------------""); + + System.out.println(""Case #"" + i); + +// result = ProblemA.solve(util); + result = ProblemB.solve(util); +// result = ProblemC.solve(util); +// result = ProblemD.solve(util); + + util.printLine(i, result); + + } + util.closeFiles(); + } + +} +" +A20785," +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.PrintStream; + +/** + * + * @author peterboyen + */ +public class DancingWithTheGooglers { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(""/Users/peterboyen/Downloads/B-large.in"")); + + String line = br.readLine(); + + int testCases = Integer.parseInt(line); + + PrintStream ps = new PrintStream(""/Users/peterboyen/Downloads/B-large.out""); + for (int i = 1; i <= testCases; i++) { + line = br.readLine(); + + ps.println(""Case #"" + i + "": "" + solve(line)); + } + + br.close(); + ps.close(); + } + + private static int solve(String line) { + String[] split = line.split("" ""); + int N = Integer.parseInt(split[0]); + int S = Integer.parseInt(split[1]); + int p = Integer.parseInt(split[2]); + + if (p == 0) { + return N; + } + + int[] scores = new int[N]; + + for (int i = 0; i < scores.length; i++) { + scores[i] = Integer.parseInt(split[i + 3]); + } + + int result = 0; + + for (int score : scores) { + if (score >= p * 3 - 2) { + result++; + } else if (score >= p && score >= p * 3 - 4 && S > 0) { + result++; + S--; + } + } + + return result; + } +} +" +A22903,"package Q2; + + +public class DancingSolver extends Solver { + + public static void main(String[] args) throws Exception{ + Main m; + m = new Main(""B-small-attempt0""); +// m = new Main(""test""); + m.run(new DancingSolver(), false); + } + + + @Override + public String solve() throws Exception { + Integer[] spl = splitLine(readLine()); + int N = spl[0]; + int surprising = spl[1]; + int maxRes = spl[2]; + Integer $ = 0; + for(int i=3;i= maxRes){ + $++; + continue; + } + if(surprising > 0 && getMaxValSurprising(score) >= maxRes){ + $++; + surprising--; + } + } + return $.toString(); + } + + private int getMaxVal(int x){ + int mod = x % 3; + int avg = x / 3; + if(mod == 0) + return avg; + else + return avg+1; + } + private int getMaxValSurprising(int x){ + if(x == 0) + return 0; + if(x == 1) + return 1; + if(x >= 26) + return 10; + int mod = x % 3; + int avg = x / 3; + if(mod <= 1) + return avg+1; + else + return avg+2; + } + + +} +" +A22598," +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Chamika + */ +public class GDance { + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int cases = s.nextInt(); + + for(int i = 0;i < cases;i++){ + int x = s.nextInt(); + int y = s.nextInt(); + int z = s.nextInt(); + int res = 0; + for(int j = 0;j < x;j++){ + int a = s.nextInt(); + int X = a/3; + int Y = a%3; + if (X >= z){ + res++; + }else if (Y >= 1 && X + 1 >= z){ + res++; + }else if( y != 0 && Y == 2 && X + Y >= z){ + y--; + res++; + }else if (y != 0 && X != 0 && Y == 0 && X + 1 >= z){ + y--; + res++; + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + res); + } + } +} +" +A20613,"package cj2012; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Scanner; +import java.util.StringTokenizer; + +public class B { + + public static void main(String[] args) throws NumberFormatException, + IOException { + BufferedReader buffer = new BufferedReader(new FileReader( + ""B-large.in"")); + int t = Integer.parseInt(buffer.readLine()); + for (int i = 0; i < t; i++) { + String kase = buffer.readLine(); + StringTokenizer tokenizer = new StringTokenizer(kase); + int n = Integer.parseInt(tokenizer.nextToken()); + int s = Integer.parseInt(tokenizer.nextToken()); + int p = Integer.parseInt(tokenizer.nextToken()); + int[] scores = new int[n]; + for (int j = 0; j < scores.length; j++) { + scores[j] = Integer.parseInt(tokenizer.nextToken()); + } + boolean done = false; + int solution = 0, sdash = 0; + int x = 0; + for (int k = 0; k < n && !done; k++) { + int make = make(scores[k], p); + if (make == 0) + x++; + else if (make == 1 && s > sdash) { + x++; + sdash++; + } + } + solution = x; + System.out.printf(""Case #%d: %d\n"", (i + 1), solution); + } + } + + private static int make(int i, int p) { + i -= p; + if (i > 2 * p) + return 0; + if (i < 0) + return -1; + if (i > 2 * p - 3 && i < 2 * p + 3) + return 0; + if (i > 2 * p - 5 && i < 2 * p + 5) + return 1; + + return -1; + } +} +" +A21887,"import java.io.File; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + + +public class CodejamB { + + public static final String TEST = ""test.in"", SMALL = ""B-small-attempt0.in"", LARGE = ""B-large.in""; + public static final String OUTPUT = ""out.txt""; + + public static Map> triplets; + + public static void main(String[] args) throws Exception + { + + solve(LARGE); + } + + public static void makeAllTriplets() + { + triplets = new HashMap>(); + for(int i =0; i <= 10; i++) + { + for(int j = 0; j <= 10; j++) + { + for(int k = 0; k <= 10; k++) + { + Triplet trip = new Triplet(i, j, k); + if(trip.legal()) + { + int sum = i + j + k; + if(!triplets.containsKey(sum)) + triplets.put(sum, new LinkedList()); + triplets.get(sum).add(trip); + } + } + } + } + } + + public static void solve(String filename) throws Exception + { + makeAllTriplets(); + + Scanner in = new Scanner(new File(filename)); + + int cases = in.nextInt(); + in.nextLine(); + + PrintWriter out = new PrintWriter(new File(OUTPUT)); + + for(int num = 1; num <= cases; num++) + { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int result = 0; + int[] googlers = new int[N]; + for(int i =0; i < N; i++) + { + boolean unsurprised = false; + boolean valid = false; + int sum = in.nextInt(); + List poss = triplets.get(sum); + for(Triplet t: poss) + { + if(t.best() >= p && !t.surprising()) + { + unsurprised = true; + valid = true; + System.out.println(""UNSURPRISING "" + Arrays.toString(t.scores) + ""= "" + sum); + } + else if(t.best() >= p) + { + valid = true; + } + + } + if(!unsurprised && S > 0 && valid) + { + S--; + result++; + } + else if(unsurprised) + { + result++; + } + } + + + in.nextLine(); + + + + out.println(""Case #""+num+"": ""+result); + System.out.println(""Case #""+num+"": ""+result); + } + + out.close(); + } + +} + +class Triplet +{ + int[] scores; + + public Triplet(int a, int b, int c) + { + scores = new int[]{a,b,c}; + Arrays.sort(scores); + } + + public int best() + { + return scores[2]; + } + + public boolean legal() + { + return Math.abs(scores[2] - scores[0]) <= 2; + } + + public boolean surprising() + { + return Math.abs(scores[2] - scores[0]) == 2; + } +} +" +A20275,"/* + * Anand Oza + * Apr 14, 2012 + */ + +import java.util.*; +import java.io.*; + +public class B_DancingWithTheGooglers { + public static void main(String[] args) throws IOException { + long startTime = System.nanoTime(); + BufferedReader reader = new BufferedReader(new FileReader(""B_DancingWithTheGooglers.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B_DancingWithTheGooglers.out""))); + StreamTokenizer in = new StreamTokenizer(reader); + + in.nextToken(); + int T = (int) in.nval; + for (int testcase = 1; testcase <= T; testcase++) { + in.nextToken(); + int N = (int) in.nval; + in.nextToken(); + int S = (int) in.nval; + in.nextToken(); + int P = (int) in.nval; + int unsurprisingThreshold = 2 * Math.max((P - 1), 0) + P; + int surprisingThreshold = 2 * Math.max((P - 2), 0) + P; + int countUnsurprising = 0; + int countSurprising = 0; + for (int i = 0; i < N; i++) { + in.nextToken(); + int t = (int) in.nval; + if (t >= unsurprisingThreshold) + countUnsurprising++; + else if (t >= surprisingThreshold) + countSurprising++; + } + + int ans = countUnsurprising + Math.min(S, countSurprising); + out.format(""Case #%d: %d%n"", testcase, ans); + } + + out.close(); + System.out.println(""Time (ms): "" + (double) (System.nanoTime() - startTime) / 1000000); + System.exit(0); + } +} +" +A22409,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package gcjqual; + +import java.io.*; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author greg + */ +public class GCJQual2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + GCJQual2 g = new GCJQual2(); + g.run(); + } + + private void run() { + BufferedReader br = null; + BufferedWriter bw = null; + String eachLine; + int count = 1; + try { + br = new BufferedReader(new FileReader(""input2.txt"")); +// bw = new BufferedWriter(new OutputStreamWriter(System.out)); + bw = new BufferedWriter(new FileWriter(""output2.txt"")); + String numTests = br.readLine(); + while ((eachLine = br.readLine()) != null) { + bw.write(""Case #"" + count + "": ""); + bw.write(solve(eachLine)); + bw.newLine(); + count++; + } + bw.close(); + } catch (IOException ex) { + Logger.getLogger(GCJQual1.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + br.close(); + } catch (IOException ex) { + Logger.getLogger(GCJQual1.class.getName()).log(Level.SEVERE, null, ex); + } + } + + } + + private String solve(String eachLine) { + String[] params = eachLine.split("" ""); + int N = Integer.valueOf(params[0]); + int S = Integer.valueOf(params[1]); + int p = Integer.valueOf(params[2]); + + int minScore = Math.max(p * 3 - 2, p); + int minSurprise = Math.max(p * 3 - 4, p); + +// ArrayList t = new ArrayList(); + int dancerPassed = 0; + int dancerSurprise = 0; + + for (int i=0; i= minScore) { + dancerPassed++; + } else if (score >= minSurprise ) { + dancerSurprise++; + } + } + + if ( dancerSurprise > S ) { + dancerSurprise = S; + } + + + return """" + (dancerPassed + dancerSurprise); + } +} +" +A20350," +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author pulasthi + */ +public class QB12 { + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(System.in); + PrintWriter out = new PrintWriter(""b.txt""); + int T = sc.nextInt(); + for (int i = 0; i < T; i++) { + int result = 0; + int N = sc.nextInt(); //no of googlers + int S = sc.nextInt(); //surprising + int p = sc.nextInt(); //max score + int noSCutoff = p * 3 - 2; + int sCutoff = p * 3 - 4; + noSCutoff = Math.max(p, noSCutoff); + sCutoff = Math.max(p, sCutoff); + for (int j = 0; j < N; j++) { + int number = sc.nextInt(); + if (number >= noSCutoff) { + result++; + } else if (S > 0 && number >= sCutoff) { + S--; + result++; + } + } + out.print(""Case #"" + (i + 1) + "": ""); + out.println(result); + } + out.flush(); + out.close(); + } +} +" +A22467,"import java.io.IOException; +import java.util.List; + +public class Dancing extends JamProblem { + + public static void main(String[] args) throws IOException { + Dancing p = new Dancing(); + p.go(); + } + + @Override + String solveCase(JamCase jamCase) { + int res = 0; + DancingCase ca = (DancingCase) jamCase; + for (int i = 0; i < ca.sums.length; i++) { + int sum = ca.sums[i]; + if (sum == 0) { + if (ca.p == 0) { + res++; + } + continue; + } + int n = sum % 3; + int one = sum / 3; + if (n == 0) { + if (one >= ca.p) { + res++; + continue; + } + if (ca.sup > 0) { + if (one + 1 >= ca.p) { + res++; + ca.sup--; + } + } + } + + if (n == 1) { + + if (one + 1 >= ca.p) { + res++; + } + } + if (n == 2) { + if (one + 1 >= ca.p) { + res++; + continue; + } + + if (ca.sup > 0) { + if (one + 2 >= ca.p) { + res++; + ca.sup--; + } + } + } + } + return """" + res; + } + + @Override + JamCase parseCase(List file, int line) { + DancingCase ca = new DancingCase(); + ca.lineCount = 1; + String s = file.get(line); + List integers = JamUtil.parseIntList(s); + int gs = integers.get(0); + ca.sup = integers.get(1); + ca.p = integers.get(2); + ca.sums = new int[gs]; + for (int i = 0; i < gs; i++) { + ca.sums[i] = integers.get(3 + i); + } + + return ca; + } +} + +class DancingCase extends JamCase { + int p; + int[] sums; + int sup; +}" +A22681,"import java.io.BufferedWriter; +import java.util.*; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.FileReader; +import java.lang.Math; +import java.util.ArrayList; +import java.util.HashMap; +import java.math.BigInteger; + + +public class Dancing +{ + public static void main(String args[]) + { + String filename = ""C://in.txt""; + int i=0,j=0; + int testcase=0 ; + String out=""""; + BufferedWriter bufferedWriter = null; + try { BufferedReader in = new BufferedReader(new FileReader(filename)); + String str; + str = in.readLine(); + testcase = Integer.parseInt(str); + + //Construct the BufferedWriter object + bufferedWriter = new BufferedWriter(new FileWriter(""oneoutput3.wpd"")); + for (i=0;i 0) + surp_reqd++; + if (P<=score[j][2]) + nowinner++; + + } + if(t[j]%3 ==1 ) + { + score[j][0]=t[j]/3; + score[j][1]=t[j]/3; + score[j][2]=(t[j]/3)+1; + + if (P<=score[j][2]) + nowinner++; + } + if(t[j]%3 ==2 ) + { + score[j][0]=t[j]/3; + score[j][1]=(t[j]/3)+1; + score[j][2]=(t[j]/3)+1; + + if (P==score[j][2]+1) + surp_reqd++; + if (P<=score[j][2]) + nowinner++; + } + System.out.println (""score[""+j+""]=""+score[j][0]+"",""+score[j][1]+"",""+score[j][2]); + + } + + System.out.println (""surp_reqd=""+surp_reqd); + System.out.println (""nowinner=""+nowinner); + if (S>=surp_reqd) + maxwinner=nowinner+surp_reqd; + else + maxwinner=nowinner+S; + + + + out=""Case #""+(i+1)+"": ""; + + out += maxwinner+""\n""; + + System.out.println (""out =""+out); + + bufferedWriter.write(out); + + } + in.close(); } + catch (IOException ex) { ex.printStackTrace();} + finally { + //Close the BufferedWriter + try { + if (bufferedWriter != null) { + bufferedWriter.flush(); + bufferedWriter.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + } + +} +" +A20108,"package org.alaoui.googledance; + +public class Dancer { + + private int totalScore; + + private Integer maxOrdinaryScore; + + private Integer maxSurprisingScore; + + public Dancer(int totalScore) { + this.totalScore = totalScore; + computeMaxScores(); + } + + private void computeMaxScores() { + int mod = totalScore % 3; + int floor = (int) Math.floor(totalScore / 3); + + maxOrdinaryScore = floor; + if (mod >= 1) { + maxOrdinaryScore++; + } + + if (mod != 1 && maxOrdinaryScore != 10 && maxOrdinaryScore != 0) { + maxSurprisingScore = maxOrdinaryScore + 1; + } + + } + + /** + * @return the maxOrdinaryScore + */ + public Integer getMaxOrdinaryScore() { + return maxOrdinaryScore; + } + + /** + * @param maxOrdinaryScore + * the maxOrdinaryScore to set + */ + public void setMaxOrdinaryScore(Integer maxOrdinaryScore) { + this.maxOrdinaryScore = maxOrdinaryScore; + } + + /** + * @return the maxSurprisingScore + */ + public Integer getMaxSurprisingScore() { + return maxSurprisingScore; + } + + /** + * @param maxSurprisingScore + * the maxSurprisingScore to set + */ + public void setMaxSurprisingScore(Integer maxSurprisingScore) { + this.maxSurprisingScore = maxSurprisingScore; + } +} +" +A20811,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class Dancing { + + public static void main(String[] args) { + int numTestCases; + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + try { + numTestCases = Integer.parseInt(in.readLine()); + for (int i = 0; i < numTestCases; i++) { + String line = in.readLine(); + String[] ints = line.split("" ""); + int numGooglers = Integer.parseInt(ints[0]); + int numSurprising = Integer.parseInt(ints[1]); + int p = Integer.parseInt(ints[2]); + int numSuccess = 0; + + for (int j = 3; j < ints.length; j++) { + int score = Integer.parseInt(ints[j]); + // special case + if (score == 0 && p > 0) { + continue; + } + + // trivial case + if (score/3 >= p) { + numSuccess++; + continue; + } + + int remainingTwoScoresSum = score - p; + if (remainingTwoScoresSum >= (p-1)*2) { + numSuccess++; + continue; + } + + if (remainingTwoScoresSum >= (p-2)*2 && numSurprising > 0) { + numSuccess++; + numSurprising--; + continue; + } + } + + System.out.println(""Case #""+(i+1)+"": ""+numSuccess); + } + } catch (IOException e) { +// System.out.println(""oh noes""); + } + } + +} +" +A21340,"import java.util.*; + +public class DancingWithTheGooglers { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int numCases, currentCase, numGooglers, surprisingScores, searchFor, answer, currentScore; + ArrayList scores; + + numCases = scan.nextInt(); + currentCase = 0; + while (currentCase < numCases) { + currentCase++; + numGooglers = scan.nextInt(); + surprisingScores = scan.nextInt(); + searchFor = scan.nextInt(); + scores = new ArrayList(); + for (int i = 0; i < numGooglers; i++) + scores.add(scan.nextInt()); + answer = 0; + for (int i = 0; i < scores.size(); i++) { + currentScore = scores.get(i); + currentScore = currentScore / 3; + if (scores.get(i) == 0 && searchFor != 0) { + } else if (currentScore > searchFor) { + answer++; + } else if (currentScore * 3 == scores.get(i)) { + if (currentScore == searchFor) { + answer++; + } else if (surprisingScores > 0 && (currentScore + 1 == searchFor || currentScore - 1 == searchFor)) { + answer++; + surprisingScores--; + } + } else if ((currentScore * 3) + 1 == scores.get(i)) { + if (currentScore == searchFor || currentScore + 1 == searchFor) { + answer++; + } else if (surprisingScores > 0 && (currentScore - 1 == searchFor)) { + answer++; + surprisingScores--; + } + } else if ((currentScore * 3) + 2 == scores.get(i)) { + if (currentScore == searchFor || currentScore + 1 == searchFor) { + answer++; + } else if (surprisingScores > 0 && (currentScore + 2 == searchFor)) { + answer++; + surprisingScores--; + } + } + } + System.out.printf(""Case #%d: %d\n"", currentCase, answer); + } + } +} +" +A20442,"import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Formatter; +import java.util.Scanner; + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + Path path = Paths.get(args[0]); + Path file = Paths.get(""dancers.txt""); + int numberOfCases; + try (Scanner scanner = new Scanner(Files.newInputStream(path), ""UTF-8""); + OutputStreamWriter output = new OutputStreamWriter(Files.newOutputStream(file), ""UTF-8"")) { + Formatter f = new Formatter(output); + numberOfCases = scanner.nextInt(); + for (int i = 1; i <= numberOfCases; i++) { + int[] googlersScores = new int[scanner.nextInt()]; + int specialScores = scanner.nextInt(); + int scoreAtLeast = scanner.nextInt(); + for (int j = 0; j < googlersScores.length; j++) { + googlersScores[j] = scanner.nextInt(); + } + int result = solve(googlersScores, specialScores, scoreAtLeast); + f.format(""Case #%d: %d\n"", i, result); + } + f.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private static int solve(int[] googlersScores, int specialCases, int scoreAtLeast) { + int numberOfGooglers = 0; + for (int googleScore : googlersScores) { + int firstScore = (int) Math.floor(googleScore / 3.); + int secondScore = (int) Math.floor((googleScore - firstScore) / 2.); + int thirdScore = googleScore - firstScore - secondScore; + if (thirdScore >= scoreAtLeast) { + numberOfGooglers++; + } else if (thirdScore > 0 && thirdScore == scoreAtLeast - 1 && secondScore == thirdScore && specialCases > 0) { + numberOfGooglers++; + specialCases--; + } + } + return numberOfGooglers; + } +} +" +A22658,"package qualification_round; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +public class danceGooglers { + + private static void readFile () { + + String str, temp[]; + int T, n, i, s, p, totals[]; + + try { + FileInputStream fistream = new FileInputStream(""src/qualification_round/B-large.in""); + DataInputStream dis = new DataInputStream(fistream); + BufferedReader br = new BufferedReader(new InputStreamReader(dis)); + + // Read the number of test cases + str = br.readLine(); + T = Integer.parseInt(str); + System.out.println (""Number of test cases:"" + T); + + // Read the test cases + for (int tCtr = 0; tCtr < T; tCtr++) { + + System.out.print(""Case #"" + (tCtr+1) + "": ""); + + // Read each line of input file + str = br.readLine(); + + // processInput(str); + writeFile((tCtr+1), processInput(str)); + + } + dis.close(); + } catch (FileNotFoundException fnfe) { + System.out.println (""File is not found""); + } catch (IOException ioe) { + System.out.println (""IO Error""); + } + + } + + private static int processInput (String str) { + + int n, s, p, total, quo, rem; + int res = 0, sur = 0; + + String temp[] = str.split("" ""); + n = Integer.parseInt(temp[0]); + s = Integer.parseInt(temp[1]); + p = Integer.parseInt(temp[2]); + + for (int i = 0; i < n; i++) { + total = Integer.parseInt(temp[i+3]); + + if (total >= p) { + quo = total / 3; + rem = total % 3; + + if (quo >= p) { + res++; + } else if (rem == 2) { + if ((quo + 1) >= p) { + res++; + } else if ((quo + 2) >= p && sur < s) { + sur++; res++; + } + } else if (rem == 1) { + if ((quo + 1) >= p) { + res++; + } + } else if (rem == 0) { + if ((quo + 1) >= p && sur < s) { + sur++; res++; + } + } + } + } + + System.out.println(res); + return res; + } + + private static void writeFile (int n, int Res) { + try { + FileOutputStream fostream = new FileOutputStream(""src/qualification_round/B-large.out"", true); + DataOutputStream dos = new DataOutputStream(fostream); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(dos)); + + bw.write(""Case #"" + n + "": "" + Res); + bw.newLine(); + + bw.close(); + } catch (FileNotFoundException fnfe) { + System.out.println (""File is not found""); + } catch (IOException ioe) { + System.out.println (""IO Error""); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + readFile(); + } + +} +" +A21663,"package qual; + +import java.util.Scanner; + +public class GoogleDancing { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); + + in.nextLine(); + + for(int t=0;t=1) + count++; + } + else + if(rem>= (2*p - 2)) + count++; + else if(rem>= (2*p - 4) && surprising>0) + { + count++; + surprising--; + } + } + System.out.println(""Case #"" + (t+1) + "":"" + "" "" + count); + } + + } + +} +" +A20153,"import java.util.*; +public class B { + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int T = s.nextInt(); + for (int ca = 1; ca <= T; ca++) { + int N = s.nextInt(), S = s.nextInt(), p = s.nextInt(); + int good = 0, used =0; + for (int j = 0; j < N; j++) { + int t = s.nextInt(); + int x = t/3; + if (t%3==0) { + if (p==x+1 && x>0 && x<10 && used scores; + + public DanceScoreCase(String scoreLine) { + + String[] integers = scoreLine.split("" ""); + if(integers.length < 4) { + throw new IllegalArgumentException(""Not enough strings""); + } + + dancers = new Integer(integers[0]); + surpriseScores = new Integer(integers[1]); + scoreThreshold = new Integer(integers[2]); + scores = new ArrayList(); + for(int i = 3; i < integers.length; i++) { + scores.add(Integer.valueOf(integers[i])); + } + + } + + public Integer maxDancersThatCouldPass() { + int passesUnsurprising = 0; + int passesSurprising = 0; + ArrayList couldNotPassUnsuprising = new ArrayList(); + + for(Integer score : scores) { + if(canPassThresholdUnsurprising(score, scoreThreshold)) { + passesUnsurprising++; + } else if(canPassThresholdSurprising(score, scoreThreshold)) { + passesSurprising++; + } + } + + return passesUnsurprising + Math.min(passesSurprising, surpriseScores); + } + + + public static boolean canPassThresholdUnsurprising(int score, int threshold) { + int minScore = Math.max(0, threshold-1); + return (score >= threshold + 2*minScore); + } + + public static boolean canPassThresholdSurprising(int score, int threshold) { + int minScore = Math.max(0, threshold-2); + return (score >= threshold + 2*minScore); + } + + public int getDancers() { + return dancers; + } + + public int getSurpriseScores() { + return surpriseScores; + } + + public int getScoreThreshold() { + return scoreThreshold; + } + + public ArrayList getScores() { + return scores; + } +} +" +A22984,"import java.util.*; + +public class B { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); + int N, S, p; + + for (int x = 1; x <= T; x++) { + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + + int[] t = new int[N]; + int y = 0; + + for (int i = 0; i < N; i++) { + t[i] = in.nextInt(); + + int k = t[i] / 3; + int j1 = -1, j2 = -1, j3 = -1; + + // not surprising triplets + if ((k + 1) + (k + 1) + k == t[i]) { + j1 = k + 1; + j2 = k + 1; + j3 = k; + } + + else if ((k + 1) + k + k == t[i]) { + j1 = k + 1; + j2 = k; + j3 = k; + } + + else if (3 * k == t[i]) { + j1 = k; + j2 = k; + j3 = k; + } + + if (j1 >= p || j2 >= p || j3 >= p) { + y++; + continue; + } + + if(S==0) continue; + + // surprising triplets + if (k != 9 && (k + 2) + k + k == t[i]) { + j1 = k + 2; + j2 = k; + j3 = k; + } else if (k != 0 && ((k + 1) + (k + 1) + (k - 1) == t[i])) { + j1 = k + 1; + j2 = k + 1; + j3 = k - 1; + } else if (k != 0 && ((k + 1) + k + (k - 1) == t[i])) { + j1 = k + 1; + j2 = k; + j3 = k - 1; + } + + if (j1 >= p || j2 >= p || j3 >= p) { + y++; + S--; + continue; + } + + } + + System.out.println(""Case #"" + x + "": "" + y); + } + } +} +" +A21414,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; + +//DancingGooglers.java +//Completes the Dancing with Googlers problem for Google Code Jam 2012 +//By Jack Thakar +//Coded in Java using Eclipse 3.7 +public class DancingGooglers { + public static void main(String[] args){ + String input = readFile(""B-large.in""); + String[] lines = input.split(System.lineSeparator()); + String output = """"; + for(int i=1;i0){ + possible++; + surprised--; + } + } + return possible; + } + //0 - Not possible, 1 - Suprising, 2 - Not suprising + public int getBestResult(int score){ + int dividend = score/3; + int remainder = score%3; + if(dividend>=required) return 2; + if(dividend+1>=required&&(remainder>=1)) return 2; + if(dividend+2>=required&&(remainder>=2)) return 1; + if(dividend+1>=required&÷nd>0) return 1; + return 0; + } + + } + + private static String readFile(String name){ + File file = new File(""input""+File.separator+name); + Charset charset = Charset.forName(""ASCII""); + String text = """"; + try (BufferedReader reader = Files.newBufferedReader(file.toPath(), charset)) { + String line = null; + while ((line = reader.readLine()) != null) { + text+=line+System.lineSeparator(); + } + } catch (IOException e) { + } + return text; + } + private static void writeFile(String name, String data){ + File file = new File(""output""+File.separator+name); + Charset charset = Charset.forName(""ASCII""); + try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), charset)) { + writer.write(data, 0, data.length()); + } catch (IOException e) { + } + } +} +" +A21504,"import java.io.*; +import java.lang.*; +import java.util.*; + +public class B { + public static void main(String[] args) { + B prob = new B(); + prob.run(args[0]); + } + + public void run(String fileName) { + try { + Scanner fin = new Scanner(new File(fileName)); + PrintWriter fout = new PrintWriter(new File(fileName + "".out"")); + + int T = fin.nextInt(); + for (int t = 1; t <= T; ++t) { + fout.format(""Case #%d: "", t); + + int N = fin.nextInt(); + int S = fin.nextInt(); + int p = fin.nextInt(); + + int result = 0; + for (int i = 0; i < N; ++i) { + int ti = fin.nextInt(); + if (p == 0) { + ++result; + continue; + } + if (ti >= (3 * p - 2)) { + ++result; + continue; + } + if (p == 1) continue; + if (ti >= (3 * p - 4)) { + if (S == 0) continue; + ++result; + --S; + } + } + + fout.format(""%d\n"", result); + } + + fin.close(); + fout.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A21261," +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) { + InputStream in = System.in; + PrintStream out = System.out; + if (args.length > 0) { + try { + in = new FileInputStream(args[0]); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + Scanner scanner = new Scanner(in); + int cases = scanner.nextInt(); + for (int i = 1; i <= cases; ++i) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int good = 0; + int surprising = 0; + for (int j = 0; j < n; ++j) { + int t,q,r; + t = scanner.nextInt(); + if (t > 0) { + --t; + r = t % 3; + q = t / 3; + if (q + 1 >= p) { + ++good; + } else if (r > 0 && q + 2 >= p) { + ++surprising; + } + } else if (p == 0) { + ++good; + } + } + + + out.format(""Case #%d: "",i); + out.print(good + Math.min(s, surprising)); + out.println(); + } + } +}" +A20097,"import java.io.FileInputStream; +import java.util.Scanner; + +public class Q_B { + + public static void main(String[] args) throws Exception { + + Scanner sc = new Scanner(new FileInputStream(""C:\\B-large.in"")); + int tests = sc.nextInt(); + + for (int i = 0; i < tests; i++) { + + int num = sc.nextInt(); + int surprise = sc.nextInt(); + int baseMark = sc.nextInt(); + int count = 0; + + for (int j = 0; j < num; j++) { + + int totalMark = sc.nextInt(); + Double tmp = Math.ceil( (float) totalMark / 3 ); + int maxMark = tmp.intValue(); + + // baseMark shouldn't be more than total + if (baseMark > totalMark) continue; + + if (maxMark >= baseMark) { + count++; + } else { + int a = totalMark - baseMark; + int b = a / 2; + if ((baseMark - b <= 2) && surprise > 0) { + surprise--; + count++; + } + } + } + + System.out.println(""Case #"" + (i+1) + "": "" + count); + count = 0; + + } + +// Double tmp = Math.ceil( (float) 0 / 3 ); +// System.out.println(tmp.intValue()); + + } + +}" +A20980,"package fixjava; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.Map.Entry; + +public class HashMapDualKey extends HashMap> { + private static final long serialVersionUID = 1L; + + /** Returns whether the dual map contains the given key in the K1 space */ + @Override + public boolean containsKey(Object key) { + return this.containsKey(key); + } + + public boolean containsKey(K1 key1, K2 key2) { + HashMap map2 = this.get(key1); + if (map2 == null) + return false; + else + return map2.containsKey(key2); + } + + /** Searches all (K1, K2) pairs to see if any of them map to the value. Runs in O(K1) time. */ + public boolean containsValueAll(Object value) { + for (HashMap map2 : this.values()) + if (map2 != null && map2.containsValue(value)) + return true; + return false; + } + + public V get(K1 key1, K2 key2) { + HashMap map2 = this.get(key1); + if (map2 == null) + return null; + else + return map2.get(key2); + } + + public Set keySet(K1 key1) { + HashMap map2 = this.get(key1); + if (map2 == null) + return null; + else + return map2.keySet(); + } + + public V put(K1 key1, K2 key2, V value) { + HashMap map2 = this.get(key1); + if (map2 == null) + this.put(key1, map2 = new HashMap()); + return map2.put(key2, value); + } + + public void putAll(ArrayList> items) { + for (Tuple3 item : items) + put(item.getField0(), item.getField1(), item.getField2()); + } + + public void putAllListOfLists(ArrayList>>> listOfLists) { + for (Pair>> pair1 : listOfLists) { + K1 k1 = pair1.getLeft(); + for (Pair pair2 : pair1.getRight()) + put(k1, pair2.getLeft(), pair2.getRight()); + } + } + + @Override + public HashMap remove(Object key1) { + return this.remove(key1); + } + + public V remove(K1 key1, K2 key2) { + HashMap map2 = this.get(key1); + if (map2 == null) + return null; + V ret = map2.remove(key2); + if (map2.isEmpty()) + this.remove(key1); + return ret; + } + + /** Returns size across all (K1, K2) pairs. Runs in O(K1) time. */ + public int sizeAll() { + int size = 0; + for (HashMap map2 : this.values()) + if (map2 != null) + size += map2.size(); + return size; + } + + /** Returns union of values across all (K1, K2) pairs. Runs in O(N) time. */ + public HashSet valuesAll() { + HashSet values = new HashSet(); + for (HashMap map2 : this.values()) + if (map2 != null) + values.addAll(map2.values()); + return values; + } + + /** Returns the map as a list of Tuple3. Runs in O(N) time. */ + public ArrayList> getAsList() { + ArrayList> result = new ArrayList>(); + for (Entry> ent1 : this.entrySet()) { + K1 k1 = ent1.getKey(); + HashMap map2 = ent1.getValue(); + if (map2 != null) { + for (Entry ent2 : map2.entrySet()) { + K2 k2 = ent2.getKey(); + V v = ent2.getValue(); + result.add(Tuple3.make(k1, k2, v)); + } + } + } + return result; + } + + /** Returns the map as a list of Pair>>. Runs in O(N) time. */ + public ArrayList>>> getAsListOfLists() { + ArrayList>>> result = new ArrayList>>>(this.size()); + for (Entry> ent1 : this.entrySet()) { + K1 k1 = ent1.getKey(); + HashMap map2 = ent1.getValue(); + if (map2 != null) { + ArrayList> listOfK2VPairs = new ArrayList>(map2.size()); + for (Entry ent2 : map2.entrySet()) { + K2 k2 = ent2.getKey(); + V v = ent2.getValue(); + listOfK2VPairs.add(Pair.make(k2, v)); + } + result.add(Pair.make(k1, listOfK2VPairs)); + } + } + return result; + } +} +" +A21088,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +import java.io.FileWriter; + +public class DancingWithTheGooglers { + public static void main(String... args) { + + try { + File f = new File(""B-large.in""); + File outFile = new File(""output.txt""); + FileWriter w = new FileWriter(outFile); + Scanner s = new Scanner(f); + int T = s.nextInt(); + s.nextLine(); + for(int i = 1; i<= T; i++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] t = new int[N]; + for(int j = 0; j < N; j++) { + t[j] = s.nextInt(); + } + int max = findMax(N,S,p,t); + String line = ""Case #"" + i +"": "" + max + '\n'; + System.out.print(line); + w.write(line); + if(s.hasNextLine()) s.nextLine(); + } + w.close(); + } + catch(Exception e) { } + } + private static int findMax(int N, int S, int p, int[] t) { + int possible = 0; + int surprising = 0; + for(int i = 0; i < t.length; i++) { + if(p == 1) { + if(t[i] >= 1) { + possible++; + } + } + else if(t[i] >= (3*p - 2)){ + possible++; + } + else if(t[i] >= (3*p - 4)) { + surprising++; + } + } + return possible + Math.min(surprising, S); + } +}" +A20878,"import java.io.*; +import java.util.*; +public class Main +{ + public static void main(String[] args)throws IOException + { + new Main().start(); + } + public void start()throws IOException + { + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int test=Integer.parseInt(br.readLine()); + int ind=1; + + while(test-->0) + { + st=new StringTokenizer(br.readLine()); + int ans=0; + int N=Integer.parseInt(st.nextToken()); + int S=Integer.parseInt(st.nextToken()); + int p=Integer.parseInt(st.nextToken()); + int totalScore[]=new int[N]; + for(int i=0;i0;i++) + { + if(totalScore[i]>=max) + { + ans++; + cons[i]=true; + S--; + } + } + max=3*p-2; + for(int i=0;i=max && !cons[i]) + ans++; + } + System.out.println(""Case #""+ind+"": ""+ans); + ind++; + } + } +}" +A22953,"import java.io.*; +import java.util.*; +public class Qual22B +{ + public static void main(String[] args) throws IOException + { + BufferedReader ips=new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter ops=new PrintWriter(new FileWriter(""dwgop.in"")); + int T=Integer.parseInt(ips.readLine()); + for(int i=0; i=0; k--) + { + mod=ts[k]%3; + for(int l=0; l<3; l++) + marks[k][l]=ts[k]/3; + if(mod==2) + { + if(sc=p) + { + count++; + break; + } + } + //System.out.println(""""); + } + ops.println(""Case #""+(i+1)+"": ""+count); + } + ips.close(); + ops.close(); + } +}" +A22146,"import java.io.BufferedWriter; +import java.util.ArrayList; + +public class Helper { + + public Helper() { + super(); + } + + public String operate(String op) { + System.out.println(op); + String result =""""; + int total = 0; + String[] split = op.split("" ""); + int inter = Integer.valueOf(split[1]); + int goal = Integer.valueOf(split[2]); + System.out.println(""Interesting:"" + inter + "" Goal:"" + goal); + goal = goal -1; + for (int i = 3; i < split.length; i++){ + int score = Integer.valueOf(split[i]); + int base = score / 3; + int next = (score - base) / 2; + int third = score - base - next; + System.out.println(base + "" "" + next + "" "" + third); + if (third - base < 2 && third > goal) { + total += 1; + //Interesting + } else if (third - base == 2) { + if (inter > 0 && third > goal) { + inter -= 1; + total += 1; + } + } else { + if (third + 1 > goal && next > 0 && inter > 0) { + if (third - base == 1 && next == base){ + ; + } else { + inter -= 1; + total += 1; + } + } + } + } + System.out.println(""Result: "" + result + total); + return result + total; + } + + public void inputStrings(ArrayList anInput) { + + } + + public void printResult(BufferedWriter out, String input, int n) { + String result = ""Case #""+ n +"": "" + operate(input) + ""\n""; + //System.out.print(result); + try { + out.write(result); + }catch (Exception e){//Catch exception if any + System.err.println(""here Error: "" + e.getMessage()); + } + } +} +" +A20678,"import java.util.*; + +public class probB +{ + public static void main (String[] args) + { + Scanner scan = new Scanner (System.in) ; + + int T = scan.nextInt(); + int A[], S,p; + + for (int t=0 ; t=p || (n%3!=0 && n/3+1>=p)) + result++; + + else if (s= limit + int res=0; //mult result + int rem=0; //remainder + int N=0; //# tuples + int S=0; //# surprising tuples (t%r==2) + int s=0; //current count of surprising tuples + int l=0; //the limit + int minT=0,maxT=10; //minmum & maximum T values; + ArrayList al=new ArrayList(); //list of tuples + int C=0; //# cases + + C = f.nextInt(); //get # of test cases + for (int c=1;c<=C;c++){ //for each test case + N=f.nextInt();S=f.nextInt();l=f.nextInt();//get params + count=0; //reset # good tuples count + s=0; //reset surprising tuple count + al.clear(); //reset t list + for(int i=1;i<=N;i++)al.add(f.nextInt());//build t list + Collections.sort(al); //sort lowest to highest + Collections.reverse(al);//sort highest to lowest + /*for (Integer x: al)System.out.print(x + "" "");*/ + for (Integer t:al) { + res=t/3; rem=t%3; + if (res >= l) + count++; + else if (res == l-1) + if (rem != 0) + count++; + else {// rem==0 + if (sminT) { + count++; + s++; + } + } + else if (res == l-2) + if (rem == 2) { + if (s < S) { + count++; + s++; + } + } + } + + System.out.println(""Case #""+c+"": ""+count);//display result + } + } +}" +A20661,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class ProblemB { + public static void main(String[] args) throws FileNotFoundException { + PrintStream out = new PrintStream(new FileOutputStream(new File( + ""b-large.out""))); + Scanner in = new Scanner(new File(""B-large.in"")); + + int T = in.nextInt(); + + for (int i = 1; i <= T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int defCount = 0; + int surpCount = 0; + for (int j = 0; j < N; j++) { + int t = in.nextInt(); + + if (t % 3 == 0) { // (1,1,1) <-> (0,1,2) + if (t / 3 >= p) + defCount++; + else if (t / 3 >= p - 1 && t / 3 >= 1) // (0,0,0) cannot change + surpCount++; + } + if(t % 3 == 1){ // (0,0,1) -> no way to increase max score + if(t / 3 >= p - 1) // int div + defCount++; + } + if(t % 3 == 2){ // (0,1,1) <-> (0,0,2) + if(t / 3 >= p - 1) // int div + defCount++; + else if(t / 3 >= p - 2) + surpCount++; + } + + //System.out.printf(""total: %d, avg: %d, dC: %d, sC: %d\n"", t, t/3, defCount, surpCount); + } + + out.printf(""Case #%d: %d\n"", i, defCount + Math.min(surpCount, S)); + + //System.out.printf(""\n\n""); + } + + in.close(); + out.close(); + } +} +" +A22306,"package gcj; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + private String solve(Scanner in) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int p3 = 3*p; + + if (p >10) return """" + 0; + + int result = 0; + int strange = 0; + + for (int i=0; i= 0) + result++; + } + else if (diff <= 4) { + if (p - 2 >= 0) { + strange++; + if (strange <= S) result++; + } + } + } + + } + + return """" + result; + } + + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(""C:\\Users\\User\\Desktop\\dane\\data.in"")); + PrintWriter out = new PrintWriter(""C:\\Users\\User\\Desktop\\dane\\output""); + + int T = in.nextInt(); + in.nextLine(); + + for (int i = 0; i < T; i++) { + String s = ""Case #"" + (i + 1) + "": "" + new DancingWithTheGooglers().solve(in); + out.println(s); + System.out.println(s); + } + out.close(); + + } + +} +" +A20818,"package CodeJam2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Q2 { + + public static void main(String[] args) throws IOException { + FileReader buf = new FileReader(""Input.in""); + BufferedReader br = new BufferedReader(buf); + int cases = Integer.parseInt(br.readLine()); + String[] outputs = new String[cases]; + for (int i = 1; i <= cases; i++) { + String input = br.readLine(); + String[] splits = input.split("" ""); + int N = Integer.parseInt(splits[0]); + int S = Integer.parseInt(splits[1]); + int p = Integer.parseInt(splits[2]); + int thresh = 0; + int special = S; + int[] points = new int[splits.length - 3]; + for (int k = 0; k < points.length; k++) { + points[k] = Integer.parseInt(splits[k + 3]); + } + for (int j = 0; j < points.length; j++) { + int v = (int) (points[j] / 3); + int rem = points[j] % 3; + switch (rem) { + case 2: + if (v + 1 >= p || v >= p) { + thresh++; + } else if (special > 0 && v + 2 >= p) { + thresh++; + special--; + } + break; + case 1: + if (v >= p || v + 1 >= p) { + thresh++; + } else if (special > 0 && v + 1 >= p) { + thresh++; + special--; + } + break; + case 0: + if (v >= p) { + thresh++; + } else if (special > 0 && v > 0 && v + 1 >= p) { + thresh++; + special--; + } + break; + } + + } + if (i != cases) + outputs[i - 1] = ""Case #"" + i + "": "" + thresh + ""\n""; + else + outputs[i - 1] = ""Case #"" + i + "": "" + thresh; + } + br.close(); + buf.close(); + FileWriter buf1 = new FileWriter(new File(""OutputDance.txt""), true); + BufferedWriter bw1 = new BufferedWriter(buf1); + for (int i = 0; i < cases; i++) { + bw1.write(outputs[i]); + } + bw1.close(); + buf1.close(); + + } + +} +" +A22746,"package lk.iit.wall.framework.network; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Scanner; + +/** + * Created with IntelliJ IDEA. + * User: Amila + * Date: 4/13/12 + * Time: 10:48 PM + * To change this template use File | Settings | File Templates. + */ +public class CodeJamOne { + + public static void main(String[] args) { + File file = new File(""D:\\small.txt""); + try { + // + // Create a new Scanner object which will read the data + // from the file passed in. To check if there are more + // line to read from it we check by calling the + // scanner.hasNextLine() method. We then read line one + // by one till all line is read. + // + Scanner scanner = new Scanner(file); + int cases = scanner.nextInt(); + for (int i = 0; i < cases; i++) { + int googlers = scanner.nextInt(); + int supprise = scanner.nextInt(); + int max = scanner.nextInt(); + int numGoog = 0; + int[] nums = new int[googlers]; + for (int j = 0; j < googlers; j++) { + int score = scanner.nextInt(); + nums[j] = score; + } + Arrays.sort(nums); + for (int j = googlers - 1; j >= 0; j--) { + int score = nums[j]; + double d = score / 3f; + int div = (int) Math.ceil(d); + int mod = score % 3; + if (div >= max) { + numGoog++; + continue; + } + /*if (mod == 2) { + if (div + 2 >= max && supprise != 0 && score > 1 && score < 29) { + numGoog++; + supprise--; + continue; + } + } else */if(mod==0 || mod == 2){ + if (div + 1 >= max && supprise != 0 && score > 1 && score < 29) { + numGoog++; + supprise--; + continue; + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + numGoog); + + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } +} +" +A22966,"/* +PROG: ProbB +2012 Google CodeJam Qualification Round +Problem B +*/ + +import java.io.*; +import java.util.*; + +public class Prob1B{ + + public static void main(String [] args) throws IOException { + //long start = System.currentTimeMillis(); + BufferedReader f = new BufferedReader(new FileReader(""Prob1B.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""Prob1B.txt""))); + int[] normal = {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; + int[] suprising = {0,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,10,10}; + int N = Integer.parseInt(f.readLine()); + for(int i = 0; i < N; i++){ + int countn = 0; + int counts = 0; + String[] input = (f.readLine()).split("" ""); + int M = Integer.parseInt(input[0]); + int S = Integer.parseInt(input[1]); + int P = Integer.parseInt(input[2]); + for(int j = 0; j < M; j++){ + int x = Integer.parseInt(input[3+j]); + //System.out.println(x + "" "" + normal[x] + "" "" + suprising[x]); + if(normal[x] >= P) + countn++; + else if(suprising[x] >= P) + counts++; + } + int ans = countn + Math.min(counts, S); + out.println(""Case #"" + (i+1) + "": "" + ans); + } + //long end = System.currentTimeMillis(); + //System.out.println(end - start); + out.close(); + } + + +} +" +A20608,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.IOException; + + +public class Test{ + public static void main(String[] args) + throws IOException { + + BufferedReader inputStream = null; + PrintWriter outputStream = null; + + + try { + inputStream = + new BufferedReader(new FileReader(""test.in"")); + outputStream = + new PrintWriter(new FileWriter(""test.out"")); + + String l; + l = inputStream.readLine(); + int t = Integer.parseInt(l); + int i = 1; + while ((l = inputStream.readLine()) != null) { + String result = ""Case #""+(i++)+"": ""+getNum(l); + outputStream.println(result); + //System.out.println(result); + } + } finally { + if (inputStream != null) { + inputStream.close(); + } + if (outputStream != null) { + outputStream.close(); + } + } + } + + + public static int getNum(String l){ + int number; + int surpriseNumber; + int maxScore; + int[]totalPoints = new int[100]; + + String[] strArray = l.split("" ""); + + number = Integer.parseInt(strArray[0]); + surpriseNumber = Integer.parseInt(strArray[1]); + maxScore = Integer.parseInt(strArray[2]); + + + for(int i=0;i=minTotalPoint){ + returnValue++; + } + else if(totalPoints[i]>=minTotalPointWithSurprise){ + if(surpriseNumber>0){ + returnValue++; + surpriseNumber--; + } + } + } + + + return returnValue; + } + + +}" +A21708,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; +import java.util.Vector; + +class dancing { + public static void main(String[] args) throws IOException { + BufferedReader f = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter( + ""output.txt""))); + StringTokenizer st = new StringTokenizer(f.readLine()); + int cases = Integer.parseInt(st.nextToken()); + for (int k = 1; k < cases; k++) { + st = new StringTokenizer(f.readLine()); + int memSum = Integer.parseInt(st.nextToken()); + int surprising = Integer.parseInt(st.nextToken()); + int level = Integer.parseInt(st.nextToken()); + int[] scores = new int[memSum]; + for (int i = 0; i < memSum; i++) { + scores[i] = Integer.parseInt(st.nextToken()); + } + int max = getMax(memSum, surprising, level, scores); + out.println(""Case #"" + k + "": "" + max); // output result + } + + st = new StringTokenizer(f.readLine()); + int memSum = Integer.parseInt(st.nextToken()); + int surprising = Integer.parseInt(st.nextToken()); + int level = Integer.parseInt(st.nextToken()); + int[] scores = new int[memSum]; + for (int i = 0; i < memSum; i++) { + scores[i] = Integer.parseInt(st.nextToken()); + } + int max = getMax(memSum, surprising, level, scores); + out.print(""Case #"" + cases + "": "" + max); // output result + out.close(); // close the output file + System.exit(0); // don't omit this! + } + + public static int getMax(int _memSum, int _surprising, int _level, + int[] _scores) { + int[] scores = _scores; + int memSum = _memSum; + int surprising = _surprising; + int level = _level; + int max = 0; + int certainStart = level * 3 - 2; + int certainEnd = 30; + int maybeStart = level * 3 - 4; + int maybeEnd = level * 3 + 4; + + if(certainStart < 0) + { + certainStart = level; + } + + if(maybeStart < 0) + { + maybeStart = level; + } + + for (int i = 0; i < scores.length; i++) { + if (scores[i] <= certainEnd && scores[i] >= certainStart) { + max++; + } else { + if (surprising > 0) { + if (scores[i] <= maybeEnd && scores[i] >= maybeStart) { + max++; + surprising--; + } + } + } + } + return max; + } +}" +A23056,"import java.util.Scanner; + +public class Googlers { + + public static void main(String[] args) { + // 3p-4 n 3p-3 are critical.. + Scanner c = new Scanner(System.in); + int t = c.nextInt(); + for (int i = 1; i <= t; ++i) { + System.out.print(""Case #"" + i + "": ""); + int n = c.nextInt(); + int s = c.nextInt(); + int p = c.nextInt(); + int count = 0, num; + if (p == 0) { + int m=n; + while(n-- >0) + c.nextInt(); + System.out.println(m); + } else if (p == 1) { + while(n-- >0) + if(c.nextInt() > 0) + count++; + System.out.println(count); + } else { + while (n-- > 0) + if ((num = c.nextInt()) < 3 * p - 4) + continue; + else if (num < 3 * p - 2 && s-- > 0) + count++; + else if (num >= 3 * p - 2) + count++; + System.out.println(count); + } + } + + } + +} +" +A22324,"import java.util.Scanner; + + +public class B { + private static Scanner sc; + + public static void main(String[] args) { + sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int i = 0; i < t; i++) System.out.printf(""Case #%d: %d\n"", i + 1, exec()); + } + + public static int exec() { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = sc.nextInt(); + } + + int definitelyPossible = Math.max(0, p * 3 - 2); + int onlyForSpecial = Math.max(0, definitelyPossible - 2); + + int count = 0; + int left = s; + for (int i = 0; i < n; i++) { + if (t[i] == 0) count += p == 0 ? 1 : 0; + else if (t[i] == 1) count += p <= 1 ? 1 : 0; + else if (t[i] == 2 && p < 2) count++; + else if (t[i] == 2 && p > 2) ; + else if (t[i] == 2 && left > 0) { + left--; + count++; + } + else if (t[i] == 3 && p < 2) count++; + else if (t[i] == 3 && p > 2) ; + else if (t[i] == 3 && left > 0) { + left--; + count++; + } + else if (t[i] >= definitelyPossible) count++; + else if (t[i] >= onlyForSpecial && left > 0) { + left--; + count++; + } + } + + return count; + } +} +" +A22284,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) throws IOException { + Scanner scan = new Scanner(new File(""input"")); + PrintWriter out = new PrintWriter(new BufferedWriter + (new FileWriter(""output""))); + int T = scan.nextInt(); + int compteur =1; + while(T-->0){ + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int max = 0; + while(N-->0){ + int u = scan.nextInt(); + int quo = u/3; + int mod = u%3; + switch(mod){ + case 0:{ + if (quo>=p){ + max++; + } + else if(quo+1>=p&&S>0&&quo-1>=0){ + max++; + S--; + } + break; + } + case 1:{ + if (quo+1>=p){ + max++; + } + break; + } + case 2:{ + if (quo+1>=p){ + max++; + } + else if(quo+2>=p&&S>0){ + max++; + S--; + } + break; + } + } + + } + out.println(""Case #""+compteur+"": ""+max); + compteur++; + } + out.close(); + } + +} +" +A21126,"package com.codejam.qualification.b; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.FileUtils; + +public class DancingWithGooglers { + private Map language = new HashMap(); + + public void main() throws IOException { + List inputLines = FileUtils.readLines(new File(""B-large.in"")); + + int numberOfCases = Integer.parseInt(inputLines.get(0)); + List outputLines = new ArrayList(); + + for (int idx = 1; idx < numberOfCases + 1; idx++) { + int[] numbers = getNumbersForLine(inputLines, idx); + int numberOfGooglersDancing = numbers[0]; + int numberOfSuprisingTriplets = numbers[1]; + int resultBetterThan = numbers[2]; + + int countSimilarScores = 0; + int countSuprisingScores = 0; + + int possibleGoodResult = resultBetterThan * 3 - 2; + int possibleEdgeResult = resultBetterThan * 3 - 4; + + for (int resultIdx = 3; resultIdx < numbers.length; resultIdx++) { + int result = numbers[resultIdx]; + + if (result < resultBetterThan) + continue; + + if (result >= possibleGoodResult) { + countSimilarScores++; + } else if (result >= possibleEdgeResult) { + countSuprisingScores++; + } + } + + int maximumResultsAbove = countSimilarScores; + + if (countSuprisingScores > numberOfSuprisingTriplets) { + countSuprisingScores = numberOfSuprisingTriplets; + } + + maximumResultsAbove += countSuprisingScores; + + outputLines.add(""Case #"" + idx + "": "" + maximumResultsAbove); + } + + FileUtils.writeLines(new File(""out.txt""), outputLines); + } + + private int[] getNumbersForLine(List outputLines, int idx) { + String rawNumbers[] = outputLines.get(idx).split("" ""); + int numbers[] = new int[rawNumbers.length]; + + for (int javaSux = 0; javaSux < rawNumbers.length; javaSux++) { + numbers[javaSux] = Integer.parseInt(rawNumbers[javaSux]); + } + + return numbers; + } + +} +" +A20587,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class ProblemB { + public static int solve(String line) { + String[] s = line.split("" ""); + int len = Integer.valueOf(s[0]); + int S = Integer.valueOf(s[1]); + int th = Integer.valueOf(s[2]); + int[] a = new int[len]; + for (int i = 3 ; i < s.length ; i++) { + a[i-3] = Integer.valueOf(s[i]); + } + + int min_spr = th + (th - 2) * 2; + int min_nonspr = th + (th - 1) * 2; + if (th == 0) { + min_spr = 0; + min_nonspr = 0; + } else if (th == 1) { + min_spr = 1; + min_nonspr = 1; + } + + int cnt = 0; + for (int i = 0 ; i < len ; i++) { + if (a[i] >= min_nonspr) { + cnt++; + } else if (a[i] >= min_spr) { + if (S >= 1) { + S--; + cnt++; + } + } + } + return cnt; + } + + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.valueOf(reader.readLine()); + for (int t = 1 ; t <= T ; t++) { + String line = reader.readLine(); + System.out.println(""Case #"" + t + "": "" + solve(line)); + } + } +} +" +A22870," +package googleCodeJam; + +import java.io.*; +import java.util.*; + +public class ThirdExercise { + + /** + * @param args + */ + public static void main(String[] args) { + try{ + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter fstream2 = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream2); + + String strLine; + int j=0; + + strLine = br.readLine(); + + while ((strLine = br.readLine()) != null) { + + String[] st = strLine.split("" ""); + ArrayList temp = new ArrayList<>(); + int i =0; + + for (i=3;i=p) + nr++; + else if (Math.ceil(((double)tmp)/3.0)>=p-1 && ((double)tmp)/3.0-0.5>=0) + nr_s++; + nr+=((s>nr_s)?nr_s:s); + //shkrimi i rezultatit + + out.write(""Case #""+(++j)+"": ""+nr+"" \n""); + } + in.close(); + out.close(); + } + catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A20871,"import java.util.ArrayList; +import java.util.Scanner; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class Dancing { + public static void main (String[] args) throws IOException { + ArrayList scoreList = new ArrayList(); + int s, p, countBR = 0, casenum = 1; + + Scanner fileScan = new Scanner(new BufferedReader( + new FileReader(""B-large.in""))); + Scanner lineScan; + String theLine; + + Integer.parseInt(fileScan.nextLine()); + + while (fileScan.hasNextLine()) { + theLine = fileScan.nextLine(); + lineScan = new Scanner(theLine); + lineScan.useDelimiter("" ""); + + Integer.parseInt(lineScan.next()); + s = Integer.parseInt(lineScan.next()); + p = Integer.parseInt(lineScan.next()); + + for (int i = 0; lineScan.hasNext(); i++) { + scoreList.add(Integer.parseInt(lineScan.next())); + } + + for (int t : scoreList) { + if (p <= t) { + if (t/3 >= p) { + countBR++; + } + else { + if ((t - p) >= ((p - 2) * 2)) { + if ( ((2 * (p - 1)) + p) <= t) { + countBR++; + } + else if ( (((2 * (p - 2)) + p) <= t) && s > 0) { + countBR++; + s--; + } + } + } + } + } + System.out.println(""Case #"" + casenum + "": "" + countBR); + casenum++; + countBR = 0; + scoreList.clear(); + } + } +} +" +A21137,"import java.io.*; +import java.util.*; + +class CodejamB { + public static char[] map; + public static void main (String [] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""E:/B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""E:/outB.txt""))); + int nTest = Integer.parseInt(in.readLine()); + for (int testIndex = 0; testIndex < nTest; testIndex++) { + out.print(""Case #"" + (testIndex + 1) + "": ""); + /***** start **********/ + StringTokenizer st = new StringTokenizer(in.readLine()); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] data = new int[n]; + int remainingS = s; + int result = 0; + for (int i = 0; i < n; i++) { + data[i] = Integer.parseInt(st.nextToken()); + if (data[i] >= p + 2 * Math.max(0, p - 1)) { + result++; + } else if (data[i] >= p + 2 * Math.max(0, p - 2) && remainingS > 0) { + remainingS--; + result++; + } + } + out.print(result); + /***** end **********/ + out.println(); + } + out.close(); + } +}" +A21928,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * Created with IntelliJ IDEA. + * User: andraz + * Date: 14.4.12 + * Time: 13:25 + * To change this template use File | Settings | File Templates. + */ +public class Dancing { + public static void main(String args[]) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + + for(int rep=0; rep=3*p - 2) { + count++; + } else if ((total >= 3*p - 4) && (total>=p) && (s>0)) { + count++; + s--; + } + } + System.out.printf(""Case #%d: %d\n"", rep+1, count); + } + + } +} +" +A20597,"import java.util.*; + +public class Main { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + + for(int t=1; t<=T; t++) { + + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int normal = 0; + int surprising = 0; + for(int i=0; i=p || (R>=1 && M+1>=p)) { + normal++; + } else if(surprising=p) + || (R==0 && M>0 && M+1>=p))) { + surprising++; + } + + } + + System.out.println(""Case #"" + t + "": "" + (surprising+normal)); + } + + } + +} +" +A20173,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Dancing_With_the_Googlers { + + + /** + * The first line of the input gives the number of test cases, T. + * T test cases follow. + * Each test case consists of a single line containing integers separated by single spaces. + * The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. + * The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + // Reading the input file + Scanner in = new Scanner(new File(""B-large.in"")); + // writting the input file + FileOutputStream fos = new FileOutputStream(""B-large.out""); + PrintStream out = new PrintStream(fos); + //Close the output stream + int testCase=Integer.parseInt(in.nextLine()); + for(int i=0;i scores= new ArrayList(); + int BestResults=0; + int Surprising=0; + for(int j=0;j= atLeastP)) { + BestResults++; + } else { + if (((((temp / 3) + 1) >= atLeastP) && ((temp / 3) >= 1)) + && (Surprising < NoOfSurprisingResults)) { + BestResults++; + Surprising++; + + } + + } + + break; + case 1: + if ((temp / 3) + 1 >= atLeastP) { + BestResults++; + continue; + } + + break; + case 2: + if ((temp / 3) + 1 >= atLeastP) { + BestResults++; + } else { + if (((temp / 3) + 2 >= atLeastP) + && (Surprising < NoOfSurprisingResults)) { + BestResults++; + Surprising++; + } + } + break; + default: + System.out.println(""Error""); + } + + }// Internal for + out.println(BestResults); + // System.out.println(BestResults); + System.out.println(Surprising); + BestResults = 0; + }// for + in.close(); + out.close(); + fos.close(); + + } +} +" +A22529,"import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + + +public class Dancing { + + + public static void main(String[] args) throws NumberFormatException, IOException { + Scanner read = new Scanner(new InputStreamReader(System.in)); + int cases = Integer.parseInt(read.next()); + int counter =1; + while(cases>0){ + int n = Integer.parseInt(read.next()); + int s = Integer.parseInt(read.next()); + int p = Integer.parseInt(read.next()); + int bests = 0; + int p2 =0; + int googler; + for(int i=0; i=p) + bests++; + else if(googler == 2){ + if(1>=p) + bests++; + else if(2 >= p && p2=p) + bests++; + }else{ + if((x*3) == googler){ + if(x>=p) + bests++; + else if((x+1)>= p && p2= p ) + bests++; + }else if((x+x+x+2) == googler){ + if((x+1)>=p) + bests++; + else if((x+2)>=p && p2 0) || max < target ) { + continue; // Unobtainable, discard + } + else if ( normalMax >= target ) { + hits++; + } + else { + potentials++; + } + } + System.out.println(""Case #"" + i + "": "" + (hits + (exceptions >= potentials ? potentials : exceptions))); + } + } +}" +A21563,"package com.qual2; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.List; + +public class qual2 { + + public static void main(String[] args) { + cNums h = new cNums(); + FileInputStream fis; + try { + fis = new FileInputStream(""B-large.in""); + FileOutputStream fos = new FileOutputStream(""largeBout.txt""); + + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + + int lines = Integer.parseInt(br.readLine()); + String outp = null; + String inp; + + for(int i = 0; i < lines; i++) { + inp = br.readLine(); + String[] inpar = inp.split("" ""); + + int lim = Integer.parseInt(inpar[2]); + int surp = Integer.parseInt(inpar[1]); + int numbestn = 0; + int numpossbests = 0; + for(int a = 3; a < inpar.length; a++) { + int curr = Integer.parseInt(inpar[a]); + if(h.bestn[curr] >= lim) + numbestn++; + else if(h.bests[curr] >= lim) + numpossbests++; + } + outp = ""Case #"" + (i+1) + "": ""; + outp += (numbestn + Math.min(surp, numpossbests)); + outp += ""\n""; + fos.write(outp.getBytes()); + + } + fis.close(); + fos.close(); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + +final class cNums { + public int[] bestn; + public int[] bests; + + public cNums() { + bestn = new int[31]; + bests = new int[31]; + FindBests(); + } + + private void FindBests() { + bestn[0] = 0; + bests[0] = 0; + for(int i = 1; i < 31; i++) { + int mod = i % 3; + bestn[i] = i / 3; + if(mod == 0) + bests[i] = bestn[i] + 1; + else if(mod == 1) + bests[i] = ++bestn[i]; + else if(mod == 2) + bests[i] = ++bestn[i] + 1; + } + } +}" +A20863,"package utils; + +/** + * + * @author Fabien Renaud + */ +public class StopWatch { + + private long startTime = -1; + private long stopTime = -1; + private boolean running = false; + + public StopWatch start() { + startTime = System.currentTimeMillis(); + running = true; + return this; + } + + public StopWatch stop() { + stopTime = System.currentTimeMillis(); + running = false; + return this; + } + + public long getElapsedTime() { + if (startTime == -1) { + return 0; + } + if (running) { + return System.currentTimeMillis() - startTime; + } else { + return stopTime - startTime; + } + } + + public String getElapsedSeconds() { + return String.format(""%1$.4f"", getElapsedTime() / 1000.0f); + } + + public StopWatch reset() { + startTime = -1; + stopTime = -1; + running = false; + return this; + } +} +" +A21830,"import java.io.*; +import java.util.*; + +public class MainLarge { + + public static Map mapMax=Collections.synchronizedMap( new HashMap()); + public static Map mapSurprisingMax=Collections.synchronizedMap( new HashMap()); + + /** + * */ + public class TestCase{ + + public Integer id, n, s, p; + public Integer iResult=0; + public Integer[] rPoints; + /***/ + public TestCase( Integer id, Integer n, Integer s, Integer p, Integer[] rPoints){ + this.id=id; + this.n=n; + this.s=s; + this.p=p; + this.rPoints=Arrays.copyOf( rPoints, rPoints.length); } + + /***/ + public void doSolution(){ + this.iResult=0; + if( this.s==0){ + for( int i=0; i!=this.rPoints.length; i++){ + if( MainLarge.mapMax.get( this.rPoints[ i])>=this.p) + this.iResult++; } + }else{ + // MaxPoints + Integer[] rMaxPoints=new Integer[ this.rPoints.length]; + for( int i=0; i!=this.rPoints.length; i++) + rMaxPoints[ i]=MainLarge.mapMax.get( this.rPoints[ i]); + // MaxPoints using Surprising values for some (S) dancers. + int sCounter=this.s; + for( int i=0; i!=this.rPoints.length; i++) + if(( sCounter>0) && ( rMaxPoints[ i]=this.p){ + rMaxPoints[ i]=MainLarge.mapSurprisingMax.get( this.rPoints[ i]); + sCounter--; }} + // Counts + for( int i=0; i!=this.rPoints.length; i++) + if( rMaxPoints[ i]>=this.p) + this.iResult++; }} + } + public TestCase createTestCase( Integer id, Integer n, Integer s, Integer p, Integer[] rPoints){ + return new TestCase( id, n, s, p, rPoints); } + + /** + * @param args + */ + public static void main(String[] args) { + + try { + + MainLarge m=new MainLarge(); + LineNumberReader reader=new LineNumberReader( new FileReader( new File( args[ 0].trim()))); + PrintWriter printer=new PrintWriter( new FileWriter( args[ 1].trim())); + + + /** ScoreMaps */ + for( int i0=0; i0<=10; i0++){ + for( int i1=0; i1<=10; i1++){ + for( int i2=0; i2<=10; i2++){ + Integer maxScore=Math.max( i0, Math.max( i1, i2)); + if( ( Math.abs( i0- i1)<= 2) && ( Math.abs( i0- i2)<= 2) && ( Math.abs( i1- i2)<= 2)){ + Integer nSum=i0+ i1+ i2; + // Not surprising score. + if( !(( Math.abs( i0- i1)==2) || ( Math.abs( i0- i2)==2) || ( Math.abs( i1- i2)==2))){ + if( !MainLarge.mapMax.containsKey( nSum)){ + MainLarge.mapMax.put( nSum, maxScore); } + MainLarge.mapMax.put( nSum, Math.max( MainLarge.mapMax.get( nSum), maxScore)); } + // Surprising Score. + if( !MainLarge.mapSurprisingMax.containsKey( nSum)){ + MainLarge.mapSurprisingMax.put( nSum, maxScore); } + MainLarge.mapSurprisingMax.put( nSum, Math.max( MainLarge.mapSurprisingMax.get( nSum), maxScore)); }}}} + + /***/ + int nTestCases=Integer.valueOf( reader.readLine().trim()); + for( int n=0; n!=nTestCases; n++){ + String str[]=reader.readLine().split( "" ""); + Integer[] rPoints=new Integer[ str.length- 3]; + for( int i=3; i!=str.length; i++) + rPoints[ i- 3]=Integer.valueOf( str[ i].trim()); + TestCase testCase=m.createTestCase( n+ 1, + Integer.valueOf( str[ 0].trim()), + Integer.valueOf( str[ 1].trim()), Integer.valueOf( str[ 2].trim()), rPoints); + testCase.doSolution(); + printer.println( ""Case #""+ testCase.id+"": ""+ testCase.iResult); + System.out.println( ""Case #""+ testCase.id+"": ""+ testCase.iResult); } + + printer.close(); + + } catch (FileNotFoundException e) { + + e.printStackTrace(); } + catch (IOException e) { + e.printStackTrace(); }}} +" +A20603,"package com.snap.training; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class DancingGooglers { + + public static ArrayList readFromFile() + { + ArrayList inputList = new ArrayList(); + try + { + FileReader fr = new FileReader(""C:\\Users\\sanath\\Downloads\\code\\input.in""); + BufferedReader br = new BufferedReader(fr); + String readLine = null; + while((readLine=br.readLine())!=null) + { + inputList.add(readLine); + } + } + catch (IOException e) { + inputList = null; + e.printStackTrace(); + } + return inputList; + } + + public static void writeToFile(ArrayList outputList) + { + try + { + FileWriter fw = new FileWriter(""C:\\Users\\sanath\\Downloads\\code\\output.out""); + BufferedWriter br = new BufferedWriter(fw); + for(int i = 0; i < outputList.size(); i++) + { + br.write(""Case #"" + (i+1) + "": "" + outputList.get(i)); + br.newLine(); + } + br.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + + ArrayList inputList = readFromFile(); + + String inputStr = null; + String finalStr = null; + ArrayList outputList = new ArrayList(); + + int noOfGooglers, noOfSurprises, reqdResult, reqdCount; + int sCount, r, q; + + int noOfTestCases = Integer.parseInt(inputList.get(0).toString()); + for(int i = 1; i < noOfTestCases + 1; i++) + { + inputStr = inputList.get(i); + String[] splitStr = inputStr.split("" ""); + noOfGooglers = Integer.parseInt(splitStr[0]); + noOfSurprises = Integer.parseInt(splitStr[1]); + reqdResult = Integer.parseInt(splitStr[2]); + int points; + sCount = 0; + reqdCount = 0; + for(int j = 3; j < splitStr.length; j++) + { + points = Integer.parseInt(splitStr[j]); + + q = points / 3; + r = points % 3; + if(r == 0) + { + if( q >= reqdResult) + { + reqdCount++; + } + else if( (q + 1) >= reqdResult && sCount < noOfSurprises && points > 0 ) + { + reqdCount++; + sCount++; + } + } + else if (r == 1) + { + if( (q+1) >= reqdResult) + { + reqdCount++; + } + } + else if (r == 2) + { + if( (q+1) >= reqdResult) + { + reqdCount++; + } + else if( (q + 2) >= reqdResult && sCount < noOfSurprises ) + { + reqdCount++; + sCount++; + } + } + } + + finalStr = """" + reqdCount; + outputList.add(finalStr.trim()); + } + + writeToFile(outputList); + + } + +} +" +A22102,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + + +public class Dancing_improved { + + static int f_Superan_limites(String params){ + int superan_limite=0; + String[] parametros=params.split("" ""); + + int n_participantes= Integer.parseInt(parametros[0]); + int n_sorprendidos= Integer.parseInt(parametros[1]); + int nota_limite= Integer.parseInt(parametros[2]); + + int suma_notas, resto, nota_juego; + for(int i=3;i=nota_limite){ + superan_limite++; + }else if(nota_juego-1>=0 && n_sorprendidos>0 && ((nota_juego+1)>=nota_limite || (nota_juego+2)>=nota_limite)){ // no supera el límite pero podría hacerlo si quedan sorprendidos + n_sorprendidos--; + superan_limite++; + } + }else if((suma_notas+1)%3==0){ // Tendré que jugar con el valor en +-1 + nota_juego=(suma_notas+1)/3; + if(nota_juego-1>=0 && nota_juego>=nota_limite){ + superan_limite++; + }else if(nota_juego-1>=0 && n_sorprendidos>0 && (nota_juego+1)>=nota_limite){ + n_sorprendidos--; + superan_limite++; + } + }else if((suma_notas+2)%3==0){ // Tendré que jugar con el valor en +-2 + nota_juego=(suma_notas+2)/3; + if(nota_juego-1>=0 && nota_juego>=nota_limite){ + superan_limite++; + } + } + } + return superan_limite; + } + + public static void main(String[] args) throws IOException { + FileReader fr = new FileReader(args[0]); + BufferedReader bf = new BufferedReader(fr); + int ntest=0; + + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + String lines = bf.readLine(); + String liner, linew; + int lines_r=0; + String[] numbers; + int total; + + while((liner = bf.readLine())!=null && lines_r<=Integer.parseInt(lines)) { + ntest++; + numbers=liner.split("" ""); + total=f_Superan_limites(liner); + linew=""Case #""+ntest+"": ""+total+""\n""; + out.write(linew); + lines_r++; + } + out.close(); + fr.close(); + } +} +" +A20842,"package tochi.gcj2012; + +import java.io.File; +import java.io.PrintStream; +import java.util.Scanner; + +import javax.swing.text.html.MinimalHTMLWriter; + +public class B { + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + System.setOut(new PrintStream(new File(""output.txt""))); + Scanner sc = new Scanner(new File(""B-large.in"")); + int T = Integer.parseInt(sc.nextLine()); + for (int i = 1; i <= T; i++) { + String[] strs = sc.nextLine().split("" ""); + int N = Integer.parseInt(strs[0]); + int S = Integer.parseInt(strs[1]); + int p = Integer.parseInt(strs[2]); + int[] t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = Integer.parseInt(strs[3 + j]); + } + System.out.println(""Case #"" + i + "": "" + answer(N, S, p, t)); + } + } + + private static int answer(int N, int S, int p, int[] t) { + int count = 0; + int count2 = 0; + for (int i : t) { + if (i >= (3 * p - 2)) + count++; + else if ((i >= (3 * p - 4)) && p >= 2) + count2++; + } + int min = S < count2 ? S : count2; + return count + min; + } + +} +" +A21990,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package cjam; +import java.io.*; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; +/** + * + * @author Administrator + */ +public class Cjam { + + /** + * @param args the command line arguments + */ + + public BufferedWriter output; + public Scanner input; + public int T; + + + + public Cjam() + { + + + try { + input = new Scanner(new FileReader(""B-large.in"")); + output = new BufferedWriter(new FileWriter(new File(""blar.out""))); + } + catch (IOException ex) { + Logger.getLogger(Cjam.class.getName()).log(Level.SEVERE, null, ex); + } + + T = input.nextInt(); + + } + + + + + + + public static void main(String[] args) { + // TODO code application logic here + + Cjam c = new Cjam(); + + + for(int i = 1; i <= c.T ; i++) + { + int N,S,p,ti[],b1,b2; + int max1=0,max2=0,max3=0,max=0; + + N = c.input.nextInt(); + S = c.input.nextInt(); + p = c.input.nextInt(); + ti = new int[N]; + + for(int j=0 ; j < N ; j++) + { + ti[j] = c.input.nextInt(); + } + + if(p > 1) + { + b1 = 3*(p-1) - 1; + b2 = 3*(p-1) ; + + for(int k = 0 ; k < N ; k++ ) + { + if( ti[k] > b2 ) + { + max1++; + } + + else if( (ti[k]==b1) || (ti[k]==b2) ) + { + max2++; + } + + } + + + + if( max2 > S ) + { + max = max1 + S; + } + else + { + max = max1 + max2; + } + + + + } + else if(p==1) + { + for(int k = 0 ; k < N ; k++ ) + { + if(ti[k] >= 1) + { + max1++; + } + + max= max1; + + } + } + else if(p==0) + { + max = N; + } + + + + + + try { + c.output.append(""Case #""+i+"": ""+max); + + + if(i != c.T) c.output.newLine(); + } catch (IOException ex) { + Logger.getLogger(Cjam.class.getName()).log(Level.SEVERE, null, ex); + } + + + + + + } + try { + c.output.close(); + } catch (IOException ex) { + Logger.getLogger(Cjam.class.getName()).log(Level.SEVERE, null, ex); + } + c.input.close(); + + + } +} +" +A20304,"import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class G_2 { + + static int n, s, p; + static int[] tt; + + public static void main(String[] args) throws IOException { + PrintWriter bw = new PrintWriter(new FileWriter(""1.txt"")); + Scanner scan = new Scanner(System.in); + int t = scan.nextInt(); + scan.nextLine(); + for (int i = 0; i < t; i++) { + n = scan.nextInt(); + s = scan.nextInt(); + p = scan.nextInt(); + tt = new int[n]; + int a = 3 * p - 4; + if (p == 1) { + a = 1; + } + if (p == 0) { + a = 0; + } + // int b = 3 * p + 4; + int c = 3 * p - 2; + // int d = 3 * p + 2; + int count = 0; + + for (int j = 0; j < n; ++j) { + tt[j] = scan.nextInt(); + if (c <= tt[j]) { + count++; + continue; + } + if (a <= tt[j] && s != 0) { + s--; + count++; + continue; + } + } + + System.out.println(String.format(""Case #%d: %d"", (i + 1), count)); + bw.write(String.format(""Case #%d: %d\n"", (i + 1), count)); + } + bw.flush(); + bw.close(); + } +} +" +A20809,"package be.mokarea.gcj.googledancers; + +import java.io.PrintWriter; + +import be.mokarea.gcj.common.TestCaseReader; +import be.mokarea.gcj.common.Transformation; + +public class GoogleDancerTransformation extends + Transformation { + + public GoogleDancerTransformation( + TestCaseReader caseReader, + PrintWriter outputWriter) { + super(caseReader, outputWriter); + } + + @Override + protected String transform(GoogleDancerTestCase testCase) { + final int minimumScoreWithoutSurprise = Math.max((3 * testCase.getScoreLowerBoundary()) - 2,testCase.getScoreLowerBoundary()); + final int mimnumScoreWithSurprise = Math.max(minimumScoreWithoutSurprise -2,testCase.getScoreLowerBoundary()); + int countNotSurpisingScores = 0; + int countSurpisingScores = 0; + for (int score : testCase.getScores()) { + if (score >=minimumScoreWithoutSurprise) { + countNotSurpisingScores++; + } else if (score >=mimnumScoreWithSurprise) { + countSurpisingScores++; + } + } + int count = countNotSurpisingScores + Math.min(countSurpisingScores, testCase.getMaxNumberOfSurprisingTripletsOfScores()); + return formatOutput(testCase.getCaseNumber(), count); + } + + private String formatOutput(int caseNumber, int count) { + StringBuffer buf = new StringBuffer(); + buf.append(""Case #""); + buf.append(caseNumber); + buf.append("": ""); + buf.append(count); + return buf.toString(); + } + +} +" +A20821,"import java.io.*; +import java.util.Locale; +import java.util.StringTokenizer; + +public class GCJ2012QualB { + int maxNS[] = new int[31]; + int maxS[] = new int[31]; + + public void run() throws IOException { + for (int s = 0; s <= 30; ++s) { + maxNS[s] = maxS[s] = -1; + } + + for (int a = 0; a <= 10; ++a) { + for (int b = 0; b <= a; ++b) { + for (int c = 0; c <= b; ++c) { + if (a - c <= 1) { + maxNS[a + b + c] = Math.max(maxNS[a + b + c], a); + } + else if (a - c <= 2) { + maxS[a + b + c] = Math.max(maxS[a + b + c], a); + } + } + } + } + + int T = nextInt(); + for (int i = 1; i <= T; ++i) { + out.println(""Case #"" + i + "": "" + solve()); + } + } + + private int solve() throws IOException { + int N = nextInt(); + int S = nextInt(); + int p = nextInt(); + int na = 0; + int nns = 0; + int ns = 0; + int nn = 0; + + for (int i = 0; i < N; ++i) { + int t = nextInt(); + + if (maxNS[t] >= p && maxS[t] >= p) { + ++na; + } + else if (maxNS[t] >= p) { + ++nns; + } + else if (maxS[t] >= p) { + ++ns; + } + else { + ++nn; + } + } + + assert S <= N; + assert na + nns + ns + nn == N; + + if (ns >= S) { + return na + nns + S; + } + else if (na + ns + nn >= S) { + return na + nns + ns; + } + else { + return na + nns + ns - (S - (na + ns + nn)); + } + } + + public static BufferedReader in; + public static PrintStream out; + + public static void main(String[] args) throws IOException { + Locale.setDefault(Locale.US); + + String className = GCJ2012QualB.class.getSimpleName(); + char lastChar = className.charAt(className.length() - 1); + System.setIn(new FileInputStream(lastChar + "".in"")); + System.setOut(new PrintStream(lastChar + "".out"")); + + in = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintStream(new BufferedOutputStream(System.out)); + + new GCJ2012QualB().run(); + + out.close(); + } + + public static StringTokenizer tokenizer; + + public static String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(in.readLine()); + } + return tokenizer.nextToken(); + } + + public static int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + public static long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + public static double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } +} +" +A20632,"import java.util.Scanner; +import java.util.List; +import java.util.ArrayList; + +class Dancing +{ + public static void main(String... args) + { + Scanner sc = new Scanner(System.in); + int tests = sc.nextInt(); + for (int test = 1; test <= tests; test++) + { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + List scores = new ArrayList(n); + for (int i = 0; i < n; i++) + { + scores.add(sc.nextInt()); + } + int result = solve(n, s, p, scores); + System.out.println(""Case #"" + test + "": "" + result); + } + } + + public static int solve(int n, int s, int p, List scores) + { + java.util.Collections.sort(scores); + java.util.Collections.reverse(scores); + int result = 0; + for (Integer score : scores) + { + int avg = score / 3; + if (avg >= p) + { + result++; + continue; + } + if (score - (avg * 3) > 0 && avg + 1 >= p) + { + result++; + continue; + } + // need a surprising result + if (score < 2 || score > 28) + { + // suprising results impossible here + continue; + } + if (score - (avg * 3) == 2 && avg + 2 >= p && s > 0) + { + result++; + s--; + continue; + } + if (score - (avg * 3) == 0 && avg + 1 >= p && s > 0) + { + result++; + s--; + continue; + } + } + return result; + } +} +" +A20246,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + + +public class DancingGooglers { + private String[] m_testInput; + private String[] m_testOutput; + private int[] m_bestNormal = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10}; + private int[] m_bestSurprising = {0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10}; + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + System.out.println(""CodeJam #1: Speaking In Tongues!""); + DancingGooglers dg = new DancingGooglers(); + + //actual test cases: + //dg.m_testInput = dg.readInputTestCases(""./testcases/input2.in""); + dg.m_testInput = dg.readInputTestCases(""./testcases/B-large.in""); + //length: System.out.println(sit.m_testInputGooglerese.length); + int noOfTestCases = Integer.parseInt(dg.m_testInput[0]); + System.out.println(""Number of test cases: "" + noOfTestCases); + + //for(int i : dg.m_bestNormal) + //System.out.println(dg.m_bestNormal[i]); + System.out.println(dg.m_bestNormal.length); + System.out.println(dg.m_bestSurprising.length); + + + + String outputLine = null; + dg.m_testOutput = new String[noOfTestCases]; + for(int i=1; i <= noOfTestCases; i++) { + // translate each single testcase, write to output + //dg.computeMaxResult(i); + outputLine = ""Case #"" + i + "": "" + dg.computeMaxResult(i); // + sit.mapUnknownString(sit.m_testInputGooglerese[i]); + dg.m_testOutput[i-1] = outputLine; + } + for(String s : dg.m_testOutput) + System.out.println(s); + + //write to output file + dg.writeOutputTestResults(""./testcases/output2.out""); + } + + public DancingGooglers() { +/* for int(i=1; i < 10; i++) { + m_bestNormal[i] = + }*/ + } + + public int computeMaxResult(int _testCaseNo) { + int res = 0; + int curNormValue = -1; + int curSurpriseValue = -1; + int curSurprises = 0; + String input = this.m_testInput[_testCaseNo]; + + System.out.println(input); + String[] inStrings = input.split("" ""); + Integer[] integers = new Integer[inStrings.length]; + for(int i = 0; i < inStrings.length; i++) { + integers[i] = Integer.valueOf(inStrings[i]); + } + int _noGooglers = integers[0]; + int _noSurprising = integers[1]; + int _bestResult = integers[2]; + //System.out.println(_noGooglers); + + for(int i=0; i < _noGooglers; i++) { + curNormValue = m_bestNormal[integers[i+3]]; + curSurpriseValue = m_bestSurprising[integers[i+3]]; + System.out.println(curNormValue + "" "" + curSurpriseValue); + System.out.println(); + + if(curNormValue >= _bestResult) + res++; + else if(curSurprises < _noSurprising) { + if(curSurpriseValue >= _bestResult) { + res++; + curSurprises++; + } + } + } + + System.out.println(""Result: "" + res); + return res; + } + + public String[] readInputTestCases(String _filename) { + try { + BufferedReader in = new BufferedReader(new FileReader(_filename)); + String line = null; + List lines = new ArrayList(); + + while ((line = in.readLine()) != null) { + //process(str); + //System.out.println(line); + lines.add(line); + } + in.close(); + return lines.toArray(new String[lines.size()]); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public void writeOutputTestResults(String _outputFilename) { + //String[] array = ... // wherever you get this from; + + try { + File file = new File(_outputFilename); + PrintWriter out = new PrintWriter(new FileWriter(file)); + + // Write each string in the array on a separate line + for (String s : this.m_testOutput) { + out.println(s); + } + + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} +" +A20142,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +public class Dancing { + + + public static int numDancer(double[] a, double numtoget, int s) + { + int iter = 0; + for(int i = 0; i < a.length; i++) + { + a[i] = a[i] - numtoget; + double c = Math.floor(a[i]/2); + if(a[i] < 0) + { + + } + else if(c > numtoget || c == numtoget || c == numtoget - 1) + { + iter = iter + 1; + } + else if (c == numtoget - 2 && s != 0) + { + s = s - 1; + iter = iter + 1; + } + } + return iter; + } + + + + public static void main(String[] args) throws FileNotFoundException, IOException { + + FileReader theFileID = new FileReader(""B-large.in""); + BufferedReader inFile = new BufferedReader(theFileID); + FileWriter fw = new FileWriter(""output.txt""); + PrintWriter output = new PrintWriter(fw); + String line; + + int numCases = 0; + if((line = inFile.readLine()) != null) + numCases = Integer.parseInt(line); + + String[] x = null; + int n = 0, s = 0; + double numtoget = 0; + + + + for(int i = 0; (line = inFile.readLine()) != null && i < numCases; i++) { + + x = line.split("" ""); + n = Integer.parseInt(x[0]); + s = Integer.parseInt(x[1]); + numtoget = Integer.parseInt(x[2]); + double[] a = new double[n]; + for(int j = 3; j < x.length; j++) + { + a[j-3] = Integer.parseInt(x[j]); + } + + int y = numDancer(a, numtoget, s); + + output.write(""Case #""+ (i + 1) + "": "" + y); + output.println(); + + + } + + + + + inFile.close(); + output.close(); + fw.close(); + + double[] b = {15, 13, 11}; + System.out.println(numDancer(b, 5, 1)); + double[] c = {23, 22, 21}; + System.out.println(numDancer(c, 8, 0)); + double[] e = {8, 0}; + System.out.println(numDancer(e, 1, 1)); + double[] d = {29, 20, 8, 18, 18, 21}; + System.out.println(numDancer(d, 8, 2)); + } +} +" +A21693,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DancingWiththeGooglers +{ + + private static final String INPUT_FILE = ""input.txt""; + private static final String OUTPUT_FILE = ""output.txt""; + + //but not surpising + public boolean couldGetBest(int score, int best) + { + int average = best * 3; + + if (score >= average - 2) return true; + + return false; + } + + public boolean couldGetBestIfSurprising(int score, int best) + { + int average = best * 3; + + if (score >= average - 4) return true; + + return false; + } + + public int findMaxBest(int minBest, int[] dancersScore, int surprisingCount) + { + int result = 0 ; + for (int i = 0; i < dancersScore.length; i++) + { + if (dancersScore[i] < minBest) continue; + if (couldGetBest(dancersScore[i], minBest)) + { + result ++; + continue; + } + if (couldGetBestIfSurprising(dancersScore[i], minBest)) + { + if (surprisingCount != 0) + { + surprisingCount--; + result++; + continue; + } + } + + } + return result; + } + + public static void main(String[] args) throws NumberFormatException, IOException + { + DancingWiththeGooglers danGooglers = new DancingWiththeGooglers(); + Parser parser = new Parser(); + String[] input = parser.readInput(INPUT_FILE); + String[] result = new String[input.length]; + for (int i = 0; i < input.length; i++) + { + String[] data = input[i].split("" ""); + int dancersCount = Integer.parseInt(data[0]); + int surprisingCount = Integer.parseInt(data[1]); + int minBest = Integer.parseInt(data[2]); + int[] dancersScores = new int[dancersCount]; + for (int j = 0; j < dancersCount; j++) + { + dancersScores[j] = Integer.parseInt(data[3 + j]); + } + result[i] = Integer.toString(danGooglers.findMaxBest(minBest, dancersScores, surprisingCount)); + } + parser.writeOutput(result, OUTPUT_FILE); + } +} + +class Parser +{ + public String[] readInput(String fileName) throws NumberFormatException, IOException + { + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + int numberOfCases = Integer.parseInt(reader.readLine()); + String[] input = new String[numberOfCases]; + for (int i = 0; i < numberOfCases; i++) + { + input[i] = reader.readLine(); + } + reader.close(); + return input; + } + + public void writeOutput(String[] result, String file) throws IOException + { + FileWriter writer = new FileWriter(file); + BufferedWriter bufferedWriter = new BufferedWriter(writer); + for (int i = 0; i < result.length; i++) + { + bufferedWriter.write(""Case #"" + (i+1) +"": "" + result[i]); + bufferedWriter.newLine(); + } + bufferedWriter.flush(); + bufferedWriter.close(); + } +} + +" +A20145,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +import static java.lang.Math.*; + +public class Dancing { + String PROBLEM_ID = ""Dancing""; + + enum TestType { + EXAMPLE, SMALL, LARGE + } + +// TestType TYPE = TestType.EXAMPLE; +// TestType TYPE = TestType.SMALL; + TestType TYPE = TestType.LARGE; + + public String getFileName() { + String result = PROBLEM_ID + ""_""; + switch (TYPE) { + case EXAMPLE: + result += ""example""; + break; + case SMALL: + result += ""small""; + break; + case LARGE: + result += ""large""; + break; + } + return result; + } + + public String getInFileName() { + return getFileName() + "".in""; + } + + public String getOutFileName() { + return getFileName() + "".out""; + } + + public static void main(String[] args) throws Exception { + new Dancing(); + } + + public Dancing() throws Exception { + BufferedReader in = new BufferedReader(new FileReader(getInFileName())); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter( + getOutFileName()))); + Scanner scan = new Scanner(in); + int tests = scan.nextInt(); + for (int test = 0; test < tests; test++) { + int n = scan.nextInt(); + int surprising = scan.nextInt(); + int p = scan.nextInt(); + int result = 0; + for ( int i = 0; i < n; i++ ) { + int x = scan.nextInt(); + if ( x >= 3*p - 2 ) result++; + else if ( surprising > 0 && x >= 3*p - 4 && x >= 2 ) { + result++; + surprising--; + } + } + String resultStr = String.format(""Case #%d: %d"", test + 1, result); + // add answer here + + System.out.println(resultStr); + out.println(resultStr); + } + out.close(); + System.out.println(""*** in file = "" + getInFileName()); + System.out.println(""*** out file = "" + getOutFileName()); + } +} + + +" +A21789," +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Arrays; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + + +public class QB { + public static void main(String[] args){ + try{ + Scanner sc = new Scanner(new File(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""output.out""))); + + int t = sc.nextInt(); + for(int i=0;i=0;j--){ + int k = scores[j]%3; + int m = scores[j]/3; + if(scores[j]==0) s = 0; + if(k==0){ + if(m>=p) r += 1; + else if ((m+1>=p)&&(s>0)){ + r += 1; + s -= 1; + } + else break; + }else if(k==1){ + if(m+1>=p) r += 1; + else break; + }else{ + if(m+1>=p) r += 1; + else if ((m+2>=p)&&(s>0)){ + r += 1; + s -= 1; + } + else break; + } + } + bw.write(""Case #""+String.valueOf(i+1)+"": ""); + bw.write(String.valueOf(r)); + bw.newLine(); + bw.flush(); + } + bw.close(); + + } catch (Exception ex) { + Logger.getLogger(QA.class.getName()).log(Level.SEVERE, null, ex); + } + } +} +" +A20616,"public class Surprising +{ + char isSurprising; +}" +A23024,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; + +import org.apache.commons.io.IOUtils; + +public class Problem2 { + public static void main(String[] args) throws NumberFormatException, + IOException { + // The first line of the input gives the number of test cases, T. + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(args[0])); + int T = Integer.parseInt(in.readLine()); + for (int i = 1; i <= T; i++) { + String[] split = in.readLine().split("" ""); + // T test cases follow. Each test case consists of a single line + // containing integers separated by single spaces. The first + // integer will be N, the number of Googlers + int N = Integer.parseInt(split[0]); + // and the second integer will be S, the number of surprising + // triplets of + // scores. + + int S = Integer.parseInt(split[1]); + // The third integer will be p, as described above. + int p = Integer.parseInt(split[2]); + // Next will be N integers ti: the total points of the Googlers. + int[] ti = new int[N]; + for (int j = 0; j < ti.length; j++) + ti[j] = Integer.parseInt(split[j + 3]); +// System.out.println(String.format( +// ""N = %s S = %s p = %s ti = %s "", N, S, p, +// Arrays.toString(ti))); + int count = 0; + for (int j = 0; j < ti.length; j++) { + int t = ti[j]; + if (t < p) + continue; + if (t >= p * 3 - 2) + count++; + else if (t >= p * 3 - 4 && --S >= 0) + count++; + } + System.out.println(""Case #"" + i + "": "" + count); + } + } finally { + IOUtils.closeQuietly(in); + } + } +} +" +A22204,"package br.com.atama.google.jam.dancing; + +public class ScoreCalculator { + + private final Show show; + + public ScoreCalculator(int numSurprises, int scoreThreshold, + int[] totalScores) { + Context.INSTANCE.setNumSurprises(numSurprises); + Context.INSTANCE.setThreshold(scoreThreshold); + + show = new Show(totalScores); + } + + public int calculate() { + show.addSurprises(Context.INSTANCE.getNumSurprises()); + + return show.getTotalGoodScores(); + } + +} +" +A21924,"import java.awt.geom.*; +import java.io.*; +import java.math.*; +import java.util.*; +import java.util.regex.*; +import static java.lang.Math.*; + +public class Main { + public Main() throws IOException { + String input; + int t; + + input = br.readLine(); + t = Integer.valueOf(input); + + for (int i = 0; i < t; i++) { + if (i > 0) + sb.append(""\r\n""); + + input = br.readLine(); + work(input, i); + } + + System.out.print(sb); + } + + boolean isGood(int score, int P) { + int max = score / 3; + + if ((score % 3) > 0) + max++; + + if (max >= P) + return true; + + return false; + } + + boolean isSurprise(int score, int P) { + int max = score / 3; + + if (((score % 3) == 0) && (max > 0)) + max++; + else + max += score % 3; + + if (max >= P) + return true; + + return false; + } + + private void work(String input, int t) { + //debug(input); + int ret = 0; + String[] inputArray = input.split("" ""); + int N = Integer.valueOf(inputArray[0]); + int S = Integer.valueOf(inputArray[1]); + int P = Integer.valueOf(inputArray[2]); + + for (int i = 3; i < N + 3; i++) { + int score = Integer.valueOf(inputArray[i]); + + if (isGood(score, P)) { + //debug(""score:"", score, "" Good!!""); + ret++; + continue; + } + + if (S == 0) + continue; + + if (isSurprise(score, P)) { + //debug(""score:"", score, "" Surprise!!""); + ret++; + S--; + } + } + + sb.append(""Case #""); + sb.append(String.valueOf(t + 1)); + sb.append("": ""); + sb.append(String.valueOf(ret)); + } + + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader( + new InputStreamReader(System.in)); + + public static void main(String[] args) throws IOException { + new Main(); + } + + public static void debug(Object... arr) { + System.err.println(Arrays.deepToString(arr)); + } +} +" +A21584,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.dancingwiththegooglers; + +import uk.co.epii.codejam.common.AbstractMain; + +/** + * + * @author jim + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + AbstractMain.main(args, new DancingWithTheGooglersProcessor()); + } +} +" +A21796,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class ProblemB { + public static void main(String [] args){ + doIt(); + } + + public static void doIt(){ + + try{ + BufferedWriter out = new BufferedWriter(new FileWriter(""B-large.out"")); + FileInputStream fstream = new FileInputStream(new File(""B-large.in"")); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + int testLines = Integer.parseInt(br.readLine()); + int caseCounter = 0; + while ((strLine = br.readLine()) != null) { + int possibs = 0; + String[] str = strLine.split("" ""); + int n = Integer.parseInt(str[0]); + int s = Integer.parseInt(str[1]); + int p = Integer.parseInt(str[2]); + for (int i = 3 ; i < str.length ; i++) { + int score = Integer.parseInt(str[i]); + if(score >= (3*p -2)){ + possibs++; + } else if(s > 0 && score >= (3*p -4) && score >= 2){ + s--; + possibs++; + } + } + caseCounter++; + out.write(""Case #"" + caseCounter + "": "" + possibs); + out.newLine(); + } + in.close(); + out.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A22208,"import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class B { + + public static void main(String[] args) throws Throwable { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int numCases = Integer.parseInt(reader.readLine()); + + for (int c = 1; c <= numCases; c++) { + System.out.println(""Case #"" + c + "": "" + solveCase(reader.readLine())); + } + } + + private static int solveCase(String line) { + String[] tokens = line.split("" ""); + int numGooglers = Integer.parseInt(tokens[0]); + int surprisingTriplets = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int[] results = new int[numGooglers]; + for (int i = 0; i < numGooglers; i++) { + results[i] = Integer.parseInt(tokens[i + 3]); + } + + int num = 0; + + for (int i = 0; i < numGooglers; i++) { + int res = results[i]; + int lowestScore = res / 3; + int highestScore = lowestScore; + int remainder = res - lowestScore * 3; + if (remainder > 0) { + highestScore++; + } + if (highestScore >= p) { + num++; + } else if (surprisingTriplets > 0) { + switch (remainder) { + case 0: // 222 -> 123 + if (lowestScore > 0 && highestScore + 1 >= p) { + num++; + surprisingTriplets--; + } + break; + case 1: // 223 -> 133 + if (lowestScore > 0 && highestScore >= p) { + num++; + surprisingTriplets--; + } + break; + case 2: // 233 -> 224 + if (highestScore + 1 >= p) { + num++; + surprisingTriplets--; + } + break; + } + } + } + return num; + } +} +" +A20589,"import java.io.*; +import java.util.*; +import java.math.BigInteger; +public class B{ +public static void main(String []args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t, x = 0, n, s, p, ans; + t = Integer.parseInt(br.readLine()); + while(t>0) {t--; x++; + ans = 0; + String w = br.readLine(); + String arr1[] = w.split(""[ ]+""); + n = Integer.parseInt(arr1[0]); + s = Integer.parseInt(arr1[1]); + p = Integer.parseInt(arr1[2]); + int a = 0, a1 = 1, r = 2; + for(int i = 0; i < n; i++) {r++; + a = Integer.parseInt(arr1[r]); + int b = (a/3); + int c = b*3; + int d = (b+1)*3; + int e = 0; + if(b >= p) { ans++; e = 1;} + if(e == 0) { if((c+1) == a && (b+1) >= p) { ans++; e = 1;} + else if((c+2) == a && (b+1) >= p){ans++; e = 1;} + } + if(e == 0 && a1 <= s) { + if(c > 0 && (c) == a && (b+1) >= p) { ans++; a1++;} + else if((c+1) == a && (b+1) >= p) { ans++; a1++;} + else if((c+2) == a && (b+2) >= p) { ans++; a1++;} + } + } + + System.out.println(""Case #""+x+"": ""+ans); + } + } +} +" +A22740,"package codeJam; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.util.*; + +import javax.swing.*; + +@SuppressWarnings(""serial"") +public class Problem2 extends JFrame +{ + //TODO Set file names + static final String INFILE = ""codeJam/inFile2l.txt""; + static final String OUTFILE = ""codeJam/outFile2l.txt""; + + // variable declaration + JTextArea inText, outText; + + public static void main(String[] args) + { + new Problem2(); + } + + public Problem2() + { + DefaultHandler aHandler = new DefaultHandler(); + + setTitle(""Title""); + Container content = this.getContentPane(); + content.setLayout(null); + + //////////////////////////////////////////////////////////////////////// LABELS //////// + JLabel aLabel = new JLabel(""Input:""); + aLabel.setBounds(258, 5, 50, 20); + content.add(aLabel); + + aLabel = new JLabel(""Output:""); + aLabel.setBounds(791, 5, 50, 20); + content.add(aLabel); + + /////////////////////////////////////////////////////////////////////// TEXTAREAS ////// + inText = new JTextArea(); + JScrollPane scroll = new JScrollPane(inText); + scroll.setBounds(33, 33, 500, 200); + content.add(scroll); + + outText = new JTextArea(); + scroll = new JScrollPane(outText); + scroll.setBounds(566, 33, 500, 200); + content.add(scroll); + + //////////////////////////////////////////////////////////////////////// BUTTONS /////// + JButton aButton = new JButton(""Test File""); + aButton.addActionListener(aHandler); + aButton.setBounds(33, 250, 233, 40); + content.add(aButton); + + aButton = new JButton(""Run File""); + aButton.addActionListener(aHandler); + aButton.setBounds(300, 250, 233, 40); + content.add(aButton); + + aButton = new JButton(""Test TextBox""); + aButton.addActionListener(aHandler); + aButton.setBounds(566, 250, 233, 40); + content.add(aButton); + + aButton = new JButton(""Run TextBox""); + aButton.addActionListener(aHandler); + aButton.setBounds(833, 250, 233, 40); + content.add(aButton); + + setSize(1100, 325); + setResizable(false); + setLocation(100, 100); + setVisible(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + private class DefaultHandler implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals(""Test File"")) + { + ArrayList fileContents = new ArrayList(); + + Scanner scanner; + try + { + scanner = new Scanner(new File(INFILE)); + + while (scanner.hasNextLine()) + fileContents.add(scanner.nextLine()); + + scanner.close(); + } + catch (FileNotFoundException e1) + { + e1.printStackTrace(); + } + + String[] output = new String[fileContents.size()]; + fileContents.toArray(output); + + outText.setText(""""); + for (int i = 0; i < output.length; i++) + outText.setText(outText.getText() + ""."" + output[i] + ""."" + ""\n""); + } + else if (e.getActionCommand().equals(""Run File"")) + { + ArrayList fileContents = new ArrayList(); + + Scanner scanner; + try + { + scanner = new Scanner(new File(INFILE)); + + while (scanner.hasNextLine()) + fileContents.add(scanner.nextLine()); + + scanner.close(); + } + catch (FileNotFoundException e1) + { + e1.printStackTrace(); + } + + String[] output = new String[fileContents.size()]; + fileContents.toArray(output); + + String[] answer = myAlgorithm(output); + + + Writer out; + + try + { + out = new OutputStreamWriter(new FileOutputStream(OUTFILE)); + + for (int i = 0; i < answer.length; i++) + out.write(answer[i] + ""\n""); + + out.close(); + } + catch (FileNotFoundException e1) + { + e1.printStackTrace(); + } + catch (IOException e1) + { + e1.printStackTrace(); + } + + outText.setText(""File Written""); + } + else if (e.getActionCommand().equals(""Test TextBox"")) + { + String[] output = inText.getText().split(""\n""); + + outText.setText(""""); + for (int i = 0; i < output.length; i++) + outText.setText(outText.getText() + ""."" + output[i] + ""."" + ""\n""); + } + else if (e.getActionCommand().equals(""Run TextBox"")) + { + String[] output = inText.getText().split(""\n""); + + String[] answer = myAlgorithm(output); + + outText.setText(""""); + for (int i = 0; i < answer.length; i++) + outText.setText(outText.getText() + answer[i] + ""\n""); + } + } + + + // IMPORTANT NOTE:: INFILE is read and OUTFILE is written + // in the Project Directory. + + // TODO:: Write all of your algorithm code here + // String[] myData is the lines of input + // You must return a String[] + public String[] myAlgorithm(String[] myData) + { + int numProbs = Integer.parseInt(myData[0]); + + String[] workSet = new String[numProbs]; + for (int i = 0; i < numProbs; i++) + { + // mess with myData[i + 1] here and output to workSet[i] + String[] myProblem = myData[i + 1].split("" ""); + int[] myInts = new int[myProblem.length]; + for (int j = 0; j < myProblem.length; j++) + myInts[j] = Integer.parseInt(myProblem[j]); + + int numGooglers = myInts[0]; + int numSuprises = myInts[1]; + int bestResult = myInts[2]; + int[] totalPoints = new int[numGooglers]; + for (int j = 0; j < numGooglers; j++) + totalPoints[j] = myInts[3 + j]; + + int count = 0; + for (int j = 0; j < numGooglers; j++) + { + double avgScore = totalPoints[j] / 3.0; + double highHopes = Math.ceil(avgScore); + + if (highHopes >= bestResult) + count++; + else + { + double lowJudgeScore = Math.floor((totalPoints[j] - bestResult) / 2.0); + + if (lowJudgeScore >= 0) + { + if (bestResult - lowJudgeScore <= 2) + { + if (numSuprises > 0) + { + numSuprises--; + count++; + } + } + } + } + } + + workSet[i] = """" + count; + } + + String[] myOutput = new String[numProbs]; + for (int i = 0; i < numProbs; i++) + myOutput[i] = ""Case #"" + (i + 1) + "": "" + workSet[i]; + + return myOutput; + } + } +} +" +A21946,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package gcj; + +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.Set; + +/** + * + * @author daniele + */ +public class GCJ_B { + + + public static void main(String[] args) throws Exception{ + + + Scanner in = new Scanner(new File(args[0])); + FileWriter out = new FileWriter(""/home/daniele/Scrivania/Output""); + + int n,p,s; + int countp=0,counts=0; + int prove=in.nextInt(); + ArrayList tp; + + + + out.write(""""); + out.flush(); + + for(int i=1;i<=prove;i++){ + out.append(""Case #"" +i+"": "");out.flush(); + n=in.nextInt(); + s=in.nextInt(); + p=in.nextInt(); + tp= new ArrayList(); + for(int j=0;j=0 && f/2>=p-2){ + countp++; + if( f/2==p-2 && s==0 ) + countp--; + else if(f/2==p-2 && s>0) + s--; + } + + } + System.out.println(""countp=""+countp+"" counts=""+counts+"" s=""+s); + + out.append(countp+""\n"");out.flush(); + countp=0; counts=0; + System.out.println(""**************""); + + + } + + + + } + + + +} +" +A20009,"import java.io.*; +import java.math.BigInteger; +import java.util.*; + +public class r2a +{ + + int surprises = 0; + int p = 0; + int elems[] = new int[100]; + int output = 0; + + /** + * @param args + */ + public static void main(String[] args) + { + r2a mk = new r2a(); + try { + FileInputStream fstream = new FileInputStream(""d:/cjinput.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String str; + int i = 0; + while ((str = br.readLine()) != null) { + int numOfElems = 0; + mk.output = 0; + i++; + if (i == 1) + continue; + StringTokenizer strTok = new StringTokenizer(str, "" ""); + while (strTok.hasMoreTokens()) { + numOfElems = Integer.parseInt(((String) strTok.nextToken())); + mk.surprises = Integer.parseInt(((String) strTok.nextToken())); + mk.p = Integer.parseInt(((String) strTok.nextToken())); + for (int x = 0; x < numOfElems; x++) { + mk.elems[x] = Integer.parseInt(((String) strTok.nextToken())); + } + } + + mk.evaluate(i,numOfElems); + + } + in.close(); + } + catch (Exception e) { + System.err.println(e); + } + + } + + private void evaluate(int rowNum, int numOfElems) + { + + for (int i = 0; i< numOfElems; i++) { + if (isValidTotal(elems[i])) + output++; + + } + + String outputStr = ""Case #"" + (rowNum -1) + "": "" + output; + System.out.println(outputStr); + } + + private boolean isValidTotal(int num) { + + if (p==0) + return true; + if (num != 0) { + int maxVal = 3*p; + if (num >= maxVal-2) + return true; + if (num >= maxVal-4 && surprises > 0) { + surprises--; + return true; + } + } + return false; + } +} +" +A20789," import java.io.*; + import java.util.*; + public class dancing + { + public static void main(String[] args) throws Exception + { + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + int cases = Integer.parseInt(reader.readLine()); + for(int x = 0; x < cases; x++) + { + int count = 0; + String next = reader.readLine(); + StringTokenizer token = new StringTokenizer(next); + int N = Integer.parseInt(token.nextToken()); + int S = Integer.parseInt(token.nextToken()); + int p = Integer.parseInt(token.nextToken()); + int[] array = new int[N]; + for(int y = 0; y < N; y++) + array[y] = Integer.parseInt(token.nextToken()); + for(int y = 0; y < N; y++) + { + if(array[y] == 0 && p != 0){ + } + else if(array[y] >= 28) + { + if(p <= 10) + count++; + } + else if(array[y]%3 == 1) + { + if(array[y]/3 + 1 >= p) + count++; + } + else if(array[y]%3 == 2) + { + if(array[y]/3 + 1 >= p) + count++; + else if(array[y]/3 + 2 >= p) + if(S > 0) + { + S--; + count++; + } + } + else if(array[y]%3 == 0) + if(array[y]/3 >= p) + count++; + else if(array[y]/3 + 1 >= p) + if(S > 0) + { + S--; + count++; + } + } + out.println(""Case #"" + (x + 1) + "": "" + count); + } + out.close(); + } + }" +A20371,"package dancing; + +import java.io.*; +import java.util.StringTokenizer; + +public class Dancing { + + /** + * @param args + */ + + private static int[] values = null; + private static int[] googlers= null; + private static int total =0; + + public static void main(String[] args) { + + BufferedReader fin = null; + int t = 0; + StringTokenizer str = null; + + try { + fin = new BufferedReader(new FileReader(new File(""/home/bamdad/NetBeansProjects/Dancing/src/dancing/B-small-attempt0.in""))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + + + try { + t = Integer.parseInt(fin.readLine()); + //System.out.println(t); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + values = new int[3]; + + + for(int i=0;i=values[2]) + total++; + else if(remainder==0&&values[1]>0&&(value+1)>=values[2]){ + values[1]--; + total++; + } + else if(remainder>0&&(value+1)>=values[2]) + total++; + + else if(remainder==2&&(value+2)>=values[2]&&values[1]>0){ + total++; + values[1]--; + } + } + System.out.println(total); + } + +} +" +A20721,"package gcj2012qual; + +import java.io.*; +import java.util.*; + +public class Dancing { + + /** + * @param args + */ + + public static void main(String[] args) throws Exception{ + // TODO Auto-generated method stub + + Scanner input = new Scanner(new File(""B-large.in"")); + PrintWriter output = new PrintWriter(new FileWriter(""output"")); + + // Scanner in = new Scanner(System.in); + int case_num = input.nextInt(); + //String word = in.nextLine(); + + int[][] surprising = new int[31][11]; + int[][] normal = new int[31][11]; + //int i = 0; + for(int score = 0; score <= 30; score++) + for(int s = 0; s <= 10; s++){ + if(s == 0 && score == 0){ + surprising[score][s] = 0; + normal[score][s] = 1; + continue; + } + if(score == 0){ + surprising[score][s] = 0; + normal[score][s] = 0; + continue; + } + if(s == 0){ + surprising[score][s] = 0; + normal[score][s] = 1; + continue; + } + + if(score < s){ + surprising[score][s] = 0; + normal[score][s] = 0; + continue; + } + + if(score >= s * 3){ + surprising[score][s] = 1; + normal[score][s] = 1; + continue; + } + + if(s == 1 && score == 1){ + surprising[score][s] = 0; + normal[score][s] = 1; + continue; + } + + if(s == 1 && score == 2){ + surprising[score][s] = 1; + normal[score][s] = 1; + continue; + } + + if(score >= s + (s - 2) * 2){ + surprising[score][s] = 1; + if(score > s + (s - 2) * 2 + 1){ + normal[score][s] = 1; + }else{ + normal[score][s] = 0; + } + continue; + }else{ + surprising[score][s] = 0; + normal[score][s] = 0; + continue; + } + + } + for(int i = 0; i < case_num; i++){ + int n = input.nextInt(); + int s = input.nextInt(); + int p = input.nextInt(); + + int[] t = new int[n]; + + int total = 0; + int only_surprising = 0; + + for(int j = 0; j < n; j++){ + t[j] = input.nextInt(); + + if(surprising[t[j]][p] == 1 || normal[t[j]][p] == 1) + total = total + 1; + + if(surprising[t[j]][p] == 1 && normal[t[j]][p] == 0) + only_surprising = only_surprising + 1; + } + + output.println(""Case #"" + (i + 1) + "": "" + (total - Math.max(0, (only_surprising - s)))); + + + } + input.close(); + output.flush(); + output.close(); + } + +} +" +A20127,"package codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class Dancers { + + /** + * @param args + * @Testcases + */ + // Idea: + // Greater than or equal to >= 3*P - 2 then will pass the boundary of P. + // else if it was less than but greater than or equal to 3*P - 4 and S is + // still > 0 in this case consume a surprising ticket. + // else less than that Cannot. + private int calculateMax(int S, int P, int[] scores) { + int minP = Math.max(0, 3 * P - 4); + int maxP = Math.max(0, 3 * P - 2); + int maxNumWinners = 0; + for (int i = 0; i < scores.length; i++) { + int score = scores[i]; + if (score >= P) { + if (scores[i] >= maxP) { + maxNumWinners++; + } else if (scores[i] >= minP && S > 0) { + maxNumWinners++; + S--; + } + } + } + return maxNumWinners; + } + + public int performe(String[] in) { + int N = Integer.parseInt(in[0]); + int S = Integer.parseInt(in[1]); + int P = Integer.parseInt(in[2]); + int[] scores = new int[N]; + for (int i = 0; i < N; i++) { + scores[i] = Integer.parseInt(in[i + 3]); + } + return calculateMax(S, P, scores); + } + + // Input + // 4 + // 3 1 5 15 13 11 + // 3 0 8 23 22 21 + // 2 1 1 8 0 + // 6 2 8 29 20 8 18 18 21 + // + // Output + // Case #1: 3 + // Case #2: 2 + // Case #3: 1 + // Case #4: 3 + public static void main(String[] args) { + + Dancers dancers = new Dancers(); + + try { + FileInputStream fstream = new FileInputStream(""B-small-attempt0.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter fwriter = new FileWriter(""B-small-attempt0.out""); + BufferedWriter out = new BufferedWriter(fwriter); + + String strLine; + strLine = br.readLine(); + int testCases = Integer.parseInt(strLine); + + int currentCase = 0; + while ((strLine = br.readLine()) != null && currentCase < testCases) { + out.write(""Case #"" + ++currentCase + "": "" + + dancers.performe(strLine.split("" ""))); + out.newLine(); + } + in.close(); + out.close(); + } catch (Exception e) { + System.err.println(""I/O Error while reading file.""); + } + + } + +} +" +A20520,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Scanner; +public class DancingWiththeGooglers { + +public static void main(String[] args) throws Exception { + PrintWriter out = new PrintWriter(""output2.out""); + Scanner in = new Scanner(new File(""B-large.in"")); + int testCases = in.nextInt(); + for (int i = 1; i <= testCases; i++){ + int N = in.nextInt(),counter=0; + int S = in.nextInt(); + int P = in.nextInt(); + for(int j = 0 ; j < N ;j++){ + int googler= in.nextInt(); + if(googler%3 == 0 && googler!=0){ + if(googler/3 >= P){ + counter++; + } + else if(googler/3 + 1 >= P && S!=0){ + counter++; + S--; + } + } + else if (googler==0 && P==0){ + counter++; + } + else if(googler%3==1){ + if(googler/3 + 1 >= P){ + counter++; +} +} +else if(googler%3==2){ +if(googler/3 + 1 >= P){ +counter++; +} +else if(googler/3 + 2 >= P && S!=0){ +counter++; +S--; +} +} +} +out.printf(""Case #%d: %d"",i,counter); +out.printf(""\n""); +} +out.close(); +in.close(); + +} + +}" +A20183,"package codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +/* + import lib.tuple.Pair; + import lib.tuple.Tuple; + import lib.util.StringUtil; + */ + +public class CodeJam2012RQB { + + static final String fileIn = ""/Users/jhorwitz/Documents/workspace/test/src/codejam/data/RQ-B-in.txt""; //""data/in.txt""; + static final String fileOut = ""/Users/jhorwitz/Documents/workspace/test/src/codejam/data/RQ-B-out.txt""; //""data/out.txt""; + + public static void main(String[] args) throws Exception { + BufferedReader r = new BufferedReader(new FileReader(fileIn)); + BufferedWriter w = new BufferedWriter(new FileWriter(fileOut)); + String line = r.readLine(); + int T = Integer.parseInt(line); + for (int caseNum = 1; caseNum <= T; caseNum++) { + line = r.readLine(); + String str = ""Case #"" + caseNum + "": "" + solve(line); + w.write(str + ""\n""); + System.out.println(str); + } + w.close(); + r.close(); + } + + private static int solve(String line) { + String[] inputLineAsAnArray = line.split("" ""); + int N = Integer.parseInt(inputLineAsAnArray[0]); + int S = Integer.parseInt(inputLineAsAnArray[1]); + int p = Integer.parseInt(inputLineAsAnArray[2]); + int[] t = new int[N]; + int numGooglersWithMaxScoreGreaterThanP = 0; + + for (int i=0; i= p && 0<=tBy3 && tBy3<=10) { // no need for a surprising triplet for this Googler to get p or more + ++numGooglersWithMaxScoreGreaterThanP; + } else if(tBy3+1 == p && 0<=tBy3-1 && tBy3+1<=10) { // a surprising triplet is needed for this Googler to get a p or more -- ""use"" one if there's one left + if(S>0) { + ++numGooglersWithMaxScoreGreaterThanP; + --S; + } + } + // if neither of those cases, then not valid triplet (surprising or otherwise) could give this Googler a p or more + break; + case 1: + if(tBy3 + 1 >= p && 0<=tBy3 && tBy3+1<=10) { // no need for a surprising triplet for this Googler to get p or more + ++numGooglersWithMaxScoreGreaterThanP; + } // for this case (1 mod 3), a surprising triplet will have the same max as a non-surprising one + // so otherwise, then not valid triplet (surprising or otherwise) could give this Googler a p or more + break; + case 2: + if(tBy3 + 1 >= p && 0<=tBy3 && tBy3+1<=10) { // no need for a surprising triplet for this Googler to get p or more + ++numGooglersWithMaxScoreGreaterThanP; + } else if(tBy3 + 2 == p && 0<=tBy3 && tBy3+2<=10) { // a surprising triplet is needed for this Googler to get a p or more -- ""use"" one if there's one left + if(S>0) { + ++numGooglersWithMaxScoreGreaterThanP; + --S; + } + } + // if neither of those cases, then not valid triplet (surprising or otherwise) could give this Googler a p or more + break; + // default left out since there better only be the three listed cases! + } + } + + return numGooglersWithMaxScoreGreaterThanP; + } +}" +A20174,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.*; +/** + * + * @author GERALD + * JDK 7.0 + */ +public class GoogleDancing { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Scanner scanner = null; + PrintWriter output = null; + try{ + scanner = new Scanner(new FileInputStream(args[0])); + output = new PrintWriter(new FileOutputStream(""resultGoogleDancing.txt"")); + int noOfCases = scanner.nextInt(); + int noOfGooglers, minBestScore, surpScrs, count; + //prior initializations if any + List totalScoresList = new Vector<>(); + int [] buffer; + for(int i=1; i<= noOfCases;++i){ + // TODO code application logic here + noOfGooglers= scanner.nextInt(); + surpScrs = scanner.nextInt(); + minBestScore = scanner.nextInt(); + buffer = new int [noOfGooglers]; + totalScoresList.clear(); + for(int j=0; j=0; --j){ + totalScoresList.add(buffer[j]); + } + count = 0; + count = checkListNormally(totalScoresList,minBestScore,count); + //System.out.println(Arrays.toString(totalScoresList.toArray())); + count = checkListWithSurprise(totalScoresList,minBestScore,count,surpScrs); + //System.out.println(Arrays.toString(totalScoresList.toArray())); + //System.out.println(""*****""); + output.append(String.format(""Case #%d: %d\n"",i,count)); + } + + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } finally{ + if( output!= null) + output.close(); + if(scanner!= null) + scanner.close(); + } + } + + private static int checkListNormally(List totalScoresList, int minBestScore, int count) { + int num, ave,mod; + Iterator ite = totalScoresList.iterator(); + while(ite.hasNext()){ + //System.out.println(""____________""); + num = (int) ite.next(); + ave = num/3; + mod = num%3; + if(num == 0&& 0==minBestScore){ + count ++; + ite.remove(); + }else if(mod == 1 && ave ==0 && ave+1>= minBestScore){ + count ++; + ite.remove(); + }else if(mod == 2 && ave ==0 && ave+1>=minBestScore){ + count++; + ite.remove(); + } + else{ + if(ave!=0){ + if(mod == 0 && ave >= minBestScore ){ + count ++; + ite.remove(); + } + else if( mod == 1 || mod == 2){ + if(ave+1 >= minBestScore){ + count++; + ite.remove(); + } + } + } + } + // System.out.println(Arrays.toString(totalScoresList.toArray())); + // System.out.println(""_____________""); + + } + + //System.out.println(Arrays.toString(totalScoresList.toArray())); + return count; + } + + private static int checkListWithSurprise(List totalScoresList, int minBestScore, int count, int surpScrs) { + int num, ave, mod; + int i=0; + Iterator ite = totalScoresList.iterator(); + while(ite.hasNext() && i= minBestScore){ + count ++; + ite.remove(); + }else if(mod == 2 && ave ==0 && ave+2>=minBestScore){ + count++; + ite.remove(); + } + else{ + if(ave!=0){ + if(mod == 2 && ave+2 >= minBestScore ){ + count ++; + ite.remove(); + } + else if( mod == 0 || mod == 1){ + if(ave+1 >= minBestScore){ + count++; + ite.remove(); + } + } + } + + } + i++; + } + + return count; + } + +} +" +A22454,"package util; + +import java.math.BigInteger; + +public class CombinationGenerator { + + private int[] a; + private int n; + private int r; + private BigInteger numLeft; + private BigInteger total; + + //------------ + // Constructor + //------------ + + public CombinationGenerator (int n, int r) { + if (r > n) { + throw new IllegalArgumentException (); + } + if (n < 1) { + throw new IllegalArgumentException (); + } + this.n = n; + this.r = r; + a = new int[r]; + BigInteger nFact = getFactorial (n); + BigInteger rFact = getFactorial (r); + BigInteger nminusrFact = getFactorial (n - r); + total = nFact.divide (rFact.multiply (nminusrFact)); + reset (); + } + + //------ + // Reset + //------ + + public void reset () { + for (int i = 0; i < a.length; i++) { + a[i] = i; + } + numLeft = new BigInteger (total.toString ()); + } + + //------------------------------------------------ + // Return number of combinations not yet generated + //------------------------------------------------ + + public BigInteger getNumLeft () { + return numLeft; + } + + //----------------------------- + // Are there more combinations? + //----------------------------- + + public boolean hasMore () { + return numLeft.compareTo (BigInteger.ZERO) == 1; + } + + //------------------------------------ + // Return total number of combinations + //------------------------------------ + + public BigInteger getTotal () { + return total; + } + + //------------------ + // Compute factorial + //------------------ + + private static BigInteger getFactorial (int n) { + BigInteger fact = BigInteger.ONE; + for (int i = n; i > 1; i--) { + fact = fact.multiply (new BigInteger (Integer.toString (i))); + } + return fact; + } + + //-------------------------------------------------------- + // Generate next combination (algorithm from Rosen p. 286) + //-------------------------------------------------------- + + public int[] getNext () { + + if (numLeft.equals (total)) { + numLeft = numLeft.subtract (BigInteger.ONE); + return a; + } + + int i = r - 1; + while (a[i] == n - r + i) { + i--; + } + a[i] = a[i] + 1; + for (int j = i + 1; j < r; j++) { + a[j] = a[i] + j - i; + } + + numLeft = numLeft.subtract (BigInteger.ONE); + return a; + + } +} +" +A21889," +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class DancingWithGooglers { + private Scanner in; + private PrintWriter out; + public long output; + public int N; + public int S; + public int p; + public List t = new ArrayList(); + /** + * main method + */ + public static void main(String args[]){ + new DancingWithGooglers(""B-large.in""); + } + + /** + * constructor + */ + public DancingWithGooglers(String filename){ + initIO(filename); + + int n = in.nextInt(); + + for(int i=1;i<=n;i++){ + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + output = 0; + t.clear(); + for(int xx=0;xx=0;i--){ + int elem = t.get(i); + if(elem==30 || elem==29 || elem==28){ + if(10>=p) op++; + } + else if(elem==0){ + if(0>=p) op++; + } + else{ + if(elem%3==0){ + //normal case + if(elem/3 >= p){ + op++; + } + else if((elem/3)+1 >= p){ + if(S>0){ + op++; + S--; + } + } + } + else if(elem%3==1){ + //normal case + if((elem/3)+1 >= p){ + op++; + } + else if((elem/3)+1 >= p){ + if(S>0){ + op++; + S--; + } + } + } + else if(elem%3==2){ + //normal case + if((elem/3)+1 >= p){ + op++; + } + else if((elem/3)+2 >= p){ + if(S>0){ + op++; + S--; + } + } + } + } + } + return op; + } + + /** + * Set up devices to do I/O + */ + public void initIO(String filename){ + try { + in = new Scanner(new FileReader(filename)); + out = new PrintWriter(new FileWriter(filename+"".out"")); + }catch (IOException except) { + System.err.println(""File is missing!""); + } + } + + /** + * Free memory used for I/O + */ + public void closeIO(){ + in.close(); + out.close(); + } + + +} +" +A22245,"package dancingwiththegooglers; + +import inout.In; +import inout.Out; +import java.util.ArrayList; +import java.util.Collections; + +public class Main { + + public static void main(String[] args) throws Exception { + String[] strings = In.read(""B-large.in"", 1); + int cont = 1; + for (String str : strings) { + String[] split = str.split("" ""); + int number = Integer.parseInt(split[0]); + int surprises = Integer.parseInt(split[1]); + int atLeast = Integer.parseInt(split[2]); + ArrayList scores = new ArrayList(number); + for (int i = 0; i < number; i++) { + scores.add(Integer.parseInt(split[i + 3])); + } + Collections.sort(scores); + int maxGooglers = 0; + int newSurprises = 0; + boolean mores = surprises == 0 ? false : true; + for (int i = 0; i < number; i++) { + int score = scores.get(i); + int result = score / 3; + int rest = score % 3; + if (rest != 0) { + if (result + rest <= 10 && (mores || rest != 2)) { + if (result + rest >= atLeast) { + maxGooglers++; + } + if (rest == 2) { + newSurprises++; + } + } else { + if (result + 1 >= atLeast) { + maxGooglers++; + } + if (result + 1 == 2) { + newSurprises++; + } + } + } else { + if (result > 0 && result < 10 && mores) { + if (result + 1 >= atLeast) { + maxGooglers++; + } + newSurprises++; + } else { + if (result >= atLeast) { + maxGooglers++; + } + } + } + if (newSurprises == surprises) { + mores = false; + } + } + Out.write(""output.txt"", cont++, maxGooglers + """"); + } + } +} +" +A21041,"import java.io.*; +import java.util.*; + +public class Dancing { + + public static void main(String [] args) throws IOException + { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter brw = new BufferedWriter(new FileWriter(""output"")); + int t = Integer.parseInt(br.readLine().trim()); + int n = 1; + while(t-- > 0) + { + Scanner sc = new Scanner(br.readLine()); + int N = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int sum1 = p + p-2 + p-2; + int sum2 = p + p - 1 + p -1; + int ans = 0; + while(sc.hasNext()) + { + int a = sc.nextInt(); + if ( s>0 && (sum1>1) && (a ==sum1 || a ==sum1+1)) + { + s--; + ans++; + } + else if ( a >= sum2) + ans++; + } + brw.write(""Case #""+n+"": ""+ans + ""\n""); + n++; + } + brw.close(); + + + } +} +" +A21328,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.util.Scanner; + + +public class problem2 { + public static void main(String[] args){ + try{ + // Create file + FileWriter fstream1 = new FileWriter(""E:/out.txt""); + BufferedWriter outp = new BufferedWriter(fstream1); + try{ + Scanner sc = new Scanner(new File(""E:/B-large.in"")); + int cnt1=sc.nextInt(); + cnt1=0; + while (sc.hasNextInt()) { + int ng = sc.nextInt(); + int ns = sc.nextInt(); + int p = sc.nextInt(); + int cnt =0; + for(int i=0;i=p){ + cnt++; + } + else + if(gs/3+1==p){ + if(ns>0){ + cnt++; + ns--; + } + } + } + else + if(gs%3==1){ + if(gs/3+1>=p) + cnt++; + } + else + if(gs/3+1>=p){ + cnt++; + } + else{ + if(gs/3+2==p){ + if(ns>0){ + cnt++; + ns--; + } + } + } + } + outp.write(""Case #""+(cnt1+1)+"": ""+cnt+'\n');; + cnt1++; + } + }catch(FileNotFoundException e){System.out.println(""File not found"");} + outp.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A20118,"import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream; +import sun.tools.tree.ReturnStatement; + +import javax.swing.*; +import java.io.*; +import java.util.ArrayList; + +/** + * Date: 14/4/12 + * Time: 9:19 AM + */ +public class GoogleFileStream { + public static ArrayList getInput() throws IOException { + JFileChooser fc = new JFileChooser(); + fc.showOpenDialog(null); + File f = fc.getSelectedFile(); + + ArrayList ret = new ArrayList(); + LineInputStream lis = new LineInputStream(new FileInputStream(f)); + String line; + while( (line = lis.readLine()) != null ) + { + ret.add(line); + } + + // number of lines: + ret.remove(0); + + return ret; + } + + public static void setOutput(ArrayList ret) throws IOException { + + JFileChooser fc = new JFileChooser(); + fc.showSaveDialog(null); + File f = fc.getSelectedFile(); + + StringBuilder sb = new StringBuilder(); + FileWriter fw = new FileWriter(f); + for( int i = 0; i < ret.size(); i++ ) + { + sb.delete(0, sb.length()); + sb.append(String.format( ""Case #%d: "", i + 1)); + sb.append( ret.get(i) ); + sb.append( ""\n"" ); + + String o = sb.toString(); + fw.write( o ); + System.out.print(o); + } + fw.close(); + } +} +" +A20051," +import java.awt.*; +import java.awt.event.*; +import java.awt.geom.*; +import java.io.*; +import java.math.*; +import java.text.*; +import java.util.*; + +public class B { + static StringTokenizer st; + static BufferedReader br; + static PrintWriter pw; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter( + System.out))); + int qq = readInt(); + for(int casenum = 1; casenum <= qq; casenum++) { + int n = readInt(); + int s = readInt(); + int max = readInt(); + int ret = 0; + while(n-- > 0) { + int curr = readInt(); + boolean awesome = false; + boolean semiawesome = false; + for(int a = 0; a <= 10; a++) { + for(int b = a; b <= 10; b++) { + for(int c = b; c <= a+2; c++) { + if(a+b+c == curr && c-a <= 1 && c >= max) + awesome = true; + else if(a+b+c == curr && c >= max) + semiawesome = true; + } + } + } + if(awesome) + ret++; + else if(semiawesome && s > 0) { + s--; + ret++; + } + } + pw.println(""Case #"" + casenum + "": "" + ret); + } + pw.close(); + } + + public static long readLong() throws IOException { + return Long.parseLong(nextToken()); + } + + public static double readDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + public static int readInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + public static String nextToken() throws IOException { + while (st == null || !st.hasMoreTokens()) { + if (!br.ready()) { + pw.close(); + System.exit(0); + } + st = new StringTokenizer(br.readLine()); + } + return st.nextToken(); + } +} +" +A22376,"package judgescore; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Kocmi + */ +public class JudgeScore { + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + st = new StringTokenizer(br.readLine()); + int tests = Integer.parseInt(st.nextToken()); + int[] results = new int[tests]; //final result + int dancers, surprises, limit; + int[] scores; + + for (int i = 0; i < tests; i++) { + st = new StringTokenizer(br.readLine()); + dancers = Integer.parseInt(st.nextToken()); + surprises = Integer.parseInt(st.nextToken()); + limit = Integer.parseInt(st.nextToken()); + scores = new int[dancers]; + + for (int j = 0; j < dancers; j++) { + scores[j] = Integer.parseInt(st.nextToken()); + } + + results[i] = bestscore(scores, surprises, limit); + } + + for (int i = 0; i < tests; i++) { + System.out.println(""Case #""+(i+1)+"": ""+results[i]); + } + } catch (Exception ex) { + } + } + + public static int bestscore(int[] scores,int surprises,int limit){ + int score = 0; + int ifsur = 0; + + int root, rest; + for (int i = 0; i < scores.length; i++) { + root = scores[i]/3; + rest = scores[i]%3; + if(scores[i]==0){ + if(root>=limit){ + score++; + } + }else if(rest==0){ + if(root>=limit){ + score++; + }else{ + if((root+1)>=limit){ + ifsur++; + } + } + }else if(rest==1){ + if((root+1)>=limit){ + score++; + } + }else{ + if((root+1)>=limit){ + score++; + }else{ + if((root+2)>=limit){ + ifsur++; + } + } + } + } + + if(ifsur<=surprises){ + return (score+ifsur); + }else{ + return (score+surprises); + } + } +} +" +A21024,"import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Googlers { + + public static void main(String args[]) throws NumberFormatException, IOException + { + solve(); + } + + public static void solve() throws NumberFormatException, IOException + { + ArrayList array=new ArrayList(); + FileInputStream in = new FileInputStream(""B-large.in""); + Scanner s = new Scanner(in); + String solved=""""; + int num_cases=s.nextInt(); + int N=0,S=0,p=0; + int R=0,x=0,y=0,z=0; + int count=0; + + + for(int i=0;i=0 && x<=10) && (y>=0 && y<=10) && (z>=0 && z<=10)){ + if((x-y==2 || x-z==2 || y-z==2)) + { + if(x>=p || y>=p || z>=p){ + //System.out.println(""x:""+x+"" y:""+y+"" z:""+z+"" = ""+R +""(S)""); + array.add(""S""+i+j); + } + }else if(!(x-y==2 || x-z==2 || y-z==2)){ + if(x>=p || y>=p || z>=p){ + //System.out.println(""x:""+x+"" y:""+y+"" z:""+z+"" = ""+R +""(R)""); + array.add(""R""+i+j); + } + } + } + } + } + } + for(int j=0;j0) + { + count+=(array.remove(""S""+i+j) ? 1 : 0); + S-=1; + }else{ + array.remove(""S""+i+j); + } + } + } + + solved+=""Case #""+(i+1)+"": ""+count+""\n""; + System.out.println(""Case #""+(i+1)+"": ""+count); + } + + s.close(); + in.close(); + + FileWriter fstream = new FileWriter(""sollution.out""); + BufferedWriter out = new BufferedWriter(fstream); + out.write(solved); + out.close(); + fstream.close(); + } + +} +" +A22347,"package R0; + +import java.util.HashMap; +import java.util.Scanner; + +/** + * + * @author Rohit + */ +public class QB { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int Tcases = s.nextInt(); + s.nextLine(); + for (int i = 0; i < Tcases; i++) { + int Ngooglers = s.nextInt(); + int Ssurprising = s.nextInt(); + int Paim = s.nextInt(); + int score[] = new int[Ngooglers]; + for (int j = 0; j < Ngooglers; j++) { + score[j] = s.nextInt(); + } + /* + * if score is <2, surprisingNotPossible, + * if score is >=2 and <3*Paim - 4 surprisingPossible but bestNotPossible + * if score is >=3*Paim-4 and <3*Paim-2 bestPossible only using surprising + * if score is >=3*Paim-2 and <29 bestPossible and surprisingPossible + * if score is >=29 bestPossible and surprisingNotPossible + */ + int maxBest = 0; + if (Paim == 0) { + maxBest = Ngooglers; + } + if (Paim == 1) { + for (int j = 0; j < Ngooglers; j++) { + if (score[j] >= 1) { + maxBest++; + } + } + } + if (Paim > 1) { + for (int j = 0; j < Ngooglers; j++) { + if (score[j] >= 3 * Paim - 4) { + if (score[j] < 3 * Paim - 2) { + if (Ssurprising > 0) { + maxBest++; + Ssurprising--; + } + } else { + maxBest++; + } + } + } + } + //printing the output + System.out.println(""Case #"" + (i + 1) + "": "" + maxBest); + + } + } +} +" +A22851,"import java.awt.Polygon; +import java.awt.geom.Point2D; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class B implements Runnable { + + + + private void solve() throws IOException { + int N = nextInt(); + int S = nextInt(); + int p = nextInt(); + int[] t =new int[N]; + for (int i = 0; i < N; ++i) { + t[i] = nextInt(); + } + Arrays.sort(t); + int[] a = new int[N]; + for (int i = 0; i < N; ++i) { + a[i] = (t[i] + 2) / 3; + } + int ans = 0; + int l = 0; + for (l = N - 1; l >= 0 && a[l] >= p; --l) { + ++ans; + } + for (; l >= 0 && S > 0; --l) { + if (t[l] % 3 == 0 && t[l] / 3 + 1 >= p && t[l] / 3 + 1 <= 10 && t[l] / 3 - 1 >= 0) { + ++ans; + --S; + } + if (t[l] % 3 == 2 && t[l] / 3 + 2 >= p && t[l] / 3 + 2 <= 10) { + --S; + ++ans; + } + } + out.println(ans); + } + + + /** + * @param args + */ + public static void main(String[] args) { + (new Thread(new B())).start(); + } + + private BufferedReader br; + private StringTokenizer st; + private PrintWriter out; + private String filename = """"; + + @Override + public void run() { + try { + br = new BufferedReader(new FileReader(""input.txt"")); + st = new StringTokenizer(""""); + out = new PrintWriter(""output.txt""); + int T = nextInt(); + for (int i = 1; i <= T; ++i) { + out.print(""Case #"" + i + "": ""); + solve(); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } + } + + String next() throws IOException { + while (!st.hasMoreTokens()) { + String temp = br.readLine(); + if (temp == null) { + return null; + } + st = new StringTokenizer(temp); + } + return st.nextToken(); + } + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + long nextLong() throws IOException { + return Long.parseLong(next()); + } + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } +} +" +A23057,"package com.codejam; + + +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.HashMap; + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + try { + FileInputStream fstream = new FileInputStream( + ""D:\\Softwares\\B-large.in""); + + DataInputStream in = new DataInputStream(fstream); + + FileOutputStream out = new FileOutputStream( + ""D:\\Softwares\\B-large.out""); + PrintStream p = new PrintStream(out); + + int lineNo = 1; + + while (in.available() != 0) { + if (lineNo == 1) { + cases(in.readLine(), in, p); + } + lineNo++; + } + + in.close(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private static void cases(String firstLine, DataInputStream in, + PrintStream p) throws IOException { + int casesNo = Integer.parseInt(firstLine); + for (int i = 0; i < casesNo; i++) { + p.print(""Case #"" + (i + 1) + "": ""); + String line = in.readLine(); + googlers(line, p); + } + + } + + private static void googlers(String line, PrintStream p) { + + String lines[] = line.split("" ""); + int suprises = Integer.parseInt(lines[1]); + int reqP = Integer.parseInt(lines[2]); + int result = 0; + int number=0; + int quo = 0; + int rem = 0; + for(int i = 3;i=reqP || (rem+quo)>=reqP) + { + result=result+1; + continue; + } + else + { + if(suprises>=1) + { + number +=2; + quo = number/3; + rem = number%3; + rem = rem==0? 0 : 1; + if(quo>=reqP || (rem+quo)>=reqP) + { + result=result+1; + suprises=suprises-1; + continue; + } + + } + + } + } + p.println(result+""""); + } + +} +" +A21875,"import java.util.*; +import java.io.*; + +public class B { + + + + public static void main(String []args){ + Scanner input = new Scanner(System.in); + int cases = input.nextInt(); + int []result = new int[cases]; + //input.nextLine(); + for(int i = 0; i < cases ;i++){ + int n = input.nextInt(); + int s = input.nextInt(); + int p = input.nextInt(); + for(int j = 0 ;j p-1){ + result[i]++; + }else{ + if(avg == p-1 || (avg+mod)>=p){ + if(s>0 && avg>0){ + result[i]++; + s--; + } + } + } + } + } + + try { + BufferedWriter output = new BufferedWriter(new FileWriter(""outfilename.txt"")); + for(int i = 1; i<=cases ;i++){ + System.out.println(""Case #""+i+"": ""+result[i-1]); + output.write(""Case #""+i+"": ""+result[i-1]+""\n""); + + } + output.close(); + } catch (IOException e) { + } + + + } + + + + + +}" +A20900," +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author nzeyi + */ +public class B { + + public static void main(String[] arg) throws Exception { + String in = ""/home/nzeyi/Downloads/B-large.in""; + String out = ""/home/nzeyi/Desktop/out""; + long a = System.currentTimeMillis(); + BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(in))); + PrintWriter w = new PrintWriter(new FileOutputStream(out)); + int c = 0; + int t = Integer.parseInt(r.readLine()); + String s; + while ((s = r.readLine()) != null) { + if (!"""".equals(s)) { + c++; + w.print(""Case #"" + c + "": "" + max(s)); + if (c < t) { + w.println(); + } + } + } + r.close(); + w.flush(); + w.close(); + long b = System.currentTimeMillis(); + System.out.println(""Done(MS): "" + (b - a)); + } + + public static int max(String line) { + String[] t = line.trim().split(""\\s""); + int n = Integer.parseInt(t[0]); + int s = Integer.parseInt(t[1]); + int p = Integer.parseInt(t[2]); + int ret = 0; + int sp = 0; + for (int i = 3; i < t.length; i++) { + int x = Integer.parseInt(t[i]); + if (br(x, 1) >= p) { + ret++; + } else if (sp < s) { + if (br(x, 2) >= p) { + ret++; + sp++; + } + } + } + return ret; + } + + private static int br(int s, int d) { + return (s == 0) ? 0 : (s / 3) + ((d + (s % 3)) / 2); + } +} +" +A22071,"package hk.polyu.cslhu.codejam.lib; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +public class FileStream { + public static Logger logger = Logger.getLogger(FileStream.class); + + /** + * Read the content of file with the given file path + * + * @param filePath String The location of file + * @return The content of file as an instance of list + */ + public static List read(String filePath) { + List content = new ArrayList(); + + try { + BufferedReader br = new BufferedReader(new FileReader(filePath)); + String line; + + while ((line = br.readLine()) != null) { + content.add(line); + } + + br.close(); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + logger.error(""File is not found with the path \"""" + filePath + ""\""""); + } catch (IOException e) { + // TODO Auto-generated catch block + logger.error(e.getMessage()); + } + + return content; + } + + /** + * Save the content to a file + * + * @param filePath String The location of file to be saved + * @param content String The content to be saved + */ + public static void save(String filePath, String content) { + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(filePath)); + bw.write(content); + bw.flush(); + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + logger.error(e.getMessage()); + } + } +} +" +A22486,"package com.self.code.jam.twelve; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.Reader; + +public class DancingScores { + + public static void main(String[] argv) + { + try + { + long startTime = System.currentTimeMillis(); + Reader reader = new FileReader(""D:\\workspace\\Learn\\src\\com\\self\\code\\jam\\twelve\\input\\dancing\\B-large.in""); + BufferedReader bufReader = new BufferedReader(reader); + String x = bufReader.readLine(); + int count = 0; + + File file = new File(""D:\\workspace\\Learn\\src\\com\\self\\code\\jam\\twelve\\output\\dancing\\B-large.out""); + FileWriter writer = new FileWriter(file); + + while((x = bufReader.readLine()) != null) + { + count++; + String res = DancingScores.getMaxBestResult(x); + if (count == 1) + writer.write(""Case #""+count+"": "" + res); + else + writer.write(""\nCase #""+count+"": "" + res); + } + writer.close(); + System.out.println(""Total time = "" +( System.currentTimeMillis() - startTime)); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + private static String getMaxBestResult(String input) { + String[] numbers = input.split("" ""); + if(numbers.length <= 3) + return ""0""; + int N = Integer.parseInt(numbers[0]); + int S = Integer.parseInt(numbers[1]); + int P = Integer.parseInt(numbers[2]); + + int maxBestResult = 0; + + for (int i=3; i<(3+N); i++) + { + int number = Integer.parseInt(numbers[i]); + int division = number/3 ; + int remainder = number % 3; + + if (remainder == 0) + { + if (division >= P) + { + maxBestResult ++; + } + else if ((S != 0) && ((division + 1) >= P) && (division !=0)) + { + S--; + maxBestResult ++; + } + } + else if (remainder == 1) + { + if ((division + 1) >= P) + { + maxBestResult ++; + } + // it can not be a Surprising case + } + else if (remainder == 2) + { + if ((division + 1) >= P) + { + maxBestResult ++; + } + else if ((S != 0) && ((division + 2) >= P)) + { + S--; + maxBestResult ++; + } + } + } + return String.valueOf(maxBestResult); + } +} +" +A20583,"import java.io.*; +import java.util.*; + +public class GoogleQual2012B +{ public static void main(String[] args) throws Throwable + { new GoogleQual2012B(); + } + + public GoogleQual2012B() throws Throwable + { Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""B-large.out"")); + int numTests = in.nextInt(); + for (int i = 0; i < numTests; i++) + { int numGoogs = in.nextInt(); + int numSuprsLeft = in.nextInt(); + int threshhold = in.nextInt(); + int total = 0; + for (int j = 0; j < numGoogs; j++) + { int currTriple = in.nextInt(); + if (maxScore(currTriple) >= threshhold) + { total++; + } + else if (numSuprsLeft > 0 && maxScoreWithSurp(currTriple) >= threshhold) + { total++; + numSuprsLeft--; + } + } + out.println(""Case #"" + (i + 1) + "": "" + total); + } + out.close(); + } + + int maxScore(int total) + { if (total % 3 == 0) + { return total / 3; + } + return (total / 3) + 1; + } + + int maxScoreWithSurp(int total) + { if (total == 0) + { return 0; + } + if (total % 3 == 2) + { return (total / 3) + 2; + } + return (total / 3) + 1; + } +}" +A21587,"import java.util.*; + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int k = 1; k<=T; k++){ + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + + int[] t=new int[n]; + + for (int i =0; i=0; i--){ + if (t[i]=3*p-2) { + comp++; + continue; + } + if (s>0 && t[i]>=3*p-4){ + s--; + comp++; + continue; + } + break; + } + System.out.println(""Case #""+k+"": ""+comp); + } + + } + +} +" +A22639,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +public class Test { + static BufferedReader reader; + static StringTokenizer tokenizer; + static PrintWriter writer; + + static int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + static long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + static double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + static String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + return tokenizer.nextToken(); + } + + public static void main(String[] args) throws IOException { + reader = new BufferedReader(new InputStreamReader(new FileInputStream(""b.in""))); + tokenizer = null; + writer = new PrintWriter(""b.out""); + solve(); + reader.close(); + writer.close(); + } + + private static void test() throws IOException + { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + + int[] sum = new int[n]; + for(int i=0;i=p) + { + res++; + continue; + } + + if(s>0) + { + if((sum[i]+4)/3>=p) + { + s--; + res++; + } + } + } + writer.print(res); + } + + private static void solve() throws IOException { + int t = nextInt(); + for(int i=1;i<=t;i++) + { + writer.print(""Case #""+i+"": ""); + test(); + writer.println(); + } + } +} +" +A22839,"import java.io.*; +import java.util.*; +import java.lang.Math.*; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException{ + Scanner in = new Scanner(new File(""DancingWithTheGooglers.in"")); + PrintWriter p = new PrintWriter(""DancingWithTheGooglers.out""); + int t = Integer.parseInt(in.nextLine()); + int n; + int s; + int h; + int q; + int [] d = new int[100]; + for(int c = 1; c < t+1; c++){ + q = 0; + n = Integer.parseInt(in.next()); + s = Integer.parseInt(in.next()); + h = Integer.parseInt(in.next())-1; + for (int i = 0; i < n; i++){ + d[i] = Integer.parseInt(in.next()); + if(d[i] > 3*h){ + q++; + }else if((d[i]==3*h||d[i]==3*h-1)&&s > 0&& h!= 0){ + q++; + s--; + } + } + p.println(""Case #""+c+"": ""+q); + if(c!=t)in.nextLine(); + } + in.close(); + p.close(); + } + +}" +A22435," +import java.util.*; + +public class DancingWithGooglers { + public static void main( String[] args ) { + Scanner in = new Scanner( System.in ); + int T = in.nextInt(); + + for( int z = 1; z <= T; z++ ) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int count = 0; + + for( int i = 0; i < N; i++ ) { + int sum = in.nextInt(); + int avg = sum / 3; + + if( Math.ceil( sum / 3.0 ) >= p ) { + count++; + } else if( S > 0 ) { + boolean flag = false; + + for( int a = 0; a <= 10; a++ ) { + for( int b = 0; b <= 10; b++ ) { + int c = sum - a - b; + + if( c < 0 || c > 10 || max3( a, b, c )-min3( a, b, c ) > 2 ) { + continue; + } + + if( max3( a, b, c ) >= p ) { + S--; + count++; + flag = true; + break; + } + } + + if( flag ) { + break; + } + } + } + } + + System.out.println( ""Case #"" + z + "": "" + count ); + } + } + + public static int max3( int a, int b, int c ) { + return Math.max( a, Math.max( b, c ) ); + } + + public static int min3( int a, int b, int c ) { + return Math.min( a, Math.min( b, c ) ); + } +} +" +A20015,"package R2012; + +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +public class DancingGooglers { + + + public static void main(String[] args) { + int T,count,n,s,p,num,snum,tem; + try { + FileWriter out = new FileWriter(""d://test//Bl.out""); + //Scanner in=new Scanner(System.in); + Scanner in=new Scanner(new File(""d://test//Bl.in"")); + T=in.nextInt(); + count=0; + while((++count)<=T) + { + n=in.nextInt(); + s=in.nextInt(); + p=in.nextInt(); + num=snum=0; + for(int i=0;i=3*p-2) + ++num; + if(snum=1){ + res++; + } + } else { + if (r[j-3] >= 3*p-2){// x >= p+(p-1)+(p-1) pasti masuk + res++; + } else { + if (s>0 && r[j-3]>= 3*p-4){ // x>= p+(p-2)+(p-2) + s--; + res++; + } + } + } + } + + } + out.println(""Case #""+(i+1)+"": ""+res); + + + } + out.close(); + } +}" +A21443,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.LinkedList; +import java.util.List; + + +public class Dancing implements Runnable { + + private BufferedReader in; + private BufferedWriter out; + private static String inputFile = """"; + private static String outputFile = """"; + static{ + inputFile = ""B-large.in""; + outputFile = ""B-large.out""; + } + + private String count( String inputString ) { + if( inputString == null || inputString.length() <= 1 ) { + return null; + } + + String[] inputToken = inputString.split("" ""); + + int scoreCount = Integer.parseInt(inputToken[0]); + int surprise = Integer.parseInt(inputToken[1]); + int highScore = Integer.parseInt(inputToken[2]); + + List scores = new LinkedList(); + for( int i = 3; i < inputToken.length; i++ ) { + scores.add(i-3, inputToken[i]); + } + + int count = find( surprise, highScore, scores ); + + return count+""\n""; + } + + private int find( int surprise, int highScore, List scores ) { + for( int i = 0; i < scores.size(); i++ ) { + int score = Integer.parseInt(scores.get(i)); + + int remainder = score % 3; + switch( remainder ) { + case 0: + if( score/3 >= highScore ) break; + + if( score/3 <= 0 ) { + scores.remove(i); + i--; + break; + } + + if( surprise <= 0 ) { + scores.remove(i); + i--; + } else { + if( score/3 < highScore-1 ) { + scores.remove(i); + i--; + } else { + surprise--; + } + } + break; + case 1: + if( score/3 >= highScore - 1 ) break; + scores.remove(i); + i--; + break; + case 2: + if( score/3 >= highScore - 1 ) break; + if( score/3 >= highScore - 2 && surprise > 0 ) { + surprise--; + break; + } + + scores.remove(i); + i--; + break; + } + } + return scores.size(); + } + + private void solve() throws Exception { + String inputString = in.readLine(); + + int roop = Integer.parseInt(inputString); + for( int i = 1; i <= roop; i++ ) { + inputString = in.readLine(); + if(inputString == null || inputString.length() <= 0) { + i--; + continue; + } else { + out.write( ""Case #""+i+"": "" + count(inputString) ); + } + } + } + + @Override + public void run() { + try { + in = new BufferedReader( new FileReader(inputFile) ); + out = new BufferedWriter( new FileWriter(outputFile) ); + // in = new BufferedReader( new InputStreamReader(System.in) ); + // out = new BufferedWriter( new OutputStreamWriter(System.out) ); + + solve(); + + out.flush(); + } catch(Exception e) { + e.printStackTrace(); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + new Thread(new Dancing()).start(); + } +} +" +A22877,"package com.google.codejam.googlers; + +import java.util.List; + +/** + * Main class used for DancingWithGooglers. + * @author Sushant + */ +public class DancingWithGooglers { + /** + * Main method from where application start execution. + * + * @param args String [] + */ + public static void main(final String[] args) { + if (args.length != 1) { + System.out.println(""Problem with the command used for execution""); + System.out.println(""Usage: java com.google.codejam.googlers.DancingWithGooglers ""); + System.exit(1); + } + + final List testCases = InputReader.prepareTestCases(args[0]); + if (testCases != null && testCases.size() != 0) { + long startTime = System.currentTimeMillis(); + System.out.println(""Test Cases execution start time "" + startTime); + for (TestCase testcase : testCases) { + executeTestCase(testcase); + } + OutputRecorder.generateTestReport(testCases, args[0] + "".out""); + long endTime = System.currentTimeMillis(); + System.out.print(""Test cases execution end time "" + endTime); + System.out.println(""Total Execution Time "" + (endTime - startTime) + "" milliseconds""); + } + + } + + /** + * Method to execute test cases. + * + * @param testcase TestCase + */ + private static void executeTestCase(final TestCase testcase) { + int bestResultCount = 0; + final int noOfGooglers = testcase.getNoOfGooglers(); + int noSurpriseScores = testcase.getNoOfurprisingTriplets(); + final int bestResult = testcase.getBestResult(); + final int[] scores = testcase.getScores(); + for (int i = 0; i < noOfGooglers; i++) { + int[] triplets = new int[3]; + int score = scores[i]; + if(score == 0) { + triplets[0] = triplets[1] = triplets[2] = 0; + } else if (score % 3 == 0) { + int tempScore = score / 3; + triplets[0] = tempScore; + if (noSurpriseScores != 0 && (Math.abs(triplets[0] - bestResult) == 1 )) { + triplets[1] = tempScore + 1; + triplets[2] = tempScore - 1; + noSurpriseScores = noSurpriseScores - 1; + } else { + triplets[1] = tempScore; + triplets[2] = tempScore; + } + } else { + triplets[0] = score / 3; + int remainingScore = score - triplets[0]; + triplets[1] = remainingScore / 2; + triplets[2] = score - (triplets[0] + triplets[1]); + if(noSurpriseScores != 0) { + if((triplets[1] != 10 && triplets[2] != 10) + && (Math.abs(triplets[2] - bestResult)== 1)) { + triplets[1] = triplets[1] + 1; + triplets[2] = triplets[2] - 1; + noSurpriseScores = noSurpriseScores - 1; + } + } + } + boolean isBest = isBestTriplet(triplets, bestResult); + if(isBest) { + bestResultCount = bestResultCount + 1; + } + + } + testcase.setOutput(new TestResult(bestResultCount)); + } + + /** + * Method to check whether given triplet is best or not. + * @param triplets int [] + * @param bestResult int + * @return boolean + */ + private static boolean isBestTriplet(final int[] triplets, final int bestResult) { + for(int i = 0; i < triplets.length; i++) { + if(triplets[i] >= bestResult) { + return true; + } + } + return false; + } +} +" +A21144,"package CodeJam.c2012.clasificacion; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +/** + * Problem + * + * You're watching a show where Googlers (employees of Google) dance, and then + * each dancer is given a triplet of scores by three judges. Each triplet of + * scores consists of three integer scores from 0 to 10 inclusive. The judges + * have very similar standards, so it's surprising if a triplet of scores + * contains two scores that are 2 apart. No triplet of scores contains scores + * that are more than 2 apart. + * + * For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, + * 8) are surprising. (7, 6, 9) will never happen. + * + * The total points for a Googler is the sum of the three scores in that + * Googler's triplet of scores. The best result for a Googler is the maximum of + * the three scores in that Googler's triplet of scores. Given the total points + * for each Googler, as well as the number of surprising triplets of scores, + * what is the maximum number of Googlers that could have had a best result of + * at least p? + * + * For example, suppose there were 6 Googlers, and they had the following total + * points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising + * triplets of scores, and you want to know how many Googlers could have gotten + * a best result of 8 or better. + * + * With those total points, and knowing that two of the triplets were + * surprising, the triplets of scores could have been: + * + * 10 9 10 6 6 8 (*) 2 3 3 6 6 6 6 6 6 6 7 8 (*) + * + * The cases marked with a (*) are the surprising cases. This gives us 3 + * Googlers who got at least one score of 8 or better. There's no series of + * triplets of scores that would give us a higher number than 3, so the answer + * is 3. + * + * Input + * + * The first line of the input gives the number of test cases, T. T test cases + * follow. Each test case consists of a single line containing integers + * separated by single spaces. The first integer will be N, the number of + * Googlers, and the second integer will be S, the number of surprising triplets + * of scores. The third integer will be p, as described above. Next will be N + * integers ti: the total points of the Googlers. + * + * Output + * + * For each test case, output one line containing ""Case #x: y"", where x is the + * case number (starting from 1) and y is the maximum number of Googlers who + * could have had a best result of greater than or equal to p. + * + * Limits + * + * 1 ≤ T ≤ 100. 0 ≤ S ≤ N. 0 ≤ p ≤ 10. 0 ≤ ti ≤ 30. At least S of the ti values + * will be between 2 and 28, inclusive. + * + * Small dataset + * + * 1 ≤ N ≤ 3. + * + * Large dataset + * + * 1 ≤ N ≤ 100. + * + * Sample + * + * Input Output 4 Case #1: 3 3 1 5 15 13 11 Case #2: 2 3 0 8 23 22 21 Case #3: 1 + * 2 1 1 8 0 Case #4: 3 6 2 8 29 20 8 18 18 21 + * + * @author Leandro Baena Torres + */ +public class B { + + public static void main(String[] args) throws FileNotFoundException, IOException { + BufferedReader br = new BufferedReader(new FileReader(""B.in"")); + String linea; + int numCasos, N, S, p, t[], y, minSurprise, minNoSurprise; + + linea = br.readLine(); + numCasos = Integer.parseInt(linea); + for (int i = 0; i < numCasos; i++) { + linea = br.readLine(); + String[] aux = linea.split("" ""); + N = Integer.parseInt(aux[0]); + S = Integer.parseInt(aux[1]); + p = Integer.parseInt(aux[2]); + t = new int[N]; + y = 0; + minSurprise = p + ((p - 2) >= 0 ? (p - 2) : 0) + ((p - 2) >= 0 ? (p - 2) : 0); + minNoSurprise = p + ((p - 1) >= 0 ? (p - 1) : 0) + ((p - 1) >= 0 ? (p - 1) : 0); + for (int j = 0; j < N; j++) { + t[j] = Integer.parseInt(aux[3 + j]); + if (t[j] >= minNoSurprise) { + y++; + } else { + if (t[j] >= minSurprise) { + if (S > 0) { + y++; + S--; + } + } + } + } + + System.out.println(""Case #"" + (i + 1) + "": "" + y); + } + } +} +" +A20465," + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class FileUtil { + + private static final String RESULT_PATH = ""/home/ypxu/src/codejam/2012""; + + + public static String[] readFile(String filePath) { + List content = new ArrayList(); + try { + BufferedReader bis = new BufferedReader(new FileReader(filePath)); + String current = null; + while ((current = bis.readLine()) != null && current.length() > 0) { + content.add(current); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return content.toArray(new String[content.size()]); + } + + public static int getNumOfTestCases(String[] content) { + // for code jam, it's in first line + assert content != null; + String numStr = content[0]; + return Integer.parseInt(numStr); + } + + public static String[] getAllTestCases(String[] content) { + assert content != null; + int len = content.length; + String[] testCases = new String[len - 1]; + for (int i = 0; i < len - 1; i++) { + testCases[i] = content[i + 1]; + } + return testCases; + } + + public static String formatTestResult(int index, String result) { + assert result != null; + return String.format(""Case #%1$d: %2$s"", index + 1, result); + } + + public static void writeTestResult(String fileName, String[] results) { + try { + FileWriter fstream = new FileWriter(fileName); + BufferedWriter out = new BufferedWriter(fstream); + for (String result : results) { + out.write(result + ""\n""); + } + out.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } + + public static long toNumber(String in) { + return Long.valueOf(in); + } + + public static long toNumber(char ch) { + return toNumber(Character.toString(ch)); + } + + public static char toChar(String in) { + char[] chars = in.toCharArray(); + if (chars.length <= 0) { + return 0; + } + return chars[0]; + } + + public static boolean isNumber(String in) { + try { + Integer.parseInt(in); + return true; + } catch (Exception e) { + return false; + } + } + + public static String join(char[] chars, String delimiter) { + int len = chars.length; + String[] strArr = new String[len]; + + for (int i = 0; i < len; i++) { + strArr[i] = Character.toString(chars[i]); + } + return join(strArr, delimiter); + } + + public static String join(String[] strs, String delimiter) { + int len = strs.length; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < len; i++) { + if (sb.length() > 0) { + sb.append(delimiter).append(strs[i]); + } else { + sb.append(strs[i]); + } + } + return ""["" + sb.toString() + ""]""; + } + + public static class Timer { + private static long timestamp = System.currentTimeMillis(); + + public static void start() { + Timer.timestamp = System.currentTimeMillis(); + } + + public static void stop() { + long current = System.currentTimeMillis(); + long pass = current - timestamp; + System.out.println(""total: "" + pass + "" ms""); + } + } + +} +" +A20195," +public class Dance { + JamInputReader ir; + + public Dance(String fileName) { + ir = new JamInputReader(fileName); + int t = ir.getNumItems(); + + for(int i = 0; i < t; i++) { + int n = ir.getNextInt(); + int s = ir.getNextInt(); + int p = ir.getNextInt(); + + int c = 0; + int l = p * 3 - 4; + + for(int j = 0; j < n; j++) { + int q = ir.getNextInt(); + + if(p < 2) { + if(q >= p) + c++; + } else { + if(q > l + 1) + c++; + else if(s > 0 && (q == l || q == l + 1)) { + s--; + c++; + } + } + } + + System.out.println(""Case #"" + (i + 1) + "": "" + c); + } + } + + public static void main(String[] args) { + new Dance(args[0]); + } +} +" +A22820,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.StringTokenizer; + + + +public class Main { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + //BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""c:\\input_B.txt""))); + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""c:\\input_B_Large.txt""))); + int cases = Integer.parseInt(reader.readLine()); + for(int i=0; i total_points_list = new ArrayList(); + for(int j=0; j= threshold) { + ++numOfPassed; + continue; + } + + switch(remainder) { + case 0: + if( (threshold - avg) == 1 && numOfSurprised > 0 && avg > 0) { + --numOfSurprised; + ++numOfPassed; + } + break; + case 1: + if( (threshold - avg) == 1) + ++numOfPassed; + break; + case 2: + if( (threshold - avg) == 1) + ++numOfPassed; + + if( (threshold - avg) == 2 && numOfSurprised > 0) { + --numOfSurprised; + ++numOfPassed; + } + break; + } + } + + System.out.println(""Case #""+(i+1)+"": ""+numOfPassed); + + + } + + } + +} +" +A20291,"import java.io.*; +import java.util.*; +public class GA +{ + public static void main(String args[]) throws Exception + { + InputReader sc=new InputReader(new FileInputStream(args[0])); + //InputReader sc=new InputReader(System.in); + int tc=sc.readInt(),i,j,p,n,s,t[],a,b,c,res=0; + for(i=1;i<=tc;i++){ + res=0; + n=sc.readInt();s=sc.readInt();p=sc.readInt();t=new int[n]; + for(j=0;j=p){res++;continue;} + if(b>0) if((a+1)>=p){res++;continue;} + if(s>0){ + if(b==0&&t[j]>0) if((a+1)>=p) {res++;s--;} + if(b==1) if((a+1)>=p) {res++;s--;} + if(b==2) if((a+2)>=p) {res++;s--;} + } + } + System.out.print(res+""\n""); + } + } +} + +class InputReader { + private boolean finished = false; + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + public int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int peek() { + if (numChars == -1) + return -1; + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + return -1; + } + if (numChars <= 0) + return -1; + } + return buf[curChar]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public long readLong() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + long res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + private boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + private String readLine0() { + StringBuffer buf = new StringBuffer(); + int c = read(); + while (c != '\n' && c != -1) { + if (c != '\r') + buf.appendCodePoint(c); + c = read(); + } + return buf.toString(); + } + + public String readLine() { + String s = readLine0(); + while (s.trim().length() == 0) + s = readLine0(); + return s; + } + + public String readLine(boolean ignoreEmptyLines) { + if (ignoreEmptyLines) + return readLine(); + else + return readLine0(); + } + + public char readCharacter() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + return (char) c; + } + + public double readDouble() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + double res = 0; + while (!isSpaceChar(c) && c != '.') { + if (c == 'e' || c == 'E') + return res * Math.pow(10, readInt()); + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } + if (c == '.') { + c = read(); + double m = 1; + while (!isSpaceChar(c)) { + if (c == 'e' || c == 'E') + return res * Math.pow(10, readInt()); + if (c < '0' || c > '9') + throw new InputMismatchException(); + m /= 10; + res += (c - '0') * m; + c = read(); + } + } + return res * sgn; + } + + public boolean isExhausted() { + int value; + while (isSpaceChar(value = peek()) && value != -1) + read(); + return value == -1; + } + + public String next() { + return readString(); + } +}" +A22326,"package code.jam; + +import java.io.*; +import java.util.*; + +public class CodeJam { + + public static void main(String[] args) throws FileNotFoundException, IOException { + + String name = ""B-small-attempt2""; + + Scanner in = new Scanner( new BufferedReader( new FileReader(name + "".in"") ) ); + BufferedWriter out = new BufferedWriter( new FileWriter(name + "".out"") ); + + int N = in.nextInt(); + + int num , n_surprise , best_result; + int surr_count , req_count; + boolean sol_found , looper; + int x , y , diff , temp; + int i,j,k = 1; + int[] results = null; + int[] arr = new int[3]; + + while( in.hasNext() ) + { + num = in.nextInt(); + n_surprise = in.nextInt(); + best_result = in.nextInt(); + results = new int[num]; + + for(i=0 ; i= best_result) || (y >= best_result) ) + { + req_count++; + looper = false; + sol_found = true; + } + else + y++; + } + else + y++; + + if( (y >= 10) || (y >= results[i]) ) + looper = false; + } + + if(!sol_found) + { + y = best_result; + temp = results[i]-y; + + if( (temp&1) == 0 ) + { + x = temp/2; + temp /= 2; + } + else + { + x = (temp/2)+1; + temp = results[i]-x-y; + } + + arr[0] = y; + arr[1] = x; + arr[2] = temp; + + Arrays.sort(arr); + + diff = Math.abs(arr[0]-arr[2]); + + if (diff == 2) + { + if(surr_count < n_surprise) + { + surr_count++; + req_count++; + } + } + } + } + + out.write(""Case #"" + k + "": "" + req_count); + out.newLine(); + k++; + } + + out.close(); + } + + //---------------------------------------------------------------------- + + public static int digitsCount(int num) + { + int count = 0; + + while(num > 0) + { + count++; + num = num/10; + } + + return count; + } + + //---------------------------------------------------------------------- + + public static void filterArray(boolean[] arr) + { + int length = arr.length-1; + + int i; + int temp = 0; + + + if( (length > 10) && (length <= 100) ) + { + temp = 11; + for(i=2 ; i<=10 && temp <= length ; i++) + { + arr[temp] = true; + temp = i*11; + } + } + + if( (length > 100) && (length <= 1000) ) + { + temp = 111; + for(i=2 ; i<=10 && temp <= length ; i++) + { + arr[temp] = true; + temp = i*111; + } + } + + if( (length > 1000) && (length <= 10000) ) + { + temp = 1111; + for(i=2 ; i<=10 && temp <= length ; i++) + { + arr[temp] = true; + temp = i*1111; + } + } + + if( (length > 10000) && (length <= 100000) ) + { + temp = 11111; + for(i=2 ; i<=10 && temp <= length; i++) + { + arr[temp] = true; + temp = i*11111; + } + } + + if( (length > 100000) && (length <= 1000000) ) + { + temp = 111111; + for(i=2 ; i<=10 && temp <= length ; i++) + { + arr[temp] = true; + temp = i*111111; + } + } + + if( (length > 1000000) && (length <= 2000000) ) + arr[1111111] = true; + } +} +" +A21362,"import java.io.*; +import java.util.*; +public class Dance { + + public static void main(String[] args) + { + Scanner scan = null; + PrintWriter outStream = null; + try + { + scan = new Scanner(new FileInputStream(""B-large.in"")); + outStream = new PrintWriter(new FileOutputStream(""c_out.txt"")); + }catch (FileNotFoundException e) + { + System.out.println(""File not found!""); + System.exit(0); + } + int lines = scan.nextInt(); + for(int i = 0;i= p) + { + ans++; + } + else if(score >= (3*p-4)) + { + if((score/3) == (p-1)) + { + if(p == 1) + { + if(score == 0) + continue; + else + { + ans++; + continue; + } + } + else if(p == 0) + { + ans++; + continue; + } + else if(score >= (3*p-2)) + { + ans++; + continue; + } + + } + if(surprise>0) + { + surprise--; + ans++; + } + } + + } + outStream.println(""Case #"" + (i+1) + "": "" + ans); + + } + outStream.close(); +} +} +" +A22045,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + + +public class Codejam2Test { + static BufferedReader stdin; + static BufferedWriter stdout; + ArrayList list; + + + public static void main(String[] args) throws IOException{ + // TODO Auto-generated method stub + String fName = new String(""B-large.in""); + String foName = new String(""B-large.out""); + stdin = new BufferedReader(new FileReader(fName)); + ArrayList list = new ArrayList(); + stdout = new BufferedWriter(new FileWriter(foName)); + int n = Integer.parseInt(stdin.readLine()); + + for (int i=0;i spaces = new ArrayList(); + ArrayList dancers = new ArrayList(); + for (int j = 0; j 3*p){ + answer++; + } else if (score >= minScoreWithoutSurprising && p>1){ + answer++; + } else if(score >= minScoreWithSurprising && S!=0 && p>1){ + answer++; + S--; + } else if(p==0){ + answer ++; + } else if (p == 1 && score > 0){ + answer++; + } + } + String out = new String(""Case #"" + (i+1) + "": "" + answer); + stdout.write(out); + stdout.newLine(); + } + stdout.close(); + } + + + public static ArrayList check(int t, ArrayList list){ + ArrayList newList = new ArrayList(); + for(int i =0; i0) { + int total = sc.nextInt(); + if (total < p) + continue; + total -= p; + if (total/2 + 1 >= p) + res++; + else if (total/2 + 2 >= p && S > 0) + { + S--; + res++; + } + } + return """"+res; + } +} +" +A23026,"public class Googler { + private int totalScore; + private int[] scores; + private boolean isWeird; // scores of the judge + + public Googler(int totalScore) { + scores = new int[3]; + this.totalScore = totalScore; + isWeird = false; + setMins(); + } + + private void setMins() { + int copyTotal = this.totalScore; + int i = 0; // start at first index + if (copyTotal == 0) { + this.scores[0] = 0; + this.scores[1] = 0; + this.scores[2] = 0; + } + while (copyTotal > 0) { + this.scores[i] = this.scores[i] + 1; // index 0 will have highest score + i = (i + 1) % 3; + copyTotal--; + } + } + + public boolean hasHighScore(int p) { + int i; + for (i = 0; i < 3; i++) { + if (this.scores[i] >= p) { + return true; + } + } + return false; + } + private boolean canBeWeird() { + if (this.totalScore <= 1 || this.totalScore > 27 || this.totalScore % 3 == 1) { + return false; + } + return true; + } + public boolean weirdHighScore(int p) { + if (canBeWeird() && this.scores[0] + 1 >= p) { + this.isWeird = true; + this.scores[0] = this.scores[0] + 1; + this.scores[1] = this.scores[1] - 1; + return true; + } else { + return false; + } + } + @Override + public String toString() { + String s = this.isWeird ? ""W"" : """"; + s = s + ""["" + this.scores[0] + "","" + this.scores[1] + "","" + this.scores[2] + ""] tot="" + this.totalScore; + return s; + } +} +" +A20372,"import java.util.*; + +public class DancingWithTheGooglers +{ + public static void main(String []args) + { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int i = 1; i <= T; i++) + { + System.out.print(""Case #"" + i + "": ""); + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int count = 0; + for(int j = 0; j < N; j++) + { + int t = in.nextInt(); + if(t >= 2 * Math.max(p - 1, 0) + p) count++; + else if(t >= 2 * Math.max(p - 2, 0) + p && S > 0) { count++; S--; } + } + System.out.print(count); + if(i < T) System.out.println(); + } + } +}" +A22603,"import java.util.*; + +public class B { + +public static void main(String[] args) + + { + Scanner in = new Scanner(System.in); + + int T = Integer.parseInt(in.nextLine()); + + for (int test = 0 ; test < T ; test ++) + { + + String input = in.nextLine(); + String[] bIn = input.split("" ""); + + int googlersNum = Integer.parseInt(bIn[0]); + int suprisingMax = Integer.parseInt(bIn[1]); + int requirement = Integer.parseInt(bIn[2]); + + int okay=0; + int suprising=0; + + for (int run = 0 ; run < googlersNum ; run ++) + { + + int S = Integer.parseInt(bIn[3+run]); + + int temp = S; + boolean testCase = false,done=false; + + + for (int i = 10 ; i >= 0 ; i--) + { + for (int j = i ; j >= i-1 && j >= 0; j--) + { + for (int k = i ; k >= i-1 && k >= 0; k --) + { + temp = temp - k - i - j; + + if (temp == 0) + { + + if ((i >= requirement || j >= requirement || k >= requirement) && !done) + { + okay++; + done = true; + } + + } + temp = S; + } + } + } + + temp = S; + + if (!testCase && suprising < suprisingMax) + { + for (int i = 10 ; i >= 0 ; i--) + { + for (int j = i ; j >= i-2 && j >= 0 ; j--) + { + for (int k = i ; k >= i-2 && k >= 0 ; k--) + { + temp = temp - i - k - j; + if (temp == 0) + { + if ((i >= requirement || j >= requirement || k >= requirement) && !done) + { + testCase = true; + suprising++; + okay++; + done = true; + } + + } + temp = S; + + } + } + } + } + } + + System.out.println(""Case #""+(test+1)+"": ""+okay); + } + + in.close(); + } + +} + + " +A21734," + +import java.io.*; + +class ProblemB +{ + + + + public static void main(String[] args) throws IOException + { + FileReader fr = new FileReader(args[0]); + BufferedReader br = new BufferedReader(fr); + String[] splittArray; + int[] points; + int N,S,p,res; + int T = Integer.parseInt(br.readLine()); + //System.out.println(T); + + String dummy; + String result=""""; + for(int i=1;i<=T;i++) { + dummy=br.readLine(); + splittArray=dummy.split("" ""); + N=Integer.parseInt(splittArray[0]); + S=Integer.parseInt(splittArray[1]); + p=Integer.parseInt(splittArray[2]); + res=0; + points=new int[N]; + for(int j=3;j=3*p-2) { + res++; + } else if(points[j]<3*p-2 && points[j]>=3*p-4 && 3*p-4>=0 && S>0) { + S--; + res++; + } + + } + result+=""Case #""+i+"": ""+res; + if(i0) + max++; + } + } + else{ + for (int j = 0; j < sums.length; j++) { + if(sums[j]>=3*p-2) + max++; + else if(sums[j]>=3*p-4 && S>0) + { + max++; + S--; + } + + } + } + + + System.out.println(""Case #""+(i+1)+"": ""+max); + } + pw.flush(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} +" +A22605,"package gcj2012.qr; + +import java.io.*; +import java.util.StringTokenizer; + +/** + * + * @author Scott DellaTorre + */ +public class B { + + public static void main(String[] args) throws IOException { + + BufferedReader in = new BufferedReader(new FileReader(""src/gcj2012/qr/in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""src/gcj2012/qr/B.out""))); + + int T = Integer.parseInt(in.readLine()); + for (int i = 0; i < T; i++) { + StringTokenizer st = new StringTokenizer(in.readLine()); + int N = Integer.parseInt(st.nextToken()); // Number of Googlers + int S = Integer.parseInt(st.nextToken()); // Number of suprising cases + int p = Integer.parseInt(st.nextToken()); + int[] t = new int[N]; // Total points of the Googlers + for (int j = 0; j < N; j++) { + t[j] = Integer.parseInt(st.nextToken()); + } + + // What is the maximum number of Googlers that could have had a best + // result of at least p? + + int lowSurprising = p < 2 ? p : p * 3 - 4; + int lowNormal = p < 1 ? p : p * 3 - 2; + + int count = 0; + for (int j = 0; j < N; j++) { + if (t[j] >= lowNormal) { + count++; + } else if (S > 0 && t[j] >= lowSurprising) { + S--; + count++; + } + } + + out.println(""Case #"" + (i + 1) + "": "" + count); + } + + out.close(); + } +} +" +A22765,"package org.sooo; + +import java.io.File; +import java.io.OutputStreamWriter; +import java.util.List; + +import com.google.common.base.Charsets; +import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; +import com.google.common.io.CharStreams; +import com.google.common.io.Files; +import com.google.common.io.OutputSupplier; + +public class DancingWithTheGooglers { + + class TripletScore { + int a; + int b; + int c; + + public TripletScore(int a, int b, int c) { + this.a = a; + this.b = b; + this.c = c; + } + + public boolean isSatisfied(int pointRequired) { + if (c >= pointRequired) + return true; + else + return false; + } + + public boolean satisfiedIfSurprised(int pointRequired) { + if (isSatisfied(pointRequired)) + return false; + if (c == 0) + return false; + + if (pointRequired - c == 1 && (a + b) >= 1) + return true; + else + return false; + } + + @Override + public String toString() { + return String.format(""(%d, %d, %d)"", a, b, c); + } + } + + public static void main(String[] args) throws Exception { + String inputFilePath = ""src/main/resources/B-large.in""; + //String inputFilePath = ""src/main/resources/B-sample.in""; + OutputSupplier outputSupplier = Files + .newWriterSupplier(new File(inputFilePath + "".out""), + Charsets.UTF_8); + List lines = Files.readLines(new File(inputFilePath), + Charsets.UTF_8); + StringBuilder results = new StringBuilder(); + for (int i = 1; i < lines.size(); i++) { + List fromList = Lists.newArrayList(Splitter.on(' ').split( + lines.get(i))); + List info = Lists.transform(fromList, + new Function() { + public Integer apply(String input) { + return Integer.parseInt(input); + } + }); + int numSurprise = info.get(1); + int pointRequired = info.get(2); + int numSatisfied = 0; + for (int j = 3; j < info.size(); j++) { + int totalScore = info.get(j); + int avg = totalScore / 3; + TripletScore ts; + if (avg * 3 == totalScore) { + ts = new DancingWithTheGooglers().new TripletScore(avg, + avg, avg); + } else { + if (totalScore - (avg * 3) == 1) + ts = new DancingWithTheGooglers().new TripletScore(avg, + avg, avg + 1); + else + ts = new DancingWithTheGooglers().new TripletScore(avg, + avg + 1, avg + 1); + } + if (ts.isSatisfied(pointRequired)) + numSatisfied++; + else { + if (numSurprise > 0 + && ts.satisfiedIfSurprised(pointRequired)) { + numSurprise--; + numSatisfied++; + } + } + } + String result = String.format(""Case #%d: %d\n"", i, numSatisfied); + System.out.printf(result); + results.append(result); + } + CharStreams.write(results, outputSupplier); + } +} +" +A22224,"package google.codejam2012.awanish; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Scanner; +import java.util.StringTokenizer; + +public class GooglersDance { + private static int count = 0; + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + Scanner inputScan = new Scanner(System.in); + int noOfCases = Integer.parseInt(inputScan.nextLine()); + String cases; + int noOfGooglers; + int noOfSurprisingTrip; + int topScore; + + for (int i = 1; i <= noOfCases; i++) { + cases = inputScan.nextLine(); + count = 0; + ArrayList totalScores = new ArrayList(); + StringTokenizer st = new StringTokenizer(cases, "" ""); + noOfGooglers = Integer.parseInt(st.nextToken()); + noOfSurprisingTrip = Integer.parseInt(st.nextToken()); + topScore = Integer.parseInt(st.nextToken()); + while (st.hasMoreTokens()) { + totalScores.add(st.nextToken()); + } + int total; + int triplet; + int remainder; + ArrayList triplets; + ArrayList> dancers = new ArrayList>(); + int c = 0; + for (Object t : totalScores) { + triplets = new ArrayList(); + total = Integer.parseInt(t.toString()); + triplet = total / 3; + remainder = total % 3; + triplets.add(triplet); + if (remainder == 2) { + triplets.add(triplet + 1); + triplets.add(total - (triplet * 2 + 1)); + } else { + triplets.add(triplet); + triplets.add(total - triplet * 2); + } + dancers.add(triplets); + } +// System.out.println(dancers); + + analyzeSurprises(dancers, noOfSurprisingTrip, topScore); + + System.out.println(""Case #"" + i + "": "" + count); + + } + + } + + private static void analyzeSurprises(ArrayList> dancers, + int noOfSurprisingTrip, int topScore) { + // TODO Auto-generated method stub + + for (ArrayList list : dancers) { + + if (max(list) >= topScore) { + count++; + } else if (noOfSurprisingTrip > 0 && checkForSurprise(list,topScore)) { + noOfSurprisingTrip--; + count++; + + } + } + + } + + private static boolean checkForSurprise(ArrayList list, int topScore) { + // TODO Auto-generated method stub + int topScoreCount = 0; + for (Number n : list) { + if (n.intValue()==topScore-1){ + topScoreCount++; + } + } + if (topScoreCount>=2 && topScore!=1) + { + return true; + } + + return false; + } + + private static int max(ArrayList list) { + // TODO Auto-generated method stub + int max = 0; + for (Number n : list) { + if (n.intValue() > max) { + max = n.intValue(); + } + } + return max; + } + +} +" +A22561,"import java.util.*; + +public class b { + static int n,s,p; + static int[] v; + static int[][] memo; + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int t=1; t<=T; t++) { + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + v = new int[n]; + for(int i=0; i= p) win = 1; + best = Math.max(best,win+go(pos+1,left-sup)); + } + return memo[pos][left] = best; + } +}" +A20083,"import java.lang.*; +import java.util.*; +import java.io.*; +class codejam2 +{ + public static boolean check(int[] ar){ + if(ar[2]-ar[1]<3 && ar[2]-ar[0]<3 && ar[0]>=0) return true; + else return false; + } + + public static boolean sur(int[] ar){ + if(ar[2]-ar[0]==2) return true; + else return false; + } + + public static int mainHelper(int n1,int s1,int p1,int[] p2){ + int n=n1; + int s=s1; + int p=p1; + int ans=0; + int[] points=p2; + int[][] a =new int[n+1][3]; + for(int i=1;i<=n;i++){ + for(int j=0;j<3;j++){ + a[i][j]=points[i]/3; + } + if(points[i]%3==1) a[i][2]+=1; + else if(points[i]%3==2){ + a[i][2]+=1; + a[i][1]+=1; + } + + } + java.util.Arrays.sort(a[1]); + for(int i=1;i<=n;i++){ + while(check(a[i])){ + if(a[i][2]>= p){ + if(sur(a[i])){ + if(s>0){ s-=1; ans+=1;} + } + else ans+=1; + break; + } + else{ + int[] temp=a[i]; + temp[2]+=1; + temp[1]-=1; + java.util.Arrays.sort(temp); + if(check(temp)) a[i]=temp; + else break; + + } + } + } + return ans; + + } + + public static void main(String[] args) + { + //N S p .......3 1 5 15 13 11 + try{ + BufferedReader in=new BufferedReader(new FileReader(""input2.txt"")); + BufferedWriter out=new BufferedWriter(new FileWriter(""output2.txt"")); + int z=Integer.parseInt(in.readLine()); + for(int j=0;j= p * 3) { + ++count; + continue; + } + if (t < p) { + continue; + } + int diff = (t - p) / 2; + if (p - diff <= 1) { + ++count; + continue; + } + if (p - diff == 2 && s > 0) { + --s; + ++count; + } + } + return count; + } + +} +" +A20093,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlecodejam; + +import java.io.FileNotFoundException; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Pattern; + +/** + * + * @author Tobi + */ +public class GoogleCodeJam { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int T = s.nextInt(); + for(int t = 1; t <= T; t++) { + int N = s.nextInt(); //number of googlers + int S = s.nextInt(); //number of surprising results + int p = s.nextInt(); //number of target-best result + int[] points = new int[N]; + for(int i = 0; i < N; i++) + points[i] = s.nextInt(); + + int matches = 0; + for(int i = 0; i < N; i++) { + if((points[i] / 3) + 2 < p) //skip results that are too low + continue; + int a = points[i] / 3; + int b = (points[i] - a) / 2; + int c = (points[i] - a - b); + int max = Math.max(Math.max(a, b), c); + int delta = Math.max(Math.max(Math.abs(b - c), Math.abs(a - b)), Math.abs(a - c)); + + if(max >= p) { + if(delta == 2 && S > 0) { //enough points, but surprising, surprises left? + S--; + matches++; + continue; + } else if (delta < 2) { //enough points, no surprise + matches++; + continue; + } + } + + if((max + 1 >= p) && (delta < 2)) { + if((S > 0) && (delta == 0) && max > 0) { //can shift one point up and one down -> delta == 2 -> surprise left? + S--; + matches++; + } else if (S > 0 && delta == 1 && ((a == b && a == max) || (a == c && a == max) || (b == c && b == max))) { //can shift one point up, one down, but delta + S--; + matches++; + } + } + } + System.out.println(""Case #"" + t + "": "" + matches); + } + } +} +" +A23085,"package codejam2012.util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author fedez + */ +public class ReadWriteUtil +{ + private static Logger logger = Logger.getLogger(ReadWriteUtil.class.getName()); + + /** + * Read a file from a location + * @param fileName + * @return + * @throws java.io.IOException + */ + public static List readFile(String fileName) throws IOException + { + BufferedReader br = null; + List in = null; + String line; + + try + { + br = new BufferedReader(new FileReader(fileName)); + in = new ArrayList(); + while ((line = br.readLine()) != null) + { + in.add(line); + } + } + catch (FileNotFoundException ex) + { + logger.log(Level.SEVERE, null, ex); + } + finally + { + if (br != null) + { + br.close(); + } + } + return in; + } + + /** + * Write a file to location + * @param fileName + * @param content + * @throws java.io.IOException + */ + public static void writeFile(String fileName, List content) throws IOException + { + BufferedWriter bw = null; + try + { + bw = new BufferedWriter(new FileWriter(fileName)); + for (String line : content) + { + bw.write(line); + bw.write(System.getProperty(""line.separator"")); + } + } + catch (IOException ex) + { + logger.log(Level.SEVERE, null, ex); + } + finally + { + if (bw != null) + { + bw.close(); + } + } + } +}" +A21425,"/* + * @author Magix.Lu + */ + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Dancing { + + public static void main(String[] args) throws IOException { + + int count = 0; + int special = 0; + int googler = 0; + int best = 0; + int sp_co = 0; + int sat = 0; + + Scanner scanInput = new Scanner(System.in); + String target = scanInput.next(); + + File inputFile = new File(target); + Scanner fileScan = new Scanner(inputFile); + + String outpFileName = ""output.txt""; + FileWriter googlewriter = null; + googlewriter = new FileWriter(outpFileName); + + PrintWriter diskFile = new PrintWriter(googlewriter); + + count = fileScan.nextInt(); + + for (int i = 0; i < count; i++) { + googler = fileScan.nextInt(); + special = fileScan.nextInt(); + best = fileScan.nextInt(); + sp_co = 0; + sat = 0; + + int[][] scores = new int[googler][3]; + int[] totscores = new int[googler]; + + for (int j = 0; j < googler; j++) + totscores[j] = fileScan.nextInt(); + + for (int j = 0; j < googler; j++) { + scores[j][0] = totscores[j] / 3; + scores[j][1] = totscores[j] / 3; + scores[j][2] = totscores[j] / 3; + } + + for (int j = 0; j < googler; j++) { + if (scores[j][0] + scores[j][1] + scores[j][2] != totscores[j]) { + if (totscores[j] - scores[j][0] - scores[j][1] + - scores[j][2] == 2) { + scores[j][0]++; + scores[j][2]++; + } + if (totscores[j] - scores[j][0] - scores[j][1] + - scores[j][2] == 1) { + scores[j][0]++; + } + } + } + + for (int m = 0; m < googler; m++) { + if (scores[m][0] >= best || scores[m][1] >= best + || scores[m][2] >= best) { + } else if (sp_co < special && scores[m][0] != 0 + && scores[m][0] + 1 == best) { + scores[m][0]--; + scores[m][2]++; + sp_co++; + } + } + + for (int m = 0; m < googler; m++) { + if (scores[m][0] >= best || scores[m][1] >= best + || scores[m][2] >= best) + sat++; + } + + diskFile.print(""Case #"" + (i + 1) + "": "" + sat + ""\n""); + + } + + diskFile.close(); + + } // end of main + +} // end of class +" +A22913,"package actual; +import java.io.*; +import java.util.*; + +public class B +{ + String line; + StringTokenizer inputParser; + BufferedReader is; + FileInputStream fstream; + DataInputStream in; + + void openInput(String file) + { + + //is = new BufferedReader(new InputStreamReader(System.in));//stdin + try{ + fstream = new FileInputStream(file); + in = new DataInputStream(fstream); + is = new BufferedReader(new InputStreamReader(in)); + }catch(Exception e) + { + System.err.println(e); + } + + } + + void readNextLine() + { + try { + line = is.readLine(); + inputParser = new StringTokenizer(line, "" ""); + //System.err.println(""Input: "" + line); + } catch (IOException e) { + System.err.println(""Unexpected IO ERROR: "" + e); + } + + } + + int NextInt() + { + String n = inputParser.nextToken(); + int val = Integer.parseInt(n); + + //System.out.println(""I read this number: "" + val); + return val; + } + + String NextString() + { + String n = inputParser.nextToken(); + return n; + } + + void closeInput() + { + try { + is.close(); + } catch (IOException e) { + System.err.println(""Unexpected IO ERROR: "" + e); + } + + } + + public static void main(String [] argv) + { + new B(argv[0]); + } + + public B(String inputFile) + { + openInput(inputFile); + readNextLine(); + + int TC = NextInt(); + + for(int t=0; t0)ret++; + } + else + { + if(b>=(p*3-2))ret++; + else if(b>=(p*3-4))sup++; + } + } + ret+=Math.min(S, sup); + + System.out.println(""Case #""+(t+1)+"": ""+ret); + } + closeInput(); + } + + +} + +" +A21115,"import java.io.*; +import java.util.*; + +public class jam2 { + + /** + * @param args + */ + static int chuli(String in) + { + String[] ss = in.split("" ""); + int n = Integer.parseInt(ss[0]); + int s = Integer.parseInt(ss[1]); + int p = Integer.parseInt(ss[2]); + + ArrayList ar = new ArrayList(); + ArrayList sy = new ArrayList(); + ArrayList sn = new ArrayList(); + + for(int i=0;i=p) + { + map[ni][0]+=1; + } + //System.out.println(map[ni][0]); + //System.out.println(""---""); + } + + for(int ni = 1;ni<=n;ni++) + { + for(int si=1;si<=s;si++) + { + if(ar.get(ni-1)<2) + { + map[ni][si]=map[ni-1][si]+(sn.get(ni-1)>=p?1:0); + } + else + { + int s1 = map[ni-1][si]+(sn.get(ni-1)>=p?1:0); + int s2 = map[ni-1][si-1]+(sy.get(ni-1)>=p?1:0); + map[ni][si]=s1>s2?s1:s2; + } + } + } + /* + System.out.println(""###""); + for(int ni = 0;ni<=n;ni++) + { + for(int si=0;si<=s;si++) + { + System.out.print(map[ni][si]); + System.out.print("" ""); + } + System.out.println(); + } + System.out.println(""###""); + */ + return map[n][s]; + } + public static void main(String[] args) { + // TODO Auto-generated method stub + try{ + /* + System.out.println(chuli(""3 1 5 15 13 11"")); + + System.out.println(chuli(""3 0 8 23 22 21"")); + + System.out.println(chuli(""2 1 1 8 0"")); + + System.out.println(chuli(""6 2 8 29 20 8 18 18 21"")); + + */ + File fin1 = new File(""d:\\B-large.in""); + FileInputStream fs1 = new FileInputStream(fin1); + BufferedReader br1 = new BufferedReader(new InputStreamReader(fs1)); + + File fout6 = new File(""d:\\cjamout1""); + FileOutputStream fos6 = new FileOutputStream(fout6); + BufferedWriter wr6 = new BufferedWriter(new OutputStreamWriter(fos6)); + + String line = br1.readLine(); + int n = 1; + line = br1.readLine(); + while(line!=null) + { + if(!line.trim().equals("""")) + { + wr6.write(""Case #""+String.valueOf(n++)+"": ""+String.valueOf(chuli(line))); + wr6.newLine(); + } + line = br1.readLine(); + + } + br1.close(); + fs1.close(); + + wr6.close(); + fos6.close(); + + } + catch(Exception e) + { + e.printStackTrace(); + } + } + +} +" +A22625,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlecodejam; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +/** + * + * @author massimo + */ +public class ProblemB { + + //It can be proven that b=min{10,2+floor((totalPoints-2)/3)),totalPoints} if the best possibile result. + //The triple must be surprising iff totalPoints<=3*(b-1). + public static void main(String[] args) throws FileNotFoundException, IOException { + BufferedReader in = new BufferedReader(new FileReader(""in.in"")); + PrintWriter out = new PrintWriter(""out.out""); + int t = Integer.parseInt(in.readLine()); + for (int i = 1; i <= t; i++) { + StringTokenizer st = new StringTokenizer(in.readLine(), "" ""); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int res = 0, surprising = 0; + for (int j = 0; j < n; j++) { + int totalPoints = Integer.parseInt(st.nextToken()); + int b = Math.min(Math.min(totalPoints, 10), 2 + (totalPoints - 2) / 3); + if (b > p) { + res++; + } else if (b == p) { + if (totalPoints>3*(b-1)) { + res++; + } else if (surprising 0){ + max2=2; + } + if(max2 >= p){ + s--; + } + } + else if(x%3 == 0){ + max1 = x/3; + if(s > 0 && max1= p){ + s--; + } + + } + } + else if(x%3 == 1){ + max1 = x/3 + 1; + } + else{ + max1 = x/3 + 1; + if(s > 0 && (x/3 + 2) <= 10 && max1= p){ + s--; + } + } + } + if(max1>=p || max2>=p){ + y++; + } + } + + return y; + } + + + + public String[] readFromFile(String inputPath) throws FileNotFoundException,IOException { + FileInputStream fis = null; + DataInputStream dis = null; + BufferedReader br = null; + ArrayList strArrList = new ArrayList(); + try{ + fis = new FileInputStream(inputPath); + dis = new DataInputStream(fis); + br = new BufferedReader(new InputStreamReader(dis)); + String strLine; + while ((strLine = br.readLine()) != null) { + strArrList.add(strLine); + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally{ + try{ + if (br != null) { + br.close(); + } + if (dis != null) { + dis.close(); + } + if (fis != null) { + fis.close(); + } + } catch(IOException e) { + e.printStackTrace(); + } + } + return strArrList.toArray(new String[strArrList.size()]); + } + + public void writeToFile(String outputPath, String[] strArr) { + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(outputPath)); + + for(int i=0; i= firstChk) { + total++; + continue; + } + else if((tPoints[i] >= scdChk) && (s > 0)) { + total++; + s--; + continue; + } + } + + return total; + } + +} +" +A22666,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class EN2012QB { + public static void main(String[] args) { + File inputFile = new File(""c:/tmp/B-large.in""); + File outputFile = new File(""c:/tmp/B-large.out""); + + char map[] = new char[256]; + boolean mapped[] = new boolean[256]; + + FileReader filereader = null; + BufferedReader br = null; + FileWriter filewriter = null; + BufferedWriter bw = null; + + try { + // 入力 + filereader = new FileReader(inputFile); + br = new BufferedReader(filereader); + + // 出力 + filewriter = new FileWriter(outputFile); + bw = new BufferedWriter(filewriter); + + /************************************************************************************** + // 全体パラメータの読み込み + **************************************************************************************/ + int T; + + // テストケースの個数 + String lineStr = br.readLine(); + T = Integer.parseInt(lineStr); + System.out.println(""T = "" + T + ""\n""); + + /************************************************************************************** + // Caseを1つづつ処理 + **************************************************************************************/ + long caseIndex = 1; + while ((lineStr = br.readLine()) != null) { + /************************************************************************************** + // Caseを処理 + **************************************************************************************/ + + String E[] = lineStr.split("" ""); + System.out.println(lineStr); + int N = Integer.parseInt(E[0]); + System.out.println(""N = "" + N); + + int S = Integer.parseInt(E[1]); + System.out.println(""S = "" + S); + + int p = Integer.parseInt(E[2]); + System.out.println(""p = "" + p); + + int totalPoints[] = new int[N]; + + for(int i=0; i= p + && totalPoints[i] >= notSurprisingThreshold){ + notSurprisingCount++; + } + + // 少なくとも1つはp以上であるため、大前提として合計値はpより大きくないといけない + // 最大のスコアと最小のスコアの差分が2であるから、合計は28以下となる + if(totalPoints[i] >= p + && totalPoints[i] <= 28 + && totalPoints[i] >= SurprisingThreshold + && totalPoints[i] < notSurprisingThreshold){ + SurprisingCount++; + } + } + + System.out.println(""Not Surprising = "" + notSurprisingCount + "", Surprising = "" + SurprisingCount); + + // surprisingでないとクリアできていない組は、SurprisingCount 組ある。 + // このうち、実際はS組が surprisingである + int caseAnser = notSurprisingCount + Math.min(S, SurprisingCount); + + /************************************************************************************** + // Caseを出力 + **************************************************************************************/ + String output = ""Case #"" + caseIndex + "": "" + caseAnser; + caseIndex++; + System.out.println(output); + bw.write(output); + bw.newLine(); + } + /************************************************************************************** + // 次のCaseの読み込み + **************************************************************************************/ + lineStr = br.readLine(); + System.out.println(); + + bw.flush(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (br != null) { + br.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + try { + if (filereader != null) { + filereader.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + try { + if (bw != null) { + bw.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + try { + if (filewriter != null) { + filewriter.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 文字列からマッチする文字列数を求める + */ + private static int countChar(String str, int ch){ + int count = 0; + int i = 0; + while ((i = str.indexOf(ch, i)) != -1) { + count++; + i++; + } + return count; + } +} +" +A22930," +import java.io.BufferedInputStream; +import java.util.Scanner; + +public class ProblemB { + + public static void main(final String[] args) { + Scanner scanner = new Scanner(new BufferedInputStream(System.in)); + + int T = scanner.nextInt(); + + for(int i = 0; i < T; i++) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int res = 0; + + for(int j = 0; j < N; j++) { + double t = (double)(scanner.nextInt()); + + if(t >= 0) { + if(t/3 >= p) res++; + else if(t >= 1) { + if((t-1)/3 + 1 >= p) res++; + else if(t >= 2) { + if((t-2)/3 + 1 >= p) res++; + else if((t-2)/3 + 2 >= p && S > 0) {res++; S--;} + else if(t >= 3) { + if((t-3)/3 + 2 >= p && S > 0) {res++; S--;} + else if(t >= 4 && (t-4)/3 + 2 >= p && S > 0) {res++; S--;} + } + } + } + } + } + + System.out.println(""Case #""+(i+1)+"": ""+res); + } + + } + +} +" +A21903,"import java.util.*; +import java.io.*; + + +public class Dance { + public static void main(String args[]) throws Exception + { + BufferedReader in = new BufferedReader(new FileReader(new File(""dance.in""))); + FileWriter out = new FileWriter(new File(""dance.out"")); + + int n = Integer.parseInt(in.readLine()); + for (int i = 1; i <= n; i++) { + String s = in.readLine(); + StringTokenizer st = new StringTokenizer(s); + + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + + int max = 0; + for (int j = 0; j < N; j++) + { + int g = Integer.parseInt(st.nextToken()); + if (g < 2) { + if (g >= p) max++; + } + else if ((g + 2) / 3 >= p) max++; + else if ((g+4) / 3 >= p && S > 0) { + S--; + max++; + } + } + + + out.write(""Case #"" + i + "": "" + max + ""\n""); + } + in.close(); + out.close(); + + } +} +" +A21978,"package qual; + +import java.util.Arrays; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + new DancingWithTheGooglers().run(); + } + + private void run() { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int testcase = 0; testcase < T; testcase++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[N]; + for (int i = 0; i < N; i++) { + t[i] = sc.nextInt(); + } + int result = solve(N, S, p, t); + System.out.printf(""Case #%d: %d\n"", testcase + 1, result); + } + } + + /** + * + * @param N the number of Googlers + * @param S the number of surprising triplets of scores + * @param p + * @param t + * @return + */ + public int solve(int N, int S, int p, int[] t) { + int result = 0; + Arrays.sort(t); + for (int i = N - 1; i >= 0; i--) { + int b = (t[i] + 2) / 3; + if (b >= p) { + result++; +// System.out.printf(""(1) %d : %d\n"", t[i], b); + } else if (t[i] > 1 && S > 0 && b == p - 1 && ((t[i] - 1) % 3) != 0) { + result++; + S--; +// System.out.printf(""(2) %d : %d (S=%d)\n"", t[i], b, S); + } + } + return result; + } + +} +" +A21630,"package gcj; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.TreeSet; + +import java.util.Iterator; + +public class Jam2012 { + //-10^9 < Integer.MAX_VALUE (2^31) < 10^10 + //-10^18 < Long.MAX_VALUE (2^63) < 10^20 + + + public static void main(String[] args) throws NumberFormatException, IOException { + Scanner sc = new Scanner(new FileReader(filename+"".in"")); + String output; + String outputfile = filename + "".out""; + + FileOutputStream Output = new FileOutputStream(outputfile); + PrintStream file2 = new PrintStream(Output); + + boolean after25 = false; + boolean after50 = false; + boolean after75 = false; + + int T = sc.nextInt(); + //int T = Integer.parseInt(sc.nextLine()); + System.out.println(Calendar.getInstance().getTime()+"" - Started writing to: ""+outputfile); + + + //getPrimesH(); + for (int i = 0; i < T; i++) { + + //ArrayList orders = new ArrayList(); + //ArrayList v2 = new ArrayList(); + ArrayList googlers = new ArrayList(); + + //StringTokenizer st = new StringTokenizer(br.readLine(),"" ""); + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + for (int j = 0; j< n; j++) { + googlers.add(sc.nextInt()); + } + + output = solve(n,s,p,googlers); + + file2.println(""Case #"" + (i+1) + "": ""+output); + if ((100*(i+1)/T >= 25) && (!after25)) { + System.out.println(Calendar.getInstance().getTime()+"" - 25% done""); after25 = true; + } else if ((100*(i+1)/T >= 50) && (!after50)) { + System.out.println(Calendar.getInstance().getTime()+"" - 50% done""); after50 = true; + } else if ((100*(i+1)/T >= 75) && (!after75)) { + System.out.println(Calendar.getInstance().getTime()+"" - 75% done""); after75 = true; + } + } + sc.close(); System.out.println(Calendar.getInstance().getTime()+"" - Finished writing to: ""+outputfile); + } + /* + private static String solve(String nextLine) { + char[] a = {'f','g','d','e','b','c','a','n','o','l','m','j','k','h','i','w','v','u','t','s','r','q','p','z','y','x'}; + char[] b = {'c','v','s','o','h','e','y','b','k','g','l','u','i','x','d','f','p','j','w','n','t','z','r','q','a','m'}; + HashMap lib = new HashMap(); + for (int i = 0; i< a.length; i++) { + if(!lib.containsKey(a[i])) { + lib.put(a[i], b[i]); + } + } + + StringBuilder out = new StringBuilder(); + for (int i = 0; i< nextLine.length(); i++) { + if (nextLine.charAt(i) == ' ') {out.append(' ');} else { + out.append(lib.get(nextLine.charAt(i)));} + } + return out.toString(); + }*/ + + /* + private static String solve(int a, int b) { + int length = String.valueOf(b).length(); + if (length == 1) { + return ""0""; + } + HashSet found = null; + long total = 0; + for (int i = a; i < b; i++) { + found = null; + String s = String.valueOf(i); + StringBuilder sb = new StringBuilder(); + for (int j = 0; j < s.length(); j++) { + sb.append(s.charAt((j+s.length()-1)%s.length())); + } + int shift = Integer.parseInt(sb.toString()); + for (int j = 1; j < length; j++) { + + if (shift > i && shift <= b) { + if (found == null) { + found = new HashSet(); + } + if (!found.contains(shift)) { + found.add(shift); + //System.out.println(i+"",""+shift); + total++; + } + } + + //s = String.valueOf(shift); + sb = new StringBuilder(); + for (int k = 0; k < s.length(); k++) { + sb.append(s.charAt((k+s.length()-(1+j))%s.length())); + } + shift = Integer.parseInt(sb.toString()); + } + } + return String.valueOf(total); + }*/ + + private static String solve(int n, int s, int p, ArrayList googlers) { + int max= 0; + Collections.sort(googlers); + Collections.reverse(googlers); + int pmin = (3*p-4 >= 1) ? (3*p-4) : 1; + int pmax = (3*p-2 >= 1) ? (3*p-2) : 1; + for (int j = 0; j< n; j++) { + /*if ((googlers.get(j)+2)/3 >= p) { + max++; + } else if (((googlers.get(j)+4)/3 >= p) && (s > 0)) { + s--; + max++; + }*/ + if (p == 0) { + max++; + } else if ((googlers.get(j)) >= pmax) { + max++; + } else if (((googlers.get(j)) >= pmin) && (s > 0)) { + s--; + max++; + } + } + + return String.valueOf(max); + } + + //static String size = ""sample""; + //static String size = ""small""; + //static String size = ""large""= + static String filename = ""D:\\gcj\\2012\\Q\\B-large""; +} +" +A21962,"import java.io.*; +import java.util.*; + +public class DancingGooglers { + public static void main(String args[]) { + try { + String strFileName = args[0]; + BufferedReader bfReader = new BufferedReader(new FileReader(strFileName)); + long nTestCases = Integer.parseInt(bfReader.readLine()); + + for(int testCaseCounter=0;testCaseCounter=p)&&(t[i]==p1||t[i]==p2)) + s++; + else if((t[i]>=p)&&(t[i]>=px)) + ret++; + } + + if(s<=S) + ret+=s; + else + ret+=S; + System.out.println(""Case #"" + (testCaseCounter+1) + "": "" + ret); + } + + } + catch(FileNotFoundException e) { + System.out.println(e.getMessage()); + } + catch(IOException e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } +} +" +A21142,"import java.io.FileReader; +import java.util.Scanner; + + +public class Scores { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + try { + scan = new Scanner(new FileReader(""B-large.in"")); + } catch (Exception e) { + System.out.println(""poop""); + } + int inputSize = Integer.parseInt(scan.nextLine()); + int i = 0; + while (scan.hasNextLine() && i < inputSize) { + i++; + String line = scan.nextLine(); + String[] strings = line.split("" ""); + int googlers = Integer.parseInt(strings[0]); + int surprises = Integer.parseInt(strings[1]); + int atLeast = Integer.parseInt(strings[2]); + int j = 0; + int output = 0; + int surprisesSoFar = 0; + for (String s : strings) { + if (j > 2) { + int total = Integer.parseInt(s); + if (total == 0) { + if (atLeast == 0) output++; + } else if (atLeast + atLeast + atLeast - 2 <= total) { + output++; + } else if ((surprisesSoFar < surprises) && + atLeast + atLeast + atLeast -4 <= total) { + output++; + surprisesSoFar++; + } + } + j++; + } +// System.out.println(line); + System.out.println(""Case #"" + i + "": "" + output); + } + } +} +" +A21969,"package com.renoux.gael.codejam.utils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.net.URISyntaxException; +import java.net.URL; + + +/** + * Pour tests unitaires + * + * @author renouxg + */ +public final class FileUtils { + + public static File fromWorkspace(String path) throws URISyntaxException { + ClassLoader.getSystemResource(path); + URL url = FileUtils.class.getClassLoader().getResource(path); + return new File(url.toURI()); + } + + public static BufferedReader getReader(File file) throws FileNotFoundException { + FileInputStream fis = new FileInputStream(file); + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + return br; + } + +} +" +A21952,"package qr1; + +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +import static junit.framework.Assert.assertEquals; + +/** + * Created with IntelliJ IDEA. + * User: shtratos + * Date: 14/04/12 + * Time: 04:28 + */ +public class DancingGooglers { + + + public static void main(String[] args) { + + DancingGooglers dg = new DancingGooglers(); + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); + int numOfTests = Integer.valueOf(br.readLine()); + for (int i = 0; i < numOfTests; i++) { + System.out.println(""Case #"" + (i + 1) + "": "" + dg.parseAndCalc(br.readLine())); + } + } catch (Exception e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + @Test + public void testExamples() { + DancingGooglers dg = new DancingGooglers(); + + assertEquals(3, dg.parseAndCalc(""3 1 5 15 13 11"")); + assertEquals(2, dg.parseAndCalc(""3 0 8 23 22 21"")); + assertEquals(1, dg.parseAndCalc(""2 1 1 8 0"")); + assertEquals(1, dg.parseAndCalc(""2 1 2 8 1"")); + assertEquals(2, dg.parseAndCalc(""2 1 2 8 2"")); + assertEquals(1, dg.parseAndCalc(""2 0 2 8 2"")); + assertEquals(1, dg.parseAndCalc(""1 0 0 26"")); + assertEquals(0, dg.parseAndCalc(""1 0 10 26"")); + assertEquals(0, dg.parseAndCalc(""2 0 5 5 11"")); + assertEquals(0, dg.parseAndCalc(""3 3 8 17 13 4"")); + assertEquals(1, dg.parseAndCalc(""2 0 9 7 27"")); + assertEquals(2, dg.parseAndCalc(""2 0 0 30 30"")); + assertEquals(2, dg.parseAndCalc(""2 1 10 30 30"")); + assertEquals(1, dg.parseAndCalc(""1 1 6 27"")); + assertEquals(1, dg.parseAndCalc(""1 0 10 30"")); + assertEquals(0, dg.parseAndCalc(""3 0 9 24 24 21"")); + assertEquals(1, dg.parseAndCalc(""3 1 9 24 24 21"")); + assertEquals(2, dg.parseAndCalc(""3 2 9 24 24 21"")); + assertEquals(1, dg.parseAndCalc(""1 1 10 27"")); + assertEquals(0, dg.parseAndCalc(""1 1 9 6"")); + assertEquals(0, dg.parseAndCalc(""3 0 9 17 23 23"")); + assertEquals(1, dg.parseAndCalc(""3 1 9 17 23 23"")); + assertEquals(0, dg.parseAndCalc(""2 0 7 18 16"")); + assertEquals(1, dg.parseAndCalc(""1 1 10 26"")); + assertEquals(0, dg.parseAndCalc(""1 0 10 26"")); + + assertEquals(3, dg.parseAndCalc(""6 2 8 29 20 8 18 18 21"")); + } + + private int parseAndCalc(String s) { + potentialCounter = 0; + guaranteedCounter = 0; + String[] parts = s.split("" "", 4); + int numOfGooglers = Integer.parseInt(parts[0]); + int numOfSurprises = Integer.parseInt(parts[1]); + int maxScore = Integer.parseInt(parts[2]); + String[] totalScores = parts[3].split("" ""); + for (int i = 0; i < numOfGooglers; i++) { + try { + assessGoogler(Integer.valueOf(totalScores[i]), maxScore); + } catch (Exception e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + + return guaranteedCounter + Math.min(numOfSurprises, potentialCounter); + + } + + private int potentialCounter = 0; + private int guaranteedCounter = 0; + + private void assessGoogler(int totalScore, int maxScore) throws Exception { + if (totalScore > 30 || totalScore < 0) throw new Exception(); + if (maxScore > 10 || maxScore < 0) throw new Exception(); + + int base = totalScore / 3; + if (base > 10 || base < 0) throw new Exception(); + int remain = totalScore % 3; + if (remain > 2 || remain < 0) throw new Exception(); + + if (remain == 0) { + int best = base; + if ((best-maxScore) >= 0) { + if (best > 10 || best < 0) throw new Exception(); + if (best < maxScore) throw new Exception(); + guaranteedCounter++; + } else if ((best-maxScore) == -1 && totalScore >= 3 ){// && best <= 9) { + if (base+1 > 10 || base+1 < 0) throw new Exception(); + if (base-1 > 10 || base-1 < 0) throw new Exception(); + if (base+1 != maxScore) throw new Exception(); + potentialCounter++; + } + } else if (remain == 1) { + int best = base + 1; + if ((best-maxScore) >= 0) { + if (best > 10 || best < 0) throw new Exception(); + if (best < maxScore) throw new Exception(); + guaranteedCounter++; + }/* else if ((best-maxScore) == -1 && totalScore >= 4 && best <= 9) { + if (base+1 > 10 || base+1 < 0) throw new Exception(); + if (base-1 > 10 || base-1 < 0) throw new Exception(); + if (base+1 != maxScore) throw new Exception(); + potentialCounter++; + } */ + } else if (remain == 2) { + int best = base + 1; + if ((best-maxScore) >= 0) { + if (best > 10 || best < 0) throw new Exception(); + if (best < maxScore) throw new Exception(); + guaranteedCounter++; + } else if ((best-maxScore) == -1){// && best <= 9) { + if (base+1 > 10 || base+1 < 0) throw new Exception(); + if (base+2 > 10 || base+2 < 0) throw new Exception(); + if (base+2 != maxScore) throw new Exception(); + potentialCounter++; + } + } + + } + + +} +" +A22334,"import java.util.Scanner; + +/* +4 +3 1 5 15 13 11 +3 0 8 23 22 21 +2 1 1 8 0 +6 2 8 29 20 8 18 18 21 + */ +public class Problem { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + int test = 1, + numberOfTests, + dancarinos, + erros, + notaCorte, + notaAtual, + resposta; + + numberOfTests = scanner.nextInt(); + for( int i = 0; i < numberOfTests; i++ ){ + resposta = 0; + + dancarinos = scanner.nextInt(); + erros = scanner.nextInt(); + notaCorte = scanner.nextInt(); + + int[] notas = new int[dancarinos]; + + for( int j = 0; j < dancarinos; j++){ + notas[j] = scanner.nextInt(); + } + + int div, resto; + + for( int j = 0; j < dancarinos; j++ ){ + notaAtual = notas[j]; + div = notaAtual / 3; + resto = notaAtual % 3; + + switch( resto ){ + case 0: + if( div >= notaCorte){ + resposta++; + }else{ + if( erros > 0 && div > 0 && div +1 >= notaCorte){ + resposta++; + erros--; + } + } + + break; + case 1: + if (div >= notaCorte || div + 1 >= notaCorte){ + resposta++; + }else{ + if (erros > 0 && div + 1 >= notaCorte){ + resposta++; + erros--; + } + } + break; + case 2: + if (div + 1 >= notaCorte || div >= notaCorte){ + resposta++; + }else{ + if (erros > 0 && div + 2 >= notaCorte){ + resposta++; + erros--; + } + } + + break; + } + } + + System.out.println(""Case #""+test+"": ""+resposta); + test++; + + } + } +} + +" +A20134,"package template; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + +public abstract class Template { + + static BufferedReader in; + static PrintWriter out; + + public static void init(String problemName) throws Exception { + in = new BufferedReader(new FileReader(problemName + "".in"")); + out = new PrintWriter(new FileWriter(problemName + "".out""), true); + } + + public static String readString() { + try { + return in.readLine().trim(); + } catch (Exception e) { + throw new RuntimeException(); + } + } + + public static String[] readStringArray() { + return readString().split(""\\s""); + } + + public static int readInt() { + return Integer.parseInt(readString()); + } + + public static double readDouble() { + return Double.parseDouble(readString()); + } + + public static int[] readIntArray() { + String[] s = readStringArray(); + int[] r = new int[s.length]; + for (int i = 0; i < r.length; i++) { + r[i] = Integer.parseInt(s[i]); + } + return r; + } + + public static long[] readLongArray() { + String[] s = readStringArray(); + long[] r = new long[s.length]; + for (int i = 0; i < r.length; i++) { + r[i] = Long.parseLong(s[i]); + } + return r; + } + + public static String[][] readStringArray(int lines) { + String[][] r = new String[lines][]; + for (int i = 0; i < lines; i++) { + r[i] = readStringArray(); + } + return r; + } + + public static int[][] readIntArray(int lines) { + int[][] r = new int[lines][]; + for (int i = 0; i < lines; i++) { + r[i] = readIntArray(); + } + return r; + } + + public static double[][] readDoubleArray(int lines) { + double[][] r = new double[lines][]; + for (int i = 0; i < lines; i++) { + r[i] = readDoubleArray(); + } + return r; + } + + public static double[] readDoubleArray() { + String[] s = readStringArray(); + double[] r = new double[s.length]; + for (int i = 0; i < r.length; i++) { + r[i] = Double.parseDouble(s[i]); + } + return r; + } + + public static void write(String s) { + out.println(s); + System.out.println(s); + } + + public static void write(String[] s) { + String r = """"; + for (String t : s) + r += t + "" ""; + write(r.trim()); + } + + public static void write(int[] i) { + String s = """"; + for (int t : i) + s += t + "" ""; + write(s.trim()); + } + + public static void write(int[][] i) { + for (int[] t : i) + write(t); + } + + public static void write(String[][] i) { + for (String[] t : i) + write(t); + } + + public static void write(double[][] i) { + for (double[] t : i) + write(t); + } + + public static void write(double[] i) { + String s = """"; + for (double t : i) + s += t + "" ""; + write(s.trim()); + } +} +" +A21827,"import java.util.Scanner; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; + +public class Dancing2 +{ + public static void main(String[] args) throws FileNotFoundException + { + + Scanner in = new Scanner(new File(""B-large.in"")); + int numOfTests = Integer.parseInt(in.nextLine()); + + for(int tests = 0; tests < numOfTests; tests++) + { + int googlers = in.nextInt(); + int specials = in.nextInt(); //Number of special cases + int lookingFor = in.nextInt(); //Number it must contain at least + + int found = 0; + int foundSpecials = 0; + int[] googScores = new int[googlers]; + for(int googs = 0; googs < googlers; googs++) + { + googScores[googs] = in.nextInt(); + } + Arrays.sort(googScores); + for(int i = 0; i < googlers; i++) + { + + int score = googScores[i]; + boolean completed = false; + + int[] scores = {lookingFor,lookingFor,lookingFor}; + if(scores[0] == 1) + { + scores[1] = 1; + scores[2] = 1; + } + if(scores[0] == 0) + { + scores[1] = 0; + scores[2] = 0; + } + while(!completed && specials != foundSpecials) + { + if((scores[0] + (scores[1]-2) + (scores[2]-2)) > score && scores[0] > 1) + break; + if(scores[0] < 2) + { + if(scores[0] > score) + break; + } + if((scores[0] + (scores[1]-2) + (scores[2]-2)) == score && scores[0] > 1) + { + found += 1; + foundSpecials += 1; + completed = true; + break; + } + if((scores[0] + (scores[1]-2) + (scores[2]-1)) == score && scores[0] > 1) + { + found += 1; + foundSpecials += 1; + completed = true; + break; + } + if((scores[0] + (scores[1]-2) + (scores[2])) == score && scores[0] > 1) + { + found += 1; + foundSpecials += 1; + completed = true; + break; + } + if((scores[0] + (scores[1]-1) + (scores[2]+1)) == score && scores[0] >= 1)//102 + { + found += 1; + foundSpecials += 1; + completed = true; + break; + } + if((scores[0] + (scores[1]) + (scores[2]+2)) == score ) //002 + { + found += 1; + foundSpecials += 1; + completed = true; + break; + } + if((scores[0] + (scores[1]+1) + (scores[2]+2)) == score) //012 + { + found += 1; + foundSpecials += 1; + completed = true; + break; + } + if((scores[0] + (scores[1]+2) + (scores[2]+2)) == score) //022 + { + found += 1; + foundSpecials += 1; + completed = true; + break; + } + scores[0] += 1; + if (scores[0] >= 2) + { + scores[1] = (scores[0]); + scores[2] = (scores[0]); + } + else + { + scores[1] = 1; + scores[2] = 1; + } + }//end of while + if((scores[0] + (scores[1]-1) + (scores[2]-1)) <= score && specials == foundSpecials && !completed) + { + found += 1; + } + }//end for(goog) + System.out.println(""Case #"" + (tests+1) + "": "" + found); + }//end for(tests) + }//end method +}//end class + + + " +A20322,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingGooglers { + + public static String readFile(String nombreArchivo) throws Exception { + + String aux = """"; + String contenido = """"; + + BufferedReader bf = new BufferedReader(new FileReader(nombreArchivo)); + while ((aux = bf.readLine()) != null) { + contenido += aux + ""\r\n""; + } + return contenido; + } + + public static void writeFile(String nombreArchivo, String contenido) { + try { + + BufferedWriter out = new BufferedWriter(new FileWriter( + nombreArchivo)); + out.write(contenido); + out.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) throws Exception { + + String result; + + result = """"; + String lines[] = readFile(""./input.txt"").trim().split(""\r\n""); + + for (int j = 1; j < lines.length; j++) { + int total = 0; + String values[] = lines[j].split("" ""); + int dancers = Integer.parseInt(values[0]); + int maxSurprise = Integer.parseInt(values[1]); + int minScore = Integer.parseInt(values[2]); + int scores[] = new int[dancers]; + for (int i = 3; i < values.length; i++) { + scores[i - 3] = Integer.parseInt(values[i]); + } + + for (int i = 0; i < scores.length; i++) { + boolean flag = false; + int comodin = 0; + if (maxSurprise > 0) { + comodin = 4; + } + + if(scores[i] == 0){ + if (minScore == 0) { + flag = true; + } + }else{ + if (minScore == 0) { + flag = true; + } else { + if ((scores[i] + 2) / minScore >= 3) { + flag = true; + } + if (!flag) { + if ((scores[i] + comodin) / minScore >= 3) { + flag = true; + maxSurprise--; + } + } + } + } + + + if (flag) { + total++; + } + + } + result += ""Case #"" + j + "": "" + total + ""\r\n""; + } + writeFile(""./output.txt"", result.trim()); + + } +} +" +A21487," import java.io.*; + import java.util.Scanner; + import java.util.ArrayList; + public class googler{ + + public static void main(String[] args) throws IOException{ + Scanner fileScan = new Scanner(new File(""infile.in"")); + Writer out = new OutputStreamWriter(new FileOutputStream(""output.txt"")); + + fileScan.nextLine(); + int i = 0; + ArrayList totals = new ArrayList(); + while(fileScan.hasNext()){ + i++; + int count = 0; + totals.clear(); + String line = fileScan.nextLine(); + Scanner lineScan = new Scanner(line); + int n = lineScan.nextInt(); + int s = lineScan.nextInt(); + int p = lineScan.nextInt(); + while(lineScan.hasNext()){ + totals.add(lineScan.nextInt()); + } + + if (p == 0){ + count = totals.size(); + } + else if (p == 1){ + for(int temp: totals){ + if (temp > 0){ + count++; + } + } + } + else{ + int sureTotal = 3 * p -2; + int surprisingTotal = 3 * p - 4; + int surprise = 0; + for (int temp: totals){ + if (temp >= sureTotal){ + count++; + } + else if (temp >= surprisingTotal){ + surprise++; + } + } + count += ((s < surprise)? s: surprise); + } + out.write(""Case #"" + i + "": "" + count + ""\n""); + } + out.close(); + } + }" +A22876,"package com.google.codejam.googlers; + +/** + * Class to represent each test case. + * It will hold details like test case no, input to be operated and TestResult. + * @author Sushant Deshpande + * + */ +public class TestCase { + + /** + * Variable to hold value for test case number. + */ + private int caseNo; + + /** + * Variable to hold lower limit. + */ + private int noOfGooglers; + + /** + * Variable to hold upper limit. + */ + private int noOfurprisingTriplets; + + /** + * Variable to hold value of best result. + */ + private int bestResult; + + /** + * Array to hold googlers score. + + */ + private int [] scores; + + /** + * Variable holding test case result. + */ + private TestResult output; + + /** + * Constructor for creating TestCase with case no. + * @param caseNo int + * @param noOfGooglers int + * @param surprisingTriplets int + */ + public TestCase(final int caseNo, final int noOfGooglers, final int surprisingTriplets, + final int bestResult, final int [] scores) { + this.caseNo = caseNo; + this.noOfGooglers = noOfGooglers; + this.noOfurprisingTriplets = surprisingTriplets; + this.bestResult = bestResult; + this.scores = scores; + } + + /** + * Settter method for TestResult. + * @param output TestResult + */ + public final void setOutput(final TestResult output) { + this.output = output; + } + + public final int getNoOfurprisingTriplets() { + return noOfurprisingTriplets; + } + + public final int getNoOfGooglers() { + return noOfGooglers; + } + + /** + * Getter method for best result. + * @return int + */ + public final int getBestResult() { + return bestResult; + } + + /** + * Method for getting scores. + * @return int [] + */ + public final int[] getScores() { + return scores; + } + + /** + * Method to format the test output for printing in the report. + * @return String formatted output for the given input. + */ + public final String printTestResult() { + StringBuilder resultBuilder = new StringBuilder(""Case #""); + resultBuilder.append(caseNo).append("": ""); + resultBuilder.append(output.getTestOutput()).append(""\n""); + return resultBuilder.toString(); + } +}" +A22330,"package com.google; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class DancingGooglers { + + private static boolean testing = false; + + private static int surprisingScores; + + private static int getPossibleCount(int score, int findingThreshold) { + int a; + int b; + int c; + a = b = c = (score / 3); + int rem = score % 3; + if (b < findingThreshold - 2) { + return 0; + } + if (b >= findingThreshold) { + if (testing) { + System.out.println(""SUCCESS1: score: "" + score + "", a: "" + a + + "", b: "" + b + "", c: "" + c); + } + return 1; + } + if (b == findingThreshold - 1) { + if (rem >= 1) { + if (testing) { + System.out.println(""SUCCESS2: score: "" + score + "", a: "" + + a + "", b: "" + b + "", c: "" + c); + } + return 1; + } else if (surprisingScores > 0 && a > 0) { + surprisingScores--; + if (testing) { + System.out.println(""SUCCESS3: score: "" + score + "", a: "" + + a + "", b: "" + b + "", c: "" + c); + } + return 1; + } + return 0; + } + if (b == findingThreshold - 2 && rem == 2 && surprisingScores > 0) { + surprisingScores--; + if (testing) { + System.out.println(""SUCCESS4: score: "" + score + "", a: "" + a + + "", b: "" + b + "", c: "" + c); + } + return 1; + } + return 0; + } + + private static int countMaxPossible(Scanner scanner) { + int count = 0; + int numOfScores = scanner.nextInt(); + surprisingScores = scanner.nextInt(); + + int findingThreshold = scanner.nextInt(); + int[] scores = new int[numOfScores]; + for (int i = 0; i < numOfScores; i++) { + scores[i] = scanner.nextInt(); + count += getPossibleCount(scores[i], findingThreshold); + } + // start printing + if (testing) { + System.out.println(""numOfScores: "" + numOfScores); + System.out.println(""surprisingScores: "" + surprisingScores); + System.out.println(""findingThreshold: "" + findingThreshold); + for (int i : scores) { + System.out.print(i + "", ""); + } + System.out.println(); + } + // end printing + return count; + } + + public static void main(String[] args) throws FileNotFoundException { + File file = new File(""d:\\codeJam\\Dancing\\test.txt""); + Scanner scanner = new Scanner(file); + int t = scanner.nextInt(); + int count; + for (int i = 1; i <= t; i++) { + count = countMaxPossible(scanner); + System.out.println(""Case #"" + i + "": "" + count); + } + } +} +" +A22915,"import java.util.Scanner; +import java.io.*; + +public class DancingGooglers { + private static Scanner inFile; + private static PrintWriter outFile; + private static final String FILE_NAME = ""B-large""; + + /* Copy & Paste: VARIABLES */ + + private static int numCases, numGooglers, surpriseScores, bestScore, totalScore, trio, score1, score2, score3, answer; + private static boolean trioFound; + + /* Copy & Paste: VARIABLES */ + + public static void main(String[] args) throws IOException { + inFile = new Scanner(new File(FILE_NAME + "".in"")); + outFile = new PrintWriter(FILE_NAME + "".out""); + + numCases = inFile.nextInt(); + + for (int caseNum = 0; caseNum < numCases; caseNum++) { + numGooglers = inFile.nextInt(); + surpriseScores = inFile.nextInt(); + bestScore = inFile.nextInt(); + answer = 0; + + for (int googlerNum = 0; googlerNum < numGooglers; googlerNum++) { + totalScore = inFile.nextInt(); + trioFound = false; + + if (bestScore > 0) { + trio = 28 - (27 - ((bestScore - 1) * 3)); + score1 = bestScore; + score2 = bestScore - 1; + score3 = score2; + } + else { + trio = 0; + score1 = 0; + score2 = 0; + score3 = 0; + } + + for (trio = trio; trio < 31 && !trioFound; trio++) { + if (score1 + score2 + score3 == totalScore) { + answer++; + trioFound = true; + } + else { + if (trio % 3 == 0) { + score1++; + } + else if (trio % 3 == 1) { + score2++; + } + else { + score3++; + } + } + } + + if (bestScore >= 2 && (totalScore - 1) % 3 != 0 && !trioFound) { + + score1 = bestScore; + score2 = bestScore - 2; + score3 = score2; + + for (trio = (bestScore - 2) * 2; trio < 18 && !trioFound && surpriseScores > 0; trio++) { + if (score1 + score2 + score3 == totalScore) { + answer++; + surpriseScores--; + trioFound = true; + } + else { + if (trio % 2 == 0) { + score2++; + } + else { + score1++; + score3++; + } + } + } + } + } + + outFile.printf(""Case #%d: %d\n"", caseNum + 1, answer); + } + + inFile.close(); + outFile.close(); + System.out.println(""Succesfully written to "" + FILE_NAME + "".out.""); + } +} +" +A20953,"package codejam; + +import java.io.*; +public class Dance { + public static void main(String[] args)throws IOException{ + BufferedReader cin=new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter cout=new PrintWriter(new BufferedWriter(new FileWriter(""out1.txt""))); + String[] in; + int x,y,n,p,s,count,a; + int t=Integer.parseInt(cin.readLine()); + for(int i=0;isum){ + count++; + continue; + } + if(a>=sum-1 && s>0){ + count++; + s--; + } + } + cout.println(""Case #""+(i+1)+"": ""+count); + } + cout.flush(); + } +} +" +A21951,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.util.regex.Pattern; + +/** + * @(#)DancingGoogler.java, 2012-4-14. + * + * Copyright 2012 Netease, Inc. All rights reserved. + * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +/** + * + * @author bjdengdong + * + */ +public class DancingGoogler { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""E:\\google_code_jam\\B-large.in""))); + PrintStream out = new PrintStream(new FileOutputStream(""E:\\google_code_jam\\B-large.out"")); + + int cases = Integer.parseInt(br.readLine()); + + for (int i = 1; i <= cases; i++) { + String line = br.readLine(); + String[] sp = line.split(Pattern.quote("" "")); + + int n = Integer.parseInt(sp[0]);//num of googlers + int s = Integer.parseInt(sp[1]);//num of surprises + int p = Integer.parseInt(sp[2]);//best score p + + int[] scores = new int[n]; + int result = 0; + int usedSurprise = s; + for (int j = 0; j < n; j++) { + scores[j] = Integer.parseInt(sp[j + 3]); + if (canReachWithoutSuprise(scores[j], p)) { + result++; + } else if (canReachWithSuprise(scores[j], p)) { + if (usedSurprise > 0) { + result++; + usedSurprise--; + } + } + } + out.println(""Case #"" + i + "": "" + result); + } + out.close(); + } + + private static boolean canReachWithSuprise(int score, int p) { + if (score == 0 || score == 1) + return false; + return (score >= (3 * p - 4)) && (score <= (3 * p - 3)); + } + + private static boolean canReachWithoutSuprise(int score, int p) { + if (p == 0) + return true; + return score >= (3 * p - 2); + } + +} +" +A20970,"/* +ID: t.lam1 +LANG: JAVA +TASK: codejam +*/ +import java.io.*; +import java.util.*; +import java.text.*; +import static java.lang.System.*; +import static java.lang.Integer.*; +import static java.lang.Double.*; +import static java.lang.Character.*; +import static java.util.Collections.*; +import static java.lang.Math.*; +import static java.util.Arrays.*; + + +class codejam { + + public static void main (String [] args) throws IOException{ + codejam a=new codejam(); + a.run(); + } + public void run()throws IOException + { + dancing(); + } + public void recycle()throws IOException{ + Scanner file = new Scanner(new File(""codejam.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""codejam.out""))); + int cases = file.nextInt(); + file.nextLine(); + ArrayList done = new ArrayList(); + for(int x =0; x googlers = new ArrayList(); + for(int y = 0; y0){ + //System.out.println(""bye""); + if(P-(temp2-P)/2==2){ + S--; + nums++; + } + if(temp2-2*temp>=P&&(temp2-2*temp)-temp<2)nums++; + else{ + temp++; + if((temp2-2*temp>=P||temp==P)&&temp-(temp2-2*temp)<2)nums++; + } + } + else{ + //System.out.println(""hi""); + if(temp2-2*temp>=P&&(temp2-2*temp)-temp<2)nums++; + else{ + //System.out.println(""else""); + temp++; + if((temp2-2*temp>=P||temp==P)&&temp-(temp2-2*temp)<2)nums++; + } + } + + } + //System.out.println(""nums: ""+nums); + out.println(nums); + } + out.close(); + } + public void googleRese()throws IOException{ + Scanner file = new Scanner(new File(""codejam.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""codejam.out""))); + int x = file.nextInt(); file.nextLine(); + //ArrayList cases = new ArrayList(); + Map remap = new TreeMap(); + remap.put('a','y'); + remap.put('b','h'); + remap.put('c','e'); + remap.put('d','s'); + remap.put('e', 'o'); + remap.put('f', 'c'); + remap.put('g', 'v'); + remap.put('h', 'x'); + remap.put('i', 'd'); + remap.put('j', 'u'); + remap.put('k', 'i'); + remap.put('l', 'g'); + remap.put('m', 'l'); + remap.put('n', 'b'); + remap.put('o', 'k'); + remap.put('p', 'r'); + remap.put('r', 't'); + remap.put('s', 'n'); + remap.put('t', 'w'); + remap.put('u', 'j'); + remap.put('v', 'p'); + remap.put('w', 'f'); + remap.put('x', 'm'); + remap.put('y','a'); + remap.put('z','q'); + remap.put('q','z'); + remap.put(' ',' '); + for(int y = 1; y<=x; y++){ + String temp = file.nextLine(); + out.print(""Case #""+y+"": ""); + for(Character a: temp.toCharArray()){ + if(remap.get(a)==null)System.out.println(a); + out.print(remap.get(a)); + } + out.println(); + } + out.close(); + } + +} +" +A22827,"package mgg.utils; + +public class Triplet { + + public int first; + public int second; + public int third; + + public Triplet(int first, int second, int third){ + this.first = Math.max(Math.max(first, second), third); + if (first == this.first){ + this.second = Math.max(second, third); + this.third = Math.min(second, third); + } + else if (second == this.first){ + this.second = Math.max(first, third); + this.third = Math.min(first, third); + } + else{ + this.second = Math.max(first, second); + this.third = Math.min(first, second); + } + } + + @Override + public String toString() { + return ""("" + first + "", "" + second + "", "" + third + "") "" + (isSurprising()?""(*)"":""""); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + first; + result = prime * result + second; + result = prime * result + third; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Triplet other = (Triplet) obj; + if (first != other.first) + return false; + if (second != other.second) + return false; + if (third != other.third) + return false; + return true; + } + + public int sum() { + return first + second + third; + } + + public int max() { + return first; + } + + public boolean isSurprising() { + return ((Math.abs(first-second) == 2) || + (Math.abs(first-third) == 2) || + (Math.abs(second-third) == 2)); + } + +} +" +A21430,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + +// Qualification Round 2012 +// Problem A + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + Scanner sc = null; + try { + sc = new Scanner(new File(""B-large.in"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + PrintStream output = null; + + try { + output = new PrintStream(new File(""B-large.out"")); + } catch (IOException e) { + e.printStackTrace(); + } + + int[][] maxScores = new int[31][2]; + + for(int i = 0; i < 31; i++){ + maxScores[i][0] = (int) Math.round((i + 1) / 3.0); + if(i < 2 || i > 28) + maxScores[i][1] = -1; + else + maxScores[i][1] = (int) Math.round((i + 3) / 3.0); + } + + int cases = sc.nextInt(); + sc.nextLine(); + + for(int c = 0; c < cases; c++){ + int googlers = sc.nextInt(); + int surprises = sc.nextInt(); + int p = sc.nextInt(); + + int count = 0; + + for(int s = 1; s <= googlers; s++){ + int score = sc.nextInt(); + + if(maxScores[score][0] >= p) + count++; + else if (maxScores[score][1] >= p && surprises > 0){ + count++; + surprises--; + } + } + + System.out.printf(""Case #%d: %s\n"", c + 1, count); + output.printf(""Case #%d: %s\n"", c + 1, count); + } + + } +}" +A23084,"package codejam2012.qr.dancing; + +import codejam2012.qr.googlerese.Translator; +import codejam2012.util.ReadWriteUtil; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author fedez + */ +public class Main +{ + /** + * Args0 in file + * Args1 out file + * @param args the command line arguments + */ + public static void main(String[] args) throws Exception + { + List in; + List out; + String[] lineArray; + + int caseNumber = 1; + int scores[]; + int result, googlers, surprises, scoreTopass; + int i; + + in = ReadWriteUtil.readFile(args[0]); + if (in.size() < 2 || Integer.parseInt(in.get(0)) != in.size() - 1) + { + throw new Exception(""Input error""); + } + in.remove(0); + + out = new ArrayList(in.size()); + for (String line : in) + { + lineArray = line.split(""\\s""); + googlers = Integer.parseInt(lineArray[0]); + surprises = Integer.parseInt(lineArray[1]); + scoreTopass = Integer.parseInt(lineArray[2]); + scores = new int[lineArray.length-3]; + for ( i = 3; i < lineArray.length; i++ ) + { + scores[i-3] = Integer.parseInt(lineArray[i]); + } + + result = DancerSolver.solve(googlers, scores, surprises, scoreTopass); + out.add(""Case #"" + caseNumber + "": "" + result); + caseNumber ++; + } + ReadWriteUtil.writeFile(args[1], out); + } +} +" +A21327,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package javaapplication4; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; +import javax.print.DocFlavor.STRING; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.util.AbstractList; +import java.util.Iterator; +import java.util.List; + + + +/** + * + * @author Mansk + */ +public class JavaApplication4 { + + /** + * @param args the command line arguments + */ + + + + + public static void main(String[] args) throws FileNotFoundException, IOException { + // TODO code application logic here + FileInputStream fstream = new FileInputStream(""In.txt""); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + + + FileOutputStream fos = new FileOutputStream(""out.txt""); + + BufferedOutputStream bos =new BufferedOutputStream(fos); + + + + + String line; + + int num=0; + int T=0; + int S=0; + int P=0; + + + line= br.readLine(); + num= Integer.parseInt(line) ; + Scanner s= new Scanner(br); + + + + for (int i = 0; i =(3*P)) + { max ++; + } + + else + { + int temp =sum/3; + + int temp2=(sum -temp)/2; + + int temp1=sum-(temp2+temp); + + int temp3=temp; + if((temp1>=P)|(temp1>=P)|(temp1>=P)) + + { + max ++; + } + + else { + temp1=P; + temp2= sum - (P + (sum-P)/2); + temp3= (sum-P)/2; + + if((((temp1-temp2)==1)&((temp2-temp3)==1))&(S!=0)) + { + S--; + max++; + } + + else if(((temp2==temp3)&((temp1-temp2)==2)&(S!=0))) + { + S--; + max++; + } + else if((temp2==temp3)&((temp1-temp2)==1)) + { + max++; + } + + + } + + + + } + + } + + + + line2=""Case #""+(i+1)+"": ""+max+""\n""; + + bos.write(line2.getBytes()); + bos.flush(); + } + + + } + + + + + +} +" +A22650,"import java.io.*; +import java.text.Format; +import java.util.Formatter; +import java.util.List; +import java.util.Set; +import java.util.HashSet; +import java.util.ArrayList; +import java.math.*; + + + + +public class Dancing { + + + + + static public String getContents(File aFile) { + //...checks on aFile are elided + StringBuilder contents = new StringBuilder(); + + try { + //use buffering, reading one line at a time + //FileReader always assumes default encoding is OK! + BufferedReader input = new BufferedReader(new FileReader(aFile)); + try { + String line = null; //not declared within while loop + /* + * readLine is a bit quirky : + * it returns the content of a line MINUS the newline. + * it returns null only for the END of the stream. + * it returns an empty String if two newlines appear in a row. + */ + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty(""line.separator"")); + } + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + + return contents.toString(); + } + + static public void setContents(File aFile, String aContents) + throws FileNotFoundException, IOException { + if (aFile == null) { + throw new IllegalArgumentException(""File should not be null.""); + } + if (!aFile.exists()) { + throw new FileNotFoundException (""File does not exist: "" + aFile); + } + if (!aFile.isFile()) { + throw new IllegalArgumentException(""Should not be a directory: "" + aFile); + } + if (!aFile.canWrite()) { + throw new IllegalArgumentException(""File cannot be written: "" + aFile); + } + + //use buffering + Writer output = new BufferedWriter(new FileWriter(aFile)); + try { + //FileWriter always assumes default encoding is OK! + output.write( aContents ); + } + finally { + output.close(); + } + } + + /** Simple test harness. */ + public static void main (String... aArguments) throws IOException { + File testFile = new File(""/Users/MatFuck/Dropbox/Projects/Code Jam Qualification 2009/src/A-small-practice-1.in""); + //System.out.println(""Original file contents: "" + getContents(testFile)); + + String[] in = getContents(testFile).split(System.getProperty(""line.separator"")), params= in[0].split("" ""); + + + long ans[] = new long[2000]; + + + + int NC=Integer.parseInt(params[0].trim()); + + for(int ci=0;ci= 0) { + score /= 2; + if (((criteria - score) == 2) && (surprising > 0)) { + ans[ci + 1]++; + surprising--; + } + else { + if ((criteria - score) < 2) { + ans[ci + 1]++; + } + } + } + + } + + } + + + + + String out =""""; + + StringBuilder contents = new StringBuilder(); + + for (int i=0;i=0; i--) { + if (t[i] == 0) { + bestScoreFreq[0]++; + continue; + } + int t3 = t[i]/3; + if (t[i] % 3 != 0) { + if (3*t3 + 2 == t[i] && sRemaining > 0 && t3+1 < p && t3+2 >= p) { + bestScoreFreq[t3+2]++; + sRemaining--; + } else { + bestScoreFreq[t3+1]++; + } + } else if (sRemaining > 0 && t3 < p && t3+1 >= p){ + bestScoreFreq[t3+1]++; + sRemaining--; + } else { + bestScoreFreq[t3]++; + } + } + + int result = 0; + for (int i=p; i<11; i++) { + result += bestScoreFreq[i]; + } + + // Print results + io.printCase(caseNum).println(result); + + } + + /** + * Input and Output CodeJam style + * + */ + private static class CodeJamIO { + private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + private static PrintWriter out = new PrintWriter(System.out, true); + private static PrintWriter err = new PrintWriter(System.err, true); + + public String[] readNextLine() throws IOException { + String line = in.readLine(); + String[] tokens = line.split(""\\s+""); + return tokens; + } + + public CodeJamIO printCase(int caseNum) { return print(""Case #"" + caseNum + "": "" ); } + + public CodeJamIO print(Object o) { out.print(o); return this; } + + public CodeJamIO print(Object o[]) { return print(concat(o)); } + + public CodeJamIO print(Object o[][]) { return print(concat(o)); } + + public CodeJamIO println() { out.println(); return this; } + + public CodeJamIO printlnCase(int caseNum) { return printCase(caseNum).println(); } + + public CodeJamIO println(Object o) { return print(o).println(); } + + public CodeJamIO println(Object o[]) { return print(o).println(); } + + public CodeJamIO println(Object o[][]) { return print(concat(o)).println(); } + + public CodeJamIO println(List l) { return print(concat(l)).println(); } + + + private String concat(Object[] o) { + StringBuffer buf = new StringBuffer(10*o.length); + + String delim = """"; + for (int i=0; i < o.length; i++) { + buf.append(delim).append(o[i]); + delim = "" ""; + } + return buf.toString(); + } + + private String concat(Object[][] o) { + StringBuffer buf = new StringBuffer(100*o.length); + for (int i=0; i < o.length; i++) { + buf.append(concat(o[i])).append(""\n""); + } + return buf.toString(); + } + + private String concat(List list) { + StringBuffer buf = new StringBuffer(); + String delim = """"; + for (Object[] elm : list) { + buf.append(delim).append(concat(elm)).append(""\n""); + } + return buf.toString(); + } + + public void debug(String message) { + err.println(Calendar.getInstance().getTime() + "": "" + message); + } + + public void debug(String message, Object[] o) { + err.println(Calendar.getInstance().getTime() + "": "" + message); + err.println(""\t"" + concat(o)); + } + + public void debug(String message, Object[][] o) { + err.println(Calendar.getInstance().getTime() + "": "" + message); + String values = concat(o); + err.println(""\t"" + values.replaceAll(""\n"", ""\n\t"")); + } + + public void debug(String message, List list) { + err.println(Calendar.getInstance().getTime() + "": "" + message); + String values = concat(list); + err.println(""\t"" + values.replaceAll(""\n"", ""\n\t"")); + } + + } + +} +" +A21900,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class Program { + + /** + * @param args + */ + public static void main1(String[] args) { + + Speaking_in_Tongues sit=new Speaking_in_Tongues(); + sit.initialize(); + sit.register(""our language is impossible to understand"", ""ejp mysljylc kd kxveddknmc re jsicpdrysi""); + sit.register(""there are twenty six factorial possibilities"", ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd""); + sit.register(""so it is okay if you want to just give up"", ""de kr kd eoya kw aej tysr re ujdr lkgc jv""); + + for(char o='a';o<= 'z';o++) + { + System.out.print(sit.map[o]); + } + + try { + FileWriter fileWriter=new FileWriter(""A-small-attempt0.out""); + FileReader fileReader=new FileReader(""A-small-attempt0.in""); + BufferedReader in = new BufferedReader(fileReader); + + int T= Integer.parseInt(in.readLine()); + for(int t=1;t<=T;t++) + { + String translated=in.readLine(); + String normal= sit.Solve(translated); + fileWriter.write(""Case #""+t+"": ""+normal+""\n""); + } + fileWriter.close(); + fileReader.close(); + } catch (Exception e) { + System.out.println(""Error! Exception: ""+e); + } + + + } + + public static void main(String[] args) { + + try { + FileWriter fileWriter=new FileWriter(""B-large.out""); + FileReader fileReader=new FileReader(""B-large.in""); + BufferedReader in = new BufferedReader(fileReader); + + int T= Integer.parseInt(in.readLine()); + for(int t=1;t<=T;t++) + { + String[] tokens= in.readLine().split("" ""); + int N= Integer.parseInt(tokens[0]); + int[] values=new int[N]; + int S= Integer.parseInt(tokens[1]); + int p= Integer.parseInt(tokens[2]); + + for(int n=0;n 1) { + builder.append(""\r\n""); + } + builder.append(""Case #""); + builder.append(i); + builder.append("": ""); + + String input = null; + try { + input = bufferedReader.readLine(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + + String[] strs = input.split("" ""); + int length = strs.length; + int[] ints = new int[length]; + + for (int j = 0; j < length; j++) { + try { + ints[j] = Integer.parseInt(strs[j]); + } catch (Exception e) { + } + } + + int case1 = 0; + int case2 = 0; + int case3 = 0; + + int s = ints[1]; + int p = ints[2]; + + int a = 3 * p - 4; + int b = a + 2; + + if (a < 2) { + a = 2; + } + if (b < 2) { + b = 2; + } + + for (int j = 3; j < length; j++) { + int test = ints[j]; + + if (test >= a) { + if (test > 28) { + case3++; + } else if (test >= b) { + case1++; + } else { + case2++; + } + } else if (p == 1 && test >= 1) { + case3++; + } else if (p == 0) { + case3++; + } + } + + if (case2 > s) { + case2 = s; + } + + builder.append(case1 + case2 + case3); + } + + //System.out.println(builder.toString()); + try { + FileWriter writer = new FileWriter(outputFile); + writer.append(builder.toString()); + writer.flush(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + + try { + bufferedReader.close(); + fileReader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +}" +A22169,"import java.io.*; + +import java.awt.geom.Point2D; +import java.text.*; +import java.math.*; +import java.util.*; + +public class Main implements Runnable { + + final String problem = ""B""; +// final String filename = problem + ""-sample""; + +// final String filename= problem+""-small-attempt0""; + // final String filename= problem+""-small-attempt1""; + final String filename= problem+""-large""; + + int ans = 0; + + public void solve() throws Exception { + int N = iread(), S = iread(), p = iread(); + int[] t = new int[N]; + for (int i = 0; i < N; i++) { + t[i] = iread(); + } + int surp = 0; + ans = 0; + for (int i = 0; i < N; i++) { + if (p <= t[i]) { + if (p * 3 - 2 <= t[i]) + ans++; + else if (p * 3 - 4 <= t[i]) + surp++; + } + } + ans += Math.min(surp, S); + } + + public void solve_gcj() throws Exception { + int tests = iread(); + for (int test = 1; test <= tests; test++) { + out.write(""Case #"" + test + "": ""); + solve(); + out.write(ans + ""\n""); + } + } + + public void run() { + try { + // in = new BufferedReader(new InputStreamReader(System.in)); + // out = new BufferedWriter(new OutputStreamWriter(System.out)); + in = new BufferedReader(new FileReader(filename + "".in"")); + out = new BufferedWriter(new FileWriter(filename + "".out"")); + solve_gcj(); + out.flush(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + public int iread() throws Exception { + return Integer.parseInt(readword()); + } + + public double dread() throws Exception { + return Double.parseDouble(readword()); + } + + public long lread() throws Exception { + return Long.parseLong(readword()); + } + + BufferedReader in; + + BufferedWriter out; + + public String readword() throws IOException { + StringBuilder b = new StringBuilder(); + int c; + c = in.read(); + while (c >= 0 && c <= ' ') + c = in.read(); + if (c < 0) + return """"; + while (c > ' ') { + b.append((char) c); + c = in.read(); + } + return b.toString(); + } + + public static void main(String[] args) { + try { + Locale.setDefault(Locale.US); + } catch (Exception e) { + + } + new Thread(new Main()).start(); + // new Thread(null, new Main(), ""1"", 1<<25).start(); + } +}" +A20534,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class Dancing { + + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(new File(""B-large.in"")); + FileWriter fstream = new FileWriter(""Bout.txt""); + BufferedWriter outp = new BufferedWriter(fstream); + int cases = sc.nextInt(); + for (int r = 0; r < cases; r++) { + int total = 0; + int totalS = 0; + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] NN = new int[N]; +// System.out.println(""Surprising: ="" + S); + for (int rr = 0; rr < N; rr++) { + NN[rr] = sc.nextInt(); + int a = NN[rr] / 3; + int b = (NN[rr] - a) / 2; + int c = NN[rr] - a - b; + // find surprising score + // int lowest=aa?b:a; + // highest=highest>c?highest:c; + + // a- b+ + int max = max(a, b, c); + int maxS = max; + + int a1 = a - 1; + int b1 = b + 1; + int c1 = c; + if (maxDiff(a1,b1,c1)<3&&max(a1, b1, c1) > maxS) + maxS = max(a1, b1, c1); + + // a- c+ + a1 = a - 1; + b1 = b; + c1 = c + 1; + if (maxDiff(a1,b1,c1)<3&&max(a1, b1, c1) > maxS) + maxS = max(a1, b1, c1); + + // a+ b- + a1 = a + 1; + b1 = b - 1; + c1 = c; + if (maxDiff(a1,b1,c1)<3&&max(a1, b1, c1) > maxS) + maxS = max(a1, b1, c1); + + // a+ c- + a1 = a + 1; + b1 = b; + c1 = c - 1; + if (maxDiff(a1,b1,c1)<3&&max(a1, b1, c1) > maxS) + maxS = max(a1, b1, c1); + + // b- c+ + a1 = a; + b1 = b - 1; + c1 = c + 1; + if (maxDiff(a1,b1,c1)<3&&max(a1, b1, c1) > maxS) + maxS = max(a1, b1, c1); + + // b+ c- + a1 = a; + b1 = b + 1; + c1 = c - 1; + if (maxDiff(a1,b1,c1)<3&&max(a1, b1, c1) > maxS) + maxS = max(a1, b1, c1); + + if (max >= p) + total++; + if (maxS >= p) + totalS++; +// System.out.println(a+"" ""+b+"" ""+c+"" ""+max+"" ""+maxS); + } +// System.out.println(total + "" "" + totalS); + int fin=total; + if (total+S>totalS)fin=totalS; + else fin=total+S; + + System.out.println(""Case #"" + (r + 1) + "": "" + fin); + outp.write(""Case #"" + (r + 1) + "": "" + fin+""\n""); + } + outp.flush(); + fstream.close(); + } + + public static int maxDiff(int a, int b, int c) { + if (a<0||b<0||c<0||a>10||b>10||c>10)return 100; + double diff1 = Math.abs(a - b); + double diff2 = Math.abs(a - c); + double diff3 = Math.abs(b - c); + return (int) Math.max(Math.max(diff1, diff2), diff3); + } + + public static int max(int a, int b, int c) { + return (a > b ? a : b) > c ? (a > b ? a : b) : c; + } + +} +" +A22178,"import java.util.*; + +class QB{ + + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + int kase = sc.nextInt(); + for(int k = 1; k<=kase; k++){ + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] tots = new int[N]; + for(int i = 0; i0 && tots[i-1]>=(3*p-2)) i--; + int j = 0; + if(p!=1){ + while(i>0 && tots[i-1]>= 3*p-4 && j scores = new ArrayList(); + + for (int i=0; i l = new ArrayList(); + + for (Integer score : scores){ + if ((score+2)/3 >= minimum){ + count++; + } else { + l.add(score); + } + } + + scores = l; + + Collections.sort(scores); + Collections.reverse(scores); + + //moderate scores + int left = scores.size() > surprising ? surprising : scores.size(); + for (int i=0; i= minimum){ + count++; + } + } + + String prefix = ""Case #"" + index + "": ""; + return prefix + count + ""\n""; + } + + public static void main(String[] args) throws Exception{ + if (args.length < 1) throw new Exception(""Expected Filename as first argument.""); + + String filename = args[0]; + FileReader input = new FileReader(filename); + BufferedReader bufferedinput = new BufferedReader(input); + + //number of lines + int n = new Integer(bufferedinput.readLine()); + + String line = bufferedinput.readLine(); + int index = 1; + + String outfilename = ""b.txt""; + FileWriter f = new FileWriter(outfilename); + + while (line != null){ + String result = max(line, index); + + System.out.println(result); + f.write(result); + + index++; + line = bufferedinput.readLine(); + } + f.close(); + + } +} +" +A22477,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class Dancing { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in)); + String number = bReader.readLine(); + int num = Integer.parseInt(number); + for (int i = 0; i < num; i++) { + String s = bReader.readLine(); + String[] strs = s.split("" ""); + int N = Integer.parseInt(strs[0]); + int S = Integer.parseInt(strs[1]); + int P = Integer.parseInt(strs[2]); + int s1 = P + 2*Math.max(0, P-1); + int s2 = P + 2*Math.max(0, P-2); + int result = 0; + for (int j = 0; j < N; j++) { + int tmp = Integer.parseInt(strs[3+j]); + if(tmp>=s1) + { + ++result; + }else if(tmp>=s2 && S>0) + { + --S; + ++result; + } + } + System.out.println(""Case #""+(i+1)+"": ""+result); + } + } + +} +" +A22668,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingGooglers +{ + public int googlers( int surprise, int mincount, int[] scores ) + { + int counter = 0; + for( int i = 0; i < scores.length; i++ ) + { + int s = scores[i] % 3; + int base = scores[i] / 3; + if( s == 0 ) + { + if( base >= mincount ) + { + counter++; + } + else + { + if( surprise > 0 && base > 0 && base + 1 >= mincount ) + { + counter++; + surprise--; + } + } + } + else if( s == 1 ) + { + if(base >= mincount || base +1 >= mincount) + { + counter++; + } + else + { + if(surprise > 0 && base +1 >= mincount) + { + counter++; + surprise--; + } + } + + } + else if( s == 2 ) + { + if(base >= mincount || base +1 >= mincount) + { + counter++; + } + else + { + if(surprise > 0 && base +2 >= mincount) + { + counter++; + surprise--; + } + } + + } + } + return counter; + } + + public static void main( String[] args ) + { + DancingGooglers dg = new DancingGooglers(); + + try + { + FileWriter fw = new FileWriter( ""output.out"" ); + BufferedWriter out = new BufferedWriter( fw ); + + FileReader fr = new FileReader( ""in.in"" ); + BufferedReader br = new BufferedReader( fr ); + String size = br.readLine(); + + String temp = """"; + int k = 0; + while( ( temp = br.readLine() ) != null ) + { + String[] split = temp.trim().split( "" "" ); + int googlercount = Integer.parseInt( split[0] ); + int surprise = Integer.parseInt( split[1] ); + int mincount = Integer.parseInt( split[2] ); + int[] scores = new int[googlercount]; + for(int i = 0;i 0) + ans++; + } + else + { + for(j=0; j= 3*best-2 ) + ans++; + } + + sop(""Case #"" + i + "": "" + ans); + } + long tend = System.currentTimeMillis(); + System.err.println(""Time taken: "" + (tend - tstart)/1000.0 + "" seconds""); + } // end of main() +} + +" +A21410,"import java.util.*; +import java.io.*; + +class P2 { + + public static void main(String[] Args) throws IOException{ + InputStreamReader in = new InputStreamReader(System.in); + BufferedReader br = new BufferedReader(in); + int s, p, total, t = Integer.parseInt(br.readLine()); + String tmp; + String[] tmp2 = new String[10]; + int[] n = new int[10]; + for(int i=0; i= 3*p - 2) { + total++; + } + else if(n[j] >= 3*p - 4 && s>0 && n[j] >= 2) { + total++; + s--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + total); + } + } +}" +A22192,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.util.Scanner; + + +public class Googlers { + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub + int[] minScoreWithSurprise = new int[11]; + int[] minScoreWithoutSurprise = new int[11]; + + minScoreWithoutSurprise[0] = 0; + minScoreWithSurprise[0] = 0; + minScoreWithoutSurprise[1] = 1; + minScoreWithSurprise[1] = 1; + + for(int i=2; i= minSWithoutS){ + ans++; + } + else if(numOfsurprisingTriplets > 0 && current>=minSwithS){ + ans++;numOfsurprisingTriplets--; + } + } + sb.append(""Case #"").append(i+1).append("": "").append(ans); + bw.write(sb.toString()); + bw.newLine(); + } + bw.close(); + + } + +} +" +A21779,"import java.io.*; +import java.util.*; +public class Main{ + public static void main (String[] args) throws java.lang.Exception{ + BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in)); + int T=Integer.parseInt(bfr.readLine()); + int res[]=new int[T]; + Arrays.fill(res,0); + for(int i=0;i0){ + res[i]++; + } + continue; + } + if(q>x+1){ + res[i]++; + } + else if(q>=x && S>0){ + res[i]++; + S--; + } + } + } + for(int i=0;i=0; i--){ + int x = ar[i]; + int m1 = pos(x,false); + int m2 = pos(x,true); + if( m1 >= p ) count++; + else if( m2 >= p && s>0 ){ + count++; + s--; + } + } + out.println (""Case #""+(asdf+1)+"": ""+count); + } + out.close(); + System.exit(0); + } + public int pos(int x, boolean s){ + int div = (int)Math.ceil(x/3.); + int max = 0; + for(int a = Math.max(0,div-2); a2 || a+b+c!=x || (!s&& dif==2))continue; + max = Math.max(Math.max(a,b),Math.max(max,c)); + } + return max; + } +}" +A21967,"package com.renoux.gael.codejam.utils; + +import java.io.Closeable; +import java.io.IOException; + + +/** + *

+ * Cette classe comporte des méthodes utilitaires de gestion des flux d'entrée/sortie. + *

+ * + * @author renouxg + */ +public class FluxUtils { + + /** + *

+ * Constructeur privé : cette classe utilitaire n'est pas destinée à être instanciée. + *

+ */ + private FluxUtils() { + // classe non instanciable + } + + + /** + *

+ * Cette méthode utilitaire ferme tous les objets Closeable qui lui sont passés en paramètre. + * Les éléments nuls sont ignorés. Si la fermeture de l'un ou plusieurs d'entre eux renvoie une erreur, on + * tâche néanmoins de fermer tous les flux ; la première erreur survenue est ensuite relancée. + *

+ * + * @param fluxArray les objets implémentant {@link Closeable} qu'il faut fermer. + * @throws IOException toute exception qui peut se produire à la fermeture d'un {@link Closeable}. + */ + public static void closeCloseables(final Closeable... fluxArray) { + IOException relaunch = null; + + for (Closeable flux : fluxArray) { + if (flux == null) { + continue; + } + + try { + flux.close(); + } catch (IOException lEx) { + if (relaunch == null) { + relaunch = lEx; + } else { + // Nouvelle exception, ignorée + } + } + } + + if (relaunch != null) { + throw new TechnicalException(relaunch); + } + } + +} +" +A21597,"import java.text.*; +import java.util.*; +import java.lang.*; + + +public class solutionRunner { + + public solutionRunner(){ + run(); + } + + private void run(){ + + int numberOfLines = 1; + inpOutHandler io1 = new inpOutHandler(); + testCase TC = io1.readInput(""a1.txt"", numberOfLines); + String result="""";int _i=1; + for(String case1:TC.cases){ + int[] a1 = intAfromString(case1.substring(case1.indexOf('\n') +1)); + + if(_i==TC.cases.length){ + result +=""Case #"" + (_i++) +"": "" + numberOfG(a1); + }else{ + result +=""Case #"" + (_i++) +"": "" + numberOfG(a1) + ""\n""; + } + } + io1.createOutput(""OUTPUT.txt"", result); + //System.out.println(result); + /* + double xx = 1231212.9; + DecimalFormat threeDec = new DecimalFormat("".0000000""); + String shortString = (threeDec.format(xx)); + */ + + + } + + + private int numberOfG(int[] a) { + // what if a[2] == 0 ?? + if(a[2]==0) return a[0]; + + int minScoreSur = a[2] + 2*max(0,a[2]-2); + int minScore = a[2]+ 2*max(0,a[2]-1); + int numberWithSur = a[1]; + + + int googlers=0; + for(int i=3; i= minScore){ + googlers++; + }else if(numberWithSur > 0 && a[i] >= minScoreSur){ + googlers++; + numberWithSur--; + } + } + + return googlers; + } + + private int[] intAfromString(String s) { + String[] words = s.split("" ""); + int[] a = new int[words.length]; + for(int i=0;iy){ + return x; + }else{ + return y; + } + } +} +" +A20328,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package codejam; + +import java.io.File; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.TreeMap; + +/** + * + * @author Ben + */ +public class Main { + + public static Scanner freader; + public static int caseCount, _height, _width; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) + { + //solveFreeCell(); + //solveKiller(); + sovleDWG(); + //solveRC(); + //solveSIT(); + } + + public static void solveSIT() + { + try{ + freader = new Scanner( + new File(""C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/A-small-attempt0.in"")); + caseCount = freader.nextInt(); + freader.nextLine(); + + char GtoE [] = + {'y', //a + 'h', //b + 'e', //c + 's', //d + 'o', //e + 'c', //f + 'v', //g + 'x', //h + 'd', //i + 'u', //j + 'i', //k + 'g', //l + 'l', //m + 'b', //n + 'k', //o + 'r', //p + 'z', //q + 't', //r + 'n', //s + 'w', //t + 'j', //u + 'p', //v + 'f', //w + 'm', //x + 'a', //y + 'q'}; //z + + ArrayList L = new ArrayList(); + + int caseIdx; + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + L.add(freader.nextLine()); + } + + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + System.out.print(""Case #"" + (caseIdx + 1) + "": ""); + char chr [] = L.get(caseIdx).toCharArray(); + + for(int i = 0; i < chr.length; i++) + { + if(chr[i] == ' ') + continue; + chr[i] = GtoE[chr[i] - 'a']; + } + System.out.println(chr); + } + + + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static void solveRC() + { + try{ + freader = new Scanner( + new File(""C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/C-small-attempt0.in"")); + caseCount = freader.nextInt(); + freader.nextLine(); + + int caseIdx; + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + System.out.print(""Case #"" + (caseIdx+1) + "": ""); + + int A = freader.nextInt(); + int B = freader.nextInt(); + + int result = RC(A,B); + + System.out.println(result); + freader.nextLine(); + } + + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static int RC(int A, int B) + { + int count = 0; + + ArrayList iL; + ArrayList jL; + + for(int i = A; i <= B-1; i++) + { + for(int j = i + 1; j <= B; j++) + { + iL = convertNumToArray(i); + jL = convertNumToArray(j); + + if(iL.size() != jL.size()) + continue; + + if(recycled(iL, jL)) + { + count++; + } + } + } + return count; + } + + public static boolean recycled(ArrayList iL, ArrayList jL) + { + boolean equal; + int size = iL.size(); + + for(int i = 0; i < size; i++) + { + equal = true; + + //compare iL and jL + for(int j = 0; j < size; j++) + { + if(iL.get(j).intValue() != jL.get(j).intValue()) + { + equal = false; + break; + } + } + if(equal) + return true; + + //shift iL + Integer temp = iL.get(size-1); + for(int j = size-1; j > 0; j--) + { + iL.set(j, iL.get(j-1)); + } + iL.set(0, temp); + + } + + return false; + } + + public static ArrayList convertNumToArray(int x) + { + ArrayList L = new ArrayList(); + + while(x > 0) + { + int r = x % 10; + L.add(0, new Integer(r)); + + x = x / 10; + } + return L; + } + + public static void sovleDWG() + { + try{ + freader = new Scanner( + new File(""C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/B-large.in"")); + caseCount = freader.nextInt(); + freader.nextLine(); + + int caseIdx; + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + System.out.print(""Case #"" + (caseIdx+1) + "": ""); + + int n = freader.nextInt(); + int s = freader.nextInt(); + int p = freader.nextInt(); + + int T [] = new int [n]; + + for(int i = 0; i < n; i++){ + T[i] = freader.nextInt(); + } + + int count = DWG(T, n, s, p); + + System.out.println(count); + freader.nextLine(); + } + + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static int DWG(int [] T, int n, int s, int p) + { + int minSup = p + 2 * max(p-2,0); + int minNonSup = p + 2 * max(p-1,0); + int count = 0; + int maybe = 0; + + for(int i = 0; i < n; i++) + { + int curr = T[i]; + + if(curr >= minNonSup) + { + count++; + } + else if(curr < minNonSup && curr >= minSup) + { + maybe++; + } + } + + count = count + min(maybe, s); + + return count; + } + + public static int min(int x, int y) + { + if (x < y){ + return x; + } + return y; + } + public static int max(int x, int y) + { + if (x > y){ + return x; + } + return y; + } + + public static void solveKiller() + { + try{ + freader = new Scanner( + new File(""C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/B-large-practice.in"")); + caseCount = freader.nextInt(); + freader.nextLine(); + + int caseIdx; + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + System.out.print(""Case #"" + (caseIdx+1) + "": ""); + + int n = freader.nextInt(); + int m = freader.nextInt(); + + ArrayList L = new ArrayList(n); + + for(int i = 0; i < n; i++){ + L.add(freader.next()); + } + + String kword = null; + int score, worst; + + for(int j = 0; j < m; j++) + { + String todo = freader.next(); + worst = 1; + + for(int i = 0; i < n; i++) + { + score = killer(L.get(i), todo, (ArrayList)L.clone()); + if(score < worst) + { + worst = score; + kword = L.get(i); + } + } + if(j == m-1) + System.out.print(kword); + else + System.out.print(kword + "" ""); + + freader.nextLine(); + } + System.out.println(); + } + + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static int killer(String word, String todo, ArrayList dict) + { + int score = 0; + int index [] = new int [26]; + + updateTodo(todo, dict, index); + + char guess [] = new char [word.length()]; + for(int i = 0; i < word.length(); i++) + { + guess[i] = '*'; + } + + dict = updateDict(dict, guess); + + int j = 0; + while(j < 26) + { + while(index[j] == 0) + { + ++j; + if(j >= 26) + return score; + } + if(!updateGuess(guess, word, todo.charAt(j))){ + score--; + dict = filter(dict, todo.charAt(j)); + } + + dict = updateDict(dict, guess); + updateTodo(todo, dict, index); + + ++j; + } + return score; + } + + public static ArrayList filter(ArrayList dict, char c) + { + ArrayList result = new ArrayList(); + for(String str : dict) + { + if(str.indexOf(c) < 0) + { + result.add(str); + } + } + return result; + } + public static ArrayList updateDict(ArrayList dict, char [] guess) + { + ArrayList result = new ArrayList(); + for(String str : dict){ + if(matches(str,guess)){ + result.add(str); + } + } + return result; + } + public static boolean matches(String str, char [] guess) + { + if(str.length() != guess.length) + return false; + + for(int i = 0; i < guess.length; i++) + { + if(guess[i] == '*') + { + continue; + } + else if(guess[i] != str.charAt(i)) + { + return false; + } + } + return true; + } + public static void updateTodo(String todo, ArrayList dict, int [] index) + { + for(int i = 0; i < index.length; i++) + index[i] = 0; + + for(String str : dict) + { + for(int i = 0; i < str.length(); i++) + { + index[todo.indexOf(str.charAt(i))] = 1; + } + } + } + public static boolean updateGuess(char [] guess, String word, char c) + { + boolean found = false; + for(int i = 0; i < word.length(); i++){ + if(word.charAt(i) == c){ + guess[i] = c; + found = true; + } + } + return found; + } + public static void solveFreeCell() + { + try{ + freader = new Scanner( + new File(""C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/A-large-practice.in"")); + caseCount = freader.nextInt(); + freader.nextLine(); + + int caseIdx; + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + System.out.print(""Case #"" + (caseIdx+1) + "": ""); + + BigInteger n = new BigInteger(freader.next()); + long pd = freader.nextInt(); + long pg = freader.nextInt(); + + if(pd > 0 && pg == 0) + { + System.out.println(""Broken""); + continue; + } + + if(pd == 0 && pg == 100) + { + System.out.println(""Broken""); + continue; + } + + if(pd == 0 && pg != 100) + { + System.out.println(""Possible""); + continue; + } + + if(pd < 100 && pg == 100) + { + System.out.println(""Broken""); + continue; + } + + if(n.compareTo(new BigInteger(""100"")) >= 0){ + System.out.println(""Possible""); + continue; + } + + double den; + long div; + div = gcd(pd, 100); + den = (double)100/div; + + + + if(den > n.intValue()) + { + System.out.println(""Broken""); + continue; + } + System.out.println(""Possible""); + freader.nextLine(); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static long gcd(long x, long y) + { + while(x != y) + { + //System.out.println(x + "" "" + y); + if(x > y) + { + x = x - y; + } + else{ + y = y - x; + } + } + return x; + } + + public static void solveMagika() + { + try{ + freader = new Scanner( + new File(""C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/codejam/B-large-practice.in"")); + caseCount = freader.nextInt(); + freader.nextLine(); + + int caseIdx; + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + TreeMap oppMap = new TreeMap(); + TreeMap comMap = new TreeMap(); + ArrayList list = new ArrayList(); + + int c = freader.nextInt(); + + for(int i = 0; i < c; i++) + { + String str = freader.next(); + String rev = new StringBuffer(str.substring(0,2)).reverse().toString(); + comMap.put(str.substring(0, 2), str.substring(2)); + comMap.put(rev.substring(0, 2), str.substring(2)); + } + + int d = freader.nextInt(); + + for(int i = 0; i < d; i++) + { + String str = freader.next(); + String rev = new StringBuffer(str).reverse().toString(); + oppMap.put(str, str); + oppMap.put(rev, rev); + } + + int n = freader.nextInt(); + + String todo = freader.next(); + + //System.out.println(todo); + + Magika(caseIdx+1, n, todo, comMap, oppMap, list); + + freader.nextLine(); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static void Magika(int caseIdx, int n, String todo, TreeMap comMap, TreeMap oppMap, ArrayList list) + { + list.add(todo.substring(0,1)); + + for(int i = 1; i < n; i++) + { + list.add(todo.substring(i,i+1)); + + int size = list.size(); + + if(size >= 2){ + String newElement + = comMap.get( list.get(size-2).concat(list.get(size-1)) ); + if(newElement != null) + { + list.remove(list.size()-1); + list.remove(list.size()-1); + list.add(newElement); + } + } + check(oppMap, list); + } + + System.out.print(""Case #"" + caseIdx + "": [""); + if(list.isEmpty()) + { + System.out.println(""]""); + } + else + { + for(int i = 0; i < list.size()-1; i++) + { + System.out.print(list.get(i) + "", ""); + } + System.out.println(list.get(list.size()-1) + ""]""); + } + } + + public static void check(TreeMap oppMap, ArrayList list) + { + int size = list.size(); + for(int j = 0; j < size-1; j++) + { + for(int k = 0; k < size; k++) + { + if(oppMap.containsKey(list.get(j).concat(list.get(k)))) + { + list.clear(); + return; + } + } + } + } + + public static void solveBotTrust() + { + try{ + freader = new Scanner( + new File(""C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/codejam/A-large-practice.in"")); + + caseCount = freader.nextInt(); + freader.nextLine(); + + int caseIdx; + for(caseIdx = 0; caseIdx < caseCount; caseIdx++) + { + int n = freader.nextInt(); + + int buttons [] = new int [n]; + String robots [] = new String [n]; + + int i; + for(i = 0; i < n; i++) + { + robots[i] = freader.next(); + buttons[i] = freader.nextInt(); + } + + BotTrust(caseIdx+1, robots, buttons, n); + freader.nextLine(); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static void BotTrust(int caseIdx, String [] robots, int [] buttons, int n) + { + int turn, seconds; + boolean buttonPressed; + Robot B, O, active, passive; + + turn = 0; + seconds = 0; + + B = new Robot(""B""); + O = new Robot(""O""); + + for(int i = 0; i < n; i++) + if(robots[i].equals(""B"")){ + B.nextPosition = buttons[i]; + break; + } + + for(int i = 0; i < n; i++) + if(robots[i].equals(""O"")){ + O.nextPosition = buttons[i]; + break; + } + +// System.out.println(""orange pos : "" + O.nextPosition); +// System.out.println(""blue pos : "" + B.nextPosition); + + while(turn < n) + { + seconds++; + buttonPressed = false; + + if(robots[turn].equals(""O"")){ + active = O; + passive = B; + } + else{ + active = B; + passive = O; + } + int moveIncr; + + if(active.currPosition == active.nextPosition){ + moveIncr = 0; + }else if(active.currPosition < active.nextPosition){ + moveIncr = 1; + }else{ + moveIncr = -1; + } + + if(moveIncr == 0) + { + buttonPressed = true; + } + else{ + active.currPosition = active.currPosition + moveIncr; + } + + if(passive.currPosition == passive.nextPosition){ + moveIncr = 0; + }else if(passive.currPosition < passive.nextPosition){ + moveIncr = 1; + }else{ + moveIncr = -1; + } + + passive.currPosition = passive.currPosition + moveIncr; + + if(buttonPressed){ + turn++; + for(int i = turn; i < n; i++){ + if(robots[i].equals(active.name)) + { + active.nextPosition = buttons[i]; + break; + } + } + } + } + + System.out.println(""Case #"" + caseIdx + "": "" + seconds); + } + + private static class Robot + { + int currPosition, nextPosition; + String name; + + public Robot(String _name) + { + currPosition = 1; + nextPosition = 0; + name = _name; + } + } + +} +" +A23053,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.InputStreamReader; +public class GooglersDance { + static int output = 0; + static int numberOfDancers = 0; + static int surprise = 0; + static int bestResult = 0; + + public static void main(String[] args) { + try { + + InputStreamReader isr = new InputStreamReader(System.in); + BufferedReader reader = new BufferedReader(new FileReader(""e:/B-small-attempt0.in"")); + int totalLines = Integer.parseInt(reader.readLine()); + for(int k=0;k= bestResult) + { + output++; + }else if(av+1 >= bestResult && av+1 <= i && surprise > 0) + { + output++; + surprise--; + } + }else if(rem == 1) + { + if((av >= bestResult || av+1 >= bestResult) && av+1 <= i) + output++; + }else + { + if((av >= bestResult || av+1 >= bestResult) && av+1 <= i ) + { + output++; + }else if(av+2 >= bestResult && surprise > 0 && av+1 <= i ) + { + output++; + surprise--; + } + } + } +} +" +A22480,"package QR_2012; + +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class B { + + static BufferedWriter writer; + + public static void main(String[] args) throws IOException { + writer = new BufferedWriter(new FileWriter(""output.out"")); + Scanner reader = new Scanner(new FileReader(""input.in"")); + int nt = reader.nextInt(); + reader.nextLine(); + for(int tc = 1; tc <= nt; tc++) { + writer.write(""Case #"" + tc + "": ""); + int n = reader.nextInt(); + int s = reader.nextInt(); + int p = reader.nextInt(); + int count = 0; + for(int i = 0; i < n; i++) { + int t = reader.nextInt(); + if(canDoNormally(t, p)) { + count++; + } else if(s > 0 && canDoNormallyWith2(t, p)) { + count++; + s--; + } + } + writer.write(Integer.toString(count)); + writer.newLine(); + } + writer.close(); + } + + static boolean canDoNormallyWith2(int t, int p) { + for(int i = 3; i <= 4; i++) { + if((t + i) % 3 == 0 && (t + i) / 3 >= p && (t + i) / 3 - 2 >= 0) { + return true; + } + } + return false; + } + + static boolean canDoNormally(int t, int p) { + if(t % 3 == 0 && t / 3 >= p) { + return true; + } + if((t + 1) % 3 == 0 && (t + 1) / 3 >= p && (t + 1) / 3 - 1 >= 0) { + return true; + } + if((t + 2) % 3 == 0 && (t + 2) / 3 >= p && (t + 2) / 3 - 1 >= 0) { + return true; + } + return false; + } + +} +" +A21620,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package test2; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Scanner; + +/** + * + * @author Student + */ +public class Test2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException { + // TODO code application logic here + int i=1; + Scanner ss=new Scanner(new File(""B-large.in.txt"")); + PrintWriter x=new PrintWriter(new File(""B-large.out.txt"")); + if(ss.hasNext()) ss.next(); + while(ss.hasNextLine()&&i<=100){ + int n = 0; + if(ss.hasNext()) n=Integer.parseInt(ss.next()); + int s = 0; + if(ss.hasNext()) s=Integer.parseInt(ss.next()); + int p = 0; + if(ss.hasNext()) p=Integer.parseInt(ss.next()); + LinkedList l=new LinkedList<>(); + for(int index=0;index scores; + + private int S; + + private int p; + + @Override + public void solve() { + solution = 0; + int equit = 3 * p; + for (Integer score : scores) { + if (score >= p) { + int diff = equit - score; + if (diff < 3) { + solution++; + } else if (diff < 5 && S > 0) { + S--; + solution++; + } + } + } + } + + @Override + public Object getSolution() { + return solution; + } + + public void setSolution(Integer solution) { + this.solution = solution; + } + + public int getP() { + return p; + } + + public void setP(int p) { + this.p = p; + } + + public int getS() { + return S; + } + + public void setS(int s) { + S = s; + } + + public List getScores() { + return scores; + } + + public void setScores(List scores) { + this.scores = scores; + } + +} +" +A22419,"package small; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction; + +public class DancingGooglers { + private static int noOfCases; + private static int[] noOfGooglers; + private static int[] noOfSurprisingTriplets; + private static int[] bestResult; + private static int[][] scores; + private static String[] result; + + public static void main(String[] args) { + + readInputFile(); + result = new String[noOfCases]; + + for (int i = 0; i < noOfCases; i++) { + int totalSum = 0; + int surprisingCount = 0; + for (int j = 0; j < noOfGooglers[i]; j++) { + // System.out.print("" ""+scores[i][j]); + if (scores[i][j] >= bestResult[i]) { + if ((scores[i][j] - bestResult[i]) / 2 >= bestResult[i] - 2) { + totalSum++; + if ((scores[i][j] - bestResult[i]) / 2 == bestResult[i] - 2) { + surprisingCount++; + } + } + } + + } + + if (surprisingCount > noOfSurprisingTriplets[i]) { + totalSum = totalSum + - (surprisingCount - noOfSurprisingTriplets[i]); + } + System.out.println(); + System.out.println(""Case #"" + (i + 1) + "": "" + totalSum); + result[i] = ""Case #"" + (i + 1) + "": "" + totalSum; + + } + + writeToFile(result); + + } + + private static void readInputFile() { + + try { + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + noOfCases = Integer.parseInt(br.readLine()); + String strLine; + scores = new int[noOfCases][]; + noOfGooglers = new int[noOfCases]; + noOfSurprisingTriplets = new int[noOfCases]; + bestResult = new int[noOfCases]; + for (int i = 0; i < noOfCases; i++) { + strLine = br.readLine(); + String[] temp = strLine.split("" ""); + noOfGooglers[i] = Integer.parseInt(temp[0]); + noOfSurprisingTriplets[i] = Integer.parseInt(temp[1]); + bestResult[i] = Integer.parseInt(temp[2]); + scores[i] = new int[noOfGooglers[i]]; + + // System.out.println(""No of Googlers: ""+noOfGooglers); + // System.out.println(""No of surp trip: ""+noOfSurprisingTriplets); + // System.out.println(""Best Result: ""+bestResult); + + for (int j = 0; j < noOfGooglers[i]; j++) { + scores[i][j] = Integer.parseInt(temp[3 + j]); + System.out.println(scores[i][j]); + } + + } + + in.close(); + } catch (Exception e) { + e.printStackTrace(); + System.err.println(""Error: "" + e.getMessage()); + } + } + + public static void writeToFile(String args[]) { + try { + FileWriter fstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + for (int i = 0; i < args.length; i++) { + out.write(args[i]); + if (i != args.length - 1) + out.newLine(); + } + out.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A21592,"import java.io.BufferedReader; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; + +/** Main function is ""solve"" **/ +public class CodeJamProblem2 { + + static HashMap mappings=null; + public static void main(String args[]) + { + solve(); + } + + private static void solve() { + readFromInputAndWriteInOutput(); + } + + private static void readFromInputAndWriteInOutput() { + try { + File f = new File(""B-large.in""); + FileReader fileReader = new FileReader(f); + BufferedReader buff = new BufferedReader(fileReader); + String totalTestCases = buff.readLine(); + PrintWriter printWriter = new PrintWriter(""B-large.out""); + int testCases = Integer.parseInt(totalTestCases); + for(int i =1;i<=testCases;i++) + { + + String line = buff.readLine(); + String outputLine = ""Case #""+i+"": ""; + String result = solveForThisLine(line); + outputLine = outputLine.concat(result); + printWriter.println(outputLine); + //System.out.println(outputLine); + } + printWriter.close(); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private static String solveForThisLine(String line) { + + String splitS[] = line.split("" ""); + int numberOfGooglers = Integer.parseInt(splitS[0]); + int numberOfSurprisingScores = Integer.parseInt(splitS[1]); + int reqP = Integer.parseInt(splitS[2]); + int result = 0; + int number=0; + int quo = 0; + int rem = 0; + for(int i = 3;i=reqP || (rem+quo)>=reqP) + { + result=result+1; + continue; + } + else + { + if(numberOfSurprisingScores>=1) + { + number +=2; + quo = number/3; + rem = number%3; + rem = rem==0? 0 : 1; + if(quo>=reqP || (rem+quo)>=reqP) + { + result=result+1; + numberOfSurprisingScores=numberOfSurprisingScores-1; + continue; + } + + } + + } + } + return result+""""; + } +} +" +A20445,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class Dancer { + +public static void main(String args[]) throws FileNotFoundException{ + + Scanner in=new Scanner(new FileInputStream(""input2.txt"")); + + int T=in.nextInt(); + + System.out.println(""T : "" + T); + + int N,P,S,temp; + + int clear=0,surprise=0; + + for(int i=1;i<=T;i++) + { + clear=0; + + surprise=0; + + N=in.nextInt(); + + S=in.nextInt(); + + P=in.nextInt(); + + //System.out.println(""N : "" + N); + + //System.out.println(""S : "" + S); + + //System.out.println(""P : "" + P); + + + if(P==0) + { + for(int j=1;j<=N;j++) + { + temp=in.nextInt(); + clear++; + } + } + + else if(P==1) + { + for(int j=1;j<=N;j++) + { + temp=in.nextInt(); + + if(temp>=P) + clear++; + } + } + + else{ + for(int j=1;j<=N;j++) + { + temp=in.nextInt(); + + if(temp>3*P-3) + clear++; + + else if((temp==3*P-3)||(temp==3*P-4)) + surprise++; + } + //System.out.println(""clear: "" + clear); + + //System.out.println(""surprise : "" + surprise); + } + System.out.println(""Case #"" + i + "": "" + (clear+Math.min(surprise,S))); + } + + } +} +" +A20722,"import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.HashMap; + +public class DancingGooglers { + + + + /** + * @param args + */ + public static void main(String[] args) { + try { + + File inf = new File(""/home/jeyram/Downloads/""+""B-large.in""); + File of = new File(""/home/jeyram/Downloads/""+""rl-dg2-output.in""); + FileInputStream in = new FileInputStream(inf); + FileOutputStream out = new FileOutputStream(of); + // Get the object of DataInputStream + //DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + if ((strLine = br.readLine()) != null) { + System.out.println (strLine); + int itrs= Integer.parseInt(strLine); + int count=0; + //#test cases + while (count < itrs) { + if ((strLine = br.readLine()) != null){ + // input str + String[] inst = strLine.split("" ""); + //number of googlers + int N = Integer.parseInt(inst[0]); + //number of surprises atleast ==2 + int S = Integer.parseInt(inst[1]); + //result of atleast p + int p = Integer.parseInt(inst[2]); + //max no of googlers with p + int y=0; + //scores list + int[] ti = new int[inst.length-3]; + int j=0; + for(int i=3;i0)?ti[j]/3:0; + int r = (ti[j]>0)?ti[j] % 3:0; + if(q==0&& r==0){ + if(q>=p){ + y++; + } + }else + //eliminate surprise count + //divis by 3 r 0 + //2 strat one sur :n,n,n | n+1,n-1,n (sur) + if (r==0){ + //regular strat + if(q>=p){ + y++; + }else{ + if(S>0){//surprise strat + if(((q+1)>=p) || (q>=p) || ((q-1)>=p)){ + y++;S--; + } + } + } + + } + //divis by 3 r 1 + //2 strat one sur :n,n,n+1 | n+1,n-1,n+1 (sur) + else if(r==1){ + //regular strat + if(((q+1)>=p) || (q>=p)){ + y++; + } else { + if(S>0){//surprise strat + if(((q+1)>=p) || ((q-1)>=p)){ + y++;S--; + } + } + } + } + //divis by 3 r 2 + //2 strat one sur :n+1,n+1,n |n+2,n,n (sur) + else if(r==2){ + + //regular strat + if(((q+1)>=p) || (q>=p)){ + y++; + } else { + if(S>0){//surprise strat + if(((q+2)>=p) || ((q)>=p)){ + y++;S--; + } + } + } + } + j++; + } + + System.out.println(""output string""+y); + //write as Case #1: 2 3 + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); + bw.write(""Case #""+(count+1)+"": ""+y); + bw.newLine(); + bw.flush(); + } + count++; + } + + } + //Close the input stream + in.close(); + out.close(); + }catch (Exception e) + { + e.printStackTrace(); + } + finally{ + + } + } +}" +A21298,"package y2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +public class DancingWiththeGooglers { + static public void main(String args[]) throws IOException { + System.setIn(new FileInputStream(""src/y2012/B-large.in"")); + // System.setIn(new FileInputStream(""src/y2012/B-small-attempt0.in"")); + BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter wr = new BufferedWriter(new FileWriter(""src/y2012/B-large.out"")); + // BufferedWriter wr = new BufferedWriter(new FileWriter(""src/y2012/B-small-attempt0.out"")); + int nTests = Integer.valueOf(cin.readLine()); + String line; + int tid = 0; + while ((line = cin.readLine()) != null) { + String[] sa = line.split(""\\s+""); + int N = Integer.parseInt(sa[0]); + int S = Integer.parseInt(sa[1]); + int p = Integer.parseInt(sa[2]); + int rlst = 0, a1 = 0, a2 = 0; + for (int i = 0; i < N; i++) { + int tii = Integer.parseInt(sa[i + 3]); + if (tii >= p) + if (tii >= 3 * p + 5) + rlst++; + else if (tii <= 3 * p + 4 && tii >= 3 * p - 2) + a1++; + else if (tii == 3 * p - 3 || tii == 3 * p - 4) + a2++; + } + rlst += a1; + rlst += Math.min(S, a2); + ++tid; + wr.write(""Case #"" + tid + "": "" + rlst + ""\n""); + } + wr.close(); + cin.close(); + } +}" +A22826,"package mgg.utils; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +/** + * @author manolo + * @date 13/04/12 + */ +public class StringUtils { + + public static List stringWithIntegersToList(String str, int numItems, String delim){ + + ArrayList list = new ArrayList(); + StringTokenizer tokenizer = new StringTokenizer(str, delim); + if (tokenizer.countTokens() != numItems){ + throw new RuntimeException(""EXCEPTION: The string \"""" + str + + ""\"" has more tokens ("" + tokenizer.countTokens() + + "") than you said ("" + numItems + "")""); + } + for (int i = 0; i < numItems; i++) { + list.add(Integer.parseInt(tokenizer.nextToken())); + } + + return list; + } + + public static List stringWithIntegersToList(String str, String delim){ + + ArrayList list = new ArrayList(); + StringTokenizer tokenizer = new StringTokenizer(str, delim); + int numOfTokens = tokenizer.countTokens(); + for (int i = 0; i < numOfTokens; i++) { + list.add(Integer.parseInt(tokenizer.nextToken())); + } + + return list; + } + + public static List stringWithStringsToList(String str, int numItems, String delim){ + + ArrayList list = new ArrayList(); + StringTokenizer tokenizer = new StringTokenizer(str, delim); + if (tokenizer.countTokens() != numItems){ + throw new RuntimeException(""EXCEPTION: The string \"""" + str + + ""\"" has more tokens ("" + tokenizer.countTokens() + + "") than you said ("" + numItems + "")""); + } + for (int i = 0; i < numItems; i++) { + list.add(tokenizer.nextToken()); + } + + return list; + } + + public static List stringWithStringsToList(String str, String delim){ + + //System.out.println(""String: "" + str); + + ArrayList list = new ArrayList(); + StringTokenizer tokenizer = new StringTokenizer(str, delim); + + //System.out.println(""tokenizer.countTokens() = "" + tokenizer.countTokens()); + + int numOfTokens = tokenizer.countTokens(); + for (int i = 0; i < numOfTokens; i++) { + list.add(tokenizer.nextToken()); + } + + return list; + } + + public static List allCharactersToList(String str) { + + System.out.println(""String: "" + str); + + ArrayList list = new ArrayList(); + + for (int i = 0; i < str.length(); i++) { + list.add(str.charAt(i)); + } + + System.out.println(""List of characters: "" + list); + + return list; + } +} +" +A22971,"package org.weiwei.googlejam; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: ding + * Date: 12-4-14 + * Time: 上午11:28 + * To change this template use File | Settings | File Templates. + */ +public class DancingGroup { + + List dancings; + int total; + + public DancingGroup(List dancings, int total) { + this.dancings = dancings; + this.total = total; + } + + public static DancingGroup laodFromFile(String input) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(input)); + String line = reader.readLine(); + int total = Integer.parseInt(line.trim()); + List dancingList = new ArrayList(); + line = reader.readLine(); + while(line != null) { + dancingList.add(Dancing.loadFromString(line)); + line = reader.readLine(); + } + reader.close(); + return new DancingGroup(dancingList, total); + } + + public void outputResult(String outputFile) throws FileNotFoundException { + PrintWriter pw = new PrintWriter(outputFile); + for(int i = 1; i < total+1; i++){ + if(i!=1) + pw.write(""\r\n""); + pw.write(""Case #""+i+"": ""+dancings.get(i-1).getNumber()); + } + pw.close(); + } + + public static void main(String[] args) throws IOException { + DancingGroup group = DancingGroup.laodFromFile(""F:\\input.txt""); + group.outputResult(""F:\\output.txt""); + } +} +" +A20476,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * Created with IntelliJ IDEA. + * User: akim + * Date: 4/14/12 + * Time: 7:29 PM + * To change this template use File | Settings | File Templates. + */ +public class B { + + void solve() throws FileNotFoundException { + PrintWriter out = new PrintWriter(new FileOutputStream(""output.txt"")); + Scanner in = new Scanner(new FileInputStream(""input.txt"")); + int t = Integer.parseInt(in.nextLine()); + System.err.println(t); + for (int i = 0; i < t; ++i) { + out.print(""Case #"" + (i+1) + "": ""); + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int ans = 0; + for (int j = 0; j < n; ++j) { + int r = in.nextInt(); + boolean ok = false; + for (int A = 0; A <= 10; ++A) + for (int B = A; B <= A + 1; ++B) + for (int C = B; C <= A + 1; ++C) + if (A + B + C == r && C >= p) { + ok = true; + } + if (!ok && s > 0) { + for (int A = 0; A <= 10; ++A) + for (int B = A; B <= A + 2; ++B) + for (int C = B; C <= A + 2; ++C) + if (A + B + C == r && C >= p) { + ok = true; + } + if (ok) --s; + } + if (ok) ++ans; + } + out.println(ans); + System.out.println((i+1) + "" "" + ans); + } + out.flush(); + out.close(); + } + + + public static void main(String[] args) throws FileNotFoundException { + new B().solve(); + } +} +" +A22417," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author JOSE + */ +public class DancingWithTheGooglers { + + public void process() { + ArrayList inputList = readFile(""B-large.in""); + String output = """"; + int testCase = 0; + for (int i = 0; i < inputList.size(); i++) { + String input = inputList.get(i); + if (i == 0) { + testCase = Integer.parseInt(input); + } else { + int result = eachTestcaseProcess(input); + output = output + ""Case #"" + i + "": "" + result; + if (i != (inputList.size() - 1)) { + output = output + '\n'; + } + } + } + writeFile(output); + } + + public int eachTestcaseProcess(String input) { + // String test = ""3 1 5 15 13 11""; + String spliInputt[] = input.split(""\\s""); + int googler = 0; + int serprise = 0; + int p = 0; + double[] totalpoint = null; + int resultCount = 0; + + for (int i = 0; i < spliInputt.length; i++) { + if (i == 0) { + googler = Integer.parseInt(spliInputt[i]); + totalpoint = new double[googler]; + } else if (i == 1) { + serprise = Integer.parseInt(spliInputt[i]); + } else if (i == 2) { + p = Integer.parseInt(spliInputt[i]); + } else { + totalpoint[i - 3] = Double.parseDouble(spliInputt[i]); + } + } + + int[][] triplet = new int[googler][3]; + + for (int i = 0; i < totalpoint.length; i++) { + double divide = totalpoint[i] / 3; + double mod = totalpoint[i] % 3; + + triplet[i][0] = (int) divide; + triplet[i][1] = (int) divide; + triplet[i][2] = (int) divide; + for (int j = 0; j < mod; j++) { + triplet[i][j]++; + } + } + + for (int i = 0; i < triplet.length; i++) { + boolean flag = false; + int checkSurprising = 0; + while (checkSurprising != -1) { + checkSurprising = findSurprising(triplet, i); + if (checkSurprising != -1) { + + flag = isEquealOrGreaterThanP(triplet, p, i); + if (flag && (checkSurprising != 1 || serprise > 0)) { + if (checkSurprising == 1) { + serprise--; + } + resultCount++; + checkSurprising = -1; + } else { + if (triplet[i][1] > 0) { + triplet[i][0]++; + triplet[i][1]--; + } else { + checkSurprising = -1; + } + } + } + } + } + + return resultCount; + } + + private int findSurprising(int[][] triplet, int i) { + int a = (triplet[i][0] - triplet[i][1]); + int b = (triplet[i][0] - triplet[i][2]); + int c = (triplet[i][1] - triplet[i][2]); + int result = -1; + if (a < 2 && b < 2 && c < 2) { + result = 0; + } else if ((a <= 2 && b <= 2 && c <= 2)) { + result = 1; + } + return result; + } + + private boolean isEquealOrGreaterThanP(int[][] triplet, int p, int i) { + boolean result = false; + for (int j = 0; j < 3; j++) { + if (triplet[i][j] >= p) { + result = true; + } + } + return result; + } + + private ArrayList readFile(String fileName) { + + BufferedReader br = null; + ArrayList inputList = null; + try { + File file = new File(fileName); + br = new BufferedReader(new FileReader(file)); + String message = null; + inputList = new ArrayList(); + while ((message = br.readLine()) != null) { + inputList.add(message); + } + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + try { + br.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + return inputList; + } + } + + private void writeFile(String message) { + BufferedWriter bw = null; + try { + File file = new File(""Output.txt""); + bw = new BufferedWriter(new FileWriter(file)); + bw.write(message); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + try { + bw.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + + public static void main(String[] args) { + DancingWithTheGooglers dwtg = new DancingWithTheGooglers(); + dwtg.process(); + } +} +" +A21731,"package es.uam.eps.abk.qualification2012; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Scanner; + +/** + * + * Dancing With the Googlers + * + * You're watching a show where Googlers (employees of Google) dance, and then + * each dancer is given a triplet of scores by three judges. Each triplet of scores + * consists of three integer scores from 0 to 10 inclusive. The judges have very + * similar standards, so it's surprising if a triplet of scores contains two + * scores that are 2 apart. No triplet of scores contains scores that are more + * than 2 apart. + * + * For example: (8, 8, 8) and (7, 8, 7) are not surprising. + * (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. + * + * The total points for a Googler is the sum of the three scores in that + * Googler's triplet of scores. The best result for a Googler is the maximum + * of the three scores in that Googler's triplet of scores. + * Given the total points for each Googler, as well as the number of surprising + * triplets of scores, what is the maximum number of Googlers that could have + * had a best result of at least p? + * + * @author Alejandro + */ +public class B { + + private static void solve(InputStream in, PrintStream out) { + Scanner scan = new Scanner(in); + int T = scan.nextInt(); // test cases + for (int t = 1; t <= T; t++) { + int N = scan.nextInt(); // number of Googlers + int S = scan.nextInt(); // number of surprising scores + int p = scan.nextInt(); // best result + + int[] points = new int[N]; // total points + for (int i = 0; i < N; i++) { + points[i] = scan.nextInt(); + } + + int n = getGooglers(points, S, p); + + out.println(""Case #"" + t + "": "" + n); + } + } + + private static int getGooglers(int[] points, int surprisingScores, int bestResult) { + int n = 0; + double[] avg = new double[points.length]; + for (int i = 0; i < points.length; i++) { + avg[i] = 1.0 * points[i] / 3; + } + Arrays.sort(avg); +// System.out.println(Arrays.toString(avg)); + for (int i = points.length - 1, j = 0; i >= 0 && j < surprisingScores; i--) { + double m = Math.ceil(avg[i]); + if ((m > 0.0) && (m < bestResult)) { + avg[i] += 2.0 / 3; + j++; + } + } +// System.out.println(Arrays.toString(avg)); + for (int i = 0; i < points.length; i++) { + double m = Math.ceil(avg[i]); + if (m >= bestResult) { + n++; + } + } + for (int i = points.length - 1, j = 0; i >= 0 && j < surprisingScores; i--, j++) { + avg[i] -= 2.0 / 3; + } + return n; + } + + public static void main(String[] args) throws Exception { + String file = null; + file = ""inputB2012.txt""; + + file = ""2012B-small-attempt0.in""; + + file = ""2012B-large.in""; + + InputStream in = new FileInputStream(file); + PrintStream out = new PrintStream(""output."" + file); + + solve(in, out); + + in.close(); + out.close(); + } +} +" +A22093,"import java.io.*; +import java.util.Scanner; + +public class functions { + int mod(int a){ + int b = 0; + if(a > 0) b = a; else b = -a; + + return b; + } + int solve(int[] a, int p, int s, int n){ + int result = 0; + int i = 0; + int x = 0; + int onlyS = 0; + int onlyNotS = 0; + int both = 0; + int none = 0; + for ( i = 0;i < n; i++){ + x = a[i]/3; + if(a[i]%3 ==0){ + + if(a[i] == 30){ + onlyNotS++; + + } + else if(p==x+1 && a[i]!=0){ + onlyS++; + + } + else if ( p<=x ){ + both++; + + } + else{ + + none++; + } + } + else if(a[i]%3 ==1){ + + if(a[i]==1 && p<=1){ + onlyNotS++; + } + else if(p <= x+1){ + both++; + } + else none++; + } + else{ + + if(a[i] == 29){ + + onlyNotS++; + } + else if(p == x+2){ + + onlyS++; + } + else if(p <= x+1){ + + both++; + } + else { + none++; + + } + } + + } + + + if(onlyS <= s){ + result = both+onlyNotS+onlyS; + } + else{ + result = s+both+onlyNotS; + } + + return result; + } +} +" +A22638,"package Qualification_Round_2012; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class B { + + public static void main(String[] args) throws FileNotFoundException, IOException { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(""b.out""); + StringTokenizer k; + int t,n,s,p,count,player,reminder; + t=Integer.parseInt(in.readLine().trim()); + for (int i = 1; i <= t; i++) { + k=new StringTokenizer(in.readLine()); + n=Integer.parseInt(k.nextToken()); + s=Integer.parseInt(k.nextToken()); + p=Integer.parseInt(k.nextToken()); + if(p==0){ + out.append(""Case #""+i+"": ""+n+""\n""); + continue; + } + count=0; + for (int j = 0; j < n; j++) { + player=Integer.parseInt(k.nextToken()); + if(player==0)continue; + reminder=player%3; + switch (reminder){ + case 0: + if(player/3>=p) + count++; + else if(s>0 && (player/3)+1>=p){ + count++; + s--; + } + break; + case 1: + if((player/3)+1>=p) + count++; + break; + case 2: + if((player/3)+1>=p) + count++; + else if(s>0 && (player/3)+2>=p){ + count++; + s--; + } + break; + } + } + out.append(""Case #""+i+"": ""+count+""\n""); + } + out.close(); + } +}" +A20468,"import java.util.*; +import java.io.*; + +public class B { + static int dp[][]; + static int N, S, p, t[]; + public static void main(String[] args) throws FileNotFoundException { + Scanner sc = new Scanner(System.in); + System.setOut(new PrintStream(new File(""B.out""))); + int T = sc.nextInt(); + for(int ca = 1; ca <= T; ca++) { + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + t = new int[N]; + for(int i=0; i 0) return -10000; + if(n == 0) return 0; + if(dp[n][s] >= 0) return dp[n][s]; + int res = 0; + for(int x=0; x<=10; x++) { + for(int y=x; y<=x+2&&y<=10; y++) { + int z = t[n-1] - x - y; + if(z < 0 || z > 10) continue; + if(z < y - 2 || z > x + 2) continue; + int max = Math.max(y, z); + if(Math.abs(x - y) == 2 || Math.abs(x-z) == 2 || Math.abs(y-z) == 2) { + if(max >= p) res = Math.max(res, search(n-1, s-1) + 1); + else res = Math.max(res, search(n-1, s-1)); + } else { + if(max >= p) res = Math.max(res, search(n-1, s) + 1); + else res = Math.max(res, search(n-1, s)); + } + } + } + return dp[n][s] = res; + } +} +" +A22468,"import java.lang.reflect.Array; +import java.util.*; + +public class ArrayUtil { + static T[] revers (T[] t){ + List list = Arrays.asList(t); + Collections.reverse(list); + return (T[]) list.toArray(); + } + + static Map listToMap(List list) { + HashMap map = new HashMap<>(); + for (int i = 0; i < list.size(); i++) { + T t = list.get(i); + map.put(t,i); + } + return map; + } + + static List fromIndexList(List inds, List values) { + ArrayList ts = new ArrayList<>(); + for (Integer ind : inds) { + ts.add(values.get(ind)) ; + } + return ts; + } +} +" +A21184,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam.lib.converters; + +import com.isotopeent.codejam.lib.InputConverter; + + +public class StringLine implements InputConverter { + + private String input; + + @Override + public boolean readLine(String data) { + input = data; + return false; + } + + @Override + public String generateObject() { + return input; + } + +} +" +A21188,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam.lib; + +public abstract class SolverBase { + + private InputReader inputReader; + protected int[] params; + + public SolverBase(int initParamCount) { + if (initParamCount > 0) { + params = new int[initParamCount]; + } + } + + public void init(InputReader inputReader) { + this.inputReader = inputReader; + + if (params != null) { + try { + String line = inputReader.readLine(); + params = Utils.convertToIntArray(line, params.length); + } catch (Exception e) { + System.err.println(""Error while reading initial parameters""); + e.printStackTrace(); + } + } + } + + public final String solveNext() { + String solution = null; + T input = inputReader.readInput(); + if (input != null) { + solution = solve(input); + } + return solution; + } + + protected abstract String solve(T input); + +} +" +A20368,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +/** + * + * @author Dylan + */ +public class GooglerDance { + int suprises; + public GooglerDance(int sup) + { + suprises = sup; + + } + + public int getNumAboveP(int[] scores, int p) + { + int rNum = 0; + for(int i = 0; i < scores.length; i++) + { + if(testAbove(scores[i], p)) + rNum++; + } + return rNum; + } + + public boolean testAbove(int total, int p) + { + if(p == 0) + return true; + if(total == 0) + return false; + total -= p; + if(p - total/2 < 2) + return true; + if(p - total/2 < 3 && suprises > 0) + { + suprises--; + return true; + } + return false; + + } + + public boolean aboveP(int total, int p) + { + + int avg = total/3; + if(suprises > 0){ + avg += 2; + if(avg > p) + suprises--; + } + if(avg > p) + return true; + return false; + } + +} +" +A21322,"import java.util.StringTokenizer; + + +public class B { + + public int solve(String input){ + int result=0; + StringTokenizer st=new StringTokenizer(input, "" \n""); + int n=Integer.parseInt(st.nextToken()); + int s=Integer.parseInt(st.nextToken()); + int p=Integer.parseInt(st.nextToken()); + int maxThres=0; + int minThres=0; + if(p>1){ + maxThres=(p-1)*3+1; + minThres=(p-2)*3+2; + }else{ + maxThres=p; + minThres=p; + } + while(st.hasMoreTokens()){ + int num=Integer.parseInt(st.nextToken()); + if(num>=maxThres){ + result++; + continue; + } + if(num>=minThres && num0){ + result++; + s--; + } + } + + return result; + } + public static void main(String[] args) { + IOHelper io=new IOHelper(""C:\\skill\\workspace\\cj2012\\src\\B-large.in"", + ""C:\\skill\\workspace\\cj2012\\src\\B-large.out""); + int countOfTest=Integer.parseInt(io.readLine()); + B b=new B(); + for(int i=0;i> map; + + + public static void readProcessOutput() throws Exception{ + + String outputStr = """"; String result = """"; + int index = 1; + + int testCases = Integer.parseInt(scan.nextLine()); + //------- + + + + //------- + + while(index <= testCases ){ //runs testCases number of times + + System.out.println(""Running testcase : "" + index); + int surprises = 0; + int count = 0; + //----------- + Scanner temp = new Scanner(scan.nextLine()); + int N = temp.nextInt(); + int S = temp.nextInt(); + int p = temp.nextInt(); + int scores[] = new int[N]; + Integer triplet[][] = new Integer[N][3]; + map = new HashMap>(); + + for(int i =0; i < N; i++){ + scores[i] = temp.nextInt(); + int j = scores[i] / 3; + triplet[i][0] = j + scores[i] % 3; + if(triplet[i][0] <= 10) + triplet[i][1] = triplet[i][2] = j; + else{ + triplet[i][0] = 10; + triplet[i][1] = j; + triplet[i][2] = j+1; + } + + + + int min = (int) Collections.min(Arrays.asList(triplet[i])); + int max = (int) Collections.max(Arrays.asList(triplet[i])); + + Arrays.sort(triplet[i]); + if(triplet[i][2] < p) + if(max - min == 0 && max != 0){ + triplet[i][0]--; + triplet[i][2]++; + } + + List l = map.get(triplet[i][2]); + if(l == null) + l = new ArrayList(); + + l.add(i); + map.put(triplet[i][2], l); + + if(triplet[i][2] - triplet[i][0] == 2){ + surprises++; + } + } + + Object keys[] = map.keySet().toArray(); + Arrays.sort(keys); + int m = 0; int n = p; + while((m = Arrays.binarySearch(keys, n++)) < 0 && n <= 10); + int r = m; + for(; m < keys.length && m >= 0; m++) + count += map.get(((Integer) keys[m])).size(); + + if(surprises > S){ + + int diff = surprises - S; + int j = 0, k = 0; + while(j < diff && ((Integer) keys[k]) < p){ + //j += map.get(((Integer) keys[k++])).size(); + List t = map.get(((Integer) keys[k++])); + int u = t.size(); + while(--u >= 0){ + int v = t.get(u); + Arrays.sort(triplet[v]); + if(triplet[v][2] - triplet[v][0] == 2) + j++; + if(j == diff) + break; + } + } + + if(k < keys.length && ((Integer) keys[k]) >= p){ + //count -= (diff - j); + int un = diff - j; + int s = keys.length - 1; + while(un > 0){ + List l = map.get(((Integer) keys[s--])); + + int q = 0; + while(q < l.size()){ + int o = l.get(q++); + if(triplet[o][2] - triplet[o][0] == 2){ + triplet[o][2]--; + triplet[o][0]++; + Arrays.sort(triplet[o]); + if(triplet[o][2] < p){ + count--; + } + un--; + if(un == 0) + break; + } + } + } + } + + } + + else if(surprises < S){ + + +// while(surprises < S){ +// List l = map.get(((Integer) keys[r++])); +// +// int q = 0; +// while(q < l.size()){ +// int o = l.get(q++); +// Arrays.sort(triplet[o]); +// +// if(triplet[o][2] - triplet[o][0] < 2 && triplet[o][2] <10){ +// triplet[o][2]++; +// triplet[o][0]--; +// surprises++; +// } +// +// if(triplet[o][2] < p){ +// count--; +// } +// +// if(surprises == S) +// break; +// +// } +// } +// + + + } + + + + + //------------ + + + outputStr = ""Case #"" + index + "": "" + count; + + writer.println(outputStr); + + result = """"; + outputStr = """"; + index++; + + } + + scan.close(); + writer.close(); + + } + + + + static void setApart(Integer [] arr){ + + } + + + + public static void main(String[] args) throws Exception { + + Scanner in = new Scanner(System.in); + String className = B.class.getSimpleName() ; + int choice = 0; + + do{ + + System.out.println(""Enter your choice :""); + System.out.println(""1) Solve small""); + System.out.println(""2) Solve large""); + System.out.print(""Choice : ""); + choice = in.nextInt(); + + switch(choice){ + case 1 : + scan = new Scanner(new File(className + ""-small-practice.in"")); + writer = new PrintWriter(new BufferedWriter(new FileWriter(new File(className +""small.txt"")))); + readProcessOutput(); + System.out.println(""Solved successfully!\n""); + break; + case 2 : + scan = new Scanner(new File(className + ""-large-practice.in"")); + writer = new PrintWriter(new BufferedWriter(new FileWriter(new File(className +""large.txt"")))); + readProcessOutput(); + System.out.println(""Solved successfully!\n""); + break; + } + + + }while (choice != 0); + + System.out.println(""Program finished!""); + + } +} +" +A22900,"package dancing; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; + +public class DanceAllNight { + + + public static void main(String[] args) throws Exception + { + BufferedReader br = new BufferedReader(new FileReader(new File(""test.txt""))); + BufferedWriter wr = new BufferedWriter(new FileWriter(new File(""output.txt""))); + int count = Integer.parseInt(br.readLine()); + int yes,surprising,p,numsurprising,current,div3,output; + String[] buffer; + int[] values; + for(int i=1; i<=count; i++) + { + String line = br.readLine(); + buffer = line.split("" ""); + values = new int[buffer.length]; + for(int j=0; j= p) + { + yes++; + } + else if(div3 == p-1 && current >= p) + { + surprising++; + } + } + else if(current %3 == 1) + { + if(div3 >= p-1 && current >= p) + { + yes++; + } + + } + else + { + if(div3 >= p-1 && current >= p) + { + yes++; + } + else if(div3 == p-2 && current >= p) + { + surprising++; + } + } + + + } + output = Math.min(yes+surprising, yes+numsurprising); + //make sure that its not more than the total # of contestants + //output = Math.min(output, values[0]); + wr.write(""Case #""+i+"": ""+output); + + wr.newLine(); + + } + wr.close(); + } + +} +" +A21933,"package jp.funnything.competition.util; + +import java.math.BigInteger; + +/** + * Utility for BigInteger + */ +public class BI { + public static BigInteger ZERO = BigInteger.ZERO; + public static BigInteger ONE = BigInteger.ONE; + + public static BigInteger add( final BigInteger x , final BigInteger y ) { + return x.add( y ); + } + + public static BigInteger add( final BigInteger x , final long y ) { + return add( x , v( y ) ); + } + + public static BigInteger add( final long x , final BigInteger y ) { + return add( v( x ) , y ); + } + + public static int cmp( final BigInteger x , final BigInteger y ) { + return x.compareTo( y ); + } + + public static int cmp( final BigInteger x , final long y ) { + return cmp( x , v( y ) ); + } + + public static int cmp( final long x , final BigInteger y ) { + return cmp( v( x ) , y ); + } + + public static BigInteger div( final BigInteger x , final BigInteger y ) { + return x.divide( y ); + } + + public static BigInteger div( final BigInteger x , final long y ) { + return div( x , v( y ) ); + } + + public static BigInteger div( final long x , final BigInteger y ) { + return div( v( x ) , y ); + } + + public static BigInteger mod( final BigInteger x , final BigInteger y ) { + return x.mod( y ); + } + + public static BigInteger mod( final BigInteger x , final long y ) { + return mod( x , v( y ) ); + } + + public static BigInteger mod( final long x , final BigInteger y ) { + return mod( v( x ) , y ); + } + + public static BigInteger mul( final BigInteger x , final BigInteger y ) { + return x.multiply( y ); + } + + public static BigInteger mul( final BigInteger x , final long y ) { + return mul( x , v( y ) ); + } + + public static BigInteger mul( final long x , final BigInteger y ) { + return mul( v( x ) , y ); + } + + public static BigInteger sub( final BigInteger x , final BigInteger y ) { + return x.subtract( y ); + } + + public static BigInteger sub( final BigInteger x , final long y ) { + return sub( x , v( y ) ); + } + + public static BigInteger sub( final long x , final BigInteger y ) { + return sub( v( x ) , y ); + } + + public static BigInteger v( final long value ) { + return BigInteger.valueOf( value ); + } +} +" +A22084,"package codejam2012; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Scanner; + +class ProbB{ + public static void main(String[] args) throws FileNotFoundException{ + + File in; + File out; + Scanner sc; + PrintWriter pw; + int T; + + in = new File(""B-large.in""); + out = new File(""B.out""); + + sc = new Scanner(in); + pw = new PrintWriter(out); + + T = sc.nextInt(); + sc.nextLine(); + + for(int j = 1; j<=T; j++){ + int N = sc.nextInt(); + int S = sc.nextInt(); + int S2 = S; + int p = sc.nextInt(); + int ans = 0; + for(int u = 1; u<=N; u++){ + int a = sc.nextInt(); + int e = isEligible(a, p); + switch(e){ + case 2: + ans++; + break; + case 1: + S--; + ans++; + break; + } + + } + if(S<0){ + ans = ans + S; + } + pw.println(""Case #"" + j + "": "" + ans); + } + pw.close(); + + } + static int isEligible(int a, int p){ + int lo = a/3; + int me = (a - lo)/2; + int hi = a - lo - me; + + if(hi>=p){ + return 2; + } + if(hi==me && hi+1>=p && me != 0){ + return 1; + } + else{ + return 0; + } + } + +}" +A20577,"package Controller; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class IO { + + private String fileName; + private BufferedReader reader; + + public IO(String fileName) { + this.fileName = fileName; + createReader(); + } + + public String readLine() { + try { + return reader.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public int readInt() { + try { + return Integer.parseInt(reader.readLine()); + } catch (IOException e) { + e.printStackTrace(); + } + return -1; + } + + private void createReader() { + FileReader file = null; + try { + file = new FileReader(fileName); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + reader = new BufferedReader(file); + } +} +" +A22040,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class dancing { + + + public static void dancers(String input) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""src/test1"")); + String newline; + String line; + StringBuilder bubs = new StringBuilder(); + + + //String[] lines = input.split(""\\r?\\n""); + int T = Integer.parseInt(""""+in.readLine().charAt(0)); + + int i=0; + while ((line=in.readLine())!=null) { + i++; + String[] splitline = line.split(""\\s+""); + int count = 0; + int N = Integer.parseInt(splitline[0]); + int S = Integer.parseInt(splitline[1]); + int p = Integer.parseInt(splitline[2]); + + StringBuilder subs = new StringBuilder(); + subs.append(""Case #"" + i + "": ""); + + for (int j=3;j= 3*p) { + count++; + } else if (t >= 3*p-2 && t>0){ + count++; + } else if ( t>= 3*p-4 && S>0 && t>1) { + count++; + S--; + } + } + subs.append(count); + bubs.append(subs.toString()); + System.out.println(subs.toString()); + } + + + try { + BufferedWriter out = new BufferedWriter(new FileWriter(""output"")); + out.write(bubs.toString()); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} +" +A22750,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package code3; + + import java.io.File; + import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; + import java.lang.IllegalStateException; +import java.util.Arrays; + import java.util.NoSuchElementException; + import java.util.Scanner; + +/** + * + * @author nhan + */ +public class Code3 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException { + // TODO code application logic here + Scanner input; + input = new Scanner( new File( ""B-large.in"" ) ); + FileOutputStream fos= new FileOutputStream(""B-large.out"",false); + try (PrintWriter pw = new PrintWriter(fos)) { + int t,n,s,p; + + t=input.nextInt(); + + for (int i=1;i<=t;i++){ + System.out.print(""Case #""+i+"": ""); + pw.print(""Case #""+i+"": ""); + + n=input.nextInt(); + s=input.nextInt(); + p=input.nextInt(); + + int count = 0; + int count0 = 0; + for (int j=0;jcount0 && s<=n){ + pw.print(count); + + } else { + pw.print(""0""); + + } + + + + pw.print(""\n""); + } + + pw.close(); + } + } +} +" +A21532,"import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + public static void main(String[] args){ + Scanner keyin=new Scanner(System.in); + int T=keyin.nextInt(); + int caseCount=0; + while ((T--)>0){ + int N=keyin.nextInt(); + int S=keyin.nextInt(); + int P=keyin.nextInt(); + int[] googler=new int[N]; + for (int i=0; i googlerScore=new ArrayList(); + + for (int index=0; index0; i--){ + int temp=remainder/i; + remainder-=temp; + arrayInit[3-i]=temp; + } + int[][] arrayScore=new int[2][3]; + arrayScore[0]=arrayInit; + if (arrayInit[0]==arrayInit[1] && arrayInit[1]==arrayInit[2]){ + int[] temp={arrayInit[0]-1,arrayInit[1],arrayInit[2]+1}; + arrayScore[1]=temp; + } + else if (arrayInit[0]==arrayInit[1] && arrayInit[1]!=arrayInit[2]){ + int[] temp={arrayInit[0]-1,arrayInit[1]+1,arrayInit[2]}; + arrayScore[1]=temp; + } + else if (arrayInit[0]!=arrayInit[1] && arrayInit[1]==arrayInit[2]){ + int[] temp={arrayInit[0],arrayInit[1]-1,arrayInit[2]+1}; + arrayScore[1]=temp; + } + //System.out.println(Arrays.deepToString(arrayScore)); + googlerScore.add(arrayScore); + } + + int result=N; + for (int index=0; index0 && googlerScore.get(index)[1][0]<0){ + S--; + result--; + //System.out.println(""S R ""+S+"" ""+result); + } + else if (S>0){ + S--; + //System.out.println(""S ""+S); + } + else if (S<=0) { + result--; + //System.out.println(""R ""+result); + } + } + } + } + System.out.println(""Case #""+caseCount+"": ""+result); + } + } +} +" +A21627,"import java.util.*; +import java.io.*; + +public class dancing { + public static void main(String[] args) throws Throwable { + Scanner input=new Scanner(new File(""dancing.in"")); + PrintWriter out=new PrintWriter(new File(""dancing.out"")); + int cases=input.nextInt(); + for(int test=1;test<=cases;test++) { + int n=input.nextInt(); + int s=input.nextInt(); + int p=input.nextInt(); + int[] t=new int[n]; + for(int i=0;i=p) numNS++; + } + for(int i=0;i=p) numS++; + } + else { + if((t[i]-2)/3+2>=p) numS++; + } + } + int ans=numNS+Math.min(numS-numNS, s); + out.println(""Case #""+test+"": ""+ans); + } + out.close(); + } + }" +A21981,"import java.io.File; +import java.util.Scanner; + + +public class DancingGooglers { + + public static void calculate(File file){ + + String output=""""; + int cases = 0; + String singleLine = """"; + try{ + Scanner scanner = new Scanner(file); + cases = Integer.parseInt(scanner.nextLine()); + int []result = new int[cases]; + int counter=0; + for(int i=0; i=3*best-2){ + counter++; + } + if((3*best-4>=0)&&(surprise!=0)&&(scores[l]>=3*best-4)&&(scores[l]<3*best-2)){ + counter++; + surprise--; + } + + } + result[i]=counter; + + output+=""Case #""+(i+1)+"": ""; + output+=result[i]+"" ""; + output+=""\n""; + counter=0; + } + }catch(Exception e){ + System.out.println(""Please debug this program to find the exception.""); + } + + System.out.println(output); + } + public static void main(String[] args) { + File file = new File(""./src/B-large.in""); + calculate(file); + } + +} +" +A21648,"package de.johanneslauber.codejam.model; + +import java.util.List; + +public interface IProblem { + + public void setListOfCases(List listOfCases); + + public void solveCases(); +} +" +A20740,"import java.io.BufferedReader; +import java.io.InputStreamReader; + + +public class Main { + + + public static void main(String[] args) { + Main main = new Main(); + try { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + String line = bf.readLine(); + int T = Integer.parseInt(line); + for (int testcaseIndex=0; testcaseIndex= Math.max(3*p-2, 0)) { + //System.out.println(""not""); + ret++; + } else if (s >= Math.max(3*p-4, 0) && numS < S && s >= p) { + //System.out.println(""SUP""); + ret++; + numS++; + } + } + return ret; + } + +} +" +A21449,"import java.io.*; + +/** + * *************************************************************************** + * Created by IntelliJ IDEA. + * User: Narender Singh Pal + * Date: 4/14/12 + * Time: 8:32 AM + *

+ * *************************************************************************** + *

+ * Copyright (c) 2012 All Rights Reserved. + *

+ *

+ * *************************************************************************** + */ +public class DancingWithTheGooglers +{ + public static void main (String args[]) + { + try + { + BufferedReader Br = new BufferedReader(new FileReader(""C:\\Input\\B-large.in"")); + BufferedWriter Bw = new BufferedWriter(new FileWriter(""C:\\Input\\B-large.out"")); + //read number if test cases + int $TC = Integer.valueOf(Br.readLine()); + //System.out.println(""$TC :""+ $TC); + int $N, $S, $P; + int [] $Input; + for(int tc=1; tc <=$TC; tc++) + { + String Pl = Br.readLine(); + String []arr = Pl.split("" ""); + $Input = new int[arr.length]; + for(int j =0; j < arr.length; j++) + { + $Input[j] = Integer.valueOf(arr[j]); + } + $N = $Input[0]; + $S = $Input[1]; + $P = $Input[2]; + //System.out.println(""$N :"" + $N + ""\n$S :"" + $S + ""\n$P :"" + $P); + + int $Result=0, $BR_Min=0, $BS_Min=0, $BS_Max=0; + if($P ==0) + { + $Result = $N; + } + else + { + //Calculate minimum sum for Best Result + $BR_Min = ($P * 3) - 2; + + //calculate maximum and minimum sum for Best and Surprising result + $BS_Min = $BR_Min - 2; + $BS_Max = $BR_Min; + + //count the maximum number of best results + for (int n=3; n < 3+$N ; n++) + { + int $Num = $Input[n]; + if($Num >= $BR_Min) + { + $Result++; + } + else if($Num <= $BS_Max && $Num >= $BS_Min && $S > 0 && $Num > 0) + { + $Result++; + $S--; + } + } + } + //System.out.println(""Case #""+ tc+"": ""+$Result); + Bw.write(""Case #""+ tc+"": ""+$Result); + Bw.write('\n'); + } + Br.close(); + Bw.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } +} + +" +A21248,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.LinkedList; +import java.util.Scanner; + + +public class dancing { + + public static int maxScore(int a){ + if(a==0) return 0; + return ((a%3)==0)?(a/3)+1:(a%3)+a/3; + } + + public static int maxScoreSanSurprise(int a){ + return (a/3)+Math.min(1, a%3); + } + + public static int solveOne(Scanner scan){ + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int nbok =0; + LinkedList possible = new LinkedList(); + for(int i=0; i=p){ + // System.out.println(""sans surprise""+tmp); + nbok++; + } + else if(maxScore(tmp)>= p){ + //System.out.println(""avec surprise""+tmp); + possible.add(tmp); + } + else{ + //System.out.println(""impossible""+tmp+"" ""+maxScore(tmp)+"" ""+maxScoreSanSurprise(tmp)); + } + } + return nbok+Math.min(s, possible.size()); + } + + public static void main(String[] args) throws FileNotFoundException{ + Scanner s = new Scanner(new File(""input.txt"")); + int nbcas = s.nextInt(); + for(int i=0; i scores = new ArrayList(); + String str; + StringTokenizer st; + + while( (str = br.readLine()) != null) + { + NoOfGooglers = -1; + surprisingResults = -1; + pi = -1; + scores.clear(); + st = new StringTokenizer(str, "" \n""); + scores.clear(); + while( st.hasMoreTokens()) + { + if( totalLines == 0 ) + { + totalLines = Integer.parseInt(str); + break; + } + if( NoOfGooglers == -1) + { + NoOfGooglers = Integer.parseInt(st.nextToken()); + continue; + } + if(surprisingResults == -1) + { + surprisingResults = Integer.parseInt(st.nextToken()); + continue; + } + if(pi == -1) + { + pi = Integer.parseInt(st.nextToken()); + continue; + } + scores.add(Integer.parseInt(st.nextToken())); + } + if ( pi != -1) + { + int passPi = findProbabilityPi(NoOfGooglers, surprisingResults, pi, scores); + writeFile(passPi); + } + } + } + catch(IOException | NumberFormatException e) + { + System.out.println(""error is "" +e.getMessage()); + } + } + + public static void writeFile(int passPi) + { + String line=""""; + try{ + // Create file + FileWriter fstream = new FileWriter(outputFile,true); + count++; + try (BufferedWriter out = new BufferedWriter(fstream)) { + line = ""Case #""+count+"": ""+passPi; + out.write(line); + out.newLine(); + } + } + catch(Exception e) + { + System.out.println(""error is "" +e.getMessage()); + } + } + + public static int findProbabilityPi(int NoOfGooglers, int surprisingResults,int pi,ArrayListscores) + { + int passPi = 0; + NoOfGooglers = 3; + for(int sc : scores) + { + if( sc % NoOfGooglers == 0) + { + if( (sc/3) == 0 && pi != 0) + continue; + if( sc/NoOfGooglers >= pi) + { passPi++; + continue; + } + if( surprisingResults>0 ) + { + + if( (sc/NoOfGooglers)+1 >= pi) + { passPi++; + surprisingResults--; + continue; + } + + } + + } + else if( (sc+1) % NoOfGooglers == 0) + { + if( (sc+1)/NoOfGooglers >= pi) + { + passPi++; + continue; + } + } + else if( (sc-1) % NoOfGooglers == 0) + { + if( (((sc-1)/NoOfGooglers)+1) >= pi) + { + passPi++; + continue; + } + } + + if(surprisingResults > 0) + { + if( (sc+2) % NoOfGooglers == 0) + { + if( (sc+2)/NoOfGooglers >= pi) + { + passPi++; + surprisingResults--; + continue; + } + } + else if( (sc-2) % NoOfGooglers == 0) + { + if( (((sc-2)/NoOfGooglers)+2) >= pi) + { + passPi++; + surprisingResults--; + continue; + } + } + } + } + return passPi; + } + + +} +" +A22065,"package hk.polyu.cslhu.codejam.solution.impl; + +public class AlienLanguage { + +} +" +A20736," + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; + +public abstract class TestCase { + + public abstract void readInput(BufferedReader in) throws IOException, MalformedInputFileException; + + public abstract void solve(); + + public abstract void writeOutput(PrintWriter out); + +}" +A22280," +public class possible { + + int Anom; + int High; + int count = 0; + + possible(int anom, int high){ + Anom = anom; + High = high; + + } + + + public void canDo(int score){ + int Score = score; + if(High > 0 && Score - High - (2 * (High- 1 )) >= 0){ + ++count; + }else if( Anom > 0 && High > 1 && Score - High - (2 * (High- 2 )) >= 0 ){ + ++count; + --Anom; + }else if( High == 0){ + ++count; + } + + } + + + + + + +} +" +A21940,"package jp.funnything.competition.util; + +import java.util.Iterator; + +/** + * Do NOT change the element in iteration + */ +public class Combination implements Iterable< int[] > , Iterator< int[] > { + private final int _n; + private final int _k; + private int[] _data; + + public Combination( final int n , final int k ) { + if ( k < 0 || k > n ) { + throw new IllegalArgumentException(); + } + + _n = n; + _k = k; + } + + @Override + public boolean hasNext() { + return _data == null || _data.length > 0 && _data[ 0 ] < _n - _k; + } + + @Override + public Iterator< int[] > iterator() { + return this; + } + + @Override + public int[] next() { + if ( _data == null ) { + _data = new int[ _k ]; + for ( int index = 0 ; index < _k ; index++ ) { + _data[ index ] = index; + } + } else { + int i = 0; + + while ( i < _k - 1 && _data[ i + 1 ] == _data[ i ] + 1 ) { + _data[ i ] = i++; + } + + _data[ i ]++; + } + + return _data; + } + + @Override + public void remove() { + } +} +" +A22170,"import java.io.*; +import java.util.*; +public class Prob2 { + public static PrintStream out; + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(new File(""in.txt"")); + out = new PrintStream(new File(""out.txt"")); + int numCases = Integer.parseInt(sc.nextLine()); + int caseNum = 1; + while(caseNum<=numCases) + solve(sc.nextLine(), caseNum++); + } + public static void solve(String input, int caseNum){ + StringTokenizer st = new StringTokenizer(input, "" ""); + int numPeople = Integer.parseInt(st.nextToken()); + int numSurprising = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + LL scores = new LL(); + for(int i=0; i=surePassLimit) + scores.removeLast(); + return origLength - scores.size(); + } + public static int countCanPass(LL scores, int p){ + int canpass = 0; + for(int i=0; i= p) + canpass++; + }else if(cur%3==2){ + if((cur-2)/3+2 >= p) + canpass++; + } + } + return canpass; + } + public static class LL extends LinkedList{} +} +" +A20747,"import java.util.ArrayList; + + +public class TestCase { + private int scoreCount; + private int suprisingCount; + private int pScore; + private ArrayList triplets; + + public TestCase(String s) { + String[] result = s.split("" ""); + scoreCount = Integer.parseInt(result[0]); // N + suprisingCount = Integer.parseInt(result[1]); // S + pScore = Integer.parseInt(result[2]); // P + triplets = new ArrayList(scoreCount); + for (int i = 0; i < scoreCount; i ++) { + triplets.add(new Triplet(Integer.parseInt(result[i+3]))); + } + } + + public int getScoreCount() { + return scoreCount; + } + + public int getSuprisingCount() { + return suprisingCount; + } + + public int getpScore() { + return pScore; + } + + public ArrayList getTriplets() { + return triplets; + } + +} +" +A21704," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +class DancingGooglers{ + public static void main(String[] args) + throws Exception{ + BufferedReader br = new BufferedReader(new FileReader(""in.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""out.txt"")); + int T = Integer.parseInt(br.readLine()); + + for(int i=0; i= p) + nos++; + if(t[j] == p - 1){ + if(r[j] > 0) + nos++; + else if(t[j]>0){ + nos++; + S--; + } + } + if(t[j] == p-2){ + if(r[j] == 2){ + nos++; + S--; + } + } + } + if(S<0) + nos += S; + bw.write(""Case #""+(i+1)+"": ""+nos+""\n""); + } + bw.close(); + } +}" +A20763,"import java.io.*; +import java.math.*; +import java.util.*; +import java.text.*; + +public class b { + public static void main(String[] args) { + Scanner sc = new Scanner(new BufferedInputStream(System.in)); + + int T = sc.nextInt(); + + for (int casenumber = 1; casenumber <= T; ++casenumber) { + + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int[] ts = new int[n]; + for (int i = 0; i < n; ++i) + ts[i] = sc.nextInt(); + + int thresh1 = (p == 1 ? 1 : (3 * p - 4)); + int thresh2 = (3 * p - 2); + + int count1 = 0, count2 = 0; + + for (int i = 0; i < n; ++i) { + if (ts[i] >= thresh2) { + ++count2; + continue; + } + if (ts[i] >= thresh1) { + ++count1; + } + } + + if (count1 > s) { + count1 = s; + } + + System.out.format(""Case #%d: %d%n"", casenumber, count1 + count2); + } + } +} +" +A22706,"import java.io.*; +import java.util.*; + +public class ProblemB +{ + public static void main(String[] args) + { + String txtfile=""B-large.in""; + try + { + Scanner scan = new Scanner(new FileInputStream(txtfile)); + FileWriter fstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + int T = scan.nextInt(); + int N,S,p; + int[] t ; + int max=0; + + for (int X=1;X<=T;X++) + { + max = 0; + N = scan.nextInt(); + S = scan.nextInt(); + p = scan.nextInt(); + t = new int[N]; + for (int i=0;i=0;i--) + { + a = t[i] / 3; + b = t[i] % 3; + if (a>=p) + max++; + else if (p-a<=2) + { + if (b>0) a++; + if (a

0) + { + if (p-a==1 && b==0 && S>0) + { + a++; + S--; + } + else if (b==2 && S>0) + { + a++; + S--; + } + } + if (a>=p) max++; + + } + } + out.write(""Case #"" + X + "": "" + max + ""\n""); + } + out.close(); + } + catch (Exception ex) + { + System.out.println(ex); + System.exit(1); + } + + } +}" +A21441,"package template; + +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + +public class TestCase { + + private boolean isSolved; + private Object solution; + private Map intProperties; + private Map> intArrayProperties; + private Map>> intArray2DProperties; + private Map doubleProperties; + private Map> doubleArrayProperties; + private Map>> doubleArray2DProperties; + private Map stringProperties; + private Map> stringArrayProperties; + private Map>> stringArray2DProperties; + private Map booleanProperties; + private Map> booleanArrayProperties; + private Map>> booleanArray2DProperties; + private Map longProperties; + private Map> longArrayProperties; + private Map>> longArray2DProperties; + private int ref; + private double time; + + public TestCase() { + initialise(); + } + + private void initialise() { + isSolved = false; + intProperties = new HashMap<>(); + intArrayProperties = new HashMap<>(); + intArray2DProperties = new HashMap<>(); + doubleProperties = new HashMap<>(); + doubleArrayProperties = new HashMap<>(); + doubleArray2DProperties = new HashMap<>(); + stringProperties = new HashMap<>(); + stringArrayProperties = new HashMap<>(); + stringArray2DProperties = new HashMap<>(); + booleanProperties = new HashMap<>(); + booleanArrayProperties = new HashMap<>(); + booleanArray2DProperties = new HashMap<>(); + longProperties = new HashMap<>(); + longArrayProperties = new HashMap<>(); + longArray2DProperties = new HashMap<>(); + ref = 0; + } + + public void setSolution(Object o) { + solution = o; + isSolved = true; + } + + public Object getSolution() { + if (!isSolved) { + Utils.die(""getSolution on unsolved testcase""); + } + + return solution; + } + + public void setRef(int i) { + ref = i; + } + public int getRef() { + return ref; + } + + public void setTime(double d) { + time = d; + } + public double getTime() { + return time; + } + + public void setInteger(String s, Integer i) { + intProperties.put(s, i); + } + + public Integer getInteger(String s) { + return intProperties.get(s); + } + + public void setIntegerList(String s, ArrayList l) { + intArrayProperties.put(s, l); + } + + public void setIntegerMatrix(String s, ArrayList> l) { + intArray2DProperties.put(s, l); + } + + public ArrayList getIntegerList(String s) { + return intArrayProperties.get(s); + } + + public Integer getIntegerListItem(String s, int i) { + return intArrayProperties.get(s).get(i); + } + + public ArrayList> getIntegerMatrix(String s) { + return intArray2DProperties.get(s); + } + + public ArrayList getIntegerMatrixRow(String s, int row) { + return intArray2DProperties.get(s).get(row); + } + + public Integer getIntegerMatrixItem(String s, int row, int column) { + return intArray2DProperties.get(s).get(row).get(column); + } + + public ArrayList getIntegerMatrixColumn(String s, int column) { + ArrayList out = new ArrayList(); + + for(ArrayList row : intArray2DProperties.get(s)) { + out.add(row.get(column)); + } + return out; + } + + + public void setDouble(String s, Double i) { + doubleProperties.put(s, i); + } + + public Double getDouble(String s) { + return doubleProperties.get(s); + } + + public void setDoubleList(String s, ArrayList l) { + doubleArrayProperties.put(s, l); + } + + public void setDoubleMatrix(String s, ArrayList> l) { + doubleArray2DProperties.put(s, l); + } + + public ArrayList getDoubleList(String s) { + return doubleArrayProperties.get(s); + } + + public Double getDoubleListItem(String s, int i) { + return doubleArrayProperties.get(s).get(i); + } + + public ArrayList> getDoubleMatrix(String s) { + return doubleArray2DProperties.get(s); + } + + public ArrayList getDoubleMatrixRow(String s, int row) { + return doubleArray2DProperties.get(s).get(row); + } + + public Double getDoubleMatrixItem(String s, int row, int column) { + return doubleArray2DProperties.get(s).get(row).get(column); + } + + public ArrayList getDoubleMatrixColumn(String s, int column) { + ArrayList out = new ArrayList(); + + for(ArrayList row : doubleArray2DProperties.get(s)) { + out.add(row.get(column)); + } + return out; + } + + + public void setString(String s, String t) { + stringProperties.put(s, t); + } + + public String getString(String s) { + return stringProperties.get(s); + } + + public void setStringList(String s, ArrayList l) { + stringArrayProperties.put(s, l); + } + + public void setStringMatrix(String s, ArrayList> l) { + stringArray2DProperties.put(s, l); + } + + public ArrayList getStringList(String s) { + return stringArrayProperties.get(s); + } + + public String getStringListItem(String s, int i) { + return stringArrayProperties.get(s).get(i); + } + + public ArrayList> getStringMatrix(String s) { + return stringArray2DProperties.get(s); + } + + public ArrayList getStringMatrixRow(String s, int row) { + return stringArray2DProperties.get(s).get(row); + } + + public String getStringMatrixItem(String s, int row, int column) { + return stringArray2DProperties.get(s).get(row).get(column); + } + + public ArrayList getStringMatrixColumn(String s, int column) { + ArrayList out = new ArrayList(); + + for(ArrayList row : stringArray2DProperties.get(s)) { + out.add(row.get(column)); + } + return out; + } + + + public void setBoolean(String s, Boolean b) { + booleanProperties.put(s, b); + } + + public Boolean getBoolean(String s) { + return booleanProperties.get(s); + } + + public void setBooleanList(String s, ArrayList l) { + booleanArrayProperties.put(s, l); + } + + public void setBooleanMatrix(String s, ArrayList> l) { + booleanArray2DProperties.put(s, l); + } + + public ArrayList getBooleanList(String s) { + return booleanArrayProperties.get(s); + } + + public Boolean getBooleanListItem(String s, int i) { + return booleanArrayProperties.get(s).get(i); + } + + public ArrayList> getBooleanMatrix(String s) { + return booleanArray2DProperties.get(s); + } + + public ArrayList getBooleanMatrixRow(String s, int row) { + return booleanArray2DProperties.get(s).get(row); + } + + public Boolean getBooleanMatrixItem(String s, int row, int column) { + return booleanArray2DProperties.get(s).get(row).get(column); + } + + public ArrayList getBooleanMatrixColumn(String s, int column) { + ArrayList out = new ArrayList(); + + for(ArrayList row : booleanArray2DProperties.get(s)) { + out.add(row.get(column)); + } + return out; + } + + public void setLong(String s, Long b) { + longProperties.put(s, b); + } + + public Long getLong(String s) { + return longProperties.get(s); + } + + public void setLongList(String s, ArrayList l) { + longArrayProperties.put(s, l); + } + + public void setLongMatrix(String s, ArrayList> l) { + longArray2DProperties.put(s, l); + } + + public ArrayList getLongList(String s) { + return longArrayProperties.get(s); + } + + public Long getLongListItem(String s, int i) { + return longArrayProperties.get(s).get(i); + } + + public ArrayList> getLongMatrix(String s) { + return longArray2DProperties.get(s); + } + + public ArrayList getLongMatrixRow(String s, int row) { + return longArray2DProperties.get(s).get(row); + } + + public Long getLongMatrixItem(String s, int row, int column) { + return longArray2DProperties.get(s).get(row).get(column); + } + + public ArrayList getLongMatrixColumn(String s, int column) { + ArrayList out = new ArrayList(); + + for(ArrayList row : longArray2DProperties.get(s)) { + out.add(row.get(column)); + } + return out; + } + + + + + + +} +" +A22759,"import java.util.ArrayList; + + +public class App { + + /** + * @param args + */ + public static void main(String[] args) + { + Reader reader = new Reader(); + ArrayList input = reader.LinesReader(); + + ArrayList output = new ArrayList(); + for (String i : input) + { + output.add(handleCase(i)); + } + reader.output(output); + } + + private static String handleCase(String s) + { + String output = """"; + + String[] split = s.split("" ""); + ArrayList listInt = new ArrayList(); + + for (String string : split) + { + listInt.add(Integer.valueOf(string)); + } + + int nbGooglers = listInt.get(0); + int nbSurprising = listInt.get(1); + int bestResultNeeded = listInt.get(2); + + int nbAchieved = 0; + for (int i = 0; i < nbGooglers; i++) + { + double score = listInt.get(3 + i); + + if (Math.ceil(score / 3) >= bestResultNeeded) + { + nbAchieved++; + } + else + if (nbSurprising > 0) + { + // prevention cas negatif + double maxAdded = 4; + if (score < maxAdded) + maxAdded = score; + if (((score + maxAdded) / 3) >= bestResultNeeded) + { + + nbAchieved++; + nbSurprising--; + } + } + } + + return """" + nbAchieved; + } + +} +" +A21310,"import java.io.File; +import java.io.FileReader; +import java.io.BufferedReader; +import java.io.FileWriter; +import java.io.BufferedWriter; + +public class Blarge { + + private String [] content = new String[100]; + private String [] output = new String[100]; + private StringBuffer outputString = null; + private int testCases = 0; + private String outputFile =""Blarge.out""; + private int [] n = new int[100]; + private int [] s = new int[100]; + private int [] p = new int[100]; + private int [][] t = new int[100][100]; + + public void readFile(String fileName){ + try{ + File f = new File(fileName); + FileReader fr = new FileReader(f); + BufferedReader br = new BufferedReader(fr); + testCases = Integer.parseInt(br.readLine()); + for(int i=0; i 0.5 && s[i]>0){ + if(irem+2>p[i]){ + y++; + } + else if(irem+2==p[i]){ + y++; + s[i]--; + } + } + else if(rem > 0){ + if(irem+1>=p[i]){ + y++; + } + } + else{ + if(irem+1==p[i] && irem-1>=0 && s[i]>0){ + y++; + s[i]--; + } + if(irem>=p[i]){ + y++; + } + } + } + sb.append(y); + output[i] = sb.toString(); + } + } + public void writeFile(){ + try{ + File f = new File(outputFile); + FileWriter fw = new FileWriter(f); + BufferedWriter bw = new BufferedWriter(fw); + for(int i =0 ; i1) { + rNormal = p*3 - 2; + rSurprise = p*3 - 4; + } + int countPassedNormal = 0; + int countPassedSurprise = 0; + for (int j=0; j=rNormal) { + countPassedNormal++; + } + else if (t>=rSurprise) { + countPassedSurprise++; + } + } + + if (countPassedSurprise>s) countPassedSurprise = s; + + System.out.println(""Case #""+(i+1)+"": ""+(countPassedNormal+countPassedSurprise)); + } + } +} +" +A21939,"package jp.funnything.competition.util; + +import java.io.File; +import java.math.BigDecimal; +import java.math.BigInteger; + +import org.apache.commons.io.FileUtils; + +public class CompetitionIO { + private final QuestionReader _reader; + private final AnswerWriter _writer; + + /** + * Default constructor. Use latest ""*.in"" as input + */ + public CompetitionIO() { + this( null , null , null ); + } + + public CompetitionIO( final File input , final File output ) { + this( input , output , null ); + } + + public CompetitionIO( File input , File output , final String format ) { + if ( input == null ) { + for ( final File file : FileUtils.listFiles( new File( ""."" ) , new String[] { ""in"" } , false ) ) { + if ( input == null || file.lastModified() > input.lastModified() ) { + input = file; + } + } + + if ( input == null ) { + throw new RuntimeException( ""No *.in found"" ); + } + } + + if ( output == null ) { + final String inPath = input.getPath(); + + if ( !inPath.endsWith( "".in"" ) ) { + throw new IllegalArgumentException(); + } + + output = new File( inPath.replaceFirst( "".in$"" , "".out"" ) ); + } + + _reader = new QuestionReader( input ); + _writer = new AnswerWriter( output , format ); + } + + public CompetitionIO( final String format ) { + this( null , null , format ); + } + + public void close() { + _reader.close(); + _writer.close(); + } + + public String read() { + return _reader.read(); + } + + public BigDecimal[] readBigDecimals() { + return _reader.readBigDecimals(); + } + + public BigDecimal[] readBigDecimals( final String separator ) { + return _reader.readBigDecimals( separator ); + } + + public BigInteger[] readBigInts() { + return _reader.readBigInts(); + } + + public BigInteger[] readBigInts( final String separator ) { + return _reader.readBigInts( separator ); + } + + /** + * Read line as single integer + */ + public int readInt() { + return _reader.readInt(); + } + + /** + * Read line as multiple integer, separated by space + */ + public int[] readInts() { + return _reader.readInts(); + } + + /** + * Read line as multiple integer, separated by 'separator' + */ + public int[] readInts( final String separator ) { + return _reader.readInts( separator ); + } + + /** + * Read line as single integer + */ + public long readLong() { + return _reader.readLong(); + } + + /** + * Read line as multiple integer, separated by space + */ + public long[] readLongs() { + return _reader.readLongs(); + } + + /** + * Read line as multiple integer, separated by 'separator' + */ + public long[] readLongs( final String separator ) { + return _reader.readLongs( separator ); + } + + /** + * Read line as token list, separated by space + */ + public String[] readTokens() { + return _reader.readTokens(); + } + + /** + * Read line as token list, separated by 'separator' + */ + public String[] readTokens( final String separator ) { + return _reader.readTokens( separator ); + } + + public void write( final int questionNumber , final Object result ) { + _writer.write( questionNumber , result ); + } + + public void write( final int questionNumber , final String result ) { + _writer.write( questionNumber , result ); + } + + public void write( final int questionNumber , final String result , final boolean tee ) { + _writer.write( questionNumber , result , tee ); + } +} +" +A21283,"import java.util.Scanner; + + +public class Two { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner s = new Scanner (System.in); + int cases=s.nextInt(); + for(int i=0;i=cutoff+(cutoff-1)*2){ + total++; + } + else if(suprising>0 && par>=cutoff+Math.max(0, (cutoff-2)*2)){ + total++; + suprising--; + + } + else if(par 3) ++sPass; + + } + + if( surprise >= sPass) pass += sPass; + else pass += surprise; + output.write(""Case #"" + (i+1) + "": "" + pass + ""\n""); + + } + + + + output.close(); + + + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +} +" +A23066,"import java.io.BufferedReader; +import java.io.InputStreamReader; + +class DWtG { + public static BufferedReader br = null; + public static int numCases; + public static int numDancers; + public static int numSurprises; + public static int p; // p is given by the problem as the ""best score"" + public static String[] input; + + public static void main(String[] args) { + try { + br = new BufferedReader(new InputStreamReader(System.in)); + + numCases = Integer.parseInt(br.readLine().trim()); + + for(int i = 0; i < numCases; i++) { + input = br.readLine().split("" ""); + numDancers = Integer.parseInt(input[0]); + numSurprises = Integer.parseInt(input[1]); + p = Integer.parseInt(input[2]); + int maxDancers = 0; + + for(int j = 3; j < input.length; j++) { + if(maxReg(Integer.parseInt(input[j])) >= p) + maxDancers++; + else if(numSurprises > 0 && maxSpecial(Integer.parseInt(input[j])) >= p) { + maxDancers++; + numSurprises--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + maxDancers); + } + } + catch(Exception e) { + e.getMessage(); + e.printStackTrace(); + } + } + + public static int maxReg(int n) { + if(n == 0) + return 0; + else if(n == 1) + return 1; + else if(n == 2) + return 1; + else if(n % 3 == 0) + return (n / 3); + else if(n % 3 == 1) + return (n / 3) + 1; + else if(n % 3 == 2) + return (n / 3) + 1; + return -1; + } + + public static int maxSpecial(int n) { + if(n == 0) + return 0; + else if(n == 1) + return 1; + else if(n == 2) + return 2; + else if(n % 3 == 0) + return (n / 3) + 1; + else if(n % 3 == 1) + return (n / 3) + 1; + else if(n % 3 == 2) + return (n / 3) + 2; + return -1; + } +} +" +A20269,"package gcj; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +public class Gcj { + private static final String path = ""/home/me/dev/gcj/""; + private BufferedReader br = null; + private String[] tokens; + private int itoken,ntokens; + + static public void err(String e) { + System.out.println(""\n**\n""+e+"" :-)\n""); + System.exit(1); + } + + public Gcj(String filename) { + try { + br = new BufferedReader(new FileReader(path + filename)); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public String rawLine() { + String line = null; + + try { + line = br.readLine(); + } + catch (Exception e) { + e.printStackTrace(); + } + return line; + } + + + public String[] readLine() { + + String line = rawLine(); + + if (line == null) { + tokens = null; + ntokens = 0; + } + else { + tokens = line.trim().split(""\\s+""); + ntokens = tokens.length; + } + itoken = 0; + + return tokens; + } + + private String nextToken() { + String err = null; + if (ntokens < 1) err = ""There is no token""; + else if (itoken >= ntokens) err = ""No more token""; + else { + return tokens[itoken++]; + } + + Gcj.err(err); + return null; + } + + public String sToken() { + return nextToken(); + } + + public String[] sBunch() { + String[] l = new String[ntokens-itoken]; + int i=0; + while (itoken < ntokens) l[i++] = tokens[itoken++]; + return l; + } + + public char cToken() { + return nextToken().charAt(0); + } + + public char[] cBunch() { + char[] l = new char[ntokens-itoken]; + int i = 0; + while (itoken < ntokens) l[i++] = tokens[itoken++].charAt(0); + return l; + } + + public int iToken() { + return Integer.parseInt(nextToken()); + } + + public int[] iBunch() { + int[] l = new int[ntokens-itoken]; + int i = 0; + while (itoken < ntokens) l[i++] = Integer.parseInt(tokens[itoken++]); + return l; + } + + public long lToken() { + return Long.parseLong(nextToken()); + } + + public long[] lBunch() { + long[] l = new long[ntokens-itoken]; + int i = 0; + while (itoken < ntokens) l[i++] = Long.parseLong(tokens[itoken++]); + return l; + } + + public double dToken() { + return Double.parseDouble(nextToken()); + } + + public double[] dBunch() { + double[] l = new double[ntokens-itoken]; + int i = 0; + while (itoken < ntokens) l[i++] = Double.parseDouble(tokens[itoken++]); + return l; + } + + // -- + + public void terminate() { + try { + if (br != null) br.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + System.out.println(""""); + } + + + // --- OUTPUT --- + + public static void outcase(int n, boolean rc) { + System.out.print(""Case #"" + n + "": ""); + if (rc) System.out.print(""\n""); + } +} +" +A21803,"package com.google.codejam; + +import com.google.codejam.util.CodeJamInputFile; +import com.google.codejam.util.CodeJamOutputFile; + +public class Dancer { + + /** + * @param args + */ + public static void main(String[] args) { + CodeJamInputFile f = new CodeJamInputFile(""in/B-large.in""); + + CodeJamOutputFile fo = new CodeJamOutputFile(""out/B-large.out""); + + for(int c = 0; c < f.getCases(); c++){ + int count = 0; + String line = f.getLine(); + String[] tokens = line.split("" ""); + int goog = Integer.valueOf(tokens[0]); + int surp = Integer.valueOf(tokens[1]); + int best = Integer.valueOf(tokens[2]); + for(int g = 3; g < (goog + 3); g++){ + int tot = Integer.valueOf(tokens[g]); + System.out.print(tot + "" - ""); + if(tot > ((best * 3) - 3)){ + count++; + continue; + } + if((surp > 0) && (tot > ((best * 3) - 5)) && (tot > 2)){ + count++; + surp--; + } + } + System.out.println(count + """"); + fo.writeCase(c, count + """"); + } + + f.close(); + fo.close(); + } + +} +" +A21653,"package de.johanneslauber.codejam.model; + +/** + * + * @author Johannes Lauber - joh.lauber@googlemail.com + * + */ +public interface ICase { + public void setLine(int lineNumber, String lineValue); + + public int getNumberOfAttributes(); +} +" +A22976,"//input file must be in.txt in this directory +//output file will be out.txt + +import java.io.*; +import java.util.*; +public class B +{ + public static Scanner in; + public static PrintStream out; + public static void main(String [] args) throws Throwable + { + in = new Scanner(new File(""in.txt"")); + int cases = in.nextInt(); + in.nextLine(); + out = new PrintStream(new File(""out.txt"")); + for (int i = 1; i <= cases; i++) + { + out.print(""Case #"" + i + "": ""); + printResult(); + out.println(); + } + } + public static void printResult() + { + int n,p,s; + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + + int surprize; + int good; + if (p > 1) + { + surprize = (3*p)-4; + good = (3*p) - 2; + } + else + { + surprize = p; + good = p; + } + int tot = 0; + int cur; + for (int i = 0; i < n; i++) + { + cur = in.nextInt(); + if (cur >= good) + tot++; + else if(cur >= surprize && s > 0) + { + s--; + tot++; + } + } + out.print(tot); + } +} +" +A20326,"package QuickStart; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class GoogleDancer { + + public static void main (String[] args) { + String inputFile = ""D:\\B-large.in""; + String outputFile = ""D:\\out2.txt""; + String prefix = ""Case #""; + int p = 0; + int s = 0; + int n = 0; + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile)); + BufferedReader br = new BufferedReader(new FileReader(inputFile)); + String line = """"; + line = br.readLine(); + int num = Integer.valueOf(line); + for (int i = 1; i <= num; i++) { + String tline = br.readLine(); + String[] nStr = tline.split(""\\s+""); + int result = 0; + int len = nStr.length; + int[] intS = new int[len]; + for (int j = 0; j < len; j++) { + intS[j] = Integer.valueOf(nStr[j]); + } + n = intS[0]; + s = intS[1]; + p = intS[2]; + int v1 = 3 * p - 2; + v1 = v1 > 0 ? v1 : 0; + ArrayList left = new ArrayList(); + for (int k = 0; k < n; k++) { + if (intS[k+3] >= v1) + result++; + else + left.add(intS[k+3]); + } + int v2 = v1 - 2; + v2 = v2 > 0 ? v2 : 0; + int leftlen = left.size(); + for (int k = 0; k < leftlen && s > 0; k++) { + if (left.get(k) >= v2 && left.get(k) >= 2) { + result++; + s--; + } + } + String output = prefix + i + "": "" + result; + bw.write(output); + if (i < num) + bw.write(""\n""); + } + br.close(); + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A22594,"package com.google.dancing; + +import java.util.Scanner; + +import com.google.util.FileUtil; + +/* + * + * + */ +public class Dancing { + + public static void main(String[] args) { + String orgFilePath = ""E:\\Google_Jam\\Dancing\\B-large.in""; + Scanner scanner = FileUtil.openFile(orgFilePath); + StringBuilder sb = new StringBuilder(); + + int caseNum = Integer.valueOf(scanner.nextLine()); + for (int i = 0; i < caseNum; i++) { + sb.append(""Case #"" + (i + 1) + "": ""); + String line = scanner.nextLine(); + String[] numbers = line.split("" ""); + // String[] numbers = {""15""}; + int n = 0;// ´ïµ½×î´óÖµµÄ¸öÊý + int googlers = Integer.valueOf(numbers[0]);// Ñ¡ÊÖ¸öÊý + int suprising = Integer.valueOf(numbers[1]);// µÃ·Ö²î´óÓÚ2 + int max = Integer.valueOf(numbers[2]);// ÆÚÍûÖµ + /* + * int googlers = 1; int suprising =1; int max = 3; + */ + for (int j = 0; j < googlers; j++) { + int temp = Integer.valueOf(numbers[j + 3]);// µ±Ç°Ñ¡ÊÖËùµÃ×Ü·Ö + // int temp = Integer.valueOf(numbers[0]); + if (temp / 3 >= max) { + n++; + } else if ((max - (temp / 3) == 1) + && ((temp / 3) + (temp % 3)) >= max) { + n++; + } else if ((max - (temp / 3)) > 1 + && ((temp / 3) + (temp % 3)) >= max && suprising > 0) { + n++; + suprising--; + } else if (temp != 0 && max - temp / 3 == 1 && suprising > 0 + && temp % 3 == 0) { + n++; + suprising--; + } + } + sb.append(n); + sb.append(""\n""); + } + FileUtil.writeFile(sb, ""Dancing\\large.in""); + } +} +" +A20251,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class DancingWithGooglers { + + public static void main(String[] args) throws IOException { + String msg = """"; + BufferedReader br = null; + String sCurrentLine = null; + Map map = new HashMap(); + br = new BufferedReader(new FileReader(""test"")); + sCurrentLine = br.readLine(); + int x = 0; + if (sCurrentLine != null) { + while ((sCurrentLine = br.readLine()) != null) { + int qualifiedGooglers = 0; + msg = """"; + String[] eachTestCase = sCurrentLine.split("" ""); + int noOfGooglers = Integer.parseInt(eachTestCase[0]); + int noOfSurprises = Integer.parseInt(eachTestCase[1]); + int minReqd = Integer.parseInt(eachTestCase[2]); + int[] googlersPoint = new int[noOfGooglers]; + int k = 0; + for (int i = 3; i < eachTestCase.length; i++) { + int j = Integer.parseInt(eachTestCase[i]); + googlersPoint[k++] = j; + } + for (int i = 0; i < noOfGooglers; i++) { + if (googlersPoint[i] == 0) { + if (minReqd == 0) + qualifiedGooglers++; + } else if ((googlersPoint[i] + 2) / 3 >= minReqd) { + qualifiedGooglers++; + } else if (noOfSurprises > 0) { + if ((googlersPoint[i] + 4) / 3 >= minReqd) { + qualifiedGooglers++; + noOfSurprises--; + } + + } + } + x++; + msg += ""Case #"" + x + "": "" + qualifiedGooglers; + System.out.println(msg); + } + } + + } +} +" +A22946," +package codejam2012.B; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author Rymbu VV + */ +public class DancingWithGooglers { + + private Scanner sc; + private PrintWriter pw; + private int CASES; + + public static void main(String[] args) { + DancingWithGooglers suk = new DancingWithGooglers(""c:\\bl.in"", ""c:\\bl.out""); + suk.execute(); + } + + public DancingWithGooglers(String fileIn, String fileOut) { + try{ + sc = new Scanner(new File(fileIn)); + pw = new PrintWriter(new FileWriter(fileOut)); + CASES = sc.nextInt(); + }catch(Exception e){System.out.println(""In Constructor ""+e);} + } + + public void execute(){ + int N, S, p, count; + for(int ncase = 1; ncase <= CASES; ncase++){ + pw.print(""Case #""+ncase+"": ""); + + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + count = 0; + for (int i=0; i=p && (t/3) >= p ){ + count++; + continue; + } + int tmp = t-p; + if (t>=p && (p-(tmp/2)) <= 1){ + count++; + continue; + } + if (S>0 && t>=p && (p-(tmp/2)) <= 2){ + count++; + S--; + } + } + + pw.println(count); + } + pw.flush(); + pw.close(); + sc.close(); + } +} +" +A22244,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package inout; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +/** + * + * @author Hasier Rodriguez + */ +public final class In { + + private In() { + } + + public static String[] read(String path, int mult) throws FileNotFoundException, IOException { + System.out.println(""IN""); + File f = new File(path); + BufferedReader br = new BufferedReader(new FileReader(f)); + String[] array = new String[Integer.parseInt(br.readLine()) * mult]; + String s = br.readLine(); + int i = 0; + while (s != null) { + array[i] = s; + System.out.println(s); + i++; + s = br.readLine(); + } + System.out.println(); + System.out.println(); + br.close(); + return array; + } +} +" +A22739,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package qual_b; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Formatter; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Bart + */ +public class Qual_B { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + String file = ""B-large""; + Scanner scanner = new Scanner(new FileInputStream(file + "".in"")); + Formatter formatter = new Formatter(new File(file + "".out"")); + + int numberOfCases = scanner.nextInt(); + System.out.println(""Number of cases: "" + numberOfCases); + + for (int caseNr = 0; caseNr < numberOfCases; caseNr++) { + // ** Code Here ** // + int n = scanner.nextInt(); + int nSpecialCases = scanner.nextInt(); + int max =scanner.nextInt(); + int[] numbers = new int[n]; + System.out.println(""n: "" + n); + for(int i=0;i=minAccepted){ + System.out.println(""Binnen grens: "" + i); + score++; + } + else if(nSpecialCases >0 && i>=minSpecial){ + System.out.println(""Binnen grens(speciaal)""); + score++; + nSpecialCases--; + } + } + + System.out.println(""Score: "" + score); + + formatter.format(""Case #%d: %d%n"", caseNr + 1, score); + } + formatter.close(); + } catch (FileNotFoundException ex) { + Logger.getLogger(Qual_B.class.getName()).log(Level.SEVERE, null, ex); + } + } +} +" +A21852,"import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Scanner; + + +public class MaxGooglers { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub + System.setIn(new BufferedInputStream(new FileInputStream("".\\input\\B-large.in""))); + System.setOut(new PrintStream(new File("".\\output\\B-large.out""))); + Scanner in = new Scanner(System.in); + int caseNum=in.nextInt(); + for(int i=0;i=p*3-2){ + maxNum++; + } + else if(scores[j]!=0 && scores[j]>=p*3-4){ + if(surprise!=0){ + surprise--; + maxNum++; + } + } + else if(scores[j]==0 && p==0){ + maxNum++; + } + } + System.out.println(""Case #""+(i+1)+"": "" +maxNum); + } + } + +} +" +A20915,"import java.io.*; +import java.util.Scanner; +import java.util.*; + +public class trie +{ + public static void main(String[] args) throws IOException + { + int i,j,nog,nos,p,n,count; + int[] t=new int[10]; + String s1="""",p1="""",m1=""""; + solver h1=new solver(); + Scanner fin=new Scanner(new File(""A.txt"")); + s1=fin.nextLine(); + n=Integer.parseInt(s1); + FileWriter fstream=new FileWriter(""out.txt""); + BufferedWriter out=new BufferedWriter(fstream); + for(i=0;i0) + { + if(Math.abs(k-j)>2 || Math.abs(k-i)>2 || Math.abs(i-j)>2) + continue; + + + + if(Math.max(i,Math.max(j,k))>=p) + { + if(Math.abs(i-j)==2 || Math.abs(k-j)==2 || Math.abs(k-i)==2) + { + if(S>0) + { + S--; + res++; + scores[i+j+k]--; + } + } + else + { +// res++; +// scores[i+j+k]--; + } + } + // System.out.println(""Posible sol=""+i+"",""+j+"",""+k+""\t\tS=""+S); + } + + for(int h=0;h0) + { + if(Math.abs(k-j)>2 || Math.abs(k-i)>2 || Math.abs(i-j)>2) + continue; + + + + if(Math.max(i,Math.max(j,k))>=p) + { + if(Math.abs(i-j)==2 || Math.abs(k-j)==2 || Math.abs(k-i)==2) + { + if(S>0) + { +// S--; +// res++; +// scores[i+j+k]--; + } + } + else + { + res++; + scores[i+j+k]--; + } + } + // System.out.println(""Posible sol=""+i+"",""+j+"",""+k+""\t\tS=""+S); + } + + + res=Math.min(res,N); + System.out.print((""Case #""+tc+"": ""+res+""\n"")); + out.write((""Case #""+tc+"": ""+res+""\n"").getBytes()); + } + out.close(); + // TODO code application logic here + } +} +" +A22150,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.LinkedList; +import java.util.StringTokenizer; + + +public class Principal +{ + public static void main(String [] args) throws IOException + { + + FileReader fr = new FileReader(""B-small-attempt0.in""); + BufferedReader bf = new BufferedReader(fr); + + FileWriter bw = new FileWriter(""B-small-attempt0.out""); + + int res; + int times = Integer.parseInt(bf.readLine()); + + LinkedList l = new LinkedList(); + String str = bf.readLine(); + int i = 1; + StringTokenizer st; + while(i <= times) + { + st = new StringTokenizer(str); + while(st.hasMoreTokens()) + { + l.add(Integer.parseInt(st.nextToken()) ); + } + bw.write(""Case #""); + bw.write(String.valueOf(i)); + bw.write("": ""); + l.pop(); + int s = l.pop(); + int p = l.pop(); + res = Triplet.triplete(l, p, s); + bw.write(Integer.toString(res)); + bw.write(""\n""); + str = bf.readLine(); + i++; + l = new LinkedList(); + } + bw.close(); + bf.close(); + } +} +" +A21860,"package test.com; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Stack; + +public class QualB { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + FileInputStream fos = new FileInputStream(""c:/sanker/workspace/input1/B-large.in""); + BufferedReader buf = new BufferedReader(new InputStreamReader(fos)); + String str = """"; + int S, P, N, N0; + String Car[], Dar[]; + int ar[],k=0; + + str = buf.readLine(); + N0 = Integer.parseInt(str); + for(int cnti=0; cnti= P) { + count++; + }else { + int d1 = num - P; + int d2 = (P * 2) - 2; + if(d1 >= d2) + count++; + else { + int d3 = (P * 2) - 4; + if(d1 >= d3 && surCount+1 <= S) { + count++; surCount++; + } + } + } + + } + System.out.println(""Case #""+(cnti+1)+"": ""+count); + + } + + } + + + +} +" +A20904," +public class ProblemB { + + public static int[] generateTriplet(int totalScore) + { + int third = totalScore/3; + int[] triplet = new int[3]; + int total = 0; + int i = 0; + + triplet[0] = third; + triplet[1] = third; + triplet[2] = third; + + total = third*3; + + while(total < totalScore) + { + triplet[i] += 1; + total += 1; + i = (i+1)%3; + } + //System.out.println( triplet[0] + "","" + triplet[1] + "","" + triplet[2]); + + return triplet; + } + +} +" +A22120,"import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; + + +public class Outputter { + + public static void output(long[] results) throws IOException { + Writer out = new BufferedWriter(new FileWriter(""output.txt"")); + + for (int i = 1; i < results.length; i++) { + out.write(""Case #"" + i + "": "" + results[i - 1] + '\n'); + } + + out.write(""Case #"" + results.length + "": "" + results[results.length - 1]); + + out.close(); + } +} +" +A22231,"package trupti; +import java.io.*; +import java.util.*; +public class Main2 { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + // char c[]; + int count=0; + try { + FileOutputStream out=new FileOutputStream(""out8.out""); + Scanner inFIle=new Scanner(new FileReader(""B-large.in"") ); + int t=inFIle.nextInt(); + + while (t!=0) { + count++; + int a=0,b=0; + int n=inFIle.nextInt(); + int s=inFIle.nextInt(); + int p=inFIle.nextInt(); + int ti[]=new int[n]; + int m[][]=new int[n][3]; + int cn=0; + for(int i=0;i=1)) + { + a=p-m[i][0]; + /*if(a==2 & s>0) + if((m[i][0]==m[i][1])&(m[i][1]==m[i][2])) + { + m[i][0]+=2; + m[i][1]--; + m[i][2]--; + s--; + }*/ + if(a==1 & s>0) + { + if((m[i][0]==m[i][1])&(m[i][1]==m[i][2])) + { + m[i][0]+=1; + m[i][1]--; + // m[i][2]--; + s--; + } + else + { + if((m[i][0]==m[i][1])&((m[i][1]-m[i][2])==1)) + { + m[i][0]+=1; + m[i][1]--; + // m[i][2]--; + s--; + } + } + } + } + System.out.println(m[i][0]); + if(m[i][0]>=p) + cn++; + } + + + out.write((""Case #""+count+"": ""+cn+""\n"").getBytes()); + System.out.print(""case #""+count+"": ""+cn+""\n""); + + //System.out.println(str); + t--; + } + + } catch (Exception e) { + // TODO: handle exception + } + + } + +} +" +A22626,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Scanner; + +public class SolutionB_2 { + + public static void main(String[] args) throws IOException { + + String curDir = ""DancingWithGooglers/""; + + Scanner sc = new Scanner(new FileReader(curDir + ""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(curDir + ""B-large.out"")); + + int totalTestCase = Integer.parseInt(sc.nextLine()); + + for (int testCase = 1; testCase <= totalTestCase; testCase++) { + Integer nGoogler = sc.nextInt(); + Integer nSurprising = sc.nextInt(); + Integer bestNum = sc.nextInt(); + + Integer maxNum = 0; + Integer nCheck = 0; + + List g = new ArrayList(); + List g1 = new ArrayList(); + + for (int i = 0; i < nGoogler; i++) { + Integer a = sc.nextInt(); + g.add(a); + g1.add(a); + } + + if (nSurprising == 0) { + for (Integer t : g) { + int y = t / 3; + int z = t % 3; + + if (t == 0 || t == 1) { + if (t >= bestNum) { + maxNum++; + } + } else if (z == 0) { + if (y >= bestNum) { + maxNum++; + } + } else if (z == 1) { + if (y + 1 >= bestNum) { + maxNum++; + } + } else if (z == 2) { + if (y + 1 >= bestNum) { + maxNum++; + } + } + } + } else { + java.util.Collections.sort(g, new Comparator() { + public int compare(Integer a, Integer b) { + if (a > b) { + return 1; + } else if (a < b) { + return -1; + + } else { + return 0; + } + } + }); + + for (Iterator it = g.iterator(); it.hasNext();) { + Integer t = it.next(); + + int y = t / 3; + int z = t % 3; + + if (t == 0 || t == 1) { + continue; + } else if (z == 0) { + if (y + 1 >= bestNum && nCheck < nSurprising) { + maxNum++; + nCheck++; + it.remove(); + } + } else if (z == 1) { + if (y + 1 >= bestNum && nCheck < nSurprising) { + maxNum++; + nCheck++; + it.remove(); + } + } else if (z == 2) { + if (y + 2 >= bestNum && nCheck < nSurprising) { + maxNum++; + nCheck++; + it.remove(); + } else if (y + 1 >= bestNum && nCheck < nSurprising) { + maxNum++; + nCheck++; + it.remove(); + } + } + } + + if (nCheck >= nSurprising) { + for (Integer t : g) { + int y = t / 3; + int z = t % 3; + + if (t == 0 || t == 1) { + if (t >= bestNum) { + maxNum++; + } + } else if (z == 0) { + if (y >= bestNum) { + maxNum++; + } + } else if (z == 1) { + if (y + 1 >= bestNum) { + maxNum++; + } + } else if (z == 2) { + if (y + 1 >= bestNum) { + maxNum++; + } + } + } + } + + } + + pw.println(String.format(""Case #%d: %d"", testCase, maxNum)); + System.out.println(String.format(""Case #%d: %d, %d, %s => %d"", testCase, nSurprising, bestNum, g1.toString(), maxNum)); + } + + pw.flush(); + pw.close(); + sc.close(); + } +} +" +A20502,"import java.io.*; +public class dwtg +{ + public void dwtg()throws IOException + { + FileInputStream fstream = new FileInputStream(""C:/Users/m.l/Desktop/B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + int T=Integer.parseInt(br.readLine());int i,j,k,h,g,l,p=0,N=0,S=0;String input;int temp1,temp2,r,s,n,m,ans=0; + for(i=0;i=3) + {r=t[j]/3;s=r+1;} + if(t[j]%3==1) + { + if(t[j]!=1) + {r=(t[j]+2)/3;s=r;} + if(t[j]==1) + r=(t[j]+2)/3; + } + if(t[j]%3==2) + {r=(t[j]+1)/3;s=r+1;} + if(r>=p) + n+=1; + if(r=p) + m+=1; + } + if(S>=m) + ans=n+m; + if(S 100) { + return; + } + + for (int i = 0; i < testNum; i++) { + lineStr = br.readLine(); + sb.append(""Case #"" + (i + 1) + "": "" + process(lineStr) + ""\n""); + } + + writeToFile(sb.toString()); + System.out.println(sb.toString()); + System.out.println(""Finished.""); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void writeToFile(String str) { + BufferedWriter writer = null; + try { + File out = new File(""./results/dancing.out""); + writer = new BufferedWriter(new FileWriter(out)); + writer.write(str); + System.out.println(""Test result saved to "" + out.getAbsolutePath()); + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (writer != null) + writer.close(); + } catch (IOException e) { + } + } + } + + private static String process(String inputStr) { + String[] input = inputStr.split("" ""); + if (input.length >= 3) { + int n = Integer.parseInt(input[0]); + if (n < 0 || n > 100) { + return """"; + } + int s = Integer.parseInt(input[1]); + if (s < 0 || s > n) { + return """"; + } + + int p = Integer.parseInt(input[2]); + if (p < 0 || p > 10) { + return """"; + } + + List totalPoints = new ArrayList(); + + for (int i = 3; i < input.length; i++) { + int totalPoint = Integer.parseInt(input[i]); + if (totalPoint < 0 || totalPoint > 30) { + return """"; + } + totalPoints.add(totalPoint); + } + + return """" + getMaximumNum(n, s, p, totalPoints.toArray(new Integer[0])); + } + return ""invalid""; + } + + /** + * + * @param n googler number + * @param s surprising number + * @param p maximum result + * @param totalPoints + * @return + */ + public static int getMaximumNum(Integer n, Integer s, Integer p, Integer[] totalPoints) { + int count = 0; + for (int t : totalPoints) { + int nonSurprisingMax = 3 * p - 2; + int surprisingMax = 3 * p - 4; + + if (t >= nonSurprisingMax) { + count++; + } else if (s > 0 && t >= 2 && t <= 28) { + if (t >= surprisingMax) { + count++; + s--; + } + } + } + return count; + } + +} +" +A21424,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package javaapplication1; + +import java.io.*; +import java.util.StringTokenizer; + +public class JavaApplication1 { + + public static void main(String[] args) throws FileNotFoundException, IOException { + if(args.length <= 0) + System.out.println(""Invalid input""); + String filename = args[0]; + BufferedReader br = new BufferedReader(new FileReader(filename)); + int numLines = Integer.parseInt(br.readLine()); + int higher,surprise,ans; + for(int i=1; i<=numLines; i++) + { + higher = 0; + surprise = 0; + String line = br.readLine(); + StringTokenizer st = new StringTokenizer(line); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int p1 = 3*p-3; + int p2 = 3*p-4; + for(int j=1; j<=n; j++) + { + int t = Integer.parseInt(st.nextToken()); + if(p>1) + { + if(t>p1) + higher++; + else if(t>=p2) + surprise++; + } + else + { + if(t>=p) + higher++; + } + } + ans = higher+(surprise>s?s:surprise); + System.out.println(""Case #""+i+"": ""+ans); + } + } +} +" +A20943,"package org.moriraaca.codejam.dancingwithgooglers; + +import org.moriraaca.codejam.AbstractSolver; +import org.moriraaca.codejam.SolverConfiguration; + +@SolverConfiguration(parser = DancingWithTheGooglersDataParser.class) +public class DancingWithTheGooglersSolver extends + AbstractSolver { + + public static void main(String[] args) { + new DancingWithTheGooglersSolver().getSolution(); + } + + private int cdiv(int n, int d) { + return (n % d == 0 ? n / d : n / d + 1); + } + + @Override + protected String solveTestCase(DancingWithTheGooglersTestCase testCase) { + int counter = 0; + + for (int i = 0; i < testCase.scores.length; i++) { + int max = cdiv(testCase.scores[i], 3); + + if (max >= testCase.p) { + counter++; + } else if (testCase.scores[i] > 1 && testCase.scores[i] % 3 != 1 && max + 1 >= testCase.p + && testCase.S > 0) { + counter++; + testCase.S--; + } + + } + + return String.valueOf(counter); + } +} +" +A22333,"package com.keysbuy.codejam12.GDance; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + +public class GDance { + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + + try{ + File rFile = new File(""E:/GDance/B-large.in""); + File wFile = new File(""E:/GDance/B-large.out""); + BufferedReader br = new BufferedReader(new FileReader(rFile)); + BufferedWriter bw = new BufferedWriter(new FileWriter(wFile,true)); + + int caseNum = 1; + String str = br.readLine(); + str = br.readLine(); + + while(str != null) { + StringTokenizer tokenizer = new StringTokenizer(str); + int numGoogler = Integer.parseInt(tokenizer.nextToken()); + int numSuper = Integer.parseInt(tokenizer.nextToken()); + int maxPoint = Integer.parseInt(tokenizer.nextToken()); + + int highBound = 3 * maxPoint - 2; + if(highBound < maxPoint) { + highBound = maxPoint; + } + int lowBound = 3 * maxPoint - 4; + if(lowBound < maxPoint) { + lowBound = maxPoint; + } + + int validDancer = 0; + + while(tokenizer.hasMoreTokens()) { + int points = Integer.parseInt(tokenizer.nextToken()); + if(points >= highBound) { + validDancer++; + } + else if(numSuper !=0 && points >= lowBound) { + validDancer++; + numSuper--; + } + + } + bw.append(""Case #"" + caseNum + "": "" + validDancer); + bw.newLine(); + bw.flush(); + str = br.readLine(); + caseNum++; + } + bw.close(); + br.close(); + System.out.println(""DONE!""); + }catch(Exception e){ + System.out.println(e.getMessage()); + } + + } +} +" +A20558,"package google.code.jam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +public class DancingWithTheGooglers { + + final static String fileNameIn = ""B-large.in""; + final static String fileNameOut = ""B-large.out""; + + private static int solve(int S, int p, List t) { + int count = 0; + for (int i = 0; i < t.size(); i++) { + int bestResultNotSurprising = getBestResultNotSurprising(t.get(i)); + int bestResultSurprising = getBestResultSurprising(t.get(i)); + if (bestResultNotSurprising >= p) { + count++; + } else if (bestResultSurprising >= p && S > 0) { + count++; + S--; + } + } + return count; + } + + private static int getBestResultNotSurprising(int n) { + return getBestResult(n, false); + } + + private static int getBestResultSurprising(int n) { + return getBestResult(n, true); + } + + private static int getBestResult(int n, boolean surprising) { + int average = (int) Math.floor(n / 3); + int residue = n % 3; + if (n == 0) + return 0; + if (surprising && residue == 0) + return average + 1; + if (surprising && residue == 1) + return average + 1; + if (surprising && residue == 2) + return average + 2; + if (!surprising && residue == 0) + return average; + if (!surprising && residue == 1) + return average + 1; + if (!surprising && residue == 2) + return average + 1; + return average; + } + + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(fileNameIn)); + BufferedWriter out = new BufferedWriter(new FileWriter(fileNameOut)); + int testCases = Integer.parseInt(in.readLine()); + for (int i = 0; i < testCases; i++) { + String[] elements = in.readLine().split( + new Character((char) 32).toString()); + List values = new ArrayList(); + for (String v : elements) { + values.add(Integer.valueOf(v)); + } + ListIterator iterator = values.listIterator(); + int N = iterator.next(); + int S = iterator.next(); + int p = iterator.next(); + List t = values.subList(values.size() - N, values.size()); + out.write(String.format(""Case #%s: %s\n"", i + 1, solve(S, p, t))); + } + in.close(); + out.close(); + } + +} +" +A21479,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class ProblemB { + public static void main(String[] args) { + String output = """"; + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""input.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + // Read File Line By Line + strLine = br.readLine(); + int k = 1; + while ((strLine = br.readLine()) != null) { + String[] splits = strLine.split("" ""); + int N = Integer.parseInt(splits[0]); + int S = Integer.parseInt(splits[1]); + int H = Integer.parseInt(splits[2]); + int counter = 0; + int heigh = H + 2 * (H - 1); + int low = H + 2 * (H - 2); + if (H < 2) { + heigh = H; + low = H; + } + + for (int i = 3; i < splits.length; i++) { + int temp = Integer.parseInt(splits[i]); + if (temp >= heigh) + counter++; + else if (temp >= low) { + if (S > 0) { + S--; + counter++; + } + } + + } + output += ""Case #"" + k++ + "": "" + counter + ""\n""; + } + // Close the input stream + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + try { + // Create file + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + out.write(output); + // Close the output stream + out.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A21543,"package com.codejam.two12.GooglerDance; + +import java.util.ArrayList; +import java.util.Arrays; + +import com.jp.common.Puzzle; + +public class GooglerDance implements Puzzle{ + + private int numberOfGooglers; + private int surprisingTriplets; + private int parValue; + private int[] totalPointArray; + private int currentNumberOfSurprises; + private ArrayList ResultList; + + @Override + public String[] solve(String[] dataSet) { + // TODO Auto-generated method stub + ResultList = new ArrayList(); + processInput( dataSet); + calculateResult(); + + String result[] = new String[1]; + result[0] = String.valueOf(ResultList.size()); + return result; + } + + public void processInput(String[] dataSet){ + String data[] = dataSet[0].split("" ""); + numberOfGooglers = Integer.parseInt(data[0]); + surprisingTriplets = Integer.parseInt(data[1]); + parValue = Integer.parseInt(data[2]); + + totalPointArray = new int[numberOfGooglers]; + + for(int i = 0; i < totalPointArray.length; i++){ + totalPointArray[i] = Integer.parseInt(data[ 3 + i]); + } + + Arrays.sort(totalPointArray); + + } + + public void calculateResult(){ + + for (int i = 0; i < totalPointArray.length; i++){ + int total = totalPointArray[i]; + int remainder = total / 3; + int quotient = total % 3; + + int diff = parValue - remainder; + + // This cant be part of result. so skip and continue + if(diff > 2 || (total == 0 && parValue != 0) ){ + continue; + } + else if(diff <= 0 ){ + ResultList.add(total); + continue; + } + + if(diff == 1 && quotient == 0 && currentNumberOfSurprises < surprisingTriplets){ + ++ currentNumberOfSurprises; + ResultList.add(total); + } + else if(diff == 1 && quotient == 1 ){ + if(currentNumberOfSurprises < surprisingTriplets) + ++ currentNumberOfSurprises; + + ResultList.add(total); + } + else if(diff == 1 && quotient == 2){ + ResultList.add(total); + } + else if(diff == 2 && quotient == 2 && currentNumberOfSurprises < surprisingTriplets){ + ++ currentNumberOfSurprises; + ResultList.add(total); + } + } + + + } + +} +" +A21540,"public class Runner { + public static void main(String args[]) throws Exception { + BaseSolution bs = (BaseSolution) Class.forName(args[0]).newInstance(); + bs.start(args[1]); + } +}" +A21222,"import java.util.*; +import java.io.*; + +public class P2 +{ + public static void main(String[] args) throws Exception + { + Scanner sc = new Scanner(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""output.txt"")); + + int cases = Integer.parseInt(sc.nextLine()); + int c = 0, temp = 0, us = 0; + + for (int i = 0; i < cases; i++) + { + int n = sc.nextInt(); // no. of googlers + int s = sc.nextInt(); // no. of surprising + int p = sc.nextInt(); // criterion + us = 0; // used suprises + c = 0; // googlers that pass the test + + for(int j = 0; j= p || t1 >= p) + { + c++; + continue; + } + // total = 5 (1 1 3) 1.66 + else if(us != s && t2 >= p) + { + c++; + us++; + continue; + } + } + + pw.println(""Case #"" + (i + 1) + "": "" + c); + } + + pw.close(); + sc.close(); + } +} + +// ((temp+1)/n)+ 1 >= p +// ((temp+1)/n) >= p +// q+1 >= p" +A22039,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2012pa; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; + + +/** + * + * @author Fred + */ +public class CodeJam2012PA +{ + + /** + * type entrada.txt | java -jar Programa.jar > saida.txt + */ + public static void main(String[] args) throws Exception + { + + BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); + String line = buf.readLine(); + + + int j = 1; + while((line = buf.readLine()) != null) + { + String[] str = line.split("" ""); + + int n = Integer.valueOf(str[0]); + int s = Integer.valueOf(str[1]); + int p = Integer.valueOf(str[2]); + + ArrayList triplets = new ArrayList(); + for (int i = 0; i < n; i++) + { + triplets.add(Integer.valueOf(str[3+i])); + } + + System.out.println(""Case #""+j+"": ""+calcula(s, p, triplets)); + j++; + } + } + + public static String calcula(int s, int p, ArrayList t) + { + int count = 0; + int sused = 0; + for(Integer i : t) + { + if(i == 0) + { + if(p <= 0) + count++; + } + else if(i == 1) + { + if(p <= 1) + count++; + } + else if(i == 2) + { + if(p <= 1) + count++; + else + { + if(p <= 2) + { + count++; + sused++; + } + } + } + else if(i == 3) + { + if(p <= 1) + count++; + else + { + if(p <= 2) + { + count++; + sused++; + } + } + } + else if(i % 3 == 2) //numero 11 + { + if( (i/3) + 1 >= p) + count++; + else if((i/3) + 2 >= p) + { + sused++; + count++; + } + } + else if(i % 3 == 1) // 10 + { + if((i/3) + 1 >= p) + count++; + } + else if(i % 3 == 0) //9 + { + if(i/3 >= p) + count++; + else if((i/3) + 1 >= p) + { + count++; + sused++; + } + } + } + + int inv = sused - s; + if(inv <= 0) + return String.valueOf(count); + return String.valueOf(count-inv); + } + +} +" +A22899,"package gcj.quals; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class T2 { + public static void main(String[] args) { + File fi = new File(""/home/sighless/Documents/gcj/2""); + File fo = new File(""/home/sighless/Documents/gcj/out""); + + BufferedReader in = null; + BufferedWriter out = null; + + try { + in = new BufferedReader(new FileReader(fi)); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + + try { + out = new BufferedWriter(new FileWriter(fo)); + } catch (IOException e1) { + e1.printStackTrace(); + } + + List input = new ArrayList(); + try { + int lines = Integer.parseInt(in.readLine()); + + String line = """"; + while(lines != 0) { + line = in.readLine(); + + input.add(line); + lines--; + } + } catch (IOException e) {} + + String[] parts; + int googlers = 0, surprises = 0, checkScore = 0, result = 0; + Score googlerScore = new Score(); + for(int i = 0; i < input.size(); ++i) { + parts = input.get(i).split("" ""); + + googlers = Integer.parseInt(parts[0]); + surprises = Integer.parseInt(parts[1]); + checkScore = Integer.parseInt(parts[2]); + + result = 0; + for(int g = 0; g < googlers; ++g) { + googlerScore.init(Integer.parseInt(parts[g + 3]), surprises > 0 ? true : false); + if(googlerScore.check(checkScore)) { + result++; + if(googlerScore.isSurprise()) surprises--; + } + } + + + try { + out.write(""Case #"" + (i + 1) + "": "" + result + ""\n""); + } catch (IOException e) { + e.printStackTrace(); + } + } + + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + +class Score { + int total; + boolean surprise; + + public void init(int total, boolean surprise) { + this.total = total; + this.surprise = surprise; + } + + public boolean check(int singleScore) { + int average = total / 3; + + if(average >= singleScore) {surprise = false; return true;} + + int distance = singleScore - average; + switch(total - (average * 3)) { + case 0: + if((distance == 1) && average >= 1 && surprise) return true; + break; + case 1: + if(distance == 1) {surprise = false; return true;} + break; + case 2: + if(distance == 1) {surprise = false; return true;} + if((distance == 2) && surprise) return true; + break; + } + + return false; + } + + public boolean isSurprise() { + return surprise; + } +}" +A22570," +public interface ProblemCase { + + public String getResult(); + +} +" +A22303,"package reusable; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +public abstract class CodeJamBase { + private final List inputLines; + private final String filename; + private int testCases; + private int index = 0; + + public CodeJamBase(String filename) { + this.filename = (filename != """") ? filename : ""sample""; + + try { + inputLines = Files.readAllLines(Paths.get(""data/"" + this.filename + "".in""), Charset.defaultCharset()); + } catch (IOException e) { + throw new RuntimeException(""Failed to read file: '"" + this.filename + ""'""); + } + + setup(); + } + + protected void setup() { + setTestCases(nextInt()); + } + + protected abstract String solution(); + + public void run() { + long startTime = System.currentTimeMillis(); + + List outputLines = new ArrayList<>(); + + for (int i = 0; i < testCases; i++) { + String outputLine = ""Case #"" + (i + 1) + "": "" + solution(); + outputLines.add(outputLine); + System.out.println(outputLine); + } + + try { + Files.write(Paths.get(""data/"" + filename + "".out""), outputLines, Charset.defaultCharset()); + } catch (IOException e) { + throw new RuntimeException(""Failed to write file: '"" + filename + ""'""); + } + + System.out.println(); + System.err.println(""Total run time: "" + ((System.currentTimeMillis() - startTime) / 1000d) + ""s""); + } + + protected final String nextString() { + return inputLines.get(index++); + } + + protected final int nextInt() { + return Integer.parseInt(nextString()); + } + + protected final String[] nextStringArray() { + return inputLines.get(index++).split("" ""); + } + + protected final int[] nextIntArray() { + String[] items = nextStringArray(); + + int[] result = new int[items.length]; + + for (int i = 0; i < items.length; i++) { + result[i] = Integer.parseInt(items[i]); + } + + return result; + } + + public final void setTestCases(int testCases) { + this.testCases = testCases; + } +} +" +A22391,"package main; + +import java.io.*; +import java.util.Scanner; + +class Solver { + public void createSolution(Scanner input, BufferedWriter outWriter) throws IOException { + int numCases = input.nextInt(); + for (int i = 0; i < numCases; i++) { + int solution = 0; + int possibilities = 0; + + int numDancers = input.nextInt(); + int surprises = input.nextInt(); + int p = input.nextInt(); + + for (int k = 0; k < numDancers; k++) { + int score = input.nextInt(); + if (p == 0 || score > Math.max(0, (3*p - 3))) { + solution++; + } else if (score > Math.max(0, (3*p - 5))) { + possibilities++; + } else { + // ignore because score < 3*p - 4 + } + } + + if (surprises < possibilities) { + solution = solution + surprises; + } else { + solution = solution + possibilities; + } + + outWriter.write(""Case #"" + String.valueOf(i + 1) + "": "" + solution + ""\n""); + } + outWriter.close(); + } +} +" +A22667,"/** + * B.java + * @author Joel C. Soares + */ +import java.util.Scanner; +import java.util.LinkedList; +import java.util.Collections; + +class Googlers implements Comparable +{ + int n1, n2, n3; + int restando; + + Googlers( int a, int b, int c, int r) + { + n1 = a; n2 = b; n3 = c; restando = r; + } + + public int compareTo( Googlers g ) + { + if( n3 > g.n3 ) + return 1; + else if( n3 < g.n3 ) + return -1; + else + return 0; + } + +} // fim de classe + +public class B +{ + // remove grupos que tem notas maiores que p + public static int countGooglers( LinkedList lista, int p ) + { + int count = 0; + + for( int i = 0; i < lista.size(); i++ ) + { + if( lista.get( i ).n3 >= p ) + count++; + } + + return count; + } + + // faz ajuste para casos surpreendentes + public static void ajusteGooglersSurpreendentes( LinkedList lista, int p, int s ) + { + Googlers g; + + // coloca em ordem + Collections.sort( lista ); + + for( int i = lista.size() - 1; i >= 0; i-- ) + { + g = lista.get( i ); + if( s > 0 && g.n3 < p ) + { + if( g.restando >= 2 ) + { + g.restando -= 2; + g.n3 += 2; + if( g.restando > 0 ) + { + g.restando--; + g.n2++; + } + s--; + } + } + } // fim de for + } + + public static void ajusteGooglers( LinkedList lista, int p, int s ) + { + for( Googlers g : lista ) + { + if( g.n3 + 1 >= p || g.n3 + 2 < p || g.restando == 1 || + s == 0 ) + { + if( g.restando > 0 ) + { + g.restando--; + g.n3++; + } + if( g.restando > 0 ) + { + g.restando--; + g.n2++; + } + if( g.restando > 0 ) + { + g.restando--; + g.n1++; + } + } // fim de if + } // fim de for + } // fim de método + + public static boolean existeResto( LinkedList lista ) + { + for( Googlers g : lista ) + if( g.restando > 0 ) + return true; + + return false; + } + + public static void main( String args[] ) + { + Scanner input = new Scanner( System.in ); + int t, n, s, p, x, v; + LinkedList lista = new LinkedList(); + + t = input.nextInt(); + for( int i = 0; i < t; i++ ) + { + n = input.nextInt(); + s = input.nextInt(); + p = input.nextInt(); + lista.clear(); + for( int j = 0; j < n; j++ ) + { + x = input.nextInt(); + v = x / 3; + x = x % 3; + + // ajusta + if( x == 0 && v > 0 ) + { + x = 3; + v = v - 1; + } + + lista.add( new Googlers( v, v, v, x ) ); + } // fim de for + + // faz ajuste triviais + ajusteGooglers( lista, p, s ); + + // faz ajuste surpreendentes + ajusteGooglersSurpreendentes( lista, p, s ); + + System.out.printf( ""Case #%d: %d\n"", i + 1, countGooglers( lista, p ) ); + } // fim de for externo + } +}" +A22620,"/** + * + * @author slerig + * + */ + +import java.io.*; +import java.util.*; + +public class ScoreChecker { + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + File inFile = new File(""B-large.in""); + PrintWriter outFile = new PrintWriter(""B-large.out""); + Scanner in = new Scanner(inFile); + + int cases = in.nextInt(); + for(int i = 1; i <= cases; i++) + { + int googlers = in.nextInt(); + int surprising = in.nextInt(); + int minScore = in.nextInt(); + int googlersWithMin = 0; + int[][] scores = new int[googlers][3]; + + // Determining individual scores from total scores; before + // surprising scores are taken into account. + for(int j = 0; j < googlers; j++) + { + float score = in.nextLong(); + float ftemp = score / 3; + int temp = (int)ftemp; + if(ftemp - temp > 0.5) + { + scores[j][0] = temp + 1; + scores[j][1] = temp + 1; + scores[j][2] = temp; + } + else if(ftemp - temp > .25) + { + scores[j][0] = temp + 1; + scores[j][1] = temp; + scores[j][2] = temp; + } + else + { + for(int k = 0; k < 3; k++) + { + scores[j][k] = temp; + } + } + } + + // Editing for surprising scores. + for(int j = 0; j < googlers; j++) + { + // Very complicated way of deciding which scores are the surprising scores. + if(surprising > 0 && scores[j][0] != 0 && scores[j][1] != 0 && scores[j][2] != 0) + if(scores[j][0] != 10 && (scores[j][0] >= minScore-1 && scores[j][0] < minScore)) + if((scores[j][0] == scores[j][1])) + { + scores[j][0]++; + scores[j][1]--; + surprising--; + } + } + + // Checking for googlers with min score. + for(int j = 0; j < googlers; j++) + { + if(scores[j][0] >= minScore) + googlersWithMin++; + } + + outFile.println(""Case #"" + i + "": "" + googlersWithMin); + + /* Debugging code + outFile.println(); + for(int j = 0; j < googlers; j++) + { + for(int k = 0; k < 3; k++) + { + outFile.print(scores[j][k] + "" ""); + } + outFile.println(); + } + */ + } + outFile.close(); + } + +} +" +A22696,"import java.util.Scanner; +import java.io.File; +import java.io.FileWriter; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.FileNotFoundException; + +public class Dance { + + public static void main(String[] args) + { + File f = new File(""B-large.in""); + try + { + Scanner scan = new Scanner(f); + + int lines = Integer.parseInt(scan.nextLine()); + FileWriter fstream = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + for(int i=0; i3*(p-1)) + count++; + else if(countS < s && i>0 && (i==3*(p-1) || i==3*(p-1)-1)) + { + count++; + countS++; + } + + } + return count; + } + +} + + + + + + +" +A22282,"import java.io.*; +import javax.swing.*; +import javax.swing.JOptionPane.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import javax.swing.text.*; +import java.io.File; +import javax.swing.filechooser.FileFilter; +import javax.swing.text.html.*; +import java.util.Scanner; +import java.util.StringTokenizer; + +class Dancings +{ + public static void main(String args[]) + { + + int jumlahN[]=new int[101]; + + + + int hasil[]=new int[101]; + + + int i=0; + int j=0; + int k=0; + int l=0; + int il=0; + int cok3=0; + + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""b.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + j=0; + while ((strLine = br.readLine()) != null) { + // Print the content on the console + if(j==0) + { + i=Integer.parseInt(strLine); + if(i>100) + { + i=100; + } + else if(i<1) + { + i=1; + } + System.out.println (i); + } + else + { + int jum=0; + int panjangtext=strLine.length(); + int posisi=0; + //String isi=strLine.trim(); + char arr[]=strLine.toCharArray(); + + + + String tmp3=""""; + for(l=0; l=param) + { + + System.out.println(""Masuk 1""); + jum++; + } + else if(cok2>0 && s>0) + { + cok3=cok2-p; + int p3=cok3/2; + + if(p3>=param) + { + jum++; + s--; + } + System.out.println(""Masuk 2""); + + } + + + + m++; + } + + hasil[j]=jum; + } + //Close the input stream + j++; + } + in.close(); + } + catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + + + + try + { + File makefile= new File(""resultdancing.txt""); + FileWriter fwrite= new FileWriter(makefile); + PrintWriter pw=new PrintWriter(fwrite); + for(il=1; il<=i; il++) + { + pw.println(""Case #""+(il)+"": ""+hasil[il]+""\n""); + System.out.println(""case #""+(il)+"": ""+hasil[il]+""\n""); + } + fwrite.flush(); + fwrite.close(); + } + catch(IOException e) + { + e.printStackTrace(); + } + + + } + + + + + + + + + +} + +" +A21905,"package dancing; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.StringTokenizer; + +public class DancingTestCase { + + private final int noOfDancers; + private final int noOfSurprising; + private final int minScore; + private final List scores; + private final int result; + + DancingTestCase(int noOfDancers, int noOfSurprising, int minScore, List scores) { + if (scores.size() != noOfDancers) + throw new IllegalArgumentException(""Data mismatch""); + if (noOfSurprising> noOfDancers) + throw new IllegalArgumentException(""too many surprises""); + this.noOfDancers = noOfDancers; + this.noOfSurprising = noOfSurprising; + this.minScore = minScore; + this.scores = scores; + this.result = calculateResult(); + + } + + private int calculateResult() { + int total=0; + int grandTotal=0; + int remainingSuprises = noOfSurprising; + + //needs to try all permutation of each dancer having the suprising flag + //then return the bes + + for(int score : scores) { + + int div = score / 3; + int next = score - div; + int secondDiv = next /2; + int remainder = next - secondDiv; + //System.out.println(""input ""+score+"" first:""+div+"" second: ""+secondDiv+"" third:""+remainder); + //assume these won't be more than 1 apart + //remainder should be highest, div lowest + //could decrement second div and increment reminder if we have a suprise left and smallest value only 1 less + + if (remainder 0 //could make this a suprising result + && remainder < 10 //isn't already 10 (unlikly) + && secondDiv > 0 //the second smallest isn't already at zero + && ((remainder == div +1 && remainder==secondDiv)//we are currently only one apart from smallest //the second value is same as largest so could drop + || (remainder == div && remainder ==secondDiv) )) //all values same + { + remainder++; + remainingSuprises--; + } + + + int max = remainder; + if (max >= minScore) + total++; + + } + + if (total>grandTotal) + grandTotal=total; + + + return grandTotal; + + } + + + + public static void main(String[] args) { + + DancingTestCase dt = new DancingTestCase(3,1,5,new ArrayList(Arrays.asList(15,13,11))); + System.out.println(""Result""+dt.getResult()); + + dt = new DancingTestCase(3,0,8,new ArrayList(Arrays.asList(23,22,21))); + System.out.println(""Result""+dt.getResult()); + + dt = new DancingTestCase(2,1,1,new ArrayList(Arrays.asList(8,0))); + System.out.println(""Result""+dt.getResult()); + + dt = new DancingTestCase(6,2,8,new ArrayList(Arrays.asList(29,20,8,18,18,21))); + System.out.println(""Result""+dt.getResult()); + + + if (args.length != 2) + throw new IllegalArgumentException(""No file specified""); + + List data = new ArrayList(); + List results = new ArrayList(); + try { + FileInputStream fstream = new FileInputStream(args[0]); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + while ((strLine = br.readLine()) != null) { + data.add(strLine); + } + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + if (data.size() == 0) + throw new IllegalArgumentException(""No data in file""); + + int noTestCases = Integer.parseInt(data.get(0)); + if (data.size() != noTestCases + 1) + throw new IllegalArgumentException(""Number of test cases is not "" + + noTestCases); + + for (int i = 1; i <= noTestCases; i++) { + String s = ""Case #"" + i + "": "" + parse(data.get(i)); + System.out.println(s); + results.add(s); + } + + try { + FileWriter fostream = new FileWriter(args[1]); + BufferedWriter out = new BufferedWriter(fostream); + for (int i =0;i scores = new ArrayList(); + while (st.hasMoreTokens()) + scores.add(Integer.parseInt(st.nextToken())); + DancingTestCase dt = new DancingTestCase(noOfDancers,noSuprises,minValue,scores); + // System.out.println(""Result""+dt.getResult()); + return dt.getResult(); + } + + public int getResult() { + return result; + } + +} +" +A21523,"package ru.sidorkevich.google.jam.qualification.b; + +import com.sun.org.apache.bcel.internal.generic.FieldOrMethod; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TripletGenerator { + + private static int MIN_SCORE = 0; + private static int MAX_SCORE = 10; + + public static List generateTriples(int sum) { + List result = new ArrayList(); + + for (int score1 = MIN_SCORE; score1 <= MAX_SCORE; score1++) { + for (int score2 = MIN_SCORE; score2 <= MAX_SCORE; score2++) { + for (int score3 = MIN_SCORE; score3 <= MAX_SCORE; score3++) { + if (score1 + score2 + score3 == sum && isCorrect(score1, score2, score3)) { + Triplet newTriplet = new Triplet(score1, score2, score3); + if (!result.contains(newTriplet)) { + result.add(newTriplet); + } + } + } + } + } + + return result; + } + + private static boolean isCorrect(int score1, int score2, int score3) { + return Math.abs(score1 - score2) <= Triplet.MAX_DISTANCE && Math.abs(score1 - score3) <= Triplet.MAX_DISTANCE && Math.abs(score2 - score3) <= Triplet.MAX_DISTANCE; + } +} +" +A22281,"package com.jam.google; + +public class DancingWithTheGooglers { + + public int count(int n, int s, int p, String ts) { + int count = 0; + String[] split = ts.split("" ""); + for (String st : split) { + int t = Integer.parseInt(st); + int base = t / 3; + if (base < p-2) continue; + if (base>=p || + (base>= p-1 && t > 3*base) || + (base>= p-1 && (t > 3*base || (base > 0 && s-- >0))) || + (base>= p-2 && t-1 > 3*base && s-- >0) ) + count++; + } + return count; + } + +} +" +A21252,"import java.io.*; +import java.util.*; + +public class Sample +{ + public static void main(String []args) throws IOException + { + BufferedReader con = new BufferedReader(new FileReader(""input.txt"")); + BufferedWriter out = new BufferedWriter (new FileWriter(""output.txt"")); + //Console con = System.console(); + int T = Integer.parseInt(con.readLine()); + String input; + + for(int i=1; i<=T; i++) + { + input = con.readLine(); + StringTokenizer list = new StringTokenizer(input); + int N = Integer.parseInt(list.nextToken()); // No. of googlers + int S = Integer.parseInt(list.nextToken()); // No. of surprising triplets + int p = Integer.parseInt(list.nextToken()); // maximum score + + int score, + output = 0; + + for(int j=0; j= 3*p-2) + output++; + else + if(S>0 && score>1 && score>=3*p-4) + { + S--; + output++; + } + } + out.write(""Case #""+i+"": ""+output); + out.newLine(); + } + con.close(); + out.close(); + } +} +" +A22871,"import java.io.*; + +public class Main2 { + public static void main(String[] args) { + try { + String[] a; + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + FileWriter fst = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fst); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = br.readLine(); + int x = Integer.parseInt(strLine); + int result = 0; + for (int j = 0; j < x; j++) { + result = 0; + System.out.print(""Case #"" + (j + 1) + "": ""); + strLine = br.readLine(); + a = strLine.split("" ""); + int n = Integer.parseInt(a[0]); + int s = Integer.parseInt(a[1]); + int p = Integer.parseInt(a[2]); + + for (int i = 3; i < (n + 3); i++) { + int total = Integer.parseInt(a[i]); + int temp = total / 3; + int reminder = ((Integer.parseInt(a[i])) - (3 * temp)); + + if (temp >= p) { + result++; + } else { + if (reminder == 1) { + + if ((temp + 1) >= p) + result++; + + } else if (reminder == 2) { + if ((temp + 1) >= p) + result++; + else { + if ((temp + 2) >= p && s != 0) { + result++; + s--; + } + } + } else { + if ((temp + 1) == p && s != 0 && temp != 0) { + result++; + s--; + } + + } + } + } + + out.append(""Case #"" + (j + 1) + "": "" + result); + out.newLine(); + System.out.println(result); + } + + in.close(); + out.close(); + } catch (Exception e) {// Catch exception if any + } + } +}" +A22891,"import java.util.Scanner; +import java.io.*; +public class Q2 { + public static void main(String[] args) throws IOException { + Scanner w = new Scanner(new File(""D:/sample.txt"")); + int cases = Integer.parseInt(w.nextLine()); + for (int i = 0; i < cases; i++) { + int count = 0; + int n = w.nextInt(); + int s = w.nextInt(); + int p = w.nextInt(); + for (int j = 0; j < n; j++) { + int total = w.nextInt(); + int k = total / 3; + int r = total % 3; + if (total == 0) { + if (0 >= p) count++; + } + else if(r==0){ + if(k>=p)count++; + else if(s>0&&k+1>=p){ + s--; + count++; + } + } + else if(r==1){ + if(k+1>=p)count++; + } + else if(r==2){ + if(k+1>=p)count++; + else if(s>0&&k+2>=p){ + s--; + count++; + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + count); + } + } +}" +A20488,"package dancingwiththegooglers; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +/** + * @author Emmanuel JS Hoarau - Google Code Jam 2012 + */ +public class DancingWithTheGooglers { + + /* + * Possible combos: + * - 1 1 1 => may suprisingly be 0 1 2 (max+1) + * - 1 1 2 => may suprisingly be 0 2 2 (max unchanged) + * - 1 2 2 => may suprisingly be 1 1 3 (max+1) + * + * Limits: 0 is min + * - 0 0 0 + * - 0 0 1 + */ + String executeLine(final String line) { + String words[] = line.split("" ""); + int n = 0; + int nbGooglers = Integer.parseInt(words[n++]); + int nbSurprises = Integer.parseInt(words[n++]); + int p = Integer.parseInt(words[n++]); + int result = 0; + for (int i = 0; i < nbGooglers; ++i) { + int sum = Integer.parseInt(words[n++]); + + // judge #1 (min) + int note1 = sum/3; + int remains = sum-note1; + // judge #2 + int note2 = remains/2; + remains -= note2; + // judge #3 (max) + int note3 = remains; + + if (note3 >= p) { + ++result; + } else { + if ((sum > 1) && (note3 == (p - 1)) && (nbSurprises > 0) && (note3 == note2)) { + ++result; + --nbSurprises; + } + } + } + return Integer.toString(result); + } + + void execute() { + try { + InputStreamReader stream = new InputStreamReader(System.in); + BufferedReader reader = new BufferedReader(stream); + + String line = reader.readLine(); + int lines = Integer.parseInt(line); + for (int i = 1; i <= lines; ++i) { + line = reader.readLine(); + StringBuilder out = new StringBuilder(); + out.append(""Case #""); + out.append(i); + out.append("": ""); + out.append(executeLine(line)); + System.out.println(out.toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new DancingWithTheGooglers().execute(); + } +} + +" +A20624,"import java.util.*; + +public class B { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int N = scan.nextInt(); + scan.nextLine(); + for (int i = 1; i <= N; i++) + System.out.println(""Case #""+i+"": ""+solve(scan)); + } + + public static Object solve(Scanner scan) { + int n = scan.nextInt(), s = scan.nextInt(), p = scan.nextInt(); + int out = 0, t; + + while (n-- > 0) { + t = scan.nextInt(); + if ((t+2)/3 >= p || t > 1 && (t+4)/3 >= p && s-- > 0) + out++; + } + + return out+""""; + } +} +" +A21181,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam; + +import com.isotopeent.codejam.lib.SolverBase; +import com.isotopeent.codejam.lib.Utils; +import com.isotopeent.codejam.lib.converters.IntArrayLine; + +public class Solver extends SolverBase { + + private static final String FILE_PATH = ""C:\\codejam\\""; + private static final String FILE_NAME = ""B-large""; + private static final int INIT_PARAM_COUNT = 1; + + private static final int PARAM_COUNT = 3; + private static final int MAX_ARRAY_SIZE = PARAM_COUNT + 100; // 3 params + N=100 + private static final int SCORE_COUNT = 3; + + public static void main(String [] args) { + Utils.solve(FILE_PATH, FILE_NAME, new IntArrayLine(new int[MAX_ARRAY_SIZE]), new Solver()); + } + + public Solver() { + super(INIT_PARAM_COUNT); + } + + @Override + protected String solve(int[] input) { + int surprisingScores = input[1]; + int scoreThreashold = input[2]; + int minUnsurprisingScore = scoreThreashold * SCORE_COUNT - SCORE_COUNT + 1; + int minSurprisingScore = Math.max(minUnsurprisingScore - SCORE_COUNT + 1, scoreThreashold); + + int count = 0; + int length = input.length; + for (int i = PARAM_COUNT; i < length; i++) { + int score = input[i]; + if (score >= minUnsurprisingScore) { + count++; + } else if (score >= minSurprisingScore && surprisingScores > 0) { + count++; + surprisingScores--; + } + } + return Integer.toString(count); + } + +} +" +A22187,"import java.util.ArrayList; +import java.util.List; + + +public class Main { + + public static void main(String[] args) { + List lstLinesOutput = new ArrayList(); + + List lstLinesInput = FileReaderHandler.openFile(""/home/guillaume/Bureau/input""); + for(int n=1;n< Integer.parseInt(lstLinesInput.get(0)) + 1;n++){ + System.out.println(""Case "" + n); + String sOutput = ""Case #"" + n + "": ""; + String sInput = lstLinesInput.get(n); + String[] hInput = sInput.split("" ""); + //to int array + int[] iInput = new int[hInput.length]; + for(int i=0;i < hInput.length;i++){ + iInput[i] = Integer.parseInt(hInput[i]); + } + int iNbSurprising = iInput[1]; + int iToBeat = iInput[2]; + int iNbAnswers = 0; + for(int i=0;i 0){ + int iBase = iScore/3; + int iReste = iScore%3; + if(iBase >= iToBeat || iReste > 0 && iBase + 1 >= iToBeat){ + iNbAnswers++; + }else if(iNbSurprising > 0 && (iReste == 0 && iBase + 1 >= iToBeat || iReste == 2 && iBase + 2 >= iToBeat)){ + iNbAnswers++; + iNbSurprising--; + } + } else if(iToBeat == 0){ + iNbAnswers++; + } + } + sOutput += iNbAnswers; + lstLinesOutput.add(sOutput); + } + + if(Integer.parseInt(lstLinesInput.get(0)) != lstLinesOutput.size()){ + System.out.println(""ERROR!!!""); + } + FileWriterHandler.writeToFile(lstLinesOutput); + } +}" +A20568,"package ProblemSolvers; + +import CaseSolvers.DancingGooglersCase; + +public class DancingGooglers extends ProblemSolver { + + public DancingGooglers(String filePath) { + super(filePath); + } + + @Override + public void process() { + cases = io.readInt(); + + for (int i = 1; i <= cases; i++) { + new DancingGooglersCase(i, 1, io).process().printSolution(); + } + } +} +" +A20895,"import java.util.Scanner; +import java.util.StringTokenizer; + + +public class DancingWiththeGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner in =new Scanner(System.in); + int cases=Integer.parseInt(in.nextLine())+1; + for(int tt=1;tt=best+Math.max(best-1, 0)*2){ + count++; + }else if(score>=best+Math.max(best-2,0)*2&&surprise>0){ + count++; + surprise--; + } + } + System.out.printf(""Case #%d: %d\n"",tt,count); + } + } + +} +" +A20428,"/* + a = y b = n c = f d = i e = c f = w g = l h = b i = k j = u k = o l = m m = x n = s o = e + p = v q = z r = p s = d t = r u = j v = g w = t x = h y = a z = q +*/ +import java.util.*; +public class Dancing { + + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + sc.nextLine(); + + for (int i = 0; i < T; i++) + { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + int AWESOME = p + 2*(p-1); + int SURP_GOOD = p + 2*(p-2); + + System.out.print(""Case #"" + (i + 1) + "": ""); + + int goodOnes = 0; + int[] curr = new int[N]; + for (int j = 0; j < N; j++) + { + curr[j] = sc.nextInt(); + } + Arrays.sort(curr); + for (int j = N-1; j >= 0; j--) + { + if (p == 0) + goodOnes++; + else if (curr[j] >= AWESOME && curr[j] > 0) + goodOnes++; + else if (curr[j] > 0 && S > 0 && curr[j] >= SURP_GOOD) + { + goodOnes++; + S--; + } + } + System.out.println(goodOnes); + } + } +}" +A21705,"import java.text.*; +import java.io.*; +import java.util.*; +import java.lang.Math; + +public class B +{ + public static void main(String[] args) throws Exception + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(br.readLine()); + + for(int t = 1; t <= T; t++) { + + System.out.print(""Case #"" + t + "": ""); + + + String str = br.readLine(); + String[] starr = str.split("" ""); + + int n = Integer.parseInt(starr[0]); + int s = Integer.parseInt(starr[1]); + int p = Integer.parseInt(starr[2]); + int count = 0; + for(int i = 3; i < n+3; i++) { + + int num = Integer.parseInt(starr[i]); + if(num == 0) { + if(p == 0) count++; + } + else { + + int val = (num+2)/3; + if(val >= p) { + count++; + } + else if(s > 0 && (num%3 == 0 || num%3 == 2) && val == p - 1) { + count++; + s--; + } + } + } + + + System.out.println(count); + } + } +}" +A21260,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Main { + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + + Scanner scanner = new Scanner(new File(""input.txt"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""output.txt"")); + + int N = scanner.nextInt(); + + for (int i = 1; i <= N; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + + ArrayList e = new ArrayList(); + for (int j = 0; j < n; j++) + e.add(scanner.nextInt()); + + Solver solver = new Solver(s, p, e); + + writer.append(""Case #"" + i + "": "" + solver.solve()); + writer.newLine(); + + } + + writer.close(); + scanner.close(); + + } + +} +" +A22091,"package com.google.codejam2012.qual.b; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +public class DancingWithTheGooglers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(""2012/qualB/input.txt"")); + PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(""2012/qualB/output.txt""))); + + int numberOfTests = Integer.parseInt(reader.readLine()); // T + + for (int i = 0; i < numberOfTests; i++) { + System.out.println(i); + String[] testCase = reader.readLine().split("" ""); + int numberOfGooglers = Integer.parseInt(testCase[0]); // N + int numberOfSurprisingTriplets = Integer.parseInt(testCase[1]); // S + int minBestResult = Integer.parseInt(testCase[2]); // p + //int[] totalPoints = new int[numberOfGooglers]; + int countOk = 0, surprises = 0; + if (minBestResult == 0) { + countOk = numberOfGooglers; + } else { + for (int j = 0; j < numberOfGooglers; j++) { + int totalPoints = Integer.parseInt(testCase[j + 3]); // ti + int minTotal = minBestResult + (2 * (minBestResult - 1)); + if (totalPoints >= minTotal) { + // ok without surprise + countOk++; + } else if (minBestResult > 1) { + minTotal = minBestResult + (2 * (minBestResult - 2)); + if (totalPoints >= minTotal) { + // ok with surprise + surprises++; + if (surprises <= numberOfSurprisingTriplets) { + countOk++; + } + } + } + } + } + + writer.println(""Case #"" + (i + 1) + "": "" + countOk); + } + + writer.flush(); + writer.close(); + reader.close(); + } + +} +" +A21935,"package jp.funnything.competition.util; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import org.apache.commons.io.IOUtils; + +public class AnswerWriter { + private static final String DEFAULT_FORMAT = ""Case #%d: %s\n""; + + private final BufferedWriter _writer; + private final String _format; + + public AnswerWriter( final File output , final String format ) { + try { + _writer = new BufferedWriter( new FileWriter( output ) ); + _format = format != null ? format : DEFAULT_FORMAT; + } catch ( final IOException e ) { + throw new RuntimeException( e ); + } + } + + public void close() { + IOUtils.closeQuietly( _writer ); + } + + public void write( final int questionNumber , final Object result ) { + write( questionNumber , result.toString() , true ); + } + + public void write( final int questionNumber , final String result ) { + write( questionNumber , result , true ); + } + + public void write( final int questionNumber , final String result , final boolean tee ) { + try { + final String content = String.format( _format , questionNumber , result ); + + if ( tee ) { + System.out.print( content ); + System.out.flush(); + } + + _writer.write( content ); + } catch ( final IOException e ) { + throw new RuntimeException( e ); + } + } +} +" +A23000,"package codejam; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +public class ProblemB { + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + // TODO Auto-generated method stub + + Scanner sc = new Scanner(new File(""ProblemB.txt.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""ProblemB.txt.out""))); + + int t = sc.nextInt(); + + for(int i=0;i=p) count++; + else if ((max+1) == p && s>0 && diff!=-1 && max>0){ + s--; + count++; + } + + } + + bw.write(""Case #"" + (i+1) +"": ""+ count +""\n""); + System.out.println(""Case #"" + (i+1) +"": ""+ count); + } + + bw.close(); + sc.close(); + + + } + + } + + +" +A21036,"import java.util.*; +import java.io.*; +import java.math.*; + + + +public class Solver +{ + private String key = ""yhesocvxduiglbkrztnwjpfmaq""; + + public int[] convert(String[] s) { + int[] res = new int[s.length]; + for(int i = 0;i < s.length; i++) { + res[i] = Integer.parseInt(s[i]); + } + return res; + } + + private String decode(String str, String res) { + if (str.length() == 0) {return res;} + String nextchar = """"; + if (str.charAt(0) == ' ') {nextchar = "" "";} + else {nextchar = key.substring(str.charAt(0) - 'a',str.charAt(0) - 'a' + 1);} + return decode(str.substring(1),res + nextchar); + } + + public String solve(BufferedReader reader) { + try { + String word = reader.readLine(); + return decode(word,""""); + } + catch(Exception e) {e.printStackTrace(); return """";} + } + + public String solve2(BufferedReader reader) { + try { + int[] dims = convert(reader.readLine().split("" "")); + int num = dims[0]; + int sups = dims[1]; + int target = dims[2]; + int total = 0; + for(int i = 0; i < num; i++) { + if(dims[3+i] > (target -1)*3) {total++;} + else if(dims[3+i] < Math.max((target-1)*3 - 1,1)) {} + else { + if(sups > 0) {total++; sups--;} + } + } + return """"+total; + } + catch(Exception e) {e.printStackTrace(); return """";} + } + + public static void main(String[] args) + { + try + { + FileReader flrdr = new FileReader(new File(""test.in"")); + BufferedReader br = new BufferedReader(flrdr); + FileWriter writer = new FileWriter(""output.txt""); + int n = Integer.parseInt(br.readLine()); + Solver s = new Solver(); + for(int i = 1; i < n+1; i++) + { + //System.out.println(""Case #"" + i + "": "" + s.solve4(br) + ""\n""); + writer.write(""Case #"" + i + "": "" + s.solve2(br) + ""\n""); + } + writer.close(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static void checkFiles(String f1, String f2) { + try { + FileReader flrd1 = new FileReader(new File(f1)); + FileReader flrd2 = new FileReader(new File(f2)); + BufferedReader br1 = new BufferedReader(flrd1); + BufferedReader br2 = new BufferedReader(flrd2); + int count = 1; + while(br1.readLine().equals(br2.readLine())) { + count++; + } + System.out.println(count); + } + catch(Exception e) {e.printStackTrace();} + } +}" +A22315,"package codejam.common; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public abstract class AbstractProblemSolver { + + public void solve(File input, File output) { + try (BufferedReader reader = new BufferedReader(new FileReader(input)); + BufferedWriter writer = new BufferedWriter(new FileWriter( + output))) { + String line = reader.readLine(); + int numberCases = Integer.parseInt(line); + for (int i = 1; i <= numberCases; i++) { + P problem = readProblem(reader); + S solution = solveProblem(problem); + writeSolution(i, solution, writer); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public abstract P readProblem(BufferedReader reader) throws IOException; + + public abstract S solveProblem(P problem); + + public abstract void writeSolution(int solutionNumber, S solution, + BufferedWriter writer) throws IOException; + +} +" +A21649,"package de.johanneslauber.codejam.model.impl; + +import de.johanneslauber.codejam.model.BaseProblem; +import de.johanneslauber.codejam.model.ICase; +import de.johanneslauber.codejam.model.IProblem; + +/** + * + * @author Johannes Lauber - joh.lauber@googlemail.com + * + */ +public class DancingGooglersProblem extends BaseProblem implements IProblem { + + @Override + public void solveCases() { + for (ICase currentCase : super.listOfCases) { + StringBuilder builder = new StringBuilder(); + DancingGooglersCase dancingGoogleCase = (DancingGooglersCase) currentCase; + + int[] maxPointsForGooglers = dancingGoogleCase + .getMaxPointsOfGooglers(); + + int minLimitOfPoints = dancingGoogleCase.getMinLimitOfPoints(); + int numberOfTriplets = dancingGoogleCase.getNumberOfTriplets(); + int numberOfGooglersHigherLimit = 0; + + for (int i = 0; i < maxPointsForGooglers.length; i++) { + int maxPointsForGoogler = maxPointsForGooglers[i]; + double quotient = (double) maxPointsForGoogler / (double) 3; + + // zero is a special case + if (maxPointsForGoogler != 0) { + + // test whether a triplet with 1 or 2 apart is possible with + // the + // current min level + if ((Math.round(quotient) + 1) >= minLimitOfPoints) { + + // test whether apart is 1 or 2 + if ((minLimitOfPoints - 1) >= quotient) { + + // are ther more triplets left? + if (numberOfTriplets > 0) { + numberOfGooglersHigherLimit++; + numberOfTriplets--; + } else { + // its possible to make a triplet with apart of + // 2, + // but no more left + System.out.println(""no more left""); + } + } else { + numberOfGooglersHigherLimit++; + } + } + } else if (minLimitOfPoints == 0) { + // if the limit and the max points are 0, it's possible + numberOfGooglersHigherLimit++; + } + } + + // for (int i = 0; i < maxPointsForGooglers.length; i++) { + // if (((maxPointsForGooglers[i] + 2) / 3) >= minLimitOfPoints) { + // numberOfGooglersHigherLimit++; + // } else if ((numberOfTriplets > 0) + // && (((maxPointsForGooglers[i] + 4) / 3) >= minLimitOfPoints)) { + // numberOfTriplets--; + // numberOfGooglersHigherLimit++; + // } + // } + + this.writeToFile(String.valueOf(numberOfGooglersHigherLimit)); + } + this.closeWriter(); + } + +} +" +A21628,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class Googlers_Dance { + + FileWriter fstream; + BufferedWriter out; + + Googlers_Dance() + { + try + { + fstream = new FileWriter(""E:\\Yoxos\\EclipseNew\\workspace\\TestProject\\Dance_op.txt""); + out = new BufferedWriter(fstream); + + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + Googlers_Dance obj = new Googlers_Dance(); + obj.getInput(); + + //Close the output stream + //out.close(); + } + + void printFile(String strLine) + { + try{ + // Create file + + out.write(strLine); + + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + void getInput() + { + try{ + // Open the file that is the first + // command line parameter + int iNumberOfLines = 0 ; + FileInputStream fstream = new FileInputStream(""E:\\Yoxos\\EclipseNew\\workspace\\TestProject\\src\\B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + String strLine; + //Read File Line By Line + if ((strLine = br.readLine()) != null) { + // Print the content on the console + //System.out.println (""""+strLine); + iNumberOfLines = Integer.parseInt(strLine); + } + int j=1; + while(iNumberOfLines-- > 0 && ((strLine = br.readLine())!=null)) + { + + int iTempCount = getGooglersBestNumber(strLine); + String strTemp= ""Case #""+j+"": ""+iTempCount; + + System.out.println(strTemp); + j++; + } + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + e.printStackTrace(); + } + } + + int getGooglersBestNumber(String strLine) + { + int iGooglersBestCount=0; + String strWords[] = strLine.split("" ""); + int iN = Integer.parseInt(strWords[0]); + int iSurprising = Integer.parseInt(strWords[1]); + int iP = Integer.parseInt(strWords[2]); + + int l=3,k=0; + + while(l < strWords.length) { + k=iP; + int iT = Integer.parseInt(strWords[l++]); + + while(k>=0 && k<=10) + { + int iTempMaxVal = (k*3); + if(iT >= iTempMaxVal) { + + if((iT==iTempMaxVal) || (iT == iTempMaxVal+1) || (iT == iTempMaxVal+2)) { + + iGooglersBestCount++; + break; + } + + if(iSurprising>0) { + + if((iT == iTempMaxVal+3) || (iT == iTempMaxVal+4)) { + iSurprising--; + iGooglersBestCount++; + break; + } + } + + + k++; + } + else { + + if(iT <= iTempMaxVal) { + + if((iT==iTempMaxVal) || (iT == iTempMaxVal-1) || (iT == iTempMaxVal-2)) { + iGooglersBestCount++; + break; + } + + if(iSurprising>0) { + + if(iT!=0 && (iT == iTempMaxVal-3) || (iT == iTempMaxVal-4)) { + iGooglersBestCount++; + iSurprising--; + break; + } + } + + break; + } + + } + } + } + + return iGooglersBestCount; + } +} +" +A22216,"package com.interview.prep.sorting; + +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class DancingGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + File file = new File(""/Users/Ankit/Downloads/B-large.in""); + FileInputStream fis = null; + BufferedInputStream bis = null; + DataInputStream dis = null; + + try { + fis = new FileInputStream(file); + + // Here BufferedInputStream is added for fast reading. + bis = new BufferedInputStream(fis); + dis = new DataInputStream(bis); + + // dis.available() returns 0 if the file does not have more lines. + int i = 0; + dis.readLine(); + while (dis.available() != 0) { + i++; + dancingStars(dis.readLine(), i); + } + fis.close(); + bis.close(); + dis.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public static void dancingStars(String caseString, int casenumber) { + String[] numbers = caseString.split("" ""); + int googlers = Integer.parseInt(numbers[0]); + int max = Integer.parseInt(numbers[2]); + int surprises = Integer.parseInt(numbers[1]); + int counter = 0; + int limit = 3*max - 2; + + + for (int i=0;i= (limit)){ + counter++; + continue; + } + if(surprises > 0 && score >= (limit-2) && score > 1 ) { + surprises--; + counter++; + continue; + } + } + System.out.println(""Case #""+ casenumber + "": "" +counter); + } +} +" +A20259,"import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class B { + static ArrayList surprising = new ArrayList(); + static ArrayList nonSurprising = new ArrayList(); + + public static boolean isValid(int a, int b, int c) { + if (Math.abs(a - b) > 2 || Math.abs(a - c) > 2 || Math.abs(b - c) > 2) + return false; + return true; + } + + static public void generate(int a, int b, int c, int i) { + int j = 0; + if (i == 1) + j = a; + else if (i == 2) + j = b; + + for (; j <= 10; j++) { + if (i == 0) + generate(j, b, c, 1); + else if (i == 1) + generate(a, j, c, 2); + else if (i == 2) + if (isValid(a, b, j)) { + Triplet tmp = new Triplet(a, b, j); + if (tmp.isSurprising()) + surprising.add(tmp); + else + nonSurprising.add(tmp); + } + } + } + + static private int getMax(ArrayList currTriplets, int n, + ArrayList googlers, int p) { + int removed = 0; + label:for (int i = 0; i < n; i++) { + int maxNo = -1, maxI = -1; + for (int j = 0; j < currTriplets.size(); j++) { + Triplet tr = currTriplets.get(j); + if (tr.a == tr.b && tr.a == 6) + System.out.print(""""); + int tmp = 0; + for (int j2 = 0; j2 < googlers.size(); j2++) + if (tr.sum == googlers.get(j2) && tr.best >= p) + tmp++; + if (tmp > maxNo) { + maxNo = tmp; + maxI = j; + } + } + if (maxNo == 0) + break; + Triplet chosen = currTriplets.get(maxI); + for (int j = 0; j < googlers.size(); j++) + if (chosen.sum == googlers.get(j) && chosen.best >= p) { + googlers.remove(j); + removed++; + if (removed == n) + break label; + j--; + } + } + return removed; + } + + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(new FileInputStream(""B-large.in"")); + FileWriter out = new FileWriter(new File(""B-large.out"")); + generate(0, 0, 0, 0); + int t = in.nextInt(), cnt = 1, n, s, p, res; + ArrayList googlers = new ArrayList(); + while (t-- > 0) { + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + for (int i = 0; i < n; i++) + googlers.add(in.nextInt()); + res = getMax(nonSurprising, n - s, googlers, p); + res += getMax(surprising, s, googlers, p); + out.write(""Case #"" + cnt++ + "": "" + res + ""\n""); + googlers.clear(); + } + out.close(); + in.close(); + } + + static class Triplet { + private int a, b, c, sum, best; + + public Triplet(int a, int b, int c) { + this.a = a; + this.b = b; + this.c = c; + sum = a + b + c; + best = Math.max(a, Math.max(b, c)); + } + + public boolean isSurprising() { + if (Math.abs(a - b) == 2 || Math.abs(a - c) == 2 + || Math.abs(b - c) == 2) + return true; + return false; + } + + public int sum() { + return sum; + } + + public String toString() { + return ""["" + a + "" "" + b + "" "" + c + ""]""; + } + + public int getBest() { + return best; + } + + } +} +" +A21434,"package com.google.jam.eaque.stub; + +import java.io.IOException; + +public abstract class Stub { + + private String outputFileName; + + public String getOutputFileName() { + return outputFileName; + } + + public void setOutputFileName(String outputFileName) { + this.outputFileName = outputFileName; + } + + public abstract String runTestCase(InputFileManager ifm) + throws NumberFormatException, IOException; +} +" +A21556,"import java.io.*; +import java.util.*; + +public class B { + public final static String FILE_IN = ""B-large.in""; + public final static String FILE_OUT = ""B-large.out""; + + public static class Case { + public int n, s, p; + public int[] t; + + public String toString() { + return """" + n + "","" + s + "","" + p + "":"" + Arrays.toString(t); + } + } + + public static Case readCase(BufferedReader r) throws IOException { + Case c = new Case(); + + String[] tk = r.readLine().split("" ""); + c.n = Integer.parseInt(tk[0]); + c.s = Integer.parseInt(tk[1]); + c.p = Integer.parseInt(tk[2]); + c.t = new int[c.n]; + for (int i=0; i= c.p) { + t++; + } + else if (q > 0 && q + 1 >= c.p && sr > 0) { + t++; + sr--; + } + } + else if (r == 1) { + if (q+1 >= c.p) { + t++; + } + } + else { + if (q+1 >= c.p) { + t++; + } + else if (q+2 >= c.p && sr > 0) { + t++; + sr--; + } + } + } + + w.write(""Case #"" + (index+1) + "": "" + t); + w.newLine(); + } + + public static void main(String[] args) throws Exception { + BufferedReader r = new BufferedReader(new FileReader(FILE_IN)); + BufferedWriter w = new BufferedWriter(new FileWriter(FILE_OUT)); + int num = Integer.parseInt(r.readLine()); + for (int i=0; i= 28) { + if (10 >= p) up++; + } + else if (x == 0) { + if (0 >= p) up++; + } + else { + int u = x / 3; + int m = x % 3; + if (m > 0) u++; + if (u >= p) up++; + else { + if (S > 0 && m != 1) { + u++; + if (u >= p) { + S--; + up++; + } + } + } + } + } + + Gcj.outcase(cas, false); + System.out.println(up); + } + + gcj.terminate(); + + } + +} +" +A21654,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +//package dancinggooglers; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Scanner; +import java.util.regex.Pattern; + +/** + * + * @author nasir + */ +public class Main { + + private String[] inputArray; + private int surprising; + private int P; + private int maximumGooglers = 0; + private Queue URLQueue = new LinkedList(); + + public Main() { + readConsole(); + parseInput(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Main m = new Main(); + } + + public void readConsole() { + boolean first = true; + int testCases = 0; + int loop = 0; + int index = 0; + Scanner scanner = new Scanner(System.in); + while (loop <= testCases) { + String str = scanner.nextLine(); + if (first) { + first = false; + testCases = Integer.parseInt(str); + inputArray = new String[testCases]; + } else { + + inputArray[index++] = str; + } + loop++; + } + + } + + public void parseInput() { + String split = ""[\\s]""; + Pattern p = Pattern.compile(split); + int k = 1; + for (String str : inputArray) { + String[] tokens = p.split(str); + + surprising = Integer.parseInt(tokens[1]); + P = Integer.parseInt(tokens[2]); + List googlerList = new LinkedList(); + for(int i=3; i=0; index--){ + Integer integer = googlerList.get(index); + Integer avg = integer/3; + Integer j1 = avg; + Integer j2 = avg; + Integer j3 = avg; + Integer remainder = integer%3; + if(remainder == 2){ + j1+=1; + j2+=1; + remainder = 0; + } + if(remainder == 1){ + j1+=1; + } + + if(j1>= P || j2>=P || j3>=P){ + System.out.println(""J1 ""+j1+"" J2 ""+j2+"" J3 ""+j3); + maximumGooglers++; + continue; + } + if(surprising>0){ + if(j1==j2 && j2>0 && j1+1>=P){ + surprising--; + maximumGooglers++; + } + } + + } + + System.out.println(""Case #""+k+"": ""+maximumGooglers); + k++; + + } + + } + + public class dataStructure{ + int total; + int judge1; + int judge2; + int judge3; + + public int getJudge1() { + return judge1; + } + + public void setJudge1(int judge1) { + this.judge1 = judge1; + } + + public int getJudge2() { + return judge2; + } + + public void setJudge2(int judge2) { + this.judge2 = judge2; + } + + public int getJudge3() { + return judge3; + } + + public void setJudge3(int judge3) { + this.judge3 = judge3; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + } +} +" +A22133,"import java.util.Scanner; + +public class Test { + public static void main(String[] args) { + int cases, num, sur, p; + int[] googlers; + Scanner sin = new Scanner(System.in); + int[] ans; + + cases = sin.nextInt(); + ans = new int[cases]; + for (int i = 0; i < cases; i++) { + int count = 0; + int couSur = 0; + int center, notSurLeast, least; + + num = sin.nextInt(); + googlers = new int[num]; + sur = sin.nextInt(); + p = sin.nextInt(); + for (int j = 0; j < num; j++) + googlers[j] = sin.nextInt(); + + center = 3 * p; + notSurLeast = center - 2; + least = center - 4; + if (least < p) + least = p; + for (int j = 0; j < num; j++) + if (googlers[j] >= least) { + count++; + if (googlers[j] < notSurLeast) + couSur++; + } + + if (couSur > sur) + count -= (couSur - sur); + ans[i] = count; + } + + for (int i = 0; i < cases; i++) + System.out.println(""Case #"" + (i + 1) + "": "" + ans[i]); + } +}" +A20816,"package rounds.qualification; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class B_dancing_with_the_googlers { + + public static void main(String[] args) throws IOException { + + BufferedReader reader = null; + BufferedWriter writer = null; + + try { + reader = new BufferedReader(new FileReader(""./input"")); + writer = new BufferedWriter(new FileWriter(""output"")); + int numberOfCases = Integer.valueOf(reader.readLine()); + for (int i = 1; i <= numberOfCases; i++) { + String line = reader.readLine(); + StringBuilder sb = new StringBuilder(""Case #"" + i + "": ""); + Scanner scanner = new Scanner(line); + int result = 0; + while(scanner.hasNextInt()) { + int numberOfGooglers = scanner.nextInt(); + int numberOfSurprisings = scanner.nextInt(); + int scoreToReach = scanner.nextInt(); + + while(numberOfGooglers>0) { + int googlerScore = scanner.nextInt(); + int div = googlerScore/3; + int mod =( googlerScore % 3 == 0) ? 0 : 1; + int highest = div + mod; + if(highest>=scoreToReach) { + result++; + } + else if(googlerScore > 0 && highest+1 == scoreToReach && numberOfSurprisings > 0) { + result++; + numberOfSurprisings--; + } + numberOfGooglers--; + } + sb.append(result); + } + sb.append(""\n""); + writer.write(sb.toString()); + } + } finally { + if (reader != null) { + reader.close(); + } + if(writer!=null) { + writer.flush(); + writer.close(); + } + } + } + + +} +" +A20277,"package Problem2; + + + import java.io.BufferedReader; + import java.io.BufferedWriter; + import java.io.FileInputStream; + import java.io.FileWriter; + import java.io.InputStream; + import java.io.InputStreamReader; + import java.io.PrintWriter; + import java.util.ArrayList; + + + + class FileReader{ + + public static ArrayList Parsefile(String filename){ + String chaine=""""; + String fichier =filename; + + try{ + InputStream ips=new FileInputStream(fichier); + InputStreamReader ipsr=new InputStreamReader(ips); + BufferedReader br=new BufferedReader(ipsr); + String ligne; + int j=0; + ArrayList ArS_lines = new ArrayList(); + + while ((ligne=br.readLine())!=null){ + System.out.println(ligne); + if (j>=1) + ArS_lines.add(ligne); + j++; + } + br.close(); + + return ArS_lines; + + } + catch (Exception e){ + return null; + } + + } + + public static void writeconfig(String destinationfilename , ArrayList ArS) { + try { + + FileWriter fw = new FileWriter (destinationfilename); + BufferedWriter bw = new BufferedWriter (fw); + PrintWriter fichierSortie = new PrintWriter (bw); + int i; + int n = ArS.size(); + + for (i=0;i t[j]) { + int tmp = t[i]; + t[i] = t[j]; + t[j] = tmp; + } + } + } + } +} + +class ProblemB { + private String mInputFilename; + private int T; + private ArrayList mCases; + + private BufferedReader mReader; + private BufferedWriter mWriter; + + public ProblemB(String inputFilename) + { + T = 0; + mCases = null; + mInputFilename = inputFilename; + } + + private boolean openFiles() { + if (mInputFilename != null) { + try { + mReader = new BufferedReader(new FileReader(mInputFilename)); + mWriter = new BufferedWriter(new FileWriter(mInputFilename.replace(""in"", ""out""))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return false; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + return true; + } + return false; + } + + private void closeFiles() { + try { + mReader.close(); + mWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private boolean readInput() + { + if (mReader != null) { + try { + String line; + + // number of test cases + line = mReader.readLine(); + T = Integer.valueOf(line); + System.out.println(""Cases: "" + T); + mCases = new ArrayList (); + + // read input cases + for (int i = 0; i 0) { + if (base > 0) + available = (remains == 2? 2: 1); + } else { + available = remains > 0? 1: 0; + } + + max += available; + if (max >= in.P) { + result++; + if (S>0) + S--; + } + } + writeOutput(seq, result); + } + + // test run main + public void run() + { + openFiles(); + readInput(); + + for (int i = 0; i 0) + inputFilename = new String(args[0]); + else + inputFilename = new String(""sample.in""); + + ProblemB solve = new ProblemB(inputFilename); + solve.run(); + } +} +" +A21536,"package codejam; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class Googlers { + public static void main(String[] args) throws IOException + { + Scanner scan = new Scanner(new File(""Googlers.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""Googlers.out""))); + + + int N = Integer.valueOf(scan.nextLine()); + int id =1; + while(scan.hasNextLine()) + { + String letters = scan.nextLine(); + String[] letter = letters.split("" ""); + + int peopleNum = Integer.valueOf(letter[0]); + int superiNum = Integer.valueOf(letter[1]); + int score = Integer.valueOf(letter[2]); + int[] scores = new int[peopleNum]; + for(int i=0;i= highScores) + num ++; + else + { + if(superiNum > 0) + { + if(item >= lowScores) + { + num++; + superiNum --; + } + } + } + } + + return num; + } + +} +" +A22054,"import java.util.*; + +/** + * + * @author Jhon + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Scanner cin = new Scanner(System.in); + int a = cin.nextInt(); + int dancers, surp, p, sum; + float aa; + List dancerL = new ArrayList<>(); + for (int i = 0; i < a; i++) { + sum = 0; + dancerL.clear(); + dancers = Integer.parseInt(cin.next()); + surp = Integer.parseInt(cin.next()); + p = Integer.parseInt(cin.next()); + for (int j = 0; j < dancers; j++) { + dancerL.add(Integer.parseInt(cin.next())); + } + for (Integer ii : dancerL) { + aa = (float) ii / 3; + if (p == 0) { + sum++; + } else if((int) (ii / 3)!= 0){ + if (aa == (int) (ii / 3)) { + if (p <= (int) (ii / 3)) { + sum++; + } else { + if (p == ((int) (ii / 3) + 1)) { + if (surp > 0) { + surp--; + sum++; + } + } + } + } else if (aa >= ((int) ii / 3) + 0.5) { + if (p <= (int) (ii / 3)) { + sum++; + } else { + if (p == ((int) (ii / 3) + 1)) { + sum++; + } else if (p == ((int) (ii / 3) + 2)) { + if (surp > 0) { + surp--; + sum++; + } + } + } + } else { + if (p <= (int) (ii / 3)) { + sum++; + } else { + if (p == ((int) (ii / 3) + 1)) { + sum++; + + } + } + + } + } + + } + System.out.println(""Case #"" + (i + 1) + "": "" + sum); + + } + + + + + } +} +" +A21448,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package adream; + +import java.util.Scanner; + +/** + * + * @author sarah + */ +public class GoogleDancers { + + public int max(int[] googs , int p , int s){ + int surp = 0; + int max = 0; + if(p == 0) + return googs.length; + for(int i = 0 ; i < googs.length ; i++){ + int g1=0,g = googs[i]; + if(g == 0)continue; + if(g%3 == 0){ + if(surp < s && g/3 < p && g/3 +1 >= p){ + g1 = g/3 +1; + surp++; + }else + g1 = g/3 ; + }else{ + if((g+1) % 3 == 0){ + if(surp < s &&(g+1)/3

= p){ + g1 = (g+1)/3 + 1; + surp++; + }else + g1 = (g+1)/3; + }else{ +// if(surp < s &&(g-1)/3 + 1 < p && (g-1)/3 + 1 >= p){ +// g1 = (g+1)/3 + 1; +// surp++; +// }else + g1 = (g-1)/3 +1; + } + } + if(g1 >= p) + max++; + + } + + return max; + } + + + public static void main(String args[]){ + GoogleDancers gd = new GoogleDancers(); + Scanner sc = new Scanner(System.in); + int tc = sc.nextInt(); + int i = 0 ; + while(i++ < tc){ + int n = sc.nextInt(); // dancers + int s = sc.nextInt(); //surprising + int p = sc.nextInt(); //max + int[] dancers = new int[n]; + for(int j = 0 ; j < n ; j++) + dancers[j] = sc.nextInt(); + int res = gd.max(dancers,p,s); + System.out.println(""Case #""+i +"": ""+res); + } + } +} +" +A21930,"package jp.funnything.competition.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; + +public class Packer { + private static void add( final ZipArchiveOutputStream out , final File file , final int pathPrefix ) { + if ( file.isDirectory() ) { + final File[] children = file.listFiles(); + + if ( children.length > 0 ) { + for ( final File child : children ) { + add( out , child , pathPrefix ); + } + } else { + addEntry( out , file , pathPrefix , false ); + } + } else { + addEntry( out , file , pathPrefix , true ); + } + } + + private static void addEntry( final ZipArchiveOutputStream out , final File file , final int pathPrefix , final boolean isFile ) { + try { + out.putArchiveEntry( new ZipArchiveEntry( file.getPath().substring( pathPrefix ) + ( isFile ? """" : ""/"" ) ) ); + + if ( isFile ) { + final FileInputStream in = FileUtils.openInputStream( file ); + IOUtils.copy( in , out ); + IOUtils.closeQuietly( in ); + } + + out.closeArchiveEntry(); + } catch ( final IOException e ) { + throw new RuntimeException( e ); + } + } + + public static void pack( final File source , final File destination ) { + try { + final ZipArchiveOutputStream out = new ZipArchiveOutputStream( destination ); + + add( out , source , FilenameUtils.getPath( source.getPath() ).length() ); + + out.finish(); + out.close(); + } catch ( final IOException e ) { + throw new RuntimeException( e ); + } + } +} +" +A20911,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package jam2; + +import java.util.Scanner; + +/** + * + * @author clary35 + */ +public class Jam2 { + + Jam2() { + + int[] totals = new int[10000]; + + System.out.println(""Input:""); + Scanner scan = new Scanner(System.in); + int cases = scan.nextInt(); + for (int i = 0; i < cases; i++) { + // Read case data + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + for (int k = 0; k < N; k++) { + int temp = scan.nextInt(); + totals[k] = temp; + } + + // Process case + int overs = 0; + for (int k = 0; k < N; k++) { + int themant = (int) Math.floor(totals[k] / 3); + double thefrac = totals[k] / 3.0 - themant; +// System.out.println(""Mant: "" + themant); +// System.out.println(""Frac: "" + thefrac); + if(p == 0 && totals[k] == 0){ + overs++; + } + if (totals[k] > 0.9999999) { + if (thefrac < 0.000000001) { + if (themant >= (p)) { + overs++; + } else { + if (themant >= (p - 1) && S > 0) { + overs++; + S = S - 1; + } + } + } else { + // Inte heltalsmedel + if (thefrac * 3 > 1.99999999) { + // Increase one without special, increase two with special + if (themant >= p) { + overs++; + } else { + if (themant >= (p - 1)) { + overs++; + } else { + if (themant >= (p - 2) && S > 0) { + overs++; + S = S - 1; + } + } + } + } else { + // Increase with with special only + if (themant >= p) { + overs++; + } else { + if (themant >= (p - 1)) { + overs++; + } + } + } + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + overs); + } + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + Jam2 jm = new Jam2(); + } +} +" +A22925,"package com.vp.common; + +import com.vp.fact.SolutionFactory; +import com.vp.iface.Problem; + +public class ExecutorApp { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + String inputFileName = ""C:/Workspace/GCJ2012/src/com/vp/data/sample_input.txt""; + String outputFileName = ""C:/Users/dhananitin/Desktop/sample_output.txt""; + //String outputFileName = ""C:/Workspace/GCJ2012/src/com/vp/data/sample_output.txt""; + + InputOutputProcessor inputOutputProcessor = new InputOutputProcessor(); + inputOutputProcessor.initializeInput(inputFileName); + int numberOfCases = inputOutputProcessor.getNumberOfCases(); + + String[] resultArray = new String[numberOfCases]; + inputOutputProcessor.setDoesInputHaveDataSetLines(false); + //inputOutputProcessor.setIndexOfDataSetLine(0); + inputOutputProcessor.setNumberOfDataSetLines(1); + + for (int i = 1; i <= numberOfCases; i++) { + + try { + String[] dataSet = inputOutputProcessor.getDataSet(); + Problem problem = SolutionFactory.getInstance(Problem.DANCINGWITHGOOGLERS); + resultArray[i-1] = ""Case #""+i+"": ""+ problem.solve(dataSet); + } + + catch (Exception exp) { + exp.printStackTrace(); + inputOutputProcessor.closeScanner(); + } + + } + + inputOutputProcessor.closeScanner(); + inputOutputProcessor.writeOutput(outputFileName, resultArray); + } + +} + + + + +" +A20362,"/* +Problem + +You're watching a show where Googlers (employees of Google) dance, and then each dancer is given a triplet of scores by three judges. Each triplet of scores consists of three integer scores from 0 to 10 inclusive. The judges have very similar standards, so it's surprising if a triplet of scores contains two scores that are 2 apart. No triplet of scores contains scores that are more than 2 apart. + +For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. + +The total points for a Googler is the sum of the three scores in that Googler's triplet of scores. The best result for a Googler is the maximum of the three scores in that Googler's triplet of scores. Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? + +For example, suppose there were 6 Googlers, and they had the following total points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising triplets of scores, and you want to know how many Googlers could have gotten a best result of 8 or better. + +With those total points, and knowing that two of the triplets were surprising, the triplets of scores could have been: + +10 9 10 +6 6 8 (*) +2 3 3 +6 6 6 +6 6 6 +6 7 8 (*) +The cases marked with a (*) are the surprising cases. This gives us 3 Googlers who got at least one score of 8 or better. There's no series of triplets of scores that would give us a higher number than 3, so the answer is 3. +Input + +The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing integers separated by single spaces. The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. + +Output + +For each test case, output one line containing ""Case #x: y"", where x is the case number (starting from 1) and y is the maximum number of Googlers who could have had a best result of greater than or equal to p. + +Limits + +1 = T = 100. +0 = S = N. +0 = p = 10. +0 = ti = 30. +At least S of the ti values will be between 2 and 28, inclusive. +Small dataset + +1 = N = 3. +Large dataset + +1 = N = 100. +Sample + + +Input + +Output + +4 +3 1 5 15 13 11 +3 0 8 23 22 21 +2 1 1 8 0 +6 2 8 29 20 8 18 18 21 +Case #1: 3 +Case #2: 2 +Case #3: 1 +Case #4: 3 + + +*/ + +import java.io.*; +import java.util.logging.Level; +import java.util.logging.Logger; +public class Dancing + +{ + BufferedReader read; + BufferedWriter write; + public static void main(String args[]) + { + try { + new Dancing().init(""B-large""); + } catch (Exception ex) { + //Logger.getLogger(Dancing.class.getName()).log(Level.SEVERE, null, ex); + } + } + void init(String name) throws Exception + { + read=new BufferedReader(new FileReader(new File(name+"".in""))); + write=new BufferedWriter(new FileWriter(new File(name+"".out""))); + + String x=""""; + + try { + x = read.readLine(); + int nos = Integer.parseInt(x); + for(int i=0;i=p)||(k>=p))&& c==0) + { + c++; + count+=1; + break ; + } + } + if(m==1) k=11; + } + + } + if(c==0 && s>0) + { + for(int k=2;k<=4;k++) + { + if(t[r1]==0 && p!=0) break; + if((t[r1]==(3*p)-k) || (t[r1]==(3*p)+k)) + { + count+=1; + s--; + break; + } + } + } + + } + write.write(""Case #""+(i+1)+"":""+"" ""+count+""\n""); + System.out.println(""Case #""+(i+1)+"":""+"" ""+count+""\n""); + + } + write.flush(); + write.close(); + read.close(); + // System.out.println(a+"" ""+b); + + } + catch (Exception ex) { + System.exit(0); + } + +} +}" +A21519,"import java.util.Scanner; +public class mishe { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + int cnt = scan.nextInt(); + for(int c=1 ; c<=cnt ; c++) + { + int[] nums = new int[scan.nextInt()]; + int sup = scan.nextInt(); + int max = scan.nextInt(); + int MINSUP = max+2*((max>=2)?(max-2):0),MINNSUP = max+2*((max>=1)?(max-1):0),res = 0; + for(int i=0 ; i=MINSUP && nums[i]0) + res++; + sup--; + } + else if(nums[i]>=MINNSUP) res++; + } + System.out.println(""Case #""+c+"": ""+res); + } + } + +} +" +A21191,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam.lib; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; + +public class SolutionWriter extends PrintWriter { + + private static final String FORMAT = ""Case #%1$s: %2$s%n""; + private String[] args = new String[2]; + + public SolutionWriter(File file) throws FileNotFoundException { + super(file); + } + + public void writeSolution(int caseNumber, String solution) { + args[0] = Integer.toString(caseNumber); + args[1] = solution;; + printf(FORMAT, (Object[]) args); + } + +} +" +A21497,"import java.io.*; + +public class Dancing_With_the_Googlers { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, + IOException { + FileInputStream inFile = new FileInputStream( + new File(""C:\\Users\\ruzbeh\\Downloads\\B-large.in"")); + DataInputStream br = new DataInputStream(inFile); + FileOutputStream outFile = new FileOutputStream(new File(""out.in"")); + DataOutputStream out = new DataOutputStream(outFile); + + int T = Integer.parseInt(br.readLine()); + + + for (int i = 0; i < T; i++) { + int res = 0; + String[] str = br.readLine().split("" ""); + int count = Integer.parseInt(str[1]); + int focus_score = Integer.parseInt(str[2]); + + int min_score = focus_score - 2; + if (min_score < 0) + min_score = 0; + int min_value = focus_score + (min_score) * 2; + int surprise_value = focus_score * 3 - 3; + for (int j = 0; j < Integer.parseInt(str[0]); j++) { + if (Integer.parseInt(str[3 + j]) < min_value) { + continue; + } else if (Integer.parseInt(str[3 + j]) <= surprise_value) { + if (count > 0) { + count -= 1; + res += 1; + } else + continue; + } else { + res += 1; + } + + } + out.writeBytes(""Case #"" + (i + 1) + "": "" + res); + out.writeBytes(""\n""); + + } + + } +} +" +A20787,"package quals; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class Dancing { + + public static void main(String args[]) { + try { + System.setIn(new FileInputStream(""B-large.in"")); + Scanner scanner = new Scanner(System.in); + + int testCases = scanner.nextInt(); + scanner.nextLine(); + + for (int i = 1; i <= testCases; i++) { + int numGooglers = scanner.nextInt(); + int numSurprising = scanner.nextInt(); + int bestResultThreshold = scanner.nextInt(); + + int[] googlers = new int[numGooglers]; + for (int j = 0; j < numGooglers; j++) { + googlers[j] = scanner.nextInt(); + } + + int passingGooglers = dancingWithTheGooglers(numGooglers, + numSurprising, bestResultThreshold, googlers); + System.out.println(String.format(""Case #%d: %d"", i, + passingGooglers)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + private static int dancingWithTheGooglers(int numGooglers, + int numSurprising, int bestResultThreshold, int[] googlers) { + int passingGooglers = 0; + + for (int i = 0; i < numGooglers; i++) { + if (googlers[i] / 3.0 > bestResultThreshold - 1) { + // in the case of say, [30,29,28,27,26,25], they can all meet + // a threshold of 9 without being 'surprising' + passingGooglers++; + } else if (numSurprising > 0 + && bestResultThreshold > 1 + && googlers[i] >= ((bestResultThreshold - 1) * 3) - 1) { + // boundary cases are when the threshold is 1 or less - in that + // case, any non zero score would work here. + passingGooglers++; + numSurprising--; + } + } + + return passingGooglers; + } + +} +" +A20486,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + + +public class Second { + + public static void main(String[] args) { + + try { + BufferedReader reader = new BufferedReader(new FileReader(new File(""input.txt""))); + PrintWriter writer = new PrintWriter(new FileWriter(new File(""output.txt""))); + reader.readLine(); // T + int num = 1; + String str = """"; + while((str = reader.readLine()) != null){ + String[] temp = str.split("" ""); + int result = 0; + int n = Integer.parseInt(temp[0]); // how many dancers + int s = Integer.parseInt(temp[1]); // surprising scores + int p = Integer.parseInt(temp[2]); // at least p points + int t[] = new int[n]; + for(int i = 0; i < n; i++) { + t[i] = Integer.parseInt(temp[i + 3]); + int k = t[i] / 3; + int normalMax, suprisingMax; + if(t[i] % 3 == 0){ + normalMax = k; + suprisingMax = k + 1; + } else if(t[i] % 3 == 1){ + normalMax = k + 1; + suprisingMax = k + 1; + } else { // t[i] % 3 == 2 + normalMax = k + 1; + suprisingMax = k + 2; + } + if(normalMax >= p) result++; + else if(s > 0 && suprisingMax >= p){ + if(t[i] == 0 || t[i] == 29 || t[i] == 30) continue; + s--; + result++; + } + } + writer.println(""Case #"" + num + "": "" + result); + num++; + } + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} +" +A21616,"package codejam.network172.com; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +public class CodeJam { + public static void main(String[] args) { + try { + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(""/home/harry/Downloads/cj.in""))); + PrintWriter out = new PrintWriter(new FileWriter(""/home/harry/Downloads/cj.out"")); + jam(in, out); + out.close(); + } catch (Exception e) { + System.out.print(""Exception thrown: "" + e.toString()); + } + } + + private static void jam(BufferedReader in, PrintWriter out) throws NumberFormatException, IOException { + int cases = Integer.parseInt(in.readLine()); + for (int i = 0; i < cases; i++) { + solveCase(i, in, out); + } + } + + private static void solveCase(int i, BufferedReader in, PrintWriter out) throws NumberFormatException, IOException { + String[] inStrs = in.readLine().split("" ""); + int googlers = Integer.parseInt(inStrs[0]); + int surprises = Integer.parseInt(inStrs[1]); + int p = Integer.parseInt(inStrs[2]); + int max = 0; + for (int j = 0; j < googlers; j++) { + int points = Integer.parseInt(inStrs[j+3]); + int high = points/3; + if (3*high < points) + high++; + if (high >= p) + max++; + else if (((high+1) >= p) && (3*high <= (points+1)) && (points >= 2) && (surprises > 0)) { + max++; + surprises--; + } + } + out.printf(""Case #%d: %d\n"", i+1, max); + } +} +" +A22762,"package qual2012; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + +/** + * Magicka + */ +public class B { + public static void main(String[] args) throws FileNotFoundException { + Kattio io; + +// io = new Kattio(System.in, System.out); +// io = new Kattio(new FileInputStream(""src/qual2012/B-sample.in""), System.out); +// io = new Kattio(new FileInputStream(""src/qual2012/B-small-attempt1.in""), new FileOutputStream(""src/qual2012/B-small-1.out"")); + io = new Kattio(new FileInputStream(""src/qual2012/B-large.in""), new FileOutputStream(""src/qual2012/B-large.out"")); + + int cases = io.getInt(); + for (int i = 1; i <= cases; i++) { + io.print(""Case #"" + i + "": ""); + new B().solve(io); + } + io.close(); + } + + private void solve(Kattio io) { + int n = io.getInt(), m = io.getInt(), p = io.getInt(); + + boolean[] okNormal = new boolean[31]; + boolean[] okSurprising = new boolean[31]; + + for (int i = 0; i <= 10; i++) { + for (int j = i; j <= 10; j++) { + for (int k = j; k <= 10; k++) { + if (k > i+2) continue; + if (k >= p) { + if (k > i+1) + okSurprising[i+j+k] = true; + else + okNormal[i+j+k] = true; + } + } + } + } + + int cnt = 0; + for (int i = 0; i < n; i++) { + int score = io.getInt(); + if (okNormal[score]) cnt++; + else if (m > 0 && okSurprising[score]) { cnt++; m--; } + } + io.println(cnt); + + } +} +" +A22723,"package exercise; + +public class Solver { + private static int VOTES_NB = 3; + private static int VARIABLES_NB = 3; + + public static Integer[] solve(Integer[][] input) { + Integer[] result = new Integer[input.length]; + + for (int cnt = 0; cnt < input.length; ++cnt) + result[cnt] = solve(input[cnt]); + + return result; + } + + public static int solve(Integer[] input) { + if (input == null || input.length < 3) + return 0; + + int googlersNb = input[0]; + int surprisingTriplets = input[1]; + int target = input[2]; + + if (input.length < VARIABLES_NB + googlersNb) + return 0; + + int result = 0; + + Integer[] candidates = new Integer[surprisingTriplets]; + for (int cnt = VARIABLES_NB; cnt < input.length; ++cnt) { + if (input[cnt] < target * VOTES_NB - (VOTES_NB - 1)) { + int minIndex = 0; + int min = -1; + for (int tmp = 0; tmp < candidates.length; ++tmp) { + if (candidates[tmp] == null || input[cnt] > candidates[tmp]) { + if (candidates[tmp] == null || min == -1 || candidates[tmp] < min) { + min = (candidates[tmp] == null) ? 0 : candidates[tmp]; + minIndex = tmp; + } + } + } + if (min >= 0 && input[cnt] >= min) + candidates[minIndex] = input[cnt]; + } else + ++result; + } + + if (candidates.length > 0) { + int surprisingTarget = target + target - 2 + target - 2; + if (surprisingTarget <= 0) + surprisingTarget = target; + if (candidates != null) + for (int cnt = 0; cnt < candidates.length; ++cnt) + if (candidates[cnt] != null && candidates[cnt] >= surprisingTarget) + result++; + } + + return result; + } +} +" +A20884,"import java.util.ArrayList; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + + public static int calculateBestResultGooglers(int N,int S,int p,ArrayList result){ + int noofresultpossible=0,surprisingTrippletsCount=0; + for(int i=0;i=p){ + noofresultpossible++; + }else if((result.get(i)/3)+1>=p){ + if(result.get(i)%3!=0){ + noofresultpossible++; + }else if (surprisingTrippletsCount=1){ + noofresultpossible++; + surprisingTrippletsCount++; + } + }else if((result.get(i)/3)+2>=p){ + if(result.get(i)%3==2&&surprisingTrippletsCount=2){ + noofresultpossible++; + surprisingTrippletsCount++; + } + } + } + return noofresultpossible; + } + /** + * @param args + */ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int NoOfTestCases = in.nextInt(); + int noOfGooglers,noOfSurprisingTriplets,bestResultPossibilities,totalPoints; + StringBuilder output=new StringBuilder(); + ArrayList result=null; + for(int i=1;i<=NoOfTestCases;i++){ + noOfGooglers=in.nextInt(); + noOfSurprisingTriplets=in.nextInt(); + bestResultPossibilities=in.nextInt(); +// System.out.println(""No of Googlers : ""+noOfGooglers); +// System.out.println(""No of SurprisingTriplets : ""+noOfSurprisingTriplets); +// System.out.println(""Best Result of at Least p : ""+bestResultPossibilities); +// System.out.print(""Total Points :""); + result=new ArrayList(); + for(int j=1;j<=noOfGooglers;j++){ + totalPoints=in.nextInt(); +// System.out.print("" ""+totalPoints); + result.add(totalPoints); + } + output.append(""Case #""+i+"": ""+calculateBestResultGooglers(noOfGooglers, noOfSurprisingTriplets, bestResultPossibilities, result)+""\n""); + } + System.out.println(output); + } + +} +" +A22842,"package gcj; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + +public abstract class SolverBase { + + public static final String TOKEN_SEPARATOR = "" ""; + + public static final String IMPOSSIBLE = ""IMPOSSIBLE""; + + public String problemName; + + public boolean verbose = false; + + public SolverBase(String problemName) { + this.problemName = problemName; + } + + public void solve(InputStream in, PrintStream out) throws Exception { + InputStreamReader isr = new InputStreamReader(in); + BufferedReader reader = new BufferedReader(isr); + long N = Long.parseLong(reader.readLine()); + for (long i = 1; i <= N; i++) { + out.print(""Case #"" + i + "": ""); + solveSingle(reader, out); + } + } + + public abstract void solveSingle(BufferedReader reader, PrintStream out) throws Exception; + + public long[] readSingleLineLongArray(BufferedReader reader) throws Exception { + String[] longsAsStrings = readSingleLineStringArray(reader); + long[] longs = new long[longsAsStrings.length]; + for (int i = 0; i < longsAsStrings.length; i++) { + longs[i] = Long.parseLong(longsAsStrings[i]); + } + return longs; + } + + public int[] readSingleLineIntArray(BufferedReader reader) throws Exception { + String[] intsAsStrings = readSingleLineStringArray(reader); + int[] ints = new int[intsAsStrings.length]; + for (int i = 0; i < intsAsStrings.length; i++) { + ints[i] = Integer.parseInt(intsAsStrings[i]); + } + return ints; + } + + public String[] readSingleLineStringArray(BufferedReader reader) throws Exception { + String line = reader.readLine(); + if (verbose) { + System.out.println(""Reading line "" + line); + } + return line.split(TOKEN_SEPARATOR); + // return StringUtils.split(line, TOKEN_SEPARATOR); + } + + public String[][] readStringArrays(BufferedReader reader, int lines) throws Exception { + String[][] arrays = new String[lines][]; + for (int i = 0; i < lines; i++) { + arrays[i] = readSingleLineStringArray(reader); + } + return arrays; + } + + public char[][] readCharArrays(BufferedReader reader, int lines) throws Exception { + char[][] arrays = new char[lines][]; + for (int i = 0; i < lines; i++) { + String line = reader.readLine(); + arrays[i] = line.toCharArray(); + } + return arrays; + } + + public long[][] readLongArrays(BufferedReader reader, int lines) throws Exception { + long[][] arrays = new long[lines][]; + for (int i = 0; i < lines; i++) { + arrays[i] = readSingleLineLongArray(reader); + } + return arrays; + } + + protected void check(boolean b) { + if (!b) { + throw new IllegalStateException(""Check failed""); + } + } +} +" +A20977,"package fixjava; + +import java.util.ArrayList; +import java.util.concurrent.Callable; + +/** Parallel quicksort (inefficient initially, doubles the number of threads at each pivot) */ +public class ParallelQuicksort> implements Callable { + + private ArrayList list; + private ParallelWorkQueueDynamic workQueue; + + // Have to create own stack because otherwise we can get stack overflow using normal recursion + private ArrayList loStack = new ArrayList(); + private ArrayList hiStack = new ArrayList(); + + private ParallelQuicksort(ArrayList list, int lo, int hi, ParallelWorkQueueDynamic workQueue) { + this.list = list; + this.workQueue = workQueue; + push(lo, hi); + } + + private void push(int lo, int hi) { + loStack.add(lo); + hiStack.add(hi); + } + + private void exch(int i, int j) { + T tmp = list.get(i); + list.set(i, list.get(j)); + list.set(j, tmp); + } + + private int partition(int lo, int hi) { + exch(lo, lo + (hi - lo) / 2); + int i = lo; + int j = hi + 1; + while (true) { + for (int idxLo = lo; list.get(++i).compareTo(list.get(idxLo)) < 0 && i != hi;) + ; + for (int idxLo = lo; list.get(idxLo).compareTo(list.get(--j)) < 0 && j != lo;) + ; + if (i >= j) + break; + exch(i, j); + } + exch(lo, j); + return j; + } + + @Override + public Void call() { + int stackSize = 1; + while ((stackSize = loStack.size()) > 0) { + // Pop top of stack + int lo = loStack.get(stackSize - 1); + int hi = hiStack.get(stackSize - 1); + loStack.remove(stackSize - 1); + hiStack.remove(stackSize - 1); + + // Go up a stack frame when hi <= lo + if (hi > lo) { + + // Partition + final int j = partition(lo, hi); + + if (j - lo > 1000 && workQueue.hasIdleWorkers()) { + // If there is enough work to do to justify multithreading and if there are idle threads, + // fork and recurse on one one side of partition on a different thread + workQueue.enqueueWork(new ParallelQuicksort(list, lo, j - 1, workQueue)); + + // Execute other half of subdivision in this thread + push(j + 1, hi); + + } else { + // Not worth forking another thread (not enough work to do), or not enough free workers + + push(lo, j - 1); + push(j + 1, hi); + } + } + } + return null; + } + + // --------------------------------------------------------- + + public static > void sortInPlace(ArrayList list, int numThreads) { + ParallelWorkQueueDynamic workQueue = new ParallelWorkQueueDynamic(numThreads); + workQueue.enqueueWork(new ParallelQuicksort(list, 0, list.size() - 1, workQueue)); + workQueue.waitForAllWorkersToQuit(); + workQueue.shutdown(); + } +} +" +A22781,"package google.problems; + +import google.loader.Challenge; + +public abstract class AbstractChallenge implements Challenge{ + + private final int problemNumber; + private String result; + public AbstractChallenge(int i) { + this.problemNumber = i; + + } + + protected void setResult(String result){ + this.result = result; + } + + @Override + public String getResult() { + return ""Case #""+problemNumber+"": ""+result+""\n""; + } + + protected int getInt(int pos, String[] tokens) { + return Integer.parseInt(tokens[pos]); + } + + +} +" +A21379,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.Reader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + + +public class Main +{ + +public static HashMap mapp = new HashMap(); + +public static void main(String[] args) throws Exception +{ + PrintWriter writer = new PrintWriter(new FileWriter(""output.txt"")); + BufferedReader input = new BufferedReader(new FileReader(""B-large.in"")); + int size=Integer.parseInt(input.readLine()); + for(int i=0; i google = new ArrayList(); + for(int j=3; j= 2*(p-1) && (testNum-p)>=0) + { + count++; + } + else if((testNum - p) < 2*(p-1) && (testNum-p)>=0) + { + if(S!=0 && (testNum - p) >= 2*(p-2) ) + { + count++; + S--; + } + } + } + writer.println(""Case #""+(i+1)+"": ""+count); + } + writer.close(); + input.close(); +} + +}" +A21725," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Qualification B + * @author Cristian Piacente + */ +public class QualificationB { + + public static void main(String args[]) { + + + /*for (int i = 20; i < 24; i++) { + System.out.println(""Value:"" + i); + Case c = new Case(i); + System.out.println(c.isDot0()); + System.out.println(c.isDot33()); + System.out.println(c.isDot66()); + System.out.println(""Medium value:"" + c.getMediumValue()); + System.out.println(""Normal value:"" + c.getNormalValue()); + System.out.println(""Special value:"" + c.getSpecialCaseValue()); + }*/ + try { + + //Read input file and translate + + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""c:\\B-small-attempt0.in""))); + BufferedWriter pw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""c:\\output.txt""))); + int ncases = Integer.parseInt(br.readLine()); + for (int ccase = 0; ccase < ncases; ccase++) { + ArrayList cases=new ArrayList(); + String line = br.readLine(); + StringTokenizer st=new StringTokenizer(line,"" ""); + int googlers=Integer.parseInt(st.nextToken()); + int specialCases=Integer.parseInt(st.nextToken()); + int minVal=Integer.parseInt(st.nextToken()); + int result=0; + for(int k=0;k=minVal){ + cases.remove(i); + result++; + i--; + continue; + } + } + /* + * Then based on the max num of specialCase explore their special value + */ + for(int i=0;i0;i++){ + Case c = cases.get(i); + if(c.getSpecialCaseValue()>=minVal){ + cases.remove(i); + result++; + specialCases--; + i--; + } + } + pw.write(""Case #""+(ccase+1)+"": ""+result+""\r\n""); + } + br.close(); + pw.close(); + } catch (IOException ex) { + Logger.getLogger(Qualification.class.getName()).log(Level.SEVERE, null, ex); + } + } +} + +class Case { + + boolean dot66 = false; + boolean dot33 = false; + boolean dot0 = false; + private int value = -1; + private int mediumValue; + private float mediumFloatValue; + + public Case(int value) { + this.value = value; + this.mediumFloatValue=this.value/3f; + this.mediumValue = (int) Math.floor(this.value / 3f); + if (this.value / 3f - (int) Math.floor(this.value / 3f) == 0) { + dot0 = true; + } else { + if (this.value / 3f - (int) Math.floor(this.value / 3f) > 0.4f) { + dot66 = true; + } else { + dot33 = true; + } + } + } + + public boolean isDot0() { + return dot0; + } + + public boolean isDot33() { + return dot33; + } + + public boolean isDot66() { + return dot66; + } + + public int getMediumValue() { + return mediumValue; + } + + public void setMediumValue(int mediumValue) { + this.mediumValue = mediumValue; + } + + public int getNormalValue() { + if(this.value==0){ + return 0; + } + if (isDot0()) { + return mediumValue; + } else { + if (isDot66()) { + return mediumValue + 1; + } else { + return mediumValue + 1; + } + } + } + + public int getSpecialCaseValue() { + if(this.value==0){ + return 0; + } + if (isDot0()) { + return mediumValue + 1; + } else { + if (isDot66()) { + return mediumValue + 2; + } else { + return mediumValue + 1; + } + } + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public float getMediumFloatValue() { + return mediumFloatValue; + } +} +class NormalCaseComparator implements Comparator{ + + @Override + public int compare(Case o1, Case o2) { + if(o1.getNormalValue()==o2.getNormalValue()){ + return 0; + } + else{ + if(o1.getNormalValue()>o2.getNormalValue()){ + return -1; + } + else{ + return 1; + } + } + } +} +class SpecialCaseComparator implements Comparator{ + + @Override + public int compare(Case o1, Case o2) { + if(o1.getSpecialCaseValue()==o2.getSpecialCaseValue()){ + return 0; + } + else{ + if(o1.getSpecialCaseValue()>o2.getSpecialCaseValue()){ + return -1; + } + else{ + return 1; + } + } + } +}" +A20570,"package ProblemSolvers; + +import CaseSolvers.WiresCase; + +public class Wires extends ProblemSolver { + + public Wires(String filePath) { + super(filePath); + } + + @Override + public void process() { + cases = io.readInt(); + + for (int i = 1; i <= cases; i++) { + new WiresCase(i, io.readInt(), io).process().printSolution(); + } + } +} +" +A22745,"import java.util.*; +import java.io.*; +public class Sol2 { + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(""B-large.in"")); + System.setOut(new PrintStream(new File(""B-large.out""))); + int len = sc.nextInt(); + for (int i = 0; i < len; i++) { + int nexlen = sc.nextInt(); + int surp = sc.nextInt(); + int minscore = sc.nextInt(); + int numb = 0; + for (int a = 0; a < nexlen; a++) { + int[] three = separate(sc.nextInt()); + if (isGood(three, minscore)) { + numb++; + } else { + if (((three[0]==three[1]&&three[1]==three[2]&&three[0]!=0)||(three[0]==three[1]&&three[1]-1==three[2]))&&surp>0) { + if (three[0]+1>=minscore) { + numb++; + surp--; + } + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+numb); + } + } + public static int[] separate(int i) { + int[] ret = new int[3]; + ret[0] = (int)Math.ceil(i/3.); + ret[1] = (int)Math.ceil((i-ret[0])/2.); + ret[2] = i-ret[0]-ret[1]; + return ret; + } + public static boolean isGood(int[] in,int a) { + for (int i = 0; i < 3; i++) { + if (in[i]>=a) { + return true; + } + } + return false; + } +}" +A21501,"package qualificationRound; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.util.Scanner; + + +public class B { + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(System.in); + + int ncases = sc.nextInt(); + + StringBuilder sb = new StringBuilder(); + for ( int ncase = 1; ncase <= ncases; ncase++ ) { + int nGooglers = sc.nextInt(); + int nSuprising = sc.nextInt(); + int p = sc.nextInt(); + int surprises = 0; + int count = 0; + for (int i = 0; i < nGooglers; i++) { + int s = sc.nextInt(); + int q = s/3; + int rm = s%3; + int pq = p-q; + + if ( s < p) + continue; + + if ( q >= p ) { + count++; + } + else if ( pq <= 2 ){ + if ( rm == 0 ) { + if ( pq == 1 && surprises < nSuprising ) { + count++; + surprises++; + } + } + else { + if ( pq == 1 ) + count++; + else if ( rm == 2 && surprises < nSuprising ) { + count++; + surprises++; + } + } + } + } + + sb.append(""Case #""+ ncase +"": "" + count + ""\n""); + } + + BufferedOutputStream bos = null; + bos= new BufferedOutputStream(new FileOutputStream(new File(""C:\\Users\\Christian\\workspaceCPDI\\CodeJam2012\\src\\qualificationRound\\res.txt""))); + bos.write(sb.toString().getBytes()); + bos.close(); + } + +}" +A21233,"package codejam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; + +public class CodeJamRunner { + + private PrintWriter pw = null; + + /** + * Override this to do the real stuff. + * @param inputLine + */ + protected void process( int lineNr, String inputLine ) + { + printlnOutput( ""#"" + lineNr + "" "" + inputLine ); + } + + protected void printlnOutput( String outputLine ) + { + pw.println( outputLine ); + } + + public void run( String inFilePath, String outFilePath ) + { + BufferedReader fr = null; + try { + fr = new BufferedReader( new FileReader( inFilePath ) ); + pw = new PrintWriter(new File( outFilePath )); + String nextLine; + int lineNr = 1; + while ( (nextLine = fr.readLine()) != null) { + process( lineNr, nextLine ); + lineNr++; + } + pw.flush(); + } catch (Throwable e) { + e.printStackTrace(); + } finally + { + if ( pw != null ) + { + try{ + pw.close(); + } + catch ( Throwable pwT ) { + pwT.printStackTrace(); + } + } + if ( fr != null ) + { + try + { + fr.close(); + } + catch ( Throwable frT ) { + frT.printStackTrace(); + } + } + } + } + + public void run( String[] args ){ + String inFilePath; + String outFilePath; + if (args.length < 2) { + System.out.println(""Usage : java codejam.CodeJamRunner [inputFilePath] [OutputFilePath]""); + System.out.println(""using defaults""); + inFilePath = ""input/input.txt""; + outFilePath = ""output/output.txt""; + } else { + inFilePath = args[0]; + outFilePath = args[1]; + } + run( inFilePath, outFilePath); + } + + public static void main(String[] args) { + CodeJamRunner runner = new CodeJamRunner(); + runner.run(args); + } +} +" +A20067,"import java.util.*; +import java.io.*; + +public class ProblemB { + + static boolean surprising(int s, int p) + { + int r = s % 3; + int x; + if (r == 0) + x = (s - 3) / 3; + else if (r == 1) + x = (s - 4) / 3; + else + x = (s - 2) / 3; + if (x >= 0 && x <= 8) + { + return (x + 2) >= p; + } + else + return false; + } + + static boolean nonsurprising(int s, int p) + { + int r = s % 3; + int x; + if (r == 0) + { + x = s / 3; + return x >= 0 && x <= 10 && x >= p; + } + else if (r == 1) + x = (s - 1) / 3; + else + x = (s - 2) / 3; + return (x >= 0 && x <= 9 && x + 1 >= p); + } + + public static void main(String[] args) throws FileNotFoundException { + Scanner cin = new Scanner(new File(""B.txt"")); + PrintStream cout = new PrintStream(""B.ans""); + int caseN = cin.nextInt(); + for (int caseI = 1; caseI <= caseN; caseI++) + { + int n = cin.nextInt(); + int s = cin.nextInt(); + int p = cin.nextInt(); + int scores[] = new int[n]; + boolean sur[] = new boolean[n]; + boolean non[] = new boolean[n]; + for (int i=0; i= p) { + rez++; + } + } else { + if (min >= p) { + //System.out.println(tt[i] + "" "" + min + "" "" + max + "" *""); + rez++; + } else { + if (max < p) { + //System.out.println(tt[i] + "" "" + min + "" "" + max + ""**""); + } else { + // left + //System.out.println(tt[i] + "" "" + min + "" "" + max); + potential++; + } + + } + + } + } + + //System.out.println(""real: "" + rez + "" "" + potential); + + + + return """" + (rez+Math.min(potential,s)); + } + + +} +" +A22227,"package teardrop.jam2012.qr.dancing; + +import org.testng.annotations.Test; + +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; + +public class SetSolverTest { + private static final String testInput = + ""4\n"" + + ""3 1 5 15 13 11\n"" + + ""3 0 8 23 22 21\n"" + + ""2 1 1 8 0\n"" + + ""6 2 8 29 20 8 18 18 21""; + private static final String testOutput = + ""Case #1: 3\n"" + + ""Case #2: 2\n"" + + ""Case #3: 1\n"" + + ""Case #4: 3\n""; + + @Test + public void testSolve() throws Exception { + Reader reader = new StringReader(testInput); + Writer writer = new StringWriter(); + SetSolver solver = new SetSolver(reader, writer); + solver.solve(); + String result = writer.toString(); + assert testOutput.equals(result) : String.format(""Got \n%s\ninstead of \n%s\n"", result, testOutput); + } +} +" +A20566,"import java.util.Scanner; + + +public class triplets { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int numCases = scan.nextInt(); + for(int i = 0; i < numCases; i++) { + int size = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int[] scores = new int[size]; + for(int j = 0; j < size; j++) { + scores[j] = scan.nextInt(); + } + System.out.println(""Case #"" + (i+1) + "": "" + number(scores,s,p)); + } + } + + + public static int number(int[] scores, int s, int p) { + int minScore = Math.max(p*3 - 2, p); + int minS = Math.max(p*3 - 4, p); + int count = 0; + for(int i = 0; i < scores.length; i++) { + if(scores[i]>=minScore) count++; + else if(scores[i] >= minS) { + if(s>0) { + s--; + count++; + } + } + } + return count; + } +} +" +A20861,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package utils; + +/** + * + * @author fabien + */ +public interface JamCaseSolver { + + public void parse(); + + public void solve(); +}" +A20757,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing.with.the.googlers; + +import java.io.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class DancingWithTheGooglers { + + static int numberOfTests; + static int[] testResults; + static ScoreCounter[] orders; + + public static void main(String[] args) { + InitInput(); + for (int i = 0; i < numberOfTests; i++) { + try { + testResults[i] = orders[i].Count2(); + if (testResults[i] != orders[i].Count2()) + { + System.out.print(i); + } + } catch (Exception ex) { + Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); + } + } + writeResult(); + } + + static void InitInput() { + try { + FileReader input = new FileReader(""B-large.in""); + try (BufferedReader bufRead = new BufferedReader(input)) { + String line = bufRead.readLine(); + + numberOfTests = Integer.parseInt(line); + testResults = new int[numberOfTests]; + orders = new ScoreCounter[numberOfTests]; + + for (int i = 0; i < numberOfTests; i++) { + line = bufRead.readLine(); + if (line == null) { + break; + } + orders[i] = new ScoreCounter(line); + } + } + + } catch (IOException ex) { + Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); + } + } + + + static void writeResult() { + FileWriter output = null; + try { + output = new FileWriter(""output""); + try (BufferedWriter bufWrite = new BufferedWriter(output)) { + for (int i = 0; i < numberOfTests; i++) { + String result = ""Case #""+(i+1)+"": ""+testResults[i]; + bufWrite.write(result); + bufWrite.newLine(); + } + } + } catch (IOException ex) { + Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + output.close(); + } catch (IOException ex) { + Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); + } + } + + } +} +" +A21949,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlecodejamqualifier; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * + * @author Dean + */ +public class DancingWithGooglers { + public static void main(String args[]) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int cases = Integer.parseInt(reader.readLine()); + for (int i = 0; i < cases; i ++) { + String line = reader.readLine().trim(); + String split[] = line.split(""[\\s]+""); + int people = Integer.parseInt(split[0]); + int suprising = Integer.parseInt(split[1]); + int maxScore = Integer.parseInt(split[2]); + int count = 0; + for (int j = 3; j < split.length; j++) { + double score = Double.parseDouble(split[j]); + score = (score - maxScore)/2; + if (score < 0) { + continue; + } + score = score - maxScore; + if (score >= -1) { + count++; + } + else if (score >= -2) { + if (suprising > 0) { + suprising --; + count++; + } + } + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } +} +" +A22912,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Scanner; + + +public class Dan { + + static Scanner sc; + static Writer out; + public static void main(String[] args) throws IOException { + sc=new Scanner(new File(""input.txt"")); + int num_of_cases=sc.nextInt(); + int num_of_googlers; + int num_of_surp_tup; + int max_best_eval; + int []scores; + out = new OutputStreamWriter(new FileOutputStream(""out.txt"")); + for (int i = 1; i <= num_of_cases; i++) { + num_of_googlers=sc.nextInt(); + num_of_surp_tup=sc.nextInt(); + max_best_eval=sc.nextInt(); + scores=new int[num_of_googlers]; + for (int k = 0; k < scores.length; k++) { + scores[k]=sc.nextInt(); + } + compute(scores,num_of_googlers,num_of_surp_tup,max_best_eval,i); + } + + out.close(); + //System.out.println(""Done""); + } + static void compute(int[] scores, int num_of_googlers, + int num_of_surp_tup, int max_best_eval, int case_num) throws IOException { + int winners=0; + for (int i = 0; i < scores.length; i++) { + if((scores[i] >= max_best_eval*3-2)){//&&(max_best_eval*3-2 >0)){ + winners++; + } + else if(num_of_surp_tup>0){ + if((scores[i] >= max_best_eval*3-4)&&(max_best_eval!=1)){//(scores[i] > 0)){ + num_of_surp_tup--; + winners++; + } + } + } + //System.out.println(""Case #""+case_num+"": ""+winners); + out.append(""Case #""+case_num+"": ""+winners+""\n""); + } + +} +" +A20425,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +public class Qual1b { + static int[] norm = { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, + 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10 }; + static int[] weird = { 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, + 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 }; + + public static void main(String args[]) { + + try { + FileWriter fstream = new FileWriter(""outBLarge.txt""); + BufferedWriter out = new BufferedWriter(fstream); + Scanner scanner = new Scanner(new File(""B-large.in"")); + + int count = scanner.nextInt(); + + for (int i = 1; i <= count; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + + int resultMax = 0; + for (int j = 0; j < n; j++) { + int temp = scanner.nextInt(); + if (norm[temp] >= p) { + resultMax++; + } else if (weird[temp] >= p && s > 0) { + resultMax++; + s--; + } + } + out.write(""Case #"" + i + "": "" + resultMax + ""\n""); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A20508," +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.OutputStream; +import java.io.PrintStream; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author bgamlath + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws Exception { + // TODO code application logic here + BufferedReader in = new BufferedReader(new FileReader(""input.txt"")); + PrintStream out = new PrintStream(""output.txt""); + int n = Integer.parseInt(in.readLine()); + for(int i = 1; i<=n; i++){ + out.println(""Case #"" + i + "": "" + getRes(in.readLine())); + } + } + static int getRes(String str){ + String[] m = str.split("" ""); + int n = Integer.parseInt(m[0]); + int s = Integer.parseInt(m[1]); + int p = Integer.parseInt(m[2]); + int max = 0; + int usedS = 0; + for(int i = 0; i=p; + } + static boolean Surprising(int tot, int p){ + if(tot==0) + return tot>=p; + int k = (tot % 3 == 2) ? tot/3 + 2 : tot/3 + 1; + return k>=p; + } +} +" +A21079,"package qualification; + +import java.io.*; +import java.util.Arrays; +import java.util.Scanner; + +/** + * @author Roman Elizarov + */ +public class B { + public static void main(String[] args) throws IOException { + new B().go(); + } + + Scanner in; + PrintWriter out; + + int[] maxS = new int[31]; + int[] maxNS = new int[31]; + + private void go() throws IOException { + buildMax(); + in = new Scanner(new File(""src\\qualification\\b.in"")); + out = new PrintWriter(new File(""src\\qualification\\b.out"")); + int t = in.nextInt(); + for (int tn = 1; tn <= t; tn++) { + out.println(""Case #"" + tn + "": "" + solveCase()); + } + in.close(); + out.close(); + } + + private void buildMax() { + Arrays.fill(maxS, -1); + Arrays.fill(maxNS, -1); + for (int a = 0; a <= 10; a++) + for (int b = Math.max(0, a - 2); b <= Math.min(10, a + 2); b++) + for (int c = Math.max(0, Math.max(a - 2, b - 2)); c <= Math.min(10, Math.min(a + 2, b + 2)); c++) { + int t = a + b + c; + int max = Math.max(a, Math.max(b, c)); + if (Math.abs(a - b) == 2 || Math.abs(a - c) == 2 || Math.abs(b - c) == 2) + maxS[t] = Math.max(maxS[t], max); + else + maxNS[t] = Math.max(maxNS[t], max); + } + } + + private int solveCase() { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) + t[i] = in.nextInt(); + int[][] r = new int[n + 1][s + 1]; + Arrays.fill(r[0], -1); + r[0][0] = 0; + for (int i = 0; i < n; i++) { + Arrays.fill(r[i + 1], -1); + for (int j = 0; j <= s; j++) { + if (r[i][j] >= 0 && maxNS[t[i]] >= 0) + r[i + 1][j] = r[i][j] + (maxNS[t[i]] >= p ? 1 : 0); + if (j > 0 && r[i][j - 1] >= 0 && maxS[t[i]] >= 0) + r[i + 1][j] = Math.max(r[i + 1][j], r[i][j - 1] + (maxS[t[i]] >= p ? 1 : 0)); + } + } + return r[n][s]; + } +} +" +A22582,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; +import java.io.PrintWriter; + +public class B { + InputScanner s = new InputScanner(System.in); + PrintWriter out = new PrintWriter(System.out); + + public static void main(String[] args) { + B program = new B(); + program.begin(); + } + + + int storage[][] = new int[110][4]; + public void begin() { + int T = s.nextInt(); + for(int t=1;t<=T;t++) { + int N = s.nextInt(); + int S = s.nextInt(); + int P = s.nextInt(); + + int initialCount = 0; + //int surpriseCount = 0; + + int temp[] = new int[4]; + for(int n=0;n= P || storage[n][2] >= P) + { + //System.out.println(storage[n][0]+"" ""+storage[n][2]); + storage[n][3] = 1; + initialCount++; + } + else { + if(S>0) { + temp[0] = P; + + int res = c - P; + if(res > 0) { + int div2 = res/2; + temp[1] = div2; + + if(Math.abs(temp[0]-temp[1]) <= 2) { + temp[2] = res - div2; + if(Math.abs(temp[0]-temp[2]) <= 2 && Math.abs(temp[1]-temp[2]) <= 2) { + S--; + storage[n] = temp; + initialCount++; + } + } + } + } + } + } + + + + /*System.out.println(initialCount); + for(int n=0;n=max){ + count++; + }else if(surprise>0 && (div+1) >=max){ + count++; + surprise--; + } + }else if(current%3==1){ + if((div+1) >=max){ + count++; + } + }else if(current%3==2){ + if((div+1) >=max) count++; + else if(surprise>0 && (div+2)>=max){ + count++; + surprise--; + } + } + } + +} +" +A22725,"package com.bchetty.gcj2012; + +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +/** + * + * @author Babji Prashanth, Chetty + */ +public class DancingGooglers { + public static void main(String[] args) { + DancingGooglers dancingGooglers = new DancingGooglers(); + LineNumberReader lineNumberReader = null; + BufferedWriter bufferedWriter = null; + + try { + lineNumberReader = new LineNumberReader(new FileReader(""/Users/babjichetty/Downloads/B-small-attempt0.in"")); + bufferedWriter = new BufferedWriter(new FileWriter(""/Users/babjichetty/Downloads/B-small.out.txt"")); + String line = null; + int index = 0; + int count = 0; + + while ((line = lineNumberReader.readLine()) != null) { + if(index == 0) { + count = Integer.parseInt(line); + System.out.println(""Count : "" + count); + index++; + continue; + } + if(index > count) { + break; + } + String[] arr = line.split("" ""); + int numGooglers = Integer.parseInt(arr[0]); + int surprise = Integer.parseInt(arr[1]); + int threshold = Integer.parseInt(arr[2]); + ArrayList scoreList = new ArrayList(); + + for(int i=3;i<3+numGooglers;i++) { + scoreList.add(Integer.parseInt(arr[i])); + } + + bufferedWriter.write(""Case #"" + index + "": "" + dancingGooglers.findMaxGooglers(numGooglers, surprise, threshold, scoreList)); + bufferedWriter.newLine(); + index++; + + } + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + //Close the BufferedWriter + try { + if (lineNumberReader != null) { + lineNumberReader.close(); + } + if (bufferedWriter != null) { + bufferedWriter.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + + public int findMaxGooglers(int N, int s, int p, ArrayList scoreList) { + int res = 0; + int surpriseNum = s; + int threshold = p + (2 * (p - 2)); + Collections.sort(scoreList); + + for(Integer score: scoreList) { + if(score >= p) { + System.out.print(""Score : "" + score + "" divided into : ""); + int[] triplet = split(score); + + if(triplet[2] >= p) { + res++; + } else if(surpriseNum > 0 && score >= threshold) { + res++; + surpriseNum--; + } + } + } + + return res; + } + + private int[] split(int score) { + int div = score/3; + int rem = score - (3 * div); + int[] triplet = new int[3]; + triplet[0] = div; + triplet[1] = div; + triplet[2] = div; + //System.out.println(""Div : "" + div + "" Init Rem : "" + rem); + + int index = 0; + while(rem > 0) { + if(index > 2) { + index = 0; + } + triplet[index] += 1; + index++; + rem--; + } + + Arrays.sort(triplet); + System.out.println(triplet[0] + "" - "" + triplet[1] + "" - "" + triplet[2]); + + return triplet; + } +} +" +A20389,"package codejam; +import java.util.ArrayList; +import java.util.Collections; +public class DWG { + int findCount(int N,int S,int p,ArrayListarr){ + int count = 0; + Collections.sort(arr); + int i = 0; + while( S != 0 && i=0){ + int q = (val -3 ) / 3; + if( (q+2) >=p){ + count++; + arr.set(i, -1); + S--; + } + } + else if( (val -2)%3 == 0 &&(val-2)>=0){ + int q = (val -2 ) / 3; + if( (q+2) >=p){ + count++; + arr.set(i, -1); + S--; + } + } + else if( (val -4)%3 == 0 && (val -4)>=0){ + int q = (val -4 ) / 3; + if( (q+2) >=p){ + count++; + arr.set(i, -1); + S--; + } + } + i++; + } + for(i = 0; i=0){ + if( (val)%3 == 0){ + int q = (val ) / 3; + if( (q) >=p){ + count++; + arr.set(i, -1); + } + } + else if( (val - 2)%3 == 0 && (val - 2)>=0){ + int q = (val -2 ) / 3; + if( (q+1) >=p){ + count++; + arr.set(i, -1); + + } + } + else if( (val-1)%3 == 0 && (val - 1)>=0){ + int q = (val -1 ) / 3; + if( (q+1) >=p){ + count++; + arr.set(i, -1); + + } + } + + } + } + + return count; + } + public static void main(String []args){ + DWG d = new DWG(); + + FileRead fr = new FileRead(""B-small-attempt1.in""); + FileWrite fw = new FileWrite(""B-small-ouput1.txt""); + + int num = 0; + + int t = fr.readNextInt(); + for(int i = 0; i< t ; i++){ + int arr[] = fr.readNextIntArray(); + + ArrayList a = new ArrayList(); + int j = 0; + for(;j= highestBound) { + ++count; + } else if (sum >= lowestBound && S > 0) { + --S; + ++count; + } + } + + return Long.toString(count); + + } + +} +" +A22780,"package google.solver; + +public interface ChallengeConstants { + public static final String DELIMITER = ""\\""; + public static final String CHALLENGE_DEFINITION = ""challengeDefinition""; + public static final String BASE_DIR= ""D:\\Development\\Workspaces\\test1\\googleChallanges\\src\\google\\contest""; + + public static final String CHALLENGE_NAME=""A""; + public static final String TEST_IN=""test.in""; +} +" +A20670,"package question; + +import java.util.HashMap; + +import utils.FileTools; + +public class Qualification2 { + public static void main(String[] args) { + try { + FileTools ft = new FileTools(""B-large.in""); + int T = Integer.parseInt(ft.in.readLine()); + String line; + int l = 0; + while ((line = ft.in.readLine()) != null) { + ft.out.write(""Case #"" + (++l) + "": ""); + String[] a = line.split("" ""); + int total = 0; + int size = Integer.parseInt(a[0]); + int sur = Integer.parseInt(a[1]); + int avr = Integer.parseInt(a[2]); + for (int i = 0; i < size; i++) { + int v = Integer.parseInt(a[i + 3]); + if (v >= avr && v >= 3 * avr - 2) { + total++; + } else if (sur > 0 && v >= avr && v >= avr * 3 - 4) { + sur--; + total++; + } + } + ft.out.write(Integer.valueOf(total).toString()); + System.out.println(""Case #"" + l + "": "" + total); + ft.out.newLine(); + } + ft.out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A22924,"package com.vp.impl; + +import java.util.Arrays; + +import com.vp.common.CommonUtility; +import com.vp.iface.Problem; + +public class DancingWithGooglers implements Problem { + + private static int currentNoOfSurprises; + private static int eligibleGooglers; + private static final int noOfJudges = 3; + private static int noOfGooglers; + private static int noOfSurprises; + private static int bestScore; + + @Override + public String solve(String[] dataset) { + String strReturnValue =""""; + String strDanceData = dataset[0]; + String strDanceDataArr[] = strDanceData.split("" ""); + int iDanceDataArr[] = CommonUtility.convertStringArraytoIntArray(strDanceDataArr); + + noOfGooglers = iDanceDataArr[0]; + noOfSurprises = iDanceDataArr[1]; + bestScore = iDanceDataArr[2]; + eligibleGooglers = 0; + currentNoOfSurprises =0; + + int totalScore; + int googlers[] = new int [noOfGooglers]; + int index =0 ; + int scoreSplit[] = new int[noOfJudges]; + + CommonUtility.print(iDanceDataArr); + for (int i = 3; i < iDanceDataArr.length; i++ ) + { + googlers[index] = iDanceDataArr[i]; + index++; + } + + Arrays.sort(googlers); + + for (int i = 0; i < googlers.length; i++ ) + { + totalScore = googlers[i]; + if(isEligible(totalScore)) + { + scoreSplit= split(totalScore); + if(isEligibleAfterConversion(scoreSplit)) + { + eligibleGooglers++; + CommonUtility.printWithoutExtrLine(scoreSplit); + System.out.println(""Eligible Googler #"" + eligibleGooglers); + } + } + } + + System.out.println(""Output: "" + strReturnValue + eligibleGooglers); + + return strReturnValue + eligibleGooglers; + } + + private boolean isEligibleAfterConversion(int[] scoreSplit) + { + boolean bReturn = false; + + if(currentNoOfSurprises == noOfSurprises) + { + return true; + } + + int surpriseScore[]= convertToSurpriseScore(scoreSplit); + + for(int i=0;i= bestScore) + { + bReturn = true; + break; + } + } + + return bReturn; + } + + private int[] convertToSurpriseScore(int[] scoreSplit) + { + int diff = scoreSplit[1] - scoreSplit[0]; + int diff1 = scoreSplit[2] - scoreSplit[1]; + int diff2 = scoreSplit[2] - scoreSplit[0]; + + String strDiff = diff+""""+diff1+""""+diff2; + + //System.out.println(""strDiff: "" + strDiff); + + if (strDiff.equals(""000"")) + { + if ((scoreSplit[2] - 1) >= 0) + { + scoreSplit[0] = scoreSplit[0] + 1; + scoreSplit[2] = scoreSplit[2] - 1; + } + } + else if(strDiff.equals(""011"")) + { + if((scoreSplit[0] - 1) >= 0) + { + scoreSplit[0] = scoreSplit[0] - 1; + scoreSplit[1] = scoreSplit[1] + 1; + } + } + else if(strDiff.equals(""101"")) + { + if((scoreSplit[1] - 1) >= 0) + { + scoreSplit[1] = scoreSplit[1] - 1; + scoreSplit[2] = scoreSplit[2] + 1; + } + } + + Arrays.sort(scoreSplit); + + if(isSurpriseScore(scoreSplit)) + { + currentNoOfSurprises ++; + CommonUtility.printWithoutExtrLine(scoreSplit); + System.out.println("" Surprise#: ""+currentNoOfSurprises); + + } + + return scoreSplit; + } + + private boolean isSurpriseScore(int[] scoreSplit) + { + int diff = scoreSplit[1] - scoreSplit[0]; + int diff1 = scoreSplit[2] - scoreSplit[1]; + int diff2 = scoreSplit[2] - scoreSplit[0]; + + // System.out.println(""isSurprise diff"" + diff + "" "" + diff1 + "" ""+ diff2); + + return ((diff + diff1 + diff2) == 4); + + } + + private static int [] split(int totalScore) + { + int avgScore = totalScore / 3; + int remScoreAvg = (totalScore - avgScore) / 2; + + int remScore = remScoreAvg; + int remScore1 = remScoreAvg; + int iReturn[] = new int[3]; + int mod = (totalScore - avgScore) % 2; + + if(mod == 1) + { + remScore++; + } + + iReturn[0] = avgScore; + iReturn[1] = remScore; + iReturn[2] = remScore1; + + Arrays.sort(iReturn); + + CommonUtility.printWithoutExtrLine(iReturn); + //System.out.println("" : Total Score :"" + totalScore); + + return iReturn; + } + + /*private boolean isSurprisingScore(int totalScore) + { + boolean bReturn = false; + + int bs1 = bestScore; + int bs2 = bestScore -1; + int bs3 = bestScore -2; + + if(bs1 >=0 && bs2 >=0 && bs3>=0 ) + { + bReturn = (bestScore + ( bestScore -1 ) + (bestScore -2)) == totalScore; + if(bReturn) + System.out.println(""Eligible Googler : ["" + bestScore +"", ""+ ( bestScore -1 )+"", "" + (bestScore -2) +""] = "" + totalScore + "" (Surprise#"" + (currentNoOfSurprises + 1)+"")"" ); + + if(!bReturn) + { + bReturn = (bestScore + (( bestScore -2 ) * 2)) == totalScore; + if (bReturn) + System.out.println(""Eligible Googler : ["" + bestScore +"", ""+ ( bestScore -2 )+"", "" + (bestScore -2) +""] = "" + totalScore + "" (Surprise#"" + (currentNoOfSurprises + 1)+"")"" ); + } + } + + int bs4 = bestScore; + int bs5 = bestScore +1; + int bs6 = bestScore +2; + + if(bs1 <=10 && bs2 <=10 && bs3<=10 && !bReturn) + { + bReturn = (bestScore + ( bestScore +1 ) + (bestScore +2)) == totalScore; + if(bReturn) + System.out.println(""Eligible Googler : ["" + bestScore +"", ""+ ( bestScore +1 )+"", "" + (bestScore +2) +""] = "" + totalScore + "" (Surprise#"" + (currentNoOfSurprises + 1)+"")"" ); + + if(!bReturn) + { + bReturn = (bestScore + (( bestScore +2 ) * 2)) == totalScore; + if (bReturn) + System.out.println(""Eligible Googler : ["" + bestScore +"", ""+ ( bestScore +2 )+"", "" + (bestScore +2) +""] = "" + totalScore + "" (Surprise#"" + (currentNoOfSurprises + 1)+"")"" ); + } + } + + if (bReturn) + { + currentNoOfSurprises++; + } + return bReturn; + } +*/ + private boolean isEligible(int totalScore) + { + boolean bReturn = false; + + if(noOfSurprises == 0 || currentNoOfSurprises >= noOfSurprises) + { + // System.out.println(""isEligibleIn: "" + (bestScore + ((bestScore -1) * 2)) + "" : "" + totalScore); + bReturn = (bestScore + ((bestScore -1) * 2)) <= totalScore; + } + else + { + // System.out.println(""isEligibleOut: "" + (bestScore + ((bestScore -2) * 2)) + "" : "" + totalScore); + bReturn = (bestScore + ((bestScore -2) * 2)) <= totalScore; + } + + //System.out.println(""isEligible: "" + bReturn); + + return bReturn; + } + +} +" +A22063,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Dancing { + + public static void main(String args[]) throws IOException{ + // Setup the input + File f1 = new File(""B-large.in""); + Scanner s1 = new Scanner(f1); + // setup the output: + PrintWriter out = new PrintWriter(new FileWriter(""output.out"")); + + // getting the number of test cases and getting rid of the line + int testCases = Integer.parseInt(s1.nextLine()); + //System.out.println(testCases); + + // setting up some vars + int googlers; + int surprising; + int testMax; + ArrayList scores = new ArrayList(); + int j = 0; + int resultNum; + int surprisingLeft; + // Loop over the lines + while(s1.hasNextLine()){ + scores.clear(); + resultNum = 0; + j++; + googlers = s1.nextInt(); + surprising = s1.nextInt(); + surprisingLeft = surprising; + testMax = s1.nextInt(); + for (int i = 0; i ((testMax-1)+(testMax-1)+(testMax-1))){ + resultNum++; + } + else if (surprisingLeft != 0 && scores.get(k)!=0){ + if (scores.get(k)>=testMax+testMax-2+testMax-2){ + resultNum++; + surprisingLeft--; + } + + } + } + out.println(""Case #""+j+"": ""+resultNum); + } + // close the scanner + s1.close(); + out.close(); + } +} +" +A21694,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +public class Dancing { + + public static void main(String[] args) throws IOException { + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + int cases = Integer.parseInt(in.readLine()); + for (int i = 1; i <= cases; i++) { + String[] inp = in.readLine().trim().split("" ""); + int N = Integer.parseInt(inp[0]); + int S = Integer.parseInt(inp[1]); + int p = Integer.parseInt(inp[2]); + List scores = new ArrayList(); + for (int j = 3; j < N+3; j++) { + scores.add(Integer.parseInt(inp[j])); + } + int out = 0; + Collections.sort(scores); + Collections.reverse(scores); + int j=0; + while(j=(3*p-2)) { out++; j++; } + if(p>1) while(j=(3*p-4) && S>0) { out++; j++; S--; } + System.out.println(""Case #""+i+"": ""+out); + } + } + +} +" +A21353," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class pro2 { + + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public static void main ( String [] args ) throws IOException + { + int N = Integer.parseInt(br.readLine()); + + for(int i = 0;i < N; i++) + System.out.println(""Case #"" + (i+1) + "": "" + cal()); + } + + private static String cal() throws IOException { + String[] buffer = br.readLine().split(""\\s""); + int p=Integer.parseInt(buffer[2]); + int winner=0; + int s=Integer.parseInt(buffer[1]); + int tempS=0; + + + for(int i=0;i=0){ + winner++; + tempS++; + } + } + + if(score%3==1) + if(p<=(score/3)+1) + winner++; + + if(score%3==2){ + if(p<=(score/3)+1) + winner++; + + else if(p<=(score/3)+2 && tempS= bestTotal) + ++numWin; + else if (scores[j] >= surpriseTotal) + ++numSurprise; + } + + numWin += Math.min (maxSurprise, numSurprise); + dataWriter.write (""Case #"" + (i + 1) + "": "" + numWin); + dataWriter.newLine (); + dataWriter.flush (); + } + } + catch (IOException ioE) + { + ioE.printStackTrace (); + } + } + +} +" +A21341,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Conny + */ +public class ProbQ2 { + public static void main(String[] args) { + + String fileContent = CodeJamTools.readFileAsString(""c:\\temp\\inputQ2.txt""); + String[] rows = fileContent.split(""\\n""); + int T = new Integer(rows[0]); + String output = """"; + + int counter = 1; + + for (int i=0; i= limit2) + overs++; + else if (data[j] >= limit1) + borderlines++; + } + + output += ""Case #""+(i+1)+"": ""; + output += (overs+Math.min(borderlines, S)); + output += ""\n""; + } + + System.out.print(output); + CodeJamTools.writeStringToFile(""C:\\Users\\Conny\\Documents\\conny\\own files\\java_workspace\\codejam2\\src\\outputQ2.txt"", output); + } + +} +" +A22017,"import java.io.*; +import java.util.StringTokenizer; + +public class B { + BufferedReader in; + StringTokenizer str; + PrintWriter out; + String SK; + + String next() throws IOException { + while ((str == null) || (!str.hasMoreTokens())) { + SK = in.readLine(); + if (SK == null) + return null; + str = new StringTokenizer(SK); + } + return str.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + long nextLong() throws IOException { + return Long.parseLong(next()); + } + + void solve() throws IOException { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int res = 0; + for (int i = 0; i < n; i++) { + int a = nextInt(); + int lf = (a + 2) / 3; + if (lf >= p) { + res++; + continue; + } + int t1 = lf + 1; + int t2 = lf - 1; + int t3 = a - t1 - t2; + if (t3 >= t2 && t1 >= p && s > 0 && t2 >= 0 && t3 >= 0) { + res++; + s--; + } + } + out.println(res); + } + + void run() throws IOException { + in = new BufferedReader(new FileReader(""fn.in"")); + out = new PrintWriter(""fn.out""); + int n = nextInt(); + for (int i = 0; i < n; i++) { + out.print(""Case #"" + (i + 1) + "": ""); + solve(); + } + out.close(); + } + + public static void main(String[] args) throws IOException { + new B().run(); + } + +}" +A21316,"import java.util.*; +import static java.lang.Math.*; + +public class B { + public static void main(String[] args){ + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int zz = 1; zz <= T;zz++){ + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + int answer = 0; + //int[] ti = new int[N]; + + for(int i = 0; i < N;i++){ + int ti = in.nextInt(); + int median = ti/3; + int mod = ti % 3; + if(ti>0){ + switch (mod) { + case 0: + if(median >=P) + { + answer++; + } + else if(median + 1 >= P && S>0) + { + answer++; + S--; + } + break; + case 1: + if(median + 1 >=P) + { + answer++; + } + + break; + case 2: + if(median+1 >=P) + { + answer++; + } + else if(median + 2 >= P && S>0) + { + answer++; + S--; + } + break; + default: break; + } + } + else + { + if(P == 0) + answer++; + } + } + System.out.format(""Case #%d: %d\n"", zz, answer); + } + } +} +" +A20140,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +/* + * Google Code Jam 2012 + * Qualification 2012 + * raguenets@gmail.com + * Usage : java DancingWithTheGooglers inputFileName outputFileName + */ +public class DancingWithTheGooglers { + public static int[] BEST_VALUE_NOT_SURPRISING = new int[] { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10 }; + public static int[] BEST_VALUE_SURPRISING = new int[] { 0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 }; + + public static void main(String[] args) { + int T = 0; + int N = 0; + int p = 0; + int S = 0; + + if (args.length == 2) { + String inputFilename = args[0]; + File finput = new File(inputFilename); + String outputFilename = args[1]; + File foutput = new File(outputFilename); + Scanner scanner = null; + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(foutput)); + } + catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + if (finput.exists()) { + try { + scanner = new Scanner(finput); + // Reads first line : number of Tests + if (scanner.hasNextInt()) { + T = scanner.nextInt(); + scanner.nextLine(); + } + for (int i = 0; i < T; i++) { + // Read number of flies + N = scanner.nextInt(); + S = scanner.nextInt(); + p = scanner.nextInt(); + int[] ti = new int[N]; + for (int j = 0; j < N; j++) { + ti[j] = scanner.nextInt(); + } + // Read fly positions + bw.write(""Case #"" + (i + 1) + "": "" + bestSolution(N, S, p, ti) + ""\n""); + } + } + catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + finally { + try { + bw.close(); + if (scanner != null) { + scanner.close(); + } + } + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + } + + // public static int bestSolution(int N, int S, int p, int[] ti) { + // if (S == 0) { + // int bestFound = 0; + // for (int i = 0; i < N; i++) { + // if (BEST_VALUE_NOT_SURPRISING[ti[i]] >= p) { + // bestFound++; + // } + // } + // return bestFound; + // } + // else if (S == 1) { + // int bestAll = 0; + // for (int i = 0; i < N; i++) { + // int bestFound = 0; + // for (int j = 0; j < N; j++) { + // if (ti[j] == 0 || ti[j] == 1 || ti[j] == 29 || ti[j] == 30) { + // continue; + // } + // if (i == j) { + // if (BEST_VALUE_SURPRISING[ti[j]] >= p) { + // bestFound++; + // } + // } + // else { + // if (BEST_VALUE_NOT_SURPRISING[ti[j]] >= p) { + // bestFound++; + // } + // } + // } + // if (bestFound > bestAll) { + // bestAll = bestFound; + // } + // } + // return bestAll; + // } + // else if (S == 2) { + // int bestAll = 0; + // for (int i = 0; i < N; i++) { + // if (ti[i] == 0 || ti[i] == 1 || ti[i] == 29 || ti[i] == 30) { + // continue; + // } + // for (int j = i; j < N; j++) { + // if (ti[j] == 0 || ti[j] == 1 || ti[j] == 29 || ti[j] == 30) { + // continue; + // } + // int bestFound = 0; + // for (int k = 0; k < N; k++) { + // if (k == i || k == j) { + // if (BEST_VALUE_SURPRISING[ti[k]] >= p) { + // bestFound++; + // } + // } + // else { + // if (BEST_VALUE_NOT_SURPRISING[ti[k]] >= p) { + // bestFound++; + // } + // } + // } + // if (bestFound > bestAll) { + // bestAll = bestFound; + // } + // } + // } + // return bestAll; + // } + // else if (S == 3) { + // int bestAll = 0; + // for (int i = 0; i < N; i++) { + // if (ti[i] == 0 || ti[i] == 1 || ti[i] == 29 || ti[i] == 30) { + // continue; + // } + // for (int j = i; j < N; j++) { + // if (ti[j] == 0 || ti[j] == 1 || ti[j] == 29 || ti[j] == 30) { + // continue; + // } + // for (int k = j; k < N; k++) { + // if (ti[k] == 0 || ti[k] == 1 || ti[k] == 29 || ti[k] == 30) { + // continue; + // } + // int bestFound = 0; + // for (int m = 0; m < N; m++) { + // + // if (m == i || m == j || m == k) { + // if (BEST_VALUE_SURPRISING[ti[m]] >= p) { + // bestFound++; + // } + // } + // else { + // if (BEST_VALUE_NOT_SURPRISING[ti[m]] >= p) { + // bestFound++; + // } + // } + // } + // if (bestFound > bestAll) { + // bestAll = bestFound; + // } + // } + // } + // } + // return bestAll; + // + // } + // return 0; + // } + public static int bestSolution(int N, int S, int p, int[] ti) { + int bestFound = 0; + for (int i = 0; i < N; i++) { + if (BEST_VALUE_NOT_SURPRISING[ti[i]] >= p) { + bestFound++; + } + } + int nbBestable = 0; + for (int i=0; i < N; i++) { + if (BEST_VALUE_NOT_SURPRISING[ti[i]] == p-1 && ti[i] != 0 && ti[i] != 1 && ti[i] != 29 && ti[i] != 30) { + nbBestable++; + } + } + return bestFound+Math.min(nbBestable, S); + + } +} +" +A21285,"package com.nithin; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +class SubThread implements Runnable { + Thread t; + int c=0,n=0,s=0,p=0; + int[] sc; + int res=0; + String a=""""; + SubThread(int i,int a,int b,int e,int[] d) { + c=(i+1); + n=a; + s=b; + p=e; + sc=d; + t = new Thread(this); + t.run(); + } + + public void run() { + float avg=0; + for(int i=0;i=1.5) + { + sc[i]=99; + } + else + { + if(avg>=p) + { + ++res; + a=a+sc[i]+"" ""; + sc[i]=99; + } + if( (p-avg)<1 && (p-avg)>0 ) + { + ++res; + a=a+sc[i]+"" ""; + sc[i]=99; + } + } + } + int i=0; + while(s>0 && i1 && (p-avg)<1.5 ) + { + ++res; + --s; + a=a+sc[i]+"" ""; + sc[i]=99; + } + ++i; + } + + } + public void print() + { + System.out.println(""Case #""+c+"": ""+res); + //System.out.println(a); + + } + +} + +public class Solution { + public static void main(String[] args) throws Exception { + StringTokenizer st; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t=Integer.parseInt(br.readLine()); + SubThread[] subthread=new SubThread[t]; + for(int i=0;i= comparisonScore) notSurprising++; + if((total >= (comparisonScoreMinus2)) && (total < (comparisonScore))) surprising++; + if(surprising >= allowableSurprising) surprising = allowableSurprising; + } + return notSurprising + surprising; + } + +} +" +A20050,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +public class GooglerIdol { + + /** + * @param args + */ + public static void main(String[] args) { + + File sample = new File( + ""D:/Feng/Workspace/googlecodejam2012/problemB/in/sample.in""); + + File in = new File( + ""D:/Feng/Workspace/googlecodejam2012/problemB/in/B-large.in""); + + try { + BufferedWriter out = new BufferedWriter(new FileWriter( + ""D:/Feng/Workspace/googlecodejam2012/problemB/out/outlarge.txt"")); + StringBuilder s; + String line = """"; + int googlers, surprises, p = 0; + int[] totalScores; + int idols, chances = 0; + int count = 1; + Scanner scanner = new Scanner(in); + // Ignore the first line showing total count + scanner.nextLine(); + while (scanner.hasNextLine()) { + s = new StringBuilder(""Case #""); + s.append(count); + s.append("": ""); + line = scanner.nextLine(); + + String[] tokens = line.split("" ""); + googlers = Integer.parseInt(tokens[0]); + surprises = Integer.parseInt(tokens[1]); + p = Integer.parseInt(tokens[2]); + totalScores = new int[googlers]; + for (int i = 3; i < tokens.length; i++) { + totalScores[i - 3] = Integer.parseInt(tokens[i]); + } + Arrays.sort(totalScores); + + idols = 0; + chances = surprises; + for (int j = googlers - 1; j >= 0; j--) { + if (pass(p, totalScores[j], false)) { + idols++; + } + else if (chances > 0 && pass(p, totalScores[j], true)) { + idols++; + chances--; + } + } + + s.append(idols); + /* + s.append(""\ngooglers:""); + s.append(googlers); + s.append("" surprises:""); + s.append(surprises); + s.append("" p:""); + s.append(p); + s.append(""\nTotal Scores""); + s.append(Arrays.toString(totalScores)); + */ + + System.out.println(s); + out.write(s.toString()); + out.newLine(); + count++; + } + scanner.close(); + out.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static boolean pass(int p, int totalScore, boolean surprise) { + + if (p == 0) + return true; + + if (totalScore == 0) + return false; + + int avg = totalScore / 3; + if (avg >= p) + return true; + + int diff = totalScore - (3 * avg); + + if (p - avg == 1 && diff > 0) { + return true; + } + + if (surprise && p - avg == 1 && diff == 0) { + return true; + } + + if (surprise && p - avg == 2 && diff > 1) { + return true; + } + + return false; + } +} +" +A22802,"package szarfos; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Main { + private static List numbers; + + public static void main(String[] args) throws IOException { + readFile(); + BufferedWriter out = new BufferedWriter(new FileWriter(""output.txt"")); + for (int i = 0; i < numbers.size(); i++) { + int numberOfPersons = Integer.parseInt(numbers.get(i)[0]); + int surp = Integer.parseInt(numbers.get(i)[1]); + int limit = Integer.parseInt(numbers.get(i)[2]); + + List totalPoints = new ArrayList(); + for (int j = 3; j < numbers.get(i).length; j++) { + totalPoints.add(Integer.parseInt(numbers.get(i)[j])); + } + + List points = new ArrayList(); + for (int j = 0; j < totalPoints.size(); j++) { + points.add(splitPoints(totalPoints.get(j))); + } + + int currentSurp = 0; + int count = 0; + for (int j = 0; j < points.size(); j++) { + if (totalPoints.get(j) > 1 && + points.get(j)[0] > 0 && points.get(j)[0] == limit - 1 && currentSurp < surp) { + if (points.get(j)[1] != points.get(j)[2] || + (points.get(j)[0] == points.get(j)[1] && points.get(j)[0] == points.get(j)[2])) { + points.get(j)[0]++; + currentSurp++; + } + } + + if (points.get(j)[0] >= limit) { + count++; + } + } + + int caseNum = i+1; + out.write(""Case #"" + caseNum + "": "" + count); + out.newLine(); + } + out.close(); + } + + public static Integer[] splitPoints(int p) { + Integer[] points = new Integer[3]; + int m = p / 3; + if (p%3 == 1) { + points[0] = m+1; + points[1] = m; + points[2] = m; + } else if (p%3 == 2) { + points[0] = m+1; + points[1] = m+1; + points[2] = m; + } else { + points[0] = m; + points[1] = m; + points[2] = m; + } + + return points; + } + + public static void readFile() { + try { + numbers = new ArrayList(); + BufferedReader in = new BufferedReader(new FileReader(""input.txt"")); + String str; + in.readLine(); + while ((str = in.readLine()) != null) { + String[] n = str.split("" ""); + numbers.add(n); + } + in.close(); + } catch (IOException e) { + } + } + +} +" +A22223,"package qualif2; + +import java.io.File; +import java.util.Arrays; +import java.util.Scanner; + +public class Qualif2 { + + public static void main(String[] args) throws Exception { + + Scanner scan = new Scanner(new File(""input"")); + + int num = Integer.parseInt(scan.nextLine()); + + for (int i = 1; i <= num; i++) { + int googlers = scan.nextInt(); + int surprising = scan.nextInt(); + int score = scan.nextInt(); + + int[] totals = new int[googlers]; + + for (int j = 0; j < googlers; j++) { + totals[j] = scan.nextInt(); + } + + System.out.println(""Case #"" + i + "": "" + solve(googlers, surprising, score, totals)); + } + } + + private static int solve(int googlers, int surprising, int score, int[] totals) { + Arrays.sort(totals); + int count = 0; + + if (score == 0) { + return googlers; + } + + for (int i = totals.length - 1; i >= 0; i--) { + int total = totals[i]; + if (total > 28) { + count++; + continue; + } + + if (total == 0) { + continue; + } + + int base = total / 3; + int r = total % 3; + + int n = base + (r > 0 ? 1 : 0); + + if (n >= score) { + count++; + } else if (surprising > 0) { + surprising--; + if (n + (r == 1 ? 0 : 1) >= score) { + count++; + } + } else { + break; + } + } + + return count; + } +} +" +A22385,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; + + +public class MaxBestResult { + + public static void main(String[] args) throws FileNotFoundException { + File input = new File(""B-large.in""); + Scanner data = new Scanner(input); + PrintStream output = new PrintStream(new File(""B-large.out"")); + int times = data.nextInt(); + + for(int i = 1; i <= times; i++){ + String text = data.next() + data.nextLine(); + Scanner line = new Scanner(text); + Round temp = new Round(line); + output.println(""Case #"" + i + "": "" + temp.calculate()); + } + } + +} +" +A22600,"import java.util.Scanner; + +public class DancingWithGooglers { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int numberOfTests = Integer.parseInt(in.nextLine()); + + for(int i = 0; i < numberOfTests; i++) { + int googlers = in.nextInt(), suprises = in.nextInt(), query = in.nextInt(); + int numberSatisfyingQuery = 0, numberNeedingSuprises = 0; + for(int j = 0; j < googlers; j++) { + int total = in.nextInt(); + if(total % 3 == 0) { + int high = total / 3; + if(high >= query) { + numberSatisfyingQuery++; + } else if(high + 1 >= query && high >= 1) { + numberNeedingSuprises++; + } + } else if(total % 3 == 1) { + int high = total / 3 + 1; + if(high >= query) { + numberSatisfyingQuery++; + } // Surprise not possible + } else if(total % 3 == 2) { + int high = total / 3 + 1; + if(high >= query) { + numberSatisfyingQuery++; + } else if(high + 1 >= query && high >= 1) { + numberNeedingSuprises++; + } + } + } + int result = numberSatisfyingQuery + Math.min(numberNeedingSuprises, suprises); + System.out.println(""Case #"" + (i + 1) + "": "" + result); + } + } +}" +A20761,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class GoogleDance { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); + int cases = Integer.parseInt(br.readLine().trim()); + for(int t=1;t<=cases;t++){ + String ln=br.readLine().trim(); + String[] inp=ln.split("" ""); + int n=Integer.parseInt(inp[0]); + int s=Integer.parseInt(inp[1]); + int p=Integer.parseInt(inp[2]); + int[] scores=new int[n]; + int count=0, sleft=s; + for(int i=0;i ""+scores[i]+"" :: ""+avg+"" :: ""+rem+"" :s""+sleft+"" :c ""+count); + if(avg>=p){ + count++; + continue; + } + if(rem>=1 && (avg+1)>=p){ + count++; + continue; + } + if(sleft>0){ + switch (rem) { + case 0: + if(avg>0 && (avg+1)>=p){ + sleft--; + count++; + continue; + } + break; + case 1: + break; + case 2: + if((avg+2)>=p){ + sleft--; + count++; + continue; + } + break; + + default: + break; + } + } + } + System.out.println(""Case #""+t+"": ""+count); + + } + } + +} +" +A21269,"import java.io.*; +import java.util.*; + +public class Main implements Runnable { + BufferedReader br; + StringTokenizer st; + int n, s, p, ans; + int[] t; + + public class Googler implements Comparable { + int total, a, b, c; + + public Googler(int total) { + this.total = total; + a = total / 3; + b = (total - total / 3) / 2; + c = total - a - b; + } + + public int compareTo(Googler g) { + return g.total - this.total; + } + } + + public void run() { + try { + br = new BufferedReader(new InputStreamReader(System.in)); + int caseNo = Integer.parseInt(br.readLine()); + + for (int i = 1; i <= caseNo; i++) { + st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + s = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + t = new int[n]; + Googler[] googler = new Googler[n]; + for (int j = 0; j < n; j++) { + t[j] = Integer.parseInt(st.nextToken()); + googler[j] = new Googler(t[j]); + } + + Arrays.sort(googler); + ans = 0; + for (int j = 0; j < n; j++) + if (googler[j].c >= p) + ans++; + + for (int j = 0; j < n && s > 0; j++) + if (googler[j].total > 0 && googler[j].c < p && !((googler[j].a == googler[j].b) && (googler[j].b < googler[j].c))) { + googler[j].b--; + googler[j].c++; + if (googler[j].c == p) { + ans++; + s--; + } + } + + System.out.println(""Case #"" + i + "": "" + ans); + } + } + catch (Exception e) { + } + } + + public static void main(String[] args) { + new Thread(new Main()).start(); + } +} +" +A22265,"import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.*; + +public class SurpScores { + + public int count(int[] scores, int p, int surprises) { + int countSurp = 0; + int countNonSurp = 0; + int minSurpScore = p + (p-2) + (p-2); + int minNonSurpScore = minSurpScore + 2; + if(p < 2) { + minSurpScore = minNonSurpScore = p; + } + + for(int i = 0; i < scores.length; i++) { + if(scores[i] >= minNonSurpScore) countNonSurp++; + else if(scores[i] >= minSurpScore) countSurp++; + } + + return countNonSurp + Math.min(surprises, countSurp); + } + + + public static void main(String args[]) { + SurpScores c = new SurpScores(); + String result[] = null; + + + try { + Scanner sc = new Scanner(new FileInputStream(""C:/Users/Administrator/Downloads/B-large.in"")); + String line = sc.nextLine().trim(); + int cases = Integer.parseInt(line); + result = new String[cases]; + for(int i = 0; i < cases; i++) { + line = sc.nextLine().trim(); + String temp[] = line.split("" ""); + int players = Integer.parseInt(temp[0]); + int surprises = Integer.parseInt(temp[1]); + int p = Integer.parseInt(temp[2]); + int scores[] = new int[players]; + + for(int j = 0; j < players; j++) { + scores[j] = Integer.parseInt(temp[j + 3]); + } + result[i] = ""Case #"" + (i+1) + "": "" + c.count(scores, p, surprises); + } + + } catch(Exception e) { + e.printStackTrace(); + } + + try { + FileWriter fstream = new FileWriter(""C:/out.txt""); + PrintWriter out = new PrintWriter(fstream); + + for(int i = 0; i < result.length; i++) { + out.println(result[i]); + } + out.close(); + }catch(Exception e) { + e.printStackTrace(); + } + } +} +" +A22439,"import java.io.*; +import java.util.*; + +public class B { + + void solve() throws IOException { + in(""B-large.in""); out(""B-large.out""); + + boolean[][] surprising = new boolean[31][11]; + boolean[][] plain = new boolean[31][11]; + + for (int t = 0; t <= 30; ++t) { + //plain + // a a a + // a a-1 a + // a a-1 a-1 + for (int best = 10; best >= 0; --best) { + int v = 3 * best; + if (v == t || v - 1 == t || v - 2 == t) { + for (int i = best; i >= 0; --i) { + plain[t][i] = true; + } + break; + } + } + + //surprising + // a a-2 a + // a a-2 a-1 + // a a-2 a-2 + for (int best = 10; best >= 2; --best) { + int v = 3 * best; + if (v - 2 == t || v - 3 == t || v - 4 == t) { + for (int i = best; i >= 0; --i) { + surprising[t][i] = true; + } + break; + } + } + } + + int t = readInt(); + for (int cs = 1; cs <= t; ++cs) { + int ans = 0; + int n = readInt(); + int s = readInt(); + int p = readInt(); + int[] v = new int[n]; + int[] mask = new int[n]; + for (int i = 0; i < n; ++i) { + v[i] = readInt(); + if (s > 0) { + if (surprising[v[i]][p]) { + mask[i] = 2; + --s; + ++ans; + } else if (plain[v[i]][p]) { + mask[i] = 1; + ++ans; + } + } else { + if (plain[v[i]][p]) { + mask[i] = 1; + ++ans; + } else if (surprising[v[i]][p]) { + for (int j = 0; j < i; ++j) { + if (mask[j] == 2 && plain[v[j]][p]) { + mask[j] = 1; + mask[i] = 2; + ++ans; + break; + } + } + } + } + } + if (s > 0) { + for (int i = 0; i < n && s > 0; ++i) { + if (mask[i] == 0 && v[i] >= 2 && v[i] <= 28) { + --s; + } + } + } + if (s > 0) { + System.out.println(""!bad ans""); + for (int i = 0; i < n && s > 0; ++i) { + if (mask[i] == 1 && v[i] >= 2 && v[i] <= 28) { + --s; + --ans; + } + } + } + if (s > 0) { + System.out.println(""!very bad""); + } + println(""Case #"" + cs + "": "" + ans); + } + + exit(); + } + + void in(String name) throws IOException { + if (name.equals(""__std"")) { + in = new BufferedReader(new InputStreamReader(System.in)); + } else { + in = new BufferedReader(new FileReader(name)); + } + } + + void out(String name) throws IOException { + if (name.equals(""__std"")) { + out = new PrintWriter(System.out); + } else { + out = new PrintWriter(name); + } + } + + void exit() { + out.close(); + System.exit(0); + } + + int readInt() throws IOException { + return Integer.parseInt(readToken()); + } + + long readLong() throws IOException { + return Long.parseLong(readToken()); + } + + double readDouble() throws IOException { + return Double.parseDouble(readToken()); + } + + String readLine() throws IOException { + st = null; + return in.readLine(); + } + + String readToken() throws IOException { + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(in.readLine()); + } + return st.nextToken(); + } + + boolean eof() throws IOException { + return !in.ready(); + } + + void print(String format, Object ... args) { + out.println(new Formatter(Locale.US).format(format, args)); + } + + void println(String format, Object ... args) { + out.println(new Formatter(Locale.US).format(format, args)); + } + + void print(Object value) { + out.print(value); + } + + void println(Object value) { + out.println(value); + } + + void println() { + out.println(); + } + + StringTokenizer st; + + BufferedReader in; + PrintWriter out; + + public static void main(String[] args) throws IOException { + new B().solve(); + } +} +" +A22069,"package hk.polyu.cslhu.codejam.solution; + +import java.util.List; + +import org.apache.log4j.Logger; + +public abstract class Solution implements Cloneable { + public static Logger logger = Logger.getLogger(Solution.class); + + protected String result; + + /** + * Set the problem to be solved + * + * @param problemDesc List The description of problem + */ + public abstract void setProblem(List problemDesc); + + /** + * Solve the problem + */ + public abstract void solve(); + + /** + * Return the result of problem + * + * @return String Result + */ + public String getResult() { + return this.result; + } + + public Solution clone() throws CloneNotSupportedException { + return (Solution) super.clone(); + } +} +" +A22571,"import java.io.BufferedReader; +import java.io.IOException; + +import javax.management.RuntimeErrorException; + + +public class DancingGooglersProblemCase implements ProblemCase { + + final int dancers; + final int special; + final int bar; + final int scores[]; + + public DancingGooglersProblemCase(BufferedReader reader) throws IOException { + String newCase = reader.readLine(); + String[] params = newCase.split("" ""); + dancers = Integer.parseInt(params[0]); + special = Integer.parseInt(params[1]); + bar = Integer.parseInt(params[2]); + if (dancers != params.length-3) { + throw new RuntimeErrorException(null); + } + scores = new int[dancers]; + for (int j = 0; j < dancers; j++) { + scores[j] = Integer.parseInt(params[j+3]); + } + } + + + public String getResult() { + Integer res = 0; + int caclBar = bar*3-2; + int specialCounter = special; + for (int score : scores) { + if (score >= caclBar || bar == 0 || (bar == 1 && score > 0 )){ + res++; + } else if (score >= caclBar - 2 && specialCounter > 0 && !(bar == 1 && score == 0 )) { + specialCounter--; + res++; + } + } + return res.toString(); + } + +} +" +A21360,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + +public class Triplets { + + public static void main(String[] args) throws IOException { + new Triplets().run(""B-large.in""); +// new Triplets().run(""problem.txt""); + } + + public void run(String fileName) throws IOException { + parseFile(fileName); + } + + private void parseFile(String fileName) throws FileNotFoundException { + File file = new File(fileName); + Scanner scanner = new Scanner(file); + + int numTests = Integer.parseInt(scanner.nextLine()); + for (int i = 1; i <= numTests; i++) { + System.out.println(""Case #"" + i + "": "" + solve(scanner.nextLine())); + } + scanner.close(); + } + + public String solve(String line) { + Scanner ls = new Scanner(line); + int num = ls.nextInt(); + int suprises = ls.nextInt(); + int p = ls.nextInt(); + int[] tps = new int[num]; + for (int i = 0; i < tps.length; i++) { + tps[i] = ls.nextInt(); + } + + Solver solver = new Solver(suprises, p, tps); + + return Integer.toString(solver.solve()); + } +} + +class Solver { + private int surprises; + private final int p; + private final int[] tps; + + Solver(int suprises, int p, int[] tps) { + this.surprises = suprises; + this.p = p; + this.tps = tps; + } + + public int solve() { + int possibles = 0; + if (p == 0) + return tps.length; + + for (int tp : tps) { + if (tp % 3 == 0 && tp != 0) { + int mp = tp / 3; + if (mp >= p) { + possibles++; + } else if ((mp + 1) >= p && surprises > 0) { + surprises--; + possibles++; + } + } else if (tp % 3 == 1) { + + int mp = tp / 3 + 1; + if (mp >= p) + possibles += 1; + + } else if (tp % 3 == 2) { + int mp = tp / 3 + 1; + if (mp >= p) { + possibles++; + } else if ((mp + 1) >= p && surprises > 0) { + surprises--; + possibles++; + } + } + } + + return possibles; + } + +} +" +A21508,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; + +public class B { + /** + * @param args + */ + public static void main( String[] args ) { + try { + String fileName = ""B-large"";// ""B-small-attempt0"";// ""B-test"";// + BufferedReader inFile = new BufferedReader( new FileReader( + new File( fileName+"".in"" ) ) ); + PrintStream outFile = new PrintStream( + new FileOutputStream( fileName+"".out"" )); + + String line = inFile.readLine(); + int tests = Integer.parseInt( line ); + for (int test = 0; test < tests; test++) { + line = inFile.readLine(); + String[] ss = line.split( "" "" ); + int n = Integer.parseInt( ss[0] ); + int s = Integer.parseInt( ss[1] ); + int p = Integer.parseInt( ss[2] ); + int ans = 0; + for ( int i = 0; i < n; i++ ) { + int a = Integer.parseInt( ss[i+3] ); + if ( p + 2*Math.max( p-1, 0 ) <= a ) ans++; + else if ( s > 0 && p + 2*Math.max( p-2, 0 ) <= a ){ + ans++; + s--; + } + } + outFile.println( ""Case #"" + (test+1) + "": "" + ans ); + } + inFile.close(); + outFile.close(); + + } catch ( IOException e ) { + e.printStackTrace(); + } + } + +} + + +" +A20074,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + + +public class q2 { + public static int calc(int n, int s, int p,ArrayList scores) { + int count = 0; + int aboveAve = 0; + for(int i = 0;i < n;i++) { + if(scores.get(i) >= 3*p) { + aboveAve ++; + continue; + } + if((scores.get(i) >= (3*p - 2))&&(3*p - 2 >= 0)) { + aboveAve ++; + } else { + if((scores.get(i) >= (3*p - 4))&&(3*p - 4 >= 0)) { + count ++; + } + } + } + if(count > s) { + count = s; + } + count = count + aboveAve; + return count; + } + /** + * @param args + */ + public static void main(String[] args) { + ArrayList scores = new ArrayList(); + int p = 0;//at least p + int s = 0;//surprise + int n = 0;//n dancers + try { + FileReader fr = new FileReader(""D:\\B-large.in""); + BufferedReader br = new BufferedReader(fr); + FileWriter fw = new FileWriter(""D:\\y.txt""); + BufferedWriter bw = new BufferedWriter(fw); + String str = br.readLine(); + int t = Integer.parseInt(str); + for(int i = 0;i < t;i++) { + String data = br.readLine(); + String[] numbers = data.split("" ""); + n = Integer.parseInt(numbers[0]); + s = Integer.parseInt(numbers[1]); + p = Integer.parseInt(numbers[2]); + for(int j = 0;j < n;j++) { + scores.add(Integer.parseInt(numbers[j + 3])); + } + String prefix = ""Case #"" + (i+1) + "": ""; + System.out.print(prefix + calc(n, s, p, scores) + ""\n""); + bw.write(prefix + calc(n, s, p, scores) + ""\n""); + scores.clear(); + } + br.close(); + fr.close(); + bw.close(); + fw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} +" +A22522,"import java.util.Scanner; + +import jp.ne.sakura.yuki2006.CodeJam.CodeJam; +import jp.ne.sakura.yuki2006.CodeJam.ITestCase; + +/** + * + */ + +/** + * @author yuki + * + */ +public class DancingWithTheGooglers implements ITestCase { + + /* + * (非 Javadoc) + * + * @see jp.ne.sakura.yuki2006.CodeJam.ITestCase#testCase(java.util.Scanner) + */ + @Override + public String testCase(Scanner stdIn) { + int N = stdIn.nextInt(); + int S = stdIn.nextInt(); + int P = stdIn.nextInt(); + int overCount = 0; + int under = 0; + for (int i = 0; i < N; i++) { + int t = stdIn.nextInt(); + if (3 * P - 2 <= t) { + overCount++; + } else if (2 <= P && 3 * P - 4 <= t) { + if (under < S) { + under++; + } + } + } + + return (overCount + under) + """"; + } + + /** + * @param args + */ + public static void main(String[] args) { + new CodeJam(new DancingWithTheGooglers(), ""Bout.txt""); + } + +} +" +A20467,"import java.io.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class dancing { + static int surprising; + + /** + * @param args + */ + public static final int regexOccur(String text, String regex) { + Matcher matcher = Pattern.compile(regex).matcher(text); + int occur = 0; + while(matcher.find()) { + occur ++; + } + return occur; + } + + public static int solve(BufferedReader reader) throws IOException { + + int cpt = 0; + String ligne = reader.readLine(); + int taille = regexOccur(ligne, Pattern.quote("" "")) + 1; + + String[] entiers = new String[taille]; + + entiers = ligne.split("" ""); + + int N = Integer.parseInt(entiers[0]); + int S = Integer.parseInt(entiers[1]); + int p = Integer.parseInt(entiers[2]); + surprising = 0; + + for(int i = 0; i < N; i++) { + cpt += best_result(p, Integer.parseInt(entiers[i + 3])); + } + + if(S - surprising > 0) return cpt; + else return cpt + S - surprising; + } + + public static int best_result(int p, int note) throws IOException { + + int a; + + a = note/3; + + if(a >= p) return 1; + else { + if(note - a > 0) { + if(note%3 == 0 && a + 1 >= p) { + surprising++; + return 1; + } + if(note%3 == 1 && a + 1 >= p) return 1; + if(note%3 == 2) { + if(a + 1 >= p) return 1; + if(a + 2 >= p) { + surprising++; + return 1; + } + } + } + } + + return 0; + } + + + public static void main(String[] args) { + + + try { + InputStream ips = new FileInputStream(""dancing.in""); + InputStreamReader ipsr = new InputStreamReader(ips); + BufferedReader br = new BufferedReader(ipsr); + + int cases = Integer.valueOf(br.readLine()); + + for (int i = 1; i <= cases; i++) { + imprimer(i, solve(br)); + } + } catch (IOException x) { + System.err.println(x); + } catch (NumberFormatException x) { + System.err.println(x); + } + } + + static void imprimer(int numero, int resultat) { + + try { + FileWriter fw = new FileWriter (""dancing.out"",true); + BufferedWriter bw = new BufferedWriter (fw); + PrintWriter fichierSortie = new PrintWriter (bw); + fichierSortie.println (""Case #"" + numero + "": "" + resultat); + fichierSortie.close(); + } + catch (Exception e){ + System.out.println(e.toString()); + } + + } +} +" +A22498," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Dancing { + + static int[] max_surprising = new int[31]; + static int[] max_no_surprising = new int[31]; + + public static void main(String[] args) throws IOException { + + max_surprising[0] = 0; + max_no_surprising[0] = 0; + max_surprising[1] = 0; + max_no_surprising[1] = 0; + for (int i = 2; i < 29; i++) { + + int remainder = i % 3; + int quotient = i / 3; + if (remainder == 0) { + max_no_surprising[i] = quotient; + max_surprising[i] = quotient + 1; + } else if (remainder == 1) { + max_no_surprising[i] = quotient + 1; + max_surprising[i] = quotient + 1; + } else { + max_no_surprising[i] = quotient + 1; + max_surprising[i] = quotient + 2; + } + } + max_no_surprising[29] = 10; + max_surprising[29] = 10; + max_no_surprising[30] = 10; + max_surprising[30] = 10; + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + int cases = Integer.parseInt(in.readLine()); + for (int i = 0; i < cases; i++) { + String[] inp = in.readLine().split("" ""); + int surprisesLeft = Integer.parseInt(inp[1]); + int target = Integer.parseInt(inp[2]); + String[] scores = new String[inp.length - 3]; + for(int j = 0; j < scores.length; j++) + scores[j] = inp[j+3]; + int answer = calculate(scores, surprisesLeft, target); + System.out.println(""Case #"" + (i+1) + "": "" + answer); + + } + + + + } + + public static int calculate(String[] scoresRemaining, int surprisesLeft, int target) { + int count = 0; + + if (scoresRemaining.length == surprisesLeft) { + for (int i = 0; i < scoresRemaining.length; i++) { + if (max_surprising[Integer.parseInt(scoresRemaining[i])] >= target) { + count++; + } + } + return count; + } else if (surprisesLeft == 0) { + + for (int i = 0; i < scoresRemaining.length; i++) { + if (max_no_surprising[Integer.parseInt(scoresRemaining[i])] >= target) { + count++; + } + } + return count; + + } else { + int score = Integer.parseInt(scoresRemaining[0]); + String[] temp = new String[scoresRemaining.length - 1]; + for (int i = 0; i < temp.length; i++) { + temp[i] = scoresRemaining[i + 1]; + } + if (max_no_surprising[score] >= target) { + return 1 + calculate(temp, surprisesLeft, target); + } else if (max_surprising[score] >= target) { + return 1 + calculate(temp, surprisesLeft - 1, target); + } else { + return calculate(temp, surprisesLeft, target); + } + + } + } +} +" +A20752,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class DanceGoogle { + public static void main( String[] args ) throws IOException { + File fileOut = new File( ""B-large.out"" ); + BufferedWriter writer = new BufferedWriter( new FileWriter(fileOut) ); + Scanner sc = new Scanner( new File ( ""B-large.in"" ) ); + int count = 0; + int number = sc.nextInt(); + int caseNumber = number; + for ( int caseNumberIndex = 0; caseNumberIndex < caseNumber; caseNumberIndex++ ) { + int numberOfDancer = sc.nextInt(); + int numberOfSuprise = sc.nextInt(); + int bestScore = sc.nextInt(); + int compare = ( bestScore * 3 ) - 2; + for ( int dancerIndex = 0; dancerIndex < numberOfDancer; dancerIndex++ ) { + number = sc.nextInt(); + if ( ( number > 28 ) || ( number < 2 ) ) { + if ( number > 28 ) + count++; + else if( (number > 0) && (bestScore == 1) ) + count++; + } + else if ( number < compare ) { + if ( number >= (compare - 2 ) ) { + if ( numberOfSuprise > 0 ) { + numberOfSuprise--; + count++; + } + } + } + else + count++; + } + if ( bestScore == 0 ) + count = numberOfDancer; + writeOutput( writer, count, caseNumberIndex ); + count = 0; + } + writer.close(); + sc.close(); + } + + private static void writeOutput( BufferedWriter writer, int count, int caseNumber ) throws IOException { + writer.append( ""Case #"" + (caseNumber+1) ); + writer.append( "": "" + count ); + writer.append( ""\r\n"" ); + + } +} +" +A20582,"package assignments; + +import java.util.Scanner; + +import base.Assignment; + +public class AssignmentB implements Assignment { + int bestResult; + int numberOfGooglers; + int numberOfSurprises; + int[] test; + @Override + public String solve() { + int minNeeded = 3*bestResult - 2; + int minNeededWithSurprise = 3*bestResult - 4; + int total = 0; + for (int i : test) { + if (i >= minNeeded) { + total++; + } else if (i >= minNeededWithSurprise && numberOfSurprises > 0 && bestResult > 1) { + total++; + numberOfSurprises--; + } + + } + return """" + total; + } + + public static Assignment createFromScanner(Scanner scanner) { + AssignmentB assignment = new AssignmentB(); + assignment.numberOfGooglers = scanner.nextInt(); + assignment.numberOfSurprises = scanner.nextInt(); + assignment.bestResult = scanner.nextInt(); + assignment.test = new int[assignment.numberOfGooglers]; + for (int i = 0; i < assignment.numberOfGooglers; i++) { + assignment.test[i] = scanner.nextInt(); + } + return assignment; + } +} +" +A21202,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = null; + BufferedWriter bw = null; + try{ + sc = new Scanner(new File(""input.txt"")); + bw = new BufferedWriter(new FileWriter(""gcj2b.txt"")); + + int T = sc.nextInt(); + int N, p, s, x; + int minNormal=0, minSur=0, totNor=0, totSur=0; + for(int i=0;ip)?minSur:p; + for(int j=0;j=minNormal) totNor++; + else if(x>=minSur) totSur++; + } + + totNor += s>totSur?totSur:s; + bw.write(""Case #""+(i+1)+"": ""+totNor);bw.newLine(); + } + }catch(Exception e){} + finally{ + try{ + sc.close();bw.close(); + }catch(Exception e){} + } + } + +} +" +A22678,"package ru.guredd.codejam; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public class Main { + + protected static List inputData = new ArrayList(); + protected static List outputData = new ArrayList(); + + public static void loadInputData(String fileName) throws IOException { + BufferedReader in = null; + try { + inputData.clear(); + String line; + in = new BufferedReader(new FileReader(fileName)); + + if (!in.ready()) + throw new IOException(); + + while ((line = in.readLine()) != null) + inputData.add(line); + } finally { + if(in != null) { + in.close(); + } + } + } + + public static void saveOutputData(String fileName) throws IOException { + BufferedWriter out = null; + try { + out = new BufferedWriter(new FileWriter(fileName)); + + for (String anOutputData : outputData) { + out.write(anOutputData); + out.newLine(); + } + } finally { + if(out != null) { + out.close(); + } + } + } + + public static void main (String [] argv) throws IOException { + + loadInputData(argv[0]); + + Qualification2012B QB = new Qualification2012B(); + QB.solve(); + + saveOutputData(argv[1]); + } +} +" +A21934,"package jp.funnything.competition.util; + +public class Prof { + private long _start; + + public Prof() { + reset(); + } + + private long calcAndReset() { + final long ret = System.currentTimeMillis() - _start; + + reset(); + + return ret; + } + + private void reset() { + _start = System.currentTimeMillis(); + } + + @Override + public String toString() { + return String.format( ""Prof: %f (s)"" , calcAndReset() / 1000.0 ); + } + + public String toString( final String head ) { + return String.format( ""%s: %f (s)"" , head , calcAndReset() / 1000.0 ); + } +} +" +A20581,"package base; + + +public interface Assignment { + + String solve(); +} +" +A20148,"/** + * + */ +package kr.javanese.gcj2012.qr.b; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.InputStreamReader; + +/** + * @author javanese + * + */ +public class DancingWithTheGooglers { + + private int findMax(int s, int p, int[] t) { + int n = t.length; + int[] tremaining = new int[t.length]; + int bmin[] = new int[t.length]; // min of possible best scores + int bmax[] = new int[t.length]; // max of possible best scores + boolean[] shouldBeSuprising = new boolean[n]; + + int count = 0; + int shouldBeSuprisingCount = 0; + for (int i=0; i=p) { + count++; + } else if (bmax[i]==p) { + shouldBeSuprising[i] = true; + shouldBeSuprisingCount++; + } + break; + case 1: + bmin[i] = t[i]/3+1; + bmax[i] = t[i]/3+1; + if (bmin[i]>=p) { + count++; + } + break; + case 2: + bmin[i] = t[i]/3+1; + bmax[i] = t[i]/3+2; + if (bmin[i]>=p) { + count++; + } else if (bmax[i]==p) { + shouldBeSuprising[i] = true; + shouldBeSuprisingCount++; + } + break; + } + System.err.println("">> ""+i+"": ""+bmin[i]+"", ""+bmax[i]+"", ""+count+""[""+shouldBeSuprisingCount+""]""); + } + + if (shouldBeSuprisingCount>=s) { + count += s; + } else { + count += shouldBeSuprisingCount; + } + return count; + } + + public static void main(String[] args) { + try { + DancingWithTheGooglers instance = new DancingWithTheGooglers(); + + BufferedReader reader; + if (args.length > 0) { + reader = new BufferedReader(new FileReader(args[0])); + } else { + reader = new BufferedReader(new InputStreamReader(System.in)); + } + String line = null; + line = reader.readLine(); + int caseCount = Integer.parseInt(line); + + long startTime = System.currentTimeMillis(); + + for (int i = 0; i < caseCount; i++) { + line = reader.readLine(); + String[] tokens = line.split("" ""); + int n = Integer.parseInt(tokens[0]); + int s = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int t[] = new int[n]; + for (int j=0; j= p) ans ++; + else + { + if (s > 0 && score[i] >= 2 && ((score[i] + 4) / 3 >= p)) + { + s--; + ans++; + } + } + } + output += ans; + output += '\n'; + writer.write(output); + } + reader.close(); + writer.close(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} +" +A20706,"package problems; + +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t= sc.nextInt(), N, S, P, Rnumber, number, aux; + for (int i=1; i<=t; i++){ + N= sc.nextInt(); + S= sc.nextInt(); + P= sc.nextInt(); + aux=0; + P=3*P-2; + Rnumber= P-2; + if (P==1) Rnumber =1; + System.out.print(""Case #""+i+"": ""); + for (int j=0; j=P){ + aux++; + } + else if ((S>0) && (number>=Rnumber)){ + S--; + aux++; + } + } + System.out.println(aux); + } + } +}" +A23003,"import java.util.*; +import java.io.*; + +public class dancing { + private static Reader in; + private static PrintWriter out; + public static final String NAME = ""B-large""; + + private static void main2() throws IOException { + int N = in.nextInt(), S = in.nextInt(), p = in.nextInt(); + int [] arr = new int [N + 1]; + for (int i = 1; i <= N; i++) + arr [i] = in.nextInt(); + + int [][] dp = new int [N + 1][S + 1]; + dp [0][0] = 0; + for (int i = 1; i <= N; i++) { + int curscore = (arr [i] + 2) / 3, nscore = (arr [i] + 4) / 3; + if (arr [i] == 0) curscore = nscore = 0; + dp [i][0] = dp [i - 1][0]; + if (curscore >= p) + dp [i][0] = dp [i - 1][0] + 1; + for (int j = 1; j <= S; j++) { + dp [i][j] = Math.max (dp [i - 1][j - 1], dp [i - 1][j]); + if (curscore >= p) + dp [i][j] = Math.max (dp [i][j], dp [i - 1][j] + 1); + if (nscore >= p) + dp [i][j] = Math.max (dp [i][j], dp [i - 1][j - 1] + 1); + } + } + + out.println (dp [N][S]); + } + + public static void main(String[] args) throws IOException { + in = new Reader(NAME + "".in""); + out = new PrintWriter(new BufferedWriter(new FileWriter(NAME + "".out""))); + + int numCases = in.nextInt(); + for (int test = 1; test <= numCases; test++) { + out.print(""Case #"" + test + "": ""); + main2(); + } + + out.close(); + System.exit(0); + } + + /** Faster input **/ + static class Reader { + final private int BUFFER_SIZE = 1 << 16; + private DataInputStream din; + private byte[] buffer; + private int bufferPointer, bytesRead; + + public Reader() { + din = new DataInputStream(System.in); + buffer = new byte[BUFFER_SIZE]; + bufferPointer = bytesRead = 0; + } + + public Reader(String file_name) throws IOException { + din = new DataInputStream(new FileInputStream(file_name)); + buffer = new byte[BUFFER_SIZE]; + bufferPointer = bytesRead = 0; + } + + public String readLine() throws IOException { + byte[] buf = new byte[1024]; + int cnt = 0, c; + while ((c = read()) != -1) { + if (c == '\n') + break; + buf[cnt++] = (byte) c; + } + return new String(buf, 0, cnt); + } + + public int nextInt() throws IOException { + int ret = 0; + byte c = read(); + while (c <= ' ') + c = read(); + boolean neg = (c == '-'); + if (neg) + c = read(); + do { + ret = ret * 10 + c - '0'; + } while ((c = read()) >= '0' && c <= '9'); + if (neg) + return -ret; + else + return ret; + } + + public long nextLong() throws IOException { + long ret = 0; + byte c = read(); + while (c <= ' ') + c = read(); + boolean neg = (c == '-'); + if (neg) + c = read(); + do { + ret = ret * 10 + c - '0'; + } while ((c = read()) >= '0' && c <= '9'); + if (neg) + return -ret; + else + return ret; + } + + public double nextDouble() throws IOException { + double ret = 0, div = 1; + byte c = read(); + while (c <= ' ') + c = read(); + boolean neg = (c == '-'); + if (neg) + c = read(); + do { + ret = ret * 10 + c - '0'; + } while ((c = read()) >= '0' && c <= '9'); + if (c == '.') { + while ((c = read()) >= '0' && c <= '9') + ret += (c - '0') / (div *= 10); + } + if (neg) + return -ret; + else + return ret; + } + + public char nextChar() throws IOException { + char ret = 0; + byte c = read(); + while (c <= ' ') + c = read(); + return (char) c; + } + + private void fillBuffer() throws IOException { + bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); + if (bytesRead == -1) + buffer[0] = -1; + } + + private byte read() throws IOException { + if (bufferPointer == bytesRead) + fillBuffer(); + return buffer[bufferPointer++]; + } + + public void close() throws IOException { + if (din == null) + return; + din.close(); + } + } +} +" +A22663,"package birgit.vera.schmidt.googlecodejam2012.qual; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; + +public class B { + public static void main(String[] args) { + try { + String filename = ""B-large""; + BufferedReader in = new BufferedReader(new FileReader(new File(filename + "".in""))); + PrintStream out = new PrintStream(new FileOutputStream(new File(filename + "".out""))); + + int t = Integer.parseInt(in.readLine()); + + for (int i = 0; i < t; i++) { + out.println(""Case #"" + (i+1) + "": "" + calcCase(in.readLine())); + } + + } catch (IOException e) { + // Just crash. + e.printStackTrace(); + } + } + + private static int calcCase(String line) { + String[] parts = line.split("" ""); + int n = Integer.parseInt(parts[0]); + int s = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + int[] g = new int[n]; + for (int i = 0; i < n; i++) { + g[i] = Integer.parseInt(parts[i+3]); + } + + int ok = 0; + int okWithSurprising = 0; + int notOk = 0; + + int limitOkWithoutSurprising = 3*p-2; + int limitOkWithSurprising = Math.max(3*p-4, 2); + + for (int score : g) { + if (score >= limitOkWithoutSurprising) { + ok++; + } else if (score >= limitOkWithSurprising) { + okWithSurprising++; + } else { + notOk++; + } + } + + return ok + Math.min(okWithSurprising, s); + } +} +" +A20473,"import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +public class GCIResult { + + public GCIResult() { + mResultList = new LinkedList(); + mCaseCounter = 1; + } + + public void addString(String res) + { + mResultList.add(res); + } + + public void addCase(String res) { + mResultList.add(""Case #"" + mCaseCounter + "": "" + res); + mCaseCounter++; + } + + public void clear() { + mResultList.clear(); + mCaseCounter = 1; + } + + public Iterator iterator() { + return mResultList.iterator(); + } + + private long mCaseCounter; + private List mResultList; +} +" +A21376,"import java.io.*; +import java.util.Scanner; + + +public class dance { + + + private static int T,S,p,N,current,upper,lower, count; + + + public static void main(String[] args) throws IOException { + + Scanner sc = new Scanner(System.in); + PrintWriter out = new PrintWriter(new FileWriter(""B-large.out"")); + T = sc.nextInt(); + + for(int i=1;i<=T;i++){ + + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + + count = 0; + + for(int j=1;j<=N;j++){ + + current = sc.nextInt(); + if (p<2){ + if(current>=p) + count++; + } else { + + upper = 3*p - 2; + lower = upper -2; + + if(current>=upper) + count++; + else if((S>0)&&(current>=lower)) + { + count++; + S--; + }}} + + out.println(""Case #""+i+"": ""+count); + } + + out.close(); + +} +} +" +A20474,"import java.util.*; +import java.io.*; + + + class dancing{ + + public static void main(String args[])throws FileNotFoundException + { + File myFile = new File(""B-large.in""); + PrintWriter resultFile = new PrintWriter(""B-large.out""); + Scanner fileRead = new Scanner(myFile); + int times = fileRead.nextInt(); + fileRead.nextLine(); + int guys; + int p; + int s; + int surp; + int me; + int data; + for(int i = 0; i < times; i++){ + guys = fileRead.nextInt(); + s = fileRead.nextInt(); + p = fileRead.nextInt(); + surp = 0; + for(int j = 0; j < guys; j++){ + data = fileRead.nextInt(); + me = data/3; + if(me >= p){ + surp++; + } + else if((me+1) >= p && (3*me + 1) <= data && data >= 1){ + surp++; + } + else if(s > 0){ + if((me+1) >= p && data > 1){ + s--; + surp++; + } + else if((me+2) >= p && (3*me + 2) <= data && data >= 2){ + s--; + surp++; + } + + } + + + }//end for loop + resultFile.println(""Case #"" + (i+1) + "": "" + surp); + }//end for loop + resultFile.close(); + }//end main + + +}//end class googlerese" +A21211,"import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Scanner; + +public class DancingWiththeGooglers { + final static String FILENAME = ""B-large""; + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new FileReader(""/home/workshop/Documents/"" + + FILENAME + "".in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter( + ""/home/workshop/Documents/"" + FILENAME + "".out"")); + int T = sc.nextInt(); + sc.nextLine(); + for (int ttt = 0; ttt < T; ttt++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + int s = S, count = 0; + for (int n = 0; n < N; n++) { + int t = sc.nextInt(); + switch (t % 3) { + case 0: + int z = t / 3; // z, z, z + if (z >= p) + count++; + else if (s > 0 && z + 1 >= p && z - 1 >= 0 && z + 1 <= 10) { + // z-1, z, z+1 (*) + count++; + s--; + } + break; + case 1: + int x = (t - 1) / 3; // x, x, x+1 + if (x + 1 >= p) + count++; + break; + case 2: + int y = (t - 2) / 3; // y, y+1, y+1 + if (y + 1 >= p) + count++; + else if (s > 0 && y + 2 >= p && y + 2 <= 10) { + // y, y, y+2 (*) + count++; + s--; + } + break; + } + } + + bw.write(""Case #"" + (ttt + 1) + "": "" + count); + bw.newLine(); + } + bw.close(); + sc.close(); + } + +} +" +A23052," + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Scanner; + +public class DancingWithGooglers { + + public static void main(String[] args) { + + try { + BufferedReader lector = new BufferedReader(new FileReader(args[0])); + int iterations = Integer.parseInt(lector.readLine()); + + + int numOfGooglers = 0; + int surprisingScores = 0; + int requestedPunctuation = 0; + int googlersWithPunct= 0; + int googlerPunctuation = 0; + int mediumPunctuation = 0; + int restPuntuaction = 0; + + String linea = null; + String[] values = null; + + for (int idx=1; idx <= iterations; idx++) { + //Obtenemos la línea actual o caso a trata + linea = lector.readLine(); + + //Obtenemos los valores de la línea actual + values = linea.split(""\\s""); + + //Obtenemos el número de bailadores + numOfGooglers = Integer.parseInt(values[0]); + //Obtenemos el número de puntuaciones sorprendentes + surprisingScores = Integer.parseInt(values[1]); + //Obtenemos la puntuación máxima + requestedPunctuation = Integer.parseInt(values[2]); + + //Para este caso ponemos los resultados a 0 + googlersWithPunct = 0; + + //Hacemos el tratamiento específico para cada bailador + for (int i=0; i= requestedPunctuation) { + //Determinamos si el concursante puede haber obtenido la nota mínima + mediumPunctuation = googlerPunctuation / 3; + restPuntuaction = googlerPunctuation % 3; + + //Si la media de puntuación es igual o mayor a la puntuación máxima ya sabemos que ese concursante lo cumple + if (mediumPunctuation >= requestedPunctuation) { + googlersWithPunct++; + } + else { + + if (surprisingScores == 0) { + //Si no puede haber resultados sorprendentes + + if (restPuntuaction != 0 && (mediumPunctuation + 1 == requestedPunctuation)) { + googlersWithPunct++; + } + } + else { + //Si aun puede haber sorprendentes + if (restPuntuaction == 1 && (mediumPunctuation + 1 == requestedPunctuation)) { + googlersWithPunct++; + } + else if (restPuntuaction == 2 && (mediumPunctuation + 2 >= requestedPunctuation)) { + googlersWithPunct++; + surprisingScores--; + } + else if (restPuntuaction == 0 && (mediumPunctuation + 1 >= requestedPunctuation)) { + googlersWithPunct++; + surprisingScores--; + } + } + } + } + } + + System.out.printf(""Case #%d: %s\n"", idx, googlersWithPunct); + + } + } + catch (FileNotFoundException ex) { + System.out.println(""Error:: Juego de pruebas no pasado por línea de comandos""); + } + catch (IOException ex) { + System.out.println(""Error:: Se ha producido un error en el procesamiento del archivo""); + } + } + +} +" +A22595,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Scanner; + +public class Dancing { + public static void main(String args[]) { + try{ + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""B-large.out"")); + + String line = in.readLine(); + int caseCount = Integer.parseInt(line); + + StringBuffer outputWriter = new StringBuffer(); + + int googlerCount, specialCount, bestCutoff, total, best, resultCount; + + for(int i = 1; i <= caseCount; i++){ + line = in.readLine(); + Scanner s = new Scanner(line); + googlerCount = s.nextInt(); + specialCount = s.nextInt(); + bestCutoff = s.nextInt(); + + resultCount = 0; + + for(int j = 0; j < googlerCount; j++){ + total = s.nextInt(); + best = (total + 2)/3; + + if(best >= bestCutoff) + resultCount++; + else if(best == (bestCutoff - 1) && total > 1 && total < 29 ){ + if(specialCount > 0){ + if( (total%3) != 1){//potential to specialize) + specialCount--; + resultCount++; + } + } + } + + //System.out.println(total + "" "" + best); + } + + outputWriter.append(""Case #"" + i + "": ""); + outputWriter.append(resultCount); + if(i != caseCount) + outputWriter.append(""\n""); + } + + out.write(outputWriter.toString()); + System.out.println(outputWriter.toString()); + + in.close(); + out.close(); + } catch(Exception e){ + //swallow the exception + } + } +} +" +A20141,"import java.util.Scanner; + +public class DanceWGoogle { + + public static int testcase(int S, int p, int[] arr) { + int over = 0; + int oneund = 0; + int temp; + for (int i = 0; i < arr.length; i++) { + temp=0; + if (arr[i] % 3 == 0) { + temp = arr[i] / 3; + } else { + temp = arr[i] / 3; + temp++; + } + if (temp >= p) + over++; + else if (temp == p - 1 && arr[i]>1) + oneund++; + } + over += Math.min(S, oneund); + return over; + } + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int T = scan.nextInt(); + int arr[]; + for (int i = 0; i < T; i++) { + arr = new int[scan.nextInt()]; + int S = scan.nextInt(); + int p = scan.nextInt(); + for (int a = 0; a < arr.length; a++) { + arr[a] = scan.nextInt(); + } + System.out.println(""Case #"" + (i + 1) + "": "" + testcase(S, p, arr)); + } + } +}" +A20801,"package practice.GC2012; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class Dancers { + + public static void main(String args[]) throws IOException { + Scanner s = new Scanner(new File(""Z:\\junkyard\\practice\\resources\\input2.txt"")); + FileWriter fo = new FileWriter(new File(""Z:\\junkyard\\practice\\resources\\output2.txt"")); + int num = s.nextInt(); + for(int i = 1; i<= num; i++) { + fo.write(""Case #"" + i + "": ""); + int nd = s.nextInt(); + int ns = s.nextInt(); + //System.out.println(""\n""+ i + "" - "" + nd + "" , ""+ ns); + + int p = s.nextInt(); + int alreadyhigh = Math.max(p, 0) + Math.max(p-1, 0) + Math.max(p-1, 0); + int surpriseScore = Math.max(p, 0) + Math.max(p-2, 0) + Math.max(p-2, 0); + int bestScorers = 0; + int canSurprise = 0; + for(int j = 1; j<=nd; j++) { + int score = s.nextInt(); + //System.out.print(score + "" - ""); + if (score == 0) { + continue; + } + if (score >= alreadyhigh) { + bestScorers ++; + } else if(score >= surpriseScore) { + canSurprise ++; + } + } + if (canSurprise < ns) { + bestScorers += canSurprise; + } else { + bestScorers += ns; + } + if(p==0) { + fo.write(nd + ""\n""); + } else { + fo.write(bestScorers + ""\n""); + } + } + fo.close(); + s.close(); + } +} +" +A20106,"import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStream; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + // public final static String IN_FILE = ""B.in""; + // public final static String OUT_FILE = ""B.out""; + + // public final static String IN_FILE = ""B-small-attempt0.in""; + // public final static String OUT_FILE = ""B-small-attempt0.out""; + + public final static String IN_FILE = ""B-large.in""; + public final static String OUT_FILE = ""B-large.out""; + + private static Scanner IN; + + public static void main(String[] args) throws Exception { + InputStream in = new FileInputStream(IN_FILE); + PrintWriter out = new PrintWriter(new FileWriter(OUT_FILE)); + IN = new Scanner(in); + + int T = IN.nextInt(); + for (int t = 1; t <= T; t++) { + int N = IN.nextInt(); + int S = IN.nextInt(); + int p = IN.nextInt(); + + int[] M = new int[N]; + for (int i = 0; i < N; i++) { + M[i] = IN.nextInt(); + } + + int minP = p >= 2 ? p * 3 - 4 : p; + int pp = p >= 1 ? p * 3 - 2 : p; + Arrays.sort(M); + int r = 0; + + // System.out.println(minP + "" "" + pp + "" "" + p); + + for (int i = 0; i < N; i++) { + if (M[i] < minP) + continue; + if (M[i] < pp) { + if (S <= 0) { + continue; + } + S--; + } + r++; + } + + out.println(""Case #"" + t + "": "" + r); + } + + out.flush(); + out.close(); + in.close(); + + } +} +" +A22296," + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + +//Using the Google Collections library. +public class B { + + public static void main(String [] args) throws IOException { + String inputFile = ""src/B-large.in""; + Scanner in = new Scanner(new File(inputFile)); + PrintStream out = new PrintStream(inputFile.substring(0, inputFile.length()-2)+""out""); + int cases = in.nextInt(); + for (int c = 1; c <= cases; c++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int noSurpriseThresh = p*3-2; + int surpriseThresh = p*3 - 4; + int count = 0; + int surpriseCount = 0; + for (int i = 0; i < n; i++) { + int cur = in.nextInt(); + if (cur == 0 && p > 0) { + continue; + } else if (cur >= noSurpriseThresh) { + count++; + } else if (cur >= surpriseThresh) { + surpriseCount++; + } + } + count += Math.min(s, surpriseCount); + out.print(""Case #""+c+"": ""+count); + out.println(); + } + out.close(); + } +} +" +A20022,"import java.util.ArrayList; + + +public class SpeakingInToungues { +private static String inputFile = ""C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Input.txt""; +private static String outputFile = ""C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Output.txt""; +public static void main(String[] args) { + InputReader ir = new InputReader(inputFile); + OutputWriter ow = new OutputWriter(outputFile); + ArrayList lines = ir.loadLines(); + //Given examples cover 25 chars and the one left out is q which is ideally mapped to the unused char z. + String normalText = ""aozq our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up""; + String googlereseText = ""yeqz ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv""; + StringBuffer sb = null; + for(int i=1;i=1 && t<=100) + { + for (int k = 0; k < t; k++) { + count=0; + + + String ip = sin.nextLine(); + + String[]tokens=ip.split("" ""); + + + n=Integer.parseInt(tokens[0]); + s=Integer.parseInt(tokens[1]); + p=Integer.parseInt(tokens[2]); + + if( (s>=0 && s<=n) && (p>=0 && p<=10) ) + { + int[] total=new int[n]; + + + for (int i = 0; i < n; i++) + { + total[i] = Integer.parseInt(tokens[i+3]); + } + + Comparator comparator=new PointComparator(); + PriorityQueue pq=new PriorityQueue(1, comparator); + + for (int i = 0; i < n; i++) + { + + int x=total[i]/3; + int r=total[i]%3; + if(x>=p) + count++; + else if(x<(p-2)) + continue; + else + { + //System.out.println(""enter ""+x+"" ""+(p-2)); + if(p-x==1) + { + Point temp=new Point(); + temp.q=x; + temp.r=r; + pq.add(temp); + } + else // p-x=2 + { + if(r==0) + continue; + else + { + Point temp=new Point(); + temp.q=x; + temp.r=r; + pq.add(temp); + } + + } + + } + //System.out.println(""hi ""+pq.size()); + + } + + + + while(pq.size()!=0) + { + Point temp=(Point)pq.remove(); + if(p-temp.q==1 && temp.q!=0) + { + if(temp.r>=1) + count++; + else + { + if(s!=0) + { + s--; + count++; + } + } + } + else if(p-temp.q==2) + { + if(s!=0 && (temp.q+temp.r)>=p) + { + s--; + count++; + } + } + + + } + + //System.out.println(p); + + result[j++]=count; + + } + } + + for (int i = 0; i < t; i++) + { + System.out.println(""Case #""+(i+1)+"": ""+result[i]); + } + } + + } + + + + /*Point x=new Point(); + x.q=8; + Point y=new Point(); + y.q=6; + Point z=new Point(); + z.q=7; + + pq.add(x); + pq.add(y); + pq.add(z); + */ + + + + + + +} + +class PointComparator implements Comparator +{ + @Override + public int compare(Point x, Point y) + { + // Assume neither string is null. Real code should + // probably be more robust + if (x.q < y.q) + { + return 1; + } + if (x.q > y.q) + { + return -1; + } + return 0; + } +} + + + +class Point +{ + int q,r; + + public int getQ() { + return q; + } + + public void setQ(int q) { + this.q = q; + } + + public int getR() { + return r; + } + + public void setR(int r) { + this.r = r; + } + + +} +" +A20438," +import java.util.Scanner; +import java.io.File; +import java.io.IOException; +import java.io.FileWriter; +import java.io.BufferedWriter; + +public class Dancers +{ + public static void main(String[] args) + { + try + { + Scanner s = new Scanner(new File(""dancers.in"")); + BufferedWriter w = new BufferedWriter(new FileWriter(new File(""dancers.out""))); + int numCases = s.nextInt(); + s.nextLine(); + + for(int n = 1;n <= numCases; n++) + { + int numGooglers = s.nextInt(); + int surprising = s.nextInt(); + int p = s.nextInt(); + int lowerBoundWithoutSurprising = (p * 3) - 2; + int lowerBoundWithSurprising = (p * 3) - 4; + + if(lowerBoundWithoutSurprising < p) + lowerBoundWithoutSurprising = p; + if(lowerBoundWithSurprising < p) + lowerBoundWithSurprising = p; + + int count = 0; + for(int m = 1; m <= numGooglers; m++) + { + int cur = s.nextInt(); + + if(cur >= lowerBoundWithoutSurprising) + count++; + else if(cur >= lowerBoundWithSurprising && surprising > 0) + { + count++; + surprising--; + } + } + w.write(""Case #"" + n + "": "" + count + ""\n""); + } + + w.flush(); + w.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + +}" +A21061,"package com.coding.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author madhava + * + */ +public class B { + + private static final int MAX_SCORE = 10; + private static final int MIN_SCORE = 0; + private static final int MAX_DIFFERENCE = 2; + private static int[][] dp = new int[100][101]; + static { + } + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(final String[] args) throws NumberFormatException, IOException { + + String inputFileName = args[0]; + BufferedReader reader = new BufferedReader(new FileReader(inputFileName)); + String outputFileName = inputFileName + ""_output""; + BufferedWriter writer = new BufferedWriter(new FileWriter(outputFileName)); + int noOfTestCases = getInteger(reader); + int loopCounter = 1; + while (noOfTestCases-- != 0) { + initialize(); + List input = getArray(reader); + int noOfGooglers = input.get(0); + int noOfSurprisingTriplets = input.get(1); + int bestResult = input.get(2); + List scores = new ArrayList(noOfGooglers); + for (int i = 0; i < noOfGooglers; i++) { + scores.add(input.get(i + 3)); + } + + int result = maxNoOfGooglers(scores, 0, noOfSurprisingTriplets, bestResult); + writer.write(""Case #"" + loopCounter + "": "" + result + ""\n""); + System.out.println(""Case #"" + loopCounter + "": "" + result); + loopCounter++; + } + writer.close(); + } + + /** + * + */ + private static void initialize() { + for (int i = 0; i < dp.length; i++) { + for (int j = 0; j < dp[i].length; j++) { + dp[i][j] = -1; + } + + } + + } + + /** + * @param scores + * @param index + * @param noOfSurprisingTriplets + * @param bestResult + * @return + */ + private static int maxNoOfGooglers(final List scores, final int index, + final int noOfSurprisingTriplets, final int bestResult) { + + if (noOfSurprisingTriplets < 0) { + return -(scores.size() + 1); + } + if (index == scores.size()) { + return noOfSurprisingTriplets == 0 ? 0 : -(scores.size() + 1); + } + int result = dp[index][noOfSurprisingTriplets]; + if (result != -1) { + return result; + } else { + result = 0; + for (int maxScore = MAX_SCORE; maxScore >= MIN_SCORE; maxScore--) { + + for (int i = 0; i <= MAX_DIFFERENCE; i++) { + int secondMaxScore = maxScore - i; + int thirdMaxScore = scores.get(index) - secondMaxScore - maxScore; + if ((thirdMaxScore > secondMaxScore) || (thirdMaxScore < 0) + || (maxScore - thirdMaxScore > MAX_DIFFERENCE)) { + continue; + } + result = Math.max( + maxNoOfGooglers(scores, index + 1, + noOfSurprisingTriplets - isTripletSuprising(maxScore, thirdMaxScore), + bestResult) + toInteger(maxScore >= bestResult), result); + } + } + dp[index][noOfSurprisingTriplets] = result; + return result; + } + } + + /** + * @param b + * @return + */ + private static int toInteger(final boolean b) { + if (b) { + return 1; + } else { + return 0; + } + + } + + /** + * @param maxScore + * @param thirdMaxScore + * @return + */ + private static Integer isTripletSuprising(final int maxScore, final int thirdMaxScore) { + return toInteger(maxScore - thirdMaxScore == MAX_DIFFERENCE); + + } + + /** + * @param reader + * @return + * @throws IOException + * @throws NumberFormatException + */ + private static int getInteger(final BufferedReader reader) throws NumberFormatException, IOException { + return Integer.parseInt(reader.readLine()); + } + + private static List getArray(final BufferedReader reader) throws IOException { + String[] line = reader.readLine().split("" ""); + List numbers = new ArrayList(); + for (String input : line) { + numbers.add(Integer.parseInt(input)); + } + return numbers; + } +} +" +A20751,"import java.io.*; +import java.util.*; +import static java.lang.Math.*; +import static java.util.Arrays.fill; +import static java.util.Arrays.binarySearch; +import static java.util.Arrays.sort; + +public class Main { + public static void main(String[] args) throws IOException { + long prevTime = System.currentTimeMillis(); + new Main().run(); + System.err.println(""Total time: "" + (System.currentTimeMillis() - prevTime) + "" ms""); + System.err.println(""Memory status: "" + memoryStatus()); + } + +// String inputFile = ""sample.txt""; +// String inputFile = ""input/B-small-attempt0.in""; + String inputFile = ""input/B-large.in""; + + String outputFile = ""output.txt""; + + void run() throws IOException { + in = new BufferedReader(new FileReader(inputFile)); + out = new PrintWriter(outputFile); + solve(); + out.close(); + } + + + void solve() throws IOException { + for (int testCase = 1, testCases = nextInt(); testCase <= testCases; testCase++) { + solve(testCase); + } + } + + void solve(int testCase) throws IOException { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] t = nextIntArray(n); + + int ans = 0; + + for (int i = 0; i < n; i++) { + if (good(t[i], p)) { + ans++; + } else if (s > 0 && canMakeGood(t[i], p)) { + ans++; + s--; + } + } + + out.println(""Case #"" + testCase + "": "" + ans); + } + + boolean good(int t, int p) { + return (t + 2) / 3 >= p; + } + + boolean canMakeGood(int t, int p) { + int add = min(2, t); + int rst = t - add; + return (rst / 3 + add) >= p; + } + + /*************************************************************** + * Input + **************************************************************/ + + BufferedReader in; + PrintWriter out; + StringTokenizer st = new StringTokenizer(""""); + + String nextToken() throws IOException { + while (!st.hasMoreTokens()) + st = new StringTokenizer(in.readLine()); + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + int[] nextIntArray(int size) throws IOException { + int[] ret = new int [size]; + for (int i = 0; i < size; i++) + ret[i] = nextInt(); + return ret; + } + + long[] nextLongArray(int size) throws IOException { + long[] ret = new long [size]; + for (int i = 0; i < size; i++) + ret[i] = nextLong(); + return ret; + } + + double[] nextDoubleArray(int size) throws IOException { + double[] ret = new double [size]; + for (int i = 0; i < size; i++) + ret[i] = nextDouble(); + return ret; + } + + String nextLine() throws IOException { + st = new StringTokenizer(""""); + return in.readLine(); + } + + boolean EOF() throws IOException { + while (!st.hasMoreTokens()) { + String s = in.readLine(); + if (s == null) + return true; + st = new StringTokenizer(s); + } + return false; + } + + /*************************************************************** + * Output + **************************************************************/ + void printRepeat(String s, int count) { + for (int i = 0; i < count; i++) + out.print(s); + } + + void printArray(int[] array) { + if (array == null || array.length == 0) + return; + for (int i = 0; i < array.length; i++) { + if (i > 0) out.print(' '); + out.print(array[i]); + } + out.println(); + } + + void printArray(long[] array) { + if (array == null || array.length == 0) + return; + for (int i = 0; i < array.length; i++) { + if (i > 0) out.print(' '); + out.print(array[i]); + } + out.println(); + } + + void printArray(double[] array) { + if (array == null || array.length == 0) + return; + for (int i = 0; i < array.length; i++) { + if (i > 0) out.print(' '); + out.print(array[i]); + } + out.println(); + } + + void printArray(double[] array, String spec) { + if (array == null || array.length == 0) + return; + for (int i = 0; i < array.length; i++) { + if (i > 0) out.print(' '); + out.printf(Locale.US, spec, array[i]); + } + out.println(); + } + + void printArray(Object[] array) { + if (array == null || array.length == 0) + return; + boolean blank = false; + for (Object x : array) { + if (blank) out.print(' '); else blank = true; + out.print(x); + } + out.println(); + } + + @SuppressWarnings(""rawtypes"") + void printCollection(Collection collection) { + if (collection == null || collection.isEmpty()) + return; + boolean blank = false; + for (Object x : collection) { + if (blank) out.print(' '); else blank = true; + out.print(x); + } + out.println(); + } + + /*************************************************************** + * Utility + **************************************************************/ + static String memoryStatus() { + return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + ""/"" + (Runtime.getRuntime().totalMemory() >> 20) + "" MB""; + } + + static void checkMemory() { + System.err.println(memoryStatus()); + } + + static long prevTimeStamp = Long.MIN_VALUE; + + static void updateTimer() { + prevTimeStamp = System.currentTimeMillis(); + } + + static long elapsedTime() { + return (System.currentTimeMillis() - prevTimeStamp); + } + + static void checkTimer() { + System.err.println(elapsedTime() + "" ms""); + } +} +" +A21377,"package gcj2012; + +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + long times = Integer.parseInt(sc.nextLine()); + for (long n = 0; n < times; n++) { + String b = sc.nextLine(); + String[] bb = b.split("" ""); + int N = Integer.parseInt(bb[0]); + int S = Integer.parseInt(bb[1]); + int P = Integer.parseInt(bb[2]); + Score[] score = new Score[N]; + for (int i = 0; i < N; i++) { + score[i] = new Score(Integer.parseInt(bb[3 + i])); + } + Arrays.sort(score); + int ret = 0; + for (int i = 0; i < N; i++) { + if (score[i].score[0] >= P) + ret++; + else { + if (S > 0) { + score[i].adjust(); + if (score[i].valid() && score[i].score[0]>=P) { + ret++; + S--; + } + + } + } + } + System.out.println(""Case #"" + (n + 1) + "": "" + ret); + } + } +} + +class Score implements Comparable { + int[] score = new int[3]; + + public Score(int s) { + int q = s / 3; + int r = s % 3; + Arrays.fill(score, q); + for (int i = 0; i < r; i++) { + score[i] += 1; + } + } + + public boolean valid() { + int max = Math.max(score[0], score[1]); + max = Math.max(max, score[2]); + int min = Math.min(score[0], score[1]); + min = Math.max(min, score[2]); + return max - min <= 2; + } + + public void adjust() { + if (score[0] == 0) + return; + if (score[2] > 0) { + score[0]++; + score[2]--; + return; + } + if (score[1] > 0) { + if (score[0] + 1 - score[2] <= 2 + && score[0] + 1 - (score[1] - 1) <= 2) { + score[0]++; + score[1]--; + } + } + } + + @Override + public int compareTo(Score s1) { + return s1.score[0] - this.score[0]; + } + +} +" +A20306,"package ProblemB; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class Common { + static String filename=""C:\\eclipse-jee-indigo-SR2-win32\\eclipse\\projects\\goole codejam 2012\\Qualification\\src\\ProblemB\\B-large.in""; + static BufferedReader br; + + static String output; + public static void main (String[] args) throws NumberFormatException, IOException{ + br = new BufferedReader(new FileReader(filename)); + BufferedWriter bw = new BufferedWriter(new FileWriter(""C:\\eclipse-jee-indigo-SR2-win32\\eclipse\\projects\\goole codejam 2012\\Qualification\\src\\ProblemB\\output.txt"")); + int n; + n = Integer.parseInt(br.readLine()); + String[] splitArr; + int[] input; + for (int i=1;i<=n;++i){ + splitArr=br.readLine().split("" ""); + input= new int [splitArr.length]; + for (int j=0; j< splitArr.length;++j){ + input[j] = Integer.parseInt(splitArr[j]); + } + bw.append(""Case #""+i+"": ""+process(input)+""\n""); + bw.flush(); + } + bw.close(); + } + + static int process (int[] input){ + int result=0; + int explicitSurprisesFound=0; + int limit=input[2]*3-4, surpriseLimit=limit+2; + boolean notException = 1 != input[2]; + for (int i=3;i input[i]){ + if(notException){ + if(explicitSurprisesFound < input[1]){ + ++explicitSurprisesFound; + ++result; + } + } + }else { + ++ result; + } + } + } + return result; + } +} +" +A20004,"package qualificationRound; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + +public class DancingWithTheGooglers { + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + Scanner in = new Scanner(new File(""D:/in.in"")); + PrintStream out = new PrintStream(new File(""D:/out.txt"")); + int round = in.nextInt(); + for (int z = 1; z <= round; z++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int count = 0; + for (int i = 0; i < n; i++) { + int tmp = in.nextInt(); + int mod = tmp % 3; + int avg = tmp / 3; + if (avg >= p) { + count++; + } else if (mod == 2) { + if (avg == p - 1) { + count++; + } else if (avg == p - 2 && s != 0) { + count++; + s--; + } + } else if (mod == 1) { + count += (avg == p - 1)? 1: 0; + } else if (mod == 0 && s != 0 && avg != 0) { + if (avg == p - 1) { + count++; + s--; + } + } + } + out.println(""Case #"" + z + "": "" + count); + } + in.close(); + out.close(); + } +} +" +A21728,"import java.io.*; +import java.util.*; + +public class core { + public static void main(String[] argv) throws Exception { + + String inputFile = argv[0]; + Scanner scan = null; + FileReader fR = null; + BufferedReader bR = null; + + int T; + + + try{ + + fR = new FileReader(inputFile); + bR = new BufferedReader(fR); + + + + T = Integer.parseInt(bR.readLine()); + + for(int i = 0; i <= T; i++){ + + String[] temp = (bR.readLine()).split("" ""); + int[] input = new int[temp.length]; + for(int j =0; j < temp.length; j++){ + input[j] = Integer.parseInt(temp[j]); + + } + + int N = input[0]; + int S = input[1]; + int p = input[2]; + int[] division = new int[N]; + int[] remainder = new int[N]; + int out=0; + + + for(int k = 3; k < input.length; k++){ + + division[k-3] = input[k]/3; + remainder[k-3] = input[k]-(division[k-3]*3); + //System.out.println("""" + division[k-3] + "" : "" + remainder[k-3] ); + } + + //System.out.println(); + + for(int l = 0; l < division.length; l++){ + if(division[l]>=p){ + out++; + //System.out.println(""Did "" + l); + } else if ((division[l] == (p-1)) && (remainder[l]>0) ){ + out++; + //System.out.println(""Did 1 "" + l); + } else if ((division[l] == (p-2)) && (remainder[l]==2) && S > 0){ + out++; + S--; + //System.out.println(""Did 2 "" + l); + } else if (division[l] == p-1 && remainder[l] == 0 && S > 0 && division[l] > 0){ + out++; + S--; + //System.out.println(""Did 3 "" + l); + } + + } + + int caseIndex = i+1; + System.out.println(""Case #"" + caseIndex + "": "" + out); + + } + + } catch(Exception e){} + } +} +" +A22388,"package contest.googlejam; + +import java.io.File; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import contest.ContestProblem; +import contest.Input; + +// http://code.google.com/codejam/africa_arabia/contests.html + +public class Qualifier2012 { + public static void main(String[] args) { + ContestProblem problem = codeJam2012_Qualification_B; + File folder = new File(""C:\\Users\\Admin\\Desktop\\GoogleJam Tests\\2012\\Qualification Round\\""); + + File test = new File(folder, ""test.txt""); + File small = new File(folder, ""B-small-attempt0.in""); + File large = new File(folder, ""B-large.in""); + + // ContestProblem.runProblem(problem.setInputFile(test).calcOutputFromInput()); + // ContestProblem.runProblem(problem.setInputFile(small).calcOutputFromInput()); + ContestProblem.runProblem(problem.setInputFile(large).calcOutputFromInput()); + } + + // Problem B. Dancing With the Googlers + static ContestProblem codeJam2012_Qualification_B = new ContestProblem() { + final int maxDiff = 2; + + @Override + public void parseInput(Input in, PrintWriter out) { + int cases = in.readInt(); + for (int caseNum = 1; caseNum <= cases; caseNum++) { + List input = in.readIntList(); + int numGooglers = input.get(0); + int numSurprises = input.get(1); + int p = input.get(2); + List totalPoints = input.subList(3, 3 + numGooglers); + + int goodScore = 0; + int onlySurprises = 0; + for (Integer total : totalPoints) { + int avg = total / 3; + int normal = 0; + int surprises = 0; + for (int a = avg - maxDiff; a <= avg + maxDiff; a++) { + for (int b = avg - maxDiff; b <= avg + maxDiff; b++) { + for (int c = avg - maxDiff; c <= avg + maxDiff; c++) { + if (a + b + c != total) { + // System.out.format(""%d + %d + %d != %d%n"", a, b, c, total); + continue; + } + + int min = Math.min(Math.min(a, b), c); + int max = Math.max(Math.max(a, b), c); + + if (min < 0) + continue; + + if (max >= p) { + int diff = max - min; + if (diff == 2) { + surprises++; + System.out.format(""%d + %d + %d = %d (Surprise)%n"", a, b, c, total); + } else if (diff == 0 || diff == 1) { + normal++; + System.out.format(""%d + %d + %d = %d%n"", a, b, c, total); + } else { + // System.out.format(""diff (%d + %d + %d) > %d%n"", a, b, c, maxDiff); + } + } else { + // System.out.format(""max (%d + %d + %d) < %d%n"", a, b, c, p); + } + } + } + } + + if (normal == 0 && surprises > 0) { + onlySurprises++; + System.out.format("" %d is onlySurprise%n"", total); + } else if (normal > 0) { + goodScore++; + } else { + System.out.format("" %d failed%n"", total); + } + + } + + System.out.format(""goodScores = %d%n"", goodScore); + System.out.format(""onlySurprises = %d%n"", onlySurprises); + System.out.format(""numSurprises = %d%n"", numSurprises); + int maxPossible = goodScore; + if (numSurprises > onlySurprises) { + maxPossible += onlySurprises; + } else { + maxPossible += Math.min(numSurprises, onlySurprises); + } + + out.print(String.format(""Case #%d: %s%n"", caseNum, maxPossible)); + } + } + + }; + + // Problem A. Speaking in Tongues + static ContestProblem codeJam2012_Qualification_A = new ContestProblem() { + Map charMap = new HashMap<>(); + + @Override + public void parseInput(Input in, PrintWriter out) { + charMap.put(' ', ' '); + charMap.put('a', 'y'); + charMap.put('b', 'h'); + charMap.put('c', 'e'); + charMap.put('d', 's'); + charMap.put('e', 'o'); + charMap.put('f', 'c'); + charMap.put('g', 'v'); + charMap.put('h', 'x'); + charMap.put('i', 'd'); + charMap.put('j', 'u'); + charMap.put('k', 'i'); + charMap.put('l', 'g'); + charMap.put('m', 'l'); + charMap.put('n', 'b'); + charMap.put('o', 'k'); + charMap.put('p', 'r'); + charMap.put('q', 'z'); + charMap.put('r', 't'); + charMap.put('s', 'n'); + charMap.put('t', 'w'); + charMap.put('u', 'j'); + charMap.put('v', 'p'); + charMap.put('w', 'f'); + charMap.put('x', 'm'); + charMap.put('y', 'a'); + charMap.put('z', 'q'); + + int cases = in.readInt(); + for (int caseNum = 1; caseNum <= cases; caseNum++) { + String input = in.readStr(); + String output = """"; + + for (int i = 0; i < input.length(); i++) { + output += charMap.get(input.charAt(i)); + } + + out.print(String.format(""Case #%d: %s%n"", caseNum, output)); + } + } + + }; +} +" +A21626,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Hashtable; + + + +public class test1 { + ArrayList result=new ArrayList(); + + Hashtable h=new Hashtable(); + int count =0; + + public void read_file() throws Exception { + FileReader g = new FileReader(""B-large.in""); + BufferedReader br = new BufferedReader(g); + int No_of_Cases = Integer.parseInt(br.readLine()); + String s; + for(int i=0;i=min_target) + { + if(temp >=max_target) + { + counta++; + }else + { + countb++; + } + } + } + } + if(countb 0) { + while (scanner.hasNext()) { + String[] rowValues = scanner.next().trim().split("" ""); + + int totalGooglers = Integer.parseInt(rowValues[0]); + // System.out.println(""Total Googlers : "" + totalGooglers); + int totalSuprisingCases = Integer.parseInt(rowValues[1]); + // System.out.println(""Total Surprising Cases : "" + + // totalSuprisingCases); + + int averageScore = Integer.parseInt(rowValues[2]); + // System.out.println(""Total Success Cases : "" + + // averageScore); + // System.out.println(""Total Length : "" + rowValues.length); + + int[] totalMarks = new int[totalGooglers]; + int j = 0; + for (int i = 3; i < rowValues.length; i++) { + totalMarks[j] = Integer.parseInt(rowValues[i].trim()); + // System.out.println(""Value Put : "" + totalMarks[j]); + j++; + } + int successCase = getSuccessCase(totalGooglers, + averageScore, totalSuprisingCases, totalMarks); + System.out.println(""Case #"" + k++ + "": "" + successCase); + } + + } + } + scanner.close(); + } + + public boolean doNormalCase(int totalScore, int averageScore) { + boolean success = false; + int X3value = averageScore * 3; + if (totalScore >= X3value) { + success = true; + } else if ((totalScore >= X3value - 1) || (totalScore >= X3value + 1)) { + success = true; + } else if ((totalScore >= X3value - 2) || (totalScore >= X3value + 2)) { + success = true; + } else { + success = false; + } + return success; + } + + public boolean doSurprisingCase(int totalScore, int averageScore) { + boolean success = false; + int X3value = averageScore * 3; + // System.out.println(""Total Score : "" + totalScore); + // System.out.println(""Average Score : "" + X3value); + if (((totalScore >= X3value - 3) || (totalScore >= X3value + 3)) + && totalScore > averageScore) { + success = true; + } else if (((totalScore >= X3value - 4) || (totalScore >= X3value + 4)) + && totalScore > averageScore) { + success = true; + } else { + success = false; + } + return success; + } + + public int getSuccessCase(int totalCses, int averageScore, + int surprisingCase, int[] caseValues) { + int totalSuccess = 0; + for (int i = 0; i < totalCses; i++) { + // System.out.println(""----------------------Value Put : "" + + // totalCses); + boolean normalCaseSuccess = doNormalCase(caseValues[i], + averageScore); + if (!normalCaseSuccess) { + if (surprisingCase > 0) { + boolean surprisingCaseSuccess = doSurprisingCase( + caseValues[i], averageScore); + if (surprisingCaseSuccess) { + // System.out.println(""Surprising Success..."" + + // caseValues[i]); + totalSuccess++; + surprisingCase--; + } + } + } else { + totalSuccess++; + } + } + return totalSuccess; + } + +} +" +A22822,"package mgg.utils; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +/** + * @author manolo + * @date 13/04/12 + */ +public class CombinatoryUtils { + + public static List findAddingCombination(int total, + List listOfNumbers) { + + ArrayList solution = new ArrayList(); + + for (int i = 0; i < listOfNumbers.size(); i++){ + for (int j = 0; j < listOfNumbers.size(); j++){ + + if( (i != j) && + (listOfNumbers.get(i) + listOfNumbers.get(j) == total) ){ + solution.add(listOfNumbers.get(i)); + solution.add(listOfNumbers.get(j)); + return solution; + } + + } + } + return null; + } + + public static List findAddingCombinationIndices(int total, + List listOfNumbers) { + + ArrayList solution = new ArrayList(); + + for (int i = 0; i < listOfNumbers.size(); i++){ + for (int j = 0; j < listOfNumbers.size(); j++){ + + if( (i != j) && + (listOfNumbers.get(i) + listOfNumbers.get(j) == total) ){ + solution.add(i); + solution.add(j); + return solution; + } + + } + } + return null; + } + + public static List findAddingCombinationIndicesBase1(int total, + List listOfNumbers) { + + ArrayList solution = new ArrayList(); + + for (int i = 0; i < listOfNumbers.size(); i++){ + for (int j = 0; j < listOfNumbers.size(); j++){ + + if( (i != j) && + (listOfNumbers.get(i) + listOfNumbers.get(j) == total) ){ + solution.add(i+1); + solution.add(j+1); + return solution; + } + + } + } + return null; + } + + public static List possibleTriplets(int score) { + List listOfTriplets = new ArrayList(); + + for(Triplet t : allPossibleTriplets){ + if(t.sum() == score){ + listOfTriplets.add(t); + } + } + + return listOfTriplets; + } + + private final static List allPossibleTriplets = allPossibleTriplets(); + + private static List allPossibleTriplets() { + + HashSet set = new HashSet(); + +// int cont = 0; + for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= 10; j++) { + if(Math.abs(i-j) <= 2){ + for (int k = 0; k <= 10; k++) { + if((Math.abs(i-k) <= 2) && (Math.abs(j-k) <= 2)){ +// cont++; +// System.out.println(""("" + i + "", "" + j + "", "" + k + "")\t\tcont = "" + cont);7 + set.add(new Triplet(i, j, k)); + + } + } + } + } + } + + return new ArrayList(set); + + } + +} +" +A22279,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +import java.util.StringTokenizer; + + +public class codeJam2 { + + public static void main(String[] args) throws FileNotFoundException { + + //System.out.print(""input.txt""); + Scanner input = new Scanner(new File(""input.txt"")); + String Do = input.nextLine(); + String line; + for( int i = 0 ; i < Integer.parseInt(Do) ;++i){ + line = input.nextLine(); + StringTokenizer tokens = new StringTokenizer(line); + int people = Integer.parseInt(tokens.nextToken()); + int suprice = Integer.parseInt(tokens.nextToken()); + int high = Integer.parseInt(tokens.nextToken()); + possible p = new possible(suprice, high); + for( int j = 0; j < people ; ++j ){ + p.canDo(Integer.parseInt(tokens.nextToken())); + } + System.out.print(""Case #""); + System.out.print(i+1); + System.out.print("": ""); + System.out.println(p.count); + + + }//outer for + + + } + +} +" +A21413," +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.Observable; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + + +/** + * + * @author dante + */ +public class dancers { + + + public dancers(String filename) + { + + base_size=0; + + init_database(); + contests = new int[100][6]; + + + parsing(filename); + + } + + + public void init_database() + { + int min,max; + + database= new int[30*27+1][5]; + + for(int num=30;num>2;num=num-1) + { + min= (int)Math.ceil(((double)num-3)/3); + max= (int)Math.ceil(((double)num+3)/3); + + for(int i=max; i>=min; i--) + { + for(int j=max; j>=min; j--) + { + for(int k=max; k>=min; k--) + { + if(((i+j+k)== num) && is_acceptable(i,j,k)) + { + put_database(i,j,k); + + } + } + } + } + + //2 + database[base_size][0]=2; + database[base_size][1]=1; + database[base_size][2]=1; + database[base_size][3]=0; + database[base_size][4]=is_surprising(1,1,0); + base_size++; + //1 + database[base_size][0]=1; + database[base_size][1]=1; + database[base_size][2]=0; + database[base_size][3]=0; + database[base_size][4]=is_surprising(1,0,0); + base_size++; + //0 + database[base_size][0]=0; + database[base_size][1]=0; + database[base_size][2]=0; + database[base_size][3]=0; + database[base_size][4]=is_surprising(0,0,0); + base_size++; + + + } + + + + + } + + void put_database(int i, int j, int k) + { + database[base_size][0]=i+j+k; + database[base_size][1]=i; + database[base_size][2]=j; + database[base_size][3]=k; + database[base_size][4]=is_surprising(i,j,k); + base_size++; + } + + int is_surprising(int i, int j, int k) + { + if(Math.abs(i-j)== 2) + { + return 1; + } + else if(Math.abs(i-k)==2) + { + return 1; + } + else if(Math.abs(j-k)==2) + { + return 1; + } + + return 0; + } + + boolean is_acceptable(int i, int j, int k) + { + if(Math.abs(i-j) > 2) + { + return false; + } + else if( Math.abs(j-k) > 2) + { + return false; + } + else if(Math.abs(i-k) > 2) + { + return false; + } + + return true; + + } + + + + void parsing(String filename) + { + + + //String filename = args[1]; + String strLine = null; + String [] temp= new String [150]; + String delimeter="" ""; + int num_contestants; + int best,index,found_index=0; + // int i; + // Open the file that is the first + // command line parameter + try{ + + + final FileInputStream stream = new FileInputStream(filename); + // Get the object of DataInputStream + final DataInputStream dataInputStream = new DataInputStream(stream); + final BufferedReader reader = new BufferedReader(new InputStreamReader(dataInputStream)); + + + PrintWriter out = new PrintWriter(new FileWriter(""Blarge"")); + // out.print(""Hello ""); + // out.println(""world""); + // out.close(); + //Read File Line By Line + int surp_events,my_surp_events; + int diafora=0,ptr_change; + + if((strLine = reader.readLine()) != null) + { + System.out.println(""Num_cases: ""+ strLine); + } + + + //ena reader.readLine gia to prwto noumero + int my_case=0; + while ((strLine = reader.readLine()) != null) { + + my_case++; + + temp=strLine.split(delimeter); + + num_contestants=Integer.parseInt(temp[0]); + surp_events=Integer.parseInt(temp[1]); + best=Integer.parseInt(temp[2]); + + for(int i=0;i= my_surp_events) + { + count_best(best,num_contestants);//apo reading + out.println(""Case #""+my_case+ "": "" + count_best(best,num_contestants)); + //print + } + else + { + diafora=my_surp_events-surp_events; + index=0; + while(diafora>0 && index=best) + { + ptr_change=find_other(contests[index][0],best,1); //1 for want best + } + else + { + ptr_change=find_other(contests[index][0],best,0); + } + + if(ptr_change!=-1) + { + contests[index][1]=database[ptr_change][1]; + contests[index][2]=database[ptr_change][2]; + contests[index][3]=database[ptr_change][3]; + contests[index][4]=database[ptr_change][4]; + contests[index][5]=find_best(index); + + diafora--; + } + + + } + index++; + + } //end while + + + + my_surp_events=count_surp(num_contestants); + if(surp_events >= my_surp_events) + { + count_best(best,num_contestants);//apo reading + + out.println(""Case #""+my_case+ "": "" + count_best(best,num_contestants)); + //print + } + else //sencond parsing + { + index=0; + ptr_change=-1; + diafora=my_surp_events-surp_events; + while(diafora>0 && index=best || j>=best || k>=best) + return true; + + return false; + } + + int find_best(int ptr_change) + { + int total_max=-1; + + for(int i=1;i<4;i++) + { + if(total_max=best) + { + count++; + } + } + return count; + } + + int count_surp(int num_cont) + { + int count=0; + + for(int i=0;i=1){ + res++; + } + } + }else{ + for(int j=0;j=lim1){ + res++; + }else if ( points[j]>=lim2 && S>0 ){ + res++; + S--; + } + } + } + + // produce output + //System.out.println(""Case #""+(i+1)+"": "" + res ); + bw.write(""Case #""+(i+1)+"": "" + res ); + bw.newLine(); + } + + bw.close(); + br.close(); + + + }catch(Exception ex){ + ex.printStackTrace(); + } + } + +} +" +A22932," +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class Dance { + + Scanner in; + BufferedWriter out; + + Dance(String input, String output) throws Exception { + in = new Scanner(new File(input)); + FileWriter fstream = new FileWriter(output); + out = new BufferedWriter(fstream); + } + + public void solveAll() throws IOException { + int T = in.nextInt(); + int N, S, P; + + for (int test = 1; test <= T; test++) { + N = in.nextInt(); + S = in.nextInt(); + P = in.nextInt(); + int[] t = new int[N]; + for(int i = 0; i < N; i++) { + t[i] = in.nextInt(); + } + out.write(""Case #"" + test + "": "" + solve(N, S, P, t)); + out.newLine(); + } + + } + + public int solve(int N, int S, int P, int[] t) { + int count = 0; + for(int i = 0; i < N; i++) { + if(t[i] % 3 == 0) { + if(t[i]/3 >= P) { + count++; + } else { + if(S > 0 && t[i] != 0 && t[i]/3 + 1 >= P) { + count++; + S--; + } + } + } else if(t[i] % 3 == 1) { + if(t[i]/3 + 1 >= P) { + count ++; + } + } else { + if(t[i]/3 + 1 >= P) { + count++; + } else { + if(S > 0 && t[i]/3 + 2 >= P) { + count++; + S--; + } + } + } + } + return count; + } + + + public void close() throws IOException { + in.close(); + out.close(); + } + + public static void main(String[] args) throws Exception { + Dance pb = new Dance(""input.txt"", ""output.txt""); + + pb.solveAll(); + + pb.close(); + } +} +" +A23067,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.HashMap; + + +public class Recycle { + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""output.txt"")); + + String line = """"; + line = br.readLine(); + int number = Integer.valueOf(line); + for(int i = 1; i<= number; i++){ + line = br.readLine(); + String[] tokens = line.split("" ""); + int result = 0; + int n = Integer.valueOf(tokens[0]); + int surprising = Integer.valueOf(tokens[1]); + int p = Integer.valueOf(tokens[2]); + if(p == 0){ + result = n; + } + else{ + for(int a = 1;a<=n;a++){ + int score = Integer.valueOf(tokens[2+a]); + int d = score/3; + if(score == 0) + continue; + if(d >=p){ + result++; + } + else{ + int m = score%3; + if((m == 1||m==2) && d+1 == p) + result++; + else if(m == 0 && d+1 == p && surprising !=0){ + result++; + surprising--; + } + if(m == 2&& d+2 ==p &&surprising !=0){ + result++; + surprising--; + } + } + } + } + System.out.println(result); + bw.append(""Case #""+i+"": ""+result); + bw.newLine(); + } + br.close(); + bw.close(); + } +} +" +A21698,"import java.io.*; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.ListIterator; +import java.util.Queue; +import java.util.StringTokenizer; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Vector; + +public class Solution { + + void solve() throws Exception { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int coolany = 0, coolpp = 0; + for (int i = 0; i < n; i++) { + int t = nextInt(); + if (t >= p + Math.max(0, p - 1) + Math.max(0, p - 1)) coolany++; else + if (t >= p + Math.max(0, p - 2) + Math.max(0, p - 2)) coolpp++; + } + out.println(coolany + Math.min(s, coolpp)); + } + + public static void main(String[] args) { + new Solution().run(); + } + + public void run() { + try { +// in = new BufferedReader(new InputStreamReader(System.in)); +// out = new PrintWriter(System.out); + in = new BufferedReader(new FileReader(new File(""input.txt""))); + out = new PrintWriter(""output.txt""); + int t = nextInt(); + for (int q = 1; q <= t; q++) { + out.print(""Case #"" + q + "": ""); solve(); + } + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } finally { + out.close(); + } + } + + String nextToken() throws Exception { + while (st == null || !st.hasMoreTokens()) { + String s = in.readLine(); + if (s == null) return null; + st = new StringTokenizer(s); + } + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + BufferedReader in; + PrintWriter out; + StringTokenizer st; + +}" +A22849,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.StringTokenizer; +import java.util.TreeSet; +import java.util.Set; +import java.util.ArrayList; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.Stack; + +public class TaskB implements Runnable { + class Solver implements Runnable { + int testId; + boolean failed = false; + + Solver(int testId) { + this.testId = testId; + } + + int N; + int s; + int p; + int[] t; + private void readInput() { + N=nextInt(); + s=nextInt(); + p=nextInt(); + t=new int[N]; + for(int i=0;i=mmin)) + { + for(int j=0;j<=s;j++) + { + ndp[j]=dp[j]+1; + } + } + mmin=Math.max(0, p-2)*2; + if((temp>=mmin)&&(t[i]<=28)) + { + for(int j=0;j<=s-1;j++) + { + ndp[j+1]=Math.max(dp[j]+1,ndp[j+1]); + } + } + dp=ndp; + } + res=dp[s]; + return; + } + + + private void printOutput() { + if (failed) { + writer.println(""BAD!!!""); + System.out.println(""BAD!!!""); + } else { + writer.print(""Case #""); + writer.print(testId+1); + writer.print("": ""); + writer.println(res); + } + } + } + + private void solveSequential() { + int numTests = nextInt(); + for (int testId = 0; testId < numTests; ++testId) { + Solver solver = new Solver(testId); + solver.readInput(); + solver.run(); + solver.printOutput(); + } + } + + private void solveParallel() { + int numTests = nextInt(); + ExecutorService executor = Executors.newFixedThreadPool(2); + Solver[] solver = new Solver[numTests]; + for (int testId = 0; testId < numTests; ++testId) { + solver[testId] = new Solver(testId); + solver[testId].readInput(); + } + Future[] res = new Future[numTests]; + for (int testId = 0; testId < numTests; ++testId) { + res[testId] = executor.submit(new Thread(solver[testId])); + } + for (int testId = 0; testId < numTests; ++testId) { + try { + res[testId].get(); + } catch (InterruptedException e) { + solver[testId].failed = true; + } catch (ExecutionException e) { + solver[testId].failed = true; + } + } + for (int testId = 0; testId < numTests; ++testId) { + // writer.print(""Case #""); + // writer.print(testId+1); + // writer.print("": ""); + solver[testId].printOutput(); + } + executor.shutdown(); + } + + static final String TASK_ID = ""taskB""; + + public static void main(String[] args) { + new TaskB().run(); + } + + BufferedReader reader; + StringTokenizer tokenizer = null; + PrintWriter writer; + + public void run() { + try { + long now = System.currentTimeMillis(); + reader = new BufferedReader(new FileReader(TASK_ID + "".txt"")); + writer = new PrintWriter(TASK_ID + "".out""); + solveParallel(); + reader.close(); + writer.close(); + System.out.println(System.currentTimeMillis() - now + ""ms""); + } catch (Exception e) { + e.printStackTrace(); + } + } + + int nextInt() { + return Integer.parseInt(nextToken()); + } + + double nextDouble() { + return Double.parseDouble(nextToken()); + } + + long nextLong() { + return Long.parseLong(nextToken()); + } + String nextLine() + { + String res; + try { + res = reader.readLine(); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + return res; + } + + String nextToken() { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + try { + tokenizer = new StringTokenizer(reader.readLine()); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + return tokenizer.nextToken(); + } +} + + + +" +A20440,"import java.util.Scanner; + + +public class SolutionDancingWithGooglers { + + static int[] notes; + static int surprising; + + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + int cases = sc.nextInt(); + + for(int i = 0; i < cases; i++){ + + int googlers = sc.nextInt(); + + surprising = sc.nextInt(); + + int p = sc.nextInt(); + + int counter = 0; + + for(int j = 0; j < googlers; j++){ + int triplet = sc.nextInt(); + int[] scores = new int[3]; + + scores[0] = triplet/3; + triplet = triplet - triplet/3; + scores[1] = triplet/2; + triplet = triplet - triplet/2; + scores[2] = triplet; + + counter = counter + verify(scores, surprising, p); + } + + System.out.println(""Case #"" + (i+1) + "": "" + counter); + + } + + + + } + + public static int verify(int[] v, int count, int comp){ + //System.out.println(""count: ""+count); + if(good(v, comp)){ + return 1; + }else if(count != 0 && (v[0] > 0 && v[2] < 10)){ + if(v[0] != v[1] || v[2] != v[1] + 1){ + v = mod(v); + if(possible(v) && good(v, comp)){ + surprising = count - 1; + return 1; + }else return 0; + }else return 0; + }else return 0; + + } + + public static boolean good(int[] v, int comp){ + + for(int i = 0; i < v.length; i++){ + if(v[i] >= comp){ + return true; + } + } + return false; + + } + + public static boolean possible(int[] v){ + + if(Math.abs(v[0] - v[1]) > 2) return false; + else if(Math.abs(v[1] - v[2]) > 2) return false; + else if(Math.abs(v[2] - v[0]) > 2) return false; + else return true; + + } + + public static int[] mod(int[] v){ + + + if(v[0] == v[1] && v[1] == v[2]){ + v[0] = v[0] - 1; + v[2] = v[2] + 1; + + return v; + }else{ + v[1] = v[1] - 1; + v[2] = v[2] + 1; + return v; + } + + } + + + +} +" +A20605," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ +/** + * + * @author Charles + */ +public class DancingWithGooglers +{ + + static final String FILE_NAME = ""B-large""; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException + { + ArrayList values = readFile(FILE_NAME + "".in""); + int count = 1; + + PrintWriter outFile = new PrintWriter(new File(FILE_NAME + "".out"")); + for (String line : values) + { + String output = processAlgorithm(line, count++); + System.out.println(output); + outFile.println(output); + } + outFile.close(); + } + + /** + * Reads the CodeJam files and returns the input as a List of String. + * + * @param fileName The name of the file to be read + * @return the list containing the contents of the file. + */ + public static ArrayList readFile(String fileName) + { + ArrayList results = new ArrayList(); + try + { + Scanner inFile = new Scanner(new File(fileName)); + int numberOfLines = Integer.parseInt(inFile.nextLine()); + while (inFile.hasNextLine()) + { + results.add(inFile.nextLine()); + } + + if (numberOfLines != results.size()) + { + System.err.println(""File size does not match...""); + System.exit(0); + } + + } catch (FileNotFoundException ex) + { + System.err.println(""File not found...""); + System.exit(0); + } + return results; + } + + private static String processAlgorithm(String line, int caseNumber) + { + StringBuilder result = new StringBuilder(""Case #"" + caseNumber + "": ""); + + Scanner scan = new Scanner(line); + + int numberOfDancers = scan.nextInt(); + int numberOfSuprises = scan.nextInt(); + int highestScore = scan.nextInt(); + + int usedSuprises = 0; + int count = 0; + + Dancer current; + for (int index = 0; index < numberOfDancers; index++) + { + current = new Dancer(scan.nextInt()); + if (current.highScoreWithOutSuprise >= highestScore) + { + count++; + } + else if (current.highScoreWithSuprise >= highestScore + && usedSuprises < numberOfSuprises) + { + usedSuprises++; + count++; + } + } + + result.append(count); + return result.toString(); + } +} + +class Dancer +{ + + int highScoreWithSuprise; + int highScoreWithOutSuprise; + + public Dancer(int score) + { + highScoreWithOutSuprise = highScoreWithSuprise = score / 3; + int mod = score % 3; + if (score > 0) + { + switch (mod) + { + case 0: + highScoreWithSuprise += 1; + break; + case 1: + highScoreWithOutSuprise += 1; + highScoreWithSuprise += 1; + break; + case 2: + highScoreWithOutSuprise += 1; + highScoreWithSuprise += 2; + break; + } + } + } +} +" +A21442,"import java.util.Comparator; +import java.util.PriorityQueue; +import java.util.Scanner; + + +public class GCJ_2 { + + /** + * @param args + */ + public static void main(String[] args) { +Scanner scan = new Scanner(System.in); + + int T = scan.nextInt(); + scan.nextLine(); + + int nCase = 1; + while (T-- > 0) { + + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + + PriorityQueue queue = new PriorityQueue(10, new Comparator() { + + @Override + public int compare(Integer o1, Integer o2) { + + return o2.compareTo(o1); + } + + }); + for (int i = 0; i < N; i++) { + queue.add(scan.nextInt()); + } + + int output = 0; + while (!queue.isEmpty() && S >= 0) { + Integer i = queue.poll(); + //System.out.println(i); + int r = i % 3; + int q = i / 3; + + if (r != 0) q++; + + //dont need to be surprising + if (q >= p) { + output++; + continue; + } + + if (S == 0) break; //dont need continue processing + if (q == 0) continue; + //needs to use surprising + S--; + if (r == 0) //everybody is equal + { + q++; + } else if (r == 1) + { + //cant add + } else { + q++; + } + + if (q >= p) output++; + + } + + + scan.nextLine(); + + System.out.println(""Case #"" + (nCase++) + "": "" + output); + } + + } + +} +" +A22083,"import java.util.StringTokenizer; + + +public class DancingWithTheGooglers { + public static int Solve(String q) { + StringTokenizer st = new StringTokenizer(q, "" ""); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int t; + int d; + int r; + int ans = 0; + + while(st.hasMoreTokens()) { + t = Integer.parseInt(st.nextToken()); + d = t / 3; + r = t % 3; + + if(p - d <= 0) + ans++; + else if(p - d == 1) { + if(r != 0) + ans++; + else if(s > 0 && r == 0 && t != 0) { + s--; + ans++; + } + } + else if(p - d == 2 && s > 0 && r == 2) { + ans++; + s--; + } + } + + return ans; + } +} +" +A20491,"/** + * + */ +package hu.herba.codejam.cj2012.qualification; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +import hu.herba.codejam.AbstractCodeJamBase; + +/** + * Dancing with the Googlers + * + * @author csorbazoli + */ +public class ProblemB extends AbstractCodeJamBase { + + public static void main(String[] args) { + new ProblemB(args); + } + + int T; // number of test case + + public ProblemB(String[] args) { + super(args, AbstractCodeJamBase.READER_TYPE); + } + + /* + * (non-Javadoc) + * + * @see hu.herba.codejam.AbstractCodeJamBase#process(java.io.BufferedReader, + * java.io.PrintWriter) + */ + @Override + protected void process(BufferedReader reader, PrintWriter pw) throws IOException, IllegalArgumentException { + // The first line of the input gives the number of test cases, T. T test + // cases follow, one per line. + this.T = this.readInt(reader, ""Number of cases""); + int[] items; + int result = 0; + int N, S, p; + int surp, smallest, cur, diff; + for (int i = 1; i <= this.T; i++) { + items = this.readIntArray(reader, ""N, S, p and N integers""); + // The first integer will be N, the number of Googlers, + // and the second integer will be S, the number of surprising + // triplets of scores. + // The third integer will be p, as described above. + // Next will be N integers ti: the total points of the Googlers. + if ((items.length > 0) && (items.length == 3 + items[0])) { + // * TEST */System.out.println(""Case #"" + i + "": input = "" + + // Arrays.toString(items)); + N = items[0]; + S = items[1]; + p = items[2]; + // For each test case, output one line containing ""Case #x: y"", + // where x is the case number (starting from 1) and y is the + // maximum number of Googlers who could have had a best result + // of greater than or equal to p. + surp = result = 0; + for (int j = 0; j < N; j++) { + cur = items[3 + j]; + if (cur >= p) { + // smallest result + smallest = (cur - p) / 2; + diff = p - smallest; + if (diff <= 2) { + if (diff == 2) { // only when suprising + surp++; + // * TEST */System.out.println("" "" + cur + + // "" -> SUPP""); + } else { // even if not surprising + // * TEST */System.out.println("" "" + cur + + // "" -> MAX""); + result++; + } + } // else not possible + } + } + // at most S googlers may have p points amoung surp + // * TEST */System.out.println("" result = "" + result + "" + "" + + // Math.min(surp, S)); + result += Math.min(surp, S); + pw.println(""Case #"" + i + "": "" + result); + } else { + System.out.println(""Test case "" + i + "" INVALID: input line should contain N, S, p and N integers"" + Arrays.toString(items)); + } + } + } +} +" +A20591,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + + +public class GCJ2 { + + public GCJ2() { + } + + public static void main(String[] args) { + GCJ2 gcj = new GCJ2(); + + try { + BufferedReader br = new BufferedReader(new FileReader(new File(""input.txt""))); + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""output.txt""))); + String firstLine = br.readLine(); + int lineNum = Integer.parseInt(firstLine); + for (int i=0; i= 0 ? (maxScore-1) : 0; + if (s >= min + min + maxScore) { + result++; + } else if (surpriseNum > 0) { + min = (maxScore-2) >= 0 ? (maxScore-2) : 0; + if (s >= min + min + maxScore) { + result++; + surpriseNum--; + } + } + } + bw.write(""Case #"" + (i+1) + "": "" + result); + if (i != (lineNum-1)) + bw.newLine(); + } + bw.flush(); + bw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A20620,"package net.anzix.learn.codejam.qr12; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + private InputStream input; + private PrintStream output; + + public DancingWithTheGooglers() { + + } + + public DancingWithTheGooglers(InputStream input, PrintStream output) { + super(); + this.input = input; + this.output = output; + } + + public DancingWithTheGooglers(File inputFile, File outputFile) + throws Exception { + this.input = new FileInputStream(inputFile); + output = new PrintStream(outputFile); + + } + + public void run() throws Exception { + Scanner scanner = new Scanner(input); + int lines = scanner.nextInt(); + for (int i = 0; i < lines; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + List maxs = new ArrayList(); + for (int j = 0; j < n; j++) { + maxs.add(scanner.nextInt()); + } + output.println(""Case #"" + (i + 1) + "": "" + + getNoOfBigger(maxs, s, p)); + } + output.close(); + } + + public static void main(String[] args) { + try { + new DancingWithTheGooglers(new File(args[0]), new File(args[1])) + .run(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public int getNoOfBigger(List maxPoints, int noOfSuprisings, + int limit) { + int no = 0; + for (Integer point : maxPoints) { + if (point == 0) { + if (limit == 0) { + no++; + } + } else { + int ns = maxNo(point, false); + int s = maxNo(point, true); + if (noOfSuprisings < 1 && ns >= limit) { + no++; + } + if (noOfSuprisings > 0) { + if (ns < limit && s >= limit) { + noOfSuprisings--; + no++; + } else if (ns >= limit) { + no++; + } + + } + } + + } + + return no; + + } + + public int maxNo(int sumPoint, boolean suprising) { + int c = sumPoint % 3; + if (suprising) { + switch (c) { + case 0: + return (sumPoint + 3) / 3; + case 1: + return (sumPoint + 2) / 3; + case 2: + return (sumPoint + 4) / 3; + } + } else { + switch (c) { + case 0: + return (sumPoint + 0) / 3; + case 1: + return (sumPoint + 2) / 3; + case 2: + return (sumPoint + 1) / 3; + } + } + throw new IllegalArgumentException(); + } +} +" +A21674,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; + +/** + * + */ + +/** + * @author Bryan + * + */ +public class problemB { + + /** + * @param args + */ + public static void main(String[] args) { + String filePath = ""/Users/Bryan/Documents/CodeJam/ProblemB/B-large.in""; + boolean isFirstLine = true; + int counter = 1; + StringBuffer resultString = new StringBuffer(); + + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(filePath); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + // Read File Line By Line + while ((strLine = br.readLine()) != null) { + if (isFirstLine){ + isFirstLine = false; + continue; + } + int maxNoGoogler = 0; + + resultString.append(""Case #"" + counter + "": ""); + String[] numberList = strLine.split("" ""); + int noOfGoogler = Integer.parseInt(numberList[0]); + int noOfSuprise = Integer.parseInt(numberList[1]); + int individualTarget = Integer.parseInt(numberList[2]); +// ArrayList totalScoreList = new ArrayList(); + for ( int a = 3; a < numberList.length; a++){ +// totalScoreList.add(Integer.parseInt(numberList[a])); + if ( Integer.parseInt(numberList[a]) >= miniTotal(noOfGoogler, individualTarget) ){ + maxNoGoogler++; + }else if ( noOfSuprise > 0 && Integer.parseInt(numberList[a]) >= miniTotalWithSuprise(noOfGoogler, individualTarget) ){ + noOfSuprise--; + maxNoGoogler++; + } + } + + resultString.append(maxNoGoogler); + resultString.append(""\n""); + counter++; + } + // Close the input stream + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + writeStringToFile(resultString.toString()); + + + } + + private static int miniTotalWithSuprise(int noOfGoogler, int individualTarget){ + int min = (3 * individualTarget) - (2 * (3 - 1)); + + if ( min < individualTarget){ + return individualTarget; + } + + return min; + } + + private static int miniTotal(int noOfGoogler, int individualTarget){ + int min = (3 * individualTarget) - (3 - 1); + if ( min < individualTarget){ + return individualTarget; + } + return min; + } + + private static void writeStringToFile(String outputString) { + try { + // Create file + FileWriter fstream = new FileWriter(""/Users/Bryan/Documents/CodeJam/ProblemB/output.txt""); + BufferedWriter out = new BufferedWriter(fstream); + out.write(outputString); + // Close the output stream + out.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A21284,"package Round1; + +/* + ID: kevinle7 + LANG: JAVA + TASK: dancing + */ +import java.io.*; +import java.util.*; + +class dancing +{ + public static void main(String[] args) throws IOException + { + BufferedReader f = new BufferedReader(new FileReader(""dancing.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""dancing.out""))); + int t = Integer.parseInt(f.readLine()); + for (int i = 0 ; i < t; i++) + { + StringTokenizer st = new StringTokenizer(f.readLine()); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int ans = 0; + int poss = 0; + int goodscore = 3*p - 2; + int okayscore = 3*p - 4; + if (p == 1) + okayscore = 1; + for (int j = 0; j < n; j++) + { + int score = Integer.parseInt(st.nextToken()); + if (score >= goodscore) + ans++; + else if (score >= okayscore) + poss++; + } + if (poss < s) + ans += poss; + else + ans += s; + out.println(""Case #"" + (i+1) + "": "" + ans); + } + out.close(); + System.exit(0); + } + +}" +A20231,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class dancing { + public static void main(String[] args) + { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int T; + String input; + try { + input = reader.readLine(); + T = Integer.parseInt(input); + int counter = 1; + while (T-->0) + { + int N,S,P; + List scores = new ArrayList(); + Map frequency = new HashMap(); + for(int i=0;i<31;i++) + { + frequency.put(i,0); + } + input = reader.readLine(); + String[] in = input.split("" ""); + N = Integer.parseInt(in[0]); + S= Integer.parseInt(in[1]); + P=Integer.parseInt(in[2]); + int count = 3; + while(count=1) + { + upperbound = P+2*(P-1); + } + else + { + upperbound = 0; + } + int lowerBound; + if(P>=2) + { + lowerBound = P+2*(P-2); + } + else + { + lowerBound =-1; + } + int sure = 0; + List possibleScores = new ArrayList(frequency.keySet()); + Collections.sort(possibleScores); + for(int i=upperbound;i<31;i++) + { + sure += frequency.get(i); + } + int maxPossibleSurprises=0; + if(lowerBound != -1) + { + for(int i=lowerBound;i getIntList(String listString) { + String[] listArray = listString.split("" ""); + List list = new ArrayList(); + for (String str : listArray) { + list.add(Integer.parseInt(str)); + } + return list; + } + + public static int getInt(String string) { + return Integer.parseInt(string); + } + + public static List getLongList(String listString) { + String[] listArray = listString.split("" ""); + List list = new ArrayList(); + for (String str : listArray) { + list.add(Long.parseLong(str)); + } + return list; + } +} +" +A20771,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; + + +public class Main_Dance { + public static void main(String[] args)throws Exception { + File _=new File(""dance.in""); + BufferedReader br=_.exists()? new BufferedReader(new FileReader(_)):new BufferedReader(new InputStreamReader(System.in)); + int t=Integer.parseInt(br.readLine().trim()); + int n,s,p; + ArrayList scores; + StringTokenizer st; + int k,surprising,total; + + for (int i = 1; i <= t; i++) { + scores=new ArrayList(); + st=new StringTokenizer(br.readLine()); + n=Integer.parseInt(st.nextToken()); + s=Integer.parseInt(st.nextToken()); + p=Integer.parseInt(st.nextToken()); + k=p+2*Math.max(0, p-2); + + + for (int j = 0; j < n; j++) { + scores.add(Integer.parseInt(st.nextToken())); + } + total=0; + surprising=0; + Collections.sort(scores); + for (int j = 0; j < scores.size(); j++) { + if(scores.get(j)>=k) + total++; + if((p!=1&&p!=0)&&(scores.get(j)==p+2*(p-2)||scores.get(j)==p+2*(p-2)+1)) + surprising++; + } + + if(surprising>s) + total-=surprising-s; + + + System.out.println(""Case #""+i+"": ""+total); + } + + } +} +" +A21204,"// library In.java at http://introcs.cs.princeton.edu/stdlib/stdlib.jar + +public class PB { + public static void main (String[] args) { + int t, n, s, p; + + int num, mod, quot; + int maybe; + int counter; + int max; + + In in = new In(""input.txt""); + t = Integer.parseInt(in.readLine()); + + int i = 1; + // get input + while (in.hasNextLine()) { + maybe = 0; + counter = 0; + n = in.readInt(); + s = in.readInt(); + p = in.readInt(); + + for (int j = 0; j < n; j++) { + num = in.readInt(); + quot = num / 3; + mod = num % 3; + + if (mod == 1) { + if (quot + 1 >= p) { + counter++; + continue; + } + if (3 * p - 2 <= num) { + maybe++; + continue; + } + } + if (mod == 0){ + if (quot >= p) { + counter++; + continue; + } + if (3 * p - 3 <= num && num != 0) { + maybe++; + continue; + } + } + if (mod == 2) { + if (quot + 1 >= p) { + counter++; + continue; + } + if (3 * p - 4 <= num) { + maybe++; + continue; + } + } + } + max = Math.min(s, maybe); + + System.out.print(""Case #"" + i + "": "" + (max + counter) + ""\n""); + i++; + } + } +} +" +A20049,"package QualificationRound.dancingwiththegooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Scoring { + private List inputLines = new ArrayList(); + private List outputLines = new ArrayList(); + private static final String INPUT_FILE_NAME = ""B-large.in""; + private static final String OUTPUT_FILE_NAME = ""output.txt""; + + private List cases = new ArrayList(); + + public static void main(String[] args) { + Scoring s = new Scoring(); + s.readLines(); + s.parseLines(); + s.generateOutput(); + s.outputLines(); + } + + + private void readLines() { + try { + BufferedReader reader = new BufferedReader(new FileReader(INPUT_FILE_NAME)); + + String line = reader.readLine(); + + line = reader.readLine(); + while (line != null) { + inputLines.add(line); + line = reader.readLine(); + } + + reader.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + private void parseLines() { + for (String inputLine : inputLines) { + int readNumbers = 0; + SingleCase singleCase = new SingleCase(); + String[] split = inputLine.split("" ""); + for (String s : split) { + switch (readNumbers) { + case 0: + singleCase.numberOfGooglers = Integer.parseInt(s); + break; + case 1: + singleCase.numberOfSurprises = Integer.parseInt(s); + break; + case 2: + singleCase.minBestResult = Integer.parseInt(s); + break; + default: + singleCase.scores.add(Integer.parseInt(s)); + } + readNumbers++; + } + cases.add(singleCase); + } + } + + + private void generateOutput() { + int caseNumber = 1; + for (SingleCase singleCase : cases) { + outputLines.add(getOutputPrefix(caseNumber++) + singleCase.getResult()); + } + } + + + private void outputLines() { + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE_NAME, false)); + + for (String line : outputLines) { + writer.write(line); + if (!line.equals(outputLines.get(outputLines.size() - 1))) { + writer.write(""\n""); + } + } + + writer.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + private class SingleCase { + @SuppressWarnings(""unused"") //unnecessary. Just use number of scores + private int numberOfGooglers = 0; + private int numberOfSurprises = 0; + private int minBestResult = 0; + private List scores = new ArrayList(); + + private int getResult() { + int clearPasses = 0; + int potentialSurprises = 0; + + //Minimum clear pass is x + x-1 + x-1 where x is the minBestResult + int minForClearPass = (minBestResult * 3) - 2; + //Minimum surprise pass is x + x-2 + x-2 where x is the minBestResult + int minForSurprisePass = (minBestResult * 3) - 4; + if (minForSurprisePass < 1) { + if (minBestResult == 0) { + minForSurprisePass = 0; + } + else { + minForSurprisePass = 1; + } + } + + for (int score : scores) { + if (score >= minForClearPass) { + clearPasses++; + } + else if (score >= minForSurprisePass) { + potentialSurprises++; + } + } + + return clearPasses + (Math.min(potentialSurprises, numberOfSurprises)); + } + } + + private String getOutputPrefix(int number) { + return ""Case #"" + number + "": ""; + } +} +" +A22145,"import java.io.FileInputStream; +import java.io.DataInputStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.FileWriter; +import java.io.BufferedWriter; +//import java.util.ArrayList; + + +public class Min_Scale_Prod { + public static void main(String[] args){ + try{ + String inputFileName = ""B-large.in""; + String outputFileName = ""B-large.out""; + FileInputStream fstream = new FileInputStream(inputFileName); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + FileWriter foutstream = new FileWriter(outputFileName); + BufferedWriter out = new BufferedWriter(foutstream); + String strLine; + Helper help = new Helper(); + int counter = 0; + while ((strLine = br.readLine()) != null) { + //Print the content to file + if (counter == 0) { + ; + } else { + help.printResult(out, strLine, counter); + } + counter +=1; + } + //Close the output stream + out.close(); + }catch (Exception e){//Catch exception if any + System.err.println(e); + } + } +} +" +A22660,"import java.util.Scanner; + +public class Surprising { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int cases = scan.nextInt(); + for (int trial = 1; trial <= cases; trial++) { + System.out.print(""Case #"" + trial + "": ""); + int googlers = scan.nextInt(); + int surprising = scan.nextInt(); + int p = scan.nextInt(); + int count = 0; + for (int i = 0; i < googlers; i++) { + int totScore = scan.nextInt(); + if ((totScore + 2) / 3 >= p) + count++; + else if (Math.min((totScore + 4) / 3, totScore) >= p && surprising > 0) { + surprising--; + count++; + } + } + System.out.println(count); + } + } +} +" +A21332,"/* + Copyright (c) 2005, Corey Goldberg + + StopWatch.java is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. +*/ + + +public class StopWatch { + + private long startTime = 0; + private long stopTime = 0; + private boolean running = false; + + + public void start() { + this.startTime = System.currentTimeMillis(); + this.running = true; + } + + + public void stop() { + this.stopTime = System.currentTimeMillis(); + this.running = false; + } + + + //elaspsed time in milliseconds + public long getElapsedTime() { + long elapsed; + if (running) { + elapsed = (System.currentTimeMillis() - startTime); + } + else { + elapsed = (stopTime - startTime); + } + return elapsed; + } + + + //elaspsed time in seconds + public long getElapsedTimeSecs() { + long elapsed; + if (running) { + elapsed = ((System.currentTimeMillis() - startTime) / 1000); + } + else { + elapsed = ((stopTime - startTime) / 1000); + } + return elapsed; + } + + + + +// //sample usage +// public static void main(String[] args) { +// StopWatch s = new StopWatch(); +// s.start(); +// //code you want to time goes here +// s.stop(); +// System.out.println(""elapsed time in milliseconds: "" + s.getElapsedTime()); +// } +}" +A22277,"import java.io.File; +import java.util.Scanner; + +public class Googlers { + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(""resource/B-large.in"")); + int T = sc.nextInt(); + int i = 1; + while (i<=T) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int t[] = new int[N]; + for(int j=0; j=0? (p-2): 0) + 1) { + //Never happen + continue; + } + else if(t[i] >= 3 * p - 2){ + //Not surprising + counter++; + } + else { + //Surprising + if(s>0){ + s--; + counter++; + } + } + } + return counter; + } +} +" +A20849,"package com.nigel.codejam; + + + + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + + +public class GoogleDance { + +public static int[][] gudjedScores(int a){ + + int div=a/3; + int[][] tempArray=new int[1][3]; + + + if(a==0) { tempArray[0][0]=0; tempArray[0][1]=0; tempArray[0][2]=0; + + } + else {tempArray[0][0]=div; tempArray[0][1]=div; tempArray[0][2]=div; + + if(tempArray[0][0]+tempArray[0][1]+tempArray[0][2]==a){} else {tempArray[0][0]=tempArray[0][0]+1;} + if(tempArray[0][0]+tempArray[0][1]+tempArray[0][2]==a){} else {tempArray[0][1]=tempArray[0][1]+1;} + } + + + return tempArray; +} + +public static int[][] supriseArray(int a,int b,int[][] c){ + + int surprisesAllowed=a; + int bestNo=b; + int [][] googlerScores=c; + + if(surprisesAllowed==0 || bestNo==0 || bestNo==1) return googlerScores; + else{ + int surprisesDone=0; + + for(int i=0;i=bestNo) {flag=1;} + else if(tempArray[0][1]>=bestNo) {flag=1;} + else if(tempArray[0][2]>=bestNo) {flag=1;} + + else if(flag==0){ + + tempArray[0][0]=tempArray[0][0]+1; tempArray[0][1]=tempArray[0][1]-1; + if(tempArray[0][0]-tempArray[0][1]>2 || tempArray[0][0]-tempArray[0][1]<-2 || tempArray[0][0]-tempArray[0][2]>2 || tempArray[0][0]-tempArray[0][2]<-2){ + + tempArray[0][0]=tempArray[0][0]-1; tempArray[0][1]=tempArray[0][1]+1; + } + else{ + + if(tempArray[0][0]==bestNo) + {flag=1;} + + else {tempArray[0][0]=tempArray[0][0]-1; tempArray[0][1]=tempArray[0][1]+1; } + + } + + if(flag==0){ + + tempArray[0][0]=tempArray[0][0]+1; tempArray[0][1]=tempArray[0][2]-1; + if(tempArray[0][0]-tempArray[0][1]>2 || tempArray[0][0]-tempArray[0][1]<-2 || tempArray[0][0]-tempArray[0][2]>2 || tempArray[0][0]-tempArray[0][2]<-2){ + + tempArray[0][0]=tempArray[0][0]-1; tempArray[0][2]=tempArray[0][2]+1; + } + else{ + + if(tempArray[0][0]==bestNo) + flag=1; + + else {tempArray[0][0]=tempArray[0][0]-1; tempArray[0][2]=tempArray[0][2]+1;} + + } + } + + + if(flag==0){ + + tempArray[0][0]=tempArray[0][0]+2; tempArray[0][1]=tempArray[0][1]-1; tempArray[0][2]=tempArray[0][2]-1; + if(tempArray[0][0]-tempArray[0][1]>2 || tempArray[0][0]-tempArray[0][1]<-2 || tempArray[0][0]-tempArray[0][2]>2 || tempArray[0][0]-tempArray[0][2]<-2){ + + tempArray[0][0]=tempArray[0][0]-2;tempArray[0][1]=tempArray[0][1]+1; tempArray[0][2]=tempArray[0][2]+1; + } + else{ + + if(tempArray[0][0]==bestNo) + flag=1; + + else{ tempArray[0][0]=tempArray[0][0]-2; tempArray[0][1]=tempArray[0][1]+1; tempArray[0][2]=tempArray[0][2]+1;} + + } + } + //---------------------------------- + +if(flag==0){ + + tempArray[0][1]=tempArray[0][1]+1; tempArray[0][0]=tempArray[0][0]-1; + if(tempArray[0][1]-tempArray[0][0]>2 || tempArray[0][1]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ + + tempArray[0][1]=tempArray[0][1]-1;tempArray[0][0]=tempArray[0][0]+1; + } + else{ + + if(tempArray[0][1]==bestNo) + flag=1; + + else {tempArray[0][1]=tempArray[0][1]-1;tempArray[0][0]=tempArray[0][0]+1;} + + } + } + +if(flag==0){ + + tempArray[0][1]=tempArray[0][1]+1; tempArray[0][2]=tempArray[0][2]-1; + if(tempArray[0][1]-tempArray[0][0]>2 || tempArray[0][1]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ + + tempArray[0][1]=tempArray[0][1]-1;tempArray[0][2]=tempArray[0][2]+1; + } + else{ + + if(tempArray[0][1]==bestNo) + flag=1; + + else {tempArray[0][1]=tempArray[0][1]-1;tempArray[0][2]=tempArray[0][2]+1;} + + } + } + +if(flag==0){ + + tempArray[0][1]=tempArray[0][1]+2; tempArray[0][0]=tempArray[0][0]-1;tempArray[0][2]=tempArray[0][2]-1; + if(tempArray[0][1]-tempArray[0][0]>2 || tempArray[0][1]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ + + tempArray[0][1]=tempArray[0][1]-2; tempArray[0][0]=tempArray[0][0]+1;tempArray[0][2]=tempArray[0][2]+1; + } + else{ + + if(tempArray[0][1]==bestNo) + flag=1; + + else {tempArray[0][1]=tempArray[0][1]-2;tempArray[0][0]=tempArray[0][0]+1;tempArray[0][2]=tempArray[0][2]+1;} + + } + } +//---------------------------------- +if(flag==0){ + + tempArray[0][2]=tempArray[0][2]+1; tempArray[0][0]=tempArray[0][0]-1; + if(tempArray[0][2]-tempArray[0][0]>2 || tempArray[0][2]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ + + tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1; + } + else{ + + if(tempArray[0][2]==bestNo) + flag=1; + + else {tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1;} + + } + } + +if(flag==0){ + + tempArray[0][2]=tempArray[0][2]+1; tempArray[0][1]=tempArray[0][1]-1; + if(tempArray[0][2]-tempArray[0][0]>2 || tempArray[0][2]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ + + tempArray[0][2]=tempArray[0][2]-1;tempArray[0][1]=tempArray[0][1]+1; + } + else{ + + if(tempArray[0][2]==bestNo) + flag=1; + + else {tempArray[0][2]=tempArray[0][2]-1;tempArray[0][1]=tempArray[0][1]+1;} + + } + } + +if(flag==0){ + + tempArray[0][2]=tempArray[0][2]+1;tempArray[0][0]=tempArray[0][0]-1;tempArray[0][1]=tempArray[0][1]-1; + if(tempArray[0][2]-tempArray[0][0]>2 || tempArray[0][2]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ + + tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1;tempArray[0][1]=tempArray[0][1]+1; + } + else{ + + if(tempArray[0][2]==bestNo) + flag=1; + + else {tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1;tempArray[0][1]=tempArray[0][1]+1;} + + } + } + + +if(flag==1) surprisesDone=surprisesDone+1; + + } + + googlerScores[i][0]=tempArray[0][0]; + googlerScores[i][1]=tempArray[0][1]; + googlerScores[i][2]=tempArray[0][2]; + + if(surprisesDone==surprisesAllowed){return googlerScores;} + } + + + + } + + return googlerScores; +} + + +public static int checkResult(){ + + return 0; + +} + public static void main(String args[]) throws Exception{ + BufferedReader reader = new BufferedReader(new FileReader(new File(""E:/DOWNLOADS/B-small-attempt3.in""))); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""E:/DOWNLOADS/B-small-attempt3.out""))); + String line = reader.readLine(); + int k = Integer.parseInt(line); + int count=1; + for(int i = 0 ; i < k ; i ++){ + line = reader.readLine(); + // System.out.println(""11""); + //line=line.replaceAll("" "",""""); + String[] newLine=line.split("" ""); + //char[] cArray = line.toCharArray(); + + + + System.out.println(count); + count++; + int noOfGooglers=Integer.parseInt(newLine[0]); System.out.println(""noOfGooglers ""+noOfGooglers); + int surprises=Integer.parseInt(newLine[1]); + int bestNo=Integer.parseInt(newLine[2]); + int[] totalScores=new int[noOfGooglers]; + + for(int j=3,n=0;j=bestNo || googlerScores[h][0]>=bestNo || googlerScores[h][0]>=bestNo ){ + + result++; + + } + } + + + + int Case=i+1; + writer.write(""Case #"" + Case + "": ""); + writer.write(Integer.toString(result)); + if(Case==k){} else{writer.write(""\n""); } + + + } + reader.close(); + writer.close(); + } + +} + +" +A20416,"package Parser; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + +public class MyReader { + public String[] taskArray; + public int currentString; + + public MyReader(String fileName) { + // TODO Auto-generated constructor stub + String taskString = readString(fileName); + if (taskString.indexOf('\r') == -1) { + taskArray = taskString.split(""\n""); + } else { + taskArray = taskString.split(""\r\n""); + } + currentString = 0; + } + + public String readString(String fileName) { + + StringBuffer buffer = new StringBuffer(); + try { + File file = new File(fileName); + FileInputStream fis = new FileInputStream(file); + InputStreamReader isr = new InputStreamReader(fis); + Reader in = new BufferedReader(isr); + int ch; + while ((ch = in.read()) > -1) { + buffer.append((char) ch); + } + in.close(); + return buffer.toString(); + } catch (IOException e) { + return """"; + } + } + + public String read() { + return taskArray[currentString++]; + } +} +" +A20930,"import java.awt.List; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Vector; + +import javax.swing.JFrame; +import javax.swing.JTextField; + +public class Test{ + public static void main(String[] args) { + try{ + BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); + String T = buff.readLine(); + for(int q=0;q list = new Vector(); + for(int a:inp_arr){ + if(a%3 == 0){ + int special_arr[] = new int[3]; + special_arr[0] = a/3-1; + special_arr[1] = a/3; + special_arr[2] = a/3+1; + int normal_arr[] = new int[3]; + normal_arr[0] = a/3; + normal_arr[1] = a/3; + normal_arr[2] = a/3; + data d = new data(); + d.set_normal_arr(normal_arr); + d.set_special_arr(special_arr); + list.add(d); + + } + else if(a%3 == 1){ + int special_arr[] = new int[3]; + special_arr[0] = a/3-1; + special_arr[1] = a/3+1; + special_arr[2] = a/3+1; + int normal_arr[] = new int[3]; + normal_arr[0] = a/3; + normal_arr[1] = a/3; + normal_arr[2] = a/3+1; + data d = new data(); + d.set_normal_arr(normal_arr); + d.set_special_arr(special_arr); + list.add(d); + + } + else{ + int special_arr[] = new int[3]; + special_arr[0] = a/3; + special_arr[1] = a/3; + special_arr[2] = a/3+2; + int normal_arr[] = new int[3]; + normal_arr[0] = a/3; + normal_arr[1] = a/3+1; + normal_arr[2] = a/3+1; + data d = new data(); + d.set_normal_arr(normal_arr); + d.set_special_arr(special_arr); + list.add(d); + + } + } + Iterator iter = list.iterator(); + int count =0; + while(iter.hasNext()){ + data d = (data)iter.next(); + System.out.println(""p:"" + p+""s:""+s_int+"" "" + d.normal_arr[0] + "" "" +d.normal_arr[1] + "" "" + d.normal_arr[2] + "" "" +d.special_arr[0] + "" "" +d.special_arr[1] + "" "" +d.special_arr[2]); + if(p <= d.get_largest_normal()){ + //TODO count++ + count++; + } + else{ + if(s_int!=0){ + if(p <= d.get_largest_special()){ + //TODO count++ and s_int-- + count++; + s_int--; + } + else{ + //System.out.println(""Untrue for both special as well as normal""); + } + } + } + } + System.out.println(""Case #"" + (q+1) + "": "" + count); + } + }catch(Exception e){System.out.println(e);} + } +} +class data{ + int special_arr[]; + int normal_arr[]; + void set_special_arr(int arr[]){special_arr = arr;} + void set_normal_arr(int arr[]){normal_arr = arr;} + int[] get_special_arr(){return special_arr;} + int[] get_normal_arr(){return normal_arr;} + + int get_largest_special(){if(special_arr[0] < 0 || special_arr[2]>10)return -1;return special_arr[2];} + + int get_largest_normal(){if(normal_arr[0] < 0 || normal_arr[2]>10)return -1;return normal_arr[2];} + +}" +A21157,"package problemb; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + + int T = 1; + String G = """"; + String[] inputs; + BufferedReader reader; + + reader = new BufferedReader(new InputStreamReader(System.in)); + + try { + T = Integer.parseInt(reader.readLine()); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + StringBuffer buffer = new StringBuffer(); + for (int X = 1; X <= T; X++) { + try { + G = reader.readLine(); + inputs = G.split("" ""); + int N = Integer.parseInt(inputs[0]); + int S = Integer.parseInt(inputs[1]); + int p = Integer.parseInt(inputs[2]); + int[] t; + if (inputs.length - 3 > N) { + t = new int[N]; + } else { + t = new int[inputs.length - 3]; + } + for (int i = 0; i < t.length; i++) { + t[i] = Integer.parseInt(inputs[i + 3]); + } + int surprizing = 0; + Arrays.sort(t); + int result = 0; + for (int j = t.length - 1; j >= 0; j--) { + if(p==0){ + result = t.length; + break; + } + int dev = t[j] / 3; + int mod = t[j] % 3; + if (dev >= p) { + result++; + continue; + } + if (mod == 1 && dev + 1 >= p) { + result++; + continue; + } + if (mod == 2 && dev + 1 >= p) { + result++; + continue; + } + if (mod == 2 && dev + 2 >= p && surprizing < S) { + surprizing++; + result++; + continue; + } + if (mod == 0 && dev > 0 && dev + 1 >= p && surprizing < S) { + surprizing++; + result++; + continue; + } + } + + buffer.append(""Case #"").append(X).append("": "").append(result) + .append(""\r\n""); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + System.out.println(buffer.toString()); + } + +} +" +A22513,"import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class DancingWithTheGooglers { + public static void main(String[] args) { + try { + System.setOut(new PrintStream(new FileOutputStream(""output.txt""))); + Scanner scanner = new Scanner(new File(args[0])); + int testsNum = scanner.nextInt(); + + String solution; + for (int i=1; i<=testsNum; i++) { + solution = solve(scanner); + System.out.println(""Case #""+i+"": ""+solution); + System.err.println(""Case #""+i+"": ""+solution); + } + } catch (Exception e) {e.printStackTrace();} + } + + private static String solve(Scanner scanner) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + + int score; + int ret = 0; + for (int i=0; i= 3*p-2) ret++; + else if (score >= 3*p-4 && score >= 2) { + if (s-->0) ret++; + } + } + + return """"+ret; + } +} +" +A22560,"import java.util.Scanner; + + +public class Dancing +{ + public static void main(String[] inteettskit) + { + int line = 0; + int T = 0; + int N = 0; // Number of googlers + int S = 0; // Surprises + int p = 0; // p + + Scanner line_scanner = new Scanner(System.in); + + + while(line_scanner.hasNextLine()) + { + String apa = line_scanner.nextLine(); + Scanner int_scanner = new Scanner(apa); + +// System.out.println(""line: "" + line); + + if(line == 0) + { + T = int_scanner.nextInt(); +// System.out.println(""T: "" + T); + } + + else + { + + int[] input = null; + int counter = 0; + + while (int_scanner.hasNextInt()) + { + if(counter == 0) + { + N = int_scanner.nextInt(); + input = new int[N+3]; + input[0] = N; + } + + else + { + int number = int_scanner.nextInt(); + input[counter] = number; +// System.out.println(""Scanner: "" + number + "" counter: "" + counter); + } + + counter++; + } + + N = input[0]; // Number of googlers + S = input[1]; // Surprises + p = input[2]; // p + int t[] = new int[N]; // total scores of the googlers + + int possible = 0; + + for( int i = 0; i < N; i++) + { +// System.out.println(input[i+3]); + t[i] = input[i+3]; + } + + +// System.out.println(""Googlers: "" + N); +// System.out.println(""Surprises: "" + S); +// System.out.println(""p: "" + p); +// System.out.print(""Scores:""); + + for(int score: t) + { +// System.out.print("" "" + score); + } + +// System.out.println(); + + for(int i = 0; i < N ; i++) + { + + int retur = pp(p, t[i]); + if(retur >= 1) + { + if(retur >=2) + { + if(S > 0) + { + possible++; + S--; + } + } + else + { + possible ++; + } + + } + + } + System.out.println(""Case #"" + (line) +"": "" + possible); + } + line++; + + } + } + + public static int pp(int p, int totalscore) + { + int min_normal_score = 0; + int min_surprise_score = 0; + + if(p-1 >= 0) + { + min_normal_score = (p + (p-1) + (p-1)); + } + + else + { + min_normal_score = p; + } + + if(p-2 >= 0) + { + min_surprise_score = (p + (p-2) + (p-2)); + } + + else + { + min_surprise_score = p; + } + +// System.out.println(""Minimum surprise score for p = "" + p + "" is "" + min_surprise_score); +// System.out.println(""Minimum normal score for p = "" + p + "" is "" + min_normal_score); + + if(totalscore >= min_normal_score) + { +// System.out.println(""Always!""); + return 1; + } + + else if(totalscore >= min_surprise_score) + { +// System.out.println(""Requires surprise""); + return 2; + } + + else + { +// System.out.println(""Never!""); + return 0; + } + } + +} +" +A21770,"import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; + + +public class Run2 +{ + public static void main(String[] args) + { + String path = ""files/B-large.in""; + + int T = 0; + ArrayList> googlers = new ArrayList>(); + ArrayList surprisings = new ArrayList(); + ArrayList leasts = new ArrayList(); + + try + { + boolean isFirstLine = true; + + FileReader FR = new FileReader(path); + BufferedReader BR = new BufferedReader(FR); + String str = """"; + + while((str=BR.readLine())!=null) + { + if (isFirstLine) + { + T = Integer.parseInt(str); + isFirstLine = false; + } + else + { + String[] temp = str.split("" ""); + + surprisings.add(Integer.parseInt(temp[1])); + leasts.add(Integer.parseInt(temp[2])); + + ArrayList score = new ArrayList(); + for(int i = 3; i < temp.length; i++) + { + score.add(Integer.parseInt(temp[i])); + } + googlers.add(score); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + for(int i = 0; i < T; i++) + { + ArrayList googler = googlers.get(i); + int surprising = surprisings.get(i); + int least = leasts.get(i); + int number = 0; + + int dontSurprising = 0; + int isSurprising = 0; + for(int j = 0; j < googler.size(); j++) + { + int score = googler.get(j); + + int surprisingBounds = least+(least-2)*2; + int dontSurprisingBounds = least+(least-1)*2; + if (least < 2) + { + surprisingBounds = least; + dontSurprisingBounds = least; + } + if (score >= surprisingBounds && score < dontSurprisingBounds) + { + isSurprising++; + } + else if (score >= dontSurprisingBounds) + { + dontSurprising++; + } + } + number = dontSurprising+isSurprising+((surprising-isSurprising)>=0?0:(surprising-isSurprising)); + System.out.println(""Case #""+(i+1)+"": ""+number); + } + } +}" +A20539,"package qualification; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; + +public class DancingWithGoogler { + public static void main(String[] args) throws IOException{ + BufferedReader file = new BufferedReader(new FileReader(new File(""src/input""))); + String firstline = file.readLine(); + int casenum = Integer.parseInt(firstline); + StringWriter s= new StringWriter(); + for(int i=0;i28){ + //no surprising + int min = googler/3; + if(min>=p)++count; + } + else{ + if(googler<3*p-4){ + ;//no-op + } + else if(googler>3*p-3){ + ++count; + } + else{//only when the sum is 3p-3 or 3p-4 we need a surprise + if(surprise>0){ + --surprise; + ++count; + } + } + } + } + s.append(""Case #""+(i+1)+"": ""+count); + s.append(""\n""); + } + + FileWriter fout = new FileWriter(""src/out.txt""); + fout.write(s.toString()); + fout.close(); + } +} +" +A22679," +import java.io.*; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Ankur + */ +public class DacingWithTheGooglers { + + public static void main(String[] args) { + try + { + FileWriter fout = new FileWriter(""out""); + BufferedWriter out = new BufferedWriter(fout); + try + { + Scanner in = new Scanner(new File(""in"")); + int T = in.nextInt(); + System.out.println(T); + for(int i=0; i= (3*p - 4) && t > 0) + { + if(t >= (3*p - 2)) + ans++; + else + { + if(S != 0) + { + S--; + ans++; + } + } + } + } + } + out.write(""Case #"" + (i+1) + "": "" + ans); + out.newLine(); + } + out.close(); + }catch(FileNotFoundException e) + { + System.out.println(""ERROR: File Not Found!""); + } + }catch(IOException x) + { + System.out.println(""ERROR: Can't create output file""); + } + } +} +" +A21885,"import java.util.*; +import java.util.regex.*; +import java.text.*; +import java.math.*; + +public class B { + int[] mp=new int[33], sp=new int[33]; + + void start() { + for (int a=0; a<11; a++) + for (int b=a; b<11 && b=top) re++; + else if (sp[score]>=top && surp>0) { + surp--; + re++; + } + } + System.out.printf(""Case #%d: %d\n"", t, re); + } + } + + public static void main(String[] args) throws Exception { + new B().start(); + } +}" +A22127,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Scanner; +import java.io.BufferedWriter; + +public class D { + public static void main(String[] args) throws IOException { + int n; + + InputStreamReader reader = new InputStreamReader(new FileInputStream( + args[0])); + BufferedReader read = new BufferedReader(reader); + BufferedWriter write = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(args[1]))); + + // Scanner scan = new Scanner(System.in); + n = Integer.parseInt(read.readLine()); + // n = scan.nextInt(); + for (int i = 0; i < n; i++) { + String p = read.readLine(); + write.write(""Case #"" + (i + 1) + "": "" + holy(p, read)); + write.newLine(); + } + write.flush(); + write.close(); + } + + static int holy(String s, BufferedReader read) throws IOException { + + int [] value = new int [103]; + String p = s; + int i = 0; + int min_score = 0; + int result = 0; + + + while (p.indexOf("" "") != -1){ + int pemisah = p.indexOf("" ""); + int a = Integer.parseInt(p.substring(0 , pemisah)); + value [i] = a; + i++; + p = p.substring(pemisah+1); + } + + value [i] = Integer.parseInt(p); + i++; + + switch (value[2]) { + case 0 : + min_score = 0 ; + break; + case 1 : + min_score = 1 ; + break; + case 2 : + min_score = 2 ; + break; + case 3 : + min_score = 5 ; + break; + case 4 : + min_score = 8 ; + break; + case 5 : + min_score = 11 ; + break; + case 6 : + min_score = 14 ; + break; + case 7 : + min_score = 17 ; + break; + case 8 : + min_score = 20 ; + break; + case 9 : + min_score = 23 ; + break; + case 10 : + min_score = 26 ; + break; + } + + int surprising = value [1]; + + if (value[2] == 0) { + for (int j = 3; j < i; j++) { + result++; + } + } else { + for (int j = 3; j < i; j++) { + + if ((value[j] == min_score) || (value[j] == min_score + 1)) { + if (surprising > 0) { + result++; + surprising--; + } + } + + if (value[j] > min_score + 1) { + result++; + } + } + } + + return result; + + } +}" +A20707,"package test; +import java.io.*; + +public class Test { + + static public void magic(String tmp, int Result [],int index ){ + int N=0,S=0,P=0,size; + char Carr []= new char[300]; + size=tmp.length(); + tmp.getChars(0, size, Carr, 0); + + int i=0,j=0,spc=0; + String bom; + while (spc<3){ + + if(Carr[j]!=' '){ + j++; + }else{ + bom=tmp.substring(i, j); + if(spc==0) + N=Integer.parseInt(bom); + if(spc==1) + S=Integer.parseInt(bom); + if(spc==2) + P=Integer.parseInt(bom); + spc++; + j++; + i=j; + } + } + + int counter=N; + int bomnum,nosur,sur,ans=0; + nosur=((P-1)*2)+P; + sur=((P-2)*2)+P; + if(sur<0) + sur=1; + while (counter>0){ + if(Carr[j]!=' '&&j=nosur){ + ans++; + }else if(bomnum>=sur && S>0){ + ans++; + S--; + } + j++; + i=j; + counter--; + } + } + + Result[index]=ans; + + } + + public static void main(String[] args) { + + //////// + int index=0,T,casenum=1,j; + String tmp; + + int Result[]=new int [101]; + + //////// + + BufferedReader reader; + reader = new BufferedReader(new InputStreamReader(System.in)); + try { + tmp = reader.readLine(); + T=Integer.parseInt(tmp); + + j=T; + while(j!=0){ + tmp = reader.readLine(); + magic (tmp,Result,index); + + index++; + j--; + } + + j=T; + while(j!=0){ + System.out.println(""Case #""+casenum+"": ""+Result[casenum-1]); + casenum++; + j--; + } + + + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A22321,"import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; + + +public class Dancing { + public static void main(String[] args) throws IOException { + LineNumberReader in = new LineNumberReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(in.readLine().trim()); + for (int a = 1; a <= N; a++) { + String[] tmp = in.readLine().trim().split("" ""); + int n = Integer.parseInt(tmp[0]); + int s = Integer.parseInt(tmp[1]); + int p = Integer.parseInt(tmp[2]); + + int minNormal, minSurprising; + if (p < 2) { + minNormal = minSurprising = p; + } else { + minNormal = 3 * p - 2; + minSurprising = 3 * p - 4; + } + + int res = 0; + for (int b = 0; b < n; b++) { + int val = Integer.parseInt(tmp[3 + b]); + + if (val >= minNormal) { + res++; + } else + if (val >= minSurprising && s > 0) { + res++; + s--; + } + } + + System.out.println(""Case #"" + a + "": "" + res); + } + } +} +" +A22985,"package gcj; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.Arrays; + +public class DancingWithGooglers +{ + boolean[][] isPossibleNormal; + boolean[][] isPossibleSurprising; + + int P; + int[] totalPoints; + int N; + int[][] memo; + + public DancingWithGooglers() + { + this.isPossibleNormal=new boolean[31][11]; + this.isPossibleSurprising=new boolean[31][11]; + for(int i=0;i<31;++i) + { + Arrays.fill(isPossibleNormal[i],false); + Arrays.fill(isPossibleSurprising[i],false); + } + for(int a=0;a<=10;++a) + { + for(int b=0;b<=10;++b) + { + for(int c=0;c<=10;++c) + { + int total=a+b+c; + int best=Math.max(a, b); + best=Math.max(best, c); + int maxDiff=Math.max(0,Math.abs(a-b)); + maxDiff=Math.max(maxDiff,Math.abs(b-c)); + maxDiff=Math.max(maxDiff,Math.abs(a-c)); + if(maxDiff>2) + continue; + else if(maxDiff==2) + { + isPossibleSurprising[total][best]=true; + } + else + { + isPossibleNormal[total][best]=true; + } + } + } + } + } + + private int solve(int idx,int surpriseLeft) + { + if(idx>=N) + { + if(surpriseLeft==0) + return 0; + else + return -2; + } + else if(memo[idx][surpriseLeft]!=-1) + return memo[idx][surpriseLeft]; + else + { + int ret=Integer.MIN_VALUE,t1=ret,t2=ret, t3=ret,t4=ret; + boolean goNormal=false, goSurprising=false; + for(int possi=P;possi<=10;++possi) + { + if(isPossibleNormal[totalPoints[idx]][possi]) + goNormal=true; + if(isPossibleSurprising[totalPoints[idx]][possi]) + goSurprising=true; + } + if(goNormal) + { + int t=solve(idx+1,surpriseLeft); + if(t!=-2) + t1=1+t; + } + if(goSurprising && surpriseLeft>0) + { + int t=solve(idx+1,surpriseLeft-1); + if(t!=-2) + t2=1+t; + } + { + //ignore current idx and then not alter surpriseLeft + int t=solve(idx+1,surpriseLeft); + if(t!=-2) + t3=t; + } + if(surpriseLeft>0) + { + int t=solve(idx+1,surpriseLeft-1); + if(t!=-2) + { + t4=t; + } + } + ret=Math.max(ret,t1); + ret=Math.max(ret,t2); + ret=Math.max(ret,t3); + ret=Math.max(ret,t4); + if(ret==Integer.MIN_VALUE) + ret=-2; + memo[idx][surpriseLeft]=ret; + return ret; + } + } + private int getMaximumGooglers(int N,int S,int P, int[] totalPoints) + { + this.N=N; + this.P=P; + this.totalPoints=totalPoints; + this.memo=new int[N+1][N+1]; + for(int i=0;i<=N;++i) + Arrays.fill(memo[i],-1); + int ret=solve(0,S); + return ret; + } + + /** + * @param args + */ + public static void main(String[] args) throws Exception + { + BufferedReader br=null; + if(args.length>=1) + br=new BufferedReader(new FileReader(new File(args[0]))); + else + br=new BufferedReader(new InputStreamReader(System.in)); + if(args.length>=2) + System.setOut(new PrintStream(new FileOutputStream(args[1]))); + int T=Integer.valueOf(br.readLine().trim()); + DancingWithGooglers obj=new DancingWithGooglers(); + for(int t=1;t<=T;++t) + { + String[] tok=br.readLine().trim().split("" ""); + int N=Integer.valueOf(tok[0]); + int S=Integer.valueOf(tok[1]); + int P=Integer.valueOf(tok[2]); + int[] totalPoints=new int[N]; + for(int j=0;j -1; k--) { + int min = ti[k] / 3, max = ti[k] - 2 * (ti[k] / 3); + + if (0 == max - min && 2 < ti[k]) { + max++; + min--; + } + + if (max >= p) { + if (max == p && (2 == max - min)) { + if (0 < s) { + s--; + num++; + } + } else { + num++; + } + } + } + + bufferedWriter.write(""Case #"" + (i + 1) + "": "" + num + ""\n""); + } + + bufferedWriter.flush(); + } +} +" +A22882,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class Dancing { + private static int[] data; + + public static void main(String[] args) throws IOException { + BufferedReader f = new BufferedReader(new FileReader(""A-small-practice.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""A-small-practice.out""))); + StringTokenizer st = new StringTokenizer(f.readLine()); + + int tests = Integer.parseInt(st.nextToken()); + + for (int t = 1; t <= tests; t++){ + out.printf(""Case #%d:"", t); + st = new StringTokenizer(f.readLine()); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + data = new int[n]; + for (int i = 0; i < n; i++){ + data[i] = Integer.parseInt(st.nextToken()); + } + + out.printf("" %d\n"", fun1(n, s, p)); + } + + out.close(); + System.exit(0); + } + + private static int fun1(int n, int s, int p){ + int count = 0; + int s_ = s; + for (int i = 0; i < n; i++){ + int avg = data[i] / 3; + + if (data[i] % 3 == 0){ + if(avg >= p) { + count ++; + } else{ + if((s_ > 0) && (avg + 1 >= p) && (avg - 1 >=0)){ + count ++; + s_--; + } + } + } else if(data[i] % 3 == 1){ + if(avg + 1 >= p){ + count++; + } + } else if(data[i] % 3 == 2){ + if(avg + 1 >= p){ + count ++; + } else if((s_ > 0) && (avg + 2 >= p)){ + count++; + s_--; + } + } + } + return count; + } +} +" +A21173,"import java.io.*; +public class Q2 { + + /** + * @param args + * @throws Throwable + */ + public static void main(String[] args) throws Throwable { + BufferedReader br = new BufferedReader(new FileReader(""a-small.in"")); + PrintWriter pr = new PrintWriter(new FileWriter(""output.txt"")); + + int T = Integer.parseInt(br.readLine()); + + for(int cas = 1; cas<=T; cas++) + { + String[] input = br.readLine().split("" ""); + int N = Integer.parseInt(input[0]); + int S = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + int score = 0; + + int normalMin = p + 2*(p-1); + int sMin = p + 2*(p-2); + + if(p == 0) + { + normalMin = 0; + sMin = 0; + } + else if(p == 1) + { + normalMin = 1; + sMin = 1; + } + + for(int person = 0; person= normalMin) + { + score++; + } + else if(total >= sMin && S > 0) + { + score++; + S--; + } + } + + pr.println(""Case #"" + cas + "": "" + score); + } + + pr.close(); + } + +} +" +A21808," +import java.util.Scanner; + + +public class Dancer{ + private static int t; + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + t=in.nextInt(); + in.nextLine(); +// System.out.println(t+"" Cases""); + for (int i=0;i0){ + continue; + } + if(t[i]>=limits[0]){ + y++; + } + else{ + if(t[i]>=limits[1]&&s>0){ + s--; + y++; + } + } + } + return y; + } + + public static int[] calcLimits(int p){ + int limits[]=new int[2]; + limits[0]=p+2*(p-1); + limits[1]=p+2*(p-2); + if(limits[0]<0){ + limits[0]=0; + } + if(limits[1]<0){ + limits[1]=0; + } + return limits; + } + + + + + public static int[] getTotalPoints(Scanner in,int n){ + int[] array=new int[n]; + for(int i=0;i= p) + n_over_p++; + if (best_no_surprise[a[i]] < p && best_surprise[a[i]] >= p) + n_surp++; + } + int max_val = n_over_p + Math.min(S, n_surp); + System.out.println(""Case #""+(t+1)+"": "" + max_val); + } + in.close(); + } + + static void init () { + } +}" +A21352,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class Main2 { + + public static void main(String args[]) throws IOException { + + BufferedReader fileIN=new BufferedReader(new FileReader(new File(""B-large.in""))); + BufferedWriter fileOUT=new BufferedWriter(new FileWriter(""B-LargeOUT.txt"")); + String Line; + String[] splitted; + int T, N, S, p, G, difference; + int[] ratings; + int[][] scores; + + T=Integer.parseInt(fileIN.readLine()); + for(int c=1; c0) + difference=2; + else + difference=1; + //maximo1 + int minimmum=p+2*(p-2); + //maximo1 + ratings = new int[N]; + for(int i=3; i=p || scores[n][1]>=p || scores[n][2]>=p) + G++; + if(findMaximmumDifference(triplet)==2) + S--; + if(S==0) + difference=1; + } + String output=""Case #""+c+"": ""+G+""\n""; + fileOUT.write(output); + System.out.print(output); + + } + fileIN.close(); + fileOUT.close(); + } + + private static int[] findTriplet(int rating, int difference){ + int[] triplet = new int[3]; + int r1, r2, r3=r2=r1=10; + for(; r1>=0; r1--) + for(r2=r1+difference; r2>=r1-difference; r2--) + if(r2>=0 && r2<=10) + for(r3=r1+difference; r3>=r1-difference; r3--) + if(r3>=0 && r3<=10 && r3r2-2*difference) + if(r1+r2+r3 == rating){ + triplet[0]=r1; + triplet[1]=r2; + triplet[2]=r3; + r1=r2=r3=-1; + } + return triplet; + } + + private static int findMaximmumDifference(int[] triplet){ + int a1=triplet[0]-triplet[1]; + int a2=triplet[0]-triplet[2]; + int a3=triplet[1]-triplet[2]; + if(a1<0) + a1=-a1; + if(a2<0) + a2=-a2; + if(a3<0) + a3=-a3; + if(a1==2 || a2==2 || a3==2) + return 2; + else return 1; + } + + private static int[] changeOrder(int[] rating, int minimmum){ + int times=0; + for(int i=0; i1) + limit=P+((P-2)*2); + else + limit=P; + for(int i=0;i=limit&&t<=30) + { + if(t>=0&&t<=2) + { + if(t==0&&P==0) + res++; + if(t==1&&P<=1) + res++; + if(t==2&&P<=2) + { + if(S==0&&P==1) + res++; + if(S>0&&P==2) + { + res++; + S--; + } + + } + } + else + { + temp1=t%3; + temp=t/3; + if(temp1==0) + {System.out.println(""Case #""+(cnt+1)+"": ""+temp); + if(Math.max(Math.max((temp-1), (temp)),(temp+1))>=P&&S>0) + { + res++; + if(!(temp>=P)) + S--; + } + else + { + if(temp>=P) + res++; + } + + } + if(temp1==1) + {System.out.println(""Case #""+(cnt+1)+"": ""+temp); + if((temp+1)>=P&&S>0) + { + res++; + if(!((temp+1)>=P)) + S--; + } + else + { + if((temp+1)>=P) + res++; + } + + } + if(temp1==2) + {System.out.println(""Case #""+(cnt+1)+"": ""+temp); + if((temp+2)>=P&&S>0) + { + res++; + if(!((temp+1)>=P)) + S--; + } + else + { + if((temp+1)>=P) + res++; + } + } + } + } + } + pw.println(""Case #""+(cnt+1)+"": ""+res); + } + } catch (IOException ex) { + Logger.getLogger(Speaking_in_Tongues.class.getName()).log(Level.SEVERE, null, ex); + } finally { + pw.flush(); + pw.close(); + sc.close(); + } + } +} +" +A20688,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package javaapplication2; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +/** + * + * @author Mash + */ +public class B { + public static void main(String[] args) throws IOException{ + Scanner in = new Scanner(new FileReader(""C:\\ima\\ans.txt"")); + PrintWriter out=new PrintWriter(new FileWriter(""C:\\ima\\input.txt"")); + int T,S,p,N,G[]; + T=in.nextInt(); + for(int i=1;i<=T;i++){ + N=in.nextInt(); + G=new int[N]; + S=in.nextInt(); + p=in.nextInt(); + for(int j=0;j1){ + int q=p*3-2; + int s=p*3-4; + int cnt=0; + int pt=N-1; + for(int j=N-1;j>=0;j--){ + if(G[j]>=q){cnt++;pt--;} + } + while(pt>=0&&G[pt]>=s&&S>0){ + cnt++;pt--;S--; + } + System.out.println(""Case #""+i+"": "" +cnt); + }else if(p==1){ + int m=0; + for(m=0;m0)break; + } + System.out.println(""Case #""+i+"": "" +(N-m)); + }else if(p==0)System.out.println(""Case #""+i+"": ""+N); + } + } + +} +" +A21229,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class ProblemB { + + public static void main(String[] args) { + try (BufferedReader reader = new BufferedReader(new FileReader(""B-large.in""))) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(""B-large.out""))) { + String line = reader.readLine(); + int numCases = Integer.parseInt(line); + + Scanner scanner; + for(int caseIdx = 0; caseIdx < numCases; caseIdx++) { + scanner = new Scanner(reader.readLine()); + + int N = scanner.nextInt(); // number of Googlers + int S = scanner.nextInt(); // number of suprising triplets + int p = scanner.nextInt(); // point limit - maximum number of Googlers who could have had the best result of p + +// System.out.println(String.format(""Case #%d: N_%d S_%d p_%d"", caseIdx+1, N, S, p)); + + int[] t = new int[N]; // total points of Googlers + for(int idx = 0; idx < N; idx++) { + t[idx] = scanner.nextInt(); + } + + // not suprising : 0 1 29 30 + + // 2 - 0 0 2 | 3 - 0 1 2 | 4 - 0 2 2 + // 5 - 1 1 3 | 6 - 1 2 3 | 7 - 1 3 3 + // 8 - 2 2 4 | 9 - 2 3 4 | 10 - 2 4 4 + // 11 - 3 3 5 | ... + // suprising formula: s_max(x) - (x+1)/3+1 + + // 2 - 0 1 1 | 3 - 1 1 1 | 4 - 1 1 2 + // 5 - 1 2 2 | 6 - 2 2 2 | 7 - 2 2 3 + // 8 - 2 3 3 | 9 - 3 3 3 | 10 - 3 3 4 + // 11 - 3 4 4 | 12 - 4 4 4 | ... + // unsuprising formula: us_max(x) - (x-1)/3+1 + + int possibleNotSuprising = 0; + int possibleSuprising = 0; + + for(int idx = 0; idx < N; idx++) { +// int max; boolean suprising = false; + + int ti = t[idx]; + int us_max = ti < 2 ? ti : Math.min(10, (ti - 1) / 3 + 1); + if(us_max >= p) { + possibleNotSuprising++; +// max = us_max; + } else { + int s_max = ti < 2 ? ti : Math.min(10, (ti + 1) / 3 + 1); +// max = s_max; suprising = true; + + if(s_max >= p) { + if(ti < 2 || ti > 28) possibleNotSuprising++; + else possibleSuprising++; + } + } + +// System.out.println(String.format(""Case #%d: G_%d Total_%d Max_%d S?"", caseIdx+1, idx+1, ti, max) + Boolean.toString(suprising)); + } + + int result = possibleNotSuprising + Math.min(S, possibleSuprising); + + String caseOutput = String.format(""Case #%d: %d"", caseIdx + 1, result); + + System.out.println(caseOutput); + writer.append(caseOutput); + writer.newLine(); + } + } + } catch(IOException ioEx) { + ioEx.printStackTrace(); + } + } + +} +" +A20512,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class ProblemB { + + public static int count(int s, int p, int[] notes) { + int count = 0; + for (int note : notes) { + if (note + 2 >= 3 * p) { + count++; + } else if (note + 4 >= 3 * p && s > 0 && note >= p) { + count++; + s--; + } + } + return count; + } + + public static void main(String[] args) throws IOException { + String filename = args[0]; + BufferedReader br = new BufferedReader(new FileReader(filename)); + + int T = Integer.parseInt(br.readLine()); + for (int i = 1; i <= T; ++i) { + String[] line = br.readLine().split("" ""); + + int N = Integer.parseInt(line[0]); + int s = Integer.parseInt(line[1]); + int p = Integer.parseInt(line[2]); + int[] notes = new int[N]; + + for (int j = 0; j < N; ++j) { + notes[j] = Integer.parseInt(line[3+j]); + } + + System.out.println(""Case #"" + i + "": "" + count(s, p, notes)); + } + + br.close(); + } + +}" +A22025,"import java.util.Scanner; + + +public class Main { + public static void main(String [] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int x=0; x0) + m++; + if(m>=p) { + direct++; + continue; + } + else if(m0) + poss++; + break; + case 2: + if(m<10) + poss++; + break; + } + } + int result = (S>poss)? poss : S; + result += direct; + System.out.print(""Case #"" + String.valueOf(x+1) + "": ""); + System.out.println(result); + } + } +}" +A22973,"import java.util.Scanner; + + +public class b { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt();//n cases + for (int i = 1; i <= n+1; i++) { + //for each case + int dancers = sc.nextInt(); + int surprising = sc.nextInt(); + int minscore = sc.nextInt(); + int res=0; + for (int j = 0; j < dancers; j++) { + int scoretotal = sc.nextInt(); + if (minscore!=0 && scoretotal/minscore>=1) { + + if (surprising>=1) { + if (scoretotal>minscore*3-3) { + res++; + }else if (scoretotal==minscore*3-4 || scoretotal==minscore*3-3) { + res++; + surprising--; + } + }else if (surprising==0) { + if (scoretotal>=minscore*3-2) { + res++; + } + } + }else if (minscore==0) { + res = dancers; + } + } + + System.out.println(""Case #""+i+"": ""+res); + } + } + + +} +" +A21016,"import java.io.*; + +public class B { + + private static final String FILE = ""B-large""; + + private static final boolean SAVE_OUT = true; + + public static void main(String[] args) throws IOException { + BufferedReader in = createReader(); + FileWriter out; + if (SAVE_OUT) { + out = new FileWriter(FILE+"".out""); + } + int t = Integer.parseInt(in.readLine()); + int c = 0; + while (t-- > 0) { + String row = in.readLine(); + String[] split = row.split("" ""); + int n = Integer.parseInt(split[0]); + int s = Integer.parseInt(split[1]); + int p = Integer.parseInt(split[2]); + int num = 0; + for (int i = 0; i < n; ++i) { + int k = Integer.parseInt(split[i+3]); + if (k == 0) { + num += p == 0 ? 1 : 0; + } else if (k == 1) { + num += p <= 1 ? 1 : 0; + } else if (3*p-2 <= k) { + ++num; + } else if (3*p-4 <= k && s > 0) { + ++num; + --s; + } + } + String res = String.format(""Case #%d: %d"", ++c, num); + System.out.println(res); + if (SAVE_OUT) { + out.append(res); + out.append(""\n""); + } + } + if (SAVE_OUT) { + out.close(); + } + } + + private static BufferedReader createReader() throws FileNotFoundException { + return new BufferedReader(new FileReader(FILE+"".in"")); + } +} +" +A21747,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.Reader; + + +public class ProB { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + File infile = new File(""B-large.in""); + File outfile = new File(""out.txt""); + int []scores = new int[222]; + BufferedReader reader = null; + BufferedWriter writer = null; + try{ + reader = new BufferedReader(new FileReader(infile)); + writer = new BufferedWriter(new FileWriter(outfile)); + String ss = reader.readLine(); + String out; + String []nums; + int t = Integer.parseInt(ss),i,j,res; + int n,s,p,temp,rest; + for(i=1;i<=t;i++){ + out = ""Case #"" + i + "": ""; + ss = reader.readLine(); + nums = ss.split("" ""); + n = Integer.parseInt(nums[0]); + s = Integer.parseInt(nums[1]); + p = Integer.parseInt(nums[2]); + for(j=3;j<3+n;j++){ + scores[j-3] = Integer.parseInt(nums[j]); + } + sort(scores,n); + res = 0; + for(j=0;j 0) temp++; + if(temp >= p) res++; + else{ + if(rest == 2 && s > 0 && temp + 1 >= p){ + s--; + res++; + } + if(rest == 0 && s > 0 && temp > 0 && temp + 1 >= p){ + s--; + res++; + } + } + } + out += res; + writer.write(out); + writer.newLine(); + } + reader.close(); + writer.close(); + }catch(Exception e){ + e.printStackTrace(); + } + } + + private static void sort(int []scores,int n) + { + int i,j,t,s; + for(i=0;i s){ + s = scores[j]; + t = j; + } + } + s = scores[i]; + scores[i] = scores[t]; + scores[t] = s; + } + } + +} +" +A22473,"import java.util.Scanner; + +public class B { + + public static void main(String[] args) { + + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); in.nextLine(); + + //build auxiliary arrays + int[] without = new int[31]; + int[] with = new int[31]; + for (int i = 0; i <= 30; i++) + { + without[i] = (int)Math.ceil((double)i/3.0); + + if (i == 0) with[i] = 0; + else with[i] = (int)Math.min(10, Math.ceil(((double)i+2.0)/3.0)); + } + + //for each test case + for (int i = 1; i <= T; i++) + { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int result = 0; + + for (int j = 0; j < N; j++) + { + int tp = in.nextInt(); + + if (without[tp] >= p) result++; + else if (with[tp] >= p && S > 0) + { + result++; + S--; + } + } + + System.out.format(""Case #%d: %d\n"", i, result); + } + } +}" +A21854,"package com.nolmecolindor.gcj2012.round0; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Scanner; + +public class Problem_B_0 { + + private int solve(final Scanner input) { + final int N = input.nextInt(); + final int S = input.nextInt(); + final int P = input.nextInt(); + final int[] points = new int[31]; + for (int i = 0; i < N; i++) points[input.nextInt()]++; +// System.out.println(""Point distribution: ""); +// for (int i = 0; i <= 30; i++) System.out.println(points[i] + "" dancers got "" + i + "" points.""); + + int remainingSurprises = S; + + int result = 0; + for (int i = 30; i >= 0; i--) { + if (points[i] == 0) continue; + final int min; + final int max; + switch (i % 3) { + case 0: + min = i / 3; + max = min; + if (max >= P) { // We reach the limit by default + result += points[i]; + } else if ((max + 1 == P) && (min > 0) && (max < 10)) { // We can reach the limit with surprises + final int useSurprises = Math.min(points[i], remainingSurprises); + remainingSurprises -= useSurprises; + result += useSurprises; + } else { // We can not reach the limit anyway + // We are not interested + } + break; + case 1: + max = (i - 1) / 3 + 1; + if (max >= P) result += points[i]; + break; + case 2: + min = (i - 2) / 3; + max = min + 1; + if (max >= P) { // We reach the limit by default + result += points[i]; + } else if ((max + 1 == P) && (max < 10)) { // We can reach the limit with surprises + final int useSurprises = Math.min(points[i], remainingSurprises); + remainingSurprises -= useSurprises; + result += useSurprises; + } else { // We can not reach the limit anyway + // We are not interested + } + break; + } + + } + return result; + } + + + private void solveAll(final Scanner input) throws NumberFormatException, IOException { + final int cases = input.nextInt(); + input.nextLine(); + for (int caseNum = 1; caseNum <= cases; caseNum++) { + System.out.println(""Case #"" + caseNum + "": "" + solve(input)); + } + } + + public static void main(final String[] args) { + try { + final Scanner input = new Scanner(((args.length == 2) && args[0].equals(""--input"")) ? new FileInputStream(args[1]) : System.in); + new Problem_B_0().solveAll(input); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} +" +A20846,"import java.util.Scanner; + + + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int testCases = sc.nextInt(); + for (int i = 1; i <= testCases; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] points = new int[n]; + int result = 0; + boolean[] flags = new boolean[n]; + for (int j = 0; j < n; j++) { + int temp = sc.nextInt(); + if (temp == 0) { + points[j] = 0; + flags[j] = false; + } else if (temp % 3 == 0) { + points[j] = temp / 3; + flags[j] = true; + } else if (temp % 3 == 1) { + points[j] = temp / 3 + 1; + flags[j] = false; + } else { + points[j] = temp / 3 + 1; + flags[j] =true; + } + } + for (int j = 0; j < n; j++) { + if (points[j] >= p) { + result += 1; + flags[j] = false; + } + } + int currentSurprising = 0; + for (int j = 0; j < n && currentSurprising < s; j++) { + if (flags[j] && points[j] + 1 >= p) { + result += 1; + currentSurprising += 1; + } + } + System.out.println(""Case #"" + i + "": "" + result); + } + } +} +" +A21468,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancingwiththegooglers; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * + * @author arjun + */ +public class DancingWiththeGooglers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException { + PrintStream out = new PrintStream(new FileOutputStream(""output.txt"")); + System.setOut(out); + parseAndTranslate(); + } + + private static void parseAndTranslate() { + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = br.readLine(); + if (null != strLine) { + int count = new Integer(strLine); + //Read File Line By Line + int lineNo = 0; + while ((strLine = br.readLine()) != null) { + lineNo++; + doOp(strLine, lineNo); + } + //Close the input stream + } + in.close(); + } catch (Exception e) {//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + private static void doOp(String strLine, int lineNo) { + + StringTokenizer st = new StringTokenizer(strLine); + + String temp = st.nextToken(); + int noOfGooglers = new Integer(temp); + + temp = st.nextToken(); + int surprisingTriplets = new Integer(temp); + + temp = st.nextToken(); + int bestScore = new Integer(temp); + //System.out.println(""Goog: "" + noOfGooglers + "" surp: "" + surprisingTriplets + // + "" bestScore: "" + bestScore + "" ""); + int nthNo = 0; + Map> iSet = new HashMap>(); + while (st.hasMoreTokens()) { + nthNo++; + String pts = st.nextElement().toString(); + int pt = new Integer(pts); + //System.out.print("" "" + pt); + boolean SurpUsed = compute(pt, bestScore, surprisingTriplets, iSet, nthNo); + if (SurpUsed) { + surprisingTriplets -= 1; + } + } + + int topScores = 0; + for (Integer pointNo : iSet.keySet()) { + List points = iSet.get(pointNo); + //System.out.print(""\nNo: "" + pointNo + "", Scores: ""); + boolean topScoreFoundAlready = false; + for (Integer p : points) { + if (p >= bestScore && !topScoreFoundAlready) { + topScores++; + topScoreFoundAlready = true; + } + //System.out.print("" "" + p); + } + //System.out.println(); + } + System.out.println(""Case #"" + lineNo + "": "" + topScores); + } + + private static boolean compute(int pt, int bestScore, int surprisingTriplets, + Map> iSet, int nthNo) { + List points = new ArrayList(); + boolean surpUsed = false; + + int no1 = 0, no2 = 0, no3 = 0; + int mean = Math.round(pt / 3); + int rem = pt % 3; + + if (0 == rem) { + if (mean < bestScore) { + if (surprisingTriplets > 0 && (mean + 1) >= bestScore + && (mean - 1) >= 0 && (mean + 1) <= 10) { + surpUsed = true; + no1 = mean; + no2 = mean + 1; + no3 = mean - 1; + } else { + no1 = mean; + no2 = mean; + no3 = mean; + } + } else { + no1 = mean; + no2 = mean; + no3 = mean; + } + } else if (1 == rem) { + no1 = mean + 1; + no2 = mean; + no3 = mean; + } else if (2 == rem) { + if ((mean + 1) < bestScore) { + if (surprisingTriplets > 0 && (mean + 2) >= bestScore + && (mean + 2) <= 10) { + surpUsed = true; + no1 = mean + 2; + no2 = mean; + no3 = mean; + } else { + no1 = mean + 1; + no2 = mean + 1; + no3 = mean; + } + } else { + no1 = mean + 1; + no2 = mean + 1; + no3 = mean; + } + } + + + points.add(no1); + points.add(no2); + points.add(no3); + iSet.put(nthNo, points); + return surpUsed; + } +} +" +A21223,"import java.io.*; + +public class Qualifying_B { + + public static void main(String[] args) throws Exception { + BufferedReader input = new BufferedReader(new FileReader(args[0])); + int T = Integer.parseInt(input.readLine()); + + for (int t = 1; t <= T; t++) { + String[] tokens = input.readLine().split("" ""); + + int N = Integer.parseInt(tokens[0]); + int S = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int[][] Googlers = new int[N][3]; + + for (int n = 0; n < N; n++) { + Googlers[n][0] = Integer.parseInt(tokens[3 + n]); + Googlers[n][1] = Googlers[n][0] / 3 + ((Googlers[n][0] % 3 != 0) ? 1 : 0); + Googlers[n][2] = (Googlers[n][0] < 2 || Googlers[n][0] > 28) ? -1 : (Googlers[n][0] - 2) / 3 + 2; + } + + int m = 0; + + for (int n = 0; n < N; n++) { + if (Googlers[n][1] >= p) + m++; + else if (Googlers[n][2] >= p && S > 0) { + S--; + m++; + } + } + + System.out.println(""Case #"" + t + "": "" + m); + } + } +} +" +A22237,"import java.io.*; +import java.util.*; + +/** + * @author: Ignat Alexeyenko + * Date: 4/14/12 + */ +public class DancingWithGooglersMain { + + public static final int MAX_LENGTH = 1024; + + public static void main(String[] args) { + DancingWithGooglersMain main = new DancingWithGooglersMain(); + main.runConsoleApp(System.in, System.out); + } + + public void runConsoleApp(InputStream inputStream, OutputStream outputStream) { + final String s = readLn(inputStream, MAX_LENGTH); + Integer cases = Integer.valueOf(s); + Writer writer = new OutputStreamWriter(outputStream); + for (int i= 0; i < cases; i++) { + String rawLine = readLn(inputStream, MAX_LENGTH); + + try { + writer.write(""Case #"" + (i + 1) + "": "" + runFunction(rawLine) + ""\n""); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + try { + writer.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private long runFunction(String rawLine) { + String[] edgesArr = rawLine.split("" ""); + + int numOfGooglers = Integer.valueOf(edgesArr[0]); + int surprises = Integer.valueOf(edgesArr[1]); + int minScoreP = Integer.valueOf(edgesArr[2]); + + List marksT = new ArrayList(numOfGooglers); + for (int t = 0; t < numOfGooglers; t++) { + marksT.add(Integer.valueOf(edgesArr[t + 3])); + } + + return caclulateAmountOfGooglersThatExceedScoreP(surprises, minScoreP, marksT); + } + + private int caclulateAmountOfGooglersThatExceedScoreP(int surprises, int minScoreP, List marksT) { + Map> sumToPermutations = new HashMap>(marksT.size()); + + for (Integer theSum : marksT) { + Set allPossiblePermutations = getAllPossiblePermutations(theSum, minScoreP); + sumToPermutations.put(theSum, allPossiblePermutations); + } + + int exceedsWithoutSurprises = 0; + int exceedsOnlyWithSurprises = 0; + for (Integer theSum : marksT) { + Set marksPermutations = sumToPermutations.get(theSum); + + boolean exceeded = false; + boolean needSurprise = true; + for (Mark marksPermutation : marksPermutations) { + if (marksPermutation.exceedsScore) { + exceeded = true; + if (!marksPermutation.surprise && needSurprise) { + needSurprise = false; + } + } + } + + if (exceeded && needSurprise) { + exceedsOnlyWithSurprises++; + } + if (exceeded && !needSurprise) { + exceedsWithoutSurprises++; + } + } + + return exceedsWithoutSurprises + Math.min(exceedsOnlyWithSurprises, surprises); + } + + Set getAllPossiblePermutations(int sum, int minScoreP) { + Set markList = new LinkedHashSet(5); + final int start = Math.max(sum / 3 - 2, 0); + final int stop = sum / 3 + 2; + for (int i = start; i <= stop; i++) { + for (int j = start; j <= stop; j++) { + for (int k = start; k <= stop; k++) { + final int divergence = Math.abs(max(i, j, k) - min(i, j, k)); + if ((i + j + k == sum) && divergence <= 2) { + boolean exceedsScore = i >= minScoreP || j >= minScoreP || k >= minScoreP; + markList.add(new Mark(i, j, k, divergence == 2, exceedsScore)); + } + } + } + } + return markList; + } + + private static int min(int a, int b, int c) { + return Math.min(Math.min(a, b), c); + } + + private static int max(int a, int b, int c) { + return Math.max(Math.max(a, b), c); + } + + + private String readLn(InputStream inputStream, int maxLength) { // utility function to read from stdin, + // Provided by Programming-challenges, edit for style only + byte line[] = new byte[maxLength]; + int length = 0; + int input = -1; + try { + while (length < maxLength) {//Read untill maxlength + input = inputStream.read(); + if ((input < 0) || (input == '\n')) break; //or untill end of line ninput + line[length++] += input; + } + + if ((input < 0) && (length == 0)) return null; // eof + return new String(line, 0, length); + } catch (IOException e) { + return null; + } + } + + static class Mark { + // array represents marks, always are sorted + private List marks; + + private boolean surprise; + private boolean exceedsScore; + + Mark(int m0, int m1, int m2, boolean surprise, boolean exceedsScore) { + this.marks = new ArrayList(3); + this.marks.add(m1); + this.marks.add(m0); + this.marks.add(m2); + this.surprise = surprise; + this.exceedsScore = exceedsScore; + // todo: possibly just put elements in the list in a right order + Collections.sort(this.marks); + Collections.reverse(this.marks); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Mark mark = (Mark) o; + + if (exceedsScore != mark.exceedsScore) return false; + if (surprise != mark.surprise) return false; + if (marks != null ? !marks.equals(mark.marks) : mark.marks != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = marks != null ? marks.hashCode() : 0; + result = 31 * result + (surprise ? 1 : 0); + result = 31 * result + (exceedsScore ? 1 : 0); + return result; + } + + @Override + public String toString() { + return ""Mark{"" + + ""marks="" + marks + + "", surprise="" + surprise + + "", exceedsScore="" + exceedsScore + + '}'; + } + } +} +" +A22184,"package com.google.codejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class DancingGooglers { + public static void main(String[] args) throws FileNotFoundException { + new DancingGooglers().run(); + } + + private static class Data { + @Override + public String toString() { + return ""Data [googlers="" + googlers + "", surprisingTriplets="" + + surprisingTriplets + "", p="" + p + "", totals="" + + Arrays.toString(totals) + ""]""; + } + public int googlers; + public int surprisingTriplets; + public int p; + public Integer[] totals; + + } + + private void run() throws FileNotFoundException { + Data[] data = parseInput(""input""); + Integer[] result = solve(data); + printResult(result, ""output""); + } + + private Integer[] solve(Data[] data) { + Integer[] result = new Integer[data.length]; + for (int i = 0; i < data.length; i++) { + result[i] = solve(data[i]); +// System.out.println(""Max number of Googlers with p: "" + result[i]); + } + return result; + } + + private Integer solve(Data data) { +// System.out.println(data); + + int counter = 0; + int availableSurpises = data.surprisingTriplets; + + for (Integer total : data.totals) { + if (data.p == 0) { +// System.out.println(""Googler with total="" + total + "" has scored minimum of "" + data.p); + counter++; + } else + if (total >= Math.max(1, data.p*3 - 2)) { +// System.out.println(""Googler with total="" + total + "" has scored minimum of "" + data.p); + counter++; + } else if (availableSurpises > 0 && total >= Math.max(1, data.p*3 - 4)){ +// System.out.println(""Googler with total="" + total + "" might scored minimum of "" + data.p + "" with suprising score""); + counter++; availableSurpises--; + } else { +// System.out.println(""Googler with total="" + total + "" couldn't score minimum of "" + data.p); + } + } + + return counter; + } + + private void printResult(Integer[] result, String path) throws FileNotFoundException { + PrintWriter p = new PrintWriter(new File(path)); + try { + for (int i = 1; i < result.length+1; i++) { + p.format(""Case #%d: %d\n"", i, result[i-1]); + } + } finally { + p.close(); + } + } + + private Data[] parseInput(String path) throws FileNotFoundException { + Scanner scanner = new Scanner(new File(path)); + try { + Data[] input = new Data[scanner.nextInt()]; + for (int i = 0; i < input.length; i++) { + scanner.nextLine(); // skip to the next line + Data data = new Data(); + data.googlers = scanner.nextInt(); + data.surprisingTriplets = scanner.nextInt(); + data.p = scanner.nextInt(); + + data.totals = new Integer[data.googlers]; + for (int g = 0; g < data.googlers; g++) { + data.totals[g] = scanner.nextInt(); + } + input[i] = data; + } + return input; + } finally { + scanner.close(); + } + } +} +" +A21081,"package com.google; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +public class DancingWithGooglers { + + public static void main(String[] args) throws Exception{ + DancingWithGooglers s = new DancingWithGooglers(); + s.solve(); + + } + public void solve() throws Exception + { + int lines = Integer.parseInt(readLine()); + for(int i=0;i= n1) + count++; + else if(n == n2 || n == n3) + count++; + else if(n == n4 || n == n5) + { + if(S > 0) + { + count++; + S--; + } + } + } + if(i == lines-1) + writeLine(""Case #"" + (i+1) + "": "" + count); + else + writeLine(""Case #"" + (i+1) + "": "" + count + ""\n""); + } + o.close(); + } + BufferedReader f = null; + public String readLine() throws Exception + { + if(f == null) + f = new BufferedReader(new FileReader(new File(""C:\\Users\\raj617\\workspace\\srm\\dat\\B-large.in""))); + return f.readLine(); + } + BufferedWriter o = null; + public void writeLine(String line) throws Exception + { + if(o == null) + o = new BufferedWriter(new FileWriter(new File(""C:\\Users\\raj617\\workspace\\srm\\dat\\out.txt""))); + o.write(line ); + o.flush(); + } +} +" +A21085,"import java.io.*; +import java.util.*; +class Source3 +{ + public static void main(String[] args) throws IOException + { + String s,word,buffer; + FileReader input = new FileReader(""B-large.in""); + BufferedReader in = new BufferedReader(input); + File file = new File(""B-large.out""); + BufferedWriter out = new BufferedWriter(new FileWriter(file)); + + s = in.readLine(); + int count= Integer.parseInt(s); + + int i=1; + while ((s = in.readLine()) != null && s.length() != 0) + { + out.write(""Case #""+(i++)+"": ""); + Scanner scan =new Scanner(s); + + + int N =Integer.parseInt(scan.next()); + int S=Integer.parseInt(scan.next()); + int p=Integer.parseInt(scan.next()); + int[] t =new int[200]; + + for(int x=0;x=0&&pair[i][0]<=10&&pair[i][1]>=0&&pair[i][1]<=10) + { + check=true; + //System.out.println("" ""+pair[i][0]+"" ""+pair[i][1]); + } + } + } + + + + + return check; + } +} +" +A20732,"package com.rahul.codejam; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Scanner; + +/** + * Hello world! + * + */ +public class App +{ + private int inputlength; + private int counter; + + public App(String filename) { + fFileName = filename; + } + + public static void main( String[] args ) throws IOException + { + String fileName = args[0]; + String encoding = ""utf-8""; + App test = new App(fileName); + test.process(); + } + + protected void process() throws IOException { + log(""Reading from file.""); + + StringBuilder text = new StringBuilder(); + String NL = System.getProperty(""line.separator""); + Scanner scanner = new Scanner(new FileInputStream(fFileName), fEncoding); + try { + while (scanner.hasNextLine()) { + if (inputlength == 0) { + inputlength = Integer.parseInt(scanner.nextLine()); + } else { + counter++; + String output = String.format(""Case #%d: %s"", counter,processLine(scanner.nextLine())); + System.out.println(output); + text.append(output + NL); + } + //text.append(scanner.nextLine() + NL); + } + log(""Writing to file named "" + fFileName+"".out"" + "". Encoding: "" + fEncoding); + Writer out = new OutputStreamWriter(new FileOutputStream(fFileName + "".out""), fEncoding); + try { + out.write(text.toString()); + } + finally { + out.close(); + } + } finally { + scanner.close(); + } + log(""Text read in: "" + text); + } + + protected String processLine(String s) { + //Logic goes here + String comp[] = s.split("" ""); + int googlers = Integer.parseInt(comp[0]); + int maxsurprises = Integer.parseInt(comp[1]); + int surprises = 0; + int chasingScore = Integer.parseInt(comp[2]); + int googlersGotChasingScores = 0; + String scores[] = Arrays.copyOfRange(comp, 3, comp.length); + System.out.println(""scores length: "" + scores.length); + for(int i = 0; i < scores.length && i < googlers; i++) { + if(checkChasingScore(Integer.parseInt(scores[i]), chasingScore)) { + googlersGotChasingScores++; + } else if(surprises < maxsurprises) { + if(checkChasingScoreWithSurprise(Integer.parseInt(scores[i]), chasingScore)) { + surprises++; + googlersGotChasingScores++; + } + } + } + System.out.print(googlersGotChasingScores); + return googlersGotChasingScores+""""; + } + + protected boolean checkChasingScore(int totalScore, int chasingScore) { + boolean gotScore = false; + switch (totalScore %3) { + case 0: + gotScore = totalScore/3 >= chasingScore; + break; + case 1: + case 2: + if(totalScore/3 + 1 <= totalScore) + gotScore = (totalScore/3 + 1) >= chasingScore; + break; + } + return gotScore; + } + + protected boolean checkChasingScoreWithSurprise(int totalScore, int chasingScore) { + boolean gotScore = false; + switch (totalScore % 3) { + case 0: + case 1: + if(totalScore/3 + 1 <= totalScore) + gotScore = (totalScore/3 + 1) >= chasingScore; + break; + case 2: + if(totalScore/3 + 2 <= totalScore) + gotScore = (totalScore/3 + 2) >= chasingScore; + break; + } + return gotScore; + } + +// PRIVATE + private final String fFileName; + private final String fEncoding = ""utf-8""; + + private void log(String aMessage) { + System.out.println(aMessage); + } +} +" +A22784,"package google.contest.C; + +import google.loader.Challenge; +import google.problems.AbstractChallenge; + +import java.util.HashSet; +import java.util.Set; + +public class CChallenge extends AbstractChallenge implements Challenge { + + private int B; + private int A; + private int num; + Setpairs ; + public CChallenge(int number, String line) { + super(number); + num=0; + + pairs = new HashSet(); + + String[] tokens = line.split("" ""); + + A = Integer.parseInt(tokens[0]); + B = Integer.parseInt(tokens[1]); + int i=0; + for( i=A ; i<=B; i++){ + calcFor(i); + } + + setResult(""""+num); + } + + private void calcFor(int i) { + String numString = """"+i; + + for(int j=1; j<= numString.length()-1; j++){ + String first = numString.substring(0,j); + String second = numString.substring(j); + String third = second+first; + check(i, third); + + } + } + + private void check(int i, String third) { + if(third.startsWith(""0"")){ + return; + } + int j = Integer.parseInt(third); + if(A<=i && i triplesSum; + + @Override + public void addLine(String line) { + String[] temp = line.split("" ""); + + sTriplets = Integer.parseInt(temp[1]); + scoreBase = Integer.parseInt(temp[2]); + + triplesSum = new ArrayList(temp.length - 3); + for (int i = 3; i < temp.length; i++) { + triplesSum.add(Integer.parseInt(temp[i])); + } + } + + private int notSTriplesThatFit() { + int qt = 0, currentIndex; + for (int i = 0; i - qt < triplesSum.size(); i++) { + currentIndex = i - qt; + if (fitNotSurprising(triplesSum.get(currentIndex))) { + triplesSum.remove(currentIndex); + qt++; + } + } + return qt; + } + + private int surprisingTriplesThatFit() { + if (sTriplets <= 0) { + return 0; + } + int qt = 0; + for (Integer num : triplesSum) { + if (fitSurprising(num)) { + qt++; + if (qt >= sTriplets) { + break; + } + } + } + return qt; + } + + public static int getMaxScoreNotSurprising(int num) { + return num % 3 == 0 ? num / 3 : num / 3 + 1; + } + + private boolean fitNotSurprising(int num) { + return getMaxScoreNotSurprising(num) >= scoreBase; + } + + public static int getMaxScoreSurprising(int num) { + int maxScore = 0; + if (num > 0) { + maxScore = num % 3 == 0 ? num / 3 + 1 : num / 3 + num % 3; + } + return maxScore; + } + + private boolean fitSurprising(int num) { + return getMaxScoreSurprising(num) >= scoreBase; + } + + @Override + public void printSolution() { + System.err.println(""Case #"" + getOrder() + "": "" + result); + } + + int result; + + @Override + public CaseSolver process() { + result = notSTriplesThatFit() + surprisingTriplesThatFit(); + return this; + } + + @Override + public void initializeVars() { + // TODO Auto-generated method stub + + } + +} +" +A22464,"import java.io.IOException; +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.List; + +public class MinimumScalar extends JamProblem { + public static void main(String[] args) throws IOException { + MinimumScalar p = new MinimumScalar(); + p.go(); + } + @Override + String solveCase(JamCase jamCase) { + MSCase c= (MSCase) jamCase; + Arrays.sort(c.a); + Arrays.sort(c.b); + + BigDecimal b = new BigDecimal(0); + for (int i=0; i< c.lengh; i++) { + BigDecimal aaa = new BigDecimal(c.a[i]); + BigDecimal bbb = new BigDecimal(c.b[c.lengh - i - 1]); + b = b.add(aaa.multiply(bbb)); + } + return """" + b; + } + + @Override + JamCase parseCase(List file, int line) { + MSCase c= new MSCase(); + c.lineCount=3; + int i = line; + c.lengh = Integer.parseInt(file.get(i++)); + c.a = JamUtil.parseIntList(file.get(i++),c.lengh); + c.b = JamUtil.parseIntList(file.get(i++),c.lengh); + return c; + } +} + +class MSCase extends JamCase { + int lengh; + int[] a; + int[] b; +} + +" +A20991,"package fixjava; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class CollectionUtils { + + /** + * @return the single value in the collection, throws an exception if there isn't exactly one item. + * @throws IllegalArgumentException + * if there is more than one value in the set. + */ + public static T getSingleVal(Collection collection) { + if (collection.size() != 1) + throw new IllegalArgumentException(collection.size() + "" objects in collection, expected exactly 1""); + T ret = null; + for (T val : collection) { + ret = val; + break; + } + return ret; + } + + /** + * @return the first value returned by an iterator on the collection, throws an exception if there isn't exactly one item. + * @throws IllegalArgumentException + * if collection is empty + */ + public static T getFirstVal(Collection collection) { + if (collection.size() == 0) + throw new IllegalArgumentException(collection.size() + "" objects in collection, expected at least 1""); + T ret = null; + for (T val : collection) { + ret = val; + break; + } + return ret; + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** + * Pass values in an Iterable through a function to produce an ArrayList of mapped values, one output value generated per input + * value. Returns null if input is null. + */ + public static ArrayList map(Iterable values, Lambda mapFunction) { + if (values == null) + return null; + ArrayList result = new ArrayList(); + for (S val : values) + result.add(mapFunction.apply(val)); + return result; + } + + /** + * Pass values in an Iterable through a function to produce an ArrayList of mapped values, one output value generated per input + * value. Returns null if input is null. + */ + public static ArrayList map(S[] values, Lambda mapFunction) { + if (values == null) + return null; + ArrayList result = new ArrayList(); + for (S val : values) + result.add(mapFunction.apply(val)); + return result; + } + + /** + * Pass values in an Iterable through a function to produce an ArrayList of mapped values, zero or more output values generated + * per input value. Returns null if input is null. + */ + public static ArrayList mapMultiple(Iterable values, Lambda> mapFunction) { + if (values == null) + return null; + ArrayList result = new ArrayList(); + for (S val : values) + result.addAll(mapFunction.apply(val)); + return result; + } + + /** + * Pass values in an Iterable through a function to produce a HashSet of mapped values, one output value generated per input + * value. Returns null if input is null. + */ + public static HashSet mapSet(Iterable values, Lambda mapFunction) { + if (values == null) + return null; + HashSet result = new HashSet(); + for (S val : values) + result.add(mapFunction.apply(val)); + return result; + } + + /** + * Pass values in an Iterable through a function to produce a HashSet of mapped values, one output value generated per input + * value. Returns null if input is null. + */ + public static HashSet mapSet(S[] values, Lambda mapFunction) { + if (values == null) + return null; + HashSet result = new HashSet(); + for (S val : values) + result.add(mapFunction.apply(val)); + return result; + } + + /** + * Pass values in an Iterable through a function to produce a HashSet of mapped values, zero or more output values generated per + * input value. Returns null if input is null. + */ + public static HashSet mapSetMultiple(Iterable values, Lambda> mapFunction) { + if (values == null) + return null; + HashSet result = new HashSet(); + for (S val : values) + result.addAll(mapFunction.apply(val)); + return result; + } + + // --------------------------------------------------------------------------------------------------------------------- + + public static HashSet filterSet(Iterable values, Lambda filterFunction) { + if (values == null) + return null; + HashSet result = new HashSet(); + for (T val : values) + if (filterFunction.apply(val)) + result.add(val); + return result; + } + + public static ArrayList filter(Iterable values, Lambda filterFunction) { + if (values == null) + return null; + ArrayList result = new ArrayList(); + for (T val : values) + if (filterFunction.apply(val)) + result.add(val); + return result; + } + + public static HashSet filterSet(T[] values, Lambda filterFunction) { + if (values == null) + return null; + HashSet result = new HashSet(); + for (T val : values) + if (filterFunction.apply(val)) + result.add(val); + return result; + } + + public static ArrayList filter(T[] values, Lambda filterFunction) { + if (values == null) + return null; + ArrayList result = new ArrayList(); + for (T val : values) + if (filterFunction.apply(val)) + result.add(val); + return result; + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** + * Iterate through multiple Iterables of the same element type, e.g. for (Integer i : CollectionUtils.iterateThroughAllOf(x, y, + * z)) { } + * + * N.B. you will get a warning ""Type safety: A generic array of type Iterable is created for a Varargs parameter"" (lame + * Java). + */ + @SafeVarargs + public static Iterable iterateThroughAllOf(final Iterable... iterables) { + if (iterables.length == 0) { + return (Iterable) new ArrayList(); + } else { + return new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + Iterable[] iters = iterables; + int iterIdx = -1; + Iterator currIter = null; + + private void advanceIfNecessary() { + if (currIter == null || (iterIdx < iters.length - 1 && !currIter.hasNext())) + currIter = iterables[++iterIdx].iterator(); + } + + @Override + public boolean hasNext() { + advanceIfNecessary(); + return iterIdx < iters.length && (iterIdx < iters.length - 1 || currIter.hasNext()); + } + + @Override + public T next() { + advanceIfNecessary(); + if (iterIdx == iters.length) + throw new RuntimeException(""Out of elements""); + return currIter.next(); + } + + @Override + public void remove() { + advanceIfNecessary(); + if (iterIdx == iters.length) + throw new RuntimeException(""Out of elements""); + else + currIter.remove(); + } + }; + } + }; + } + } + + /** + * Iterate through multiple Arrays of the same element type, e.g. for (Integer i : CollectionUtils.iterateThroughAllOf(x, y, z)) + * { } + */ + @SafeVarargs + public static Iterable iterateThroughAllOf(final T[]... arrays) { + if (arrays.length == 0) { + return (Iterable) new ArrayList(); + } else { + return new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + T[][] arrs = arrays; + int arrIdx = 0, arrSubIdx = 0; + + private void advanceIfNecessary() { + if (arrIdx < arrs.length && arrSubIdx == arrs[arrIdx].length) { + arrIdx++; + arrSubIdx = 0; + } + } + + @Override + public boolean hasNext() { + advanceIfNecessary(); + return arrIdx < arrs.length && (arrIdx < arrs.length - 1 || arrSubIdx < arrs[arrIdx].length); + } + + @Override + public T next() { + advanceIfNecessary(); + if (arrIdx == arrs.length) + throw new RuntimeException(""Out of elements""); + return arrs[arrIdx][arrSubIdx++]; + } + + @Override + public void remove() { + throw new RuntimeException(""Not implemented""); + } + }; + } + }; + } + } + + /** + * Iterate through multiple Iterables of the same element type (skipping over null iterables, *not* null elements), e.g. for + * (Integer i : CollectionUtils.iterateThroughAllOf(x, y, z)) { } + * + * N.B. you will get a warning ""Type safety: A generic array of type Iterable is created for a Varargs parameter"" (lame + * Java). + */ + @SuppressWarnings(""unchecked"") + public static Iterable iterateThroughAllOfIgnoringNulls(Iterable... iterables) { + ArrayList> filter = filter(iterables, new Lambda, Boolean>() { + @Override + public Boolean apply(Iterable param) { + return param != null; + } + }); + Iterable[] nonNulls = new Iterable[filter.size()]; + filter.toArray(nonNulls); + return iterateThroughAllOf(nonNulls); + } + + /** + * Iterate through multiple arrays of the same element type (skipping over null arrays, *not* null elements), e.g. for (Integer + * i : CollectionUtils.iterateThroughAllOf(x, y, z)) { } + */ + @SuppressWarnings(""unchecked"") + public static Iterable iterateThroughAllOfIgnoringNulls(T[]... arrays) { + ArrayList filter = filter(arrays, new Lambda() { + @Override + public Boolean apply(T[] param) { + return param != null; + } + }); + Iterable[] nonNulls = new Iterable[filter.size()]; + filter.toArray(nonNulls); + return iterateThroughAllOf(nonNulls); + } + + // public static void main(String[] args) { + // ArrayList x = new ArrayList(); + // ArrayList y = new ArrayList(); + // ArrayList z = new ArrayList(); + // x.add(1); + // x.add(2); + // x.add(3); + // y.add(19); + // y.add(23); + // z.add(100); + // z.add(999); + // for (Integer i : iterateThroughAllOf(x, y, z)) + // System.out.println(i); + // Integer[] a = new Integer[3]; + // Integer[] b = new Integer[2]; + // a[0] = 10; + // a[1] = 11; + // a[2] = 12; + // b[0] = 7; + // b[1] = 8; + // for (Integer i : iterateThroughAllOf(a, b)) + // System.out.println(i); + // } + + /** + * Iterate through a varargs list of iterable objects of type T, and return all the objects in a list. Null iterables are + * skipped. + */ + @SafeVarargs + public static ArrayList toListIgnoringNulls(Iterable... iterables) { + ArrayList result = new ArrayList(); + for (T item : iterateThroughAllOfIgnoringNulls(iterables)) + result.add(item); + return result; + } + + /** + * Iterate through a varargs list of iterable objects of type T, and return all the objects in a set (removing duplicates). Null + * iterables are skipped. + */ + @SafeVarargs + public static HashSet toSetIgnoringNulls(Iterable... iterables) { + return new HashSet(toListIgnoringNulls(iterables)); + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** + * Look up keys in the map, and return a collection of the corresponding values. Returns null if 'keys' is null. + * + * @throw IllegalArgumentException if key doesn't exist in map or if a key is null, depending on params. + */ + public static > C lookup(Collection keys, Map map, + LambdaVoid applyIfKeyIsNullWithoutAddingValue, Lambda applyIfKeyIsNullAndAddReturnedValue, + LambdaVoid applyWhenKeyDoesntExistWithoutAddingValue, Lambda applyWhenKeyDoesntExistAndAddReturnedValue, + C result) { + if (keys == null) + return null; + for (K key : keys) { + V val = null; + boolean addValue = false; + if (applyIfKeyIsNullWithoutAddingValue != null && key == null) { + applyIfKeyIsNullWithoutAddingValue.apply(key); + } else if (applyIfKeyIsNullAndAddReturnedValue != null && key == null) { + val = applyIfKeyIsNullAndAddReturnedValue.apply(key); + addValue = true; + } else if (applyWhenKeyDoesntExistWithoutAddingValue != null && !map.containsKey(key)) { + applyWhenKeyDoesntExistWithoutAddingValue.apply(key); + } else if (applyWhenKeyDoesntExistAndAddReturnedValue != null && !map.containsKey(key)) { + val = applyWhenKeyDoesntExistAndAddReturnedValue.apply(key); + addValue = true; + } else { + val = map.get(key); + addValue = true; + } + if (addValue) + result.add(val); + } + return result; + } + + /** + * Look up keys in the map, and return an ArrayList of the corresponding values. Returns null if 'keys' is null. + * + * @throw IllegalArgumentException if key doesn't exist in map or if a key is null, depending on params. + */ + public static ArrayList lookup(Collection keys, Map map, boolean throwExceptionIfKeyNull, + boolean throwExceptionIfKeyDoesntExist) { + if (keys == null) + return null; + return lookup(keys, map, throwExceptionIfKeyNull ? new LambdaVoid() { + @Override + public void apply(K key) { + throw new IllegalArgumentException(""Key is null""); + } + } : null, null, throwExceptionIfKeyDoesntExist ? new LambdaVoid() { + @Override + public void apply(K key) { + throw new IllegalArgumentException(""Could not find key "" + key + "" in map""); + } + } : null, null, new ArrayList()); + } + + /** + * Look up keys in the map, and return an ArrayList of the corresponding values. Performs no checking. Returns null if 'keys' is + * null. + */ + public static ArrayList lookup(Collection keys, Map map) { + if (keys == null) + return null; + ArrayList vals = new ArrayList(keys.size()); + for (K key : keys) { + // Simple version for speed + V val = map.get(key); + vals.add(val); + } + return vals; + } + + /** + * Look up keys in the map, and return an ArrayList of the corresponding values. Applies the given function if the key doesn't + * exist. Returns null if 'keys' is null. + */ + public static ArrayList lookup(Collection keys, Map map, LambdaVoid applyWhenKeyDoesntExist) { + return lookup(keys, map, null, null, applyWhenKeyDoesntExist, null, new ArrayList()); + } + + /** + * Look up keys in the map, and return an ArrayList of the corresponding values. Applies the given function if the key doesn't + * exist to produce a default value. Returns null if 'keys' is null. + */ + public static ArrayList lookup(Collection keys, Map map, Lambda applyWhenKeyDoesntExistToGetDefaultVal) { + return lookup(keys, map, null, null, null, applyWhenKeyDoesntExistToGetDefaultVal, new ArrayList()); + } + + /** + * Look up keys in the map, and return a HashSet of the corresponding values. Returns null if 'keys' is null. + * + * @throw IllegalArgumentException if key doesn't exist in map or if a key is null, depending on params. + */ + public static HashSet lookupAsSet(Collection keys, Map map, boolean throwExceptionIfKeyNull, + boolean throwExceptionIfKeyDoesntExist) { + if (keys == null) + return null; + return lookup(keys, map, throwExceptionIfKeyNull ? new LambdaVoid() { + @Override + public void apply(K key) { + throw new IllegalArgumentException(""Key is null""); + } + } : null, null, throwExceptionIfKeyDoesntExist ? new LambdaVoid() { + @Override + public void apply(K key) { + throw new IllegalArgumentException(""Could not find key "" + key + "" in map""); + } + } : null, null, new HashSet()); + } + + /** + * Look up keys in the map, and return a HashSet of the corresponding values. Performs no checking. Returns null if 'keys' is + * null. + */ + public static HashSet lookupAsSet(Collection keys, Map map) { + if (keys == null) + return null; + HashSet vals = new HashSet(keys.size()); + for (K key : keys) { + // Simple version for speed + V val = map.get(key); + vals.add(val); + } + return vals; + } + + /** + * Look up keys in the map, and return a HashSet of the corresponding values. Applies the given function if the key doesn't + * exist. Returns null if 'keys' is null. + */ + public static HashSet lookupAsSet(Collection keys, Map map, LambdaVoid applyWhenKeyDoesntExist) { + return lookup(keys, map, null, null, applyWhenKeyDoesntExist, null, new HashSet()); + } + + /** + * Look up keys in the map, and return a HashSet of the corresponding values. Applies the given function if the key doesn't + * exist to produce a default value. Returns null if 'keys' is null. + */ + public static HashSet lookupAsSet(Collection keys, Map map, + Lambda applyWhenKeyDoesntExistToGetDefaultVal) { + return lookup(keys, map, null, null, null, applyWhenKeyDoesntExistToGetDefaultVal, new HashSet()); + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** Take the union of all items in all passed collections/Iterables */ + public static HashSet union(Iterable> iterables) { + HashSet result = new HashSet(); + for (Iterable iterable : iterables) + for (T item : iterable) + result.add(item); + return result; + } + + /** Put each item in an array into a set. c.f. makeSet(), toSetIgnoringNulls(). */ + public static HashSet union(T[] items) { + HashSet result = new HashSet(); + for (T item : items) + result.add(item); + return result; + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** Varargs constructor for a typed set */ + @SafeVarargs + public static HashSet makeSet(T... items) { + HashSet set = new HashSet(items.length); + for (T it : items) + set.add(it); + return set; + } + + /** Varargs constructor for a typed list */ + @SafeVarargs + public static ArrayList makeList(T... items) { + ArrayList list = new ArrayList(items.length); + for (T it : items) + list.add(it); + return list; + } + + /** Varargs constructor for a typed list, specifying initial capacity */ + @SafeVarargs + public static ArrayList makeListWithInitialCapacity(int initialCapacity, T... items) { + ArrayList list = new ArrayList(Math.max(items.length, initialCapacity)); + for (T it : items) + list.add(it); + return list; + } + + // --------------------------------------------------------------------------------------------------------------------- + + public static ArrayList> mapToListOfPairs(Map map) { + ArrayList> result = new ArrayList>(); + for (Entry ent : map.entrySet()) + result.add(Pair.make(ent.getKey(), ent.getValue())); + return result; + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** + * Generate a sorted ArrayList of values from any collection. Does not sort in-place, but rather sorts a copy of the collection. + */ + public static > ArrayList sortCopy(Collection vals) { + ArrayList sorted = new ArrayList(vals); + Collections.sort(sorted); + return sorted; + } + + /** + * Generate a sorted ArrayList of values from any collection, using the specified comparator. Does not sort in-place, but rather + * sorts a copy of the collection. + */ + public static ArrayList sortCopy(Collection vals, Comparator comparator) { + ArrayList sorted = new ArrayList(vals); + Collections.sort(sorted, comparator); + return sorted; + } + + /** + * Make a comparator by passing in a lambda that simply returns a comparable field for an object, e.g. + * + * + * CollectionUtils.sort(nodeList, CollectionUtils.makeComparator(new Lambda() { + * public String apply(Node obj) { + * return obj.getName(); + * } + * }); + * + * + * This is not much shorter than declaring a comparator in the sort call (and has more overhead), but may be a little simpler or + * could reduce code duplication in the comparator. + * + * @param + * The type of the objects to compare + * @param + * The type of the field to compare + * @param getFieldToCompare + * A simple getter for the field to compare + * @return A comparator that can be used for sorting + */ + public static > Comparator makeComparator(final Lambda getFieldToCompare) { + return new Comparator() { + @Override + public int compare(O o1, O o2) { + return getFieldToCompare.apply(o1).compareTo(getFieldToCompare.apply(o2)); + } + }; + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** + * Build a map from objects in an Iterable to an index mapping that object to its index in the Iterable. Objects must be unique + * (!equals()) or an exception is thrown. + */ + public static HashMap buildIndex(Iterable collection) { + HashMap map = new HashMap(); + for (IndexedItem it : IndexedItem.iterate(collection)) + if (map.put(it.getItem(), it.getIndex()) != null) + throw new IllegalArgumentException( + ""Duplicate object in collection, cannot uniquely map objects to indices (try buildIndexMulti()?): "" + + it.getItem()); + return map; + } + + /** + * Build a map from objects in an array to an index mapping that object to its index in the array. Objects must be unique + * (!equals()) or an exception is thrown. + */ + public static HashMap buildIndex(T[] arr) { + HashMap map = new HashMap(); + for (IndexedItem it : IndexedItem.iterate(arr)) + if (map.put(it.getItem(), it.getIndex()) != null) + throw new IllegalArgumentException( + ""Duplicate object in collection, cannot uniquely map objects to indices (try buildIndexMulti()?): "" + + it.getItem()); + return map; + } + + /** Build a map from objects in a collection to a list of indices containing equal objects. */ + public static MultiMapKeyToList buildIndexMulti(Iterable collection) { + MultiMapKeyToList map = new MultiMapKeyToList(); + for (IndexedItem it : IndexedItem.iterate(collection)) { + T o = it.getItem(); + map.put(o, it.getIndex()); + } + return map; + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** + * Count the number of .equal() occurrences of objects of type T in the collection, and produce histogram of the results. The + * histogram can be sorted in order of ascending count if desired. + */ + public static ArrayList> countEqualOccurrences(Iterable collection) { + CountedSet set = new CountedSet(collection); + ArrayList> result = new ArrayList>(); + for (Entry ent : set.iteratableWithCounts()) + result.add(Pair.make(ent.getKey(), ent.getValue())); + return result; + } + + /** + * Build a histogram of the number of unique objects that occur each number of times. Objects occur multiple times if there are + * multiple instances that match with .equals(). Returns a Pair with number of occurrences of each unique + * object as left and number of unique objects with that number of occurrences as right. + */ + public static ArrayList> buildHistogramOfNumObjectsThatOccurGivenNumberOfTimesSparse( + Iterable collection) { + // Count unique occurrences of the objects of type T + ArrayList> counts = countEqualOccurrences(collection); + // Now count unique occurrences each of the count values to build the histogram + ArrayList> countCounts = countEqualOccurrences(Pair.getAllRights(counts)); + // Sort the result in order of number of occurrences (i.e. left) + Pair.sortPairsByLeft(countCounts, true); + return countCounts; + } + + /** + * Build a histogram of the number of unique objects that occur each number of times. Objects occur multiple times if there are + * multiple instances that match with .equals(). Returns an array with the number of occurrences of each unique object as the + * index and number of unique objects with that number of occurrences as the value of the array at that index. + */ + public static int[] buildHistogramOfNumObjectsThatOccurGivenNumberOfTimesNonSparse(Iterable collection) { + // Build histogram + ArrayList> histList = buildHistogramOfNumObjectsThatOccurGivenNumberOfTimesSparse(collection); + // Desparsify into an array and return + int maxAbscissa = histList.isEmpty() ? -1 : histList.get(histList.size() - 1).getLeft(); + int[] result = new int[maxAbscissa + 1]; + for (Pair pair : histList) + result[pair.getLeft()] = pair.getRight(); + return result; + } + + // --------------------------------------------------------------------------------------------------------------------- + + /** Reverse a list */ + public static ArrayList reverse(List list) { + ArrayList result = new ArrayList(list.size()); + for (int i = list.size() - 1; i >= 0; --i) + result.add(list.get(i)); + return result; + } + + /** + * Arrayify/rectangularize a list of lists, inserting the given filler element to make the result rectangular if lists are not + * the same length + */ + public static ArrayList> rectangularize(List> input, T filler) { + int numRows = input.size(); + int numCols = 0; + for (int i = 0; i < numRows; i++) + numCols = Math.max(numCols, input.get(i).size()); + ArrayList> output = new ArrayList>(numRows); + for (int i = 0; i < numRows; i++) { + ArrayList outRow = new ArrayList(input.get(i)); + output.add(outRow); + while (outRow.size() < numCols) + outRow.add(filler); + } + return output; + } + + public static MultiMapKeyToSet invertMap(HashMap map) { + MultiMapKeyToSet result = new MultiMapKeyToSet(); + for (Entry ent : map.entrySet()) + result.put(ent.getValue(), ent.getKey()); + return result; + } + +} +" +A20320,"package sample; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class SampleMain { + + public static void main(String[] args) throws Exception { + String linesFile = //args[0]; + ""lines.txt""; + String[] lines = getLines(linesFile); + for (int i = 0; i < lines.length; i++) { + if (i != 0) { + System.out.println(""Case #"" + i + "": "" + getOutput(lines[i])); + } + } + } + + public static String[] getLines(String pathName) throws Exception { + List lines = new ArrayList(); + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(pathName)), ""UTF-8"")); + String line; + while ((line = br.readLine()) != null) { + lines.add(line); + } + br.close(); + return (String[]) lines.toArray(new String[0]); + } + + public static int getOutput(String line) throws Exception { + String[] value = line.split("" ""); + int n = Integer.valueOf(value[0]); + int s = Integer.valueOf(value[1]); + int p = Integer.valueOf(value[2]); + int countS = 0; + int countP = 0; + for (int i = 0; i < n; i++) { + int t = Integer.valueOf(value[i + 3]); + int x = t / 3; + int y = t % 3; + switch (y) { + case 0: + if (x >= p) { + countP++; + } else if (x + 1 >= p) { + if (x != 0 && countS < s) { + countS++; + countP++; + } + } + break; + case 1: + if (x + 1 >= p) { + countP++; + } + break; + case 2: + if (x + 1 >= p) { + countP++; + } else if (x + 2 >= p) { + if (countS < s) { + countS++; + countP++; + } + } + break; + default: + break; + } + } + + return countP; + } + +} +" +A21183,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam.lib.converters; + +import com.isotopeent.codejam.lib.InputConverter; +import com.isotopeent.codejam.lib.Utils; + +public class IntArrayLine implements InputConverter { + + private int length; + private int[] input; + private int[] inputBuffer; + + /** + * fixed length arrays + */ + public IntArrayLine(int length) { + this.length = length; + } + + /** + * dynamic length arrays + */ + public IntArrayLine(int[] buffer) { + inputBuffer = buffer; + } + + @Override + public boolean readLine(String data) { + if (length > 0) { + input = new int[length]; + input = Utils.convertToIntArray(data, length); + } else { + int count = Utils.convertToIntArray(data, inputBuffer); + input = new int[count]; + System.arraycopy(inputBuffer, 0, input, 0, count); + } + return false; + } + + @Override + public int[] generateObject() { + return input; + } + +} +" +A21028,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class B { + public static final String FILENAME = ""B-large""; + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""src/""+FILENAME+"".in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""src/""+FILENAME+"".out"")); + Scanner s = new Scanner(in); + int T = s.nextInt(); + for(int i = 1; i <= T; i++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = Math.min(10, s.nextInt()); + int ok = 0; + int maybe = 0; + for(int j = 0; j < N; j++) { + int total = s.nextInt(); + if(total >= p + 2*Math.max(0, p-1)) { + ok++; + } + else if(total >= p + 2*Math.max(0, p-2)) { + maybe++; + } + } + int ret = ok + Math.min(maybe, S); + out.write(""Case #""+i+"": ""+ret+""\n""); + } + in.close(); + out.close(); + } +} +" +A20158,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Scanner; + + +/** + * @author Paul LaMotte + * + */ +public class GooglerDance { + + public static void main(String[] args) { + + Scanner in; + try { + System.setOut(new PrintStream(new File(""qualB.out""))); + in = new Scanner(new File(""B-large.in"")); + int lines = Integer.parseInt(in.nextLine()); + for (int i = 0; i < lines; i++) { + int googlers = in.nextInt(); + int trips = in.nextInt(); + int best = in.nextInt(); + int count = 0; + ArrayList scores = new ArrayList(); + for (int j = 0; j < googlers; j++) { + int score = in.nextInt(); + int rem = score - best; + int tmp = (int)Math.floor(rem / 2); + if (score < best) { + continue; + } + if (best - tmp <= 1) { + count++; + } else if (best - tmp <= 2 && trips > 0) { + trips -= 1; + count++; + } + } + + System.out.printf(""Case #%d: %d\n"", i + 1, count); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } +} +" +A21782,"package qualificationround; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class ProblemBDancingGooglers { + + public ProblemBDancingGooglers() { + try { + FileReader fr = new FileReader(""B-large.in""); + BufferedReader br = new BufferedReader(fr); + + FileWriter fw = new FileWriter(""B-large.out""); + BufferedWriter bw = new BufferedWriter(fw); + + int numCases = Integer.parseInt(br.readLine()); + int caseNum = 1; + + String line = br.readLine(); + while (line != null) { + System.out.println(line); + int numGooglers = getNumGooglersFromLine(line); + int numSurprises = getNumSurprisesFromLine(line); + int bestScore = getBestScoreFromLine(line); + int[] scores = getScoresFromLine(line, numGooglers); + + int possibles = 0; + for (int i=0; i= bestScore) { + possibles++; + } else if (withSurprise >= bestScore && numSurprises > 0) { + possibles++; + numSurprises--; + } + } + + String output = ""Case #""+ caseNum; + output += "": ""+possibles; + + System.out.println(output); + bw.append(output); + if (caseNum != numCases) + bw.newLine(); + + caseNum++; + line = br.readLine(); + } + + bw.flush(); + bw.close(); + br.close(); + + } catch(Exception e) { + e.printStackTrace(); + } + } + + public int[] getScoresFromLine(String line, int numScores) { + int[] scores = new int[numScores]; + + int firstSpace = line.indexOf("" ""); + int secondSpace = line.indexOf("" "",firstSpace + 1); + int thirdSpace = line.indexOf("" "",secondSpace + 1); + + line = line.substring(thirdSpace + 1); + + String[] scoreStrings = line.split("" ""); + for (int i=0; i readLines(String fileName) { + List result = new ArrayList(); + FileReader in = null; + try { + in = new FileReader(fileName); + BufferedReader reader = new BufferedReader(in); + String line = null; + while ((line = reader.readLine()) != null) { + if (line.trim().length() > 0) { + result.add(line); + } + } + } catch (Exception ex) { + throw new RuntimeException(ex); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException ex) { + Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); + } + } + return result; + } + + public static void writeLines(String fileName, List lines) { + FileWriter writer = null; + try { + writer = new FileWriter(fileName); + PrintWriter printWriter = new PrintWriter(writer); + for (String line : lines) { + printWriter.println(line); + } + } catch (IOException ex) { + Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); + } finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException ex) { + Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + } +} +" +A21899," +public class Dancing_With_the_Googlers { + + public int solve1(int s, int p, int[] t) + { + int ans=0; + for (int i=0;i=p || a1>=p || a2>=p) + { + ans++; + next=true; + break; + } + } + + } + if(next) + break; + } + if(next) + continue; + for(int a0=0;a0<=t[i];a0++) + { + for(int a1=0;a0+a1<=t[i];a1++) + { + int a2=t[i]-a1-a0; + if(a2<0) + continue; + if(Math.abs(a0-a1)<=2 && Math.abs(a1-a2)<=2 && Math.abs(a0-a2)<=2) + if((Math.abs(a0-a1)==2 || Math.abs(a1-a2)==2 || Math.abs(a0-a2)==2) && s>0) + { + if(a0>=p || a1>=p || a2>=p) + { + s--; + ans++; + next=true; + break; + } + } + } + if(next) + break; + } + } + + return ans; + } + + public int solve(int s, int p, int[] t) + { + int whichContainsMoreThanP=0; + int ans=0; + for (int i=0;i=p) + ans++; + continue; + }else if(t[i]==1) + { + if(1>=p) + ans++; + continue; + } + + int reminder=t[i]%3; + int division=t[i]/3; + + switch(reminder) + { + case 0:// 1,2 or 0,0 + if(division>=p) + { + whichContainsMoreThanP++; + continue; + } + break; + case 1:// 2,2 or 0,1 + if(division+1>=p) + { + whichContainsMoreThanP++; + continue; + } + break; + case 2:// 0,2 or 1,1 + if(division+1>=p) + { + whichContainsMoreThanP++; + continue; + } + break; + default: + } + + switch(reminder) + { + case 0:// 1,2 or 0,0 + if(division-1+2>=p && s>0) + { + s--; + ans++; + } + break; + case 1:// 2,2 or 0,1 + if(division-1+2>=p && s>0) + { + s--; + ans++; + } + break; + case 2:// 0,2 or 1,1 + if(division+2>=p && s>0) + { + s--; + ans++; + } + break; + default: + } + + } + return ans+whichContainsMoreThanP; + } +} +/* + import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class Program { + + + public static void main(String[] args) { + + try { + FileWriter fileWriter=new FileWriter(""B-small-attempt0.out""); + FileReader fileReader=new FileReader(""B-small-attempt0.in""); + BufferedReader in = new BufferedReader(fileReader); + + int T= Integer.parseInt(in.readLine()); + for(int t=1;t<=T;t++) + { + String[] tokens= in.readLine().split("" ""); + int N= Integer.parseInt(tokens[0]); + int[] values=new int[N]; + int S= Integer.parseInt(tokens[1]); + int p= Integer.parseInt(tokens[2]); + + for(int n=0;n { + + private final int caseNumber; + + public JamCaseResolver(int caseNumber) { + this.caseNumber = caseNumber; + } + + @Override + public final String call() throws Exception { + return this.resolve(); + } + + protected abstract String resolve(); + + protected long[] parse(final String[] numbers) { + final long[] parsed = new long[numbers.length]; + for (int i = 0; i < numbers.length; i++) + parsed[i] = this.parse(numbers[i]); + return parsed; + } + + protected long parse(final String number) { + return Long.parseLong(number); + } + + protected int[] parseInt(final String[] numbers) { + final int[] parsed = new int[numbers.length]; + for (int i = 0; i < numbers.length; i++) + parsed[i] = this.parseInt(numbers[i]); + return parsed; + } + + protected int parseInt(final String number) { + return Integer.parseInt(number); + } + + protected long sum(final Iterable elements) { + long sum = 0; + for (final long element : elements) + sum += element; + return sum; + } + + protected long sum(final Long[] elements) { + return this.sum(Arrays.asList(elements)); + } + + protected String toMatrixString(final String matrixString) { + return matrixString.replaceAll(""\\},\\{"", ""\n"").replaceAll(""(^\\{\\{|\\}\\}$)|,"", """"); + } + + public int getCaseNumber() { + return caseNumber; + } + + @Override + public String toString() { + return ""JamCaseResolver [caseNumber="" + caseNumber + ""]""; + } + +} + +" +A21159,"package com.google.codejam; + +public class CodeJamTest { + public static void main(String[] args){ + Utils.run(DancingGoogler.class); + } +} + +" +A22955,"package cj2012.qual; + +import java.io.*; +import java.util.Arrays; + +public class ProblemB extends PrintWriter { + + private final static String PREFIX = ""ProblemB_""; + private final static String INPUT_FILE = PREFIX + ""in.txt""; + private final static String OUTPUT_FILE = PREFIX + ""out.txt""; + + private static final int BUFF_SIZE = 64 * 1024; + int pos = 0; + int len = -1; + final DataInputStream dis; + final byte[] b = new byte[BUFF_SIZE]; + + public static void main(String[] args) throws Exception { + ProblemB problem = new ProblemB(new BufferedOutputStream(System.out)); + problem.solve(); + problem.flush(); + problem.close(); + } + + public ProblemB(OutputStream os) throws FileNotFoundException { + super(new BufferedOutputStream(new FileOutputStream(OUTPUT_FILE))); + dis = new DataInputStream(new BufferedInputStream(new FileInputStream(INPUT_FILE))); + } + + public int read() { + if (pos >= len) { + pos = 0; + len = -1; + try { + len = dis.read(b); + } catch (IOException ex) { + } + } + return pos < len ? b[pos++] : -1; + } + + public int nextInt() throws IOException { + int ret = 0; + int ch = skipWhite(); + int sign = 1; + if (ch == '-') { + sign = -1; + ch = read(); + } + while (!isSpaceChar(ch) && ch != -1) { + ret *= 10; + ret += ch - '0'; + ch = read(); + } + return ret * sign; + } + + public long nextLong() throws IOException { + long ret = 0; + int ch = skipWhite(); + int sign = 1; + if (ch == '-') { + sign = -1; + ch = read(); + } + while (!isSpaceChar(ch) && ch != -1) { + ret *= 10; + ret += ch - '0'; + ch = read(); + } + return ret * sign; + } + + public int skipWhite() throws IOException { + int ch = read(); + while (true) { + if (ch == -1) { + return -1; + } + if (!isSpaceChar(ch)) { + return ch; + } + ch = read(); + } + } + + public boolean isSpaceChar(int c) { + return c <= 32 && c >= 0; + } + + public int next(char[] buff) throws IOException { + int c = skipWhite(); + int len = 0; + while (!isSpaceChar(c) && c != -1) { + buff[len++] = (char) c; + c = read(); + } + return len; + } + + public String next() throws IOException { + int c = skipWhite(); + StringBuilder res = new StringBuilder(); + while (!isSpaceChar(c) && c != -1) { + res.appendCodePoint(c); + c = read(); + } + return res.toString(); + } + + public String nextLine() throws IOException { + int c = skipWhite(); + StringBuilder res = new StringBuilder(); + while (c != '\n' && c != '\r' && c != -1) { + res.appendCodePoint(c); + c = read(); + } + return res.toString(); + } + + void debug(Object... obj) { + println(""-->"" + Arrays.deepToString(obj)); + } + + void solve() throws Exception { + int cases = nextInt(); + for (int kk = 1; kk <= cases; kk++) { + + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int sol = 0; + for (int i = 0; i < n; i++) { + int v = nextInt(); + if (v >= (p * 3 - 2)) { + sol++; + continue; + } + if (s > 0 && v >= (p * 3 -4) && p>1) { + s--; + sol++; + continue; + } + } + + println(String.format(""Case #%d: %d"", kk, sol)); + } + } +}" +A20480,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.io.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +/** + * + * @author Sagar + */ +public class Dancing_With_the_Googlers +{ + + Map m; + int no_of_test_cases = 0; + StringBuffer [] sb; + Integer []output ; + String inputfile = """"; + String outputfile = """"; + Integer [][] input ; + int no_of_digits = 0; + + + + public void setInputOutput(String input, String output) + { + inputfile = input; + outputfile = output; + } + + public void readFile() + { + String line=""""; + boolean firstTime = true; + int i = 0; + try + { + FileReader filename = new FileReader(inputfile); + BufferedReader reader = new BufferedReader(filename); + while((line=reader.readLine()) !=null) + { + if(firstTime) + { + firstTime = false; + no_of_test_cases = Integer.parseInt(line); + System.out.println(""testcases:""+no_of_test_cases); + output = new Integer[no_of_test_cases]; + for (int s = 0;s=p) + output[i]=output[i]+1; + else + { + if((p-result)==1 && special_cases>0) + { + output[i]=output[i]+1; + special_cases--; + } + } + } + else if(number%3==1) + { + result = (number/3); + + if(result >=p || result+1 >=p) + output[i]=output[i]+1; + else if((p-result+1)==1 && special_cases>0) + { + output[i]=output[i]+1; + special_cases--; + } + } + else if(number%3==2) + { + result = (number/3); + + if(result >=p || result+1 >=p) + { + output[i]=output[i]+1; + } + else if (result+2>=p &&special_cases>0) + { + output[i]=output[i]+1; + special_cases--; + } + else if((p-result+1)==1 && special_cases>0) + { + output[i]=output[i]+1; + special_cases--; + } + + } + } + + + } + //System.out.println(""OutPut""+i+ +output[i]); + } + } + + public void displayOutput() + { + try + { + // Create file + FileWriter fstream = new FileWriter(outputfile); + BufferedWriter out = new BufferedWriter(fstream); + for(int i=0;i= p){ + Pmaxs++; + }else if(ter+1 >= p && ter+1 <= 10 && ter+1 <= t && ter-1 >= 0 ){ + noS++; + Pmaxs++; + } + break; + } + case 1:{ + if(ter >= p){ + Pmaxs++; + }else if(ter+1 >= p && ter+1 <= 10){ + Pmaxs++; + } + break; + } + case 2:{ + if(ter >= p){ + Pmaxs++; + }else if(ter+1 >= p && ter+1 <= 10){ + Pmaxs++; + }else if(ter+2 >= p && ter+2 <= 10){ + noS++; + Pmaxs++; + } + break; + } + } + + } + if(noS > S){ Pmaxs -= (noS - S); } + pw.println(""Case #""+(i+1)+"": ""+Pmaxs); + } + pw.close(); + s.close(); + } +} +" +A21474,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package gcj_b; + +/** + * + * @author kay + */ +public class Gcj_B { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Generate app = new Generate(); + app.do_processing(""G:/b_input.txt""); + // TODO code application logic here + } +} +" +A20029,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + + +public class DancingWithGooglers { + static class Googler implements Comparable{ + int averageScore; + int remainder; + + Googler(int averageScore, int remainder) { + this.averageScore = averageScore; + this.remainder = remainder; + } + + @Override + public int compareTo(Googler o) { + return this.averageScore - o.averageScore; + } + + } + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int testCases = Integer.parseInt(br.readLine()); + for (int t = 1; t <= testCases; t++) { + String[] nspt = br.readLine().split("" ""); + int n = Integer.parseInt(nspt[0]); + int s = Integer.parseInt(nspt[1]); + int p = Integer.parseInt(nspt[2]); + int[] totalPoints = new int[n]; + for (int i = 0, j = 3; i < n; i++, j++) { + totalPoints[i] = Integer.parseInt(nspt[j]); + } + + Googler[] googlers = new Googler[n]; + for (int i = 0; i < n; i++) { + googlers[i] = new Googler(totalPoints[i] / 3, totalPoints[i] % 3); + } + Arrays.sort(googlers); + +// System.out.println(""minimum = "" + p + "", surprising = "" + s); +// for (int i = 0; i < n; i++) { +// System.out.println(""("" + googlers[i].averageScore + "" "" + googlers[i].averageScore + "" "" + googlers[i].averageScore + "") "" + googlers[i].remainder); +// } + + int count = 0; + int i = n - 1; + for (;i >= 0; i--) { + if (googlers[i].averageScore >= p) { + count++; + } else { + break; + } + } + + //average + 1 == p + for (;i >= 0; i--) { + if (googlers[i].averageScore + 1 == p) { + if (googlers[i].remainder == 0 && googlers[i].averageScore != 0 && s > 0) { + count++; + s--; + } else if (googlers[i].remainder >= 1) { + count++; + } + } else { + break; + } + } + + //average + 2 == p + for (;i >= 0;i--) { + if (googlers[i].averageScore + 2 == p) { + if (googlers[i].remainder == 2 && s > 0) { + count++; + s--; + } + } else { + break; + } + } + + System.out.println(""Case #"" + t + "": "" + count); + } + } +} +" +A20550,"package jam2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class Test2 { + public static void main(String argv[]){ + Test2 tb = new Test2(); + + ArrayList strin = tb.readFile(""B-large.in""); + + ArrayList> intin = tb.getInt(strin); + + tb.printInt(intin); + + ArrayList strout = new ArrayList(); + + tb.computeDancer(intin, strout); + + tb.writeResult(strout, ""outtest2_large.txt""); + } + + public void computeDancer(ArrayList> intin, + ArrayList strout){ + if(intin==null || strout==null || intin.size()==0) return; + int nTest = intin.get(0).get(0); + for(int i=1; i<=nTest; ++i){ + + int ndancer = intin.get(i).get(0); + if(ndancer!=(intin.get(i).size()-3)){ + System.out.println(""dancer do not match!""); + return; + } + + int nsurprise = intin.get(i).get(1); + int thresh = intin.get(i).get(2); + final int tri =3; + + int ng = 0; //the googlers have score above threshold + for(int j=3; j (tri*(thresh-1))){ + ng++; + }else if(score>(tri*(thresh-2)+1)){ + int div = score/tri; + int residule = score%tri; + if(nsurprise > 0){ + if(residule <=1 && div==0) continue; // + ng++; + nsurprise --; + } + } + } + + //write out the results + String line = ""Case #""+i+"": ""+ng; + System.out.println(line); + strout.add(line); + } + + + } + + public void printInt(ArrayList> intin){ + if(intin==null ) return; + for(ArrayList arr:intin){ + for(Integer i: arr){ + System.out.print(i+"",""); + } + System.out.println(); + } + } + + public ArrayList> getInt(ArrayList strlist){ + if(strlist == null) return null; + ArrayList> intlist = new ArrayList>(); + for(String s:strlist){ + ArrayList tarr = new ArrayList(); + String astr[] = s.split("" ""); + for(int i=0; i readFile(String inname){ + if(inname == null) return null; + + ArrayList arr = new ArrayList(); + try{ + FileInputStream fstream = new FileInputStream(inname); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + arr.add(strLine); + } + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + return arr; + } + + public void writeResult(ArrayList res, String fname){ + if(res == null || res.size()==0) return; + try{ + FileWriter fstream = new FileWriter(fname); + BufferedWriter out = new BufferedWriter(fstream); + + for(int i=0; i words = new ArrayList(); + for (int i = 0; i < n; i++) { + words.add(sc.nextLine()); + } + String toreturn[] = new String[words.size()]; + words.toArray(toreturn); + return toreturn; + } + + public static void main(String[] args) { + String[] input = Dancing.reader(); + for (int i = 0; i < input.length; i++) { + String vals[] = input[i].split("" ""); + int surprise = Integer.parseInt(vals[1]); + int min = Integer.parseInt(vals[2]); + int counter = 0; + int surprisecounter = 0; + for (int j = 3; j < vals.length; j++) { + int tocount = 0; + int sup = 1; + int madeit = 0; + for (int k = min; k < 11; k++) { + //System.out.println(vals[j]); + int test = Integer.parseInt(vals[j]) - k; + int test2 = test/2; + //System.out.println(""im "" + k); + //System.out.println(test2); + if ((test2 - k) <= 2 && (test2 - k) >= -2 && test >= 0) { + if (test2 - k == 2 || k - test2 == 2) { + tocount = 1; + madeit = 1; + //System.out.println(""surprise""); + } + else { + tocount = 1; + sup = 0; + madeit = 1; + //System.out.println(""no surprise""); + } + } + //System.out.println(tocount + "" "" + sup); + } + if (tocount == 1) { + counter++; + if (sup == 1 && madeit == 1) surprisecounter++; + } + //System.out.println(surprisecounter); + if (surprisecounter > surprise && sup == 1 && madeit == 1) { + counter--; + //System.out.println(""WHYYY""); + //break; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + counter); + } + } +} +" +A21987,"import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class Dancing { + + public static void main(String[] args) throws IOException{ + Scanner sc = new Scanner(new File(""dancing.in"")); + System.setOut(new PrintStream(new File(""dancing.out""))); + ArrayList changeAble = new ArrayList(100); + int t = sc.nextInt(); + for(int i=1; i<=t; i++){ + changeAble.clear(); + int n = sc.nextInt();//number of googlers + int s = sc.nextInt();//number of surprises + int p = sc.nextInt();//target + int y = 0;//number that match + for(int j=0; j{ + int distAway; + boolean changeAble = false; + int maxScore; + int sScore; + int score; + int t; + public Googler(int score, int target){ + t = target; + this.score=score; + int i = score/3; + if(i*3==score){ + maxScore = i; + changeAble = true; + } + else if(i*2+i+1 == score) + maxScore = i+1; + else if(i+(i+1)*2==score){ + maxScore = i+1; + changeAble = true; + } + if(maxScore==0) + changeAble = false; + distAway = target-maxScore; + } + public int compareTo(Googler g){ + return distAway-g.distAway; + } + public String toString(){ + return score+""""; + } +} +" +A22253,"package de.pat.dev.y2012.qualification.b; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +/** + * @author pat.dev@alice.de + * @since 14.04.12 + */ +public class Main { + public static void main(String[] args) { + try { + BufferedReader reader = new BufferedReader(new FileReader(args[0])); + int numberOfTestCases = nextInt(reader); + for (int i = 0; i < numberOfTestCases; i++) { + StatisticParameters statisticParameters = nextParameters(reader); + System.out.printf(""Case #%d: %s\n"", i+1, + statisticParameters.statistics.numberOfGooglersReaching(statisticParameters.bestScore)); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static StatisticParameters nextParameters(BufferedReader reader) throws IOException { + String[] params = reader.readLine().trim().split(""\\s+""); + int numberOfGooglers = toInt(params[0]); + int numberOfSurprises = toInt(params[1]); + int bestScore = toInt(params[2]); + int[] scores = new int[numberOfGooglers]; + for (int i = 0; i < scores.length; i++) { + scores[i]=toInt(params[i+3]); + } + ScoreStatistics statistics = new ScoreStatistics(numberOfSurprises, scores); + return new StatisticParameters(bestScore,statistics); + } + private static int toInt(String value) { + return Integer.parseInt(value); + } + + private static int nextInt(BufferedReader reader) throws IOException { + return toInt(reader.readLine().trim()); + } + + private static class StatisticParameters { + public final int bestScore; + public final ScoreStatistics statistics; + + public StatisticParameters(int bestScore, ScoreStatistics statistics) { + this.bestScore = bestScore; + this.statistics = statistics; + } + + @Override + public String toString() { + return ""StatisticParameters{"" + + ""bestScore="" + bestScore + + "", statistics="" + statistics + + '}'; + } + } +} +" +A20768,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.util.*; + + +public class B implements Runnable{ + + public static void main(String[] args) { + new Thread(new B()).start(); + } + + private BufferedReader in; + private PrintWriter out; + + public B() { + try { + System.setIn(new FileInputStream(""C:/Users/Admin/AppData/Local/Temp/b-small.in"")); + System.setOut(new PrintStream(new FileOutputStream(""b-small.out""))); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + in = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(System.out); + } + + @Override + public void run() { + // TODO Auto-generated method stub + System.err.println(""hello""); + String Scases = null; + try { + Scases = in.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + int cases = Integer.parseInt(Scases); + System.err.println(cases + "" tests found.""); + for(int testNo = 1; testNo <= cases; testNo++) { + out.print(""Case #"" + testNo + "": ""); + + try { + String line1 = in.readLine(); + + String[] strings = line1.split("" ""); + int participants = Integer.parseInt(strings[0]); + int surprises = Integer.parseInt(strings[1]); + int neededScore = Integer.parseInt(strings[2]); + + System.err.printf(""%d participants, %d surprises, %d min. score.\n"", participants, surprises, neededScore); + + Vector scores = new Vector(); + for (int i=3; i < strings.length; i++) { + scores.add(Integer.parseInt(strings[i]) ); + } + System.err.printf(""scores: %s \n"", scores.toString()); + + int possible = 0; + int possibleWithSurprise = 0; + int impossible = 0; + + for(int score : scores) { + float f = score / 3.0f; + float diff = neededScore - f; + + if ( (2*(Math.max(neededScore-2,0)) + 1*neededScore) > score) { + impossible++; + } else { + if (diff >= 0.7 && diff < 1.4) { + possibleWithSurprise++; + } else if (diff < 0.7) { + possible++; + } else { + impossible++; + } + } + + System.err.println(""score/3: "" + f + ""nf:"" + (neededScore - f) ); + } + System.err.printf(""%d possible %d possibleWithSurprise %d impossible\n\n"", possible, possibleWithSurprise, impossible); + + int total = Math.min(possibleWithSurprise, surprises) + possible; + out.print(total); + + + + } catch (Exception e) { + System.err.println(e.getMessage()); + } + out.print(""\n""); + } + out.close(); + } + +} +" +A20262,"package com.gcj.main; + +import java.util.ArrayList; + +import com.gcj.parser.Parser; +import com.gcj.parser.MaxPoints; + +public class Main { + + + public static void main(String[] args) { + Parser parser = new Parser(""resource/InputData.txt""); + ArrayList[] datas = parser.toArray(); + int index = 1; + + for (ArrayList dataRow : datas){ + + int nbGooglers = dataRow.get(0).intValue(); + int nbSurprinsingResult = dataRow.get(1).intValue(); + int targetPoints = dataRow.get(2).intValue(); + + int result = 0; + + for (int i = 0 ; i < nbGooglers ; i++) { + if (MaxPoints.normal(dataRow.get(i+3)) >= targetPoints){ + result ++; + } + else { + if (nbSurprinsingResult > 0){ + if (MaxPoints.surprising(dataRow.get(i+3)) >= targetPoints){ + result ++; + nbSurprinsingResult --; + } + } + } + } + + StringBuffer stringBuf = new StringBuffer(""Case #"").append(index).append("": "").append(result); + System.out.println(stringBuf.toString()); + index ++; + } + } +}" +A22734,"import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + + +public class B { + + private static final String NAME = ""B-large.txt""; + private static final File input = new File(""in"", NAME); + private static final File output = new File(""out"", NAME); + + public static void main(String[] args) throws Exception { + Scanner scanner = new Scanner(input); + scanner.useDelimiter(""[\\s\\n\\r]+""); + + FileWriter writer = new FileWriter(output); + int numberOfTests = scanner.nextInt(); + for (int test = 0; test < numberOfTests; test++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int[] totals = new int[n]; + for (int i = 0; i < n; i++) { + totals[i] = scanner.nextInt(); + } + String result = calculate(p * 3 - 4, p * 3 - 2, s, totals); + String line = String.format(""Case #%d: %s\n"", test + 1, result); + writer.append(line); + System.out.print(line); + } + writer.close(); + } + + private static String calculate(int low, int high, int surprising, int[] totals) { + int result = 0; + for (int total : totals) { + if (total >= high) { + result++; + } + else if (total >= low && total > 1) { + if (surprising > 0) { + surprising--; + result++; + } + } + } + return Integer.toString(result); + } +} +" +A21075,"import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) throws IOException { + FileInputStream fis = new FileInputStream(new File(""in.txt"")); + FileOutputStream fos = new FileOutputStream(new File(""out.txt"")); + Scanner sc = new Scanner(fis); + PrintWriter out = new PrintWriter(fos); + int cases = sc.nextInt(); + for(int cs = 1; cs <= cases; cs++) + { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int [] sums = new int[n]; + for(int i=0; i=p) + notsup++; + if(getMax(sums[i],2)=0 && k<=10) + { + int d = Math.abs(i-j); + d = Math.max(d, Math.abs(k-j)); + d = Math.max(d, Math.abs(k-i)); + if(d<=diff) + { + max = Math.max(i, max); + max = Math.max(j, max); + max = Math.max(k, max); + + } + } + } + return max; + } +} +" +A20682,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class DancingWithGooglers { + + private static String[] linhas; + private static String[] linhasRespostas; + private static String stringDoArquivo = """"; + private static Integer numeroDeTestes = null; + + /** + * @param args + */ + public static void main(String[] args) { + + try { + FileInputStream fs = new FileInputStream(""/home/gustavo/Downloads/B-large.in""); + DataInputStream di = new DataInputStream(fs); + BufferedReader br = new BufferedReader(new InputStreamReader(di)); + + linhas = new String[101]; + + int i = 0; + String linha; + while((linha = br.readLine()) != null && (i <= 100)){ + if(i== 0 && numeroDeTestes == null){ + numeroDeTestes = Integer.valueOf(linha); + if(numeroDeTestes > 100 || numeroDeTestes < 1){ + System.out.println(""Erro: Número de casos de teste fora dos padrões!""); + } + }else{ + linhas[i] = linha; + i++; + } + } + + + di.close(); + if(i == 0 || i > 100 || i > numeroDeTestes){ + System.out.println(""Número de linhas fora dos padrões.""); + System.exit(0); + } + + linhasRespostas = new String[i]; + + for(int j = 0; j < i; j++){ + linhasRespostas[j] = ""Case #"" + (j + 1) + "": "" + Converterlinha(linhas[j]); + } + + + for (int k = 0; k < linhasRespostas.length; k++) { + if (k + 1 == linhasRespostas.length) { + stringDoArquivo = stringDoArquivo + linhasRespostas[k]; + break; + } + stringDoArquivo = stringDoArquivo + linhasRespostas[k] + ""\n""; + } + + escreverNoArquivo(stringDoArquivo); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (NumberFormatException e){ + System.out.println(""Numero de casos de teste errado!""); + } + + } + + private static String Converterlinha(String string) { + + String[] stringComNumero = string.split("" ""); + Integer numeroVariaveis = stringComNumero.length; + Integer googlers; + Integer surpresa = 0; + Integer pontoMinimo = 0; + Integer jogadores = 0; + + if(numeroVariaveis > 0){ + googlers = Integer.valueOf(stringComNumero[0]); + if(numeroVariaveis > 1){ + surpresa = Integer.valueOf(stringComNumero[1]); + } + if(numeroVariaveis > 2){ + pontoMinimo = Integer.valueOf(stringComNumero[2]); + } + try{ + for(int i = 3; i < 3 + googlers; i++){ + Integer base = Integer.valueOf(Integer.valueOf(stringComNumero[i])/3); + switch(Integer.valueOf(stringComNumero[i]) % 3){ + case 0: + if (base >= pontoMinimo){ + jogadores++; + }else{ + if(surpresa > 0 && base > 0 && base + 1 >= pontoMinimo){ + surpresa--; + jogadores++; + } + } + break; + case 1: + if(base >= pontoMinimo || base + 1 >= pontoMinimo){ + jogadores++; + }else{ + if(surpresa > 0 && base > 0 && base + 1 >= pontoMinimo){ + jogadores++; + surpresa--; + } + } + break; + case 2: + if(base >= pontoMinimo || base + 1 >= pontoMinimo){ + jogadores++; + }else{ + if(surpresa > 0 && base > 0 && base + 2 >= pontoMinimo){ + jogadores++; + surpresa--; + } + } + break; + } + } + } catch(ArrayIndexOutOfBoundsException e){ + System.out.println(""Erro! Número de jogadores errado.""); + System.exit(0); + } + }else{ + System.out.println(""Erro: Número argumentos inválido.""); + } + + return String.valueOf(jogadores); + } + + public static char criarMapa(char x) { + switch (x) { + case 'a': + return 'y'; + case 'b': + return 'h'; + case 'c': + return 'e'; + case 'd': + return 's'; + case 'e': + return 'o'; + case 'f': + return 'c'; + case 'g': + return 'v'; + case 'h': + return 'x'; + case 'i': + return 'd'; + case 'j': + return 'u'; + case 'k': + return 'i'; + case 'l': + return 'g'; + case 'm': + return 'l'; + case 'n': + return 'b'; + case 'o': + return 'k'; + case 'p': + return 'r'; + case 'q': + return 'z'; + case 'r': + return 't'; + case 's': + return 'n'; + case 't': + return 'w'; + case 'u': + return 'j'; + case 'v': + return 'p'; + case 'w': + return 'f'; + case 'x': + return 'm'; + case 'y': + return 'a'; + case 'z': + return 'q'; + } + return x; + } + + public static void escreverNoArquivo(String texto) { + try { + String file_name = ""A-small.out""; + FileWriter fstream = new FileWriter(file_name); + BufferedWriter out = new BufferedWriter(fstream); + out.write(texto); + out.close(); + System.out.println(""Saída criada!""); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + +} +" +A22989,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package exercises; + +/** + * + * @author dannocz + */ +public class Parser { + + public static char parse(char character){ + + switch(character) + { + case ' ': + return ' '; + case 'a': + return 'y'; + case 'b': + return 'h'; + case 'c': + return 'e'; + case 'd': + return 's'; + case 'e': + return 'o'; + case 'f': + return 'c'; + case 'g': + return 'v'; + case 'h': + return 'x'; + case 'i': + return 'd'; + case 'j': + return 'u'; + case 'k': + return 'i'; + case 'l': + return 'g'; + case 'm': + return 'l'; + case 'n': + return 'b'; + case 'o': + return 'k'; + case 'p': + return 'r'; + case 'q': + return 'z'; + case 'r': + return 't'; + case 's': + return 'n'; + case 't': + return 'w'; + case 'u': + return 'j'; + case 'v': + return 'p'; + case 'w': + return 'f'; + case 'x': + return 'm'; + case 'y': + return 'a'; + case 'z': + return 'q'; + default: + return ' '; + } + + } + + public static String parse(String cad){ + + // System.out.println(cad); + char[] chars = cad.toCharArray(); + char[] newChars = new char[chars.length]; + for (int i = 0; i < chars.length; i++) { + newChars[i]= parse(chars[i]); + } + + return new String(newChars); + + } + +} +" +A20185,"package com.webcumo.tasks.b; + +import java.awt.FileDialog; +import java.awt.Frame; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +/** + * + * @author Cumo + */ +public class Start { + + public static void main(String... agrs) { + Frame d = null; + FileDialog fd = new FileDialog(d, ""Load in file"", FileDialog.LOAD); + fd.setVisible(true); + String file = fd.getDirectory() + fd.getFile(); + if (file != null) { + File f = new File(file); + File fo = new File (""result.out""); + if (!f.exists()) + return; + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(fo)); + BufferedReader br = new BufferedReader(new FileReader(f)); + String t = br.readLine(); + + int countSamples = Integer.parseInt(t); + + String sample; + + for (int i = 0 ; i < countSamples ; i++) { + sample = br.readLine(); + String result = ""Case #"" + (i + 1) + "": "" + Worker.translateFromGooglereseToEnglish(sample) + ""\n""; + bw.write(result); + + } + + bw.close(); + br.close(); + } catch (NullPointerException npe) { + //ignore at current + } catch (Exception e) { + //ignore at current + } + } + fd.dispose(); + } +} +" +A22493,"package qualifications2012; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.util.Scanner; + +public class GoogleDancers { + + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(""input.txt"")); + BufferedWriter out = null; + try { + FileWriter fstream = new FileWriter(""out.txt""); + out = new BufferedWriter(fstream); + int cases = in.nextInt(); + for (int i = 0; i < (cases); i++) { + int result = 0; + int n = in.nextInt(); + int s = in.nextInt(); + int tempS = s; + int possSup = 0; + int p = in.nextInt(); + for (int j = 0; j < n; j++) { + int current = in.nextInt(); + int div = current / 3; + int mod = current % 3; + switch (mod) { + case 0: + if (div >= p) { + result++; + if (div + 1 < 11) + possSup++; + } else if (div != 0 && div + 1 >= p) { + result++; + tempS--; + } else if (div != 0) { + possSup++; + } + break; + case 1: + if (div + 1 >= p) { + result++; + } + possSup++; + break; + case 2: + if (div + 1 >= p) { + result++; + if (div + 2 < 11) + possSup++; + } else if (div + 2 >= p) { + result++; + tempS--; + } else + possSup++; + break; + default: + break; + } + } + if (tempS < 0) { + result = result + tempS; + } else if (tempS > 0) { + if (possSup < tempS) + result = result - (tempS - possSup); + } + System.out.println(result); + out.write(""Case #"" + (i + 1) + "": "" + result + ""\n""); + } + out.close(); + } catch (Exception e) {// Catch exception if any + e.printStackTrace(); + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A22958,"package codejam.contest; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Vector; + +public class ProblemB +{ + public static void main(String[]arg) + { + try + { + FileInputStream fInputStream = new FileInputStream(arg[0]); + DataInputStream in = new DataInputStream(fInputStream); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + String strLine; + int i = 0; + while ((strLine = reader.readLine()) != null) + { + + if (i > 0) + { + String[] arrString = strLine.split("" ""); + + System.out.println(""Case #"" + i + "": "" + getResult(arrString)); + } + + i++; + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + private static int getResult(String[] arrValues) + { + int result = 0; + int numGooglers = Integer.parseInt(arrValues[0]); + int numSurprise = Integer.parseInt(arrValues[1]); + int numResult = Integer.parseInt(arrValues[2]); + + Vector vctScores = new Vector(); + for (int i = 3; i < arrValues.length; i++) + { + int score = Integer.parseInt(arrValues[i]); + vctScores.add(getSubScores(score)); + } + + result = getBestResult(vctScores, numSurprise, numResult); + + return result; + } + + private static Vector getSubScores(int value) + { + int score1 = value / 3; + int score2 = value / 3; + int score3 = value / 3; + + if (value % 3 == 1) + score1++; + else if (value % 3 == 2) + { + score1++; + score2++; + } + + Vector vctResult = new Vector(); + vctResult.add(score1); + vctResult.add(score2); + vctResult.add(score3); + + return vctResult; + } + + private static int getBestResult(Vector vct, int numSurp, int numScore) + { + int result = 0; + + for (int i = 0; i < vct.size(); i++) + { + Vector score = (Vector) vct.elementAt(i); + int elem1 = (Integer) score.elementAt(0); + int elem2 = (Integer) score.elementAt(1); + int elem3 = (Integer) score.elementAt(2); + + if (numScore == 0) + result++; + else if (elem1 != 0) + { + if (((elem1 == numScore - 1 && numSurp > 0) && ((elem2 != elem3) || ((elem1 == elem2) && (elem2 == elem3))))) + { + numSurp--; + result++; + } + else if (elem1 >= numScore) + result++; + } + } + + return result; + } +} +" +A22023,"import java.util.Vector; + + +public class TestCaseB { + + public int googlers; + public int surprises; + public int minscore; + public Vector scores; + + public TestCaseB(int g, int s, int m, Vector sc) { + googlers = g; + surprises = s; + minscore = m; + scores = sc; + System.out.println(""tc: "" + g + "" "" + s + "" "" + m + "" "" + scores); + } + +} +" +A21000,"package fixjava; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +public class IOUtils { + + public static void writeLinesToFile(List lineList, File outputFile) { + try { + PrintWriter writer = new PrintWriter(outputFile); + for (String line : lineList) + writer.println(line); + writer.close(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + public static void writeLinesToFile(List lineList, String outputFilename) { + writeLinesToFile(lineList, new File(outputFilename)); + } + + // --------------------------------------------------------------------------------------------------------- + + public static ArrayList readLinesFromFile(File inputFile) { + ArrayList lines = new ArrayList<>(); + for (String line : new FileLineIterator(inputFile)) + lines.add(line); + return lines; + } + + public static ArrayList readLinesFromFile(String inputFilename) { + return readLinesFromFile(new File(inputFilename)); + } + + // --------------------------------------------------------------------------------------------------------- + + public static String readFileAsString(File inputFile) { + int len = (int) inputFile.length() + 1; + StringBuilder buf = new StringBuilder(len); + for (String line : new FileLineIterator(inputFile)) { + buf.append(line); + buf.append('\n'); + } + return buf.toString(); + } + + public static String readFileAsString(String inputFilename) { + return readFileAsString(new File(inputFilename)); + } +} +" +A20207,"package me.stapel.kai.google.codejam2012.quali; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Locale; + +public class ProblemB { + + private static final String NL = System.getProperty(""line.separator""); + + public ProblemB() { + // nothing to do here yet + } + + public static void main(String[] args) { + ProblemB problemB = new ProblemB(); + + + problemB.processFile(""in/B-large.in"", ""out/B-large.txt""); + + } + + private Object processFile(String inFileName, String outFileName) { + Object obj = new Object(); + + File inFile = new File(inFileName); + File outFile = new File(outFileName); + + String line = """"; + int T = 1; + + OutputStreamWriter output; + BufferedReader br; + try { + br = new BufferedReader(new FileReader(inFile)); + output = new OutputStreamWriter(new BufferedOutputStream( + new FileOutputStream(outFile)), ""8859_1""); + + line = br.readLine(); + + // skipping first line + line = br.readLine(); + + while (line != null) { + String[] split = line.split("" ""); + + int N = Integer.parseInt(split[0]); + int S = Integer.parseInt( split[1]); + int p = Integer.parseInt(split[2]); + int[] t = new int[N]; + + for(int i = 0; i= Math.max(3*p-2, p)) + Gmax1++; + if(t[i] >= Math.max(3*p-4, p)) + Gmax2++; + } + + return Math.min(Gmax1+S, Gmax2); + } + +} +" +A20728,"import java.io.*; +import java.util.*; +import java.math.*; + +import static java.lang.System.out; +import static java.lang.Math.*; + +public class BaiB implements Runnable { + + public void run() { + int[][] C = new int[33][2]; + for (int[] a1 : C) Arrays.fill(a1, -1); + for (int i = 0; i <= 10; ++i) { + for (int j = 0; j <= 10; ++j) { + for (int k = 0; k <= 10; ++k) if (abs(i - j) <= 2 && abs(j - k) <= 2 && abs(k - i) <= 2) { + int sur = 0; + if (abs(i - j) == 2 || abs(j - k) == 2 || abs(k - i) == 2) { + sur = 1; + } + C[i + j + k][sur] = max(C[i + j + k][sur], max(i, max(j, k))); + } + } + } + int ntest = nextInt(); + for (int test = 1; test <= ntest; ++test) { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] a = new int[n]; + for (int i = 0; i < n; ++i) { + a[i] = nextInt(); + } + int[][] F = new int[n + 1][n + 1]; + for (int[] a1 : F) Arrays.fill(a1, -1); + F[0][0] = 0; + for (int i = 0; i < n; ++i) + for (int j = 0; j <= i; ++j) + if (F[i][j] >= 0) { + for (int k = 0; k < 2; ++k) if (C[a[i]][k] >= 0) { + F[i + 1][j + k] = max(F[i + 1][j + k], F[i][j] + (C[a[i]][k] >= p ? 1 : 0)); + } + } + out.println(""Case #"" + test + "": "" + F[n][s]); + } + } + + int[] ar(int st, int en) { int[] res = new int[Math.max(en - st, 0)]; for (int i = st; i < en; ++i) res[i - st] = i; return res; } + int[] ar(int n) { return ar(0, n); } + void viet(Object...os) { System.err.println(Arrays.deepToString(os)); } + BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer strtok = null; + + String nextStr() { + try { + while(strtok == null || !strtok.hasMoreTokens()) + strtok = new StringTokenizer(keyboard.readLine()); + return strtok.nextToken(); + } + catch(Exception ex) { + System.out.println(ex.getMessage()); + ex.printStackTrace(); + return null; + } + } + + int nextInt() { + return Integer.parseInt(nextStr()); + } + + long nextLong() { + return Long.parseLong(nextStr()); + } + + double nextDouble() { + return Double.parseDouble(nextStr()); + } + + public static void main(String[] args) { + new BaiB().run(); + } +}" +A22172,"package com.brootdev.gcj2012.common; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; + +public class DataUtils { + + public static long readLongLine(BufferedReader in) throws IOException { + return Long.valueOf(in.readLine()); + } + + public static long[] readLongsArrayLine(BufferedReader in) throws IOException { + String[] numsS = in.readLine().split(""\\s+""); + long[] nums = new long[numsS.length]; + for (int i = 0; i < nums.length; i++) { + nums[i] = Long.valueOf(numsS[i]); + } + return nums; + } + + public static void writeCaseHeader(PrintWriter out, long case_) { + out.print(""Case #""); + out.print(case_ + 1); + out.print("": ""); + } +} +" +A22909,"package _2012.qualification; + +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + Scanner consola = new Scanner(System.in); + int nGooglers, nSurprise, top, total, cont, times = consola.nextInt(); + for(int t = 1; t <= times; t++){ + nGooglers = consola.nextInt(); + nSurprise = consola.nextInt(); + top = consola.nextInt(); + cont = 0; + for(int i = 0; i < nGooglers; i++){ + total = consola.nextInt(); + if(total < top) + continue; + if(total >= (top * 3) - 2) + cont++; + else if(nSurprise > 0 && total >= (top * 3) - 4){ + cont++; + nSurprise--; + } + } + System.out.println(""Case #"" + t + "": "" + cont); + } + } +}" +A22934,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) throws NumberFormatException, IOException { + // open file and create a buffered reader + FileReader input = new FileReader(args[0]); + BufferedReader buffer = new BufferedReader(input); + + //read the number of testcases + int max = Integer.parseInt(buffer.readLine().trim()); + + // read a line and call the solving procedure for a single test case. We expect back the result as a string + for (int i = 1; i <= max; i++) { + System.out.println(""Case #""+i+"": "" + solve(buffer.readLine())); + } + + } + + private static int solve(String input) { + String[] split = input.split("" ""); + int n = Integer.parseInt(split[0]); + int s = Integer.parseInt(split[1]); + int p = Integer.parseInt(split[2]); + int normal = 0; + int special = 0; + for(int i = 0; i < n; i++) + { + int t = Integer.parseInt(split[i+3]); + if (t > 3 * (p - 1)) + { + normal++; + } else { + if(t > Math.max(1, 3 * (p - 2)+1)) + { + special++; + } + } + } + return normal + Math.min(special, s); + } + +} +" +A22387,"package contest; + +import java.awt.Desktop; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + +public abstract class ContestProblem { + + File inputFile = new File(""input.txt""); + File outputFile = new File(""output.txt""); + + public ContestProblem() { + + } + + public ContestProblem(String inputFilename) { + this.inputFile = new File(inputFilename); + calcOutputFromInput(); + } + + public void run() throws Exception { + BufferedReader in = new BufferedReader(new FileReader(inputFile)); + PrintWriter out = new PrintWriter(new FileWriter(outputFile)); + try { + parseInput(new Input(in), out); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + out.close(); + in.close(); + } + + public abstract void parseInput(Input in, PrintWriter out); + + public static void runProblem(ContestProblem problem) { + try { + long start = System.currentTimeMillis(); + problem.run(); + long end = System.currentTimeMillis(); + System.out.format(""Took: %d ms%n"", end - start); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + if (Desktop.isDesktopSupported()) { + Desktop.getDesktop().open(problem.outputFile); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public File getInputFile() { + return inputFile; + } + + public ContestProblem setInputFile(File inputFile) { + this.inputFile = inputFile; + return this; + } + + public File getOutputFile() { + return outputFile; + } + + public ContestProblem setOutputFile(File outputFile) { + this.outputFile = outputFile; + return this; + } + + public ContestProblem calcOutputFromInput() { + this.outputFile = new File(inputFile.getParentFile(), inputFile.getName() + ""-output.txt""); + return this; + } +} +" +A22375,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Dancing { + String inputFilePath = ""C:\\Temp\\Google\\B-large.in""; + String outputFilePath = ""C:\\Temp\\Google\\output.txt""; + + + public static void main(String[] args) throws NumberFormatException, IOException{ + + new Dancing().go(); + + } + + public void go() throws NumberFormatException, IOException{ + + + FileReader input = new FileReader(inputFilePath); + BufferedReader reader = new BufferedReader(input); + + int numTests = Integer.parseInt(reader.readLine()); + + ArrayList results = new ArrayList(); + + + for (int i = 0; i < numTests; i++){ + String[] details = reader.readLine().split("" ""); + int numDancers = Integer.parseInt(details[0]); + int numSurprise = Integer.parseInt(details[1]); + int targetScore = Integer.parseInt(details[2]); + Integer[] scores = new Integer[numDancers]; + for (int d = 0; d= nonSpecialThreshold){ + numMeetingThreshold++; + } else if (scores[i] >= specialThreshold) { + numPossibleSpecial++; + } + } + + return numMeetingThreshold + Math.min(numSurprise, numPossibleSpecial); + } +} +" +A21389,"package de.hg.codejam.tasks.dance.controller; + +import de.hg.codejam.tasks.dance.domain.Case; +import de.hg.codejam.tasks.dance.help.Converter; +import de.hg.codejam.tasks.dance.service.Calculator; +import de.hg.codejam.tasks.io.Reader; +import de.hg.codejam.tasks.io.Writer; + +public class Test { + + public static void main(String[] args) { + String inputPath = ""file/B-large.in""; + String outputPath = Writer.generateOutputPath(inputPath); + + // System.out.println(""=== READ FILE: "" + inputPath + "" ===""); + String[] input = Reader.readFile(inputPath); + // Writer.print(input); + + // System.out.println(""=== CASES ===""); + Case[] cases = new Case[input.length]; + for (int i = 0; i < input.length; i++) { + cases[i] = Case.parse(input[i]); + // System.out.println(cases[i]); + } + + // System.out.println(""=== CALCULATION: Start ===""); + int[] results = Calculator.calculate(cases); + // System.out.println(""=== CALCULATION: End ===""); + + // System.out.println(""=== RESULTS ===""); + String[] resultStrings = Converter.convert(results); + // Writer.write(resultStrings); + + // System.out.println(""=== WRITE TO FILE: "" + outputPath + "" ===""); + Writer.write(resultStrings, outputPath); + System.out.println(""=== FILE WRITTEN ===""); + } +} +" +A20646,"package codejam2012.qualifier; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class DancingWithTheGooglers { + private int noOfCases; + private int currentCase; + private BufferedReader reader; + private BufferedWriter writer; + + String str; + + int noOfTriplets, noOfSurprisingTriplets, targetScore; + int noOfTargetScores; + + public static void main(String[] args) throws Exception { + new DancingWithTheGooglers().solveProblem(""input/2012Qualifier/B-large.in.txt"", ""input/2012Qualifier/B-large.out.txt""); + } + + private void solveProblem(String inputFileName, String outputFileName) throws Exception { + reader = new BufferedReader(new FileReader(inputFileName)); + writer = new BufferedWriter(new FileWriter(outputFileName)); + + try { + String str = reader.readLine(); + noOfCases = Integer.parseInt(str); + currentCase = 0; + + for(int i=0;i= targetScore) { + noOfTargetScores++; + } else if(quotient + 1 == targetScore) { + if(reminder > 0) { + noOfTargetScores++; + } else if(reminder == 0 && noOfSurprisingTriplets > 0) { + noOfSurprisingTriplets--; + noOfTargetScores++; + } + } else if(quotient + 2 == targetScore) { + if(reminder == 2 && noOfSurprisingTriplets > 0) { + noOfSurprisingTriplets--; + noOfTargetScores++; + } + } + } + } + } + + private void writeOutput() throws Exception { + writer.write(""Case #"" + currentCase + "": ""); + writer.write("""" + noOfTargetScores); + writer.write(""\n""); + } +} +" +A22414,"package google; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + +public class Dancing +{ + public static void main(String[] args) throws FileNotFoundException, IOException + { + IO.changeGoogleIO('B', 1); + + Scanner input = new Scanner(System.in); + + int T = input.nextInt(); + int N, S, p, min, now; + int result0; + String result; + + for (int i = 0; i < T; ++i) + { + result = ""Case #"" + (i + 1) + "": ""; + + result0 = 0; + + N = input.nextInt(); + S = input.nextInt(); + p = input.nextInt(); + min = 3 * (p - 1); + + for (int j = 0; j < N; ++j) + { + now = input.nextInt(); + + if (now > min) + ++result0; + else if ((now > (min - 2)) && (now > 0) && (S > 0)) + { + ++result0; + --S; + } + } + + result += result0; + + System.out.println(result); + } + } +} +" +A21986,"package dancers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Dancers { + + public static int SURPRISE = 0; + public static int ATENDEE = 0; + public static int BESTRESULT = 0; + public static int[] SCORES; + public static int[] RESULTS; + public static String[] inputLines; + + + public static void main(String args[]) + { + try { + readIo(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + solveProblemsFromLine(); + try { + saveOutputFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static int countResult() + { + int result = 0; + int mayResult = 0; + for(int score:SCORES){ + if(score>=(BESTRESULT+(Math.max(0, 2*(BESTRESULT-1))))) + result++; + else + if(score>=BESTRESULT+(Math.max(0,2*(BESTRESULT-2)))) + mayResult++; + } + mayResult = Math.min(mayResult, SURPRISE); + + return result+mayResult; + } + + + + public static void readIo() throws Exception + { + DataInputStream in = new DataInputStream(new FileInputStream(""B2.in""));//inp2.in + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + int lineNum = Integer.parseInt(br.readLine()); + inputLines = new String[lineNum]; + RESULTS = new int[lineNum]; + String strLine=null; + int count=0; + while ((strLine = br.readLine()) != null) + { + inputLines[count] = strLine; + count++; + } + } + + public static void parse(String input) + { + String tokens[] = input.split("" ""); + ATENDEE = Integer.parseInt(tokens[0]); + SURPRISE = Integer.parseInt(tokens[1]); + BESTRESULT = Integer.parseInt(tokens[2]); + SCORES = new int[ATENDEE]; + for(int i = 3; i 0) { + s = s - 1; + r = r + 1; + i = i + 1; + } + + else { + i = i + 1; + } + } else { + i = i + 1; + } + } else if ((tab[i] / 3) + 1 - p == 0) { + + if (tab[i] % 3 == 0) { + if (s > 0) { + s = s - 1; + r = r + 1; + i = i + 1; + } + + else { + i = i + 1; + } + } else { + i = i + 1; + r = r + 1; + } + } else { + i = i + 1; + r = r + 1; + } + + } + + int x = o + 1; + out.write(""Case #"" + x + "": "" + r); + out.newLine(); + } + in.close(); + out.close(); + } +} +" +A20309,"import java.io.BufferedReader; +import java.io.IOException; + +public class TestTwoSolver extends SolverModule { + + public StringBuilder process(BufferedReader in, StringBuilder builder) + throws IOException { + in.readLine(); + String line = in.readLine(); + int count = 1; + while (line != null) { + line = processline(line); + appendLine(line, builder, count); + count++; + line = in.readLine(); + } + return builder; + } + + private String processline(String line) { + int[] lines = toIntegers(line.split("" "")); + int bestResultCount = 0; + int S = lines[1]; + int p = lines[2]; + for (int i = 3; i < lines.length; i++) { + if (lines[i] >= (p - 1) * 2 + p) { + bestResultCount++; + } else { + if (lines[i] >= (p - 2) * 2 + p) { + if (S > 0 && (p - 2) >= 0) { + S--; + bestResultCount++; + } + } + } + } + return String.valueOf(bestResultCount); + } + + private int[] toIntegers(String[] split) { + int[] ints = new int[split.length]; + for (int i = 0; i < split.length; i++) { + ints[i] = Integer.valueOf(split[i]); + } + return ints; + } +} +" +A21965,"import java.io.*; + +/** + * Created with IntelliJ IDEA. + * User: Frederick + * Date: 4/14/12 + * Time: 8:36 AM + * To change this template use File | Settings | File Templates. + */ +public class DancingWithTheGooglers { + + private static int solve(int number, int surprising, int p, int[] totalPoints) { + int count = 0; + for (int i = 0; i < number; i++) { + int total = totalPoints[i]; + if (total >= p * 3) { + count++; + continue; + } + total -= p; + if (total < 0) { + continue; + } + int lower = total / 2; + int higher = total - lower; + int dif; + if (lower > p) { + dif = higher - p; + } else { + dif = p - lower; + } + if (dif < 2) { + count++; + } else if (surprising > 0 && dif == 2) { + surprising--; + count++; + } + } + return count; + } + + public static void main(String[] args) throws IOException { + File input = new File(""C:\\Users\\Frederick\\Downloads\\B-large.in""); + File output = new File(input.getAbsolutePath() + "".out""); + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(input))); + PrintStream out = new PrintStream(output); + int cases = Integer.parseInt(in.readLine()); + for (int i = 1; i <= cases; i++) { + String[] s = in.readLine().split("" ""); + int number = Integer.parseInt(s[0]); + int surprising = Integer.parseInt(s[1]); + int p = Integer.parseInt(s[2]); + int[] totalPoints = new int[number]; + for (int o = 0; o < number; o++) { + totalPoints[o] = Integer.parseInt(s[o + 3]); + } + int maximum = solve(number, surprising, p, totalPoints); + String print = ""Case #"" + i + "": "" + maximum; + System.out.println(print); + out.println(print); + } + } +} +" +A20315,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Saransh + */ +import java.io.*; +import java.util.*; +import java.math.*; +import java.lang.*; + + +public class Main { + + static int pts[]; + static int n,s,p; + static int memo[][]; + static boolean marked[][]; + public static void main(String[] args) + { + try + { + Scanner sc=new Scanner(System.in); + int t=sc.nextInt(); + int test=1; + while(t-->0) + { + n=sc.nextInt(); + s=sc.nextInt(); + p=sc.nextInt(); + pts=new int[n]; + memo=new int[n+1][s+1]; + marked=new boolean[n+1][s+1]; + for(int i=0;i=0&&p3<=10) + { + int arr[]=new int[3]; + arr[0]=p1; + arr[1]=p2; + arr[2]=p3; + Arrays.sort(arr); + if(arr[2]-arr[0]==2&&sur>0) + { + if(arr[2]>=p) + { + max=Math.max(max,1+find(pos+1,sur-1)); + } + else + { + max=Math.max(max,find(pos+1,sur-1)); + } + } + else if(arr[2]-arr[0]<2) + { + if(arr[2]>=p) + { + max=Math.max(max,1+find(pos+1,sur)); + } + else + { + max=Math.max(max,find(pos+1,sur)); + } + } + } + } + } + memo[pos][sur]=max; + return max; + + } + +} + + +" +A23025," +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author dave + */ +public class Main { + + public static void main(String g[]) { + char map[] = new char[300]; + + Scanner sc = new Scanner(System.in); + int t = Integer.parseInt(sc.next()); + int k = 1; + while (t > 0) { + t--; + int n = Integer.parseInt(sc.next()); + + int s = Integer.parseInt(sc.next()); + int b = Integer.parseInt(sc.next()); + int list[] = new int[35]; // scores + + int initialCount = 0; + + int i = 0; // googler index + while (n > 0) { + n--; + int score = Integer.parseInt(sc.next()); + int minVal = b + 2 * (b - 2); + if(minVal<0) + minVal=b; + int specialNumber = (3 * b - 3); + if(specialNumber<0) + { + specialNumber=0; + + } + + //System.out.println(""score = ""+score); + //System.out.println(""minVal = ""+minVal); + if (score < minVal) + { + //System.out.println(""SKIP""); + continue; + } + + initialCount++; + + if (score <= specialNumber ) { + if (s > 0 && score>=2 && score<=28) { + //System.out.println(""using special for :"" + score); + s--; + } + else + { + //System.out.println(""required but cannot use!""); + initialCount--; + } + + if(score<2) + initialCount++; + } + + + + } + + + System.out.println(""Case #"" + (k++) + "": "" + initialCount); + + } + + } +} +" +A22883,"package javaapplication1; +import java.io.*; +public class DancingWithTheGooglers2 { + public static int numberOfGooglers(int scores[],int s,int minScore){ + int count=0; + int score=0; + for(int i=0;i=minScore){ + count++; + } + else{ + if(s>0&&base>0&&(base+1)>=minScore){ + count++; + s--; + } + } + break; + + case 1://System.out.println(""1score = ""+score); + if(base>=minScore||(base+1)>=minScore){ + count++; + } + else{ + if(s>0&&(base+1)>=minScore){ + count++; + s--; + } + } + break; + case 2://System.out.println(""2score = ""+score); + if((base+1)>=minScore||base>=minScore){ + count++; + } + else{ + if(s>0&&(base+2)>=minScore){ + count++; + s--; + } + } + break; + } + } + return count; + } + public static void main(String args[])throws IOException{ + BufferedWriter bw= new BufferedWriter(new FileWriter(""c:/codejam/testolarge.txt"")); + BufferedReader br=new BufferedReader(new FileReader(""c:/codejam/B-large.in"")); + int t=Integer.parseInt(br.readLine()); + for(int i=1;i<=t;i++){ + String[] str=(br.readLine()).split("" ""); + int n=Integer.parseInt(str[0]); + int s=Integer.parseInt(str[1]); + int p=Integer.parseInt(str[2]); + int arr[]=new int[n]; + for(int j=0;j containsGreaterThanP = new Vector(); + Vector containsPminus1 = new Vector(); + + for ( int j = 0; j < numGooglers; j++ ) { + Triplet t = new Triplet(); + + int score = scan.nextInt(); + int n = Math.round( score / 3f ); + int n_2 = score - 2*n; + + // Ordered triplets + if ( n_2 > n ) { + t.add(n_2); + t.add(n); + t.add(n); + } else { + t.add(n); + t.add(n); + t.add(n_2); + } + + if ( t.containsGreaterThan(p) ) { + // Check if it can be made surprising + containsGreaterThanP.add(t); + } else if ( t.contains(p-1) > 1 && p > 1 && t.contains(0) <= 1) { + containsPminus1.add(t); + } + } +// System.out.println(""Googlers: "" + numGooglers); +// System.out.println(""Surprising: "" + numSurprising); +// System.out.println(""P: "" + p); +// System.out.println(containsGreaterThanP); +// System.out.println(containsPminus1); + + return containsGreaterThanP.size() + Math.min(numSurprising, containsPminus1.size()); + + + } + + static class Triplet { + int[] values = new int[3]; + + int i = 0; + + public void add(int a) { + if ( i > 2) + throw new InputMismatchException(""Bad input""); + + values[i] = a; + i++; + } + + public int contains(int v) { + + int retval = 0; + + retval += values[0] == v ? 1 : 0; + retval += values[1] == v ? 1 : 0; + retval += values[2] == v ? 1 : 0; + + return retval; + + } + + public boolean containsGreaterThan(int v) { + // Ordered triplets + return values[0] >= v; + } + + public boolean allEqual() { + return values[0] == values[1] && values[1] == values[2]; + } + + public String toString() { + return ""("" + values[0] + "" "" + values[1] + "" "" + values[2] + "")""; + } + } +} +" +A20720,"import java.util.Scanner; + +/* + * Google Code Jam 2012 + * Program by Tommy Ludwig + * Problem: Dancing With the Googlers + * Date: 2012-04-13 + */ + + +public class dancing { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T, N, S, p; + T = in.nextInt(); + + for (int i = 1; i <= T; i++) { + int y = 0; + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + int [] t = new int[N]; + + for (int j = 0; j < N; j++) + t[j] = in.nextInt(); + + //minimum number with surprise case + int minNumS = (3 * p) - 4; + if (minNumS < 2) minNumS = 2; + //minimum number without surprise case + int minNum = (3 * p) - 2; + //if (minNum < 0) minNum = 0; + + for (int j = 0; j < N; j++) { + if (t[j] >= minNum) + y++; + else if (t[j] >= minNumS && S > 0) { + y++; + S--; + } + } + System.out.printf(""Case #%d: %d\n"", i, y); + } + } + +} +" +A23009,"import java.util.*; + import java.io.*; + import java.math.BigDecimal; +import java.math.BigInteger; + + + + +public class Main { + + + + private void solve() throws Exception { + int test = in.nextInt(); + for(int t=1; t <= test; ++t) { + solveTest(t); + out.println(); + } + } + private void solveTest(int testNum) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] t = new int[n]; + for(int i = 0; i < n; ++i) { + t[i] = in.nextInt(); + } + int[][] d = new int[n + 1][n + 1]; + for(int[] dd : d) + Arrays.fill(dd, -1); + + + d[0][0] = 0; + for(int i = 0; i < n; ++i) + for(int surp = 0; surp <= n; ++surp) { + int cur = d[i][surp]; + if (cur == -1) + continue; + + { + // surprise + for(int d1=0; d1 <= 10; ++d1) + for(int d2=d1; d2 <= 10; ++d2) + for(int d3=d2; d3 <= 10; ++d3) { + if (d1+d2+d3!=t[i] || d3-d1>2 || d3-d1==1) + continue; + int add = (d3 >= p ? 1 : 0); + d[i + 1][surp + 1] = Math.max(d[i + 1][surp + 1], cur + add); + } + } + { + // not surprise + for(int d1=0; d1 <= 10; ++d1) + for(int d2=d1; d2 <= 10; ++d2) + for(int d3=d2; d3 <= 10; ++d3) { + if (d1+d2+d3!=t[i] || d3-d1 > 1) + continue; + int add = (d3 >= p ? 1 : 0); + d[i + 1][surp] = Math.max(d[i + 1][surp], cur + add); + } + } + + } + int ans = d[n][s]; + out.print(""Case #"" + testNum + "": "" + ans); + + } + private void run() { + try { + long start = System.currentTimeMillis(); + in = new FastScanner(""input.txt"", ""output.txt""); + solve(); + out.flush(); + System.err.print(""running time = "" + (System.currentTimeMillis() - start) * 1e-3); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public static void main(String[] args) { + Main main = new Main(); + main.run(); + } + FastScanner in; + static PrintWriter out; + static class FastScanner { + public BufferedReader reader; + private StringTokenizer tokenizer; + public FastScanner(String input, String output) { + try { + reader = new BufferedReader(new FileReader(new File(input))); + out = new PrintWriter(new File(output)); + tokenizer = null; + } catch (Exception e) { + reader = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(System.out); + tokenizer = null; + } + } + public double nextDouble() { + return Double.parseDouble(nextToken()); + } + public String nextToken() { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + try { + tokenizer = new StringTokenizer(reader.readLine()); + } catch (Exception e) { + e.printStackTrace(); + } + } + return tokenizer.nextToken(); + } + int nextInt() { + return Integer.parseInt(nextToken()); + } + long nextLong() { + return Long.parseLong(nextToken()); + } + } + }" +A20538,"import java.util.Scanner; + + +public class DancingWiththeGooglers { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for (int index = 1; index <= T; index++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int count = 0; + int matter = 0; + int notmatter = 0; + while (N-- > 0) { + int score = in.nextInt(); + if (score >= 29) { //at least one judge gave 10 + count++; + } else if (score <= 1) { + if (score >= p) + count++; + } else { + int div = score / 3; + int mod = score % 3; + if (mod == 0) { + if (div + 1 >= p) { + if (div + 1 == p) + matter++; + else + notmatter++; + } + } else if (mod == 1) { + if (div + 1 >= p) + notmatter++; + } else { + if (div + 2 >= p) { + if (div + 2 == p) + matter++; + else + notmatter++; + } + } + } + } + count += notmatter + Math.min(S, matter); + System.out.println(""Case #"" + index + "": "" + count); + } + } + +} +/* +4 +3 1 5 15 13 11 +3 0 8 23 22 21 +2 1 1 8 0 +6 2 8 29 20 8 18 18 21 +*/" +A20672,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class Dancing { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // read input file + File file = new File(""B-large.in""); + //File file = new File(""input.txt""); + BufferedReader br = new BufferedReader(new FileReader(file)); + String ln = """"; + int count = Integer.parseInt(br.readLine()); + + // write output file + File out = new File(""outB.txt""); + BufferedWriter bw = new BufferedWriter(new FileWriter(out)); + + int y = 0; + for (int i=0; i < count; i++){ + ln = br.readLine(); + y = getY(ln); + bw.write(""Case #"" + (i+1) + "": "" + y); + bw.newLine(); + } + bw.close(); + } + + private static int getY(String str) { + String[] data = str.split("" ""); + int n = Integer.parseInt(data[0]); + int s = Integer.parseInt(data[1]); + int p = Integer.parseInt(data[2]); + int[] t = new int[n]; + for (int i=0; i < n; i++){ + t[i] = Integer.parseInt(data[i+3]); + } + int y = 0; + int base = 0; + for(int j=0; j < t.length; j++){ + base = t[j] / 3; + if(base >= p) { y++; } + else if(base == p-1){ + if(t[j] - (base+p) > base-1 && t[j] > 0){ + y++; + } else if(s>0 && t[j] - (base+p) > base-2 && t[j] > 0){ + s -= 1; + y++; + } + } else if(base == p-2){ + if(s > 0 && t[j] - (base+p) > base-1 && t[j] > 0){ + s -= 1; + y++; + } + } + } + + return y; + } + +} +" +A21147,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package dancing; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +/** + * + * @author admin + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + // TODO code application logic here + FileReader fr=new FileReader(""B-large.in""); + BufferedReader br=new BufferedReader(fr); + FileWriter fw=new FileWriter(""result3.txt""); + PrintWriter pw=new PrintWriter(fw); +getOutPut(br,pw); +pw.close(); + } + public static void getOutPut(BufferedReader br,PrintWriter pw) throws IOException { + int t=Integer.parseInt(br.readLine()); + int N,S,P; + int[] num; + for(int i=0;i=P&&(num[i])/3>=0){ + count++; + } + else if ((num[i] + 3) / 3 >= P && ((num[i] / 3) - 1 >= 0)&&S>0) + {count++; + S--; + } + } + if(num[i]%3==1){ + if((num[i]+2)/3>=P&&((num[i]+2)/3)-1>=0 ){ + count++; + } + else if ((num[i] + 2) / 3 >= P && ((num[i] + 2) / 3) - 2 >= 0&&S>0) { + count++; + S--; + } + + } + if(num[i]%3==2){ + if((num[i]+1)/3>=P&&((num[i]+1)/3)-1>=0){ + count++; + } + else if (S>0&&(num[i] + 4) / 3 >= P && ((num[i] + 4) / 3) - 2 >= 0) { + count++; + // System.out.print(num[i]+"" ""); + S--; + } + + } + } + return count; + } +} +" +A21329,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + +public class B { + public static void main(String[] args) throws IOException { + StringBuilder sb = new StringBuilder(); + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); + StringTokenizer tokenizer = new StringTokenizer(reader.readLine(), "" ""); + int testCases = Integer.valueOf(tokenizer.nextToken()); + int currentCase = 0; + while (++currentCase <= testCases) { + tokenizer = new StringTokenizer(reader.readLine(), "" ""); + int googlers = Integer.valueOf(tokenizer.nextToken()); + int surprises = Integer.valueOf(tokenizer.nextToken()); + int topScore = Integer.valueOf(tokenizer.nextToken()); + int worseScore = topScore - 1; + if (worseScore < 0) + worseScore = 0; + int worstScore = topScore - 2; + if (worstScore < 0) + worstScore = 0; + int result = 0; + while (--googlers >= 0) { + int score = Integer.valueOf(tokenizer.nextToken()); + if (score >= topScore + worseScore + worseScore) + result++; + else if (surprises > 0 && score >= topScore + worstScore + worstScore) { + result++; + surprises--; + } + } + sb.append(""Case #"" + currentCase + "": "" + result + '\n'); + } + reader.close(); + FileWriter fileWriter = new FileWriter(""output.txt""); + fileWriter.write(sb.toString()); + fileWriter.close(); + } +} + +" +A20223,"package codejam2.dancing; + +import java.util.Scanner; + +import codejam2.CodejamCase; +import codejam2.CodejamRunner; + +public class Dancing extends CodejamRunner implements CodejamCase { + + private int nGooglers; + private int surprising; + private int pointMin; + private int[] points; + private String result; + @Override + public void compute() { + int ns = 0; + int s = 0; + + for(int i = 0; i < nGooglers; i++) { + if(points[i] >= 3*pointMin-2) + ns++; + else if(pointMin>1 && points[i] >= 3*pointMin-4) + s++; + } + result = String.valueOf(ns + Math.min(s, surprising)); + + } + + @Override + public String getOutput() { + return result; + } + + @Override + public CodejamCase parseCase(Scanner s) { + Dancing d = new Dancing(); + d.nGooglers = s.nextInt(); + d.surprising = s.nextInt(); + d.pointMin = s.nextInt(); + d.points = new int[d.nGooglers]; + for(int i = 0; i < d.nGooglers; i++) + d.points[i] = s.nextInt(); + return d; + } + + /** + * @param args + */ + public static void main(String[] args) { + new Dancing().run(args); + } + +} +" +A21369,"package qualification; + +import java.util.Scanner; + +public class Dancing { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int num = scan.nextInt(); + for(int i=0; i= score) + count++; + else if(surprisesLeft > 0) { + if(totalScores[i] > 0 && (totalScores[i]/3 + (totalScores[i]%3 == 2 ? 2 : 0) >= score || totalScores[i]/3 + 1 >= score)) { + count++; + surprisesLeft--; + } + } + } + return count; + } + +} +" +A21773," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + + +/** + * + * @author Shubham + */ +public class Dancers { + + public static void main(String a[]) throws IOException + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + for(int i=1;i<=t;i++) + { + String line = br.readLine(); + String[] ints = line.split("" ""); + int n = Integer.parseInt(ints[0]); + int s = Integer.parseInt(ints[1]); + int l = Integer.parseInt(ints[2]); + int c=0; + for(int j=3;j<3+n;j++) + { + int sum = Integer.parseInt(ints[j]); + int r = sum - 3*l; + if(sum>=l) + { + if(r>=-2) + { + c++; + } + else if(r>=-4 && s>0) + { + c++; + s--; + } + } + } + System.out.println(""Case #""+i+"": ""+c); + } + } +} +" +A21134,"import java.io.*; +import java.util.*; +public class B { + public static int a []; + public static void main(String[] args) throws Exception{ + int N = 100; + a = new int[N]; + File f = new File(""B-large.in""); + Scanner sc = new Scanner(f); + int t = sc.nextInt(); + BufferedWriter bw = new BufferedWriter(new FileWriter(""output.txt"")); + for(int i = 0;i30) continue; + if((a[i]>= 3*p)||((a[i]+1 == 3*p||a[i]+2 == 3*p)&&p>=1)) + t ++; + else { + if(s>0) + if((a[i]+3 == 3*p||a[i]+4 == 3*p)&&p>=2){ + s--; + t++; + } + } + } + return t; + } +}" +A22906,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Scanner; + +public class B { + HashMap>> pre = new HashMap>>(); + { + for(int a = 0; a <= 10; a++) + for(int b = 0; b <= a; b++) + for(int c = 0; c <= b; c++){ + ArrayList tmp = new ArrayList(); + tmp.add(a); + tmp.add(b); + tmp.add(c); + Integer sum = a + b + c; + if(a - c > 2) continue; + if(pre.get(sum) == null) + pre .put(sum, new HashSet>()); + pre.get(sum).add(tmp); + } + } + /* + * 18 = 6 6 6, 5 6 7 + * 19 = 5 7 7, 6 6 7 + * 20 = 6 7 7 + * 21 = 7 7 7, 6 7 8 + * 28 = 8 10 10 + */ + private boolean isSurprize(ArrayList a){ + return (a.get(0) - a.get(2)) == 2; + } + private boolean canBeSurprize(int a) { + for(ArrayList t: pre.get(a)) + if(isSurprize(t)) return true; + return false; + } + private int getBestScore(int a, boolean surprize){ + int best = -1; + for(ArrayList t: pre.get(a)) + { + if(surprize != isSurprize(t)) + continue; + if(best < t.get(0)) + best = t.get(0); + } + return best; + } + private void printState(int a){ + for(ArrayList t: pre.get(a)){ + for(Integer i: t) + System.out.print(i + "" ""); + System.out.print("", ""); + } + System.out.println(); + } + private void run() throws FileNotFoundException { + Scanner sc = new Scanner(new FileInputStream(""B-large.in"")); + System.setOut(new PrintStream(new FileOutputStream(""b.out""))); + int t = sc.nextInt(); + for (int i = 0; i < t; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int arr[] = new int[n]; + for (int j = 0; j < n; j++) { + arr[j] = sc.nextInt(); +// printState(arr[j]); + } + Arrays.sort(arr); + int bes[] = new int[n]; + for(int j = n - 1; j >= 0; j--){ + int bestS = getBestScore(arr[j], true); + int bestNS = getBestScore(arr[j], false); + if(bestNS >= p){ + bes[j] = bestNS; + continue; + } + if(s > 0 && bestS >= p) + { + bes[j] = bestS; + s--; + continue; + } + + bes[j] = bestNS; + } + int res = 0; + for(int j = 0; j < bes.length; j++) + if(bes[j] >= p) res++; + + System.out.println(""Case #"" + (i + 1) + "": "" + res); + } + } + + public static void main(String[] args) throws FileNotFoundException { + B b = new B(); + b.run(); + } +} +" +A22420,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.StringTokenizer; + +class GoogleDance{ + + HashMap nonSurpriseMax = new HashMap(); + HashMap surpriseMax = new HashMap(); + + GoogleDance(){ + nonSurpriseMax.put(0, 0); + nonSurpriseMax.put(1, 1); + nonSurpriseMax.put(2, 1); + nonSurpriseMax.put(3, 1); + nonSurpriseMax.put(4, 2); + nonSurpriseMax.put(5, 2); + nonSurpriseMax.put(6, 2); + nonSurpriseMax.put(7, 3); + nonSurpriseMax.put(8, 3); + nonSurpriseMax.put(9, 3); + nonSurpriseMax.put(10, 4); + nonSurpriseMax.put(11, 4); + nonSurpriseMax.put(12, 4); + nonSurpriseMax.put(13, 5); + nonSurpriseMax.put(14, 5); + nonSurpriseMax.put(15, 5); + nonSurpriseMax.put(16, 6); + nonSurpriseMax.put(17, 6); + nonSurpriseMax.put(18, 6); + nonSurpriseMax.put(19, 7); + nonSurpriseMax.put(20, 7); + nonSurpriseMax.put(21, 7); + nonSurpriseMax.put(22, 8); + nonSurpriseMax.put(23, 8); + nonSurpriseMax.put(24, 8); + nonSurpriseMax.put(25, 9); + nonSurpriseMax.put(26, 9); + nonSurpriseMax.put(27, 9); + nonSurpriseMax.put(28, 10); + nonSurpriseMax.put(29, 10); + nonSurpriseMax.put(30, 10); + + surpriseMax.put(0, 0); + surpriseMax.put(1, 1); + surpriseMax.put(2, 2); + surpriseMax.put(3, 2); + surpriseMax.put(4, 2); + surpriseMax.put(5, 3); + surpriseMax.put(6, 3); + surpriseMax.put(7, 3); + surpriseMax.put(8, 4); + surpriseMax.put(9, 4); + surpriseMax.put(10, 4); + surpriseMax.put(11, 5); + surpriseMax.put(12, 5); + surpriseMax.put(13, 5); + surpriseMax.put(14, 6); + surpriseMax.put(15, 6); + surpriseMax.put(16, 6); + surpriseMax.put(17, 7); + surpriseMax.put(18, 7); + surpriseMax.put(19, 7); + surpriseMax.put(20, 8); + surpriseMax.put(21, 8); + surpriseMax.put(22, 8); + surpriseMax.put(23, 9); + surpriseMax.put(24, 9); + surpriseMax.put(25, 9); + surpriseMax.put(26, 10); + surpriseMax.put(27, 10); + surpriseMax.put(28, 10); + surpriseMax.put(29, 10); + surpriseMax.put(30, 10); + } + + + int getcount(String input){ + int p = 0,surprises=0; + + int no_of_score =0; + int count=0; + StringTokenizer t = new StringTokenizer(input); + + if(t.hasMoreTokens()){ + no_of_score = Integer.parseInt(t.nextToken()); + } + if(t.hasMoreTokens()){ + surprises = Integer.parseInt(t.nextToken()); + } + if(t.hasMoreTokens()){ + p = Integer.parseInt(t.nextToken()); + } + while(t.hasMoreTokens()){ + + int inputsum = Integer.parseInt(t.nextToken()); + + if(nonSurpriseMax.get(inputsum) >= p) + count++; + else if(surpriseMax.get(inputsum) >= p && surprises >0 ){ + surprises--; + count++; + + } + } + return count; + } + + + public static void main(String args[]){ + + GoogleDance d = new GoogleDance(); + + int no_of_cases = 0; + String input = """"; + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + try{ + no_of_cases = Integer.parseInt(br.readLine()); + } + catch(Exception e){ + System.out.println(""First line is not a number""); + } + + for(int i=1; i <= no_of_cases;i++){ + try{ + input = br.readLine(); + } + catch(Exception e){ + System.out.println(""Number of test cases different from the number mentioned in first line""); + } + + System.out.print(""Case #"" +i+"": ""); + System.out.println(d.getcount(input)); + + + + } + + + } +}" +A21901," +import codejam.StoreCredit; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author java + */ +public class DancingGooglers { + + static BufferedReader in; + + private static void open() { + in = new BufferedReader(new InputStreamReader(System.in)); + } + + private static void close() { + try { + in.close(); + } catch (IOException ex) { + Logger.getLogger(StoreCredit.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private static int readInt() throws IOException { + Integer i = Integer.parseInt(in.readLine()); + return i; + } + + private static int[] readInts() throws IOException { + String[] vals = in.readLine().split("" ""); + int[] arr = new int[vals.length]; + for (int i = 0; i < vals.length; i++) { + arr[i] = Integer.parseInt(vals[i]); + } + return arr; + } + + public static void main(String[] args) throws IOException { + open(); + int T = readInt(); + for (int t = 0; t < T; t++) { + int[] line = readInts(); + int N = line[0]; + int s = line[1]; + int p = line[2]; + int pCount = 0; + int[] scores = new int[line.length - 3]; + System.arraycopy(line, 3, scores, 0, scores.length); + if (p == 0) { + pCount = scores.length; + } else { + for (int i = 0; i < scores.length; i++) { + int score = scores[i]; + int minSum = p + (2 * (p - 2) < 0 ? 0 : 2 * (p - 2)); + if (p == 1) { + if (score >= p) { + pCount++; + } + } else if ((score == minSum || score == minSum + 1) && s > 0) { + pCount++; + s--; + } else if (score > minSum + 1) { + pCount++; + } + } + } + System.out.println(""Case #"" + (t + 1) + "": "" + pCount); + } + + close(); + } +} +" +A22046,"import java.io.*; + +public class Prof2ProB { + public static void main(String args[]) { + try { + BufferedReader breader = new BufferedReader(new FileReader(""F:\\test.txt"")); + int noo; + noo= Integer.parseInt(breader.readLine()); + + int casen=0; + int noofgglrs; + int specialcases; + int maxnumber,i; + String tempstr; + String outp; + outp=""""; + String nos[]; + int tmp; + int count; + + while( casen < noo ) { + tempstr = breader.readLine(); + nos = tempstr.split("" ""); + outp += ""Case #""+(casen+1)+"": ""; + + noofgglrs = Integer.parseInt(nos[0]); + specialcases = Integer.parseInt(nos[1]); + maxnumber = Integer.parseInt(nos[2]); + + count = 0; + + for(i=0;i= maxnumber ) + count++; + else if( tmp%3 == 1 && (tmp/3)+(tmp%3) >= maxnumber) { + System.out.println(""here2:"" + tmp); + count++; + } + else if( tmp%3 == 2 && specialcases > 0 && (tmp%3)+(tmp/3) >= maxnumber ) { + System.out.println(""here: "" + tmp); + count++; + specialcases--; + } + else if( tmp%3 == 2 && ((tmp/3)+((tmp/3)+1)*2) == tmp && (tmp/3)+1>=maxnumber ) { + System.out.println(""here3: "" + tmp); + count++; + } + else if( tmp!=0 && tmp%3 == 0 && specialcases > 0 && (tmp/3)+1 >= maxnumber ) { + System.out.println(""here1: "" + tmp); + count++; + specialcases--; + } + } + outp += count; + if( casen != noo-1 ) + outp += ""\n""; + casen++; + } + System.out.println(outp); + + BufferedWriter bwrtr = new BufferedWriter( new FileWriter(""F:\\result.txt"")); + bwrtr.write(outp); + bwrtr.close(); + breader.close(); + } + catch( Exception e ) { + e.printStackTrace(); + } + } +} +" +A22698,"package javaapplication2; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class DancingWithTheGooglers { + private final static String INPUT_PATH = ""resources/dancing_with_the_googlers.in""; + private final static String OUTPUT_PATH = ""resources/dancing_with_the_googlers.out""; + private static int caseNumber = 0; + + public static void main(String[] args) throws FileNotFoundException, IOException { + try (Scanner scanner = new Scanner(new File(INPUT_PATH))) { + int T = scanner.nextInt(); + try (FileWriter out = new FileWriter(OUTPUT_PATH)) { + for (int i = 0; i < T; ++i) { + processCase(scanner, out); + } + } + } + } + + private static void processCase(Scanner scanner, FileWriter out) throws IOException { + out.write(""Case #"" + (++caseNumber) + "": ""); + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int result = 0; + for (int i = 0; i < N; ++i) { + int P = scanner.nextInt(); + if ((P + 2) / 3 >= p) { + ++result; + } else if (p + 2 * Math.max(p - 2, 0) <= P && S > 0) { + ++result; + --S; + } + } + out.write(result + """"); + out.write(""\n""); + } +} +" +A20548,"import java.io.*; +import java.util.*; + +/** + * + * @author posv + */ + +public class GoogleDance{ + public static void main(String[] args){ + int cs = 0; + int n,s,p,ln,count,counts,total,temp; + count = 0; counts = 0; total = 0; + //List scores = new ArrayList(); + try{ + File file = new File(""lines1.txt""); + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line = null; + while ((line = reader.readLine()) != null){ + String[] tokens = line.split("" ""); + //System.out.println(""Length : #"" +tokens.length); + ln = tokens.length; + if(cs==0){ + cs++; + continue; + } else { + n = Integer.parseInt(tokens[0]); + s = Integer.parseInt(tokens[1]); + p = Integer.parseInt(tokens[2]); + for(int i=3;i= (p*3-2)) { + count++; + }else if(temp >= (p*3-4) && temp < (p*3-2)){ + counts++; + } + } + if(counts >= s){ + total = count + s; + } else{ + total = count + counts; + } + System.out.println(""Case #"" +cs+"": "" +total); + } + cs++; + count = 0; counts = 0; total = 0; + } + } catch(Exception ex){ + ex.printStackTrace(); + } + } +} +" +A20855,"import java.util.Arrays; +import java.util.Scanner; + +public class DanceJudging { + + public static int count(int[] totalPoints, int numSurprise, int target) { + final int totalMin = target + ((target >= 1) ? (target - 1) : 0) * 2; + final int surpriseTotalMin = target + ((target >= 2) ? (target - 2) : 0) * 2; + int count = 0; + Arrays.sort(totalPoints); + for (int i = totalPoints.length - 1; i >= 0; i--) { + if (totalPoints[i] >= totalMin) { + count++; + } else if (numSurprise > 0 && totalPoints[i] >= surpriseTotalMin) { + numSurprise--; + count++; + } else { + break; + } + } + + return count; + } + + public static void main(String[] args) { + final Scanner in = new Scanner(System.in); + final int numCase = in.nextInt(); + in.nextLine(); + int numGoogler, numSurprise, target; + int[] totalPoints; + for (int i = 0; i < numCase; i++) { + numGoogler = in.nextInt(); + numSurprise = in.nextInt(); + target = in.nextInt(); + totalPoints = new int[numGoogler]; + for (int j = 0; j < numGoogler; j++) { + totalPoints[j] = in.nextInt(); + } + System.out.println(""Case #"" + (i+1) + "": "" + count(totalPoints, numSurprise, target)); + in.nextLine(); + } + } +} +" +A21844,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class B_Small { + + static int[] resu; + + /** + * @param args + */ + public static void main(String[] args) { + File input=new File(""D:\\Users\\xiaoguo\\Downloads\\B-small-attempt0.in""); + File output=new File(""D:\\Users\\xiaoguo\\Desktop\\output.txt""); + readCaseFromInput(input); + writeToOutput(output); + System.out.println(""Programe exist!""); + } + + static void readCaseFromInput(File input ) + { + try { + FileReader reader=new FileReader(input); + BufferedReader buf=new BufferedReader(reader); + int numberCase=Integer.parseInt(buf.readLine()); + resu=new int[numberCase]; + String contentLine=null; + int numerLine=0; + while((contentLine=buf.readLine())!=null) + { + String[] tab=contentLine.split(""\\s""); + int s=Integer.parseInt(tab[1]); + int p=Integer.parseInt(tab[2]); + int n=0; + int needS=0; + for(int i=3;i=Math.max((3*p-4),p)) + { + + if(totalP>=(3*p-2)) + { + n++; + } + else + { + needS++; + } + } + } + n+=Math.min(needS, s); + resu[numerLine]=n; + numerLine++; + } + + buf.close(); + reader.close(); + + + } catch (Exception e) { + e.printStackTrace(); + } + } + + static void writeToOutput(File output) + { + try { + FileWriter out=new FileWriter(output); + BufferedWriter buf=new BufferedWriter(out); + String headLine=""Case #""; + for(int i=0;i 0) { + possible++; /* 0 */ + isSurprising++; + } else if (totals[j] % 3 == 1) { + possible++; + } else if (totals[j] % 3 == 2) { + possible++; + } + } else if (p - (totals[j] / 3) == 2) { + if (totals[j] % 3 == 0) { + + } else if (totals[j] % 3 == 1) { + + } else if (totals[j] % 3 == 2) { + possible++; + isSurprising++; + } + } + } + + if (isSurprising > surprising) { + possible -= isSurprising - surprising; + } + + System.out.println(""Case #"" + i + "": "" + possible); + } + } + +} +" +A22811,"import java.io.FileWriter; +import java.io.IOException; + + +public class OutputPrinter { + public OutputPrinter() + { + try { + m_writer = new FileWriter(""C:/AHK/output.txt""); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + FileWriter m_writer; + + int m_case = 1; + public void print(String result) + { + try { + m_writer.write(""Case #""+ (m_case++)+"": "" + result + ""\n""); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} +" +A22157,"import java.io.*; +import java.util.Scanner; + +public class B { + +public static void main(String[] args) throws FileNotFoundException, IOException { + Scanner sc = new Scanner(new FileReader(""input.txt"")); + PrintWriter pw = new PrintWriter(new FileWriter(""output.txt"")); + + int noOfCases = sc.nextInt(); + +for (int caseNum = 0; caseNum < noOfCases; caseNum++){ + int noOfGooglers = sc.nextInt(); + int supprizing = sc.nextInt(); + int bestScore = sc.nextInt(); + int scores[] = new int[noOfGooglers]; + int result = 0; + for (int i = 0; i < noOfGooglers; i++) { + scores[i] = sc.nextInt(); + } + + int suppLowest = ((bestScore-1)*3)-1; + int normLowest = (bestScore*3)-2; + + for (int i = 0; i < scores.length; i++) { + if(scores[i]==0){ + if(bestScore==0){ + result++; + } + } + else if(scores[i]>=normLowest){ + result++; + } + else if(scores[i]>=suppLowest){ + if(supprizing>0){ + result++; + supprizing--; + } + } + + } + + pw.print(""Case #"" + (caseNum + 1) + "": "" + result); + + if(caseNum < noOfCases-1) + pw.println(""""); +} + + + pw.flush(); + pw.close(); + sc.close(); +} +} + +" +A21277,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Problem2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + +/** + * + * @author Mohammed + */ +public class NewDancers { + + static int in[][], out[]; + + private static void readFile(String fileName) throws FileNotFoundException, IOException { + BufferedReader br = new BufferedReader(new FileReader(fileName)); + String line; + int x = Integer.parseInt(br.readLine()); + + in = new int[x][103]; + out = new int[x]; + + for (int i = 0; i < x; i++) { + line = br.readLine(); + StringTokenizer st = new StringTokenizer(line); + int j = 0; + while (st.hasMoreTokens()) { + in[i][j++] = Integer.parseInt(st.nextToken()); + } + + } + } + + private static void writeOutput(String string) throws IOException { + BufferedWriter bw = new BufferedWriter(new FileWriter(string)); + for (int i = 0; i < out.length; i++) { + bw.write(""Case #"" + (i + 1) + "": "" + out[i]); + if (i != out.length - 1) { + bw.write(""\r\n""); + } + } + bw.close(); + } + + public static void main(String[] args) throws FileNotFoundException, IOException { + readFile(""data""); + for (int i = 0; i < in.length; i++) { + int googlers = in[i][0]; + int surp = in[i][1]; + int p = in[i][2]; + int minCountedTriplet = 3 * p - 2; + int minCountedTripletWithSur = 3 * p - 4; + int output = 0; + for (int j = 3; j < googlers + 3; j++) { + int temp = in[i][j]; + if (temp >= minCountedTriplet) { + output++; + } else { + if (surp > 0 && temp >= minCountedTripletWithSur && minCountedTripletWithSur >= 0) { + output++; + surp--; + } + } + + } + out[i] = output; + } + writeOutput(""output.txt""); + } +}" +A22687,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class Googlers { + public static void main(String args[])throws IOException{ + Scanner scan = new Scanner(new File(System.getProperty(""user.dir"")+""/input.in"")); + FileWriter file = new FileWriter(""output.out""); + int n=Integer.parseInt(scan.nextLine()); + for(int j=0;j=0&&p-(int)Math.floor(totalsMinus[i]/2)<=2){ + max++; + if(p-(int)Math.floor(totalsMinus[i]/2)==2) + surprising++; + } + } + while(surprising>totalSurprising){ + surprising--; + max--; + } + file.write(""Case #""+Integer.toString(j+1)+"": ""+Integer.toString(max)+""\r\n""); + } + file.close(); + } +} +" +A21053,"package QualificationRound; + + import java.io.BufferedReader; + import java.io.File; + import java.io.FileNotFoundException; + import java.io.FileReader; + import java.io.IOException; + import java.util.ArrayList; +import java.util.Dictionary; +import java.util.regex.Pattern; + + public class B + { + public B() + { + + } + public int solveLine(String in) + { + String[] input = in.split("" ""); + int N = Integer.parseInt(input[0]); //N - number of googlers + int S = Integer.parseInt(input[1]); //S - suprising results + int P = Integer.parseInt(input[2]); //P - at lest best result criteria + int P3 = P * 3; + int Pmin = P3-3; + int Sleft = S; + int totalPoints = 0; + int maxNumOfGooglerDancers = 0; + if (Pmin == 0) + { + Pmin = 2; + } + for (int i=0; i Pmin) + { + maxNumOfGooglerDancers++; + } + else + if (((totalPoints == Pmin)||((totalPoints == (Pmin-1)))) && (Sleft > 0)) + { + maxNumOfGooglerDancers++; + Sleft--; + } + + } + else + { + maxNumOfGooglerDancers++; + } + } + return maxNumOfGooglerDancers; + } + + + + public static void calcFromFile(String fileName) + { + + File file = new File(fileName); + BufferedReader reader = null; + + try { + reader = new BufferedReader(new FileReader(file)); + String sentence = null; + // repeat until all lines is read + int numOfLine = 1; + B q2 = new B(); + sentence = reader.readLine(); + + //Read the n test cases + while ((sentence = reader.readLine()) != null) + { + System.out.println(""Case #"" + numOfLine++ + "": ""+q2.solveLine(sentence)); + } + + + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + +" +A22006,"package code12; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.List; + +public class Googlers { + + public static void main(String[] args) { + + try { + BufferedReader fileGoo = new BufferedReader(new FileReader(""B-large.in"")); + FileWriter miArchivo = new FileWriter(""B-large.out""); + + List listaCasos = new ArrayList(); + String linea; + while ((linea = fileGoo.readLine()) != null) { + listaCasos.add(linea); + } + int casos = new Integer(listaCasos.get(0)); + + listaCasos.remove(0); + int indc=1; + + if (casos>0 && casos<=100){ + for (String cadenas: listaCasos) { + String [] valores= cadenas.split("" ""); + int n= new Integer (valores[0]); + int s= new Integer (valores[1]); + int p= new Integer (valores[2]); + if(s<0 || s>n) + continue; + if(p<0 || p>10) + continue; + if(n<1 || n>100) // SmallData + continue; + + int contador = 0; + int casoEsp=1; + for (int i = 3; i < valores.length; i++) { + Integer p1= p-1<0?0:p-1; + Integer p2= p-2<0?0:p-2; + Integer valor =new Integer(valores[i]); + Integer caso1 = p+ p+ p; + Integer caso2 = p+ p+ p1; + Integer caso3 = p+ p1+ p1; + Integer caso4 = p+ p1+ p2; + Integer caso5 = p+ p2+ p2; + Integer caso6 = p+ p+ p2; + + if(valor<0 || valor>30) + continue; + + if (caso10 && casoEsp<=s) && (caso4.equals(valor) || caso5.equals(valor)|| caso6.equals(valor))){ + contador++; + casoEsp++; + } + } + miArchivo.write(""Case #"" + indc + "": "" + contador+""\n""); + indc++; + } + } + + + + miArchivo.flush(); + miArchivo.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} +" +A21625,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package javaapplication2; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.*; + +/** + * + * @author fawad + */ +public class codejam2 { + //static char arr[]={'a',98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122}; + //static char res[] = {'y','h','e','s','o','c','v','x','d','u','i','g','l','b','k','r','z','t','n','w','j','p','f','m','a','q'}; + static int ar[] = {0, 1, 1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9, 9, 10,10,10}; + static int arsur[] ={-1,-1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,-1,-1}; + public static void main(String args[]){ + + try{ + FileReader fr = new FileReader(""B-large.in""); + //FileReader fr = new FileReader(""New.txt""); + BufferedReader br = new BufferedReader(fr); + int size = Integer.parseInt(br.readLine()); + for(int i=0;i1 && arrayint[j1]<29){ + if(S>0){ + if(arsur[arrayint[j1]] >= P){ + S--; + result++; + }else if(ar[arrayint[j1]] >= P){ + result++; + } + }else if(ar[arrayint[j1]] >= P){ + result++; + } + }else{ + if( ar[arrayint[j1]] >= P){ + result++; + } + } + } + + + System.out.println(""Case #""+(i+1)+"": ""+result); + } + + br.close(); + fr.close(); + + }catch(IOException ex){ + ex.printStackTrace(); + } + + //System.out.println(arr[25]+""""); + } + +} +" +A21174,"package codejam2012.qualified; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class ProblemB { + + static BufferedReader buffReader = null; + static BufferedWriter buffWriter = null; + static FileReader fileReader = null; + static FileWriter fileWriter = null; + static String input_test = ""/home/qimeng/problemB.test""; + static String input_small = ""/home/qimeng/B-small-attempt1.in""; + static String input_large = ""/home/qimeng/B-large.in""; + + public static final void main(String[] args){ + try { + fileReader = new FileReader(input_large); + buffReader = new BufferedReader(fileReader); + fileWriter = new FileWriter(""/home/qimeng/problemB.out""); + buffWriter = new BufferedWriter(fileWriter); + + int total_size = Integer.parseInt(buffReader.readLine()); + //iterate through every input line + for(int i=1; i<=total_size; i++){ + String[] str = buffReader.readLine().split("" ""); + int strLen = str.length; + + int T = Integer.parseInt(str[0]); + int s = Integer.parseInt(str[1]); + int p = Integer.parseInt(str[2]); + + int[] scores = new int[T]; + + int k = 0; + for(int j=3; j= p){ + result++; + } + else { + if(rem == 0){ + if(avg + 1 >= p) { + if(s>0){ + result++; + s--; + } + } + } + else if(rem == 1){ + if(avg + 1 >= p) { result++; } + } + else if(rem == 2){ + if(avg + 2 >= p) { + if(avg+1>=p){ result++;} + else{ + if(s>0){ + result++; + s--; + } + } + } + } + } + i++; + } + + return result; + } +} +" +A21526,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package dancingwithgooglers; + +import java.io.*; + +/** + * + * @author Intellitech + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static int isGreat(long S, long total_score, boolean can_be_great) + { + long[] local_score = new long[3]; + + for (int i = 0; i < 3; i++) + { + local_score[i] = total_score/3; + } + + int rem = (int) (total_score % 3); + int i = 0; + + while (rem > 0) + { + local_score[i]++; + rem--; + i++; + } + + if (local_score[0] >= S) + return 1; + + if (can_be_great == false) + return 0; + + if (local_score[0] == local_score[1] && local_score[1] != 0) + { + local_score[0]++; + local_score[1]--; + } + if (local_score[0] >= S) + return 2; + return 0; + + } + public static void main(String[] args) throws Exception { + // TODO code application logic here + BufferedReader reader = new BufferedReader(new FileReader(new File(""input.txt""))); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""output.txt""))); + reader.readLine(); + + String input = """"; + int CASE = 1; + while ((input = reader.readLine()) != null) + { + String[] tokens = input.split("" ""); + int N = Integer.parseInt(tokens[0]); + long S = Long.parseLong(tokens[1]); + long P = Long.parseLong(tokens[2]); + + boolean can_be_great = false; + if (S > 0) + can_be_great = true; + int total_count = 0; + for (int i = 0; i < N; i++) + { + long currentMax = Long.parseLong(tokens[i+3]); + int result = isGreat(P, currentMax, can_be_great); + if (result == 1) + total_count++; + else if (result == 2) + { + S--; + total_count++; + if (S <= 0) + can_be_great = false; + } + } + + writer.write(""Case #"" + CASE + "": "" + total_count+""\n""); + CASE++; + } + writer.close(); + reader.close(); + + } + +} +" +A22055,"import java.io.*; +import java.util.*; + +public class Solution { + + + private StringTokenizer st; + private BufferedReader in; + private PrintWriter out; + +// final String file = ""sample""; + final String file = ""B-large""; + + public void solve() throws IOException { + int tests = nextInt(); + for (int test = 0; test < tests; ++test) { + int n = nextInt(); + int k = nextInt(); + int p = nextInt(); + int[] d = new int[k + 1]; + Arrays.fill(d, -1000000000); + d[0] = 0; + for (int i = 0; i < n; ++i) { + int[] d1 = new int[k + 1]; + int a = nextInt(); + int val0 = -1000000000, val1 = -1000000000; + for (int u = 0; u <= 10 && 3 * u <= a; ++u) { + for (int v = u; v <= 10 && v <= u + 2 && u + 2 * v <= a; ++v) { + int w = a - u - v; + if (w <= u + 2 && w >= 0 && w <= 10) { + if (w - u <= 1) { + val0 = Math.max(val0, w >= p ? 1 : 0); + } else { + val1 = Math.max(val1, w >= p ? 1 : 0); + } + } + } + } + for (int j = 0; j <= k; ++j) { + d1[j] = d[j] == -1000000000 ? -1000000000 : d[j] + val0; + } + for (int j = 0; j < k; ++j) { + if (d[j] != -1000000000) { + d1[j + 1] = Math.max(d1[j + 1], d[j] + val1); + } + } + d = d1; + } + out.printf(""Case #%d: %d%n"", test + 1, d[k]); + } + } + + public void run() throws IOException { + in = new BufferedReader(new FileReader(file + "".in"")); + out = new PrintWriter(file + "".out""); + eat(""""); + + solve(); + + out.close(); + } + + void eat(String s) { + st = new StringTokenizer(s); + } + + String next() throws IOException { + while (!st.hasMoreTokens()) { + String line = in.readLine(); + if (line == null) { + return null; + } + eat(line); + } + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + long nextLong() throws IOException { + return Long.parseLong(next()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + public static void main(String[] args) throws IOException { + Locale.setDefault(Locale.US); + new Solution().run(); + } + +}" +A22884,"import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + + +public class Parser { + + private Scanner sc; + private int ncases; + private int curcase; + + public Parser(String inputFile) throws FileNotFoundException { + InputStream input = (inputFile == null) ? System.in : new FileInputStream(new File(inputFile)); + sc = new Scanner(input); + ncases = sc.nextInt(); + } + + public boolean hasNext() { + return ncases > curcase; + } + + public Case nextCase() { + if (!hasNext()) + return null; + curcase++; + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + List g = new ArrayList(n); + for (int i = 0; i < n; i++) + g.add(sc.nextInt()); + return new Case(curcase, n, s, p, g); + } + +}" +A21019,"import java.util.Scanner; + +public class GoogleDancers { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); + + for (int i = 1; i <= n; i++) { + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int count = 0; + int p2 = (p - 1) + (p - 1) + p; + + int t; + int t1; + for (int j = 0; j < N; j++) { + t = scan.nextInt(); + if (t > 0 || p == 0) { + if ((t1 = t - p2) >= 0) + count++; + else if (t1 + 2 >= 0 && S-- > 0) + count++; + } + } + System.out.println(""Case #"" + i + "": "" + count); + } + } +} +" +A20436,"import java.io.BufferedReader; +import java.io.FileReader; + +public class DG { + + public static void main (String[] args) throws Exception + { + + BufferedReader sr = new BufferedReader(new FileReader(""c:\\Projects\\DG.txt"")); + + int total = Integer.parseInt(sr.readLine()); + + for (int i=0; i=p) + total++; + else + { + //it could be a surprising one + if ((base+2)>=p && + remaining >0) + { + total++; + remaining--; + } + } + } + else + if (add == 0) + { + if (base >= p) + total++; + else + { + //it could be surprising as well + if ((base+1) >= p && + remaining > 0 && + base > 0) + { + total++; + remaining--; + } + } + } + else + { + if ((base+add)>=p) + total++; + } + } + + System.out.printf (""Case #%d: %d\n"", c, total); + } +} +" +A20454,"import java.util.Scanner; +class Another{ + private int total, modulo; + public Another(int a){ + total = a; + modulo = a % 3; + } + public int surprisingScore(){ + if (total < 3){ + return total; + } else + if (modulo == 2){ + return (total/3) + 2; + } else { + return (total/3) + 1; + } + } + public int notSurprisingScore(){ + if (total < 2){ + return total; + } else if (total == 2){ + return 1; + } else + if (modulo == 0){ + return (total/3); + } else { + return (total/3) + 1; + } + } +} +class DanceResult{ + private int[] myArray; + private int arraySize, minimum, numberOfSurprises; + private int[][] result; + public DanceResult(int[] anArray, int min, int surprises){ + myArray = anArray; + minimum = min; + numberOfSurprises = surprises; + arraySize = myArray.length; + result = new int[arraySize][2]; + } + public void generateScores(){ + for (int i = 0; i < arraySize; i++){ + int value = myArray[i]; + Another checkScore = new Another(value); + int surprising = checkScore.surprisingScore(); + int notSurprising = checkScore.notSurprisingScore(); + result[i][0] = surprising; + result[i][1] = notSurprising; + } + return; + } + public int solve(){ + int countSurprise = 0; + int countNotSurprise = 0; + for (int i = 0; i < arraySize; i++){ + if (result[i][0] >= minimum){ + countSurprise++; + } + if (result[i][1] >= minimum){ + countNotSurprise++; + } + } + int difference = countSurprise - countNotSurprise; + if (difference >= numberOfSurprises){ + return countNotSurprise + numberOfSurprises; + } else + return countSurprise; + } +} +public class Dance { + + public static void main(String[] args) { + int numberOfGooglers, numberOfSurprising, leastScore, numberOfCases, currentCase; + int[] scores; + DanceResult myResult; + Scanner myScanner = new Scanner(System.in); + numberOfCases = myScanner.nextInt(); + currentCase = 1; + for (int j = 0; j < numberOfCases; j++){ + numberOfGooglers = myScanner.nextInt(); + numberOfSurprising = myScanner.nextInt(); + leastScore = myScanner.nextInt(); + scores = new int[numberOfGooglers]; + for(int i = 0; i < numberOfGooglers; i++){ + scores[i] = myScanner.nextInt(); + } + myResult = new DanceResult(scores, leastScore, numberOfSurprising); + myResult.generateScores(); + System.out.println(""Case #"" + currentCase + "": "" + myResult.solve()); + currentCase++; + } + + + } + +} +" +A22537,"import java.io.*; +import java.util.*; + +public class codejam2 { + + static class triplet { + + int a, b, c; + int maxdiff; + + public triplet(int pa, int pb, int pc) { + a = pa; + b = pb; + c = pc; + maxdiff = maxdiff(); + if (pa < 0 || pb < 0 || pc < 0) maxdiff = 3; + } + + public boolean isSurprising() { + return Math.abs(a-b) == 2 || Math.abs(a-c) == 2 || Math.abs(b-c) == 2; + } + + public int maxdiff() { + return Math.max(Math.abs(a-c), Math.max(Math.abs(a-b), Math.abs(b-c))); + } + } + + public static void main(String[] args) throws IOException { + BufferedReader f = new BufferedReader(new FileReader(""B-small-attempt0.in"")); + int T; + + T = Integer.parseInt(f.readLine()); + StringTokenizer t; + + for (int q = 0; q < T; q++) { + int N, S, p; + triplet[] ts; + boolean[] sat; + t = new StringTokenizer(f.readLine()); + N = Integer.parseInt(t.nextToken()); + S = Integer.parseInt(t.nextToken()); + p = Integer.parseInt(t.nextToken()); + ts = new triplet[N]; + sat = new boolean[N]; + int surpcount = 0; + for (int i = 0; i < N; i++) { + int n = Integer.parseInt(t.nextToken()); + int diff = n - (3 * (n/3)); + if (diff == 0 || diff == 1) { + ts[i] = new triplet(n/3, n/3, n/3 + diff); + } + if (diff == 2) { + ts[i] = new triplet(n/3, n/3+1, n/3+1); + } + } + + for (int i = 0; i < N; i++) { + if (ts[i].c >= p) { + sat[i] = true; + continue; + } + + triplet newtrip = new triplet(ts[i].a, ts[i].b-1, ts[i].c+1); + if (newtrip.maxdiff == 1 && (newtrip.c >= p)) { + sat[i] = true; + continue; + } + if (surpcount >= S) continue; + + if (newtrip.maxdiff == 2 && (newtrip.c >= p)) { + sat[i] = true; + surpcount++; + continue; + } + + triplet newnewtrip = new triplet(ts[i].a - 1, ts[i].b-1, ts[i].c+2); + if (newnewtrip.maxdiff == 2 && (newtrip.c >= p)) { + sat[i] = true; + continue; + } + + } + int tot = 0; + for (int i = 0; i < N; i++) { + if (sat[i]) { + tot++; + } + } + System.out.println(""Case #"" + (q+1) + "": "" + tot); + } + } + +} +" +A22148,"import java.util.*; +import static java.lang.Math.*; +import java.io.*; + +public class B { + +public static void main(String[] args) throws IOException { + /*BufferedReader in = new BufferedReader(new FileReader(""C:/Users/Disha/Desktop/codejam/B-small.in"")); + FileWriter fw = new FileWriter(""C:/Users/Disha/Desktop/codejam/B-small.out""); + */ +BufferedReader in = new BufferedReader(new FileReader(""C:/Users/Disha/Desktop/codejam/B-large.in"")); +FileWriter fw = new FileWriter(""C:/Users/Disha/Desktop/codejam/B-large.out""); + + int N = new Integer (in.readLine()); + for (int cases = 1; cases <= N; cases++) { + String[] ss = in.readLine().split("" ""); + int nGoog = Integer.parseInt(ss[0]); + int nSur = Integer.parseInt(ss[1]); + int atleast = Integer.parseInt(ss[2]); + int count = 0; + int j = 3; + for(int i=0; i= (3 * atleast - 2)) {count++ ;} + else { + if (nSur > 0) + {count ++; + nSur--; + } + } + } + fw.write (""Case #"" + cases + "": "" + count + ""\n"" ); + } + fw.flush(); + fw.close(); + }} +" +A22359,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + + +public class Dancing { + public static void main(String[] args){ + List input=new ArrayList(); + List output=new ArrayList(); + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""c:/input/B-small-attempt0.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + // Print the content on the console + input.add(strLine); + } + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + /*input done*/ + for(int j=1;j=p){ + count++; + //System.out.println(""normal""+t[i]); + }else if((div+Math.min(mod,1)>=p)){ + count++; + //System.out.println(""with increment""+t[i]); + }else if((div+Math.min(mod,2)>=p)&&(s>0)){ + count++; + if(mod>=2){ + s--; + //System.out.println(""surprised""+t[i]+""remaining s""+s); + } + }else if((div+1>=p)&&(div>0)&&(s>0)){ + count++; + s--; + //System.out.println(""superficial""+t[i]); + }else{ + //System.out.println(""noting happened""+t[i]+"" div is ""+div+""mod is""+mod); + } + } + output.add(count+""""); + /*counting done*/ + //System.out.println(count); + } + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""C:/output/Dancing.out""), true)); + for(int i=0;i0) { + res++; + S--; + } + } + out.println(""Case #""+(t+1)+"": ""+res); + } + out.close(); + System.exit(0); + } +} +" +A20157,"package qualification.dancing; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + +public class App { + + public static final String INPUT_FILE_NAME = ""C:\\Users\\Fred\\Desktop\\input.txt""; + + private int T; + + private int numberOfGooglers; + + private int numberOfSurprises; + + private int floor; + + public App() { + execute(); + } + + public void execute() { + ArrayList linhas = scanning(INPUT_FILE_NAME); + ArrayList allCases = new ArrayList(); + for (int i = 0; i < T; i++) { + int[] placar = extractParameters(linhas.get(i)); + allCases.add(new OneCase(getNumberOfGooglers(), getNumberOfSurprises(), getFloor(), placar)); + } + for (int i = 0; i < T; i++) { + OneCase oneCase = allCases.get(i); + int resp = oneCase.counting(oneCase.devolveMaxTodos(oneCase.getPlacar())); + int j = i + 1; + System.out.println(""Case #"" + j + "": "" + resp); + } + } + + public static void main(String[] args) { + new App(); + } + + public int[] extractParameters(String linha) { + String[] pedacos = linha.split("" ""); + setNumberOfGooglers(Integer.parseInt(pedacos[0])); + setNumberOfSurprises(Integer.parseInt(pedacos[1])); + setFloor(Integer.parseInt(pedacos[2])); + int[] placar = new int[getNumberOfGooglers()]; + for (int k = 0; k < getNumberOfGooglers(); k++) { + placar[k] = Integer.parseInt(pedacos[k + 3]); + } + return placar; + } + + public ArrayList scanning(String fileName) { + ArrayList linhas = new ArrayList(); + File dominioArq = new File(fileName); + try { + FileReader dominioFileReader = new FileReader(dominioArq); + BufferedReader reader = new BufferedReader(dominioFileReader); + String linha = """"; + int count = 0; + while ((linha = reader.readLine()) != null) { + if (count == 0 && fileName.equals(INPUT_FILE_NAME)) + setT(Integer.parseInt(linha)); + else + linhas.add(new String(linha)); + count++; + } + reader.close(); + dominioFileReader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return linhas; + } + + public void setT(int numberOfCases) { + this.T = numberOfCases; + } + + public int getNumberOfGooglers() { + return numberOfGooglers; + } + + public void setNumberOfGooglers(int numberOfGooglers) { + this.numberOfGooglers = numberOfGooglers; + } + + public int getNumberOfSurprises() { + return numberOfSurprises; + } + + public void setNumberOfSurprises(int numberOfSurprises) { + this.numberOfSurprises = numberOfSurprises; + } + + public int getFloor() { + return floor; + } + + public void setFloor(int floor) { + this.floor = floor; + } + + public int getT() { + return T; + } + + public class OneCase { + + + int numberOfGooglers; + + int numberOfSurprises; + + int floor; + + int[] placar; + + OneCase(int N, int S, int p, int[] t) { + this.numberOfGooglers = N; + this.numberOfSurprises = S; + this.floor = p; + this.placar = t; + //testeSanidade(); + } + + public void testeSanidade() { + if (placar.length != numberOfGooglers) + System.out.println(""ERRO: entrada de dados.""); + else + System.out.println(""entrada de dados esta ok.""); + } + + public int[] devolveMax(int placarIndividual) { + int[] max = new int[2]; + switch(placarIndividual % 3) { + case 0 : { + max[0] = (placarIndividual / 3); + max[1] = (placarIndividual / 3) + 1; + break; + } + case 1 : { + max[0] = (placarIndividual - 1) / 3 + 1; + max[1] = (placarIndividual - 4) / 3 + 2; + break; + } + case 2 : { + max[0] = (placarIndividual - 2) / 3 + 1; + max[1] = (placarIndividual - 2) / 3 + 2; + break; + } + default : + break; + } + return max; + } + + public HashMap devolveMaxTodos(int[] placar) { + HashMap mappingMax = new HashMap(); + for (int i = 0; i < placar.length; i++) { + int[] max; + switch(placar[i]) { + case 0 : { + max = new int[]{0,0}; + break; + } + case 1 : { + max = new int[]{1,1}; + break; + } + case 29 : { + max = new int[]{10,10}; + break; + } + case 30 : { + max = new int[]{10,10}; + break; + } + default : { + max = devolveMax(placar[i]); + break; + } + } + mappingMax.put(new Integer(i), max); + + } + return mappingMax; + } + + public void printMaxForEachGoogler(HashMap mapping) { + for (int i = 0; i < numberOfGooglers; i++) { + System.out.println(""googler #"" + i + "": {"" + mapping.get(i)[0] + "", "" + mapping.get(i)[1] + ""}""); + } + } + + public int counting(HashMap mapping) { + int count = 0; + int count1 = 0; + int count2 = 0; + for (int i = 0; i < numberOfGooglers; i++) { + int[] individualMaximos = mapping.get(new Integer(i)); + if (isPossibleGetBetter(individualMaximos, floor)) + count2++; + else{ + if (isSufficient(individualMaximos, floor)) + count1++; + } + } + count = count1 + Math.min(count2, numberOfSurprises); + return count; + } + + public boolean isPossibleGetBetter(int[] maximos, int parametro) { + boolean isPossible = false; + if ( (parametro == Math.max(maximos[0], maximos[1])) && (maximos[0] != maximos[1])) + isPossible = true; + return isPossible; + } + + public boolean isSufficient(int[] maximos, int parametro) { + boolean sufficient = false; + if (parametro <= Math.min(maximos[0], maximos[1])) + sufficient = true; + return sufficient; + } + + public int[] getPlacar() { + return placar; + } + } + + +} +" +A22402,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Scanner; +public class DancingWiththeGooglers { + + public static void main(String[] args) throws Exception { + PrintWriter out = new PrintWriter(""output.out""); + Scanner in = new Scanner(new File(""B-large.in"")); + int testCases = in.nextInt(); + for (int i = 1; i <= testCases; i++){ + int N = in.nextInt(),counter=0; + int S = in.nextInt(); + int P = in.nextInt(); + for(int j = 0 ; j < N ;j++){ + int googler= in.nextInt(); + if(googler%3 == 0 && googler!=0){ + if(googler/3 >= P){ + counter++; + } + else if(googler/3 + 1 >= P && S!=0){ + counter++; + S--; + } + } + else if (googler==0 && P==0){ + counter++; + } + else if(googler%3==1){ + if(googler/3 + 1 >= P){ + counter++; + } + } + else if(googler%3==2){ + if(googler/3 + 1 >= P){ + counter++; + } + else if(googler/3 + 2 >= P && S!=0){ + counter++; + S--; + } + } + } + out.printf(""Case #%d: %d"",i,counter); + out.printf(""\n""); + } + out.close(); + in.close(); + + } + +}" +A20453,"import java.util.*; +import java.io.*; + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + scan.nextLine(); + int c = 1; + while(scan.hasNextLine()) { + Scanner ls = new Scanner(scan.nextLine()); + ls.nextInt(); + int s = ls.nextInt(); + int p = ls.nextInt(); + ArrayList sc = new ArrayList(); + while(ls.hasNextInt()) { + sc.add(ls.nextInt()); + } + System.out.println(""Case #"" + c++ + "": "" + process(s, p, sc)); + } + + } + + public static int process(int surprises, int scoreToBeat, ArrayList scores) { + int ok = 0; + int s = 0; + for (int i = 0; i < scores.size(); i++) { + int score = scores.get(i); + int third = score / 3; + int rem = score % 3; + if(third >= scoreToBeat || (rem > 0 && (third + 1) >= scoreToBeat)) { + ok++; + } else { + if(s < surprises && rem != 1) { + if((rem == 2 && (third + 2) >= scoreToBeat) || (rem == 0 && (third > 0) && (third + 1) >= scoreToBeat)) { + s++; + ok++; + } + } + } + } + return ok; + } + +} +" +A22940,"package com.nbarraille.gcj; +import java.io.IOException; + + +public class GCJ extends GCJHelper { + protected static final String TEST_CASE = ""B-large""; // CHANGE THIS WHEN CHANGING PROBLEM + protected static final boolean RUN_ALL_CASES = true; + protected static final boolean DEBUG = true; + + // DO WHATEVER TO SOLVE THE CASE + // AND APPEND THE OUTPUT TO SB + protected static void solveCase() throws IOException { + long[] input = readLongArray(); + int nbDancers = (int)input[0]; + int nbSurprises = (int)input[1]; + int minScore = (int) input[2]; + long[] totals = new long[nbDancers]; + System.arraycopy(input, 3, totals, 0, nbDancers); + int nbOk = 0; + int nbOkWithS = 0; + for (long t : totals) { + if (minScore == 0) { + nbOk++; + } else if (minScore == 1) { + if (t >= 1) { + nbOk++; + } + } else if (t >= 3 * minScore - 2) { + nbOk++; + } else if (t >= 3 * minScore - 4) { + nbOkWithS++; + } + } + + sb.append(nbOk + Math.min(nbSurprises, nbOkWithS)); + + } + + + + + // DONT TOUCH THIS + public static void main(String[] args) throws Exception { + run(); + } +} +" +A22469,"import java.io.IOException; +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.StringTokenizer; +import java.util.Hashtable; +import java.util.Arrays; + +class Triplet { + public int first; + public int second; + public int third; + + public Triplet(int one, int two, int three) { + first = one; + second = two; + third = three; + } + + public boolean isSurprising() { + if ((Math.abs(third - second) == 2) || (Math.abs(second - first) == 2) + ||(Math.abs(third - first) == 2)) { + return true; + } else { + return false; + } + } + + public int getMax() { + return Math.max(first, Math.max(second, third)); + } + + public String print() { + return first + "" "" + second + "" "" + third; + } +} + +public class Dancers { + + private static Triplet getCombo1(int number) { + int remainder = number % 3; + if (remainder == 0) { + return new Triplet(number/3,number/3, number/3); + } else { + int first = (number + (3 - remainder)) / 3; + int second = first - 1; + int third = number - first - second; + return new Triplet(first, second, third); + } + } + + private static Triplet getCombo2(int number) { + int remainder = number % 3; + int first, second, third; + if (remainder == 0) { + first = (number / 3) + 1; + second = first - 1; + third = number - first - second; + + } else { + first = (number - remainder) / 3; + second = first - 1; + third = number - first - second; + } + if (second < 0) { + second++; + first--; + } + if (third < 0) { + first--; + third++; + } + if (first < 0) { + first++; third--; + } + if (third - second > 2) { + second++; third--; + } + if (first > 10) { + first--; second++; + } + if (second > 10) { + second --; third++; + } + if (third > 10) { + third--;second++; + } + return new Triplet(first, second, third); + } + + public static void main(String[] args) throws IOException{ + Triplet[] combo1 = new Triplet[31]; + Triplet[] combo2 = new Triplet[31]; + + for (int i=0;i<=30;i++) { + //System.out.print(""i: "" + i); + combo1[i] = getCombo1(i); + //System.out.println("" "" + combo1[i] .print()); + //System.out.print(""i: "" + i); + combo2[i] = getCombo2(i); + //System.out.println("" "" + combo2[i] .print()); + } + if (args.length != 1) { + System.out.println(""Error: incorrect number of arguments.""); + System.out.println(""Usage: Dancers ""); + } else { + BufferedReader inputStream = null; + try { + inputStream = new BufferedReader(new FileReader(args[0])); + int totalCases = Integer.valueOf(inputStream.readLine()).intValue(); + //System.out.println(""Total number of cases is: ""+totalCases); + for (int i=0;i=bestReqd && !googCombo1.isSurprising()) { + output++; + } else if (googCombo2.getMax()>=bestReqd && !googCombo2.isSurprising()) { + output++; + break; + } else if (googCombo2.getMax()>=bestReqd && googCombo2.isSurprising() && numSurprises>0) { + output++; + numSurprises--; + } + } + //System.out.println(""*** Answer is "" + output + ""****""); + System.out.println(output); + //System.out.println(""**********************************""); + } + } catch (IOException e) { + System.out.println(""Error in reading file""); + } finally { + if (inputStream != null) { + inputStream.close(); + } + } + + } + } +}" +A21709,"package dancinggooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +public class DancingGooglers { + + public static void main(String[] args) { + + String input; + String output = """"; + int i = 0, googler, div, under, valid, remains; + int cases, surp, point; + + try { + FileReader fr = new FileReader(new File(""B-large.in"")); + BufferedReader br = new BufferedReader(fr); + + FileWriter fstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + + cases = Integer.parseInt(br.readLine()); + i = 0; + + while(i < cases) { + input = br.readLine(); + output += ""Case #""+(++i)+"": ""; + String[] split = input.split("" ""); + + surp = Integer.parseInt(split[1]); + point = Integer.parseInt(split[2]); + under = 0; + valid =0; + + for (int j=0; j -3)&&(remains >= 0)){ valid++; } + + else if((div > -5)&&(remains >= 0)){ under++; } + } + + if(under <= surp) { valid += under; } + else { valid += surp; } + + output += valid; + + out.write(output); + output = ""\n""; + } + + out.close(); + br.close(); + + }catch (Exception e) { System.err.println(""Error: "" + e.getMessage()); } + + } +} +" +A23006,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + + + public static void main(String[] args) throws IOException { + setStandardIO(); + setFileIO(""dancingwiththegooglers""); + + readLine(); + int T = nextInt(); + for (int t = 1; t <= T; ++t) { + readLine(); + int N = nextInt(); + int S = nextInt(); + int p = nextInt(); + int tab[] = new int[N]; + int ta[] = new int[N]; + int tb[] = new int[N]; + for (int i = 0; i < N; ++i) { + tab[i] = nextInt(); + switch (tab[i] % 3) { + case 0: + ta[i] = tab[i] / 3; + tb[i] = (ta[i] == 0 ? ta[i] : ta[i] + 1); + break; + case 1: + ta[i] = tab[i] / 3 + 1; + tb[i] = ta[i]; + break; + case 2: + ta[i] = tab[i] / 3 + 1; + tb[i] = ta[i] + 1; + break; + } + } + + int count = 0; + for (int i = 0; i < N; ++i) + if (ta[i] >= p) count++; + + for (int i = 0; i < N && S > 0; ++i) + if (ta[i] < p && tb[i] >= p) { + count++; + S--; + } + + println(""Case #"" + t + "": "" + count); + } + + flush(); + } + + //~ ---------------------------------------------------------------------------------------------------------------- + //~ - Auxiliary code ----------------------------------------------------------------------------------------------- + //~ ---------------------------------------------------------------------------------------------------------------- + static BufferedReader in; + static PrintWriter out; + static StringTokenizer st; + + private static void setStandardIO() { + in = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); + } + + private static void setFileIO(String fileName) throws FileNotFoundException, IOException { + in = new BufferedReader(new FileReader(fileName + "".in"")); + out = new PrintWriter(new BufferedWriter(new FileWriter(fileName + "".out""))); + } + + public static void readLine() throws IOException { + st = new StringTokenizer(in.readLine()); + } + + public static int nextInt() { + return Integer.parseInt(st.nextToken()); + } + + public static long nextLong() { + return Long.parseLong(st.nextToken()); + } + + public static String nextString() { + return st.nextToken(); + } + + public static List nextStrings() { + List strings = new ArrayList(); + while (st.hasMoreTokens()) + strings.add(st.nextToken()); + + return strings; + } + + public static void flush() { + out.flush(); + } + + public static void println(Object object) { + out.println(object); + } + + public static void print(Object object) { + out.print(object); + } + + public static long gcd(long a, long b) { + if (b == 0) return a; + return gcd(b, a % b); + } + + public static class Pair { + public long x, y; + public Pair(long x, long y) { + this.x = x; + this.y = y; + } + @Override + public String toString() { + return ""Pair [x="" + x + "", y="" + y + ""]""; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (x ^ (x >>> 32)); + result = prime * result + (int) (y ^ (y >>> 32)); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Pair other = (Pair) obj; + if (x != other.x) + return false; + if (y != other.y) + return false; + return true; + } + } +} +" +A21623,"package y2012.Qualification; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class DancingWithGooglers extends IOStream { + + List completeEntries = new ArrayList(); + List aboveList = new ArrayList(); + List belowList = new ArrayList(); + List considerableList = new ArrayList(); + static int P_bestResult = 0; + int N = 0; + int surprisingTriplets = 0; + + public DancingWithGooglers(String fileName) { + super(fileName); + } + + private int runThisTestCase() throws IOException { + + completeEntries = new ArrayList(); + aboveList = new ArrayList(); + belowList = new ArrayList(); + considerableList = new ArrayList(); + + int[] intValues = splitString2Int(bufferedReader.readLine().trim().split("" "")); + N = intValues[0]; + surprisingTriplets = intValues[1]; + P_bestResult = intValues[2]; + createTriplets(intValues); + int max = (surprisingTriplets > considerableList.size()) ? considerableList.size() : surprisingTriplets; + System.out.println(aboveList.size() + max ); + + return aboveList.size() + max; + } + + + + private void createTriplets(int[] intValues) { + + for(int i=3; i atMax) + belowList.add(triplet); + else + considerableList.add(triplet); + } + + public static void main(String[] args) { + + DancingWithGooglers obj = new DancingWithGooglers(""/net/10.0.0.60/Users/454083/Desktop/Moshin/CodeJam/DancingGooglers""); + try { + obj.getReader(); + obj.getWriter(); + int testcases = Integer.parseInt(bufferedReader.readLine().trim()); + for(int testcase=1; testcase<=testcases; testcase++){ + int value = obj.runThisTestCase(); + System.out.println(""Case #"" + testcase + "": "" + value); + bufferedWriter.write(""Case #"" + testcase + "": "" + value + ""\n""); + } + obj.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + + +} + +class Triplet { + int sum = 0; + int reminder = 0; + boolean suprise = false; + int maxScore = 0; + + public Triplet(int sum) { + this.sum = sum; + if ((reminder = sum % 3) == 1) + maxScore = (int) (sum / 3) + 1; + } + + public boolean isSuprise() { + return suprise; + } + + public void setSuprise(boolean suprise) { + this.suprise = suprise; + } + + public int getMaxScore() { + return maxScore; + } + + public void setMaxScore(int maxScore) { + this.maxScore = maxScore; + } + + public int getSum() { + return sum; + } + + public int getReminder() { + return reminder; + } + +} + +class IOStream { + + static public BufferedReader bufferedReader = null; + static public BufferedWriter bufferedWriter = null; + + String fileName = """"; + + public IOStream(String fileName) { + this.fileName = fileName; + } + + protected void getReader() throws IOException { + bufferedReader = new BufferedReader(new FileReader(new File(fileName + "".in""))); + } + + protected void getWriter() throws IOException { + bufferedWriter = new BufferedWriter(new FileWriter(new File(fileName + "".out""))); + } + + protected void close() throws IOException { + if (bufferedReader != null) + bufferedReader.close(); + if (bufferedWriter != null) { + bufferedWriter.flush(); + bufferedWriter.close(); + } + } + + protected int[] splitString2Int(String[] words){ + int[] ints = new int[words.length]; + int i=0; + for(String str: words){ + ints[i] = Integer.parseInt(str); + i++; + } + + return ints; + } +} +" +A22783,"package google.contest.C; + +import google.loader.Challenge; +import google.problems.AbstractReader; + +public class CReader extends AbstractReader { + + @Override + protected Challenge createChallenge(int number) { + int theLine = getActualLine(); + String[] lines = getLines(); + CChallenge chal = new CChallenge(number, lines[theLine]); + setActualLine(theLine+1); + return chal; + } + +} +" +A22694,"package google.codejam; + +public interface GoogleSolver { + String solve(String str); +} +" +A21659,"/** + * @(#)Main.java + * + * + * @author + * @version 1.00 2012/4/14 + */ + import java.io.*; + +public class Main { + + public static void main(String[] args)throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + FileWriter fstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + String in = br.readLine(); + int testCases = Integer.parseInt(in); + int i = 1; + + while(testCases > 0) { + in = br.readLine(); + out.write(""Case #"" + i + "": "" + solve(in.split("" "")) + ""\n""); + testCases--; + i++; + } + out.close(); + } + + public static int solve(String[] in) { + int n = Integer.parseInt(in[0]); + int s = Integer.parseInt(in[1]); + int p = Integer.parseInt(in[2]); + int solution = 0; + + for(int i = 3; i < in.length; i++) { + int t = Integer.parseInt(in[i]); + switch(p) { + case 0:solution++;break; + case 1:if(t >= 1) solution++;break; + case 2:if(s > 0 && (t >= 2 && t <= 3)){solution++; s--;}else if(t > 3)solution++;break; + case 3:if(s > 0 && (t >= 5 && t <= 6)){solution++; s--;}else if(t > 6)solution++;break; + case 4:if(s > 0 && (t >= 8 && t <= 9)){solution++; s--;}else if(t > 9)solution++;break; + case 5:if(s > 0 && (t >= 11 && t <= 12)){solution++; s--;}else if(t > 12)solution++;break; + case 6:if(s > 0 && (t >= 14 && t <= 15)){solution++; s--;}else if(t > 15)solution++;break; + case 7:if(s > 0 && (t >= 17 && t <= 18)){solution++; s--;}else if(t > 18)solution++;break; + case 8:if(s > 0 && (t >= 20 && t <= 21)){solution++; s--;}else if(t > 21)solution++;break; + case 9:if(s > 0 && (t >= 23 && t <= 24)){solution++; s--;}else if(t > 24)solution++;break; + case 10:if(s > 0 && (t >= 26 && t <= 27)){solution++; s--;}else if(t > 27)solution++;break; + } + } + return solution; + } +} +" +A20711,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package DancingWithTheGooglers; + +import java.io.File; +import java.io.FileWriter; +import java.io.Writer; +import java.util.Scanner; + +/** + * + * @author Rishabh + */ +public class DancingWithTheGooglers { + + public void readFile(String path) throws Exception{ + File f = new File(path); + Scanner scanner = new Scanner(f); + String name = f.getName().substring(0,f.getName().indexOf('.')); + Writer writer = new FileWriter(name+"".out""); + int n = Integer.parseInt(scanner.nextLine()); + int caseno=0; + while(scanner.hasNextLine()){ + caseno++; + long[] num_arr = toIntArray(scanner.nextLine().split("" "")); + int N = (int)num_arr[0]; + int S = (int)num_arr[1]; + int p = (int)num_arr[2]; + int[] arr = new int[N]; + for(int i=0;i=Math.max(0,3*p-2)) + vals[i][0] = true; + if(arr[i]<=28&&arr[i]>=Math.max(2, 3*p-4)) + vals[i][1] = true; + } + int single_count=0; + for(int i=0;i= -2) + max++; + else if(surprises > 0 && googlers[i] > 1 && googlers[i] - (3 * bound) >= -4) { + max++; + surprises--; + } //end else if + } //end for + return max; + } //end writeSolution + + public static void writeSolutionsToFile(int[] solutionsArray) { + System.out.println(""Writing solutions to file""); + + try { + PrintWriter pw = new PrintWriter(FILE_OUT); + for(int i = 0; i < solutionsArray.length; i++) + if(i < solutionsArray.length - 1) + pw.println(""Case #"" + (i + 1) + "": "" + solutionsArray[i]); + else + pw.print(""Case #"" + (i + 1) + "": "" + solutionsArray[i]); + pw.close(); + } //end try + catch(IOException e) { + System.out.println(""Error writing to file - "" + e); + } //end catch + } //end writeSolutionsToFile +} //end DancingWithTheGooglers" +A20580,"package base; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import assignments.AssignmentB; + + +public class Solver { + public static void main(String... args) throws IOException { + List assignments = readAssignments(""test""); + PrintWriter pw = new PrintWriter(new FileWriter(""output.txt"")); + int i = 0; + for (Assignment assignment : assignments) { + String answer = ""Case #"" + ++i + "": "" + assignment.solve(); + pw.println(answer); + System.out.println(answer); + } + pw.flush(); + pw.close(); + + } + + private static List readAssignments(String filename) throws FileNotFoundException { + Scanner scanner = new Scanner(new File(filename)); + int amountOfAssignments = scanner.nextInt(); + scanner.nextLine(); + List result = new ArrayList(); + for (int i = 0; i < amountOfAssignments; i++) { + result.add(AssignmentB.createFromScanner(scanner)); + } + scanner.close(); + return result; + } +} +" +A22041,"package gcj.qualifier; +/** + * @(#)ProbB.java + * + * + * @author + * @version 1.00 2011/5/9 + */ + +import java.io.*; +import java.math.*; +import java.lang.*; +import java.util.*; + +import static java.lang.System.*; +import static java.lang.Integer.*; +public class ProbB +{ + + public FileReader fr; + public BufferedReader br; + + + public ProbB(String file, String output) + { + if (output!=null) + setOut(output); + + try + { + fr=new FileReader(file); + br=new BufferedReader(fr); + + int caseNo=parseInt(br.readLine()); + //out.println(caseNo); + for (int i=0; i2) + test=(p-2)*3; + // out.println(); + // out.println(test); + int num=0; + //double test=((double)p-((double)2/3)); + + int div; int mod; + for (int i=0; i=p) + { + if (div>=p-2) + { + if (div>=p || (div==(p-1)&&(mod==2||mod==1))) + { + num++; + } + else if (s>0) + { + if ((div==(p-2)&&mod==2)||(div==(p-1)&&mod==0)) + { + s--; +// out.print(""*""); + num++; + + } + + + } + else continue; + +/* + out.print(tt[i]); + out.print("" : ""); + out.print(tt[i]/3); + out.print("" : ""); + out.print(tt[i]%3); + out.print("" : ""); + out.println(); + */ + } + } + +// out.println(p+"":::""+tt[i]+"":""+tt[i]/3+"":""+tt[i]%p); + + + //out.println(tt[i]); + } + + + //out.println(num); + + return new Integer(num).toString(); + } + + public static void main(String [] args) + { + ProbB gjct=new ProbB(""C:/JavaPgms/workspace/codejam/2012/in/qualifier/B-large.in"", ""C:/JavaPgms/workspace/codejam/2012/out/qualifier/B.out""); + } + + + + +}" +A20533,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author ZAMAN + */ +import java.io.*; + +public class test { + + public static void main(String args[]) { + try { + BufferedReader a = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter b = new BufferedWriter(new FileWriter(""B-large.out"")); + + int Case = Integer.parseInt(a.readLine()); + for (int i = 1; i <= Case; i++) { + String line[] = a.readLine().split("" ""); + int c[] = new int[line.length]; + b.append(""Case #"" + i + "": ""); + for (int j = 0; j <= line.length - 1; j++) { + c[j] = Integer.parseInt(line[j]); + + } + int contestants = c[0]; + int suprise = c[1]; + int margin = c[2]; + int best = 0; + if (suprise == 0) { + for (int j = 0; j < contestants; j++) { + if (c[j + 3] % 3 == 0) { + if (c[j + 3] / 3 >= margin) { + best++; + } + } else if (c[j + 3] % 3 == 1 || c[j + 3] % 3 == 2) { + if (((c[j + 3] / 3) + 1) >= margin) { + best++; + } + } + } + } else { + for (int j = 0, k = suprise; j < contestants; j++) { + int remain = c[j + 3] % 3; + int dv = c[j + 3] / 3; + if (remain == 0) { + if (dv >= margin) { + best++; + } else if (k > 0 && (dv + 1) >= margin && (dv + 1) <= c[j + 3]) { + best++; + k--; + } + } else if (remain == 1) { + if (((dv) + 1) >= margin && (dv + 1) <= c[j + 3]) { + best++; + } + + } else if (remain == 2) { + + if (((dv) + 1) >= margin && (dv + 1) <= c[j + 3]) { + best++; + } else if (k > 0 && (dv + 2) >= margin && (dv + 1) <= c[j + 3]) { + best++; + k--; + } + } + } + + } + b.append("""" + best); + b.newLine(); + } + b.flush(); + a.close(); + b.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +}" +A20675,"import java.io.*; + +public class Test { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in, ""UTF-8"")); + int num = Integer.parseInt(br.readLine()); + int nline = 1; + String line; + while ((line = br.readLine()) != null && nline <=num) { + String[] tok = line.split("" ""); + int N = Integer.parseInt(tok[0]); + int S = Integer.parseInt(tok[1]); + int p = Integer.parseInt(tok[2]); + int max = N; + if (p == 1) { + for (int i = 3; i < N+3; i++) { + if ((Integer.parseInt(tok[i]) == 0)) { + --max; + } + } + } + if (p >= 2) { + for (int i = 3; i < N+3; i++) { + if (Integer.parseInt(tok[i]) <= 3*p-5) { + --max; + } + if ((Integer.parseInt(tok[i]) == 3*p-3) || (Integer.parseInt(tok[i]) == 3*p-4)) { + if (S > 0) --S; + else --max; + } + } + } + System.out.println(""Case #"" + nline + "": "" + max); + nline++; + } + + } + +} + + +" +A21829,"import java.util.*; +import java.io.*; + +public class B { + public static void main (String [] args) { + try { + BufferedReader br = new BufferedReader(new FileReader(""B-large-0.in"")); + PrintWriter pw = new PrintWriter(""B-large-0.out""); + int inputNo; + inputNo = Integer.parseInt(br.readLine()); + + for (int i = 1; i <= inputNo; i++) { + // get one input here + String in = br.readLine(); + pw.println(""Case #"" + i + "": "" + processInput(in)); + } + + br.close(); + pw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static int processInput(String in) { + int result = 0; + + Scanner sc = new Scanner(in); + int gNo = Integer.parseInt(sc.next()); + int sup = Integer.parseInt(sc.next()); + int max = Integer.parseInt(sc.next()); + int supNo = 0; + int goodNo = 0; + + for (int i = 0; i < gNo; i++) { + int total = Integer.parseInt(sc.next()); + int can = canMax(max, total); + if (can == 1) supNo++; + if (can == 0) goodNo++; + } + + if (supNo > sup) result = goodNo + sup; + else result = goodNo + supNo; + + return result; + } + + public static int canMax(int max, int total) { + int av = total/3; + int r = total%3; + if (r == 0) { + if (av >= max) return 0; + if (av+1 >= max && av+1 <= 10 && av-1 >= 0) return 1; + return -1; + } + if (r == 1) { + if (av+1 >= max && av + 1 <= 10) return 0; + return -1; + } + if (r == 2) { + if (av+1 >= max && av+1 <= 10) return 0; + if (av+2 >=max && av+2 <= 10) return 1; + return -1; + } + + return -1; + } +} +" +A20997,"package fixjava; + +import java.util.Collection; +import java.util.Comparator; + +/** + * Typed 3-tuple + */ +public class Tuple4 { + + private final A field0; + private final B field1; + private final C field2; + private final D field3; + + public A getField0() { + return field0; + } + + public B getField1() { + return field1; + } + + public C getField2() { + return field2; + } + + public D getField3() { + return field3; + } + + public Tuple4(final A field0, final B field1, final C field2, final D field3) { + this.field0 = field0; + this.field1 = field1; + this.field2 = field2; + this.field3 = field3; + } + + /** Convenience method so type params of pair don't have to be specified: just do Tuple4.make(a, b, c, d) */ + public static Tuple4 make(A field0, B field1, C field2, D field3) { + return new Tuple4(field0, field1, field2, field3); + } + + // --------------------------------------------------------------------------------------------------- + + private static final boolean objEquals(Object p1, Object p2) { + if (p1 == null) + return p2 == null; + return p1.equals(p2); + } + + @Override + public final boolean equals(Object o) { + if (!(o instanceof Tuple4)) { + return false; + } else { + final Tuple4 other = (Tuple4) o; + return objEquals(getField0(), other.getField0()) && objEquals(getField1(), other.getField1()) + && objEquals(getField2(), other.getField2()) && objEquals(getField3(), other.getField3()); + } + } + + @Override + public int hashCode() { + int h0 = getField0() == null ? 0 : getField0().hashCode(); + int h1 = getField1() == null ? 0 : getField1().hashCode(); + int h2 = getField2() == null ? 0 : getField2().hashCode(); + int h3 = getField3() == null ? 0 : getField3().hashCode(); + return h0 + 53 * h1 + 97 * h2 + 131 * h3; + } + + // --------------------------------------------------------------------------------------------------- + + public static , B, C, D> Comparator> comparatorOnField0(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple4 o1, Tuple4 o2) { + return o1.getField0().compareTo(o2.getField0()); + } + }; + } + + public static , C, D> Comparator> comparatorOnField1(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple4 o1, Tuple4 o2) { + return o1.getField1().compareTo(o2.getField1()); + } + }; + } + + public static , D> Comparator> comparatorOnField2(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple4 o1, Tuple4 o2) { + return o1.getField2().compareTo(o2.getField2()); + } + }; + } + + public static > Comparator> comparatorOnField3(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple4 o1, Tuple4 o2) { + return o1.getField3().compareTo(o2.getField3()); + } + }; + } + + // --------------------------------------------------------------------------------------------------- + + @Override + public String toString() { + return ""("" + getField0() + "", "" + getField1() + "", "" + getField2() + "", "" + getField3() + "")""; + } +} +" +A21299,"import java.util.*; + + +public class GCJ2012QualB{ + public static void main(String args[]){ + + Scanner s = new Scanner(System.in); + int t = s.nextInt(); + + for(int mon=1;mon<=t; mon++){ + + int nplayer=s.nextInt(); + int nsuprise=s.nextInt(); + int nscore=s.nextInt(); + int ans=0; + int scores[]; + scores = new int [nplayer]; + for (int i=0; i=limnormalall){ + ans+=1; + } + else if(checkscore>=limsupall){ + if (nsuprise>0){ + ans+=1; + nsuprise-=1; + } + } + } + + + System.out.println(""Case #""+ mon+"": ""+ans); + + } + + } +} +" +A21058,"package org.nos.gcj; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Calendar; +import java.util.StringTokenizer; + +public class GCJ_Q_02 { + +// static final String path = ""F:/GCJ/GCJ_Qalification_02/Small_1""; + static final String path = ""F:/GCJ/GCJ_Qalification_02/Large""; + + class TestCase + { + int N; + int S; + int p; + int[] t; + } + + public TestCase readTestCase(BufferedReader br) throws Exception + { + TestCase tc = new TestCase(); + + String line = br.readLine(); + StringTokenizer st = new StringTokenizer(line); + tc.N = Integer.valueOf(st.nextToken()); + tc.S = Integer.valueOf(st.nextToken()); + tc.p = Integer.valueOf(st.nextToken()); + tc.t = new int[tc.N]; + + for (int i=0; i= (3*tc.p-2) ) + total++; + else if ((tc.t[i] >= (3*tc.p - 4)) && (tc.S > 0)) + { + tc.S--; + total++; + } + } + + bw.write(""""+total); + } + + public void solve() throws Exception + { + BufferedReader br = new BufferedReader(new FileReader(path+""/input.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(path+""/output.out"")); + int testCases = new Integer(br.readLine()); + for (int i=0; i= 3*p -2) + withoutSurprise++; + else if(totalScore >= 3*p-4 && totalScore >= p) + withSurprise++; + } + int totalScore = Integer.parseInt(temp); + if(totalScore >= 3*p -2) + withoutSurprise++; + else if(totalScore >= 3*p-4 &&totalScore >= p) + withSurprise++; + int numWinners; + if(withSurprise >= numSurprising) + numWinners = numSurprising + withoutSurprise; + else + numWinners = withSurprise + withoutSurprise; + writer.print(""Case #"" + (i+1) + "": "" + numWinners + ""\n""); + + + } + writer.close(); + } + catch(Exception e) + { + throw(e); + } + } + +} +" +A20611,"import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class DancingGooglers { + + private static String infile = ""B-large.in""; + private static String outfile = ""out.txt""; + private static String encoding = ""UTF-8""; + + public static void main(String[] args) { + try { + runTests(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + + } + + public static void runTests() throws IOException { + Scanner scanner = new Scanner(new FileInputStream(infile), encoding); + BufferedWriter writer = new BufferedWriter(new FileWriter(outfile)); + int nCases = Integer.parseInt(scanner.nextLine()); + + for (int i = 0; i < nCases; i++) { + int val = testCase(scanner.nextLine()); + writer.write(""Case #"" + (i + 1) + "": "" + val + ""\n""); + } + + writer.close(); + } + + public static int testCase(String input) { + String delimiter = "" ""; + String[] inputs = input.split(delimiter); + int nSurprising = Integer.parseInt(inputs[1]); + int maxScore = Integer.parseInt(inputs[2]) * 3; + int nQualifying = 0; + + for (int i = 3; i < inputs.length; i++) { + int score = Integer.parseInt(inputs[i]); + + if (score >= 2 && maxScore >= 6) { + if (score >= maxScore - 2) { + nQualifying++; + } else if (score >= maxScore - 4 && nSurprising > 0) { + nQualifying++; + nSurprising--; + } + } else if ((maxScore == 0) || (maxScore == 3 && score > 0)) { + nQualifying++; + } + } + + return nQualifying; + } + +} +" +A22993,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package IO; + +/* + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Oracle or the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS + * IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import exercises.Exercise2; +import java.io.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.SwingUtilities; +import javax.swing.filechooser.*; + +/* + * FileChooserDemo.java uses these files: + * images/Open16.gif + * images/Save16.gif + */ +public class FileManagerGUI extends JPanel + implements ActionListener { + static private final String newline = ""\n""; + JButton openButton; + static JTextArea log; + JFileChooser fc; + + public FileManagerGUI() { + super(new BorderLayout()); + + //Create the log first, because the action listeners + //need to refer to it. + log = new JTextArea(5,20); + log.setMargin(new Insets(5,5,5,5)); + log.setEditable(false); + JScrollPane logScrollPane = new JScrollPane(log); + + //Create a file chooser + fc = new JFileChooser(); + + //Uncomment one of the following lines to try a different + //file selection mode. The first allows just directories + //to be selected (and, at least in the Java look and feel, + //shown). The second allows both files and directories + //to be selected. If you leave these lines commented out, + //then the default mode (FILES_ONLY) will be used. + // + //fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + //fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + + //Create the open button. We use the image from the JLF + //Graphics Repository (but we extracted it from the jar). + openButton = new JButton(""Open a File...""); + openButton.addActionListener(this); + + + //For layout purposes, put the buttons in a separate panel + JPanel buttonPanel = new JPanel(); //use FlowLayout + buttonPanel.add(openButton); + + //Add the buttons and the log to this panel. + add(buttonPanel, BorderLayout.PAGE_START); + add(logScrollPane, BorderLayout.CENTER); + } + + public void actionPerformed(ActionEvent e) { + + //Handle open button action. + if (e.getSource() == openButton) { + int returnVal = fc.showOpenDialog(FileManagerGUI.this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + //This is where a real application would open the file. + log.append(""Opening: "" + file.getName() + ""."" + newline); + Input input=InputReader.readFile(file.getName()); + Exercise2.run(input); + } else { + log.append(""Open command cancelled by user."" + newline); + } + log.setCaretPosition(log.getDocument().getLength()); + + //Handle save button action. + } + } + + + /** + * Create the GUI and show it. For thread safety, + * this method should be invoked from the + * event dispatch thread. + */ + private static void createAndShowGUI() { + //Create and set up the window. + JFrame frame = new JFrame(""FileChooser""); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + + //Add content to the window. + frame.add(new FileManagerGUI()); + + //Display the window. + frame.pack(); + frame.setVisible(true); + frame.setSize(500, 300); + } + + public static void main(String[] args) { + //Schedule a job for the event dispatch thread: + //creating and showing this application's GUI. + SwingUtilities.invokeLater(new Runnable() { + public void run() { + //Turn off metal's use of bold fonts + UIManager.put(""swing.boldMetal"", Boolean.FALSE); + createAndShowGUI(); + } + }); + } +} +" +A21488,"import java.io.*; +import java.util.*; + +public class DancingWithGooglers { + public static void main(String... args) throws Exception { + + BufferedReader br = new BufferedReader(new FileReader( + System.getProperty(""user.home"") + ""/Desktop/googlers.in"")); + + BufferedWriter bw = new BufferedWriter(new FileWriter( + System.getProperty(""user.home"") + ""/Desktop/googlers.out"")); + + Map dictionary = new HashMap(); + + for (int x = 0; x <= 10; x++) { + dictionary.put(x + x + x, new TripleCounter(x, x, x, false)); + if (x >= 10) + continue; + dictionary + .put(x + x + x + 1, new TripleCounter(x, x, x + 1, false)); + dictionary.put(x + x + 1 + x + 1, new TripleCounter(x, x + 1, + x + 1, false)); + } + + Map specialdictionary = new HashMap(); + + for (int x = 0; x <= 8; x++) { + specialdictionary.put(x + x + x + 2, new TripleCounter(x, x, x + 2, + true)); + specialdictionary.put(x + x + 2 + x + 2, new TripleCounter(x, + x + 2, x + 2, true)); + specialdictionary.put(x + x + 1 + x + 2, new TripleCounter(x, + x + 1, x + 2, true)); + } + + int times = Integer.parseInt(br.readLine()); + + for (int i = 0; i < times; i++) { + googlers(br.readLine(), dictionary, specialdictionary, bw, i + 1); + } + + bw.flush(); + bw.close(); + } + + public static void googlers(String line, + Map dictionary, + Map specialdictionary, BufferedWriter bw, + int num) throws IOException { + String[] split = line.split("" ""); + + int special = Integer.parseInt(split[1]); + int p = Integer.parseInt(split[2]); + List scores = new ArrayList(); + int count = 0; + + for (int i = 3; i < split.length; i++) { + scores.add(Integer.parseInt(split[i])); + } + + for (int i : scores) { + TripleCounter c = dictionary.get(i); + if (c != null && c.hasGreaterOrEqualTo(p)) { + count++; + continue; + } + + c = specialdictionary.get(i); + if (special > 0) { + if (c != null && c.hasGreaterOrEqualTo(p)) { + count++; + special--; + } + } + } + + bw.write(""Case #"" + num + "": "" + count); + if (num < 100) + bw.write(""\n""); + } + +} + +class TripleCounter { + + public int x, y, z; + public boolean special; + + public TripleCounter(int x, int y, int z, boolean special) { + this.x = x; + this.y = y; + this.z = z; + this.special = special; + } + + public boolean hasGreaterOrEqualTo(int num) { + return (x >= num || y >= num || z >= num); + } + + @Override + public String toString() { + return ""("" + x + "", "" + y + "", "" + z + "", "" + special + "")""; + } + +} +" +A22125,"package gcj2012.qual; + +import java.util.Scanner; + +public class B_DancingWithGooglers +{ + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + + int t = sc.nextInt(); + + for(int cases=1; cases<=t; cases++) + { + int players = sc.nextInt(); + int surprising = sc.nextInt(); + int limit = sc.nextInt(); + + int count = 0; + + for(int i=0; i 0 && limit - score <= 2) + { + count ++; + surprising --; + } + } + + System.out.println(""Case #""+cases+"": ""+count); + } + } +} +" +A22153,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + +import static java.lang.Math.*; + + +public class Solution implements Runnable { + + public static void main(String[] args) { + new Thread(new Solution()).start(); + } + + @Override + public void run() { + try { + solve(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(""Laja in solution""); + } + } + + private String next() throws IOException { + while (tok == null || !tok.hasMoreTokens()) { + tok = new StringTokenizer(cin.readLine()); + } + + return tok.nextToken(); + } + + private int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + private long nextLong() throws IOException { + return Long.parseLong(next()); + } + + BufferedReader cin; + StringTokenizer tok; + PrintWriter cout; + + public void solve() throws Exception { + //cin = new BufferedReader(new FileReader(""input.txt"")); + cin = new BufferedReader(new FileReader(""B-large.in "")); + cout = new PrintWriter(""output.txt""); + //cout = new PrintWriter(""""); + + int testcases = nextInt(); + for (int testcase = 0; testcase < testcases; ++testcase) { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + + int[] a = new int[n]; + for (int i = 0; i < n; ++i) { + a[i] = nextInt(); + } + + int[][] d = new int[n + 1][s + 1]; + for (int i = 0; i < n + 1; ++i) { + Arrays.fill(d[i], -10000); + } + + d[0][s] = 0; + + for (int i = 0; i < n; ++i) { + for (int j = 0; j <= s; ++j) { + int mod = a[i] % 3; + int del = a[i] / 3; + + // non surprising + if (mod == 0) { + d[i + 1][j] = max(d[i + 1][j], d[i][j] + toInt(del >= p)); + } else { + d[i + 1][j] = max(d[i + 1][j], d[i][j] + toInt(del + 1 >= p)); + } + + // surprising + if (j > 0 && 2 <= a[i] && a[i] <= 28) { + if (mod == 2) { + d[i + 1][j - 1] = max(d[i + 1][j - 1], d[i][j] + toInt(del + 2 >= p)); + } else { + d[i + 1][j - 1] = max(d[i + 1][j - 1], d[i][j] + toInt(del + 1 >= p)); + } + } + } + } + + cout.println(""Case #"" + (testcase + 1) + "": "" + d[n][0]); + } + + cout.close(); + } + + private int toInt(boolean b) { + return b ? 1 : 0; + } +} +" +A21921,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +/** + * + * @author Vale + */ +public class DancingWithGooglers { + + + public static void main(String[] args){ + String inputFile=""/Users/Vale/Desktop/CodeJam/B-large.in""; + String outputFile=""/Users/Vale/Desktop/CodeJam/B-large-output.txt""; + + String[] lines=readAllLinesOfFile(inputFile); + int numberOfCases=Integer.parseInt(lines[0]); + String[] result=new String[numberOfCases]; + + for (int i = 1; i <= numberOfCases; i++) { + String currentLine=lines[i]; + int numberOfGooglers=Integer.parseInt(currentLine.substring(0, currentLine.indexOf("" ""))); + int start=currentLine.indexOf("" "")+1; + int surprisingTriplets=Integer.parseInt(currentLine.substring(start, currentLine.indexOf("" "", start))); + start=currentLine.indexOf("" "", start)+1; + int valueOfP=Integer.parseInt(currentLine.substring(start, currentLine.indexOf("" "", start))); + start=currentLine.indexOf("" "", start)+1; + String totalPointsString=currentLine.substring(start); + int[] totalPoints=getIntArrayFromSpaceSeperatedString(totalPointsString, numberOfGooglers); + java.util.Arrays.sort(totalPoints); + int resultValue=0; + for (int j = totalPoints.length-1; j >=0 ; j--){ + if(valueOfP==1){ + if(totalPoints[j]>0){ + resultValue++; + } + } else if(totalPoints[j]>3*valueOfP-3){ + resultValue++; + } else if(totalPoints[j]>3*valueOfP-5 && surprisingTriplets>0){ + resultValue++; + surprisingTriplets--; + } + } + result[i-1]=""Case #""+i+"": ""+resultValue; + } + writeLinesToFile(outputFile, result); + } + + public static String[] readAllLinesOfFile(String file) { + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(file); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + String[] result = new String[1000000]; + int index = 0; + while ((strLine = br.readLine()) != null) { + result[index++] = strLine; + } + //Close the input stream + in.close(); + String[] newResult = java.util.Arrays.copyOf(result, index); + return newResult; + } catch (Exception e) {//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + return new String[]{}; + } + } + + public static void writeLinesToFile(String filename, String[] linesToWrite) { + try { + PrintWriter pw = new PrintWriter(new FileWriter(filename)); + for (int i = 0; i < linesToWrite.length; i++) { + pw.println(linesToWrite[i]); + } + pw.flush(); + pw.close(); + } catch (Exception e) { + throw new RuntimeException(""Writing File \"""" + filename + ""\"" Failed!""); + } + } + + public static int[] getIntArrayFromSpaceSeperatedString(String numbers, int numberOfInts){ + numbers=numbers.trim(); + int[] result= new int[numberOfInts]; + int start=0; + int end=numbers.indexOf("" ""); + for(int i=0; i 3 * (p - 1)) { + hscr++; + } else if (p>1 && scr > 3 * (p - 2) + 1) { + mscr++; + } + } + int max=hscr+ Math.min(S, mscr); + System.out.println(""Case #"" + i+"": ""+max); + bf.write(""Case #"" + i+"": ""+max+ ""\n""); + } + bf.close(); + } +} +" +A20361,"package R0; + +import java.io.*; +import java.util.*; + +public class B { + + private static void solve(int TC) { + int N = ni(); + int S = ni(); + int p = ni(); + int g[] = new int[N]; + for (int i = 0; i < g.length; i++) + g[i] = ni(); + + int ok = 3 * p - 2; + int pok = ok - 2; + if ( p == 1 ) + pok = 1; + int ret = 0; + for (int i : g) { + if ( i >= ok ) { + ret++; + continue; + } + if ( S > 0 && i >= pok ) { + ret++; + S--; + } + } + out.println(String.format(""Case #%d: %d"", TC, ret)); + } + private static final boolean STDIO = false; + private static final String TASK = ""B""; + private static final String ROUND = ""R0""; + private static final String DATA = ""large""; + private static Scanner sc; + private static PrintStream out; + + public static void main(String[] args) throws FileNotFoundException, IOException { + Locale.setDefault(Locale.ENGLISH); + + String DATA_IN = String.format(""tst/%s/%s.%s.in"", ROUND, TASK, DATA); + String DATA_OUT = String.format(""tst/%s/%s.%s.out"", ROUND, TASK, DATA); + + String str = null; + if ( args.length > 0 ) + str = args[0]; + else if ( !STDIO ) + str = DATA_IN; + sc = new Scanner((str != null) ? new FileInputStream(str) : System.in); + + str = null; + if ( args.length > 1 ) + str = args[1]; + else if ( !STDIO ) + str = DATA_OUT; + + out = (str != null) ? new PrintStream(str) : System.out; + + int TC = ni(); + for (int i = 1; i <= TC; i++) { + solve(i); + } + } + + private static int ni() { + return sc.nextInt(); + } +} +" +A20889,"import java.util.Arrays; +import java.util.Scanner; +public class DancingGoogler { + public static void main (String [] args) { + Scanner sc = new Scanner (System.in); + int x = sc.nextInt(); + for (int i = 0; i < x; i++) { + int num = sc.nextInt(); + int lim = sc.nextInt(); + int goal = sc.nextInt(); + int [] list = new int [num]; + for (int j = 0; j < num; j++) + list[j] = sc.nextInt(); + Arrays.sort(list); + int count = 0; + for (int j = num-1; j >= 0; j--) { + if (list[j] >= goal*3-2) count++; + else if (lim > 0 && list[j] >= goal && list[j] >= goal*3-4) { + count++; + lim--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } +} +" +A21522,"package ru.sidorkevich.google.jam.qualification.b; + +import java.util.HashSet; +import java.util.Set; + +public class Triplet { + + public static int MAX_DISTANCE = 2; + + private int score1; + private int score2; + private int score3; + + public Triplet(int score1, int score2, int score3) { + this.score1 = score1; + this.score2 = score2; + this.score3 = score3; + } + + public int getScore1() { + return score1; + } + + public int getScore2() { + return score2; + } + + public int getScore3() { + return score3; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Triplet triplet = (Triplet) o; + + Set set1 = new HashSet(); + set1.add(score1); + set1.add(score2); + set1.add(score3); + + Set set2 = new HashSet(); + set2.add(triplet.score1); + set2.add(triplet.score2); + set2.add(triplet.score3); + + return set1.equals(set2); + } + + @Override + public int hashCode() { + int result = score1; + result = 31 * result + score2; + result = 31 * result + score3; + return result; + } + + @Override + public String toString() { + return score1 + "" "" + score2 + "" "" + score3; + } + + public boolean isSurprising() { + return Math.abs(score1 - score2) == MAX_DISTANCE || Math.abs(score1 - score3) == MAX_DISTANCE || + Math.abs(score2 - score3) == MAX_DISTANCE; + } + + public int bestScore() { + return Math.max(Math.max(score1, score2), score3); + } +} +" +A22026," +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + + +public class gjam { + + public static void main(String[] args) + { + + int TestCases = 0; + int currentCase = 0; + + try + { + + + FileInputStream fstream = new FileInputStream(""B-small-attempt2.in""); + DataInputStream dstream = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(dstream)); + + String inputStr = br.readLine(); + + TestCases = Integer.parseInt(inputStr); + + while(currentCase != TestCases) + { + int N = 0; + int S = 0; + int p = 0; + int[] scores; + int result = 0; + + inputStr = br.readLine(); + + String[] variableStr = inputStr.split("" ""); + + N = Integer.parseInt(variableStr[0]); + + S = Integer.parseInt(variableStr[1]); + + p = Integer.parseInt(variableStr[2]); + + String[] scoreStr = new String[N]; + + for(int i = 3; i < variableStr.length;i++) + { + scoreStr[i - 3] = variableStr[i]; + } + + scores = new int[N]; + + for(int i = 0; i < scores.length; i++) + { + scores[i] = Integer.parseInt(scoreStr[i]); + } + for(int i = 0; i< scores.length; i++) + { + int tmp = scores[i]; + + float d = tmp/3.0f; + + if(d == p) + { + result++; + } + else + { + if(d > p) + { + int r = 0; + r += d; + + if((r + r + r) == tmp) + { + result++; + } + else + if((r + r + (r-1)) == tmp) + { + result++; + } + else + if((r + (r-1) + (r-1)) == tmp) + { + result++; + } + else + if((r + (r+1)+r)==tmp) + { + result++; + } + else + if((r +(r+1) + (r+1))==tmp) + { + result++; + } + else + { + if(S > 0) + { + if((r + r + (r-2))==tmp) + { + result++; + S--; + } + else + if((r+(r-2)+(r-2)) == tmp) + { + result++; + S--; + } + else + if((r + (r-1) + (r-2)) == tmp) + { + result++; + S--; + } + if((r + (r+2)+r)==tmp) + { + result++; + S--; + } + else + if((r +(r+2) + (r+2))==tmp) + { + result++; + S--; + } + else + if((r + (r+1)+(r+2))==tmp) + { + result++; + S--; + } + + } + } + + } + else + if((p + p + (p-1)) == tmp) + { + result++; + } + else + if((p + (p-1) + (p-1)) == tmp) + { + result++; + } + else + { + if((S > 0) && (tmp != 0)) + { + if((p + p + (p-2))==tmp) + { + result++; + S--; + } + else + if((p+(p-2)+(p-2)) == tmp) + { + result++; + S--; + } + else + if((p + (p-1) + (p-2)) == tmp) + { + result++; + S--; + } + + } + + } + + } + + + } + + + + + System.out.println(""Case #"" + (currentCase +1) + "": "" + result); + currentCase++; + } + + + } + catch(Exception e) + { + System.err.println(""Err: "" + e.getMessage()); + } + + } + +} +" +A21911,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package test; + +/** + * + * @author KAMIKATAZ + */ + + + + + + +//~--- JDK imports ------------------------------------------------------------ + +import dancit.*; +import dancit.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * + * @author KAMIKATAZ + */ +public class DanceGoogle { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + FileInputStream fstream = + new FileInputStream(""C:\\Users\\KAMIKATAZ\\Desktop\\codejam\\p2\\B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + BufferedWriter out1 = new BufferedWriter( + new FileWriter( + ""C:\\Users\\KAMIKATAZ\\Desktop\\codejam\\p2\\out-B.ou"", + true)); + String times = br.readLine(); + int n = Integer.valueOf(times); + + System.out.println(""number of test cases : "" + n); + + // will be used vars + + int currentCase = 0; + int G; + int S ; + int P; + int fav = 0; + int s = 0; + + // processor starts + + while ((strLine = br.readLine()) != null) { + + + + fav=0; + + ++currentCase; + out1.write(""Case #"" + currentCase + "": ""); + + // System.out.println(strLine); + + StringTokenizer st=new StringTokenizer(strLine,"" ""); + G=Integer.valueOf(st.nextToken()); + int scores[]=new int[G]; + S=Integer.valueOf(st.nextToken()); + P=Integer.valueOf(st.nextToken()); + int tmp=0; + + System.out.println(""\n""+G+"" ""+S+"" ""+P); + + while(st.hasMoreTokens()){ + + scores[tmp]=Integer.valueOf(st.nextToken()); + System.out.print(scores[tmp]+"" ""); + ++tmp; + + } + + // logic starts + int favorable=0; + int special=0; + + /// var declaration ends + + + for (int g =0;g=0){ + + + if (((w)+(w)+(w-1))==scores[g]){ ///// 3w-1 + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +""by 3w-1""); + } + if(((w)+(w-1)+(w-1))==scores[g]){ //// 3w-2 + + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +"" by 3w-2""); + } + } + + if((w+1)<=10){ + + if(((w)+(w)+(w+1))==scores[g]){ ///// scores 3w+1 + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +"" by 3w+1""); + + } + + if(((w)+(w+1)+(w+1))==scores[g]){ ///// scores 3w+2 + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +"" by 3w +2""); + + } + + } + + if(((w)*3)==scores[g]){ + + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +"" by 3w""); + + } + + + }} + + ////////// NORMAL ENDS + + //// loop d speciale + for (int w=P;w<=10;++w) + { + + //////////// TEST CASES + + + + + /////////////////////////////////////////////SPECIAL + + if(S>0 && special=0){ + + if(((w)+(w-1)+(w-2))==scores[g]){ ////////////// 3w-3 + + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +"" by 3w-3""); + ++special; + + } + if((w)+(w-2)+(w-2)==scores[g]){ ///////////// 3w-4 + + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +"" by 3w-4""); + ++special; + + } + + + } + if ((w+2)<=10){ + if(((w+2)+(w+2)+(w))==scores[g]){ ////// 3w+4 + + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +""with 3w+4""); + ++special; + + } + if(((w+2)+(w+1)+(w))==scores[g]){ //// 3w+3 + + ++favorable;System.out.println(""Checking : ""+scores[g] + "" for : ""+w +"" by 3w+3""); + ++special; + + } + + } + } + + + + + + //////////// TEST CASES END + + + } + if (favorable >0){ + ++fav; + } + //logic ends + + + System.out.println(""for score : "" +scores[g]+"" values of favorable : ""+fav +"" value of special is : ""+special); + + + + + } + out1.write(String.valueOf(fav)); + out1.newLine(); + + } + //out1.newLine(); + //out1.flush(); + + // Close the input stream + in.close(); + out1.close(); + } catch (Exception e) { // Catch exception if any + System.out.println(""Error: "" + e.getMessage() + "" "" + e); + } + } +} + + +//~ Formatted by Jindent --- http://www.jindent.com +" +A21077,"package GCJ2012QR2012; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.*; +import java.util.HashMap; +import java.util.TreeMap; +import java.util.Iterator; +import java.util.ArrayList; +import java.lang.Math; +import java.util.LinkedList; + +import java.util.Map; +import java.util.Collections; +import java.util.Comparator; + +import template.Template; + +public class B { + public static void main(String[] args) throws Exception{ + Template tpl = new Template('B', false, false, 0); + String line = tpl.read(0); + int T = Integer.parseInt(line); + for(int i=1; i=2){ + cnf_sup = p+(p-1)+(p-1); + psb_sup = p+(p-2)+(p-2); + } + else if(p>=1){ + cnf_sup = p+(p-1)+(p-1); + psb_sup = p+(p-1)+(p-1); + } + else{ + cnf_sup = p*3; + psb_sup = p*3; + } + + for(int j=0; j=cnf_sup) confirmed++; + else if(t[j]>=psb_sup) possible++; + else never++; + } + int result = confirmed+Math.min(possible, S); + String rst = ""Case #""+i+"": ""+ result; + tpl.addLine(rst); + } + tpl.write(); + + } +} +" +A21868,"import java.lang.*; +import java.util.*; +import java.io.*; + +public class B +{ + public static void main(String[] args) throws Exception + { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(bf.readLine()); + for (int i = 0; i < T; ++i) { + int N = 0, S = 0, p = 0; + StringTokenizer st = new StringTokenizer(bf.readLine()); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + int r = 0; + for (int j = 0; j < N; ++j) { + int t = Integer.parseInt(st.nextToken()); + if ((t / 3 + ((t % 3 > 0) ? 1 : 0)) >= p) + ++r; + else if ((t / 3 + t % 3) >= p && S > 0) { + --S; + ++r; + } + else if (t > 0 && (t / 3 + 1) >= p && S > 0) { + --S; + ++r; + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + r); + } + } +} +" +A20044,"import java.util.Scanner; +import java.util.ArrayList; + +public class dancing { + public static void main(String [] args){ + Scanner Keyboard = new Scanner(System.in); + int testCases; + ArrayList input = new ArrayList(); + ArrayList totalPoints = new ArrayList(); + int whitespaceNumber = 1; + int previousWhitespace = 0; + int numberOfGooglers = 0; + int surprisingTriplet = 0; + int bestResult = 0; + int k = 0; + int [] triplet = {0, 0, 0}; + int numberOfBestResults = 0; + + testCases = Keyboard.nextInt(); + Keyboard.nextLine(); + + for (int i = 0; i < testCases; i++){ + input.add(Keyboard.nextLine()); + } + + for (int i = 0; i < testCases; i++){ + for (int j = 0; j < input.get(i).length(); j++){ + if (input.get(i).charAt(j) == ' '){ + if (whitespaceNumber == 1){ + numberOfGooglers = Integer.parseInt(input.get(i).substring(0, j)); + whitespaceNumber++; + previousWhitespace = j; + } + else if (whitespaceNumber == 2){ + surprisingTriplet = Integer.parseInt(input.get(i).substring(previousWhitespace+1, j)); + whitespaceNumber++; + previousWhitespace = j; + } + else if (whitespaceNumber == 3){ + bestResult = Integer.parseInt(input.get(i).substring(previousWhitespace+1, j)); + whitespaceNumber++; + previousWhitespace = j; + } + else if (whitespaceNumber >= 4){ + totalPoints.add(Integer.parseInt(input.get(i).substring(previousWhitespace+1, j))); + whitespaceNumber++; + previousWhitespace = j; + } + } + } + totalPoints.add(Integer.parseInt(input.get(i).substring(previousWhitespace+1, input.get(i).length()))); + + for (int b = 0; b < numberOfGooglers; b++){ + while(true){ + if (k + k + k < totalPoints.get(b)){ + k++; + } + else if (k + k + k > totalPoints.get(b)){ + if (k + k + (k-1) == totalPoints.get(b)){ + triplet[0] = k; + triplet[1] = k; + triplet[2] = k-1; + break; + } + else if (k + (k-1) + (k-1) == totalPoints.get(b)){ + triplet[0] = k; + triplet[1] = k-1; + triplet[2] = k-1; + break; + } + } + else if (k + k + k == totalPoints.get(b)){ + triplet[0] = k; + triplet[1] = k; + triplet[2] = k; + break; + } + } + if (triplet[0] < bestResult && triplet[1] < bestResult && triplet[2] < bestResult && surprisingTriplet > 0){ + while (k < bestResult){ + k++; + } + if (k + k + (k-2) == totalPoints.get(b) && k >= bestResult && (k-2)>=0){ + triplet[0] = k; + triplet[1] = k; + triplet[2] = k-2; + surprisingTriplet--; + } + else if (k + (k-1) + (k-2) == totalPoints.get(b) && k >= bestResult && (k-2)>=0){ + triplet[0] = k; + triplet[1] = k-1; + triplet[2] = k-2; + surprisingTriplet--; + } + else if (k + (k-2) + (k-2) == totalPoints.get(b) && k >= bestResult && (k-2)>=0){ + triplet[0] = k; + triplet[1] = k-2; + triplet[2] = k-2; + surprisingTriplet--; + } + } + + if (triplet[0] >= bestResult || triplet[1] >= bestResult || triplet[2] >= bestResult){ + numberOfBestResults++; + } + k = 0; + } + + System.out.println(""Case #"" + (i+1) + "": "" + numberOfBestResults); + + whitespaceNumber = 1; + previousWhitespace = 0; + numberOfGooglers = 0; + surprisingTriplet = 0; + bestResult = 0; + numberOfBestResults = 0; + totalPoints.clear(); + } + + + } +} +" +A22423,"package fr.lcwi.googlecodejam; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +/** + * For Google Code Jam 2012 + */ +public class ProblemB { + + private static Scanner scanner; + private static int nbCases; + + public static void main(String[] args) throws IOException { + String filename = args[0]; + scanner = new Scanner(ProblemB.class.getClassLoader().getResourceAsStream(filename + "".in"")); + + nbCases = Integer.valueOf(scanner.nextLine()); + + try (BufferedWriter bWriter = new BufferedWriter(new FileWriter(filename + "".out""))) { + for (int i = 1; i <= nbCases; i++) { + resolveCase(i, bWriter); + } + } + } + + private static void resolveCase(int caseNb, BufferedWriter bWriter) throws IOException { + int nbGooglers = scanner.nextInt(); + int nbSurprises = scanner.nextInt(); + int minScore = scanner.nextInt(); + + int result = 0; + if (minScore == 0) { + result = nbGooglers; + for (int i = 0; i < nbGooglers; i++) { + scanner.nextInt(); + } + + } else { + for (int i = 0; i < nbGooglers; i++) { + int totalScore = scanner.nextInt(); + + if (totalScore > 0) { + if (totalScore >= minScore * 3 - 2) { + result++; + } else { + if (totalScore >= minScore * 3 - 4 && nbSurprises > 0) { + result++; + nbSurprises--; + } + } + } + } + + } + + bWriter.write(""Case #"" + caseNb + "": "" + result); + if (caseNb < nbCases) { + bWriter.newLine(); + } + } +} +" +A20553,"package codejam2012.qualification.b; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.ArrayListMultimap; + +public final class Memory { + + private static Logger log = LoggerFactory.getLogger(Memory.class); + + public ArrayListMultimap data = ArrayListMultimap.create(); + + private static int startFor(int a) { + return a < 2 ? 0 : a - 2; + } + + private static int endFor(int a) { + return a > 8 ? 10 : a + 2; + } + + public void init() { + log.debug(""init: start""); + for (int a = 0; a <= 10; ++a) { + int bStart = startFor(a); + int bEnd = endFor(a); + for (int b = bStart; b <= bEnd; ++b) { + int cStart = startFor(b); + int cEnd = endFor(b); + for (int c = cStart; c <= cEnd; ++c) { + int total = a + b + c; + data.put(total, Triplet.of(a, b, c, total)); + } + } + } + log.debug(""init: finished""); + } +} +" +A20813,"package qualifying; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Google Code Jam, Problem B. Result finder + * + * @author Petar + * + */ +public class Dancers { + private static BufferedReader in; + private static BufferedWriter out; + + /** + * Main, reads in scores, outputs max num of Googler's with result p + * + * @param args + */ + public static void main(String[] args) { + List scores; + int numSurprise, numGooglers, p, maxGooglers; + String currLine = """"; + + try { + out = new BufferedWriter(new FileWriter("".out"")); + in = new BufferedReader(new FileReader("".in"")); + int testNum = Integer.parseInt(in.readLine()); + for (int i = 0; i < testNum; i++) { + maxGooglers = 0; + currLine = in.readLine(); + String[] testBound = currLine.split("" ""); + + numGooglers = Integer.parseInt(testBound[0]); + numSurprise = Integer.parseInt(testBound[1]); + p = Integer.parseInt(testBound[2]); + System.out + .println(String + .format(""The bounds of the problem are %d googlers, %d surprising results and %d p value"", + numGooglers, numSurprise, p)); + // Read in the scores + scores = new ArrayList(numGooglers); + + for (int j = 0; j < numGooglers; j++) { + scores.add(Integer.parseInt(testBound[j + 3])); + } + + // Determine the tallies + for (Integer score : scores) { + if (score < (3 * p - 4) || score < p) { + continue; + } else if (score >= (3 * p - 2)) { + maxGooglers++; + } else { + if (numSurprise > 0) { + maxGooglers++; + numSurprise--; + } + } + } + + Collections.sort(scores); + + out.write(String.format(""Case #%d: %d"", i + 1, maxGooglers)); + out.newLine(); + } + + in.close(); + out.flush(); + out.close(); + } catch (FileNotFoundException e) { + System.err.println(""Input file was not found""); + } catch (IOException e) { + System.err.println(""Problem reading from input file""); + e.printStackTrace(); + } + } +} +" +A21729,"import java.io.*; +import java.util.*; + +public class Second2 +{ + public static void main(String[]args)throws Exception + { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new File(""B-large.out"")); + StringTokenizer st; + int cases = Integer.parseInt(br.readLine()); + for(int c = 0; c < cases; c++) + { + st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int [] totals = new int[n]; + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + for(int i = 0; i < n; i++) + totals[i] = Integer.parseInt(st.nextToken()); + Arrays.sort(totals); + int res = 0; + + for(int i = 0; i < n; i++) + { + outer:for(int j = p; j <= totals[i]; j++) + { + for(int k = j-2; k <= j; k++) + { + if(k < 0) + continue; + for(int l = j-2; l <= j; l++) + { + if(l < 0) + continue; + if(j+k+l > totals[i]) + break outer; + if(j+k+l == totals[i]) + { + if(j-k == 2 || j-l == 2) + { + + if(s > 0) + s--; + else + continue; + } + res++; + break outer; + } + } + } + } + } + pw.printf(""Case #%d: %d\n"", c+1, res); + } + pw.close(); + pw.flush(); + /* + for(int i = 0; i < totals.length; i++) + { + for(int j = 0; j <= s; j++) + System.out.println(dp[i][j]); + }*/ + //System.out.println(dp[totals.length-1][s]); + } +}" +A20310,"import java.io.BufferedReader; +import java.io.IOException; + +public class SolverModule { + + public StringBuilder process(BufferedReader in, StringBuilder builder) + throws IOException { + in.readLine(); + String line = in.readLine(); + int count = 1; + while (line != null) { + appendLine(line, builder,count); + count++; + line = in.readLine(); + } + return builder; + } + + public static void appendLine(String line, StringBuilder builder, int count) { + builder.append(""Case #""+count+"": ""+line + ""\r\n""); + } +} +" +A22207,"package br.com.atama.google.jam.dancing; + +public class TripletScore implements Comparable { + + private final int threshold = Context.INSTANCE.getThreshold(); + private final int total; + private final int mod; + private final int gap; + private int potential = 0; + private int numGoodScore = 0; + private boolean isSurprise = false; + + public TripletScore(int total) { + this.total = total; + final int div = total / 3; + mod = total % 3; + gap = threshold - div; + + calculateGoodScore(); + } + + private void calculateGoodScore() { + if (total == 0) { + numGoodScore = 0; + isSurprise = false; + + if (gap <= 0) + numGoodScore = 3; + + potential = Integer.MIN_VALUE; + } else if (isSurprise) { + numGoodScore = 0; + if (mod == 0) { + if (gap == 1) { + numGoodScore = 1; + potential = -1; + } else if (gap == 0) { + numGoodScore = 2; + potential = 1; + } else if (gap < 0) { + numGoodScore = 3; + potential = 0; + } + } else if (mod == 1) { + if (gap == 1) { + numGoodScore = 2; + potential = -1; + } else if (gap == 0) { + numGoodScore = 2; + potential = 1; + } else if (gap < 0) { + numGoodScore = 3; + potential = 0; + } + } else if (mod == 2) { + if (gap == 2) { + numGoodScore = 1; + potential = -1; + } else if (gap == 1) { + numGoodScore = 1; + potential = 1; + } else if (gap <= 0) { + numGoodScore = 3; + } + } else { + assert false; + } + } else { + numGoodScore = 0; + if (mod == 0) { + if (gap == 1) { + potential = 1; + } else if (gap == 0) { + numGoodScore = 3; + potential = -1; + } else if (gap < 0) { + numGoodScore = 3; + } + } else if (mod == 1) { + if (gap == 1) { + numGoodScore = 1; + potential = 1; + } else if (gap == 0) { + numGoodScore = 3; + potential = -1; + } else if (gap < 0) { + numGoodScore = 3; + potential = 0; + } + } else if (mod == 2) { + if (gap == 2) { + potential = 1; + } else if (gap == 1) { + numGoodScore = 2; + potential = -1; + } else if (gap <= 0) { + numGoodScore = 3; + potential = 0; + } + } else { + assert false; + } + } + } + + @Override + public int compareTo(TripletScore o) { + if (numGoodScore == 0) { + if (o.numGoodScore == 0) + return potential - o.potential; + return 1; + } else { + if (o.numGoodScore == 0) + return -1; + return potential - o.potential; + } + } + + public boolean isSurprise() { + return isSurprise; + } + + public void setSurprise(boolean b) { + isSurprise = b; + calculateGoodScore(); + } + + public int getNumGoodScore() { + return numGoodScore; + } + + public boolean isZero() { + return total == 0; + } + +} +" +A21409,"import java.util.Scanner; + + +public class DancingWithGooglers { + public static void main(String[]args){ + Scanner sc = new Scanner(System.in); + //Read in the T int -- Test Cases + int T = Integer.parseInt(sc.nextLine()); + for (int t = 1; t <= T; t++) { + int num = 0; + //START OF CODE + int N = sc.nextInt(); //Num of googlers + int S = sc.nextInt(); //Surprising Triplets + int p = sc.nextInt(); + int ti [] = new int[N]; + for (int n = 0; n < N; n++) { + ti[n] = sc.nextInt(); + } + + + for (int i = 0; i < ti.length; i++) { + //Do not care if scores are above p + //Only lower than p and if need be adjusted + if(ti[i] == 0 && p == 0){ + num++; + } else if(ti[i] == 0){ + + } else if(ti[i] / 3 >= p || (ti[i] / 3 == p-1 && ti[i] % 3 != 0)){ + num++; + } else if(S !=0 && ((ti[i] / 3 == p-2 && ti[i] % 3 == 2 ) || (ti[i] / 3 == p-1))){ + num++; + S--; + } + } + //END OF CODE + //OUTPUT + System.out.format(""Case #%d: %d\n"", t, num); + } + } +} +" +A20947,"package org.moriraaca.codejam; + +public enum OutputDestination { + STDOUT, FILE; +} +" +A20588,"import java.io.File; +import java.io.PrintWriter; +import java.util.NoSuchElementException; +import java.util.Scanner; + + +public final class GoogleDanceJudge { + + public static enum TripletType { + INVALID, + USUAL, + SURPRISING + }; + + public static TripletType findResultType (final int resultsSum, final int bestResult) { + final int meanValue = resultsSum / 3; + if (meanValue > bestResult) + return TripletType.USUAL; + //else + final int unknownTwoResultsSum = resultsSum - bestResult; //hypothesing + if (unknownTwoResultsSum < 0) + return TripletType.INVALID; + final int lowestAcceptedResult = unknownTwoResultsSum / 2; + switch (bestResult - lowestAcceptedResult) { + case 0: + case 1: + return TripletType.USUAL; + case 2: + return TripletType.SURPRISING; + default: + return TripletType.INVALID; + } + } + + private static final String OUTPUT_FILE_EXTENSION = ""out""; + + public static void main (final String[] args) throws Exception { + //input init + if (args.length < 1) + throw new IllegalArgumentException(); + + final String inputFileName = args[0]; + final int lastDotIndex = inputFileName.lastIndexOf('.'); + final String fileName = (lastDotIndex < 0) ? inputFileName : inputFileName.substring(0, lastDotIndex); + final String outputFileName = fileName + ""."" + OUTPUT_FILE_EXTENSION; + + final File inputFile = new File(inputFileName); + final File outputFile = new File(outputFileName); + Scanner inputScanner = null; + PrintWriter outputWriter = null; + + try { + inputScanner = new Scanner(inputFile); + outputWriter = new PrintWriter(outputFile); + final int numberLines = inputScanner.nextInt(); + inputScanner.nextLine(); //go to first text line + for (int i = 0; i < numberLines; ++i) { + final int googlersNumber = inputScanner.nextInt(); + final int maxSurprisingTripletsNumber = inputScanner.nextInt(); + final int minimumBestResult = inputScanner.nextInt(); + int possibleResultsNumber = 0; + int unusualResultsNumber = 0; + for (int j = 0; j < googlersNumber; ++j) { + final int result = inputScanner.nextInt(); + final TripletType resultType = findResultType(result, minimumBestResult); + switch (resultType) { + case SURPRISING: + if (unusualResultsNumber >= maxSurprisingTripletsNumber) + break; //not acceptable anymore + ++unusualResultsNumber; + //no break + case USUAL: + ++ possibleResultsNumber; + break; + //invalid, don't count + } + } + outputWriter.println(""Case #"" + (i+1) + "": "" + possibleResultsNumber); + } + } catch (final NoSuchElementException noSuchElementException) { + System.err.println(""invalid input""); + throw noSuchElementException; + } finally { + if (inputScanner != null) { + inputScanner.close(); + } + if (outputWriter != null) { + outputWriter.flush(); + outputWriter.close(); + } + } + } + +} +" +A22975,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + + + +public class B implements Runnable{ + BufferedReader in; + BufferedWriter out; + static String inputFile=""""; + static String outputFile=""""; + static { + inputFile=B.class.getName()+"".in""; + outputFile=B.class.getName()+"".out""; + } + public int iread() throws Exception { + return Integer.parseInt(readword()); + } + public long lread() throws Exception { + return Long.parseLong(readword()); + } + public double dread() throws Exception { + return Double.parseDouble(readword()); + } + public String readword() throws Exception { + int k = in.read(); + if(k < 0) return """"; + while(k>=0 && k<=' ') k=in.read(); + StringBuilder bld = new StringBuilder(); + while(k>' ') { + bld.append((char)k); + k=in.read(); + } + return bld.toString(); + } + + public void solve() throws Exception { + int T = iread(); + for(int t=1; t<=T; t++) { + int N = iread(); + int S = iread(); + int P = iread(); + int[] score = new int[N]; + int result = 0; + for(int n=0; n 1){ + if(score[n]<3*P-4) continue; + else if(score[n]==3*P-3||score[n]==3*P-4){ + if(S > 0) { + result++; + S--; + } + else continue; + } + else result++; + } + else { + if(P == 1) { + if(score[n]==0) continue; + else result++; + } + else { + result++; + } + } + } + out.write(""Case #""+t+"": ""+result+""\n""); + } + } + + public void run() { + try{ + in = new BufferedReader(new FileReader(inputFile)); + out = new BufferedWriter(new FileWriter(outputFile)); + solve(); + out.flush(); + }catch(Exception e){ + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new Thread(new B()).start(); + } + +} +" +A21368,"package qualification; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.StringTokenizer; + +import com.sun.org.apache.xpath.internal.axes.ReverseAxesWalker; + +public class BMain { + + private static final int S_THEN_P = 0; + private static final int NO_S_THEN_P = 1; + private static final int ALWAYS_P = 2; + private static final int CAN_BE_S = 3; + + public static void main(String[] args) { + String inputFileName = args[0]; + String outputFileName = args[1]; + BufferedReader reader = null; + File outputfile = new File(outputFileName); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(outputfile); + } catch (FileNotFoundException e1) { + System.err.println(""Output file not found""); + System.exit(1); + } + + DataOutputStream dos = new DataOutputStream(fos); + try { + reader = new BufferedReader(new FileReader(inputFileName)); + + String numberOfCasesStr = reader.readLine(); // Number of cases + int numberOfCases = Integer.valueOf(numberOfCasesStr); // Default: + // number of + // cases + for (int i = 0; i < numberOfCases; i++) { + System.out.println(""Case #"" + (i + 1)); + // Read Case + StringTokenizer tokenizer = new StringTokenizer( + reader.readLine()); + int N = Integer.valueOf(tokenizer.nextToken()); + int S = Integer.valueOf(tokenizer.nextToken()); + int p = Integer.valueOf(tokenizer.nextToken()); + + List totalPoints = new ArrayList(); + for (int j = 0; j < N; j++) { + totalPoints.add(Integer.valueOf(tokenizer.nextToken())); + } + + // Solve Case + int result = N; + + Collections.sort(totalPoints, Collections.reverseOrder()); + + for (Integer points : totalPoints) { + boolean sThenP = false; + boolean noSThenP = false; + boolean alwaysP = false; + boolean canBeS = false; + if (p == 0) { + continue; + } else if (points.equals(0) || points.equals(1)) { + if (points >= p) { + continue; + } else { + sThenP = false; + noSThenP = false; + } + } else if (points.equals(30) || points.equals(29)) { + sThenP = true; + noSThenP = true; + } else { + boolean divBy3 = (points % 3) == 0; + double third = (double) points / 3; + + // TODO Ver caso de borde 10 + if (divBy3) { + sThenP = third + 1 >= p; + noSThenP = third >= p; + } else { + int ceiling = (int) Math.ceil(third); + boolean prevDivBy3 = ((points - 1) % 3 == 0); + + if (prevDivBy3) { + sThenP = ceiling >= p; + noSThenP = ceiling >= p; + } else { + sThenP = ceiling + 1 >= p; + noSThenP = ceiling >= p; + } + } + } + + alwaysP = sThenP && noSThenP; + if (sThenP && !noSThenP) { + if (S > 0) { + canBeS = true; + S--; + } else { + canBeS = false; + } + } else { + canBeS = false; + } + + if (!alwaysP && !canBeS) { + result--; + } + + } + try { + dos.writeBytes(""Case #"" + (i + 1) + "": "" + result + ""\n""); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } catch (FileNotFoundException e) { + System.out.println(""Input file not found""); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } +} +" +A22441,"/* + * Abstract class that reads either the standard input, a named file, or prompts at the terminal. + * Implement ""process"" for each CodeJam problem. + * Reads input through a ReadWrapper, wrapping a BufferedReader. + */ + +import java.io.*; +import java.util.StringTokenizer; +import java.text.*; + +public abstract class CodeJammer { + + protected ReadWrapper reader; + protected int caseNum = 1; + + //Processes one case + public abstract void process() throws IOException; + + public void init() { + //Do nothing unless overridden. + } + + //Process all cases... usually just read the number of them and then run process on each. + //Override if necessary. + public void processAll() throws IOException { + init(); + int numTrials = reader.readInt(); + for (int i=0; i readLongsSetFromRow(String row) { + String[] cText = row.split(""\\s""); + Set result = new TreeSet(); + for (int i=0; i0) + res += "", ""; + res += t.substring(i,i+1); + } + res += ""]""; + return res; + } + + + // http://www.proglogic.com/code/java/calculator/lcm.php + + public static long leastCommonMultiplier (long m, long n){ + return m * (n / greatestCommonDivisor(m, n)); + } + + public static long greatestCommonDivisor (long m, long n){ + long x; + long y; + while(m%n != 0){ + x = n; + y = m%n; + m = x; + n = y; + } + return n; + } + + //http://www.vogella.de/articles/JavaAlgorithmsPrimeFactorization/article.html: + + public static List primeFactors(int number) { + int n = number; + List factors = new ArrayList(); + for (int i = 2; i <= n; i++) { + while (n % i == 0) { + factors.add(i); + n /= i; + } + } + return factors; + } +} + " +A21541,"import java.util.StringTokenizer; +public class DancingWithGooglers extends BaseSolution { + public String solveTestCase() throws Exception { + String inp = readLine(); + StringTokenizer st = new StringTokenizer(inp); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int ans=0; + for(int i=0;i0){ + maxNormal = ((t-1)/3) + 1; + } + if(t>1){ + maxSurprise = ((t-2)/3) + 2; + if(maxSurprise>10){ + maxSurprise = 10; + } + } + if(maxNormal>=p){ + ans++; + } else if(S>0&&maxSurprise>=p){ + S--; + ans++; + } + } + return ans+""""; + } + +} +" +A21874,"import java.io.*; +import java.util.*; + +public class Main { + private static IO io; + + public static void main(String[] args) throws IOException { + new Main().run(); + } + + private void run() throws IOException { + io = new IO(System.getProperty(""ONLINE_JUDGE"")!=null);//false->files; true->console + solve(); + io.flush(); + } + + private void solve() throws IOException { + int k = io.nI(); + for(int i = 1; i<=k; i++){ + int n = io.nI(), s = io.nI(), p = io.nI(), a[] = new int[n]; + for(int j = 0; j0&&(p>1&&3*p-4<=a[i]||p==1&&3*p-2<=a[i])){s--; r++;} + }else { + /*if(3*p+2>=a[i])r++;else + if(3*p+4>=a[i]&&s>0){s--; r++;}*/ + r++; + } + } + return r; + } + + @SuppressWarnings(""unused"") + private class IO{ + StreamTokenizer in; PrintWriter out; BufferedReader br; Reader reader; Writer writer; + public IO(boolean oj) throws IOException{ + Locale.setDefault(Locale.US); + reader = oj ? new InputStreamReader(System.in) : new FileReader(""input.txt""); + writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(""output.txt""); + br = new BufferedReader(reader); + in = new StreamTokenizer(br); + out = new PrintWriter(writer); + } + public void wln(){out.println();} + public void wln(int arg){out.println(arg);} + public void wln(long arg){out.println(arg);} + public void wln(double arg){out.println(arg);} + public void wln(String arg){out.println(arg);} + public void wln(boolean arg){out.println(arg);} + public void wln(char arg){out.println(arg);} + public void wln(float arg){out.println(arg);} + public void wln(Object arg){out.println(arg);} + public void w(int arg){out.print(arg);} + public void w(long arg){out.print(arg);} + public void w(double arg){out.print(arg);} + public void w(String arg){out.print(arg);} + public void w(boolean arg){out.print(arg);} + public void w(char arg){out.print(arg);} + public void w(float arg){out.print(arg);} + public void w(Object arg){out.print(arg);} + public void wf(String format, Object...args){out.printf(format, args);} + public void flush(){out.flush();} + public int nI() throws IOException {in.nextToken(); return(int)in.nval;} + public long nL() throws IOException {in.nextToken(); return(long)in.nval;} + public String nS() throws IOException {in.nextToken(); return in.sval;} + public double nD() throws IOException {in.nextToken(); return in.nval;} + public float nF() throws IOException {in.nextToken(); return (float)in.nval;} + public void wc(char...a){for(char c : a){in.ordinaryChar(c);in.wordChars(c, c);}} + public void wc(char c1, char c2){in.ordinaryChars(c1, c2); in.wordChars(c1, c2);} + } +}" +A22796,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Dance { + + private static final int[] maxBestResult = { 0, 1, 2 }; + private static final int[] maxBestResultSurprise = { 0, 1, 2 }; + private static final int[] minBestResult = { 0, 1, 2 }; + private static final int[] minBestResultSurprise = { 0, 1, 2 }; + + public static void main(String[] args) throws IOException { + long t0 = System.currentTimeMillis(); + BufferedReader in = new BufferedReader(new FileReader(""in.txt"")); + PrintWriter out = new PrintWriter(""out.txt""); + int t = Integer.parseInt(in.readLine()); + for (int i = 1; i <= t; i++) { + String[] ss = in.readLine().split("" ""); + int idx = 0; + int n = Integer.parseInt(ss[idx++]); // number of Googlers + int s = Integer.parseInt(ss[idx++]); // number of Surprises + int p = Integer.parseInt(ss[idx++]); // minimum score + int[] sums = new int[n]; + for (int j = 0; j < n; j++) { + sums[j] = Integer.parseInt(ss[idx++]); + } + int result = compute(sums, s, p); + out.println(""Case #"" + i + "": "" + result); + System.out.println(""Case #"" + i + "": "" + result); + } + out.close(); + System.out.println(""time: "" + (System.currentTimeMillis() - t0)); + } + + private static int compute(int[] sums, int s, int p) { + if (p == 0) + return sums.length; + int pointsRequiredWithOutSurprise = Math.max(1, (p * 3) - 2); // p, p-1, p-1 + int pointsRequiredWithSurprise = Math.max(2, (p * 3) - 4); // p, p-2, p-2 + int result = 0; + for (int i = 0; i < sums.length; i++) { + int sum = sums[i]; + if (sum >= pointsRequiredWithOutSurprise) { + result++; + // splitStd(sum); + } else if (s > 0 && sum >= pointsRequiredWithSurprise) { + s--; + result++; + // splitSurprise(sum); + } else { + // failed + // splitStd(sum); + } + } + return result; + } + + private static void splitStd(int sum) { + switch (sum % 3) { + case 0: + System.out.println(sum + "": "" + sum / 3 + "","" + sum / 3 + "","" + sum / 3); + break; + case 1: + System.out.println(sum + "": "" + (1 + sum / 3) + "","" + sum / 3 + "","" + sum / 3); + break; + case 2: + System.out.println(sum + "": "" + (1 + sum / 3) + "","" + (1 + sum / 3) + "","" + sum / 3); + break; + } + } + + private static void splitSurprise(int sum) { + switch (sum % 3) { + case 0: + System.out.println(sum + "": "" + (1 + sum / 3) + "","" + sum / 3 + "","" + (sum / 3 - 1)); + break; + case 1: + System.out.println(sum + "": "" + (1 + sum / 3) + "","" + (sum / 3 - 1) + "","" + (sum / 3 - 1)); + break; + case 2: + System.out.println(sum + "": "" + (2 + sum / 3) + "","" + (sum / 3) + "","" + sum / 3); + break; + } + } + +} +" +A22659,"import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + HashMap nonsurprising=new HashMap(); + HashMap surprising=new HashMap(); + + for(int i=0;i<=10;i++) + for(int j=0;j<=10;j++) + for(int k=0;k<=10;k++) + { + if(Math.abs(i-j)>2||(Math.abs(i-k)>2)||(Math.abs(k-j)>2)) + { + continue; + } + else if(Math.abs(i-j)<=2||(Math.abs(i-k)<=2)||(Math.abs(k-j)<=2)) + { + //suprising + Integer sum=i+j+k; + Integer local_Max=Math.max(i, Math.max(j, k)); + if(surprising.containsKey(sum)) + { + Integer Global_max=surprising.get(sum); + if(local_Max>Global_max) + { + surprising.remove(sum); + surprising.put(sum, local_Max); + } + } + else + { + surprising.put(sum, local_Max); + } + if(Math.abs(i-j)<=1&&(Math.abs(i-k)<=1)&&(Math.abs(k-j)<=1)) + { + //nonsurprising + + if(nonsurprising.containsKey(sum)) + { + Integer Global_max=nonsurprising.get(sum); + if(local_Max>Global_max) + { + nonsurprising.remove(sum); + nonsurprising.put(sum, local_Max); + } + } + else + { + nonsurprising.put(sum, local_Max); + } + } + } + else + { + + } + } + + Scanner input=new Scanner(System.in); + int t=input.nextInt(); + for(int l=1;l<=t;l++) + { + int n=input.nextInt(); + int s=input.nextInt(); + int p=input.nextInt(); + + int[] totalsum=new int[n+1]; + for(int j=1;j<=n;j++) + { + totalsum[j]=input.nextInt(); + } + + int [][] M=new int [n+1][s+1]; + for(int j=0;j<=s;j++) + M[0][j]=0; + for(int i=1;i<=n;i++) + { + if(nonsurprising.get(totalsum[i])>=p) + M[i][0]=M[i-1][0]+1; + else + M[i][0]=M[i-1][0]; + } + for(int i=1;i<=n;i++) + for(int j=1;j<=s;j++) + { + + int vertical=M[i-1][j]+(nonsurprising.get(totalsum[i])>=p?1:0); + int diag=M[i-1][j-1]+(surprising.get(totalsum[i])>=p?1:0); + if(vertical>diag) + M[i][j]=vertical; + else + M[i][j]=diag; + } + System.out.println(""Case #""+l+"": ""+M[n][s]); + } + } + +} +" +A22815,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Arrays; +import java.util.Scanner; + +public class ProblemB { + public static void main(String[] args) throws IOException { + new ProblemB(); + } + + private int numOfTest; + private static final int ATTEMPT_NO = 0; + private static int SOLVE_HARD = 1; + + int n, s, p; + int[] a = new int[128]; + int ans; + + public ProblemB() throws IOException { + // Scanner input = new Scanner(new File(""input.txt"")); + Scanner input = new Scanner(new File(""B-small-attempt"" + ATTEMPT_NO + "".in"")); + Writer output = new FileWriter(""B-small-attempt"" + ATTEMPT_NO + "".out""); + if (SOLVE_HARD != 0) { + input = new Scanner(new File(""B-large.in"")); + output = new FileWriter(""B-large.out""); + } + //output = new BufferedWriter(new OutputStreamWriter(System.out)); + + numOfTest = input.nextInt(); + for (int test = 1; test <= numOfTest; test++) { + // read from input + n = input.nextInt(); + s = input.nextInt(); + p = input.nextInt(); + for (int i = 0; i < n; i++) { + a[i] = input.nextInt(); + } + + process(); + output.write(""Case #"" + test + "": "" + ans + ""\n""); + } + + input.close(); + output.flush(); + output.close(); + } + + private void process() { + Arrays.sort(a, 0, n); + ans = 0; + for (int i = n - 1; i >= 0; i--) { + int k = a[i] / 3; + int m = k; + if (k * 3 < a[i]) { + m++; + } + if (m >= p) { + ans++; + continue; + } + if (s == 0) { + break; + } + + if (a[i] <= 1) { + break; + } + k = (a[i] - 2) / 3; + m = k + 2; + if (m >= p) { + ans++; + s--; + continue; + } + break; + } + } +}" +A23023,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2012; + +/** + * + * @author Abdelrahman + */ +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class CaseB { + + public static void main(String[] args) throws FileNotFoundException, IOException { + File f1 = new File(""E:\\new c++\\Google\\codejame 2011\\2012\\inputCodejame.txt""); + BufferedReader reader = new BufferedReader(new FileReader(f1)); + int count = Integer.parseInt(reader.readLine()); + for (int i = 0; i < count; i++) { + String[] line = reader.readLine().split("" ""); + int n = Integer.parseInt(line[0]); + int s = Integer.parseInt(line[1]); + int p = Integer.parseInt(line[2]); + int[] scores = new int[line.length - 3]; + int k = 0; + for (int j = 3; j < line.length; j++) { + scores[k++] = Integer.parseInt(line[j]); + } + int counter = 0; + for (int j = 0; j < n; j++) { + int score = scores[j]; + if (score == 0 || score == 30) { + if (score / 3 >= p) { + counter++; + } + } else if (score % 3 == 0) { + if (score / 3 >= p) { + counter++; + } else if ((score / 3) + 1 >= p) { + if (s > 0) { + s--; + counter++; + } + } + } else if (score % 3 == 1) { + if ((score / 3) + 1 >= p) { + counter++; + } + } + else if (score % 3 == 2) { + if ((score / 3)+1 >= p) { + counter++; + } else if ((score / 3) + 2 >= p) { + if (s > 0) { + s--; + counter++; + } + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + counter); + } + } +}" +A22456,"import java.io.IOException; +import java.util.List; + +public class ReverseWords extends JamProblem { + public static void main(String[] args) throws IOException { + ReverseWords p = new ReverseWords(); + p.go(); + } + @Override + String solveCase(JamCase jamCase) { + StringBuilder builder = new StringBuilder(); + ReverseWordsCase c = (ReverseWordsCase) jamCase; + int length = c.words.length; + for (int i = 0; i < length; i++) { + String word = c.words[length-i-1]; + builder.append(word + "" ""); + } + return builder.toString(); + } + + @Override + JamCase parseCase(List file, int line) { + ReverseWordsCase c= new ReverseWordsCase(); + c.lineCount = 1; + c.words = file.get(line).split("" ""); + return c; + } +} + +class ReverseWordsCase extends JamCase{ + String[] words; +}" +A22268,"import java.io.BufferedReader; +import java.io.FileReader; +import java.util.StringTokenizer; + + +public class GooglerDancing { + + public static void main(String[] args) { + try { + BufferedReader fileIn = new BufferedReader(new FileReader(""B-large.in"")); + int cases = Integer.valueOf(fileIn.readLine()); + for(int i = 0; i < cases; i++) { + StringTokenizer str = new StringTokenizer(fileIn.readLine()); + int googlers = Integer.valueOf(str.nextToken()); + int surprises = Integer.valueOf(str.nextToken()); + int minScore = Integer.valueOf(str.nextToken()); + int scoreNoSurprise = minScore + (minScore - 1) * 2; + int scoreSurprise = minScore + (minScore - 2) * 2; + int numHigher = 0; + for(int j = 0; j < googlers; j++) { + int score = Integer.valueOf(str.nextToken()); + if(score >= scoreNoSurprise) { + numHigher++; + } else if(score >= scoreSurprise && surprises > 0 && score != 0) { + numHigher++; + surprises--; + } else if(score >= scoreSurprise && surprises == 0) { + //System.out.println(""Error Case #""+(i+1)+"": min ("" + minScore + "") score (""+score+"") ith (""+j+"")""); + } + } + System.out.println(""Case #""+(i+1)+"": "" + numHigher); + } + + } catch(Exception err) { + System.out.println(""Another fabulous error: "" + err); + err.printStackTrace(); + } + } +} +" +A20202,"import java.io.*; + +public class gcj2 { + static int T; // tesztesetek száma + static int N[]; // Googlerek számai + static int S[]; // meglepő tripletek száma + static int p[]; // pék + static int total[][]; // összpontszámok + static int tripletek[][]; + + + static void beolvas (String f) throws IOException { + BufferedReader be = new BufferedReader(new FileReader(f)); + String sor = be.readLine(); + T = Integer.parseInt(sor); + N = new int[T]; + S = new int[T]; + p = new int[T]; + tripletek = new int[T][3]; + for (int i = 0; i < T; i++) { + sor = be.readLine(); + String nums[] = sor.split("" ""); + N[i] = Integer.parseInt(nums[0]); + S[i] = Integer.parseInt(nums[1]); + p[i] = Integer.parseInt(nums[2]); + } + be.close(); + + int Nmax = N[0]; + for (int j = 0; j < T; j++){ + if (N[j] > Nmax) Nmax = N[j]; + } + total = new int[T][Nmax]; + BufferedReader be2 = new BufferedReader(new FileReader(f)); + sor = be2.readLine(); + for (int i = 0; i < T; i++) { + sor = be2.readLine(); + String nums[] = sor.split("" ""); + for (int j = 0; j < N[i]; j++) { + total[i][j] = Integer.parseInt(nums[3+j]); + } + } + be2.close(); + } + + static void kiir () { + System.out.println(T); + for (int i = 0; i < T; i++) { + System.out.print(N[i]+"" ""+S[i]+"" ""+p[i]+"" ""); + for (int j = 0; j < N[i]; j++) { + System.out.print(total[i][j]+"" ""); + } + System.out.println(); + } + } + + static int count (int a) { + int er = 0; + int surp = S[a]; + for (int i = 0; i < N[a]; i++) { + if (total[a][i] >= (3*p[a])-2) { + er++; + } else { + if (surp > 0 && total[a][i] >= (p[a]+2*(p[a]-2)) && p[a] > 1) { + er++; + surp--; + } + } + } + return er; + } + + public static void main (String args[]) throws IOException { + beolvas(""B-large.in""); + // kiir(); + for (int a = 0; a < T; a++) { + System.out.println(""Case #""+(a+1)+"": ""+count(a)); + } + } +} + +" +A21975,"package com.renoux.gael.codejam.cj2012.qb; + +import com.renoux.gael.codejam.fwk.Solver; +import com.renoux.gael.codejam.utils.ArrayUtils; +import com.renoux.gael.codejam.utils.Input; +import com.renoux.gael.codejam.utils.Output; + +public class QB extends Solver { + + public static void main(String... args) throws Exception { + new QB().run(); + } + + @Override + protected void solveCase(Input in, Output out) { + System.out.println(); + int[] line = ArrayUtils.parseInts(in.readLine().split("" "")); + int ctGooglers = line[0]; + int ctSurprises = line[1]; + int target = line[2]; + + int ctStars = 0; + + for (int i = 3; i < line.length; i++) { + int totalScore = line[i]; + + int lowestScoreNoSurprise = Math.max(target - 1, 0); + int lowestScoreWithSurprise = Math.max(target - 2, 0); + + int lowestTotalNoSurprise = target + 2 * lowestScoreNoSurprise; + int lowestTotalWithSurprise = target + 2 * lowestScoreWithSurprise; + + if (lowestTotalNoSurprise <= totalScore) { + ctStars++; + System.out.println(""Guy "" + (i - 2) + "" did great""); + } else if (lowestTotalWithSurprise <= totalScore && ctSurprises > 0) { + ctStars++; + ctSurprises--; + System.out.println(""Guy "" + (i - 2) + "" did ok""); + } + } + + out.writeLine(ctStars); + } + + @Override + protected String getProblemName() { + return ""QB""; + } + + @Override + protected boolean disableSmall() { + return true; + } + + @Override + protected boolean disableLarge() { + return true; + } +} +" +A20814,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Scanner; + +public class Main { + + public static void main (String[] args) throws IOException { + Writer writer = new FileWriter(""/home/a/dev/codejam-2012/B-submit.txt""); + Scanner scanner = new Scanner(new File(""/home/a/dev/codejam-2012/A-dev.txt"")); + int n_cases = scanner.nextInt(); + scanner.nextLine(); + for (int i = 0; i < n_cases; ++i) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int [] scores = new int[N]; + for (int j = 0; j < scores.length; ++j) { + scores[j] = scanner.nextInt(); + } + Main main = new Main(); + writer.write(""Case #"" + (i + 1) + "": "" + main.solve(S, p, scores) + ""\n""); + } + writer.close(); + } + + public int solve (int S, int p, int [] scores) { + int count = 0; + for (int score : scores) { + int mod = score % 3; + int max; + if (mod == 0) { + max = score / 3; + if (max >= p) { + ++count; continue; + } + if (score < 3) { + continue; + } + if (max < p - 1) { + continue; + } + if (S > 0) { + --S; ++count; continue; + } + } else if (mod == 1) { + max = (score - 1) / 3 + 1; + if (max >= p) { + ++count; continue; + } + continue; + } else if (mod == 2) { + max = (score - 2) / 3 + 1; + if (max >= p) { + ++count; continue; + } + if (max < p - 1) { + continue; + } + if (S > 0) { + --S; ++count; continue; + } + } + } + return count; + } + +} +" +A21287,"/** + * + * @author luoyuan + * + */ +package codejam; + +import java.util.ArrayList; +import static java.lang.Math.*; + +public class Dancing { + + public static void bestResult(String inF,String outF) { + InOutTool iot = new InOutTool(inF,outF); + ArrayList js = new ArrayList(); + for(int i=1;i=p){ + count ++; + }else{ + if(i_0<(p-2)||(temp-i_0)(2*p+2)||(temp-i_0)<(2*p-2)){ + //no case want + }else{//maybe surprising cases + i_1 = p; i_2 = temp - i_0 - i_1; + count ++; + if(abs(i_2-i_0)>1||abs(i_2-i_1)>1)sup ++; + } + } + } + if(sup>s)count -= (sup-s); + js.add(""Case #"" + i + "": "" + count); + } + iot.clear();iot.addAll(js); + iot.outText(); + } + public static void main(String...args){ + Dancing.bestResult(""B-large.in"", ""B-large.out""); + } +} +" +A20109,"package org.alaoui.googledance; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class App { + public static void main(String[] args) throws NumberFormatException, + IOException { + InputStream is = App.class + .getResourceAsStream(""/org/alaoui/googledance/input/sample.in""); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + + String line; + int lineNumber = 0; + + while ((line = br.readLine()) != null) { + if (lineNumber > 0) { + String[] lineArray = line.split("" ""); + int s = Integer.parseInt(lineArray[1]); + int p = Integer.parseInt(lineArray[2]); + + int okWithoutSurprise = 0; + int okWithSurprise = 0; + + for (int i = 3; i < lineArray.length; i++) { + Dancer dancer = new Dancer(Integer.parseInt(lineArray[i])); + if (dancer.getMaxOrdinaryScore() >= p) { + okWithoutSurprise++; + } else if (dancer.getMaxSurprisingScore() != null + && dancer.getMaxSurprisingScore() >= p) { + okWithSurprise++; + } + } + + int result = okWithoutSurprise + Math.min(okWithSurprise, s); + + System.out.println(""Case #"" + lineNumber + "": "" + result); + + } + lineNumber++; + } + br.close(); + } +} +" +A21436,"package com.google.jam.eaque.stub; + +public class Util { + + private Util() { + } + + + public static long[] stringsToLongs(String[] strings) + { + long[] res = new long[strings.length]; + + for (int i = 0; i < strings.length; i++) { + res[i] = Long.parseLong(strings[i]); + } + + return res; + } +} +" +A21539,"import java.io.PrintWriter; +import java.io.FileWriter; +import java.io.BufferedReader; +import java.io.FileReader; +/** + * Base class to provide a framework for Google Code Jam type of problems and avoid redundant tasks + * @author nitin + */ +public class BaseSolution { + + /** + * Used to write log for debugging + */ + PrintWriter logger; + /** + * to print solution to output.txt + */ + PrintWriter output; + /** + * used to read the problem file + */ + BufferedReader br; + boolean logToConsole = false; + public void setLogToConsole(boolean flag){ + logToConsole = flag; + } + public void start(String probPath) throws Exception { + logger = new PrintWriter(new FileWriter(""debug.txt"")); + output = new PrintWriter(new FileWriter(""output.txt"")); + br = new BufferedReader(new FileReader(probPath)); + init(); + closeAll(); + } + public void logTo(PrintWriter pw){ + logger = pw; + } + public void init() throws Exception{ + int num_test_cases = readInt(); + log(""Total test cases : ""+num_test_cases); + for(int i=0;i { +// +// public int a; +// public int b; +// +// public int compareTo(node a) { +// if (a.b == this.b) { +// return a.a - this.a; +// } else { +// return a.b - this.b; +// } +// } +// +// public node(int a, int b) { +// this.a = a; +// this.b = b; +// } +// } + private void solve() throws IOException { + int n = nextInt(); + for (int x = 0; x < n; x++) { + int count = 0; + int N = nextInt(), s = nextInt(), p = nextInt(); + int[] t = new int[N]; + for (int y = 0; y < N; y++) { + t[y] = nextInt(); + if (t[y] >= p * 3) { + count++; + } else if (t[y] >= (p * 3) - 2 && t[y] != 0) { + count++; + } else if (t[y] >= (p * 3) - 4 && s > 0 && t[y] != 0 ) { + count++; + s--; + } + } + System.out.println(""Case #"" + (int) (x + 1) + "": "" + count); + } + } + + public static void main(String[] args) { + try { + br = new BufferedReader(new InputStreamReader(System.in)); + //br = new BufferedReader(new FileReader(""input.txt"")); + out = new PrintWriter(System.out); + //out = new PrintWriter(new BufferedWriter(new FileWriter(""output.txt""))); + new Main().solve(); + out.close(); + } catch (Throwable e) { + System.out.println(e); + System.exit(239); + } + } + static BufferedReader br; + static StringTokenizer st; + static PrintWriter out; + + static String nextToken() throws IOException { + while (st == null || !st.hasMoreTokens()) { + String line = br.readLine(); + if (line == null) { + return null; + } + st = new StringTokenizer(line); + } + return st.nextToken(); + } + + static int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + static long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + static double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + static int[] nextIntArray(int n) throws IOException { + int[] temp = new int[n]; + for (int x = 0; x < n; x++) { + temp[x] = nextInt(); + } + return temp; + } + + static long[] nextLongArray(int n) throws IOException { + long[] temp = new long[n]; + for (int x = 0; x < n; x++) { + temp[x] = nextLong(); + } + return temp; + } + + static String[] nextArray(int n) throws IOException { + String[] temp = new String[n]; + for (int x = 0; x < n; x++) { + temp[x] = nextToken(); + } + return temp; + } +} +" +A21561,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package codejam12; + +import java.io.*; +import java.util.StringTokenizer; + +/** + * + * @author Mohamed Ibrahim (MIM) + */ +public class Problem_B { + public static void main(String[] args) throws IOException { + + BufferedReader r = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + + int nCases = Integer.parseInt(r.readLine()); + + for (Integer k = 1; k <= nCases; k++) { + int ret=0; + w.print(""Case #"" + k + "": ""); + String line=r.readLine(); + StringTokenizer st = new StringTokenizer(line); + int n= Integer.parseInt(st.nextToken()); + int more= Integer.parseInt(st.nextToken()); + int p= Integer.parseInt(st.nextToken()); + + for (int i = 0; i =p)ret++; + else{ + if(p-div==1 && rem>0)ret++; + else if(p-div==1 && more>0){ + ret++; + more--; + } + else if(p-div==2 && rem==2 && more>0){ + ret++; + more--; + } + /* else if(p-div==2 && more>0 && rem>0){ + ret++; + more--; + }*/ + } + } + + w.println(ret); + } + w.close(); + + + } +} +" +A20519,"import java.util.Scanner; +import java.util.Arrays; +import java.io.*; +public final class problem1 { + static int N; + static int S; + static int p; + + + public static String getResult(int[] input){ + Arrays.sort(input); + + int min; + if(p < 2) + min = p; + else + min = p + (p-2) + (p-2); + + int sur = S; + int total = 0; + for(int i = 0 ; i < input.length ; i++){ + //System.out.print(input[i] + "" "" + min); + //large than min surprise -> will handle this value + if(input[i] >= min && input[i] <= 28){ + if(input[i] % 3 == 2){ //value like 11 + if(sur > 0){ + int large = input[i] / 3 + 2; + if(large >= p){ + total++; + sur--; + } + }else{ + int large = input[i] / 3 + 1; + if(large >= p){ + total++; + } + + } + + }else if(input[i] % 3 == 1){//value like 13 + if(sur > 0){ + int large = input[i] / 3 + 1; + if(large >= p){ + total++; + sur--; + } + }else{ + int large = input[i] / 3 + 1; + if(large >= p){ + total++; + } + + } + + + }else{ // valeu like 15 + + if(sur > 0){ + int large = input[i] / 3 + 1; + if(large >= p){ + total++; + sur--; + } + }else{ + int large = input[i] / 3; + if(large >= p){ + total++; + } + } + + } + + }else if(input[i] > 28){ + total++; + } + + } + //System.out.println(); + return Integer.toString(total); + } + + + + public static void main(String[] args){ + try{ + //Scanner sc = new Scanner(new File(""yo.txt"")); + Scanner sc = new Scanner(new File(""B-large.in"")); + FileWriter fw = new FileWriter(""Large.txt""); + + String tmp = sc.nextLine(); + int step = Integer.valueOf(tmp); + + int counter = 1; + while(sc.hasNextLine()){ + + String s = sc.nextLine(); + Scanner ssc = new Scanner(s); + N = ssc.nextInt(); + S = ssc.nextInt(); + p = ssc.nextInt(); + + int[] arr = new int[N]; + for(int i = 0 ; i < N ; i++) + arr[i] = ssc.nextInt(); + + String xx = getResult(arr); + System.out.println(""Case #"" + counter + "": "" + xx); + + + fw.write(""Case #"" + counter + "": "" + xx); + fw.write(""\n""); + counter++; + if(step < counter) + break; + } + fw.close(); + }catch(Exception e){} + + } + +}" +A22637,"import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class QualB { + + /** + * @param args + */ + public static void main(String[] args)throws Exception { + + Scanner sc = new Scanner(new File(""E:/inp.txt"")); + PrintWriter pr = new PrintWriter(new File(""E:/out.txt"")); + int tc=sc.nextInt(); + int cnt=0; + for(int i=1;i<=tc;i++){ + int n=sc.nextInt(); + int sup=sc.nextInt(); + int p=sc.nextInt(); + cnt=0; + for(int j=1;j<=n;j++){ + int pt=sc.nextInt(); + if(pt==0){ + if(p==0)cnt++; + } + else if(pt!=0 && pt%3==0){ + int t=pt/3; + if(p<=t){ + cnt++; + } + else if (sup>=1 && p-t==1){ + cnt++; + sup--; + } + } + else if(pt!=0 && pt%3!=0){ + int t=pt/3; + if(p<=t+1){ + cnt++; + } + else if (sup>=1 && p-t==2){ + cnt++; + sup--; + } + } + } + pr.printf(""Case #%d: %d%n"", i,cnt); + } + sc.close(); + pr.close(); + + } + +} +" +A22573,"import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class Main { + public Scanner sc; + public Map mapping = new HashMap(); + + public static void main(String[] args) { + Main m = new Main(); + m.start(); + } + + public void start() { + sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int i = 1; i <= t; i++) { + System.out.print(""Case #"" + i + "": ""); + solve(); + } + } + + public void solve() { + int ans = 0; + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + for (int i = 0; i < n; i++) { + int t = sc.nextInt(); + if (calcMax(t, false) >= p) { + ans++; + continue; + } + + if (s > 0 && calcMax(t, true) >= p) { + ans++; + s--; + continue; + } + } + System.out.println(ans); + } + + public int calcMax(int t, boolean suprising) { + + if (t == 0) { + return 0; + } + + int max = 0; + switch (t % 3) { + case (0): + max = t / 3; + if (suprising) { + max++; + } + break; + case (1): + max = (int) t / 3 + 1; + break; + case (2): + max = (int) t / 3 + 1; + if (suprising) { + max++; + } + break; + } + return max; + } +} +" +A21303,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class qualB { + public static void main(String[] args) { + String prblm=""B""; boolean fl=true; + String filein=prblm+""-""+((fl)?""large"":""small"")+"".in.txt""; + String fileout=prblm+""-""+((fl)?""large"":""small"")+"".out.txt""; + try { + BufferedReader fr= new BufferedReader(new FileReader(filein)); + BufferedWriter fw= new BufferedWriter(new FileWriter(fileout)); + String s=fr.readLine(); + int n=Integer.parseInt(s); + for (int i = 1; i <= n; i++) { + s=fr.readLine(); + String[] tok=s.split("" ""); + int N=Integer.parseInt(tok[0]); + int S=Integer.parseInt(tok[1]); + int p=Integer.parseInt(tok[2]); + int ng=0; + int nag=0; + for (int j = 3; j < tok.length; j++) { + int ssc=Integer.parseInt(tok[j]); + int bsc=(ssc+2)/3; + if (bsc>=p) ng++; + else if (bsc==p-1 && ssc%3!=1 && ssc>0) nag++; + } + System.out.println((ng+Math.min(S, nag))); + fw.write(""Case #""+i+"": ""+ (ng+Math.min(S, nag)) +""\n""); + } + fr.close(); + fw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A23008,"import java.io.*; +import java.util.*; +import java.math.*; + +public class Timus implements Runnable { + BufferedReader in; + PrintWriter out; + StringTokenizer st; + Random rnd; + + boolean[][][] canBe; + int[][] d; + int[] scores; + + void precalc() { + canBe = new boolean[30 + 1][10 + 1][2]; + + for(int a = 0; a <= 10; a++) { + for(int b = 0; b <= 10; b++) { + for(int c = 0; c <= 10; c++) { + int sum = a + b + c, max = Math.max(a, Math.max(b, c)); + int maxDiff = Math.max(Math.abs(a - b), Math.max(Math.abs(a - c), Math.abs(b - c))); + int flag = 0; + + if(maxDiff > 2) { + continue; + } else if(maxDiff == 2) { + flag = 1; + } + + for(int lower = 0; lower <= max; lower++) { + canBe[sum][lower][flag] = true; + } + } + } + } + } + + int solveOne(int n, int s, int p) throws IOException { + d = new int[n + 1][s + 1]; + + for(int i = 0; i < d.length; i++) { + Arrays.fill(d[i], Integer.MIN_VALUE / 2); + } + + d[0][0] = 0; + + scores = new int[n]; + + for(int i = 0; i < n; i++) { + scores[i] = nextInt(); + } + + for(int i = 0; i < n; i++) { + int curScore = scores[i]; + + for(int j = 0; j <= s; j++) { + if(canBe[curScore][p][0]) { + d[i + 1][j] = Math.max(d[i + 1][j], d[i][j] + 1); + } else { + d[i + 1][j] = Math.max(d[i + 1][j], d[i][j]); + } + + if(j < s) { + + if(canBe[curScore][p][1]) { + d[i + 1][j + 1] = Math.max(d[i + 1][j + 1], d[i][j] + 1); + } else { + d[i + 1][j + 1] = Math.max(d[i + 1][j + 1], d[i][j]); + } + + + } + } + } + + return d[n][s]; + } + + void solve() throws IOException { + precalc(); + + int tests = nextInt(); + + for(int test = 1; test <= tests; test++) { + out.printf(""Case #%d: %d\n"", test, solveOne(nextInt(), nextInt(), nextInt())); + } + } + + public static void main(String[] args) { + new Timus().run(); + } + + public void run() { + try { + in = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(System.out); + + rnd = new Random(); + + solve(); + + out.close(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(42); + } + } + + String nextToken() throws IOException { + while (st == null || !st.hasMoreTokens()) { + String line = in.readLine(); + + if (line == null) { + return null; + } + + st = new StringTokenizer(line); + } + + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } +}" +A21471,"import java.util.Scanner; +import java.io.File; + +public class dancing +{ + Scanner in; + int p; + int s; + int[] scores; + int minScore; + int minSurpScore; + + public dancing() + { + try + { + in = new Scanner(new File(""input.txt"")); + in.nextLine(); + int count = 1; + + while(in.hasNextLine()) + { + String line = in.nextLine(); + String[] inputCrap = line.split("" ""); + + s = Integer.parseInt(inputCrap[1]); + p = Integer.parseInt(inputCrap[2]); + + scores = new int[Integer.parseInt(inputCrap[0])]; + + for(int i = 0; i < scores.length; i++) + { + scores[i] = Integer.parseInt(inputCrap[i+3]); + } + + minScore = calcMinScore(); + minSurpScore = calcMinSurpScore(); + int total = countScores(); + + System.out.println(""Case #"" + count + "": "" + total); + count++; + } + } + + catch(Exception e) + { + System.out.println(""You messed up.""); + e.printStackTrace(); + } + } + + public int calcMinSurpScore() + { + if(p < 2) + return p; + return 2 * (p-1) + (p-2); + } + + public int calcMinScore() + { + if(p<2) + return p; + return 2 * (p-1) + p; + } + + public int countScores() + { + int count = 0; + + for(int i = 0; i < scores.length; i++) + { + if(scores[i] >= minScore) + count++; + else if(scores[i] >= minSurpScore && s > 0) + { + count++; + s--; + } + } + + return count; + } + + public static void main(String[] args) + { + dancing d = new dancing(); + } + +} +" +A20062,"package cat.aubricoc.codejam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(ClassLoader.getSystemResource(""in.txt"").getFile())); + PrintWriter out = new PrintWriter(new File(""C:/esilog/codejam/dancing-with-the-googlers/src/main/resources/out.txt"")); + int num = Integer.parseInt(in.readLine().trim()); + for (int iter = 0; iter < num; iter++) { + String line = in.readLine(); + Integer sol = calculate(line); + out.println(""Case #"" + (iter + 1) + "": "" + sol); + } + in.close(); + out.flush(); + out.close(); + } + + private static Integer calculate(String line) { + int n = 0; + String[] nums = line.split("" ""); + int numGooglers = Integer.parseInt(nums[0].trim()); + int numSurpises = Integer.parseInt(nums[1].trim()); + int punts = Integer.parseInt(nums[2].trim()); + + for (int iter = 0; iter < numGooglers; iter++) { + int score = Integer.parseInt(nums[3 + iter].trim()); + int mid = score / 3; + int res = score % 3; + if (mid >= punts) { + n++; + } else { + int diff = punts - mid; + if (res == 0 && diff == 1 && numSurpises > 0 && mid > 0) { + n++; + numSurpises--; + } else if (res == 1 && diff == 1) { + n++; + } else if (res == 2) { + if (diff == 1) { + n++; + } else if (diff == 2 && numSurpises > 0) { + n++; + numSurpises--; + } + } + } + } + + return n; + } +} +" +A21012," +package de.ivu.swa.jam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * 0 - 10 Maximal 2 auseinander, also 7..9 + * + */ +public class App2 { + + private static final String INPUT_FILE = ""c:/jam/input2.txt""; + + private static final String OUTPUT_FILE = ""c:/jam/output.txt""; + + public static void main(String[] args) { + List lines = readFile(); + + List result = new ArrayList(); + + for (int i = 1; i < lines.size(); i++) { + result.add(getResult(lines.get(i))); + } + + writeFileAsCase(result); + + // List numbers = new ArrayList(Arrays.asList(29, 20, 8, 18, + // 18, 21)); + // getMaxResults(2, numbers); + } + + private static String getResult(String line) { + // TODO Auto-generated method stub + List numbers = new ArrayList(); + List split = new ArrayList(Arrays.asList(line.split("" ""))); + + int numberOfGooglers = Integer.valueOf(split.get(0)); + int numberOfSurprisingCases = Integer.valueOf(split.get(1)); + int higherThanThis = Integer.valueOf(split.get(2)); + + for (int i = 3; i < split.size(); i++) { + numbers.add(Integer.valueOf(split.get(i))); + } + return getMaxResults(numberOfSurprisingCases, higherThanThis, numbers); + } + + // what is the maximum number of Googlers that could have had a best result of at least p + // you want to know how many Googlers could have gotten a best result of 8 or better + private static String getMaxResults(int numberOfSurprisingCases, + int higherThanThis, List numbers) { + // Collections.sort(numbers); + System.out.println(""------------""); + + System.out.println(""numberOfSurprisingCases: "" + numberOfSurprisingCases + + "" -> "" + numbers); + + int countSuprisingCases = 0; + int countGreaterAs = 0; + + for (Integer integer : numbers) { + TripletResult tripletResult = new TripletResult(integer, higherThanThis); + + if (tripletResult.isHigherWithoutSrprise()) { + countGreaterAs++; + } else if ((countSuprisingCases < numberOfSurprisingCases) + && (tripletResult.canBeHigherWithSuprise())) { + countGreaterAs++; + countSuprisingCases++; + } + } + + System.out.println(""------------""); + return String.valueOf(countGreaterAs); + } + + private static class TripletResult { + + private static final int MIN = 0; + + private static final int MAX = 10; + + public final int result; + + public final int higherThanThis; + + public TripletResult(int result, int higherThanThis) { + System.out.println(""New TripletResult [result="" + result + + "",higherThanThis="" + higherThanThis + ""]""); + + this.result = result; + this.higherThanThis = higherThanThis; + } + + public boolean isHigherWithoutSrprise() { + // 29 - 8 = 21 + // 18 = 2*9; + if (this.result - this.higherThanThis >= (2 * (this.higherThanThis - 1))) { + System.out.println(""isHigherWithoutSrprise == true""); + return true; + } else { + System.out.println(""isHigherWithoutSrprise == false""); + return false; + } + } + + public boolean canBeHigherWithSuprise() { + // + + if (this.result < this.higherThanThis) { + return false; + } + + int restOfOtherTwoNumbers = this.result - this.higherThanThis; + int refNumber = 2 * (this.higherThanThis - 2); + System.out.println(""[restOfOtherTwoNumbers="" + restOfOtherTwoNumbers + + "",refNumber="" + refNumber + ""]""); + if (restOfOtherTwoNumbers >= refNumber) { + System.out.println(""canBeHigher ~~ true""); + return true; + } else { + System.out.println(""canBeHigher == false""); + return false; + } + } + } + + private static void writeFileAsCase(List lines) { + + List caseLines = new ArrayList(); + for (int i = 0; i < lines.size(); i++) { + // +1 to not print the index, but the number of the list-entry + caseLines.add(convertToCase(i + 1, lines.get(i))); + } + + System.out.println(); + for (String string : caseLines) { + System.out.println(string); + + } + writeFile(caseLines); + } + + private static String convertToCase(int i, String string) { + return String.format(""Case #%d: %s"", i, string); + } + + private static void writeFile(List lines) { + + deleteFile(); + + try { + PrintWriter writer = new PrintWriter(new FileWriter(OUTPUT_FILE)); + for (int i = 0; i < lines.size(); i++) { + writer.print(lines.get(i)); + if (i != lines.size() - 1) { + writer.print(""\n""); + } + } + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void deleteFile() { + File file = new File(OUTPUT_FILE); + if (file.exists()) { + file.delete(); + } + } + + private static List readFile() { + + List lines = new ArrayList(); + + try { + BufferedReader in = new BufferedReader(new FileReader(INPUT_FILE)); + String str; + while ((str = in.readLine()) != null) { + lines.add(str); + } + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return lines; + + } +} +" +A22651,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancinggooglers; + +import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author administrator + */ +public class DancingGooglers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + String input = ""c:\\input.in""; + String output = ""c:\\output.txt""; + System.out.println(""Hello World""); + DancingGooglers code1 = new DancingGooglers(); + File in = new File(input); + File out = new File(output); + code1.processOutput(in, out, ""UTF-8""); + } + + public void processOutput(File input, File output, String charSet) { + String temp = """"; + try { + Scanner scanner = new Scanner(input, charSet); + PrintWriter out = new PrintWriter(output); + + int count = 0; + int test_case = 0; + + while (scanner.hasNext()) { + + String test = scanner.nextLine(); + int noOfGooglers; + int surprising_triplets; + int P; + int t[]; + + int surprises_left; + int result; + + if (count == 0) { + test_case = Integer.parseInt(test); + count++; + } else { + String[] line_data = test.split(""\\s""); + noOfGooglers = Integer.parseInt(line_data[0]); + surprising_triplets = Integer.parseInt(line_data[1]); + P = Integer.parseInt(line_data[2]); + t = new int[noOfGooglers]; + + result = 0; + surprises_left = surprising_triplets; + for (int i = 0; i < noOfGooglers; i++) { + t[i] = Integer.parseInt(line_data[i + 3]); + } + for (int i = 0; i < noOfGooglers; i++) { + if (isTGreaterThanP(t[i], P)) { + result++; + } else { + if (surprises_left > 0 && isTGreaterPSurprises(t[i], P)) { + result++; + surprises_left--; + } + } + } + System.out.println(""Case #"" + count + "": "" + result); + if (count == test_case) { + out.print(""Case #"" + count + "": "" + result); + } else { + out.println(""Case #"" + count + "": "" + result); + } + + count++; + + } + temp = temp + ""\n"" + test; + } + out.close(); + scanner.close(); + } catch (Exception e) { + System.out.println(""File read/write error""); + + return; + } + + } + + private boolean isTGreaterThanP(int total, int P) { + int max = (total + 2) / 3; + + if (max >= P) { + return true; + } + return false; + } + + private boolean isTGreaterPSurprises(int total, int P) { + int max = (total + 4) / 3; + if (max >= 10) { + max = 10; + } + if (total == 1) { + max = 1; + } else if (total == 0) { + max = 0; + } + + if (max >= P) { + return true; + } + return false; + } +} +" +A22214,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Scanner; + +/** + * + * @author linlin + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + // TODO code application logic here + File file=new File(""B-large.in""); + FileOutputStream o=new FileOutputStream(""a.txt""); + Scanner s=new Scanner(file); + + int t=Integer.valueOf(s.nextLine()); + for(int i=1;i<=t;i++){ + int out=0; + String line=s.nextLine(); + String[] num=line.split("" ""); + int n=Integer.valueOf(num[0]); + int s1=Integer.valueOf(num[1]); + int p=Integer.valueOf(num[2]); + int high=p*3; + for(int k=0;k<2;k++){ + if(high>0) + high--; + } + int low=high; + for(int k=0;k<2;k++){ + if(low>0) + low--; + } + int m=2; + for(int j=0;j=high) + out++; + else if((score>=low)){ + if(s1>0){ + s1--; + out++; + } + } + + } + + String output=""Case #""+i+"": ""+out+""\r\n""; + o.write(output.getBytes()); + + } + } + +} +" +A22004,"package qualif.problem2; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class ReadWrite { + + public Scanner read(String pathname){ + Scanner scanner = null; + File data = new File(pathname); + try{ + scanner = new Scanner(new FileReader(data)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return scanner; + } + + public void write(String pathname, String[] contents){ + File file = new File(pathname); + try { + file.createNewFile(); + BufferedWriter output = new BufferedWriter(new FileWriter(file)); + try{ + for(int i = 0 ; i < contents.length; i++){ + if(i>0){ + output.newLine(); + } + String content = ""Case #""+(i+1)+"": ""+contents[i]; + output.write( content ); + System.out.println(content); + } + } finally{ + output.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A21991,"import java.io.*; +import java.util.*; + +public class Pilot { + + public static void main(String[] args) { + Pilot my = new Pilot(); + + Calendar cal1 = Calendar.getInstance(); + my.doAll(); + Calendar cal2 = Calendar.getInstance(); + // System.out.println(""\nseconds : "" + (cal2.getTimeInMillis() - + // cal1.getTimeInMillis())/1000); + } + + public void doAll() { + try { + + String out = """"; + + FileInputStream fstream = new FileInputStream(""in.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = """"; + + int glob = Integer.parseInt(strLine = br.readLine()); + + for (int j = 0; j < glob; j++) { + int num = 0; + strLine = br.readLine(); + String[] MAll = strLine.split("" ""); + int N = Integer.parseInt(MAll[0]); + int S = Integer.parseInt(MAll[1]); + int p = Integer.parseInt(MAll[2]); + + Integer[][] T = new Integer[N][3]; + + for (int i = 0; i < N; i++) { + + int k = Integer.parseInt(MAll[3 + i]); + T[i][0] = k; + + // non-suprising + if ((k + 3) % 3 == 0) + T[i][1] = (k + 3) / 3 - 1; + else if ((k + 1) % 3 == 0) + T[i][1] = (k + 1) / 3; + else if ((k + 2) % 3 == 0) + T[i][1] = (k + 2) / 3; + + // suprising + if ((k + 2) % 3 == 0) + T[i][2] = (k + 2) / 3; + else if ((k + 3) % 3 == 0) + T[i][2] = (k + 3) / 3; + else if ((k + 4) % 3 == 0) + T[i][2] = (k + 4) / 3; + + if (T[i][2] == 1) + T[i][2] = -100; + + if (T[i][1] < p) + T[i][1] = -100; + + if (T[i][2] < p) + T[i][2] = -100; + } + + Arrays.sort(T, new Comparator() { + @Override + public int compare(Integer[] entry1, Integer[] entry2) { + if (entry2[1] < 0 && entry2[2] < 0 + && (entry1[1] < 0 || entry1[2] < 0)) + return -1; + else + return 0; + } + }); + + int bo = 0, su = 0, no = 0; + + for (int i = 0; i < N; i++) { + if (T[i][1] >= 0 && T[i][2] >= 0) + bo++; + else if (T[i][1] >= 0 && T[i][2] < 0) + no++; + else if (T[i][1] < 0 && T[i][2] >= 0) + su++; + } + + //System.out.println(""both= "" + bo + ""\nnormal= "" + no + ""\nsuprising= "" + su); + + if (S >= su) { + num += su; + S -= su; + su = 0; + } else { + num += S; + su -= S; + S = 0; + } + + if (S == 0) { + num += no + bo; + } else { + num += no + bo; + } + + for (int i = 0; i < N; i++) { + //System.out.println(T[i][0] + "" "" + T[i][1] + "" "" + T[i][2]); + } + + out += (""Case #"" + (j + 1) + "": "" + num + ""\n""); + } + in.close(); + out = out.trim(); + + Writer output = null; + File file = new File(""out.out""); + output = new BufferedWriter(new FileWriter(file)); + output.write(out); + output.close(); + + System.out.print(out); + + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + + } + } +} +" +A23047,"import java.util.Arrays; +import java.util.Scanner; + +/** + * @author Dmitry Levshunov (levshunov.d@gmail.com) + */ +public class TaskB { + private static final int INF = 1000 * 1000 * 1000; + + private static final int[] BEST_NON_SURPRISING = new int[31]; + private static final int[] BEST_SURPRISING = new int[31]; + + private static int n; + private static int p; + private static int[] scores = new int[100]; + private static int[][] dp = new int[100][101]; + + public static void main(String[] args) throws Exception { + init(); + + Scanner scanner = new Scanner(System.in); + + int tests = Integer.parseInt(scanner.nextLine().trim()); + + for (int test = 1; test <= tests; test++) { + n = scanner.nextInt(); + int s = scanner.nextInt(); + p = scanner.nextInt(); + + for (int i = 0; i < n; i++) { + scores[i] = scanner.nextInt(); + } + + for (int i = 0; i < n; i++) { + Arrays.fill(dp[i], -1); + } + + System.out.printf(""Case #%d: %s"", test, get(0, s)); + System.out.println(); + } + + scanner.close(); + } + + private static void init() { + for (int i1 = 0; i1 <= 10; i1++) { + for (int i2 = i1; i2 <= 10 && i2 - i1 <= 2; i2++) { + for (int i3 = i2; i3 <= 10 && i3 - i1 <= 2; i3++) { + int sum = i1 + i2 + i3; + + if (i3 - i1 == 2) { + BEST_SURPRISING[sum] = Math.max(BEST_SURPRISING[sum], i3); + } else { + BEST_NON_SURPRISING[sum] = Math.max(BEST_NON_SURPRISING[sum], i3); + } + } + } + } + } + + private static int get(int pos, int s) { + if (s < 0) { + return -INF; + } + + if (pos == n) { + return s == 0 ? 0 : -INF; + } + + if (dp[pos][s] != -1) { + return dp[pos][s]; + } + + int bestNonSurprising = BEST_NON_SURPRISING[scores[pos]]; + int bestSurprising = BEST_SURPRISING[scores[pos]]; + + int result = get(pos + 1, s) + (bestNonSurprising >= p ? 1 : 0); + if (bestSurprising != -1) { + result = Math.max(result, get(pos + 1, s - 1) + (bestSurprising >= p ? 1 : 0)); + } + + return dp[pos][s] = result; + } +} +" +A21579,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.common; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +/** + * + * @author jim + */ +public class Output { + + private final String[] data; + + public Output(String[] data) { + this.data = data; + } + + public Output(ArrayList data) { + this(data.toArray(new String[0])); + } + + public int size() { + return data.length; + } + + public String get(int i) { + StringBuilder sb = new StringBuilder(data[i].length() + 10); + sb.append(""Case #""); + sb.append(i + 1); + sb.append("": ""); + sb.append(data[i]); + return sb.toString(); + } + + public void export(String fileName) { + if (fileName == null) + print(); + else { + try { + save(fileName); + } + catch (IOException ioe) { + System.out.println(ioe.getMessage()); + ioe.printStackTrace(); + } + } + } + + private void print() { + for (int i = 0; i < size(); i++) + System.out.println(get(i)); + } + + private void save(String fileName) throws IOException { + FileWriter fw = new FileWriter(fileName); + PrintWriter pw = new PrintWriter(fw); + for (int i = 0; i < size(); i++) { + pw.println(get(i)); + } + pw.flush(); + pw.close(); + fw.close(); + } + +} +" +A22933,"/* +choochootrain +Google Code Jam 2012 +*/ +import java.io.*; +import java.util.*; + +class ProblemB +{ + public static void main (String [] args) throws IOException + { + String filename = ""B-large""; + BufferedReader f = new BufferedReader(new FileReader(filename + "".in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename + "".out""))); + int numberOfTests = Integer.parseInt(f.readLine()); + for(int n = 1; n <= numberOfTests; n++) + { + StringTokenizer st = new StringTokenizer(f.readLine()); + int numPeople = Integer.parseInt(st.nextToken()); + int numSurprising = Integer.parseInt(st.nextToken()); + int threshold = Integer.parseInt(st.nextToken()); + ArrayList points = new ArrayList(numPeople); + for(int i = 0; i < numPeople; i++) { + points.add(Integer.parseInt(st.nextToken())); + } + + int num = 0; + for(int i = 0; i < points.size(); i++) { + if(max(makeNormal(points.get(i))) >= threshold) { + num++; + points.remove(i); + i--; + } + } + + for(int i = 0; i < points.size() && numSurprising > 0; i++) { + if(max(makeSurprising(points.get(i))) >= threshold) { + num++; + numSurprising--; + points.remove(i); + i--; + } + } + String solution = """" + num; + out.println(""Case #"" + n + "": "" + solution); + } + out.close(); + System.exit(0); + } + + private static int max(int[] nums) { + if (Math.min(Math.min(nums[0], nums[1]), nums[2]) >= 0) + return Math.max(Math.max(nums[0], nums[1]), nums[2]); + else + return -1; + } + + private static int[] make (int a, int b, int c) { + int[] arr = new int[3]; + arr[0] = a; + arr[1] = b; + arr[2] = c; + return arr; + } + + private static int[] makeNormal(int total) { + if (total % 3 == 0) + return make(total/3, total/3, total/3); + else if (total % 3 == 1) + return make(total/3, total/3, total/3 + 1); + else + return make(total/3, total/3 + 1, total/3 + 1); + } + + private static int[] makeSurprising(int total) { + if (total % 3 == 0) + return make(total/3 - 1, total/3, total/3 + 1); + else if (total % 3 == 1) + return make(total/3 - 1, total/3 + 1, total/3 + 1); + else + return make(total/3, total/3, total/3 + 2); + } +} +" +A20657,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class Main { + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + // TODO Auto-generated method stub + + File fi = new File(""D:\\B-small-attempt0.in""); + Scanner in=new Scanner(fi); + int c=in.nextInt(); + int goo=0; + int sup=0; + int p=0; + int ans=0; + for(int co=1;co<=c;co++){ + goo=in.nextInt(); + sup=in.nextInt(); + p=in.nextInt(); + int base=0; + int score=0; + int z[] ={0,0,0}; + for(int i=0;i=p){ + ans++; + } + else + { + if(sup>0 && base >0 && (base+1)>=p){ + ans++; + sup--; + } + + } + break; + } + case 1: + { + if(base >=p||(base+1)>=p){ + ans++; + } + else{ + if(sup>0&&(base+1)>=p){ + ans++; + sup--; + } + } + + + break; + } + case 2:{ + if ((base + 1) >= p|| base >= p){ + ans++; + } else { + if(sup>0&&(base+2)>=p){ + ans++; + sup--; + } + } + + + + + break; + + } } + }System.out.println(""Case #""+co+"": ""+ans); +ans=0; + } + } + } + + +" +A21004,"package fixjava; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Set; + +/** + * Simple multimap class. + + MultiMap map = MultiMapKeyToList.make(); + map.put(""a"", ""x""); + map.put(""a"", ""x""); + map.put(""a"", ""y""); + map.put(""b"", ""z""); + System.out.println(Join.joinRecursive(map.entrySet(), "", "", ""["", ""]"")); + + + * + * @author luke + */ +public class MultiMapKeyToList { + + HashMap> map = new HashMap>(); + + public static MultiMapKeyToList make() { + return new MultiMapKeyToList(); + } + + public void put(S key, T value) { + ArrayList list = map.get(key); + if (list == null) { + list = new ArrayList(); + map.put(key, list); + } + list.add(value); + } + + public ArrayList get(S key) { + return map.get(key); + } + + public boolean containsKey(S key) { + return map.containsKey(key); + } + + public int sizeKeys() { + return map.size(); + } + + public HashSet valuesUnion() { + HashSet result = new HashSet<>(); + for (Entry> ent : map.entrySet()) + for (T val : ent.getValue()) + result.add(val); + return result; + } + + public Set>> entrySet() { + return map.entrySet(); + } + + public HashMap> getRawMap() { + return map; + } + + public ArrayList>> getRawMapAsList() { + ArrayList>> result = new ArrayList>>(); + for (Entry> ent : map.entrySet()) + result.add(Pair.make(ent.getKey(), ent.getValue())); + return result; + } + + public void putAll(S key, Iterable values) { + boolean putSomething = false; + for (T val : values) { + put(key, val); + putSomething = true; + } + if (!putSomething && !map.containsKey(key)) + // If putting an empty collection, need to create an empty set at the key + map.put(key, new ArrayList()); + } + + public void putAll(S key, T[] values) { + if (values.length == 0 && !map.containsKey(key)) + // If putting an empty collection, need to create an empty set at the key + map.put(key, new ArrayList()); + else + for (T val : values) + put(key, val); + } + + /** Invert the mapping */ + public MultiMapKeyToList invert() { + MultiMapKeyToList inv = new MultiMapKeyToList(); + for (Entry> ent : map.entrySet()) { + S s = ent.getKey(); + for (T t : ent.getValue()) + inv.put(t, s); + } + return inv; + } + + public ArrayList>> toList() { + ArrayList>> result = new ArrayList>>(); + for (Entry> ent : map.entrySet()) + result.add(Pair.make(ent.getKey(), ent.getValue())); + return result; + } + + /** Write out to a TSV file */ + public void writeOutToFile(String tsvFile) throws IOException { + PrintWriter writer = new PrintWriter(tsvFile); + for (Entry> ent : map.entrySet()) { + S key = ent.getKey(); + StringBuilder buf = new StringBuilder(); + buf.append(key); + for (T val : ent.getValue()) + buf.append(""\t"" + val); + writer.println(buf.toString()); + } + writer.close(); + } + + /** Read in a String->String map from a TSV file */ + public static MultiMapKeyToList readFromFile(String tsvFile) throws IOException { + MultiMapKeyToList map = new MultiMapKeyToList(); + for (String line : new FileLineIterator(tsvFile)) { + String[] parts = Split.split(line, ""\t""); + String key = parts[0]; + for (int i = 1; i < parts.length; i++) + map.put(key, parts[i]); + } + return map; + } + +} +" +A21677,"import java.io.*; +import java.util.*; + +public class Problem2 +{ + static ArrayList scores; + public static void main(String args[]) + { + try + { + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + String line; + int total; + int i = 0, cases; + Scanner sc; + int number, surprising, minpoints; + while ((line = br.readLine()) != null) + { + if(i == 0) + { + total = Integer.parseInt(line); + i = 1; + continue; + } + sc = new Scanner(line); + scores = new ArrayList(); + number = sc.nextInt(); + surprising = sc.nextInt(); + minpoints = sc.nextInt(); + cases = 0; + for(int j = 0; j < number; j++) + { + scores.add(sc.nextInt()); + } + for(int score : scores) + { + int base = (int)(score/3); + + switch(score%3) + { + case 0: + { + if(base>=minpoints) + { + cases++; + } + else if(surprising > 0 && base > 0 && base + 1 >= minpoints) + { + cases++; + surprising--; + } + break; + } + case 1: + { + if(base>=minpoints | base + 1 >= minpoints) + { + cases++; + } + else if(surprising > 0 && base + 1 >= minpoints) + { + cases++; + surprising--; + } + break; + } + case 2: + { + if(base + 1>= minpoints | base>=minpoints) + { + cases++; + } + else if(surprising > 0 && base + 2 >= minpoints) + { + cases++; + surprising--; + } + break; + } + } + } + System.out.println(""Case #""+i+"": ""+cases); + write(""Case #""+i+"": ""+cases); + i++; + } + in.close(); + }catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + } + + + public static void write(String text) + { + try + { + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""Problem2Large.out""), true)); + bw.write(text); + bw.newLine(); + bw.close(); + }catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } +}" +A22779,"package google.solver; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; + +public class ProblemPackageCreator implements ChallengeConstants{ + + private final String packageName; + private String directoryName; + private String challengeDef; + private String readerName; + private String challengeName; + private String packagePath; + + + ProblemPackageCreator(String packageName){ + this.packageName = packageName; + packagePath = ""google.contest.""+packageName; + directoryName = BASE_DIR+DELIMITER+packageName; + challengeDef = BASE_DIR+DELIMITER+packageName+DELIMITER+CHALLENGE_DEFINITION; + readerName = packageName.substring(0,1).toUpperCase()+packageName.substring(1)+""Reader""; + challengeName = packageName.substring(0,1).toUpperCase()+packageName.substring(1)+""Challenge""; + } + + private void create() { + try{ + createDirectory(); + createTestIn(); + createChallengeDefinition2(); + createReader(); + createChallenge(); + } + catch(Exception e){ + throw new RuntimeException(e); + } + } + + private void createTestIn() { + writeToPath(TEST_IN, """"); + + } + + private void createChallenge() { + String def =""package ""+packagePath+"";\n\n""+ + ""import google.loader.Challenge;\n""+ + ""import google.problems.AbstractChallenge;\n\n""+ + ""public class ""+challengeName+"" extends AbstractChallenge implements Challenge {\n\n""+ + ""public ""+challengeName+""(int number) {\n""+ + ""super(number);\n""+ + ""setResult(\""\"");\n""+ + ""}\n""+ + ""}\n""; + writeJava(challengeName, def); + } + + private void createReader() { + String def = ""package ""+packagePath+"";\n\n""+ + ""import google.loader.Challenge;\n""+ + ""import google.problems.AbstractReader;\n\n""+ + ""public class ""+readerName+"" extends AbstractReader {\n \n""+ + ""@Override\n""+ + ""protected Challenge createChallenge(int number) {\n""+ + ""int theLine = getActualLine();\n""+ + ""String[] lines = getLines();\n""+ + ""int value = Integer.parseInt(getLines()[theLine]);\n""+ + challengeName+"" chal = new ""+challengeName+""(number);\n""+ + ""setActualLine(theLine+1);\n""+ + ""return chal;\n""+ + ""}\n""+ + ""\n""+ + ""}\n""; + + writeJava(readerName, def); + } + + private void writeToPath(String fileName, String text){ + write(directoryName+DELIMITER+fileName, text); + } + + private void writeJava(String baseName, String text) { + writeToPath(baseName+"".java"", text); + } + + private void createChallengeDefinition() { + String def = ""fileName=""+TEST_IN+""\n""+ + ""# fileName=A-small-practice.in\n""+ + ""# fileName=A-large-practice.in\n""+ + ""# fileName=B-small-practice.in\n""+ + ""# fileName=B-large-practice.in\n""+ + ""# fileName=C-small-practice.in\n""+ + ""# fileName=C-large-practice.in\n""+ + ""readerClassName=""+packagePath+"".""+readerName; + write(challengeDef, def); + } + + private void createChallengeDefinition2() { + String def = ""fileName=""+TEST_IN+""\n""+ + ""# fileName=""+packageName+""-small-practice.in\n""+ + ""# fileName=""+packageName+""-large-practice.in\n""+ + ""readerClassName=""+packagePath+"".""+readerName; + write(challengeDef, def); + } + + private void createDirectory() throws Exception{ + File file = new File(directoryName); + if(! file.exists()){ + file.mkdir(); + }else{ + throw new RuntimeException(""alreadyExisting""); + } + } + + public static void main(String[] args) { + String packageName =CHALLENGE_NAME; + ProblemPackageCreator creator = new ProblemPackageCreator(""A""); + creator.create(); + creator = new ProblemPackageCreator(""B""); + creator.create(); + creator = new ProblemPackageCreator(""C""); + creator.create(); + } + + public static void write(String aFileName, String text) { + try{ + FileWriter fstream = new FileWriter(aFileName); + BufferedWriter out = new BufferedWriter(fstream); + out.write(text); + out.close(); + }catch (Exception e){ + throw new RuntimeException(e); + } + } + + +} +" +A20037,"import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; + + +public class DancingGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + + BufferedReader inFile = null; + try { + inFile = new BufferedReader( + new InputStreamReader( + new BufferedInputStream(new FileInputStream(""B-large.in"")), + ""UTF-8"" + ) + ); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + int numCases = 0; + List goodDancersInCase = new ArrayList(); + try { + numCases = Integer.parseInt(inFile.readLine()); + for (int caseNum = 0; caseNum < numCases; caseNum++) { + + String[] words; + words = inFile.readLine().split("" ""); + List inputNums = new ArrayList(); + for (String word : words) { + inputNums.add(Integer.parseInt(word)); + } + + int nDancers = inputNums.remove(0); + int nSurprisingTriplets = inputNums.remove(0); + int bestResultLimit = inputNums.remove(0); + List totalPoints = new ArrayList(inputNums); + + int maxDancersAboveResultLimit = 0; + for (Integer dancerTotalPoints : totalPoints) { + if((dancerTotalPoints + 2) >= 3 * bestResultLimit) { + maxDancersAboveResultLimit += 1; + } else if ((dancerTotalPoints + 4) >= 3 * bestResultLimit && + nSurprisingTriplets > 0 && + dancerTotalPoints >= bestResultLimit + ) { + maxDancersAboveResultLimit += 1; + nSurprisingTriplets--; + } + } + goodDancersInCase.add(maxDancersAboveResultLimit); + } + } catch (IOException e) { + e.printStackTrace(); + } + + try { + BufferedWriter bw = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream(""B-large.out.txt""), ""UTF-8"" + ) + ); + + for (int caseNum = 0; caseNum < numCases; caseNum++) { + bw.append(""Case #"" + (caseNum+1) + "": "" + goodDancersInCase.get(caseNum)); + bw.newLine(); + } + bw.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} +" +A21544,"package com.jp.common; + +import com.codejam.two12.tongue.Googlerese; + +public class ExecutorApp { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + // String inputFileName = ""/Users/joekumar/Documents/workspace/CodeJam/src/com/jp/data/sample_input.txt""; + // String outputFileName = ""/Users/joekumar/Documents/workspace/CodeJam/src/com/jp/data/sample_output.txt""; + String inputFileName = ""/Users/joekumar/Downloads/B-large.in""; + String outputFileName = ""/Users/joekumar/Desktop/output/sample_output.txt""; + InputOutputProcessor inputOutputProcessor = new InputOutputProcessor(); + inputOutputProcessor.initializeInput(inputFileName); + int numberOfCases = inputOutputProcessor.getNumberOfCases(); + + String[] resultArray = new String[numberOfCases]; + inputOutputProcessor.setDoesInputHaveDataSetLines(false); + inputOutputProcessor.setNumberOfDataSetLines(1); + + + // Googlerese.init(); + + for (int i = 1; i <= numberOfCases; i++) { + + try { + String[] dataSet = inputOutputProcessor.getDataSet(); + + /* BotTrust botTrust = new BotTrust(); + int result = botTrust.findRequiredSeconds(dataSet); + String resultCase = ""Case #""+ i + "": ""+ result; + resultArray[i-1] = resultCase; + System.out.println(resultCase);*/ + Puzzle puzzle = PuzzleFactory.getPuzzleSolution(""GooglerDance""); + String[] result = puzzle.solve(dataSet); + String resultCase = ""Case #""+ i + "": ""+ result[0] ; + System.out.println(resultCase); + resultArray[i-1] = resultCase; + + } + + catch (Exception exp) { + exp.printStackTrace(); + inputOutputProcessor.closeScanner(); + } + + } + + inputOutputProcessor.closeScanner(); + inputOutputProcessor.writeOutput(outputFileName, resultArray); + + } + +} +" +A20013,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class Dancing { + + private static final String fileInName = ""file.in""; + private static final String fileOutname = ""file.out""; + + + + public static void main(String[] args) throws IOException{ + + System.out.println(""Init""); + + FileWriter fw = new FileWriter(fileOutname); + BufferedReader br = new BufferedReader(new FileReader(fileInName)); + + + int numCases = Integer.parseInt(br.readLine()); + System.out.println(""Num cases: "" + numCases); + + for(int numCase = 1; numCase <= numCases; numCase++){ + + String[] caseIn = br.readLine().split("" ""); + + int numG = Integer.parseInt(caseIn[0]); + int numS = Integer.parseInt(caseIn[1]); + int pScore = Integer.parseInt(caseIn[2]); + + System.out.println(""\tNumG: "" + numG + ""\n\tNumS: "" + numS + ""\n\tpScore: "" + pScore); + + int[] totalPoints = new int[caseIn.length - 3]; + + for (int i = 0; i < totalPoints.length; i++){ + totalPoints[i] = Integer.parseInt(caseIn[i + 3]); + } + + for(int i = 0; i < totalPoints.length; i++){ + System.out.println(""\t\ti: "" + totalPoints[i] + "":: Triplet: "" + printArray(calculateTriplet(totalPoints[i]))); + } + + int numGBestp = 0; //Result + + for(int i = 0; i < totalPoints.length; i++){ + + int[] t = calculateTriplet(totalPoints[i]); + + if(withNormalScore(pScore, t)){ + numGBestp++; + }else if(numS > 0 && withSorpriseScore(pScore, t)){ + numS--; + numGBestp++; + } + + } + + fw.write(""Case #"" + numCase +"": "" + numGBestp +""\n""); + + System.out.println(""\tRes: "" + numGBestp); + System.out.println(""--------------""); + + } + + br.close(); + fw.close(); + + } + + private static int[] calculateTriplet(int score){ + + int[] res = new int[3]; + + int baseScore = score / 3; + + int modScore = score % 3; + + for(int i = 0; i < res.length; i++){ + + res[i] = baseScore; + + if(modScore > 0){ + res[i] = res[i] + 1; + modScore--; + } + + } + return res; + } + + private static boolean withNormalScore(int target, int[] triplet){ + return triplet[0] >= target; + } + + private static boolean withSorpriseScore(int target, int[] triplet){ + + int a = (triplet[0] + 1); + + return a >= target && (a - triplet[1]) < 3 && (triplet[2] - 1) >= 0; + } + + private static String printArray(int[] res){ + String s = ""[""; + + for(int i = 0; i < res.length; i++){ + s+="" "" + res[i]; + if(i < res.length - 1){ + s+="",""; + } + } + + return s+""]""; + } +} +" +A20852,"import java.util.ArrayList; +import java.util.List; + + +public class Dancers implements Solver { + int N; + int S; + int p; + List dan = new ArrayList(); + + + public Dancers(List lineas) { + String[] cosa = lineas.get(0).split("" ""); + N=Integer.parseInt(cosa[0]); + S=Integer.parseInt(cosa[1]); + p=Integer.parseInt(cosa[2]); + for (int i=0; i=p+p-1+p-1 && dan.get(i)>=p){ + conta++; + } + else if(dan.get(i)>=p+p-2+p-2 && dan.get(i)>=p && S>0){ + conta++; + S--; + } + } + // TODO Auto-generated method stub + return conta+""""; + } + +} +" +A20167,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class GCJ2012QB { + static int[] a = new int[100]; + + public static void main(String[] args) throws Exception { + BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); + PrintWriter pw = new PrintWriter(System.out); + StringTokenizer st; + int t = Integer.parseInt(r.readLine()); + int n, s, p, a, result, best; + for (int i = 1; i <= t; i++) { + st = new StringTokenizer(r.readLine()); + n = Integer.parseInt(st.nextToken()); + s = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + result = 0; + for (int j = 0; j < n; j++) { + a = Integer.parseInt(st.nextToken()); + best = maxBest(a); + if (best >= p) { + result++; + } else { + if (s > 0) { + best = maxBestWithSurprise(a); + if (best >= p) { + result++; + s--; + } + } + } + } + pw.println(""Case #"" + i + "": "" + result); + } + pw.flush(); + } + + private static int maxBestWithSurprise(int a) { + if (a == 0) { + return 0; + } else { + return (a + 4) / 3; + } + } + + private static int maxBest(int a) { + return (a + 2) / 3; + } +} +" +A21806,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Ari + */ +public class ProblemB { + static String in = ""src/b.in""; + static String out = ""src/b.out""; + + public static void main(String[] args) throws FileNotFoundException, IOException { + Scanner scan = new Scanner(new File(in)); + BufferedWriter write = new BufferedWriter(new FileWriter(out)); + int numlines = scan.nextInt(); + int peeps; + int surprises; + int minScore; + int minTotal; + int minSurpriseTotal; + int answer; + int totalScore; + for(int x = 0; x < numlines; x++) { + write.write(""Case #"" + (x+1) + "": ""); + answer = 0; + peeps = scan.nextInt(); + surprises = scan.nextInt(); + minScore = scan.nextInt(); + minTotal = minScore*3 - 2; + minSurpriseTotal = minTotal - 2; + + if(minTotal < 0) { + minTotal = 0; + //minSurpriseTotal = 0; + } + else if(minSurpriseTotal < 0) { + minSurpriseTotal = 1; + } + + for(int y = 0; y < peeps; y++) { + totalScore = scan.nextInt(); + if(totalScore >= minTotal) { + answer++; + } + else if(totalScore >= minSurpriseTotal && surprises > 0) { + surprises--; + answer++; + } + } + + write.write("""" + answer); + write.write('\n'); + } + scan.close(); + write.close(); + } +} +" +A21153,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + + +public class ProblemB { + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + // TODO Auto-generated method stub + Scanner sc = new Scanner(new File(args[0])); + int numberOfLines = Integer.parseInt(sc.nextLine()); + Scanner lineScan; + int numberOfPeople =0, numberOfSurprising = 0, bestRes = 0; + ArrayList> list = new ArrayList>(); + ArrayList triple; + + int score, count = 0; + String line = "" ""; + + for (int i=0; i(); + if (score % 3 == 0) + { + + if (score/3 < bestRes && score/3 + 1 >= bestRes && score > 0 && numberOfSurprising > 0) + { + triple.add(score/3 -1); + triple.add(score/3); + triple.add(score/3 +1); + numberOfSurprising --; + } + else + { + for (int k = 0; k<3; k++) + triple.add(score/3); + } + list.add(triple); + } + else + { + double mean = (double) score /3; + double boundary = score/3 +0.5; + if (mean > boundary ) + { + if (score/3 + 2 == bestRes && numberOfSurprising >0) + { + triple.add(score/3); + triple.add(score/3); + triple.add(score/3 +2); + numberOfSurprising--; + } + else + { + triple.add(score/3); + triple.add(score/3 +1); + triple.add(score/3 + 1); + } + + } + else + { + triple.add(score/3); + triple.add(score/3); + triple.add(score/3 +1); + } + + list.add(triple); + + + } + } + + //System.out.println(""Line "" + line); + for (ArrayList tri: list) + { + if (tri.get(tri.size()-1) >= bestRes) + count++; + + } + + System.out.printf(""Case #%d: %d\n"", i+1, count); + + list.clear(); + + } + } + +} +" +A21997,"import java.io.*; + + +public class B +{ + public static void main(String args[]) throws IOException + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + String[] line; + int N,S,p; + int[][] tuple = new int[1000][3]; + int[][] stuple = new int[1000][3]; + int count = 0; + int scount = 0; + + for(int i=10;i>=0;i--) + { + for(int j=i-2;j<=i+2;j++) + { + if(j<0 || j>10) continue; + for(int k=i-2;k<=i+2;k++) + { + if(k<0 || k>10) continue; + if(j-k >2 || k-j > 2) + continue; + int a = (i-j > 0) ? i-j : j-i; + int b = (i-k > 0) ? i-k : k-i; + int c = (k-j > 0) ? k-j : j-k; + + if(a==2 || b==2 || c==2) + { + stuple[scount][0] = i; + stuple[scount][1] = j; + stuple[scount++][2] = k; + continue; + } + tuple[count][0] = i; + tuple[count][1] = j; + tuple[count++][2] = k; + } + } + } + + + for(int i=1;i<=T;i++) + { + line = br.readLine().split(""\\W+""); + N = Integer.parseInt(line[0]); + S = Integer.parseInt(line[1]); + p = Integer.parseInt(line[2]); + int[] score = new int[N]; + + for(int j=0;j= p || tuple[k][1] >= p || tuple[k][2] >= p) + { + found = true; + ret++; + break; + } + } + } + if(!found && S!=0) + { + for(int k=0;k= p || stuple[k][1] >= p || stuple[k][2] >= p) + { + found = true; + S--; + ret++; + break; + } + } + } + } + } + + System.out.println(""Case #""+i+"": ""+ret); + } + } +} +" +A22646,"package cj2; + +import dancingwiththegooglers.ScoreAnalyzer; +import edu.uwec.cs.genacje.codejam.speakingintongues.GooglereseTranslator; +import edu.uwec.cs.genacje.codejam.utilities.objects.IoMgr; +import edu.uwec.cs.genacje.codejam.utilities.objects.StringFormatter; + +/** + * + * @author James Genac + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + long totalTime = System.currentTimeMillis(); + solveDancingWithTheGooglers(); + System.out.println(""Total time to solve: "" + (System.currentTimeMillis() - totalTime) + "" ms.""); + + } + + private static void solveDancingWithTheGooglers() { + IoMgr io = new IoMgr(""B-large.in""); + + int linecount = 1; + long start = 0; + io.rls(); // eat first line + + ScoreAnalyzer scoreAnalyzer = null; + + while (io.ready()) { + scoreAnalyzer = new ScoreAnalyzer(io.rlia("" "")); + + + start = System.currentTimeMillis(); + + io.wlf(""Case #""+linecount+"": "" + scoreAnalyzer.getMaxNumOfHighScoringDancers()); + System.out.println(""Case "" + linecount + "" took "" + (System.currentTimeMillis()-start) + "" ms.""); + linecount++; + } + + + io.close(); + } + + private static void solveSpeakingInTongues() { + IoMgr io = new IoMgr(""A-small-attempt0.in""); + + int linecount = 1; + long start = 0; + io.rls(); // eat first line + String in = """"; + long totalTime = System.currentTimeMillis(); + + while (io.ready()) { + in = io.rls(); + + + start = System.currentTimeMillis(); + + io.wlf(""Case #""+linecount+"": "" + GooglereseTranslator.translateString(in)); + System.out.println(""Case "" + linecount + "" took "" + (System.currentTimeMillis()-start) + "" ms.""); + linecount++; + } + + + io.close(); + } +} + + +" +A22738,"package er.dream.codejam.helpers; + +import java.io.File; +import java.util.List; + +public abstract class ProblemSolver { + + protected FileHandler fileHandler = new FileHandler(); + + protected abstract List handleInput(); + + public void execute(){ + File[] files = fileHandler.listFiles(); + + for(File f : files){ + long start = System.currentTimeMillis(); + fileHandler.loadFile(f); + List results = handleInput(); + fileHandler.writeOutput(results); + fileHandler.closeConnection(); + long stop = System.currentTimeMillis(); + System.out.println(""File ""+f.getName()+"" took me ""+(stop-start)+""ms""); + } + } + +} +" +A20130,"import java.awt.Point; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; + +public class Prob3 { + + private static String doAlgorithm(String[] lines) { + StringBuilder ans = new StringBuilder(); + int numCase = Integer.parseInt(lines[0]); + for (int i = 0; i < numCase; i++) + ans.append(""Case #"" + (i + 1) + "": "") + .append(doActualAlgorithm(lines[i + 1])).append('\n'); + return ans.toString(); + } + + static String doActualAlgorithm(String s) { + String[] separated = s.trim().split("" ""); + int nGoog = Integer.parseInt(separated[0]), nStar = Integer + .parseInt(separated[1]), treshold = Integer + .parseInt(separated[2]); + int[] data = new int[nGoog]; + int couldHaveBeenIncreased = 0; + int passTreshold = 0; + for (int i = 0; i < data.length; i++) + data[i] = Integer.parseInt(separated[i + 3]); + // start here + for (int i = 0; i < data.length; i++) { + int current = data[i]; + int maxValue, maxValueWithStar; + if (current % 3 == 0) { + maxValue = current / 3; + maxValueWithStar = current / 3 + 1; + if(current==0) + maxValueWithStar=0; + } else if (current % 3 == 1) { + maxValue = current / 3 + 1; + maxValueWithStar = current / 3 + 1; + + } else { + maxValue = current / 3 + 1; + maxValueWithStar = current / 3 + 2; + } + if (maxValue >= treshold) + passTreshold++; + else if (maxValueWithStar >= treshold) + couldHaveBeenIncreased++; + } + int ans = passTreshold + Math.min(couldHaveBeenIncreased, nStar); + return ans + """"; + } + + private static void initAlgorithm() { + + } + + public static void main(String[] args) throws IOException { + File inputFile = new File(""input.txt""); + File outputFile = new File(""output.txt""); + FileReader reader = new FileReader(inputFile); + BufferedReader br = new BufferedReader(reader); + String line; + ArrayList input = new ArrayList(); + while ((line = br.readLine()) != null) { + input.add(line); + } + br.close(); + initAlgorithm(); + String output = doAlgorithm(input.toArray(new String[0])); + FileWriter writer = new FileWriter(outputFile); + writer.write(output.trim()); + writer.close(); + + } + + enum NullableBoolean { + TRUE, FALSE, NULL; + } + + class Triplet { + final int[] value; + + public Triplet(int x, int y, int z) { + value = new int[3]; + value[0] = x; + value[1] = y; + value[2] = z; + Arrays.sort(value); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Triplet) { + return Arrays.equals(value, ((Triplet) obj).value); + } + return super.equals(obj); + } + } +} +" +A21500,"import java.io.*; +import java.util.*; + +public class Launcher { + static int t, n, s, p, tcount, ncount, scount, pcount; + static int a, b, num, ans; + + + public static void main(String[] args){ + String c; + int i,j; + + + try { + FileInputStream fin = new FileInputStream (""input.txt""); + System.out.println(""Input file stream created""); + Scanner sc = new Scanner(fin); + System.out.println(""Scanner created""); + + FileOutputStream fout = new FileOutputStream (""output.txt""); + DataOutputStream dout = new DataOutputStream (fout); + + t=sc.nextInt(); + tcount=0; + + + while (tcount0){ + ans++; + } + } + else{ + + if (num>a) { + ans++; + }else { + if (num>b && scount=min){ + getMinMax++; + } + else if((totTriplets/3)!=0 && (totTriplets/3)+1>=min && surprisingUsed=min){ + getMinMax++; + } + else if(totTriplets%3==2){ + if((totTriplets/3)+1>=min){ + getMinMax++; + } + else if((totTriplets/3)+2>=min && surprisingUsed= min) + capable++; + else if((min-1 >= 0) && (cur/3 == (min-1)) && (cur%3 > 0)) + capable++; + else if(surps > 0 && (min-2 >= 0) && (cur/3 >= (min-2)) && (cur %3 > 1)){ + capable++; + surps--; + } else if(surps > 0 && (min-2 >= 0) && (cur/3 >= (min-1))){ + capable++; + surps--; + } + } + + StringBuilder ob = new StringBuilder(); + ob.append(""Case #"").append(i).append("": ""); + ob.append(capable); + System.out.println(ob.toString()); + } + +// String inp = ""3 3 8 3 21 13""; +// +// String[] ins = inp.split("" ""); +// +// int gs = Integer.parseInt(ins[0]); +// int surps = Integer.parseInt(ins[1]); +// int min = Integer.parseInt(ins[2]); +// +// int capable = 0; +// +// for(int j = 0; j < gs; j++){ +// int cur = Integer.parseInt(ins[3+j]); +// +// System.out.println(""cur/3: ""+(cur/3)); +// System.out.println(""cur%3: ""+(cur%3)); +// +// if(cur / 3 >= min) +// capable++; +// else if((min-1 >= 0) && (cur/3 == (min-1)) && (cur%3 > 0)) +// capable++; +// else if(surps > 0 && (min-2 >= 0) && (cur/3 >= (min-2)) && (cur %3 > 1)){ +// capable++; +// surps--; +// } else if(surps > 0 && (min-2 >= 0) && (cur/3 >= (min-1))){ +// capable++; +// surps--; +// } +// } +// System.out.println(capable); + } +} +" +A21243,"import java.io.*; +import java.util.*; +import java.text.*; + +public class ProblemB { + + int N, S, P; + int[] scores; + + Map> ts = new TreeMap>(); + int[] surprisecount = new int[31]; + int[][] bestsurprise = new int[31][11]; + int[][] notbestsurprise = new int[31][11]; + HashMap memo = new HashMap(); + + public static void main(String[] args) { + try { + new ProblemB().solve(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void appplySet() { + int total = 0; + for (int i=0;i<=30;i++) { + this.surprisecount[i]=0; + this.ts.put(i, new ArrayList()); + } + for (int i=0;i<=10;i++) { + for (int j=0;j<=10;j++) { + for (int k=0;k<=10;k++) { + if (!canHappen(i,j,k)) continue; + Triplet t = new Triplet(i,j,k); + total = i+j+k; + ArrayList temp = ts.get(total); + + if (temp.contains(t)) { + continue; + } + if (temp.add(t)) { + if (t.isSurprise()) { + this.surprisecount[total]++; + } + } + } + } + } + +// for (Integer n : ts.keySet()) { +// System.out.println(n); +// for (Triplet t : ts.get(n)) { +// System.out.println(t); +// } +// } + } + + private boolean canHappen(int a, int b, int c) { + int mx = Math.max(a, Math.max(b, c)); + int mn = Math.min(a, Math.min(b, c)); + if (mx - mn > 2) return false; + return true; + } + + public void solve() throws Exception { + System.setIn(new FileInputStream(""D:\\input.in"")); + Scanner scan = new Scanner(System.in); + PrintWriter out = new PrintWriter(System.out); + + this.appplySet(); + + int T = scan.nextInt(); + scan.nextLine(); + for (int i=0; i= N) { + if (scount == S) { + return bcount; + } else { + return 0; + } + } + if (memo.containsKey(gindex)) { + return memo.get(gindex); + } + + int mxt = 0; + ArrayList tps = this.ts.get(scores[gindex]); + for (Triplet t : tps) { + if (t.isSurprise()) { + scount++; + } + if (t.bestresult() >= P) { + mxt = Math.max(mxt, process(gindex + 1, scount, bcount + 1)); + } else { + mxt = Math.max(mxt, process(gindex + 1, scount, bcount)); + } + if (t.isSurprise()) { + scount--; + } + } + //System.out.println(gindex+"": ""+scores[gindex]+""=""+mxt); + memo.put(gindex, mxt); + return mxt; + } + +} + +class Triplet implements Comparable { + int a,b,c; + + Triplet(int a, int b, int c) { + int[] ns = new int[] {a,b,c}; + Arrays.sort(ns); + this.a=ns[0]; + this.b=ns[1]; + this.c=ns[2]; + } + + @Override + public boolean equals(Object o) { + Triplet t = (Triplet)o; + if (t.a==a && t.b==b && t.c==c) return true; + return false; + } + + public boolean isSurprise() { + if (b-a == 2 || c-b==2 || c - a==2) return true; + return false; + } + public int bestresult() { + return c; + } + @Override + public String toString() { + return ""(""+ a+"",""+b+"",""+c+"")""; + } + + @Override + public int compareTo(Object o) { + Triplet t = (Triplet)o; + if (t.a == a && t.b==b && t.c==c) return 0; + return -1; + } + +} +" +A21916,"import java.util.*; + +public class Dance { + static int s; + static int go(int sum, int p) + { + boolean flag=false; + for(int x=0; x<11; x++) + { + for(int y=0; y<11; y++) + { + for(int z=0; z<11; z++) + { + if(x+y+z!=sum) + continue; + int max=Math.max(Math.max(x,y),z), min=Math.min(Math.min(x,y),z); + if(max-min>2) + continue; + else if(max-min==2&&max>=p) + { + if(s>0) + flag=true; + } + else if(max>=p) + { + flag=false; + return 1; + } + } + } + } + if(flag) + { + s--; + return 1; + } + return 0; + } + public static void main(String args[]) + { + Scanner in=new Scanner(System.in); + int cases=in.nextInt(); + for(int i=1; i<=cases; i++) + { + int ans=0; + int n=in.nextInt(); + s=in.nextInt(); + int p=in.nextInt(); + for(int j=0; j= minStdScore) { + result++; + } else { + if (allowedException > 0) { + Integer minExcScore = minStdScore - 2; + if (minExcScore < 0) minExcScore = data.bestValue; + + if (total >= minExcScore) { + result++; + allowedException--; + } + } + + } + } + return result; + } +} +" +A22048,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + + +public class DancingWithTheGooglers { + ArrayList result = new ArrayList<>(); + public void solve(int N, int S, int p, int[] ts){ + int max = 0; + if(p==0){ + max = ts.length; + result.add(""""+max); + return; + } + //Filter of those how cannot have p based on total score + ArrayList totals = new ArrayList<>(); + for(int i=0;i=3*p-4&&ts[i]>0){ + totals.add(ts[i]); + } + } + //Count those that must have a score above p without surprise + ArrayList needSurprise = new ArrayList<>(); + for(int i=0;i=3*p-2){ + max++; + }else{ + needSurprise.add(val); + } + } + if(S>=needSurprise.size()){ + max += needSurprise.size(); + }else{ + max += S; + } + result.add(""""+max); + } + + public void saveResults(String file){ + try { + FileWriter fstream = new FileWriter(file); + BufferedWriter out = new BufferedWriter(fstream); + int count = 1; + for(int i=0;i 2.0) continue; + if (diff > 1.0) { + if (S > 0) { + S--; + count++; + } + else continue; + } + else count++; + } + return count; + } + +}" +A20256," +package code_jam; + +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Code_Jam { + + + public static void main(String[] args) throws IOException { + + + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + FileWriter out= new FileWriter(""B-large.out""); + //BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); + int T,S,P,N,C; + T=Integer.parseInt(in.readLine()); + StringTokenizer x; + for (int i = 1; i <= T; i++) { + C=0; + x=new StringTokenizer(in.readLine()); + N=Integer.parseInt(x.nextToken()); + S=Integer.parseInt(x.nextToken()); + P=Integer.parseInt(x.nextToken()); + int G[]=new int[N]; + for (int j = 0; j < N; j++) { + G[j]=Integer.parseInt(x.nextToken()); + } + Arrays.sort(G); + for (int j = 0; j < N; j++) { + if(G[j]=10){ + C++; + continue; + } + if(P-B>2) + continue; + else if(P-B==2&&S>0){ + C++; + S--; + } + else if(P-B<=1){ + C++; + } + + + } + //System.out.println(C); + out.write(""Case #""+i+"": ""+C+""\n""); + + + } + out.close(); + + } +} +" +A21032,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class Problem2 { + public static void main(String[] args) throws FileNotFoundException { + Scanner input = new Scanner(new File(""input.txt"")); + PrintStream output = new PrintStream(new FileOutputStream(new File(""output.txt""))); + + int T = input.nextInt(); + input.nextLine(); + + for(int i=1; i <= T; ++i) { + Scanner line = new Scanner(input.nextLine()); + int N = line.nextInt(); + int S = line.nextInt(); + int p = line.nextInt(); + + System.out.printf(""Case:%d, N:%d, S:%d, p:%d\n"", i,N,S,p); + + int result = 0; + for(int j=0; j < N; ++j) { + int points = line.nextInt(); + + int threshold,special_threshold; + + if (p==0) { + threshold = 0; + special_threshold = 0; + } + if (p==1) { + threshold = 1; + special_threshold = 1; + } + else { + threshold = 3*p-2; + special_threshold = 3*p-4; + } + + + if(points >= threshold) { + result++; + } + else if( (S>0) && (points >= special_threshold)) { + S--; + result++; + } + } + + output.println(""Case #"" + i + "": "" + result); + } + } +} +" +A22357,"import java.util.*; +import java.io.*; +class DancingWithTheGooglers{ + Scanner input; + PrintWriter output; + StringBuilder answer = new StringBuilder(); + + public static void main(String[] args){ + DancingWithTheGooglers app = new DancingWithTheGooglers(); + app.openInput(args[0]+"".in""); + app.setOutput(args[0]+"".out""); + app.solve(); + app.saveAndCloseOutput(); + } + + public void openInput(String filename){ + try{ + input = new Scanner(new File(filename)); + } catch (Exception e){ + e.printStackTrace(); + } + } + + public void setOutput(String filename){ + try{ + output = new PrintWriter(new BufferedWriter(new FileWriter(filename))); + } catch (Exception e){ + e.printStackTrace(); + } + } + + public void solve(){ + int nCase = input.nextInt(); + input.nextLine(); + int n,s,p; + int count = 0; + for(int i=1;i<=nCase;i++){ + n = input.nextInt(); + s = input.nextInt(); + p = input.nextInt(); + + count = 0; + for(int j=0;j=p){count++;} + else if(s>0 && score != 0 && score/3+1 == p){count++;s--;} + break; + case 1: + if(score/3 + 1 >= p){count++;} + break; + case 2: + if(score/3 + 1 >= p){count++;} + else if(s>0 && score/3 + 2 == p){count++;s--;} + break; + } + } + output.println(""Case #""+i+"": ""+count); + } + } + + public void saveAndCloseOutput(){ + output.close(); + } +} +" +A21078,"package QualRound; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class DancingWiththeGooglers { + String inFile = ""c:/temp/DancingWiththeGooglers/B-small-attempt0.in""; + String outFile = ""c:/temp/DancingWiththeGooglers/B-small-attempt0.out""; + ArrayList input = new ArrayList(); + ArrayList output = new ArrayList(); + int T; + + public DancingWiththeGooglers(){ + input = readInput(); + process(input); + createOutputFile(output); + } + + public void process(ArrayList input){ + T = Integer.valueOf(input.get(0)); + for(int i = 1; i=P){ + result++; + }else if(value/3+1<=10 && value/3+1>=P && S>0 && value/3-1>=0){ + S--; + result++; + } + } + if(value - 3*(value/3)==2){ + if(value/3+1>=P){ + result++; + } else if(value/3+2>=P && value/3+2<=10 && S>0){ + S--; + result++; + } + } + + if(value - 3*(value/3)==1){ + if(value/3+1>=P){ + result++; + } + } + } + return result; + } + + public void createOutputFile(ArrayList output){ + try{ + FileWriter fstream = new FileWriter(outFile); + BufferedWriter out = new BufferedWriter(fstream); + int i = 1; + for(String str : output) { + out.write(""Case #""+i+"": ""); + out.write(str); + out.newLine(); + i++; + } + + out.close(); + }catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + + } + + public ArrayList readInput(){ + ArrayList inp = new ArrayList(); + + try{ + FileInputStream fstream = new FileInputStream(inFile); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //T = Integer.parseInt(br.readLine()); + + while ((strLine = br.readLine()) != null) { + inp.add(strLine); + } + in.close(); + }catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + + return inp; + } + + + public static void main(String[] args) { + + DancingWiththeGooglers dancingWiththeGooglers = new DancingWiththeGooglers(); + } + +} +" +A22563,"import java.io.*; + +/* + *Problem + +You're watching a show where Googlers (employees of Google) dance, and then each dancer is given +a triplet of scores by three judges. Each triplet of scores consists of three integer scores from 0 to 10 inclusive. +The judges have very similar standards, so it's surprising if a triplet of scores contains two scores that are 2 apart. +No triplet of scores contains scores that are more than 2 apart. +For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. + +The total points for a Googler is the sum of the three scores in that Googler's triplet of scores. +The best result for a Googler is the maximum of the three scores in that Googler's triplet of scores. +Given the total points for each Googler, as well as the number of surprising triplets of scores, what is +the maximum number of Googlers that could have had a best result of at least p? + **/ + +public class Dancing_With_the_Googlers +{ + public static void main(String[] args) + { + try + { + BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(new File(""g:/G.txt"")))); + int n=Integer.parseInt(br.readLine()); + String str=null; + String arr[]=new String[n]; + String array[]; + File f=new File(""g:/Output1.txt""); + f.createNewFile(); + int N=0,S=0,P=0; + int count=0; + int rescount=0; + boolean result[]; + for(int i=0;i(S-count)) + { + if(S-count>0) + result=getResult(Integer.parseInt(array[2+j]),P,true,true); + else + result=getResult(Integer.parseInt(array[2+j]),P,true,false); + } + else + { + if(S-count>0) + result=getResult(Integer.parseInt(array[2+j]),P,false,true); + else + result=getResult(Integer.parseInt(array[2+j]),P,false,false); + } + if(result[0]) + { + rescount++; + System.out.println(""rescount""+rescount); + } + if(result[1]) + { + count++; + System.out.println(""count""+count); + } + } + arr[i]=new String(""Case #""+(i+1)+"": ""+rescount); + } + FileWriter bout=new FileWriter(f); + for(int i=0;i=P) + { + System.out.println(""1 ""); + if(flag) + return new boolean[]{true,false}; + else + return new boolean[]{true,true}; + } + if(temp+1>=P) + { + a=temp+1; + b=c=temp; + System.out.println(""+2 ""+a); + if(a+b+c==sum) + return new boolean[]{true,false}; + b=b+1; + if(a+b+c==sum) + return new boolean[]{true,false}; + + } + if(temp+2>=P) + { + System.out.println(""+3 ""+a); + a=temp+2; + b=c=temp+1; + if(a+b+c==sum) + return new boolean[]{true,false}; + + } + if(temp-1>=P) + { + a=temp-1; + b=c=temp; + System.out.println(""+4 ""+a); + if(a+b+c==sum) + return new boolean[]{true,false}; + c=c+1; + if(a+b+c==sum) + return new boolean[]{true,false}; + + } + if(temp-2>=P) + { + a=temp-2; + b=c=temp-1; + System.out.println(""+5 ""+a); + if(a+b+c==sum) + return new boolean[]{true,false}; + + } + if(temp+1>=P) + { + a=temp+1; + b=c=temp; + c=c-1; + System.out.println(""+6 ""+a); + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + b=b-1; + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + } + if(temp+2>=P) + { + a=temp+2; + b=c=temp+1; + c=c-1; + System.out.println(""+7 ""+a); + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + b=b-1; + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + } + if(temp-1>=P) + { + a=temp-1; + b=c=temp; + b=b+1; + System.out.println(""+8 ""+a); + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + c=c+1; + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + } + if(temp-2>=P) + { + a=temp-2; + b=c=temp-1; + b=b+1; + System.out.println(""+9 ""+a); + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + c=c+1; + if(a+b+c==sum&&flag1) + return new boolean[]{true,true}; + } + + return new boolean[]{false,false}; + } + + +}" +A21235,"package codejam; + +public class Triplet { + + private int total; + private int mod3; + private int div3; + private int maxNormal; + private int maxSurprise; + + public Triplet(int totalPoints) { + init(totalPoints); + } + + private void init(int totalPoints) { + total = totalPoints; + mod3 = total % 3; + div3 = total / 3; + maxNormal = calcMaxNormal(); + maxSurprise = calcMaxSurprise(); + } + + public int calcMaxSurprise() { + if ( total == 0 ) return 0; + return (mod3 == 2) ? div3 + 2 : div3 + 1; + } + + public int calcMaxNormal() { + if ( total == 0 ) return 0; + return (mod3 == 0) ? div3 : div3 + 1; + } + + public int getMaxNormal() { + return maxNormal; + } + + public int getMaxSurprise() { + return maxSurprise; + } + + public static void main(String[] args){ + System.out.println(""Testing Triplet""); + for ( int i=0; i<6; i++ ) { + Triplet t = new Triplet(i); + System.out.println(i+"" n:""+t.calcMaxNormal() + "" s:"" + t.calcMaxSurprise()); + } + } +} +" +A21417,"/** + * Dancing With the Googlers + */ + +package com.google.jam.qualification; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) { + try { + FileOutputStream fos = new FileOutputStream(""B-large.out""); + System.setOut(new PrintStream(fos, true)); + + FileInputStream fis=new FileInputStream(new File(""B-large.in"")); + InputStreamReader in=new InputStreamReader(fis); + BufferedReader br=new BufferedReader(in); + + String line=""""; + int nbTest = Integer.parseInt(br.readLine()); + + for(int i=1; i<=nbTest; i++) { + line = br.readLine(); + Scanner sc = new Scanner(line); + int nbJ = sc.nextInt(); + int nbS = sc.nextInt(); + int minPoint = sc.nextInt(); + + int res = 0; + boolean stop = false; + for(int j=0; j= minPoint) res++; + else if((moy+1)>= minPoint) { + if(reste==2 || reste ==1) res++; + else if(nbS>0 && reste==0 && moy>0) { + res++; + nbS--; + } + + } + else if((moy+2)>= minPoint) { + if(nbS>0 && reste==2) { + res++; + nbS--; + } + } + + } + + System.out.println(""Case #"" + i + "": "" + res); + } + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + System.out.println(""File not found""); + e.printStackTrace(); + } + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} +" +A21021,"import java.util.Scanner; +public class rab1 +{ + public static void main(String[] aesdfwer) + { + Scanner sc= new Scanner (System.in); + int t=sc.nextInt(); + int o; + int n,s,p,pt; + int a,r; + + for(int c=1;c<=t;c++) + { + n=sc.nextInt(); + s=sc.nextInt(); + p=sc.nextInt(); + o=0; + + for(int i=0;i=p) + { + o++; + } + else if(r==0) + { + if(a+1>=p && a>0 && s>0) + { + o++; + s--; + //System.out.println(pt+"" kasus spesial! sisa ""+s); + } + + } + else if(r==1) + { + if(a+1>=p) + { + o++; + } + } + else + { + if(a+1>=p) + { + o++; + } + else if(a+2>=p && s>0) + { + o++; + s--; + //System.out.println(pt+"" kasus spesial! sisa ""+s); + } + } + //System.out.println(pt+"" ""+r+"" ""+a+"" ""+s+"" ""+p); + + } + + System.out.println(""Case #""+c+"": ""+o); + } + } +}" +A22507,"package round0.p2; + +import java.io.File; +import java.util.Scanner; + +public class Main +{ + public static void main(final String[] args) throws Exception + { + Scanner s = new Scanner(new File(""D:\\unsorted\\b.in"")); + int T = s.nextInt(); + + for (int i = 0; i < T; i++) + { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] t = new int[N]; + for (int j = 0; j < N; j++) + t[j] = s.nextInt(); + + int successes = 0; + for (int j = 0; j < N; j++) + { + if (t[j] >= Math.max(p*3-2, p)) + successes++; + else if (t[j] >= Math.max(p*3-4, p) && S > 0) + { + successes++; + S--; + } + } + + System.out.println(""Case #""+(i+1)+"": ""+successes); + } + } +}" +A20731,"import java.io.*; +import java.util.*; + + +public class Dancing { + public static void main(String[] args) throws FileNotFoundException { + + Scanner console = new Scanner(System.in); + + // gets the filename to work with + Scanner input = getInput(console); + // gets the name of file to output to + PrintStream output = getOutput(console); + + int numOfCases = input.nextInt(); + + for (int i = 1; i <= numOfCases; i++) { + int numOfDancers = input.nextInt(); + int surprisingScore = input.nextInt(); + int passingMark = input.nextInt(); + + int lowestPassingScore = passingMark * 3 - 2; + if (lowestPassingScore < 0) { + lowestPassingScore = 0; + } + + int lowestAidedPassingScore = passingMark * 3 - 4; + if (lowestAidedPassingScore < 0 ) { + lowestAidedPassingScore = 0; + } + + //output.println(lowestPassingScore + "":"" + lowestAidedPassingScore); + + int passingDancers = 0; + + for (int dancer = 0; dancer < numOfDancers; dancer++) { + int dancerScore = input.nextInt(); + + + if (dancerScore >= lowestPassingScore) { + // passes without surprising score + passingDancers++; + } else if (dancerScore == 0) { + // do nothing + } else if (dancerScore == 1) { + // do nothing + } else if (dancerScore >= lowestAidedPassingScore) { + + // needs surprising score to pass + if (surprisingScore > 0) { + // uses up a surprising score to pass + surprisingScore--; + passingDancers++; + } + } + } + output.println(""Case #"" + i +"": "" + passingDancers); + } + } + + public static int lineSearcher(String sentence, String welcomeString) { + if (welcomeString.length() == 0) { + return 1; + } else if (sentence.length() == 0) { + return 0; + } else { + if (sentence.substring(0,1).equals(welcomeString.substring(0,1))){ + return lineSearcher(sentence.substring(1), welcomeString.substring(1)) + + lineSearcher(sentence.substring(1), welcomeString); + } else { + return lineSearcher(sentence.substring(1), welcomeString); + } + } + } + + public static Scanner getInput(Scanner console) { + Scanner input = null; + while(input == null) { + System.out.print(""Input file name: ""); + String name = console.nextLine(); + try { + input = new Scanner(new File(name)); + } catch (FileNotFoundException e) { + } + } + return input; + } + + // gets the filename to output to (if blank, outputs to console) + public static PrintStream getOutput(Scanner console) throws FileNotFoundException{ + System.out.print(""Output file name: ""); + String output = console.nextLine(); + if (output.equals("""")) { + return new PrintStream(System.out); + } else { + return new PrintStream(new File(output)); + } + } +}" +A22782,"package google.problems; + +import google.loader.Challenge; +import google.loader.ChallengeReader; + +import java.util.ArrayList; +import java.util.List; + + +public abstract class AbstractReader implements ChallengeReader { + + private String[] lines; + private List challenges; + private int actualLine; + + public AbstractReader(){ + challenges = new ArrayList(); + } + + + protected void setLines(String[] input) { + lines=input; + } + + protected String[] getLines(){ + return lines; + } + + protected int getNumberOfChallenges() { + return Integer.parseInt(lines[0]); + } + + @Override + public List createChallenges(String[] input) { + setLines(input); + readChallenges(); + return challenges; + } + + private void readChallenges() { + int numOfChallanges = getNumberOfChallenges(); + setActualLine(1); + actualLine = 1; + for(int i=1;i<=numOfChallanges; i++){ + challenges.add(createChallenge(i)); + } + } + + protected int[] asInt(String values) { + String[] split = values.split("" ""); + int res [] = new int[split.length]; + for(int i=0;i asIntList(String values) { + List res = new ArrayList(); + for(int i : asInt(values)){ + res.add(i); + } + return res; + } + + + protected abstract Challenge createChallenge(int i) ; + + protected void setActualLine(int i) { + actualLine =i; + } + protected int getActualLine(){ + return actualLine; + } + +} +" +A20690,"package qualification; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Scanner; + +public class DancingWithTheGoogler { + public static void main(String[] args) throws IOException { + String inputFile = ""B-large.in""; + Scanner input = new Scanner(new FileInputStream(inputFile)); + + FileOutputStream out = new FileOutputStream(inputFile + "".out"", false); + slove(input, out); + out.close(); + } + + private static void slove(Scanner input, FileOutputStream out) throws IOException + { + int cases = input.nextInt(); + for (int caseOrder = 1; caseOrder <= cases; caseOrder++) { + int n = input.nextInt(); + int s = input.nextInt(); + int p = input.nextInt(); + + int[] a = new int[n]; + + for (int i = 0; i < n; i++) { + a[i] = input.nextInt(); + } + + int r = 0; + for (int i = 0; i < n; i++) { + int d = p * 3 - a[i]; + if (d <= 2) { + r++; + } else if (d <= 4) { + if (s > 0 && a[i] >= p) { + s--; + r++; + } + } + } + + String outline = String.format(""Case #%d: %d\r\n"", caseOrder, r); + out.write(outline.getBytes()); + } + } +} +" +A20681,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlecodejamproblemb; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author Fluffy Dragon + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + //setup(); + File inputFile = new File(""B-large.in""); + File outputFile = new File(""output2.txt""); + FileReader fr = null; + try { + fr = new FileReader(inputFile); + BufferedReader br = new BufferedReader(fr); + FileWriter fw = new FileWriter(outputFile, false); + BufferedWriter bw = new BufferedWriter(fw); + int count = Integer.parseInt(br.readLine()); + for (int i = 0; i < count; i++) { + String readLine = br.readLine(); + String[] split = readLine.split(""\\s""); + int[] input = new int[split.length]; + for (int i2 = 0; i2 < split.length; i2++) { + input[i2] = Integer.parseInt(split[i2]); + } + String output = calculate(i + 1, input); + bw.write(output); + if (i + 1 < count) { + bw.newLine(); + } + } + br.close(); + fr.close(); + bw.close(); + fw.close(); + } catch (FileNotFoundException e) { + } catch (IOException e) { + } + } + + private static String calculate(int count, int[] input) { + String output = ""Case #"" + count + "": ""; + int googlers = input[0]; + int surprising = input[1]; + int bestResultSearch = input[2]; + ArrayList scoresHigh = new ArrayList(0); + ArrayList scoresLow = new ArrayList(0); + for (int i = 3; i < (googlers + 3); i++) { + for (int j = i + 1; j < (googlers + 3); j++) { + if (input[i] <= input[j]) { + int a = input[i]; + int b = input[j]; + input[i] = b; + input[j] = a; + } + } + } + for (int i = 3; i < (googlers + 3); i++) { + int total = input[i]; + int score1 = Math.round(total / 3); + int score2 = Math.round(total / 3); + int score3 = Math.round(total / 3); + if ((score1 + score2 + score3) == total) { + score3--; + } + if ((score1 + score2 + score3) == total) { + score2--; + } + if (score1 < 0) { + score1 = 0; + } + if (score2 < 0) { + score2 = 0; + } + if (score3 < 0) { + score3 = 0; + } + while ((score1 + score2 + score3) != total) { + if ((score1 + 1 <= 10) && score1 - score2 < 2 && score1 - score3 < 2) { + score1++; + } else if ((score2 + 1 <= 10) && score2 - score1 < 2 && score2 - score3 < 2) { + score2++; + } else if ((score3 + 1 <= 10) && score3 - score1 < 2 && score3 - score2 < 2) { + score3++; + } else { + throw new RuntimeException(""no deviation could be created""); + } + } + System.out.println(score1 + "" "" + score2 + "" "" + score3 + "" "" + total); + //System.out.println(score1 + "" "" + score2 + "" "" + score3); + scoresHigh.add(new int[]{score1, score2, score3}); + score1 = Math.round(total / 3); + score2 = Math.round(total / 3); + score3 = Math.round(total / 3); + if (score1 < 0) { + score1 = 0; + } + if (score2 < 0) { + score2 = 0; + } + if (score3 < 0) { + score3 = 0; + } + while ((score1 + score2 + score3) != total) { + if ((score1 + 1 <= 10) && score1 - score2 < 1 && score1 - score3 < 1) { + score1++; + } else if ((score2 + 1 <= 10) && score2 - score1 < 1 && score2 - score3 < 1) { + score2++; + } else if ((score3 + 1 <= 10) && score3 - score1 < 1 && score3 - score2 < 1) { + score3++; + } else { + throw new RuntimeException(""no deviation could be created""); + } + } + scoresLow.add(new int[]{score1, score2, score3}); + } + for (int i = 0; i < googlers; i++) { + int[] low = scoresLow.get(i); + if (low[0] >= bestResultSearch || low[1] >= bestResultSearch || low[2] >= bestResultSearch) { + System.out.println(""Changed 1""); + scoresHigh.set(i, low); + } + } + int surprisingCounter = 0; + for (int i = 0; i < googlers; i++) { + int[] temp = scoresHigh.get(i); + if (temp[0] >= bestResultSearch || temp[1] >= bestResultSearch || temp[2] >= bestResultSearch) { + continue; + } + if (Math.abs(temp[0] - temp[1]) == 2 || Math.abs(temp[0] - temp[2]) == 2 || Math.abs(temp[1] - temp[2]) == 2) { + surprisingCounter++; + if (surprisingCounter > surprising) { + scoresHigh.set(i, scoresLow.get(i)); + surprisingCounter--; + } + } + } + //error lies between here + surprisingCounter = 0; + for (int i = 0; i < googlers;i++){ + int[] temp = scoresHigh.get(i); + if (Math.abs(temp[0] - temp[1]) == 2 || Math.abs(temp[0] - temp[2]) == 2 || Math.abs(temp[1] - temp[2]) == 2) { + surprisingCounter++; + if (surprisingCounter > surprising) { + scoresHigh.set(i, scoresLow.get(i)); + surprisingCounter--; + } + } + } + //and here + if (surprisingCounter != surprising) { + System.out.println(""Error: "" + surprisingCounter + "" "" + surprising); + } + int bestScoresReached = 0; + for (int[] temp : scoresHigh) { + System.out.println(temp[0] + "" "" + temp[1] + "" "" + temp[2]); + if (temp[0] >= bestResultSearch || temp[1] >= bestResultSearch || temp[2] >= bestResultSearch) { + bestScoresReached++; + } + } + output = output.concat(String.valueOf(bestScoresReached)); + return output; + } +} +//input +//4 +//3 1 5 15 13 11 +//3 0 8 23 22 21 +//2 1 1 8 0 +//6 2 8 29 20 8 18 18 21 +// +//output +//Case #1: 3 +//Case #2: 2 +//Case #3: 1 +//Case #4: 3 + +" +A20385,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Scanner; + + +public class GoogleCodeB { + public static void main(String args[]) throws Exception { + FileReader fr = new FileReader(""C:/Users/moez/Desktop/B-large.in""); + BufferedReader br = new BufferedReader(fr); + FileWriter fstream = new FileWriter(""C:/Users/moez/Desktop/out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + int l= 1; + String s; + + int N, S, P, X, Y, nsurp, surp, temp; + int i = 0; + int[] t = new int[6]; + String[] st = new String [6]; + br.readLine(); + while((s = br.readLine()) != null) { + Scanner sc = new Scanner(s); + i = 0; + N = sc.nextInt(); + S = sc.nextInt(); + P = sc.nextInt(); + X = 3*P-2; + Y = ((3*P-4 > 0) ? 3*P-4 : P); + nsurp = surp= 0; + for (i=0; i= X){ + nsurp++; + }else if ( temp >= Y) + surp++; + } + nsurp+=((surp > S) ? S : surp); + + out.write(""Case #""+l+"": ""+nsurp); + out.write(""\r\n""); + + + l++; + } + out.close(); + fr.close(); + } +} +" +A21637,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + + +public class CodeJamTextOutputWriter { + private final BufferedWriter writer; + + CodeJamTextOutputWriter(File outputFile) throws IOException { + writer = new BufferedWriter(new FileWriter(outputFile)); + } + + public void outputTestCase(int num, String out) throws IOException { + writer.append(""Case #""); + writer.append(Integer.toString(num)); + writer.append("": ""); + writer.append(out); + writer.newLine(); + } + + public void close() throws IOException { + writer.close(); + } +} +" +A20041,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +import java.io.*; +import java.util.*; +/** + * + * @author Maleen + */ +public class B { + public static void main(String[] args) throws FileNotFoundException, IOException { + Scanner sc = new Scanner(new File(""in/B.txt"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""Bout.txt""))); + + int[] SMax = new int[31]; + int[] NMax = new int[31]; + SMax[0] = 0; NMax[0] = 0; + for (int i=1;i<=30;i++){ + SMax[i] = Math.min((i+1)/3 +1,10); + NMax[i] = Math.min((i-1)/3 +1,10); + + System.out.println(i+ "" ""+NMax[i] +"" ""+ SMax[i]); + } + int T = sc.nextInt(); + for (int t=0;t=P) clear ++; + else if (SMax[n] >=P) margin++; + } + System.out.println(""S ""+S +"" clear ""+ clear +"" margin ""+margin); + out.println(""Case #""+(t+1) + "": ""+ (clear + Math.min(margin, S))); + } + out.close(); + } +} +" +A22394,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancingwithgoogler; + +import java.io.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * + * @author WC + */ +public class CodeJamFileManager { + private final static String problemIntro = ""Problem reading file: ""; + private final static String location = ""C:\\CodeJamTests\\""; + + public static String getStringOfFile(String filename) { + String filepath = location + filename; + byte[] buffer = new byte[(int) new File(filepath).length()]; + BufferedInputStream stream = null; + try { + stream = new BufferedInputStream(new FileInputStream(filepath)); + stream.read(buffer); + } + catch (Exception ex) { + return problemIntro + ex.getMessage(); + } + finally { + if (stream != null) { + try { + stream.close(); + } + catch (IOException ex) { + return problemIntro + ex.getMessage(); + } + } + } + return new String(buffer); + } + + public static int getIntFromFirstLineOfFile(String filename, String separator) { + String[] lines = getTextLinesOfFile(filename, separator); + int i = 1; + return extractInt(lines[0]); + } + + public static String[] getTextLinesOfFile(String filename, String separator) { + String fileStr = getStringOfFile(filename); + return fileStr.split(separator); + } + + public static void saveOutputFile(String output, String filename, String separator) { + String filepath = location + filename; + try { + File outFile = new File(filepath); + FileWriter writer = new FileWriter(outFile); + BufferedWriter bWriter = new BufferedWriter(writer); + bWriter.write(output); + bWriter.close(); + } + catch (Exception ex) { + System.out.println(""Failed to save file with error: "" + ex.getMessage()); + } + } + + + private static int extractInt(String line) { + Matcher intMatcher = Pattern.compile(""[0-9]*"").matcher(line); + int i = 0; + if (intMatcher.find()) { + String numStr = intMatcher.group(0); + i = Integer.parseInt(numStr); + } + return i; + } +} +" +A22897,"package qualification; + +import java.util.Scanner; + +public class B { + + public static void main(String[] args) { + try { + Scanner scanner = new Scanner(System.in); + int lp = scanner.nextInt(); + int c = 0; + for (int loop = 0; loop < lp; loop++) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int ans = 0; + for (int j = 0; j < N; j++) { + int t = scanner.nextInt(); + if (t < 2) { + if (p <= t) { + ans++; + } + } + if (t == 2) { + if (p < t) { + ans++; + } + if (p == t && S > 0) { + ans++; + S--; + } + } + if (t > 2) { + if (t / 3 >= p) { + ans++; + } else { + switch (t % 3) { + case 0: + if (t / 3 + 1 == p && S > 0) { + S--; + ans++; + } + break; + case 1: + if (t / 3 + 1 == p) { + ans++; + } + break; + case 2: + if (t / 3 + 1 == p) { + ans++; + } else if (t / 3 + 2 == p && S > 0) { + ans++; + S--; + } + break; + } + } + } + } + c++; + System.out.println(""Case #"" + c + "": "" + ans); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} +" +A20115,"import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.StringTokenizer; +public class code_jam { + + /** + * @param args + */ + public static void main(String[] args) { + + File file = new File(""C:\\test.in""); + FileInputStream fis = null; + BufferedInputStream bis = null; + DataInputStream dis = null; + + try { + fis = new FileInputStream(file); + bis = new BufferedInputStream(fis); + dis = new DataInputStream(bis); + + int cc = Integer.parseInt(dis.readLine()); + int i, j; + for (i=0;i= (index * 3 - 2)) { + count += 1; + } else if ((googler_score >= (index * 3 - 5)) && (googler_score > 1)){ + can_surprise += 1; + } + } + if (can_surprise > surprising) + count += surprising; + else + count += can_surprise; + + System.out.println(""Case #"" + (i+1) + "": "" + count); + + /*int from = Integer.parseInt(range.substring(0, range.indexOf(' '))); + int to = Integer.parseInt(range.substring(range.indexOf(' ')+1, range.length())); + int count = 0; + int x,y; + for (x=from; x < to; x++){ + int length = String.valueOf(x).length(); + for (y = 0; y < length-1; y++){ + int head = (int) (x / Math.pow(10, y+1)); + int tail = (int) (x % Math.pow(10, y+1)); + int new_num = (int) (tail * Math.pow(10, length-y-1) + head); + if ((new_num <= to) && (new_num > x)) + count++; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + */ + } + fis.close(); + bis.close(); + dis.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + +} +" +A22307,"import static java.util.Arrays.deepToString; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class DancingWithTheGooglers { + + final static String FILENAME = ""B-large""; + //final static String FILENAME = ""B-small-attempt0""; + //final static String FILENAME = ""sample""; + final static String FILENAME_IN = FILENAME + "".in""; + final static String FILENAME_OUT = FILENAME + "".out""; + + final static int THREADS = 1; // use 1 to solve them sequentially + + // VM arguments: -ea -Xms4096M -Xmx4096M + + static class Solver implements Callable { + + // PROBLEM SOLUTION STARTS HERE ----------------------------------------------------------- + // ---------------------------------------------------------------------------------------- + + + Solver(Scanner in, int testId) { + this.testId = testId; + + // TODO: Read input + + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + numbers = new int[N]; + for (int i=0; i= normal) { + count++; + } else if (number >= surprising && countSurprise < S) { + count++; countSurprise++; + } + } + + + String res = Integer.toString(count); + + System.err.println(String.format(""%4d ms %s"" , (System.nanoTime() - now) / 1000000, res)); + return res; + } + + // PROBLEM SOLUTION ENDS HERE ------------------------------------------------------------- + // ---------------------------------------------------------------------------------------- + + final int testId; + } + + + static void debug(Object...os) { + System.err.println(deepToString(os)); + } + ; + + public static void main(String[] args) throws FileNotFoundException, InterruptedException { + long now = System.nanoTime(); + System.setIn(new FileInputStream(FILENAME_IN)); + System.setOut(new PrintStream(new FileOutputStream(FILENAME_OUT))); + Scanner in = new Scanner(System.in); + int numTests = in.nextInt(); in.nextLine(); + System.err.println(String.format(""TESTS: %d"" , numTests)); + List solvers = new ArrayList(); + for (int i=0; i> solutions = executor.invokeAll(solvers); + for (int i = 0; i < numTests; i++) { + try { + System.out.println(String.format(""Case #%d: %s"", solvers.get(i).testId, solutions.get(i).get())); + } catch (Exception e) { + System.out.println(String.format(""Case #%d: EXCEPTION !!!!!"", solvers.get(i).testId)); + System.err.println(String.format(""Case #%d: EXCEPTION !!!!!"", solvers.get(i).testId)); + e.printStackTrace(System.err); + } + } + executor.shutdown(); + System.err.println(String.format(""TOTAL: %d ms"" , (System.nanoTime() - now) / 1000000)); + } + + +}" +A20648,"import java.io.FileReader; +import java.io.LineNumberReader; +import java.io.PrintWriter; +import java.util.Scanner; + +public class go2 { + + public static final String IN_FILE = ""B-large.in""; + public static final String OUT_FILE = ""out.txt""; + + + public static void main(String[] args) throws Throwable { + + try (LineNumberReader reader = new LineNumberReader(new FileReader(IN_FILE))) { + try (PrintWriter writer = new PrintWriter(OUT_FILE)) { + + int T = Integer.parseInt(reader.readLine()); + + //Tests + for (int t = 1; t <= T; t++) { + Scanner scanner = new Scanner(reader.readLine()); + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int P = scanner.nextInt(); + + int result = 0; + int bothSurprisingAndNotSurprising = 0; + + for (int i = 0; i < N; i++) { + int currentScore = scanner.nextInt(); + if (currentScore == 0) { + if (P == 0) { + result++; + } + } else if (currentScore == 1) { + if (P == 0 || P == 1) { + result++; + } + } else if (currentScore == 30) { + result++; + } else if (currentScore == 29) { + result++; + } + // 2 <= currentScore <= 28 + else { + int bestSurprising; + int bestNotSurprising; + + if ((currentScore % 3 == 0)) { + bestSurprising = (currentScore / 3) + 1; + bestNotSurprising = (currentScore / 3); + } + else if ((currentScore % 3 == 1)) { + bestNotSurprising = bestSurprising = (currentScore / 3) + 1; + } + else { + bestSurprising = (currentScore / 3) + 2; + bestNotSurprising = (currentScore / 3) + 1; + } + + if(bestNotSurprising < P && bestSurprising == P){ + if(S > 0) { + S--; + result++; + } + } + else if(bestNotSurprising >= P){ + bothSurprisingAndNotSurprising++; + } + } + } + + result += bothSurprisingAndNotSurprising; + + writer.printf(""Case #%d: %d\n"", t, result); + } + } + } + } +} + +" +A22348,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class CodeJam2012Ex2Small { + + public static void main(String arg[]) throws FileNotFoundException { + File file = new File(""B-large.in""); + Scanner scanner = new Scanner(file); + String output; + int numTestCases = scanner.nextInt(); + for (int i = 0; i < numTestCases; i++) { + StringBuffer buffer = new StringBuffer(""Case #"" + (i + 1) + "": ""); + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int[] googlersPoints = new int[N]; + int bestResults = 0; + for (int j = 0; j < N; j++) { + googlersPoints[j] = scanner.nextInt(); + if ((googlersPoints[j] >= (p * 3 - 2))){ + bestResults++; + + } else if ((googlersPoints[j] >= (p * 3 - 4)) + && S > 0 && googlersPoints[j] != 0) { + + bestResults++; + S--; + } + } + buffer.append(bestResults); + if (i != numTestCases - 1) { + buffer.append(""\n""); + } + output = buffer.toString(); + + System.out.print(output); + } + + } +} +" +A21979,"import java.util.Scanner; + +class Dancing{ + static Scanner sc = new Scanner(System.in); + + public static void solve() + { + int sum,X; + int n =sc.nextInt(); + int sur =sc.nextInt(); + int k =sc.nextInt(); + int max=0; + for(int i=0;i0) + { + sur--; + max++; + } + } + else + if(k<=X) + max++; + else + if(k==X+1) + { + if(sum%3!=0) + max++; + else + if(sur>0) + { + max++; + sur--; + } + } + else + if(k==X+2 && sum%3==2 && sur>0) + { + max++; + sur--; + } + } + System.out.println(max); + } + + public static void main(String[] args) + { + int n=sc.nextInt(); + sc.nextLine(); + + for(int i=0;i0){ + StringTokenizer tokens=new StringTokenizer(in.readLine()); + int answer=0; + + int N=Integer.parseInt(tokens.nextToken()); + int S=Integer.parseInt(tokens.nextToken()); + int P=Integer.parseInt(tokens.nextToken()); + + if(P==0){ + writeln(""Case #""+(number++)+"": ""+N); + continue; + } + int mincount=P==1?1:3*(P-1)-1; + + + for (int i = 0; i < N; i++) { + int x=Integer.parseInt(tokens.nextToken()); + + if(x=P){ + answer++; + } + else{ + if(S<=0)continue; + + if((divideX+2)>=P){ + answer++; + S--; + } + + } + } + + + + writeln(""Case #""+(number++)+"": ""+answer); + } + + + } + + + + + + + private int nextInt() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return Integer.parseInt(input.nextToken()); + } + private long nextLong() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return Long.parseLong(input.nextToken()); + } + private double nextDouble() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return Double.parseDouble(input.nextToken()); + } + private String nextString() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return input.nextToken(); + } + private void write(String output){ + out.write(output); + out.flush(); + } + private void writeln(String output){ + out.write(output+""\n""); +// out.flush(); + } + private void end() throws IOException{ + in.close(); + out.close(); + System.exit(0); + } + + private BufferedReader in; + private PrintWriter out; + private StringTokenizer input; + + public B() throws IOException { + //Input Output for Console to be used for trying the test samples of the problem +// in = new BufferedReader(new InputStreamReader(System.in)); +// out = new PrintWriter(System.out); + //------------------------------------------------------------------------- + //Input Output for File to be used for solving the small and large test files + in = new BufferedReader(new FileReader(""B-large.in"")); + out = new PrintWriter(""output2Large.txt""); + //------------------------------------------------------------------------- + //Initialize Stringtokenizer input + + } + + public static void main(String[] args) throws Exception { + //------------------------------------------------------------------------- + //initializing... + B sol = new B(); + //------------------------------------------------------------------------- + sol.run(); + //------------------------------------------------------------------------- + //closing up + sol.end(); + //-------------------------------------------------------------------------- + } + +} +" +A20124,"import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.FileWriter; + +class Start{ + BufferedInputStream bis=new BufferedInputStream(System.in); + PrintWriter out=new PrintWriter(System.out, true); + int i,j,k,l,m,n,o,p,q,r,s,t,w,x,y,z,ry,rz,rs; + long a,b,c; + double d,e,f,g,h; + char u,v; + String st; + int[] in,arr,res; + final double pi=3.14159265; + final double l2=0.69314718; + + char chr()throws IOException{ + while((ry=bis.read())==10 || ry==13 || ry==32){} + return (char)ry; + } + + int num()throws IOException{ + rz=0;rs=0; + ry=bis.read(); if(ry=='-') rs=-1; else rz+=(ry-'0'); + while((ry=bis.read())>='0' && ry<='9') rz=rz*10+(ry-'0'); + if(rs==-1) rz=-rz; + if(ry==13) bis.read(); + return rz; + } + + String str()throws IOException{ + StringBuilder sb=new StringBuilder(); + while((ry=bis.read())!=10 & ry!=13 && ry!=32) sb.append((char)ry); + if(ry==13) bis.read(); + return sb.toString(); + } + + String line()throws IOException{ + StringBuilder sb=new StringBuilder(); + while((ry=bis.read())!=10 && ry!=13) sb.append((char)ry); + if(ry==13)bis.read(); + return sb.toString(); + } + + int log2(double par){return (int)(Math.log(par)/l2);} + + long perm(int p1,int p2){ + long ret=1; int it; + it=p1; while(it>p2) ret*=it--; + return ret; + } + + long comb(int p1,int p2){ + long ret=1; int it; + if(p2p2) ret*=it--; + it=p1-p2; while(it>1) ret/=it--; + return ret; + } + + public void go()throws IOException{ + out =new PrintWriter(new FileWriter(""out.txt""),true); + t=num(); + j=t; + while(--t>=0){ + n=num(); + s=num(); + p=num(); + x=0; + for(i=0;i=p) || + ((z+1 + z*2 == y) && z+1>=p) || + (((z+1)*2 + z == y) && z+1>=p)) x++; + else if(s>0 && + ((z-1>0 && (z*3 == y) && z+1>=p)|| + (z-2>0 && (z*3+2 == y) && z+2>=p)|| + (z-2>0 && (z*3-2 == y) && z>=p))|| + (z+2<10 && (z*3+4 == y) && z+2>=p)|| + (z-2>0 && (z*3-4 == y) && z>=p)) + { x++; s--;} + } + out.println(""Case #""+(j-t)+"": ""+x); + } + while(bis.available()>0)bis.read(); + out.close(); + } + + public static void main(String args[])throws IOException{new Start().go();} +} +" +A20754," +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class ProblemB { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(new File(""B-large.in""))); + PrintWriter pw = new PrintWriter(new File(""B-large.out"")); + int n, s,p, count, temp; + int t= new Integer(br.readLine()); + for(int c=1; c<=t; c++) + { + pw.append(""Case #""+c+"": ""); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = new Integer(st.nextToken()); + s= new Integer(st.nextToken()); + p = new Integer(st.nextToken()); + count=0; + if(p==0) + count=n; + else + for(int i=0; i< n ; i++) + { + temp= new Integer(st.nextToken()); + if(temp< p ) + continue; + + temp = (temp-p)/2; + + if(temp >=p-1) + count++; + else if (temp>=p-2 && s>0 && p>1) + { + count++; + s--; + } + } + pw.append(count+""""); + pw.append('\n'); + } + pw.flush(); + pw.close(); + br.close(); + } +} +" +A22761,"package qual2012; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class Kattio extends PrintWriter { + public Kattio(InputStream i) { + super(new BufferedOutputStream(System.out)); + r = new BufferedReader(new InputStreamReader(i)); + } + + public Kattio(InputStream i, OutputStream o) { + super(new BufferedOutputStream(o)); + r = new BufferedReader(new InputStreamReader(i)); + } + + public boolean hasMoreTokens() { + return peekToken() != null; + } + + public int getInt() { + return Integer.parseInt(nextToken()); + } + + public double getDouble() { + return Double.parseDouble(nextToken()); + } + + public long getLong() { + return Long.parseLong(nextToken()); + } + + public String getWord() { + return nextToken(); + } + + + private BufferedReader r; + private String line; + private StringTokenizer st; + private String token; + + private String peekToken() { + if (token == null) + try { + while (st == null || !st.hasMoreTokens()) { + line = r.readLine(); + if (line == null) return null; + st = new StringTokenizer(line); + } + token = st.nextToken(); + } catch (IOException e) { + } + return token; + } + + private String nextToken() { + String ans = peekToken(); + token = null; + return ans; + } +}" +A22588,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; +public class ProblemB { + public static void main(String[] args) throws IOException { + BufferedReader leer= new BufferedReader(new InputStreamReader(System.in)); + int T=intS(leer.readLine()); + for (int i = 1; i <= T; i++) { + StringTokenizer st= new StringTokenizer(leer.readLine()); + int N=intS(st.nextToken()); + int S=intS(st.nextToken()); + int p=intS(st.nextToken()); + int[][] g= new int[N][3]; + for (int j = 0; j < N; j++){ + int v=intS(st.nextToken()); + g[j][0]=v/3; + g[j][1]=v%3; + int score[]={g[j][0],g[j][0],g[j][0]}; + if(g[j][1]>=1) + score[0]++; + if(g[j][1]==2) + score[1]++; + if(score[0]>=p) + g[j][2]=2; + else if(score[0]+1>=p && score[0]-score[1]==0 && score[0]!=0 ) + g[j][2]=1; + else + g[j][2]=0; + } + int r=0; + for (int j = 0; j < N; j++){ + if(g[j][2]==1 && S>0){ + g[j][2]=2; + S--; + } + if(g[j][2]==2) + r++; + } + System.out.println(""Case #""+i+"": ""+r); + } + } + static int intS(String s){ + return Integer.parseInt(s); + } +} +" +A20243,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) throws IOException { + String file = ""B-large""; + File inputFile = new File(""C:\\Users\\Harutsedo\\Workspace\\Google Code Jam\\input\\2012\\QR\\"" + file + "".in""); + File outputFile = new File(""C:\\Users\\Harutsedo\\Workspace\\Google Code Jam\\output\\2012\\QR\\"" + file + "".out""); + outputFile.createNewFile(); + Scanner scanner = new Scanner(inputFile); + FileWriter writer = new FileWriter(outputFile); + + int T = scanner.nextInt(); + + for (int c = 0; c < T; c++) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + int[] scores = new int[N]; + for (int i = 0; i < N; i++) { + scores[i] = scanner.nextInt(); + } + + String solution = solveCase(S, p, scores); + + StringBuffer s = new StringBuffer(""Case #"" + (c + 1) + "":""); + System.out.println(s + "" "" + solution); + writer.write(s + "" "" + solution); + //if (c != N - 1) { + writer.write(""\n""); + //} + + } + writer.close(); + } + + public static String solveCase(int S, int p, int[] scores) { + int max = 0; + for (int i = 0; i < scores.length; i++) { + if ((scores[i] - p) >= 2 * p || ((scores[i] - p) >= 2 * p - 2 && p >= 1)) { + max++; + } else if ((scores[i] - p) >= 2 * p - 4 && S > 0 && p >= 2) { + max++; + S--; + } + } + return String.valueOf(max); + } + +} +" +A21029,"package com.lewis.codeJamInJava; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + try { + + File outpuFile = new File(""output.txt""); + FileWriter fileWriter = new FileWriter(outpuFile); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + + BufferedReader bufferedReader; + File inputFile = new File(""input.txt""); + FileReader fileReader = new FileReader(inputFile); + bufferedReader = new BufferedReader(fileReader); + + int numTestCases = Integer.parseInt(bufferedReader.readLine()); + + for (int i = 1; i <= numTestCases; i++) { + + StringTokenizer st = new StringTokenizer( + bufferedReader.readLine()); + + int numGooglers = Integer.parseInt(st.nextToken()); + int numSurprisingScores = Integer.parseInt(st.nextToken()); + int passingScore = Integer.parseInt(st.nextToken()); + + int scores[] = new int[numGooglers]; + + for (int j = 0; j < numGooglers; j++) { + scores[j] = Integer.parseInt(st.nextToken()); + } + + int passingGrades = getNumPassingScores(scores, passingScore, + numSurprisingScores); + + bufferedWriter + .write(""Case #"" + i + "": "" + passingGrades + ""\r\n""); + + } + bufferedWriter.flush(); + bufferedWriter.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * Given scores, passing score and surpising scores, generates the number of + * passes. + * + * @param scores + * @param passingScore + * @param numSurprisingScores + * @return + */ + public static int getNumPassingScores(int[] scores, int passingScore, + int numSurprisingScores) { + + int numPassing = 0; + int easyPass = passingScore * 3 - 2; + int surprisingPass = passingScore * 3 - 4; + + if (easyPass < 0) { + surprisingPass = 0; + easyPass = 0; + } else if(surprisingPass < 0){ + surprisingPass = 0; + } + + for (int i = 0; i < scores.length; i++) { + if(scores[i] < passingScore){ + + } else if (scores[i] >= easyPass) { + numPassing++; + } else if (numSurprisingScores > 0 && scores[i] >= surprisingPass) { + numSurprisingScores--; + numPassing++; + } + + } + + return numPassing; + } + +} +" +A23091,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +public class DancingWithGooglers { + + public int numberOfGooglers; + public int exptectedSurprisingScores; + public int realSurprisingScores = 0; + public int bestScore; + public int googlersBetterThanBestScore = 0; + + public static void main(String[] args) throws NumberFormatException, + IOException { + File file = new File(""C:\\Users\\xebia\\Downloads\\B-large.in""); + + FileInputStream fis = new FileInputStream(file); + DataInputStream in = new DataInputStream(fis); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + int numberOfTestCases = new Integer(br.readLine()); + + for (int k = 0; k < numberOfTestCases; k++) { + DancingWithGooglers da = new DancingWithGooglers(); + String[] strings = br.readLine().split("" ""); + da.numberOfGooglers = new Integer(strings[0]); + da.exptectedSurprisingScores = new Integer(strings[1]); + da.bestScore = new Integer(strings[2]); + for (int i = 0; i < da.numberOfGooglers; i++) { + Googlers googler = new Googlers(); + int totalScore = new Integer(strings[3 + i]); + googler.setTotalScore(totalScore); + da.calculateOptimizedTriplet(googler); + } +// if (da.realSurprisingScores < da.exptectedSurprisingScores) { +// da.googlersBetterThanBestScore = da.googlersBetterThanBestScore +// - (da.exptectedSurprisingScores - da.realSurprisingScores); +// } + System.out.println(""Case #"" + (k+1) + "": "" + da.googlersBetterThanBestScore); + } + + } + + public void calculateOptimizedTriplet(Googlers googler) { + if (googler.getTotalScore() >= ((3 * bestScore) - 2)) { + googlersBetterThanBestScore++; + } else if (googler.getTotalScore() == (3 * (bestScore) - 3) + || googler.getTotalScore() == (3 * (bestScore) - 4)) { + + if(googler.getTotalScore() == 0 || googler.getTotalScore() == 1){ + + }else if (realSurprisingScores < exptectedSurprisingScores) { + realSurprisingScores++; + googlersBetterThanBestScore++; + } + } + } + +} + +class Googlers { + private int firstScore; + private int secondScore; + private int thirdScore; + private int totalScore; + private boolean surprisingScore = false; + private boolean invalidScore = false; + + public Googlers() { + // TODO Auto-generated constructor stub + } + + public Googlers(int firstScore, int secondScore, int thirdScore) { + this.firstScore = firstScore; + this.secondScore = secondScore; + this.thirdScore = thirdScore; + } + + public void setFirstScore(int firstScore) { + this.firstScore = firstScore; + } + + public int getFirstScore() { + return firstScore; + } + + public void setSecondScore(int secondScore) { + this.secondScore = secondScore; + } + + public int getSecondScore() { + return secondScore; + } + + public void setThirdScore(int thirdScore) { + this.thirdScore = thirdScore; + } + + public int getThirdScore() { + return thirdScore; + } + + public int getHighestScore() { + + int highestScore = firstScore; + if (secondScore > highestScore) { + highestScore = secondScore; + } + if (thirdScore > highestScore) { + highestScore = thirdScore; + } + + return highestScore; + + } + + public int getSmallestScore() { + int smallestScore = firstScore; + if (secondScore < smallestScore) { + smallestScore = secondScore; + } + if (thirdScore < smallestScore) { + smallestScore = thirdScore; + } + + return smallestScore; + + } + + public void setSurprisingScore(boolean surprisingScore) { + this.surprisingScore = surprisingScore; + } + + public boolean isSurprisingScore() { + return surprisingScore; + } + + public void setTotalScore(int totalScore) { + this.totalScore = totalScore; + } + + public int getTotalScore() { + return totalScore; + } + + public void setInvalidScore(boolean invalidScore) { + this.invalidScore = invalidScore; + } + + public boolean isInvalidScore() { + return invalidScore; + } + +} +" +A22260,"import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +/** + * Created by IntelliJ IDEA. + * User: elbek + * Date: 4/13/12 + * Time: 9:51 PM + * To change this template use File | Settings | File Templates. + */ +public class Task2 { + + static Map map = new HashMap(); + + public static void main(String[] args) { + + int t = 100; + + Scanner scanner = new Scanner(System.in); + for (int q = 0; q <= t; q++) { + String str = scanner.nextLine(); + String[] arg = str.split("" ""); + int googler = Integer.valueOf(arg[0]); + int suprising = Integer.valueOf(arg[1]); + int condition = Integer.valueOf(arg[2]); + int found = 0; + + for (int i = 3; i < googler + 3; i++) { + int sum = Integer.valueOf(arg[i]); + int del = sum / 3; + + if (condition == 0) { + found++; + continue; + } + + if (condition == 1 && sum >= 1) { + found++; + continue; + } + + if (sum < 2) + continue; + + if (3 * condition - 4 <= sum && sum < 3 * condition - 2) { + + if (suprising == 0) + continue; + + suprising--; + found++; + } else { + if (sum >= 3 * condition - 2) + found++; + } + } + System.out.println(""Case #"" + (q + 1) + "": "" + found); + } + } +} +" +A22611,"import java.io.*; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class Main { + + public static void main(String[] args) throws Exception { + PrintWriter out = new PrintWriter(new FileOutputStream(new File(""output.txt"")), true); + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File(""input.txt"")))); + // StringTokenizer st = new StringTokenizer(in.readLine()); + // Scanner s = new Scanner(System.in); + int t = Integer.parseInt(in.readLine()); + for(int a = 0;a < t;a++) { + StringTokenizer st = new StringTokenizer(in.readLine()); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + Map> map = new TreeMap<>(); + ArrayList scores = new ArrayList<>(); + + for(int m = 0;m < n;m++) { + int g = Integer.parseInt(st.nextToken()); + scores.add(g); + map.put(g, dec(g)); + //out.println(dec(g).toString()); + } + + int colSurpWinAndWin = 0; + int colSurpWin = 0; + int colWin = 0; + for(int i = 0;i < n;i++) { + if(isDecomposeThere(map.get(scores.get(i)),p,true) && isDecomposeThere(map.get(scores.get(i)),p,false)) { + colSurpWinAndWin++; + }else if(isDecomposeThere(map.get(scores.get(i)),p,true)) { + colSurpWin++; + }else if(isDecomposeThere(map.get(scores.get(i)),p,false)) { + colWin++; + } + } + + //out.println(colSurpWinAndWin+"" ""+colSurpWin+"" ""+colWin); + + if(colSurpWin >= s) { + out.println(""Case #""+(a+1)+"": ""+(s+colWin+colSurpWinAndWin)); + }else{ + s -= colSurpWin; + out.println(""Case #""+(a+1)+"": ""+(colSurpWin+colSurpWinAndWin+colWin)); + } + + } + + } + + public static boolean isDecomposeThere(ArrayList decomposes, int p, boolean surprise) { + for(Decompose dec : decomposes) { + if(dec.a >= p && dec.surprise == surprise) return true; + } + return false; + } + + public static ArrayList dec(int n) { + ArrayList list = new ArrayList<>(); + for(int i = 0;i <= 10;i++) { + for(int j = 0;j <= i;j++) { + for(int k = 0;k <= j;k++) { + if(i - j <= 2 && j - k <= 2 && i - k <= 2 && i+j+k == n) { + boolean surprise = (i-j == 2 || j-k == 2 || i-k == 2); + list.add(new Decompose(i,j,k,surprise)); + } + } + } + } + return list; + } + +} + +class Decompose { + int a, b, c; + boolean surprise; + + public Decompose(int a, int b, int c, boolean surprise) { + this.a = a; + this.b = b; + this.c = c; + this.surprise = surprise; + } + + @Override + public String toString() { + return """"+a+"" ""+b+"" ""+c+"" ""+surprise; + } +}" +A20544,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; +import java.util.TreeSet; + + +public class Main { + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(""C:\\Users\\JiaKY\\Desktop\\out.txt""); + //Scanner in = new Scanner(System.in); + + int t = Integer.valueOf(in.nextLine()); + for(int ii=0;ii=0;i--){ + int valid = 3*p-2; + if(p<2) + valid = p; + int min = 3*p-4; + if(p <= 2) + min = p; + if(score[i] >= valid) + ans++; + else if(s > 0){ + if(score[i] >= min){ + ans++; + s--; + if(s == 0) + break; + } + } + } + out.printf(""Case #%d: %d"",ii+1,ans); + out.println(); + out.flush(); + } + + } + +}" +A21083,"import java.util.*; +import java.io.*; +class dance +{ + public static void main(String[] args) + { + String fileName=""../Problem/B-large.in""; + String outputFile=""output-large.in""; + List data=dance.readFile(fileName); + String ans=""""; + int testCase=Integer.parseInt(data.get(0).toString()); + int indexTC=1; + for(int tc=0;tc=most) count++; + } + return count; + } + public static int[] setNumber(int n,int frag) + { + int[] num=new int[3]; + //System.out.print(""num = ""); + for(int x=0;x<3;x++) + { + num[x]=n; + if(frag>0) { num[x]++; frag--; } + //System.out.print(num[x]+"",""); + } + //System.out.println(""""); + return num; + } + public static void surNumber(int[][] num,int surprise,int googler,int mostNumber) + { + //System.out.println(""================surNumber================""); + for(int y=0;y=mostNumber) + { + if(surprise>0) + { + //System.out.println(""surprise=""+surprise+"" fixnumber""); + if(same!=0) + { + if(num[y][0]==num[y][1] && num[y][1]==num[y][2]) + { + num[y][0]++; + num[y][1]--; + } + else if(num[y][0]==num[y][1]) { if(num[y][2]>num[y][0]) num[y][0]--; else num[y][0]++; } + else if(num[y][0]==num[y][2]) { if(num[y][1]>num[y][0]) num[y][0]--; else num[y][0]++; } + else if(num[y][1]==num[y][2]) { if(num[y][0]>num[y][1]) num[y][2]--; else num[y][2]++; } + } + surprise--; + } + } + } + //System.out.println(""""); + } + } + public static void showList(int N,int[][] num) + { + System.out.println(""===========Show Number=====""); + for(int i=0;i=number[1]) most=number[0]; + else if(number[0]>=number[2]) most=number[0]; + else if(number[1]>=number[2]) most=number[1]; + return most; + } + public static String[] cutString(String st) + { + String s[]=st.split("" ""); + return s; + } + public static List readFile(String pathFile) + { + List data=new ArrayList(); + File file=new File(pathFile); + try + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String text; + while((text = br.readLine()) != null) data.add(text); + br.close(); + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + return data; + } + public static void writeFile(String output,String fileName) + { + try + { + FileWriter fw=new FileWriter(fileName); + BufferedWriter bw=new BufferedWriter(fw); + String new_output[]=output.split(""\n""); + for(int i=0;i= targetScore && scores[i]/3 >= targetScore) + count++; + else if(scores[i] >= targetScore && scores[i]%3 > 0 && scores[i]/3 + 1 >= targetScore) + count++; + else if(scores[i] >= targetScore && numSurprising > 0 && scores[i]%3 == 0 && scores[i]/3 + 1 >= targetScore) + { + count++; + numSurprising--; + } + else if(scores[i] >= targetScore && numSurprising > 0 && scores[i]%3 > 1 && scores[i]/3 + 2 >= targetScore) + { + count++; + numSurprising--; + } + } + + return count; + } + + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + int numCase, numSurprising, numGooglers, targetScore; + int[] totalScores; + + numCase = sc.nextInt(); + + for(int i = 0; i < numCase; i++) + { + numGooglers = sc.nextInt(); + numSurprising = sc.nextInt(); + targetScore = sc.nextInt(); + totalScores = new int[numGooglers]; + for(int j = 0; j < numGooglers; j++) + totalScores[j] = sc.nextInt(); + + System.out.println(""Case #""+(i+1)+"": ""+compute(numGooglers, numSurprising, targetScore, totalScores)); + } + } +}" +A21357,"package com.codejam.googlearse; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class Problem2 { + public static void main(String arg[]) + { + + try{ + FileInputStream fstream = new FileInputStream(""textfile.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter foutstream = new FileWriter(""test1.out""); + BufferedWriter out = new BufferedWriter(foutstream); + + + String strLine,copyStrLine=""""; + int caseCount = -1; + strLine = br.readLine(); + caseCount = Integer.parseInt(strLine); + + for(int j=0; j < caseCount; j++) + //System.out.println (strLine); + { + strLine = br.readLine(); + String[] splitStrings = strLine.split("" ""); + int countGooglers = Integer.parseInt(splitStrings[0]); + int surprisingSet = Integer.parseInt(splitStrings[1]); + int pValue = Integer.parseInt(splitStrings[2]); + int pMaxCount = 0; + + for(int i = 0 ; i < countGooglers; i++ ) + { + int score = Integer.parseInt(splitStrings[3+i]); + int n = score / 3; + if(pValue > score){ + continue; + } + if(score % 3 == 0){ + if(n >= pValue){ + pMaxCount++; + } + if(n == pValue - 1){ + if(surprisingSet > 0){ + pMaxCount++; + surprisingSet--; + } + } + } + else if(score % 3 == 1){ + if(n >= pValue - 1){ + pMaxCount++; + } + } + else{ + if(n >= pValue - 1){ + pMaxCount++; + } + if(n == pValue - 2){ + if(surprisingSet > 0){ + pMaxCount++; + surprisingSet--; + } + } + } + } + System.out.println(""Case #"" + (j + 1) + "": "" + pMaxCount + ""\n""); + out.write(""Case #"" + (j + 1) + "": "" + pMaxCount + ""\n""); + + } + out.close(); + } + catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + + } + } + +} +" +A22052,"import java.io.*; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.InputMismatchException; + +/** + * @author Mikeldi Latorre (mikeldi10@gmail.com) + */ +public class Googlers implements Runnable { + private InputReader in; + private PrintWriter out; + + public static void main(String[] args) { + new Thread(new Googlers()).start(); + } + + public Googlers() { + try { + System.setIn(new FileInputStream(""B-large.in"")); + System.setOut(new PrintStream(new FileOutputStream(""B-large.out""))); +// System.setIn(new FileInputStream(""inputGooglers.txt"")); +// System.setOut(new PrintStream(new FileOutputStream(""outputGooglers.txt""))); + } catch (FileNotFoundException e) { + throw new RuntimeException(); + } + in = new InputReader(System.in); + out = new PrintWriter(System.out); + } + + public void run() { + int numTests = in.readInt(); + for (int testNumber = 0; testNumber < numTests; testNumber++) { + out.println(""Case #"" + (testNumber + 1) + "": ""+algorithm()); + } + out.close(); + } + + private int algorithm(){ + int n = in.readInt(); + int s = in.readInt(); + int p = in.readInt(); + + int nP = 0; //number of scores with at least one P or more + int nS = 0; //number of surprising scores with at least one P + + for (int i = 0; i < n; i++) { + int score = in.readInt(); + if(p<2){ + if(score>=p){ + nP++; + } + }else{ + int nPS = (3*p)-2; //min score for nP + int nSS = (3*p)-4; //min score for nS + if(score >= nPS){ + nP++; + }else if(score >= nSS){ + nS++; + } + } + } + return nP + Math.min(nS, s); + } + + + private static class InputReader { + private InputStream stream; + private byte[] buf = new byte[1000]; + private int curChar, numChars; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + private int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public long readLong() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + long res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + private boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + private String readLine0() { + StringBuffer buf = new StringBuffer(); + int c = read(); + while (c != '\n' && c != -1) { + buf.appendCodePoint(c); + c = read(); + } + return buf.toString(); + } + + public String readLine() { + String s = readLine0(); + while (s.trim().length() == 0) + s = readLine0(); + return s; + } + + public String readLine(boolean ignoreEmptyLines) { + if (ignoreEmptyLines) + return readLine(); + else + return readLine0(); + } + + public BigInteger readBigInteger() { + try { + return new BigInteger(readString()); + } catch (NumberFormatException e) { + throw new InputMismatchException(); + } + } + + public char readCharacter() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + return (char) c; + } + + public double readDouble() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + double res = 0; + while (!isSpaceChar(c) && c != '.') { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } + if (c == '.') { + c = read(); + double m = 1; + while (!isSpaceChar(c)) { + if (c < '0' || c > '9') + throw new InputMismatchException(); + m /= 10; + res += (c - '0') * m; + c = read(); + } + } + return res * sgn; + } + } +} +" +A22763,"import java.io.*; +import java.util.*; + +public class googlers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + + Scanner fe = new Scanner(new FileInputStream( + ""/home/gllera/Desktop/data.in"")); + FileWriter fs = new FileWriter(""/home/gllera/Desktop/data.out""); + + int cases = fe.nextInt(); + + for (int i = 0; i < cases; i++) { + int n = fe.nextInt(); + int s = fe.nextInt(); + int p = fe.nextInt(); + + int sol = 0; + + for (int j = 0; j < n; j++) { + int num = fe.nextInt(); + + if (num == 0) { + if (p == 0) + sol++; + + continue; + } + + if (num / 3 >= p) { + sol++; + continue; + } + + if (num % 3 != 0) + if (num / 3 + 1 >= p) { + sol++; + continue; + } + + if (num % 3 != 1) + if (s != 0) + + if (num % 3 != 0) { + + if (num / 3 + 2 >= p) { + sol++; + s--; + } + + } else { + + if (num / 3 + 1 >= p) { + sol++; + s--; + } + + } + } + + fs.write(""Case #"" + (i + 1) + "": "" + sol + '\n'); + } + + fe.close(); + fs.flush(); + fs.close(); + } + +} +" +A20677,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class Q2 { + private static void run(int CASE) throws Exception { + StringTokenizer st = new StringTokenizer(readLine()); + int count = 0; + int N = parseInt(st.nextToken()); + int S = parseInt(st.nextToken()); + int p = parseInt(st.nextToken()); + for (int i = 0; i < N; i++) { + int total = parseInt(st.nextToken()); + int min = (int) Math.floor(total/3.0); + int max = (int) Math.ceil(total/3.0); + if(max>=p) { + count++; + } else if(max>=p-1 && S>0 && max+1<=total) { + int left = total-(max+1); + if((max+1) - Math.floor(left/2.0) <= 2) { + S--; + count++; + } + } + } + printf(""Case #%d: %d\n"", CASE, count); + } + + //-- Supporting --// + static BufferedReader in; + static PrintWriter out; + static { + try { + in = new BufferedReader(new FileReader(""B-small-attempt2.in"")); + out = new PrintWriter(new FileWriter(""out.txt"")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) throws Exception { + int T = Integer.parseInt(readLine()); + for (int c = 1; c <= T; c++) { + run(c); + } + in.close(); + out.close(); + } + + private static String readLine() throws IOException { + return in.readLine(); + } + + private static void printf(String str, Object... o) { + System.out.printf(str, o); + out.printf(str, o); + } + + private static int parseInt(String t) { + return Integer.parseInt(t); + } +} +" +A20667,"package codeJam2012; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.RandomAccessFile; + +public class B { + + public static void main(String[] args) throws IOException { + RandomAccessFile raf = new RandomAccessFile(""input.in"", ""r""); + PrintWriter raf2 = new PrintWriter(""output.txt""); + int testCases = Integer.parseInt(raf.readLine()); + for(int i=0;i= least - 2) + counter++; + else + if(currentScore >= least - 4 && least-4>0 && S > 0) + { + counter++; + S--; + } + } + raf2.write(""Case #""+(i+1)+"": ""+counter); + if(i!=testCases-1) + raf2.println(); + } + raf.close(); + raf2.close(); + + } +} +" +A20342,"import java.util.Scanner; + + +public class Q2 { + + public static void main(String[] args) { + + Scanner s = new Scanner(Q2.class.getResourceAsStream(""B-large.in"")); + + int n = s.nextInt(); + + int nt = 1; + while (n-- > 0) { + + int resp = 0; + + int ng = s.nextInt(); + int ex = s.nextInt(); + int nm = s.nextInt(); + + if (nm == 0) { + resp = ng; + while (ng-- > 0) { + int nota = s.nextInt(); + } + } else if (nm == 1) { + while (ng-- > 0) { + int nota = s.nextInt(); + if (nota >= 1) { + resp++; + } + } + } else { + while (ng-- > 0) { + int nota = s.nextInt(); + + if (nota >= nm * 3 - 2) { + resp++; + } else if (nota >= nm * 3 - 4 && ex > 0) { + resp++; + ex--; + } + } + } + + System.out.println(""Case #"" + nt + "": "" + resp); + + nt++; + } + + } + +} +" +A21272,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + + +public class Dancers { + + private static final int P_MIN = 0; + private static final int P_MAX = 10; + static final int MAXDIFFERENCEINTRIPLE=4; + static final int REGULARDIFFERENCEINTRIPLE=2; + static final Map thresholdRegular=new HashMap(); + static final Map thresholdSurprising=new HashMap(); + + + public static void main(String[] args) throws IOException { + + calcThresholdSumOfPointsForDifferentPs(); + Vector result=readAndevaluateCases(); + writeResults(result); + + + } + + + // p between 0 and 10-> calculate min sum of points a dancer has to have been able to achieve at least p points once + private static void calcThresholdSumOfPointsForDifferentPs() { + Integer pointThresholdRegular=0; + Integer pointThresholdSurprising=0; + for (int p = P_MIN; p <= P_MAX; p++) { + pointThresholdSurprising=Math.max(3*p-MAXDIFFERENCEINTRIPLE,p); + thresholdSurprising.put(p, pointThresholdSurprising); + + pointThresholdRegular=Math.max(3*p-REGULARDIFFERENCEINTRIPLE,p); + thresholdRegular.put(p, pointThresholdRegular); + } + } + + + private static Vector readAndevaluateCases() throws IOException { + + Vector result = new Vector(); + + try{ + FileInputStream fstream = new FileInputStream(""InputDancers""); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine; + int caseCounter=0; + int numberSurprisingTriplets; + int counterSurprisingT; + int p; + int minPointsNecessaryToBeAbleToAchievePRegulary; + int minPointsNecessaryToBeAbleToAchievePSurprisingly; + int sumOfPointsGoogeler; + int counterPAchieved=0; + //jump over first line + br.readLine(); + while ((strLine = br.readLine()) != null) { + String[] round=strLine.split("" ""); + caseCounter++; + numberSurprisingTriplets=Integer.parseInt(round[1]); + counterSurprisingT=0; + p=Integer.parseInt(round[2]); + minPointsNecessaryToBeAbleToAchievePRegulary=thresholdRegular.get(p); + minPointsNecessaryToBeAbleToAchievePSurprisingly=thresholdSurprising.get(p); + counterPAchieved=0; + for (int i = 3; i < round.length; i++) { + sumOfPointsGoogeler=Integer.parseInt(round[i]); + if(employeAchievedThresholdForRegularT(sumOfPointsGoogeler,minPointsNecessaryToBeAbleToAchievePRegulary)) counterPAchieved++; + else if (suprisingTripletsleft(numberSurprisingTriplets,counterSurprisingT) && employeeAchievedThresholdForSuprisingT(sumOfPointsGoogeler,minPointsNecessaryToBeAbleToAchievePSurprisingly)){ + counterSurprisingT++; + counterPAchieved++; + } + } + //System.out.println(""Case #""+caseCounter+"": ""+counterPAchieved); + result.add(""Case #""+caseCounter+"": ""+counterPAchieved); + + + } + fstream.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + return result; + + } + + private static boolean employeeAchievedThresholdForSuprisingT(int sumOfPointsGoogeler, int minPointsNecessaryToBeAbleToAchievePSurprisingly) { + return sumOfPointsGoogeler>=minPointsNecessaryToBeAbleToAchievePSurprisingly; + } + + private static boolean suprisingTripletsleft(int numberSurprisingTriplets, int counterSurprisingT) { + return numberSurprisingTriplets>counterSurprisingT; + } + + private static boolean employeAchievedThresholdForRegularT(int sumOfPoint, int threshold) { + return sumOfPoint>=threshold; + + } + + private static void writeResults(Vector result) { + try{ + FileWriter fw = new FileWriter(""outputDancers""); + BufferedWriter out = new BufferedWriter(fw); + for (int i = 0; i < result.size(); i++) { + out.write(result.get(i)); + if(i { + public void apply(P param); +} +" +A20531,"package com.gao.t2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.Arrays; + +public class Main { + public static void main(String args[]){ + try{ + FileInputStream fin=new FileInputStream(""C:\\Users\\Gao\\Downloads\\B-large.in""); + BufferedReader br=new BufferedReader(new InputStreamReader(fin)); + FileOutputStream fout=new FileOutputStream(""out.txt""); + BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fout)); + int n=Integer.parseInt(br.readLine()); + for(int i=0;i=2){ + if(xRe<=1){ + if(b+1<=10&&b+1>=P){ + k++; + r++; + } + } else if(xRe==2){ + if(b+2<=10&&b+2>=P){ + k++; + r++; + } + } + }else { + if(xRe>=1&&b<=9){ + b++; + } + if(b>=P){ + r++; + } + } + } + String str=""Case #""+(i+1)+"": ""+r; + bw.write(str); + if(i= p) + y++; + else if (S > 0 && max[t] >= p) { + y++; + S--; + } + } + + System.out.println(""Case #"" + x + "": "" + y); + } + } +} +" +A20656,"/** + * + */ +package google.exercise.b; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +/** + * @author tomtom + * + */ +public class B { + + private static Scanner in; + private static PrintWriter out; + private static int nbCase; + + private static class Solver { + + private int currentNbMax; + private int currentNbMin; + private int treshold; + private int nbGooglers; + private List scores; + private int nbSurprise; + + public void solve() { + for (int i = 1; i <= nbCase; i++) { + out.printf(""Case #%d: %s%n"", i, doSolve()); + in.nextLine(); + } + } + + private int doSolve() { + int nbGoodScorer = 0; + scores = new ArrayList(); + nbGooglers = in.nextInt(); + nbSurprise = in.nextInt(); + treshold = in.nextInt(); + currentNbMax = treshold * 3 - 2; + currentNbMin = ((treshold - 2) < 0 ? 0 : treshold - 2) * 2 + + treshold; + + for (int i = 0; i < nbGooglers; i++) { + scores.add(in.nextInt()); + } + + Collections.sort(scores); + Collections.reverse(scores); + + for (Integer score : scores) { + if (score >= currentNbMax) { + nbGoodScorer++; + } else if (score < currentNbMax && score >= (currentNbMax - 2)) { + if (nbSurprise > 0) { + nbSurprise--; + if (score >= treshold) { + nbGoodScorer++; + } + } + } + } + + return nbGoodScorer; + } + + } + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + in = new Scanner(new File( + ""/Users/tomtom/Desktop/jam-2012/input-B/B-large.in"")); + out = new PrintWriter(new FileOutputStream( + ""/Users/tomtom/Desktop/jam-2012/input-B/B-large.out"")); + + nbCase = in.nextInt(); + in.nextLine(); + + new Solver().solve(); + + in.close(); + out.close(); + } +} +" +A21013,"package qualifiers.dancing; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Dancing +{ + public static void main(String[] args) + { + try + { + FileReader fileReader = new FileReader(""input/B-large.in""); + BufferedReader bufferedReader = new BufferedReader(fileReader); + + String record = null; + int numOfCases = -1; + int lineCount = 0; + List inputList = new ArrayList(); + + // Read input + while ((record = bufferedReader.readLine()) != null) + { + // First row is number of cases + if (lineCount == 0) + { + numOfCases = Integer.valueOf(record); + } + // Input + else + { + inputList.add(record); + } + + lineCount++; + } + fileReader.close(); + + // Perform algo + List results = new ArrayList(); + for (String input : inputList) + { + String[] inputStrArray = input.split("" ""); + int numOfGooglers = Integer.valueOf(inputStrArray[0]); + int numOfSurprisingScores = Integer.valueOf(inputStrArray[1]); + int point = Integer.valueOf(inputStrArray[2]); + + // Constraints + int constraint1 = ((3 * point - 4) < point) ? point : (3 * point - 4); + int constraint2 = (constraint1 < 2) ? constraint1 : constraint1 + 1; + int surePassConstraint = (constraint2 < 2) ? constraint2 : constraint2 + 1; + + // Calc + int result = 0; + int count = 3 + numOfGooglers; + for (int i = 3; i < count; i++) + { + int totalScoreOfGoogler = Integer.valueOf(inputStrArray[i]); + // Sure pass + if (totalScoreOfGoogler >= surePassConstraint) + { + result++; + } + // Sure fail + else if (totalScoreOfGoogler < constraint1) + { + continue; + } + // Surprise score + else if (totalScoreOfGoogler == constraint1 || totalScoreOfGoogler == constraint2) + { + if (numOfSurprisingScores > 0) + { + result++; + numOfSurprisingScores--; + } + else + { + continue; + } + } + } + + results.add(result); + } + + // Write output + FileWriter fileWriter = new FileWriter(""output/results.out""); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + for (int i = 0; i < results.size(); i++) + { + int result = results.get(i); + bufferedWriter.write(""Case #"" + (i+1) + "": "" + result); + if (i < results.size() - 1) bufferedWriter.write(""\n""); + } + //Close the output stream + bufferedWriter.close(); + } + catch (IOException e) + { + System.out.println(""IOException error!""); + e.printStackTrace(); + } + } +} +" +A20542,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Scanner; + + +public class DancingGooglers { + + + public static void main(String[] args) { +// Scanner sc = new Scanner(System.in); + Scanner sc; + try { + sc = new Scanner(new FileInputStream(""B-large.in"")); + } catch (FileNotFoundException e) { + sc = new Scanner(System.in); // file not exist, so get input from console + } + + Writer out; + + try { + out = new OutputStreamWriter(new FileOutputStream(""B-large.out"")); + } catch (FileNotFoundException e) { + out = new OutputStreamWriter(System.out); // use console + } + + int T = sc.nextInt(); + + for (int t = 0; t < T; t++) { + int N = sc.nextInt(); // num dancers + int S = sc.nextInt(); // num surprises + int P = sc.nextInt(); // minimum best result + + int[] totals = new int[N]; // total scores for all dancers; + int count = 0; + + for (int n = 0; n < N; n++) + totals[n] = sc.nextInt(); + + quickSortDesc(totals, 0, totals.length - 1); + + for (int n = 0; n < N; n++) { + if (findBest(totals[n]) >= P) + count++; + else if (S > 0) { + if (findSurpriseBest(totals[n]) >= P) { + count++; + S--; + } + } + } + + // output + System.out.println(""Case #"" + (t + 1) + "": "" + count); + try { + out.write(""Case #"" + (t + 1) + "": "" + count + ""\n""); + } catch (IOException e) { + // do nothing + } + } + + + try { + out.close(); + } catch (IOException e) { + // do nothing + } + } + + public static void quickSortDesc (int arr[], int left, int right) { + int i = left, j = right, tmp; + int pivot = arr[(left + right) / 2]; + + while (i < j) { + while (arr[i] > pivot) + i++; + while (arr[j] < pivot) + j--; + if (j >= i) { + tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + i++; + j--; + } + } + + if (left < j) + quickSortDesc(arr, left, j); + if (i < right) + quickSortDesc(arr, i, right); + } + + static Boolean canSurprise(int t) { + return (t%3 != 1); + } + + static int findBest(int t) { + if (t > 0) { + if (t%3 == 0) + return t/3; + else return t/3 + 1; + } else return t; + } + + static int findSurpriseBest(int t) { + if (t > 0) { + if (t%3 == 2) + return t/3 + 2; + else return t/3 + 1; + } else return t; + } + +} +" +A21378,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; + +public class Google { + public static void main(String args[]) throws Exception { + Google g = new Google(); + g.run(""texto.txt""); + } + + void run(String file) throws Exception { + FileReader fr = new FileReader(file); + BufferedReader br = new BufferedReader(fr); + + br.readLine(); + String line = br.readLine(); + + + FileWriter fw = new FileWriter(""saida.txt""); + PrintWriter pw = new PrintWriter(fw); + + + int n2 = 1; + while(line != null) { + System.out.println(""dddd""); + String[] nums = line.split("" ""); + int n = Integer.parseInt(nums[0]); + int numSurprising = Integer.parseInt(nums[1]); + int p = Integer.parseInt(nums[2]); + int output = 0; + + int numNotas = nums.length - 3; + int[] notas = new int[numNotas]; + + for(int i = 3, j=0; i < nums.length; i++,j++) { + notas[j] = Integer.parseInt(nums[i]); + } + + ArrayList possiveis = new ArrayList(); + ArrayList talvez = new ArrayList(); + + if(p==0) { + possiveis.add(0); + } + if(p==1) { + possiveis.add(3); + possiveis.add(2); + possiveis.add(1); + } else if(p>1) { + possiveis.add(p + p + p); + possiveis.add(p + p + (p-1)); + possiveis.add(p + (p-1) + (p-1)); + + talvez.add(p + p + (p-2)); + talvez.add(p + (p-1) + (p-2)); + talvez.add(p + (p-2) + (p-2)); + } + + for(int i = 0; i < notas.length; i++) { + if(notas[i] > (p+p+p)) { + output++; + } else if(possiveis.contains(notas[i])) { + output++; + } else if(talvez.contains(notas[i])) { + if(numSurprising > 0) { + output++; + numSurprising--; + } + } + } + + pw.println(""Case #"" + n2 + "": "" + output); + + line = br.readLine(); + n2++; + } + + pw.close(); + br.close(); + } +}" +A20494,"import java.util.*; + +public class B { + public static void main (String [] args) { + + Scanner s = new Scanner(System.in); + int T = s.nextInt(); + + int[] normalBestScores = new int[]{ + 0, //0: (0, 0, 0) + 1, //1: (1, 0, 0) + 1, //2: (1, 1, 0) + 1, //3: (1, 1, 1) + 2, //4: (2, 1, 1) + 2, //5: (2, 2, 1) + 2, //6: (2, 2, 2) + 3, //7: (3, 2, 2) + 3, //8: (3, 3, 2) + 3, //9: (3, 3, 3) + 4, //10: (4, 3, 3) + 4, //11: (4, 4, 3) + 4, //12: (4, 4, 4) + 5, //13: (5, 4, 4) + 5, //14: (5, 5, 4) + 5, //15; (5, 5, 5) + 6, //16: (6, 5, 5) + 6, //17: (6, 6, 5) + 6, //18: (6, 6, 6) + 7, //19: (7, 6, 6) + 7, //20: (7, 7, 6) + 7, //21: (7, 7, 7) + 8, //22: (8, 7, 7) + 8, //23: (8, 8, 7) + 8, //24: (8, 8, 8) + 9, //25: (9, 8, 8) + 9, //26: (9, 9, 8) + 9, //27: (9, 9, 9) + 10, //28: (10, 9, 9) + 10, //29: (10, 10, 9) + 10 //30: (10, 10, 10) + }; + + int[] surpriseBestScores = new int[] { + -1, //0: None + -1, //1: None + 2, //2: (2, 0, 0) + 2, //3: (2, 1, 0) + 2, //4: (2, 2, 0) + 3, //5: (3, 1, 1) + 3, //6: (3, 2, 1) + 3, //7: (3, 3, 1) + 4, //8: (4, 2, 2) + 4, //9: (4, 3, 2) + 4, //10: (4, 4, 2) + 5, //11: (5, 3, 3) + 5, //12: (5, 4, 3) + 5, //13: (5, 5, 3) + 6, //14: (6, 4, 4) + 6, //15: (6, 5, 4) + 6, //16: (6, 6, 4) + 7, //17: (7, 5, 5) + 7, //18: (7, 6, 5) + 7, //19: (7, 7, 5) + 8, //20: (8, 6, 6) + 8, //21: (8, 7, 6) + 8, //22: (8, 8, 6) + 9, //23: (9, 7, 7) + 9, //24: (9, 8, 7) + 9, //25: (9, 9, 7) + 10, //26: (10, 8, 8) + 10, //27: (10, 9, 8) + 10, //28: (10, 10, 8) + -1, //29: None + -1 //30: None + }; + + for (int t = 1; t <= T; t++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] tp = new int[N]; + for (int i = 0; i < N; i++) + tp[i] = s.nextInt(); + Arrays.sort(tp); + int ans = 0; + for (int i = N-1; i >= 0; i--) { + if (normalBestScores[tp[i]] >= p) { + ans++; + } else if (S > 0 && tp[i] >= 2 && tp[i] <= 28) { + S--; + if (surpriseBestScores[tp[i]] >= p) { + ans++; + } + } + } + + System.out.println(""Case #"" + t + "": ""+ans); + } + } +}" +A22631,"package codejam.y2012.r0; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Scanner; + +/** + * @author Ilya Lantuh + */ +public class Task2 { + + static Scanner input; + static BufferedWriter output; + + public static void main(String[] args) throws Exception { + input = new Scanner(new File(""D:/Programming/Projects/CodeJam/input.txt"")); + output = new BufferedWriter(new FileWriter(""D:/Programming/Projects/CodeJam/output.txt"")); + int T = input.nextInt(); + for (int i = 1; i <= T; i++) { + String result = getResult(); + System.out.println(""Case #"" + i + "": "" + result); + output.write(""Case #"" + i + "": "" + result); + output.newLine(); + } + output.close(); + } + + public static String getResult() { + int N = input.nextInt(); + int S = input.nextInt(); + int p = input.nextInt(); + List scores = getList(N); + int s = 0; + int res = 0; + for (int i = 0; i < N; i++) { + int num = scores.get(i); + if (num >= p * 3) res++; + else if (num == p + p + (p-1)) res++; + else if (num == p + (p-1) + (p-1)) res++; + else if ((num == p + (p-1) + (p-2)) || (num == p + (p-2) + (p-2))) { + if ((s < S) && (p-2 >= 0)) { + s++; + res++; + } + } + } + return String.valueOf(res); + } + + public static List getList(int size) { + List result = new ArrayList(size); + for (int i = 0; i < size; i++) { + result.add(input.nextInt()); + } + return result; + } + +} +" +A22465,"import java.io.IOException; +import java.util.List; + +public class StoreCredit extends JamProblem { + public static void main(String[] args) throws IOException { + StoreCredit problem= new StoreCredit(); + problem.go(); + } + + @Override + String solveCase(JamCase jamCase) { + StoreCreditCase cas = (StoreCreditCase) jamCase; + for (int i=0; i file, int line) { + StoreCreditCase cas = new StoreCreditCase(); + String fist = file.get(line); + String second = file.get(line+1); + String third = file.get(line+2); + cas.credit= Integer.parseInt(fist); + cas.lineCount = 3; + cas.itemCount = Integer.parseInt(second); + cas.prices = JamUtil.parseIntList(third, cas.itemCount); + return cas; + } +} + +class StoreCreditCase extends JamCase { + int itemCount; + int[] prices; + public int credit; +} +" +A22501,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class B { + + private static final String PROBLEM_NAME = ""B-large""; + + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader r = new BufferedReader(new FileReader(PROBLEM_NAME + "".in"")); + BufferedWriter w = new BufferedWriter(new FileWriter(PROBLEM_NAME + "".out"")); + int testsNumber = Integer.parseInt(r.readLine()); + for (int i = 0; i < testsNumber; ++i) { + String[] line = r.readLine().split("" ""); + int n = Integer.parseInt(line[0]); + int s = Integer.parseInt(line[1]); + int p = Integer.parseInt(line[2]); + int good = 0; + int almost = 0; + for (int j = 0; j < n; ++j) { + int sum = Integer.parseInt(line[3 + j]); + if (sum % 3 == 0) { + if (sum / 3 >= p) { + ++good; + } else if (sum / 3 > 0 && sum / 3 + 1 >= p) { + ++almost; + } + continue; + } + if (sum % 3 == 1) { + if (sum / 3 + 1 >= p) { + ++good; + } + continue; + } + if (sum % 3 == 2) { + if (sum / 3 + 1 >= p) { + ++good; + } else if (sum / 3 + 2 >= p) { + ++almost; + } + continue; + } + } + w.write(""Case #"" + (i + 1) + "": ""); + w.write(good + ((almost < s)? almost: s) + """"); + w.newLine(); + } + r.close(); + w.close(); + } + +} +" +A22415,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.PriorityQueue; +import java.util.TreeMap; +import java.util.Vector; + + +public class Dancers +{ + + /** + * @param args + */ + public static void main(String[] args) + { + BufferedReader fin; + try + { + BufferedWriter fout = new BufferedWriter(new FileWriter(""C:\\Users\\Nick\\Desktop\\CodeJam2012\\BLarge-output.txt"")); + fin = new BufferedReader(new FileReader(args[0])); + int tests = Integer.parseInt(fin.readLine()); + for(int t = 0; t < tests; t++) + { + String line = fin.readLine(); + String[] splitLine = line.split("" ""); + int numScores = Integer.parseInt(splitLine[0]); + int numSurprises = Integer.parseInt(splitLine[1]); + int targetScore = Integer.parseInt(splitLine[2]); + int numAboveScore = 0; + Vector scores = new Vector(); + for(int s = 0; s < numScores;s++) + scores.add(Integer.parseInt(splitLine[s + 3])); + //Fix score of 0 cases + if(targetScore > 0) + while(scores.contains(0)) + scores.remove(new Integer(0)); + //Get all possible >= target score without surprises + for(int s = 0; s < scores.size(); s++) + { + if((scores.get(s) % 3 == 0 && scores.get(s) / 3 >= targetScore) || + (scores.get(s) % 3 == 1 && scores.get(s) / 3 + 1 >= targetScore) || + (scores.get(s) % 3 == 2 && scores.get(s) / 3 + 1 >= targetScore)) + { + numAboveScore++; + scores.remove(s); + s--; + } + } + //Now add in surprises >= target score + for(int s = 0; s < scores.size() && numSurprises > 0; s++) + { + if((scores.get(s) % 3 == 0 && scores.get(s) / 3 + 1 >= targetScore) || + (scores.get(s) % 3 == 1 && scores.get(s) / 3 + 1 >= targetScore) || + (scores.get(s) % 3 == 2 && scores.get(s) / 3 + 2 >= targetScore)) + { + numAboveScore++; + numSurprises--; + } + } + + //Print output + fout.write(""Case #"" + (t+1) + "": "" + numAboveScore); + fout.newLine(); + } + fout.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + +} +" +A20669,"package nl.maartenvangrootel.googlecodejam.qualifiers.dancing; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.regex.Pattern; + +/** + * Hello world! + * + */ +public class DancingScores { + private File file; + + private static Pattern pattern = Pattern.compile(""[\\ ]""); + + public DancingScores(String filename) { + if (filename == null) + throw new IllegalArgumentException(""filename should not be null""); + + file = new File(filename); + if (!(file.exists() && file.isFile())) + throw new IllegalArgumentException(String.format( + ""'%s' does not exist or is not a file."", filename)); + + } + + private BufferedReader getReader() { + BufferedReader reader = null; + try { + FileReader stream = new FileReader(file); + reader = new BufferedReader(stream); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + return reader; + } + + public String calculateResult() { + BufferedReader reader = getReader(); + + StringBuilder builder = new StringBuilder(); + try { + int T = Integer.parseInt(reader.readLine()); + int i = 1; + String line; + while ((line = reader.readLine()) != null) { + if (i > 1) { + builder.append(""\n""); + } + builder.append(""Case #""); + builder.append(i); + builder.append("": ""); + builder.append(parseLine(line)); + i++; + } + } catch (IOException e) { + e.printStackTrace(); + } + + return builder.toString(); + } + + public static int parseLine(String line) { + String[] input = pattern.split(line); + int googlers = Integer.parseInt(input[0]); + int maxSurprises = Integer.parseInt(input[1]); + int bestResultGoal = Integer.parseInt(input[2]); + + int[] totalResults = new int[googlers]; + int[] totalResultsMinusGoal = new int[googlers]; + + int surpriseOrNot = 0, not = 0, normal = 0, surpriseOrNormal = 0; + + for (int i = 0; i < googlers; i++) { + // totalResults[i] = Integer.parseInt(input[i + 3]); + // totalResultsMinusGoal[i] = totalResults[i] - bestResultGoal; + int result = Integer.parseInt(input[i + 3]); + int resultMinusGoal = result - bestResultGoal; + + if (resultMinusGoal < 0 + || resultMinusGoal < (bestResultGoal - 2) * 2) { + not++; + } else if (resultMinusGoal < (bestResultGoal + (bestResultGoal - 2))) { + surpriseOrNot++; + } else if (resultMinusGoal == (bestResultGoal + (bestResultGoal - 2))) { + surpriseOrNormal++; + } else { + normal++; + } + + } + int retVal = 0; + if (surpriseOrNot == maxSurprises) { + // exactly enough surpriseOrNot: all surpriseOrNormal are normal + retVal = normal + surpriseOrNormal + surpriseOrNot; + } else if (surpriseOrNot > maxSurprises) { + // too many surpriseOrNot, all surpriseOrNormals are normal, some + // surpriseOrNot are not. + retVal = normal + surpriseOrNormal + maxSurprises; + } else if (surpriseOrNot < maxSurprises) { + // Too little surprisesOrNot, take them from surpriseOrNormal, the + // rest is Normal. + retVal = normal + surpriseOrNot + surpriseOrNormal; + } + return retVal; + } + + public static void main(String[] args) { + if (args.length > 0) { + DancingScores starter = new DancingScores(args[0]); + String result = starter.calculateResult(); + + System.out.println(result); + + } else { + System.err.println(""No arguments given.""); + } + + } +} +" +A20914,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + + +public class ProblemB { + public int[] deriveScores(int totalScore) { + if (totalScore < 0 || totalScore > 30) { + throw new IllegalArgumentException(""invalid totalScore passed: "" + totalScore); + } + + int n = totalScore / 3; + int r = totalScore % 3; + int[] scores = new int[3]; + + scores[0] = n; + scores[1] = n + r / 2; + scores[2] = n + r - (r / 2); + +// if (n == 0) { +// if (surprise) { +// scores[2] += r; +// } else { +// scores[1] += r / 2; +// scores[2] += r - (r / 2); +// } +// } else if (n == 9) { +// scores[1] += r / 2; +// scores[2] += r - (r / 2); +// } else if (0 < n && n < 9) { +// if (surprise) { +// if (r == 0) { +// scores[0]--; +// scores[2]++; +// } else if (r == 1) { +// scores[0]--; +// scores[1]++; +// scores[2] += 1; +// } else if (r == 2) { +// scores[2] += r; +// } +// } else { +// scores[1] += r / 2; +// scores[2] += r - (r / 2); +// } +// } + + return scores; + } + + public int[] makeSurprise(int[] scores) { + int[] newScores = scores.clone(); + + if (scores[0] >= 1 && scores[2] <= 9) { + if (scores[2] == scores[0]) { + newScores[0]--; + newScores[2]++; + } else if (scores[2] == scores[1]) { + newScores[1]--; + newScores[2]++; + } + } + + return newScores; + } + + public boolean checkIfSurprisingScore(int[] scores) { + return scores[scores.length - 1] - scores[0] >= 2; + } + + public void solve(String inputFileName, String outputFileName) { + try { + BufferedReader reader = new BufferedReader(new FileReader(new File(inputFileName))); + BufferedWriter writer = new BufferedWriter(new FileWriter(outputFileName)); + + int testCount = Integer.parseInt(reader.readLine()); + for (int i = 0; i < testCount; i++) { + String testCase = reader.readLine(); + String[] fields = testCase.split("" ""); + int manCount = Integer.parseInt(fields[0]); + int surpriseCount = Integer.parseInt(fields[1]); + int bestScore = Integer.parseInt(fields[2]); + int bestScoreCount = 0; + + for (int j = 0; j < manCount; j++) { + int totalScore = Integer.parseInt(fields[j + 3]); + int[] scores = this.deriveScores(totalScore); + + if (scores[2] < bestScore) { + if (surpriseCount > 0) { + int[] tempScores = this.makeSurprise(scores); + if (tempScores[2] >= bestScore) { + scores = tempScores; + surpriseCount--; + } + } + } + + if (scores[2] >= bestScore) { + bestScoreCount++; +// System.out.println(totalScore + "", best""); + } else { +// System.out.println(totalScore); + } + } + + writer.write(""Case #"" + (i + 1) + "": "" + bestScoreCount); + writer.newLine(); + } + + reader.close(); + writer.close(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + public static void main(String[] args) { + ProblemB problem = new ProblemB(); +// problem.solve(""B-small-attempt.in"", ""B-small-attempt.out""); +// problem.solve(""B-small-attempt0.in"", ""B-small-attempt0.out""); + problem.solve(""B-large.in"", ""B-large.out""); +// problem.solve(""B-small-attempt.in"", ""B-small-attempt.out""); +// problem.solve(""B-small-attempt.in"", ""B-small-attempt.out""); + } +} +" +A21304," + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.HashMap; + +public class Googlers { + public static void main(String[] args) throws Exception{ + String inputFile = ""B-large.in""; + + BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile))); + BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""output""))); + long num_cases = Long.parseLong(input.readLine()); + int current_case = 0; + + while (current_case < num_cases){ + current_case++; + + String[] fields = input.readLine().split("" ""); + int N = Integer.parseInt(fields[0]); + int S = Integer.parseInt(fields[1]); + int p = Integer.parseInt(fields[2]); + + int max = 0; + int sc = 0; + for (int i = 0; i < N; i++){ + int v = Integer.parseInt(fields[3+i]); + double d = Math.ceil(v/3.0); + if (d >= p){ + max++; + } else { + if (d != 0 && d == p-1){ + if (sc < S){ + max++; + sc++; + } + } + } + } + System.out.println(""Case #"" + current_case + "": "" + max); + output.write(""Case #"" + current_case + "": "" + max + ""\n""); + } + output.close(); + } +} +" +A21582,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.dancingwiththegooglers; + +/** + * + * @author jim + */ +public class DataRow { + + public final int N; + public final int S; + public final int p; + public final int[] t; + + public DataRow(String in) { + String[] parts = in.split("" ""); + N = Integer.parseInt(parts[0]); + S = Integer.parseInt(parts[1]); + p = Integer.parseInt(parts[2]); + t = new int[N]; + for (int i = 3; i < N + 3; i++) + t[i - 3] = Integer.parseInt(parts[i]); + } + +} +" +A21335,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; + +public class Main { + + public static void main(String[] args) throws Exception { + + FileReader in = new FileReader(""F:\\download\\B-large.in""); + BufferedReader br = new BufferedReader(in); + FileWriter out = new FileWriter(""F:\\download\\out.txt""); + BufferedWriter bw = new BufferedWriter(out); + + int t = Integer.parseInt(br.readLine()); + for (int c = 0; c < t; c++){ + String line = br.readLine(); + StringTokenizer aSt = new StringTokenizer(line, "" ""); + int number = Integer.valueOf(aSt.nextToken()).intValue(); + int surprise = Integer.valueOf(aSt.nextToken()).intValue(); + int p = Integer.valueOf(aSt.nextToken()).intValue(); + + int sum_ok = 0; + int sum_surprise = 0; + for (int n = 0; n < number; n++){ + int ti = Integer.valueOf(aSt.nextToken()).intValue(); + int judge = judge(ti, p); + switch (judge){ + case 2: + sum_ok++; + break; + case 1: + sum_surprise++; + break; + default: + break; + } + } + + int result; + if (sum_surprise <= surprise){ + result = sum_ok + sum_surprise; + } + else{ + result = sum_ok + surprise; + } + + bw.write(String.format(""Case #%d: %d\n"", c+1, result)); + } + + br.close(); + in.close(); + bw.close(); + out.close(); + + } + + private static int judge(int score, int p){ + int p1 = (p-1 >= 0) ? p-1: 0; + if (score >= p + p1 + p1){ + return 2; + } + int p2 = (p-2 >= 0) ? p-2: 0; + if (score >= p + p2 + p2){ + return 1; + } + return 0; + } + +} +" +A22523,"package jp.ne.sakura.yuki2006.CodeJam; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class CodeJam { + private FileWriter file; + static int caseNumber = 0; + private Scanner stdIn; + + private void write(String data) { + caseNumber++; + + try { + file.append(""Case #""); + file.append(String.valueOf(caseNumber)); + file.append("": ""); + file.append(data); + file.append(""\n""); + file.flush(); + + } catch (IOException e) { + // TODO 自動生成された catch ブロック + e.printStackTrace(); + } + + } + + public CodeJam(ITestCase test, String fileName) { + try { + file = new FileWriter(fileName); + } catch (IOException e) { + e.printStackTrace(); + } + stdIn = new Scanner(System.in); + stdIn.nextLine(); + while (stdIn.hasNext()) { + + write(test.testCase(stdIn)); + } + } + +} +" +A20496,"package _2012_qual; + +import static java.lang.Math.*; +import java.util.*; +import java.io.*; + + +public class B { + + boolean showDebug = true; + static boolean fromFile = false; + static String filePath = ""E:/AAA/_gcj/""; + static boolean intoFile = !false; + + public void solve() throws Exception { + int testCasesCnt = nextInt(); + nextCase: for(int testCase=1; testCase<=testCasesCnt; testCase++) { + print(""Case #""+testCase+"": ""); + + int n = nextInt(), s = nextInt(), p =nextInt(); + int lim = p+2*max(0,(p-1)), lims = p+2*max(0,(p-2)); + int res = 0; + for (int i=0; i=lim) res++; + else if (t>=lims && s>0) { + res++; s--; + } + } + println(res); + + } + } + + + + //////////////////////////////////////////////////////////////////////////// + + double EPS = 1e-7; + int INF = Integer.MAX_VALUE; + long INFL = Long.MAX_VALUE; + double INFD = Double.MAX_VALUE; + + + int absPos(int num) { + return num<0 ? 0:num; + } + long absPos(long num) { + return num<0 ? 0:num; + } + double absPos(double num) { + return num<0 ? 0:num; + } + + int min(int... nums) { + int r = Integer.MAX_VALUE; + for (int i: nums) + if (ir) r=i; + return r; + } + long minL(long... nums) { + long r = Long.MAX_VALUE; + for (long i: nums) + if (ir) r=i; + return r; + } + double minD(double... nums) { + double r = Double.MAX_VALUE; + for (double i: nums) + if (ir) r=i; + return r; + } + + long sumArr(int[] arr) { + long res = 0; + for (int i: arr) + res+=i; + return res; + } + long sumArr(long[] arr) { + long res = 0; + for (long i: arr) + res+=i; + return res; + } + double sumArr(double[] arr) { + double res = 0; + for (double i: arr) + res+=i; + return res; + } + + long partsFitCnt(long partSize, long wholeSize) { + return (partSize+wholeSize-1)/partSize; + } + + boolean odd(long num) { + return (num&1)==1; + } + + boolean hasBit(int num, int pos) { + return (num&(1<0; + } + + long binpow(long a, int n) { + long r = 1; + while (n>0) { + if ((n&1)!=0) r*=a; + a*=a; + n>>=1; + } + return r; + } + + boolean isLetter(char c) { + return (c>='a' && c<='z') || (c>='A' && c<='Z'); + } + boolean isLowercase(char c) { + return (c>='a' && c<='z'); + } + boolean isUppercase(char c) { + return (c>='A' && c<='Z'); + } + boolean isDigit(char c) { + return (c>='0' && c<='9'); + } + + boolean charIn(String chars, String s) { + if (s==null) return false; + if (chars==null || chars.equals("""")) return true; + for (int i=0; i=bufLim) fillBuf(); + return (char)buf[bufPos++]; + } + boolean hasInput() throws IOException { + if (bufPos>=bufLim) fillBuf(); + return bufPos' ') { + sb.append(c); + c = inputReader.read(); + } + return new String(sb); + } + String nextLine() throws IOException { + StringBuilder sb = new StringBuilder(); + char c = inputReader.read(); + while (c<=' ') c=inputReader.read(); + while (c!='\n' && c!='\r') { + sb.append(c); + c = inputReader.read(); + } + return new String(sb); + } + int nextInt() throws IOException { + int r = 0; + char c = nextNonWhitespaceChar(); + boolean neg = false; + if (c=='-') neg=true; + else r=c-48; + c = nextChar(); + while (c>='0' && c<='9') { + r*=10; + r+=c-48; + c=nextChar(); + } + return neg ? -r:r; + } + long nextLong() throws IOException { + long r = 0; + char c = nextNonWhitespaceChar(); + boolean neg = false; + if (c=='-') neg=true; + else r = c-48; + c = nextChar(); + while (c>='0' && c<='9') { + r*=10L; + r+=c-48L; + c=nextChar(); + } + return neg ? -r:r; + } + double nextDouble() throws NumberFormatException, IOException { + return Double.parseDouble(nextWord()); + } + int[] nextArr(int size) throws NumberFormatException, IOException { + int[] arr = new int[size]; + for (int i=0; i list = new ArrayList(); + int sMax = -1; + int uMax = -1; + + void add(int a, int b, int c) { + list.add(new Triple(a, b, c)); + } + + int getSurpriseMaximum() { + if (sMax == -1) { + sMax = 0; + for (Triple curr : list) { + if (curr.isSurprising()) { + sMax = Math.max(curr.max, sMax); + } + } + } + return sMax; + } + + int getUsualMaximum() { + if (uMax == -1) { + uMax = 0; + for (Triple curr : list) { + if (!curr.isSurprising()) { + uMax = Math.max(curr.max, uMax); + } + } + } + return uMax; + } + } + + static final int MAX_COUNT = 100; + static final int MAX_POINTS = 10; + + Point p[] = new Point[31]; + + int res[][]; + int scores[]; + + int gen(int idx, int remainSurp, int least) { + if (idx == -1) { + if (remainSurp == 0) { + return 0; + } else { + return Integer.MIN_VALUE / 10; + } + } + if (res[idx][remainSurp] != -1) { + return res[idx][remainSurp]; + } + int ans = 0; + int score = scores[idx]; + int maxSurp = p[score].getSurpriseMaximum(); + int maxUsual = p[score].getUsualMaximum(); + + if (remainSurp != 0) { + if (maxUsual >= least || maxSurp >= least) { + ans++; + } + ans += gen(idx - 1, remainSurp - 1, least); + } + int ans2 = 0; + if (maxUsual >= least) { + ans2++; + } + ans2 += gen(idx - 1, remainSurp, least); + + res[idx][remainSurp] = Math.max(ans, ans2); + return res[idx][remainSurp]; + } + + + int solveOne() { + scores = new int[in.nextInt()]; + int nSurprising = in.nextInt(); + int least = in.nextInt(); + for (int i = 0; i < scores.length; i++) { + scores[i] = in.nextInt(); + } + + res = new int[scores.length][nSurprising + 1]; + for (int []ar : res) { + Arrays.fill(ar, -1); + } + + return gen(scores.length - 1, nSurprising, least); + } + + void solve() { + for (int i = 0; i < p.length; i++) { + p [i] = new Point(); + } + for (int i = 0; i <= 10; i++) { + for (int j = i; j <= 10; j++) { + for (int k = j; k <= 10; k++) { + if (k - i <= 2) { + int sum = i + j + k; + p[sum].add(i, j, k); + } + } + } + } + + int nTests = in.nextInt(); + in.nextLine(); + for (int i = 0; i < nTests; i++) { + out.println(""Case #"" + (i+1) + "": "" + solveOne()); + } + } + + void run() { + try { + in = new Scanner(new FileReader(""C:/GCJ/"" + problemName + "".in"")); + out = new PrintWriter(new FileWriter(""C:/GCJ/"" + problemName + "".out"")); + } catch (IOException e) { + in = new Scanner(System.in); + out = new PrintWriter(System.out); + // throw new Error(); + } + + try { + solve(); + } finally { + out.close(); + } + } + + public static void main(String[] args) { + new Main().run(); + } +}" +A20525,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package practicejam; + +import java.io.*; + +/** + * + * @author GreenTie + */ +public class PracticeJam { + +// public int[] compute(int[][] input){ +// int[] result=new int[input.length]; +// for(int i=0;i= 'A' && x <= 'Z') { + sb.append(DicB[x - 'A']); + } else if (x >= 'a' && x <= 'z') { + sb.append(DicA[x - 'a']); + } else { + sb.append(x); + } + } + return sb.toString(); + } + + public static int problemB(String G){ + int result=0; + String[] temp=G.split("" ""); + int N=Integer.parseInt(temp[0]); + int S=Integer.parseInt(temp[1]); + int p=Integer.parseInt(temp[2]); + int[] scr=new int[N]; + int count=N; + int suprise=S; + for(int i=0;i=29){result++;count--;} + else if(scr[i]==1){count--;if(p<=1)result++;} + else if(scr[i]==0){count--;if(p==0)result++;} + else if(Normal[scr[i]]>=p){ + result++;count--; + } + else{ + if(Surprising[scr[i]]>=p&&suprise>0){ + result++; + count--; + suprise--; + } + } + } + + return result; + } + + + /** + * @param args the command line arguments + */ + public static void mainA(String[] args) { + String[] x = {""ejp mysljylc kd kxveddknmc re jsicpdrysi"", ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"", ""de kr kd eoya kw aej tysr re ujdr lkgc jv""}; + for (String G : x) { + System.out.println(problemA(G)); + } + } + + public static void main(String[] args) throws FileNotFoundException, IOException { + BufferedReader br = new BufferedReader(new FileReader(new File(""B-large.in""))); + int x = Integer.parseInt(br.readLine()); + StringBuilder sb = new StringBuilder(); + for (int i = 1; i <= x; i++) { + //String[] temp=br.readLine().trim().split("" ""); + sb.append(""Case #"").append(i).append("": "").append(problemB(br.readLine())); + sb.append('\n'); + //sb.append(""Case #"").append(i).append("": "").append(Result[compute(Integer.parseInt(temp[0]),Integer.parseInt(temp[1]))]).append('\n'); + //System.out.printf(""Case #%d: %s\n"",i,Result[compute(Integer.parseInt(temp[0]),Integer.parseInt(temp[1]))]); + } + System.setOut(new PrintStream(new File(""B-large.out""))); + System.out.print(sb.toString()); + br.close(); + + } +} +" +A20769,"import java.util.Scanner; +import java.io.*; + + +public class B{ + public static int calculate(String str){ + String[] numbers = str.split("" ""); + int googlers = Integer.parseInt(numbers[0]); + int surprising = Integer.parseInt(numbers[1]); + int p = Integer.parseInt(numbers[2]); + int loc = 3; + int ret = 0; + + for(int i = 0; i < googlers; i++){ + int total = Integer.parseInt(numbers[loc]); + loc ++; + if(total % 3 == 0){ + if((total / 3) > (p - 1)) + ret++; + else if((total / 3) == (p - 1) && surprising > 0 && total != 0 && total != 30){ + surprising--; + ret++; + } + } + else if(total % 3 == 1){ + if((total / 3) > (p - 2)) + ret++; + } + else if(total % 3 == 2){ + if((total / 3) > (p - 2)) + ret++; + else if((total / 3) == (p - 2) && surprising > 0 && total != 29){ + surprising--; + ret++; + } + } + } + return ret; + } + + public static void main(String[] args){ + Scanner sc = null; + String next; + int out; + try{ + sc = new Scanner(new File(""B-large.in"")); + int cases = Integer.parseInt(sc.nextLine()); + int current = 0; + + + FileWriter fs = new FileWriter(""output.txt""); + BufferedWriter buff = new BufferedWriter(fs); + while(current < cases){ + next = sc.nextLine(); + current++; + out = calculate(next); + buff.write(""Case #"" + current + "": "" + out + ""\n""); + } + buff.close(); + } + catch(Exception ex){} + } +}" +A23033," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + +public class DancingWithTheGooglers +{ + static HashMap absoluteMap = new HashMap(); + static HashMap surpriseMap = new HashMap(); + + static class TestCaseData + { + int numberOfGooglers; + int surprisingTripletsOfScores; + int minBestResult; + int[] scores; + + int minBestResultCount; + + static TestCaseData readTestCaseData(BufferedReader IN) throws IOException + { + TestCaseData result = new TestCaseData(); + String[] words = IN.readLine().split("" ""); + + result.numberOfGooglers = Integer.parseInt(words[0]); + result.surprisingTripletsOfScores = Integer.parseInt(words[1]); + result.minBestResult = Integer.parseInt(words[2]); + + result.scores = new int[result.numberOfGooglers]; + + for (int i = 0; i < result.scores.length; i++) + { + result.scores[i] = Integer.parseInt(words[3+i]); + } + + return result; + } + } + + public static void computeMaps() + { + HashSet> absIntSet = new HashSet>(); + HashSet> surpriseIntSet = new HashSet>(); + + for (int i = 0; i <= 10; i++) + { + int pos1 = i; + for (int j = -1; j <= 1; j++) + { + int pos2 = pos1+j; + if (pos2 < 0 || pos2 > 10) continue; + + int low, high; + if (pos1 == pos2) { + low = -1; + high = 1; + } + else if (pos1 < pos2) { + low = 0; + high = 1; + } + else { + low = -1; + high = 0; + } + + for (int k = low; k <= high ; k++) + { + int pos3 = pos1+k; + if (pos3 < 0 || pos3 > 10) continue; + int fourSum = pos1 + pos2 + pos3; + Integer[] triplet = {pos1, pos2, pos3}; + Arrays.sort(triplet); + if (absIntSet.add(Arrays.asList(triplet))) { + //printLn(""[%d, %d, %d] = %d"", triplet[0], triplet[1], triplet[2], fourSum); + absoluteMap.put(fourSum, triplet); + } + } + } + } + + for (int i = 0; i <= 10; i++) + { + int pos1 = i; + for (int j = -2; j <= 2; j++) + { + int pos2 = pos1+j; + if (pos2 < 0 || pos2 > 10) continue; + + int low, high; + if (pos1 == pos2) { + low = -2; + high = 2; + } + else if (pos1 < pos2) { + low = 2-j; + high = 2; + } + else { + low = -2; + high = -2-j; + } + + for (int k = low; k <= high ; k++) + { + int pos3 = pos1+k; + if (pos3 < 0 || pos3 > 10) continue; + int fourSum = pos1 + pos2 + pos3; + Integer[] triplet = {pos1, pos2, pos3}; + Arrays.sort(triplet); + List tripletList = Arrays.asList(triplet); + if (!absIntSet.contains(tripletList) && ! surpriseIntSet.contains(tripletList)) { + surpriseIntSet.add(tripletList); + surpriseMap.put(fourSum, triplet); + //printLn(""[%d, %d, %d] = %d"", triplet[0], triplet[1], triplet[2], fourSum); + } + } + } + } + + surpriseMap.put(0, absoluteMap.get(0)); + } + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException + { + computeMaps(); + BufferedReader IN = new BufferedReader(new InputStreamReader(System.in)); + + int testCaseCount; + try + { + String input = IN.readLine(); + testCaseCount = Integer.parseInt(input); + } + catch (Exception e) + { + testCaseCount = 0; + } + + if (testCaseCount > 0) + { + TestCaseData[] testCaseData = new TestCaseData[testCaseCount]; + for (int i = 0; i < testCaseData.length; i++) + { + testCaseData[i] = TestCaseData.readTestCaseData(IN); + } + + for (int i = 0; i < testCaseData.length; i++) + { + testCaseData[i].minBestResultCount = processTestCase(testCaseData[i]); + printLn(""Case #%d: %d"", i + 1, testCaseData[i].minBestResultCount); + } + + } + + IN.close(); + } + + protected static int processTestCase(TestCaseData testCaseData) + { + int absoulteBSCount = 0; + int surpriseBSCount = 0; + int best = testCaseData.minBestResult; + + for (int i = 0; i < testCaseData.numberOfGooglers; i++) + { + int score = testCaseData.scores[i]; + Integer[] triplet = absoluteMap.get(score); + if (triplet[2] >= best) { + absoulteBSCount++; + } + else + { + triplet = surpriseMap.get(score); + if (triplet != null && triplet[2] >= best) { + surpriseBSCount++; + } + } + } + + return absoulteBSCount + Math.min(testCaseData.surprisingTripletsOfScores, surpriseBSCount); + } + + // to ensure that '\n' is used as EOL on my Windows Machine, just to be sure ;) + // + static void printLn(String val) + { + System.out.print(val); + System.out.print('\n'); + } + static void printLn(String format, Object ... args) + { + System.out.print(String.format(format, args)); + System.out.print('\n'); + } +} +" +A21198,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + + +public class DancingWiththeGooglers { + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub + System.setIn(new FileInputStream(""dancing.in"")); + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + int Case = Integer.parseInt(bf.readLine()); + int cCase = 1; + while(Case > 0){ + String line = bf.readLine(); + String [] parts = line.trim().split(""[ ]+""); + int [][] t = new int[Integer.parseInt(parts[0])][2]; + int S = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + for (int i = 3; i < parts.length; i++){ + int sum = Integer.parseInt(parts[i]); + if(sum == 0){ + t[i-3][0] = 0; + t[i-3][1] = 0; + } + else if(sum == 1){ + t[i-3][0] = 1; + t[i-3][1] = 1; + } + else if(sum == 2){ + t[i-3][0] = 1; + t[i-3][1] = 2; + } + else{ + int caso = 0; + if((sum-1)%3 == 0)caso = 1; + double h = sum/3.0; + int x = (int) Math.ceil(h); + t[i-3][0] = x; + if(caso == 1 || x == 10)t[i-3][1] = x; + else t[i-3][1] = x+1; + } + } + int count = 0; + for(int i = 0; i < Integer.parseInt(parts[0]);i++){ + if(t[i][0] >= p)count++; + else if(t[i][1] >= p && S>0){ + S--; + count++; + } + } + System.out.println(""Case #""+cCase+"": ""+count); + cCase++; + Case--; + } + } + +} +" +A22457,"import java.util.ArrayList; +import java.util.List; + +public class JamUtil { + static int[] parseIntList(String str, int count) { + int[] res = new int[count]; + String[] parts = str.split("" ""); + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + res[i] = Integer.parseInt(part); + } + return res; + } + + static List parseIntList(String str) { + ArrayList res = new ArrayList(); + String[] parts = str.split("" ""); + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + res.add(Integer.parseInt(part)); + } + return res; + } + + static String printTable(T[][] t) { + StringBuilder res = new StringBuilder(); + for (int i = 0; i < t.length; i++) { + T[] ts = t[i]; + for (int j = 0; j < ts.length; j++) { + T t1 = ts[j]; + res.append(t1+ "" ""); + } + res.append(""\n""); + } + return res.toString(); + } +} +" +A22201,"package gcj; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +class Dancing { + Scanner sc; + PrintWriter pw; + + int t, n, y, p, s; + int[] scores; + + Dancing() { + try { + sc = new Scanner(new File(""B-large.in"")); + pw = new PrintWriter(new FileWriter(""out-large.txt"")); + } catch (IOException e) { + + } + + t = sc.nextInt(); + + int caseNum = 1; + + while (caseNum <= t) { + n = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + y = 0; + + scores = new int[n]; + for (int i = 0; i < n; i++) + scores[i] = sc.nextInt(); + + // start algorithm + if (p == 0) + y = n; + else { + for (int score : scores) { + if ( score >= 3*p-2 ) { + y++; + } else if (s > 0 && score >= Math.abs(3*p-4)) { + y++; + s--; + } + } + } + pw.println(""Case #"" + caseNum + "": "" + y); + caseNum++; + } + pw.flush(); + pw.close(); + } + + public static void main(String[] args) { + new Dancing(); + } + +} +" +A22868,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.math.BigInteger; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + + +public class ProblemB { + + + + + + // ************************************************************************************* + // *********************************** FRAMEWORK *************************************** + // ************************************************************************************* + + public static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + public static boolean isStandardInput = false; + + public static File input; + public static FileReader inputreader; + public static BufferedReader in; + + public static File output; + public static FileWriter outputwriter; + public static BufferedWriter out; + + public static StringTokenizer st; + + public static void main(String[] args) throws Exception { + doSTDIN(true); + setOutput(""test.out""); + run(); + close(); + } + + public static void run() throws Exception { + + + init(""E:\\workspace\\2012\\src\\B-small""); + + int cases = INT(); + + for(int cc = 1;cc<=cases;cc++) { + StringBuffer outputString = new StringBuffer(100); + int dancers = INT(); + int s = INT(); + int p = INT(); + + + int scores [] = new int [dancers]; + + for (int i=0; i < dancers; i++){ + scores[i] = INT(); + } + + int count = 0; + for (int i=0; i= p){ + count++; + continue; + } + + + + + switch (dif) { + case 2: + switch (reminder) { + case 2: + if (--s >=0){ + count++; + } + break; + default: + break; + } + break; + case 1: + switch (reminder) { + case 2: + count++; + break; + case 1: + count++; + break; + case 0: + if (--s>= 0){ + count++; + } + break; + default: + break; + } + break; + case 0: + break; + + default: + break; + } + + } + + print(""Case #""+cc+"": ""); + println(count); + + } + + } + + + + public static void init(String problemName) throws Exception { + doSTDIN(false); + setInput(problemName+"".in""); + setOutput(problemName+"".out""); + } + + // **************** PRINT METHODS ********************** + + public static void println() throws IOException { + out.write(""\n""); + System.out.println(); + } + + public static void println(Object obj) throws IOException { + out.write(obj.toString()); + out.write(""\n""); + System.out.println(obj.toString()); + } + + public static void print(Object obj) throws IOException { + out.write(obj.toString()); + System.out.print(obj.toString()); + } + + public static void println(long number) throws IOException { + out.write(Long.toString(number)); + out.write(""\n""); + System.out.println(number); + } + + public static void print(long number) throws IOException { + out.write(Long.toString(number)); + System.out.print(number); + } + + public static void println(char c) throws IOException { + out.write(Character.toString(c)); + out.write(""\n""); + System.out.println(c); + } + + public static void print(char c) throws IOException { + out.write(Character.toString(c)); + System.out.print(c); + } + + public static void println(String line) throws IOException { + out.write(line); + out.write(""\n""); + System.out.println(line); + } + + public static void print(String line) throws IOException { + out.write(line); + System.out.print(line); + } + + // ******************** INPUT DECLARATION ****************** + + public static void doSTDIN(boolean standard) { + isStandardInput = standard; + } + + public static void setInput(String filename) throws IOException { + input = new File(filename); + inputreader = new FileReader(input); + in = new BufferedReader(inputreader); + } + + public static void setOutput(String filename) throws IOException { + output = new File(filename); + outputwriter = new FileWriter(output); + out = new BufferedWriter(outputwriter); + } + + public static void close() throws IOException { + if(in!=null)in.close(); + if(inputreader!=null)inputreader.close(); + + if(out!=null)out.flush(); + if(out!=null)out.close(); + if(outputwriter!=null)outputwriter.close(); + } + + // ************************** INPUT READING ***************** + + static String LINE() throws IOException { return isStandardInput?stdin.readLine():in.readLine(); } + static String TOKEN() throws IOException { + while (st == null || !st.hasMoreTokens())st = new StringTokenizer(LINE()); + return st.nextToken(); + } + static int INT() throws IOException {return Integer.parseInt(TOKEN());} + static long LONG() throws IOException {return Long.parseLong(TOKEN());} + static double DOUBLE() throws IOException {return Double.parseDouble(TOKEN());} + static BigInteger BIGINT() throws IOException {return new BigInteger(TOKEN());} + + +} +" +A22097,"package qualification; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + String solve(Scanner in) throws IOException { + int N = in.nextInt(), S = in.nextInt(), p = in.nextInt(), + count = 0, need_surprise = 0; + + for(int i = 0; i < N; i++) { + int t = in.nextInt(); + + if((t+2)/3 >= p) + count++; + else if(2 <= t && t <= 28 && (t+4)/3 >= p) + need_surprise++; + } + count += Math.min(S, need_surprise); + + return """"+count; + } + +/*************************************************************************************************/ + + public static void main(String[] args) throws IOException { + for(File f : new File(""."").listFiles()) + if(f.isFile() && f.getName().startsWith(B.class.getSimpleName() + ""-"") + && f.getName().endsWith("".in"")) { + + Scanner in = new Scanner(new FileReader(f)); + PrintWriter out = new PrintWriter(new FileWriter(f.getName() + "".out"")); + + int cases = in.nextInt(); in.nextLine(); + for(int caseno = 1; caseno <= cases; caseno++) + out.printf(""Case #%d: %s%n"", caseno, new B().solve(in)); + + out.close(); + } + } +} +" +A22010,"import java.io.InputStream; +import java.io.PrintStream; +import java.util.Scanner; + + +public abstract class AbstractCodeJam { + + public void solveProblems(InputStream in, PrintStream out) { + Scanner scan = new Scanner(in); + int nb = scan.nextInt(); + for (int i = 1; i <= nb; i++) { + Problem problem = readProblem(scan); + problem.solve(); + out.println(""Case #""+i+"": ""+problem.getSolution()); + } + } + + + protected abstract Problem readProblem(Scanner scan); + +} +" +A21995,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancingwithgooglers; + +import java.util.Scanner; + +/** + * + * @author topik + */ +public class DancingWithGooglers +{ + + /** + * @param args the command line arguments + */ + public static void main(String[] args) + { + final Scanner scanner = new Scanner(System.in); + final int testCases = scanner.nextInt(); + for( int tc=1; tc <= testCases; tc++ ) + { + final int googlers = scanner.nextInt(); + int surprising = scanner.nextInt(); + final int p = scanner.nextInt(); + + int goodGooglers = 0; + + for( int i=0; i < googlers; i++ ) + { + final int score = scanner.nextInt(); + + if( score == 0 ) + { + if( p == 0 ) + { + goodGooglers++; + } + continue; + } + + final int d = score / 3; + final int r = score % 3; + + if( d >= p ) + { + goodGooglers++; + } + else if( d+1 >= p ) + { + if( r > 0 ) + { + goodGooglers++; + } + else if( surprising > 0 ) + { + surprising--; + goodGooglers++; + } + } + else if( d+2 >= p ) + { + if( r == 2 && surprising > 0 ) + { + surprising--; + goodGooglers++; + } + } + } + + System.out.println(""Case #"" + tc + "": "" + goodGooglers); + } + } +} +" +A20827,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class letDance { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + StringBuffer output = new StringBuffer(); + + try{ + FileInputStream fstream = new FileInputStream(""/Users/iToR/Documents/workspace/CodeJam2/src/B-large.in""); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + + strLine = br.readLine(); + int line = (new Integer(strLine)).intValue(); + + int i = 1; + while ((strLine = br.readLine()) != null) { + + + + + + output.append(""Case #""+i+"": ""); + + String[] temp; + + /* delimiter */ + String delimiter = "" ""; + /* given string will be split by the argument delimiter provided. */ + temp = strLine.split(delimiter); + + int compet = (new Integer(temp[0])).intValue(); + int surprise = (new Integer(temp[1])).intValue(); + int max = (new Integer(temp[2])).intValue(); + int count = 0; + + for(int j = 3;j=0||dif==-1||dif==-2){ + count++; + } + else if(dif==-3||dif==-4){ + if(surprise>0){ + count++; + surprise--; + } + + } + } + output.append(count); + if(i p-1){ + max++; + } + else if(tempsurps=min_score) + { + count++; + } + else + { + if (surprise>0 && quot>0 && quot+1>=min_score) + { + count++; + surprise--; + } + } + break; + + case 1: + if (quot>=min_score || quot+1>=min_score) + { + count++; + } + else + { + if (surprise>0 && quot+1>=min_score) + { + count++; + surprise--; + } + } + + break; + + case 2: + if (quot+1>=min_score || quot>=min_score) + { + count++; + } + else + { + if (surprise>0 && quot+2>=min_score) + { + count++; + surprise--; + } + } + break; + } + + } + out.println(""Case #""+(i+1)+"": ""+count); + out.flush(); + } + } +} +" +A20833,"package qualification; + + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Scanner; + +public class Task2 { + + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(new FileInputStream(""task21.txt"")); + int T = scanner.nextInt(); + for (int i = 0; i < T; i++) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int[] t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = scanner.nextInt(); + } + int noProbMin = Math.max(p * 3 - 2, p); + int surpriseMin = Math.max(p * 3 - 4, p); + int noProbCount = 0; + int surpriseCount = 0; + for (int googler : t) { + if (googler >= noProbMin) { + noProbCount++; + } + if (googler < noProbMin && googler >= surpriseMin) { + surpriseCount++; + } + } + surpriseCount = Math.min(surpriseCount, S); + System.out.println(""Case #"" + (i + 1) + "": "" + (noProbCount + surpriseCount)); + } + } +} +" +A22534,"package jam2012.dancers; + +import java.io.File; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Scanner; + +import commons.FileUtilities; + +public class GoogleDancers { + + public static void main(String[] args) throws IOException { + + List strings = FileUtilities.readFile(new File( + ""B-large.in"")); + + int number = Integer.parseInt(strings.get(0)); + + List result = new LinkedList(); + + for (int i = 1; i <= number; i++) { + + Scanner s = new Scanner(strings.get(i)); + + int dancers = s.nextInt(); + int surprisingAmount = s.nextInt(); + int atLeast = s.nextInt(); + + int[] values = new int[dancers]; + for (int j = 0; j < dancers; j++) { + values[j] = s.nextInt(); + } + int[] minvalues = new int[dancers]; + boolean[] cansurprise = new boolean[dancers]; + int tresult = 0; + + // Unsurprising values + for (int j = 0; j < dancers; j++) { + int minAmount = values[j] / 3; + int rest = values[j] - (minAmount * 3); + if (rest > 0) { + minAmount++; + } + if (rest != 1 && values[j] > 1 && values[j] < 28) { + cansurprise[j] = true; + } + minvalues[j] = minAmount; + if (minAmount >= atLeast) { + tresult++; + } + } + for (int j = 0; j < dancers; j++) { + if (surprisingAmount > 0 && atLeast == minvalues[j] + 1 && cansurprise[j]) { + + surprisingAmount--; + tresult++; + } + } + result.add(Integer.toString(tresult)); + } + FileUtilities.writeFile(result, new File(""B-large.out"")); + } +} +" +A21831,"import java.util.Scanner; + +/** + * Created by IntelliJ IDEA. + * User: Linkov Mikl + * Date: 15.04.12 + * Time: 2:51 + * To change this template use File | Settings | File Templates. + */ +public class ProblemB { + public static void main(String [] args) { + Scanner scanner = new Scanner(System.in); + + int testCount = scanner.nextInt(); + + for (int i = 0; i < testCount; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int answer = 0; + for (int j = 0; j < n; j++) { + int point = scanner.nextInt(); + int flag = 0; + int max1 = -1; + int max2 = -1; + for (int k1 = 0; k1 < 11; k1++) { + for (int k2 = 0; k2 < 11; k2++) { + for (int k3 = 0; k3 < 11; k3++) { + if (k3 + k2 + k1 == point) { + if ((Math.abs(k3 - k2) < 3) && (Math.abs(k1 - k2) < 3) && (Math.abs(k3 - k1) < 3)) { + + if ((Math.abs(k3 - k2) == 2) || (Math.abs(k2 - k1) == 2) || (Math.abs(k3 - k1) == 2)) { + flag = 1; + max1 = Math.max(k1, max1); + max1 = Math.max(k2, max1); + max1 = Math.max(k3, max1); + } else { + max2 = Math.max(k1, max2); + max2 = Math.max(k2, max2); + max2 = Math.max(k3, max2); + } + } + } + } + } + } + + if (max2 >= p) { + answer++; + } else { + if (s > 0) { + if (max1 >= p) { + answer++; + s--; + } + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + answer); + } + } +} +" +A22541,"import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.Iterator; +import java.util.Scanner; + +public class DancingWithGooglers { + + public static class Scores { + public final int S; + public final int p; + public final int[] t; + + public Scores(int S, int p, int[] t) { + this.S = S; + this.p = p; + this.t = t; + } + } + + public static Iterator iterator(Readable input) { + final Scanner scanner = new Scanner(input); + + return new Iterator() { + private int cases = scanner.nextInt(); + + @Override + public boolean hasNext() { + return cases > 0; + } + + @Override + public Scores next() { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + int[] t = new int[N]; + for (int i = 0; i < N; i++) { + t[i] = scanner.nextInt(); + } + + cases--; + return new Scores(S, p, t); + } + + @Override + public void remove() { + throw new AbstractMethodError(); + } + }; + } + + public static int maxTuples(Scores scores) { + int tuples = 0; + int s = scores.S; + + for (int i : scores.t) { + int[] tuple = tuplesWithMax(i, scores.p); + + if (tuple.length == 3) { + if (tuple[0] - tuple[2] == 2 && s > 0) { + tuples++; + s--; + } else if (tuple[0] - tuple[2] <= 1) { + tuples++; + } + } + } + + return tuples; + } + + public static int[][] tuples(int total) { + if (total == 0) { + return new int[][]{{0, 0, 0}}; + } + + if (total == 30) { + return new int[][]{{10, 10, 10}}; + } + + int max = total / 3; + + if (total % 3 == 0) { + return new int[][]{{max, max, max}, {max + 1, max, max - 1}}; + } + + if (total % 3 == 1) { + return new int[][]{{max + 1, max, max}, {max + 1, max + 1, max - 1}}; + } + + if (max < 9) { + return new int[][]{{max + 1, max + 1, max}, {max + 2, max, max}}; + } + + return new int[][]{{max + 1, max + 1, max}}; + } + + + public static int[] tuplesWithMax(int t, int max) { + for (int[] tuple : tuples(t)) { + if (tuple[0] >= max) + return tuple; + } + return new int[]{}; + } + + public static void main(String[] args) throws FileNotFoundException { + FileReader fileReader = new FileReader(args[0]); + + int caseId = 1; + Iterator iterator = iterator(fileReader); + + while (iterator.hasNext()) { + int result = maxTuples(iterator.next()); + System.out.format(""Case #%s: %s\n"", caseId, result); + caseId++; + } + } +} +" +A22921,"package com.g0414.b; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class Problem { + public final String FILE_PATH = ""C:/data/workspace/googleCodeJam/src/"" + ""com/g0414/b/""; + public final String FILE_BASE = ""B-large""; + // public final String FILE_BASE = ""sample""; + public final String INPUT_FILE = FILE_PATH + FILE_BASE + "".in""; + public final String OUTPUT_FILE = FILE_PATH + FILE_BASE + "".txt""; + + long testN = -1; + ArrayList testList = new ArrayList(); + + public static void main(String[] args) { + try { + Problem p = new Problem(); + p.init(); + p.printResult(); + p.end(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void printResult() throws ProblemException { + long i = 1; + for (Test p : testList) { + prlong(""Case #"" + i + "": "" + p.check()); + i++; + } + } + + public static boolean flag = true; + FileWriter outputFile = null; + public void prlong(String str) throws ProblemException { + try { + // ƒtƒ@ƒCƒ‹‚̍폜Aƒtƒ@ƒCƒ‹‚̐V‹KƒI[ƒvƒ“ + if (flag) { + flag = false; + File fw01 = new File(OUTPUT_FILE); + fw01.delete(); + outputFile = new FileWriter(OUTPUT_FILE, true); + } + outputFile.write(str + ""\r\n""); + System.out.println(str); + } catch (IOException e) { + throw new ProblemException(e.getMessage(),e); + } + } + + public void end() throws ProblemException { + try { + outputFile.close(); + } catch (IOException e) { + throw new ProblemException(e.getMessage(),e); + } + } + + public void init() throws ProblemException { + try { + FileReader in = new FileReader(INPUT_FILE); + BufferedReader br = new BufferedReader(in); + String line; + testN = Long.parseLong(br.readLine()); + while ((line = br.readLine()) != null) { + String[] ch = line.split("" ""); + System.out.println(line); + ch = line.split("" ""); + long n = Long.parseLong(ch[0]); + long s = Long.parseLong(ch[1]); + long p = Long.parseLong(ch[2]); + ArrayList tList = new ArrayList(); + for (int i = 3; i < ch.length; i++) { + tList.add(Long.parseLong(ch[i])); + } + Test test = new Test(n,s,p,tList); + testList.add(test); + } + br.close(); + in.close(); + } catch (IOException e) { + System.out.println(e); + throw new ProblemException(e.getMessage(),e); + } + } + + + public class Test { + long n = -1; + long s = -1; + long p = -1; + ArrayList tList = null; + + public Test (long n, long s, long p, ArrayList tList) { + this.n = n; + this.s = s; + this.p = p; + this.tList = tList; + } + + public String check () { + ArrayList danceList = new ArrayList (); + for (long t : tList) { + long high = t / 3; + if (t % 3 > 0) { + high ++; + } + long highPlus = high; + if (t % 3 != 1 && t / 3 > 0) { + highPlus ++; + } + Dance dance = new Dance(high, highPlus); + danceList.add(dance); + } + int result = 0; + int surprisingUpper = 0; // surprising‚ª‚ ‚Á‚½‚珸Ši‰Â”\ + for (Dance dance : danceList) { + if (dance.getHigh() >= p) { + result ++; + } else if (dance.getHighPlus() >= p) { + surprisingUpper ++; + } + } + // System.out.println(""sur="" + surprisingUpper + "", s="" + s); + if (surprisingUpper > s) { + result += s; + } else { + result += surprisingUpper; + } + return """" + result; + } + + + @Override + public String toString() { + String list = "" ""; + for (Long l : tList) { + list += l + "",""; + } + return ""("" + n + "","" + s + "","" + p + "")"" + list; + } + } + + private class Dance { + long high; + long highPlus; + public Dance(long high, long highPlus){ + this.high = high; + this.highPlus = highPlus; + } + public long getHigh() { + return high; + } + public long getHighPlus() { + return highPlus; + } + } + + public class ProblemException extends Exception { + private static final long serialVersionUID = 2080823058826051635L; + public ProblemException(String message) { + super(message); + } + public ProblemException(String message, Throwable e) { + super (message, e); + } + } + + /* + * +Case #1: 1 +Case #2: 256 +Case #3: 4 +Case #4: 674 +Case #5: 461 + * + */ +} +" +A22177,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class problem2 { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + FileInputStream fstream = new FileInputStream(""C:\\Profiles\\sys4qa\\Desktop\\in.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + Integer T= 0; + + int N=0; + int S=0; + int p=0; + ArrayList score=new ArrayList(); + + ArrayList inputList =new ArrayList(); + ArrayList input =new ArrayList(); + while ((strLine = br.readLine()) != null) { + + + if (T==0) + { + T= Integer.parseInt(strLine); + } + else + { + String s[]=strLine.split("" ""); + inputList =new ArrayList(); + for(int i=0;i=2) + min =(p-1)*3+1; + else + min=p*3; + + int surpiseMin = min-2; + + for (int i=0;i=min) + count++; + else if (((Integer)score.get(i)>=surpiseMin) && S>0) + { + S--; + count++; + } + } + return count; + + } + } + + +" +A22250,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + + +public class Dancing { + + + Map> bestResultsMap; + + public static void main(String[] args) { + String inFile = args[0]; + //String inFile = ""resources/B-small-attempt0.in""; + + try { + new Dancing().countGooglers(inFile, inFile+"".out""); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public void countGooglers(String inFile, String outFile) throws NumberFormatException, IOException{ + StringBuffer out = new StringBuffer(); + + BufferedReader br = new BufferedReader(new FileReader(new File(inFile))); + String line; + int currentLineNumber = 0; + int totalTestCases = 0; + + while((line = br.readLine()) != null) { + if(currentLineNumber == 0){ + totalTestCases = Integer.valueOf(line); + currentLineNumber++; + continue; + } + + String[] tokenizedLine = line.split("" ""); + int numberOfGooglers = Integer.valueOf(tokenizedLine[0]); + int suprisingTriplets = Integer.valueOf(tokenizedLine[1]); + int minBestResult = Integer.valueOf(tokenizedLine[2]); + + /* + System.out.println(""numberOfGooglers""+numberOfGooglers); + System.out.println(""suprisingTriplets""+suprisingTriplets); + System.out.println(""minBestResult""+minBestResult); + System.out.println(""tokenizedLine length: ""+tokenizedLine.length); + */ + + int[] resultTotals = new int[tokenizedLine.length - 3 ]; + for(int i = 3; i < tokenizedLine.length; i++){ + resultTotals[i-3] = Integer.valueOf(tokenizedLine[i]); + } + + int googlers = calculateMaxGooglersForBestResult(numberOfGooglers, suprisingTriplets, minBestResult, resultTotals); + out.append(""Case #""+currentLineNumber+"": ""+googlers +System.getProperty(""line.separator"")); + + currentLineNumber++; + } + + writeTextToFile(out.toString(), outFile); + + } + + + private int calculateMaxGooglersForBestResult(int numberOfGooglers, int suprisingTriplets, int minBestResult, int[] totalPoints){ + int googlerCount = 0; + int surprisedTriplets = 0; + + for (int totalPoint : totalPoints) { + if(totalPoint < minBestResult){ + continue; + } + + int twoResults = totalPoint - minBestResult; + int r1 = twoResults / 2; + int r2 = twoResults - r1; + + int apart = getMaxApart(minBestResult, r1, r2); + + + if(apart < 2){ + googlerCount++; + }else if(apart == 2){ + if(surprisedTriplets < suprisingTriplets){ + surprisedTriplets++; + googlerCount++; + } + } + + //System.out.println(""tot: ""+totalPoint +"" minbest ""+minBestResult+"" surp: ""+suprisingTriplets+""-> ""+minBestResult +"":""+r1+"":""+r2 +"" apart: ""+apart); + } + + return googlerCount; + } + + private int getMaxApart(int r1, int r2, int r3){ + int apart = 0; + if(Math.abs(r1-r2) > Math.abs(apart)) apart = r1-r2; + if(Math.abs(r3-r3) > Math.abs(apart)) apart = r2-r3; + if(Math.abs(r1-r3) > Math.abs(apart)) apart = r1-r3; + return apart; + } + + private void writeTextToFile(String text, String outputFileName) throws IOException{ + BufferedWriter out = new BufferedWriter(new FileWriter(outputFileName)); + out.write(text); + out.close(); + } +} + +" +A20941,"package contests.googleJam; + +import java.io.*; +import java.util.StringTokenizer; + + +public class googleDance +{ + public static void main(String[] args) + { + int noOfDancers; + int requiredSpecial; + int bestScore; + StringTokenizer st; + char ch; + BufferedReader br = null; + + try { + FileWriter fstream = new FileWriter(""output.out""); + BufferedWriter out = new BufferedWriter(fstream); + String sCurrentLine; + + br = new BufferedReader(new FileReader(""B-large.in"")); + sCurrentLine = br.readLine();//read the no. of test cases + int i = 1; + while ((sCurrentLine = br.readLine()) != null) + { + out.write(""Case #"" + i++ + "": ""); + st = new StringTokenizer(sCurrentLine,"" ""); + noOfDancers = Integer.parseInt(st.nextToken());//no. of dancers + requiredSpecial = Integer.parseInt(st.nextToken());//no. of special cases + bestScore = Integer.parseInt(st.nextToken());//best score required + int ans = 0; + int special_Max = 0; + for (int j = 0; j < noOfDancers; j++) + { + int total = Integer.parseInt(st.nextToken()); + int last2 = total - bestScore; + int second = last2/2; + if(total > 28 || (last2/2) >= bestScore || total >= (bestScore + 2*(bestScore-2)) + 2) + ans++; + else if(total < 2 ) + { + if(total >= bestScore) + special_Max++; + } + else if(total >= (bestScore + 2*(bestScore-2))) + { + special_Max++; + } + } + if(special_Max <= requiredSpecial) + out.write(ans + special_Max + ""\n""); + else + out.write(ans + requiredSpecial + ""\n""); + } + out.close(); + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (br != null)br.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } +} +" +A20567,"package ProblemSolvers; + +import CaseSolvers.AllYourBaseCase; + +public class AllYourBase extends ProblemSolver { + + public AllYourBase(String filePath) { + super(filePath); + } + + @Override + public void process() { + cases = io.readInt(); + for (int i = 1; i <= cases; i++) { + new AllYourBaseCase(i, 1, io).process().printSolution(); + } + } + +} +" +A21931,"package jp.funnything.competition.util; + +import java.util.Comparator; + +import com.google.common.base.Objects; + +public class Pair< T1 , T2 > { + public static < T1 extends Comparable< T1 > , T2 extends Comparable< T2 > > Comparator< Pair< T1 , T2 > > getFirstComarator() { + return new Comparator< Pair< T1 , T2 > >() { + @Override + public int compare( final Pair< T1 , T2 > o1 , final Pair< T1 , T2 > o2 ) { + final int c = o1.first.compareTo( o2.first ); + return c != 0 ? c : o1.second.compareTo( o2.second ); + } + }; + } + + public static < T1 extends Comparable< T1 > , T2 extends Comparable< T2 > > Comparator< Pair< T1 , T2 > > getSecondComarator() { + return new Comparator< Pair< T1 , T2 > >() { + @Override + public int compare( final Pair< T1 , T2 > o1 , final Pair< T1 , T2 > o2 ) { + final int c = o1.second.compareTo( o2.second ); + return c != 0 ? c : o1.first.compareTo( o2.first ); + } + }; + } + + public T1 first; + public T2 second; + + public Pair( final Pair< T1 , T2 > that ) { + this.first = that.first; + this.second = that.second; + } + + public Pair( final T1 first , final T2 second ) { + this.first = first; + this.second = second; + } + + @Override + public boolean equals( final Object obj ) { + if ( this == obj ) { + return true; + } + + if ( obj == null || getClass() != obj.getClass() ) { + return false; + } + + final Pair< ? , ? > that = ( Pair< ? , ? > ) obj; + + return Objects.equal( this.first , that.first ) && Objects.equal( this.first , that.first ); + } + + @Override + public int hashCode() { + final int prime = 31; + + int result = 1; + result = prime * result + ( first == null ? 0 : first.hashCode() ); + result = prime * result + ( second == null ? 0 : second.hashCode() ); + + return result; + } + + @Override + public String toString() { + return ""Pair [first="" + first + "", second="" + second + ""]""; + } +} +" +A22577,"package GoogleDance; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + +public class GoogleDance { + + /** + * @param args + */ + public static void main(String[] args) { + try{ + String userDir = System.getProperty(""user.dir""); //get working directory + userDir.replaceAll(""['\']"", ""\\""); // replace all chars '\' with '\\' in the string + File file = new File(System.getProperty(""user.dir"") + ""\\QualificationRound\\GoogleDance\\in-out\\B-large.in""); + Scanner fileScanner = new Scanner(file); + //delimiter is how input text is set up in this case it's the new line char + fileScanner.useDelimiter(System.getProperty(""line.separator"")); + //declared for file writing + BufferedWriter outFile = new BufferedWriter(new FileWriter(System.getProperty(""user.dir"") + ""\\QualificationRound\\GoogleDance\\in-out\\B-large.out"")); + int counter, inCounter, deepCounter, masterCounter, numCases, startIndex, numPpl, suprisingScores, minScore, currentNum, maxH, result; + int judgeHigh, judgeLow; + ArrayList intList = new ArrayList(); + int [] judgeScores = new int[3]; + String inputText; + boolean suprisingScoresReal; + numCases = Integer.parseInt(fileScanner.nextLine()); + for(masterCounter = 1; masterCounter <= numCases; masterCounter++){ + inputText = fileScanner.nextLine(); + startIndex = 0; + result = 0; + for( counter = 0; counter < inputText.length(); counter ++){ + if (inputText.charAt(counter) == ' ') + { + intList.add(Integer.parseInt(inputText.substring(startIndex, counter))); + startIndex = counter + 1; + } + } + intList.add(Integer.parseInt(inputText.substring(startIndex, counter))); + numPpl = intList.get(0); + suprisingScores = intList.get(1); + minScore = intList.get(2); + intList.remove(0); + intList.remove(0); + intList.remove(0); + if(suprisingScores == 0) + suprisingScoresReal = false; + else + suprisingScoresReal = true; + for(counter = 0; counter < intList.size(); counter++){ + if(intList.get(counter) <= 2){ + for(inCounter = 0; inCounter < intList.get(counter); inCounter++) + judgeScores[inCounter] = 1; + for(deepCounter = inCounter; deepCounter < 3; deepCounter++) + judgeScores[deepCounter] = 0; + maxH = 0; + } + else{ + currentNum = intList.get(counter) / 3; + judgeScores[0] = currentNum; + judgeScores[1] = currentNum; + judgeScores[2] = currentNum; + maxH = intList.get(counter) - (currentNum + currentNum + currentNum); + } + deepCounter = 0; + if(maxH > 0) + for(inCounter = 0; inCounter < maxH; inCounter++){//distribute extra points (from /3) + judgeScores[deepCounter] = judgeScores[deepCounter] + 1; + deepCounter++; + if(deepCounter >= 3) + deepCounter = 0; + } + Arrays.sort(judgeScores); //sorted from low (position[0]) to high (position[2]) + + if(judgeScores[2] >= minScore) + result++; + else if(suprisingScoresReal == true && judgeScores[2] != 0){ + if(judgeScores[2] == judgeScores[1] && suprisingScores != 0 && judgeScores[2] + 1 >= minScore){ + result++; + suprisingScores--; + } + } + } + //System.out.println(""suprisingScores :"" + suprisingScores); + //outFile.write(""suprisingScores :"" + suprisingScores + ""\n""); + System.out.println(""Case #"" + masterCounter + "": "" + result); + outFile.write(""Case #"" + masterCounter + "": "" + result + ""\n""); + intList.clear(); + } + + fileScanner.close(); + outFile.close(); + } + catch (FileNotFoundException e) { + System.out.println(""File not found""); e.printStackTrace(); + } + catch (IOException e) { + System.out.println(""IOException""); + } + } + +} +" +A20916," +/** + * Write a description of class solver here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class solver +{ + public int solve(int nog,int nos,int p,int t[]) + { + int[] aux=new int[2*nog]; + int i=0,count=0; + for(i=0;i=p) + { + count++; + aux[nog+i]=-1; + } + } + for(i=0;i=p) + { + nos-=1; + count++; + } + } + return count; + + } +}" +A20485,"package gcj2012.qualification; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class GooglerDance { + public static void main(String[] args) throws Exception { + GooglerDance main = new GooglerDance(args[0]); + main.solve(); + } + + private final BufferedReader in; + + public GooglerDance(String input) throws Exception { + in = new BufferedReader(new FileReader(this.getClass().getResource(input).getFile())); + } + + private void solve() throws Exception { + int T = getInt(); + for (int c = 1; c <= T; c++) { + List n = getIntegers(); + long ans = solveOne(n); + System.out.println(""Case #"" + c + "": "" + ans); + } + } + + private int solveOne(List n) { + int sum = 0; + int N = n.remove(0).intValue(); + int S = n.remove(0).intValue(); + int p = n.remove(0).intValue(); + + for (Integer candid : n) { + if (candid.intValue() >= p * 3 - 2) { + sum++; + } else if (candid.intValue() >= p * 3 - 4 && S > 0 && p >= 2) { + S--; + sum++; + } + } + + return sum; + } + + /* + * File processing + */ + private int getInt() throws Exception { + return Integer.valueOf(in.readLine()).intValue(); + } + + private List getIntegers() throws Exception { + List list = new ArrayList(); + for (String s : getStrs()) { + list.add(Integer.valueOf(s)); + } + return list; + } + + private List getStrs() throws Exception { + return Arrays.asList(in.readLine().split("" "")); + } + +} +" +A21325,"package com.teamg9.codejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; + +interface ISolver { + public String evaluate(); +} +public abstract class Solver implements ISolver { + + protected Scanner in; + + public void solve() { + in = new Scanner(System.in); + _solve(System.out); + } + + public void solve(File inFile) { + String filename = inFile.getPath(); + filename = filename.substring(0, filename.lastIndexOf('.')); + File outFile = new File(filename + "".out""); + try { + in = new Scanner(inFile); + _solve(new PrintStream(outFile)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + private void _solve(PrintStream out) { + int count = in.nextInt(); + in.nextLine(); + for(int index = 0; index= p){ + result++; + } else if (((rem == 1)||(rem ==2)) && ((ave + 1) == p)){ + result++; + } else if ( S > 0) { + if ((rem == 2) && ((ave + rem) == p)){ + result++; + S--; + } else if ((rem == 0) && ((ave + 1) == p)){ + if (ave == 0){ + ; + } else { + result++; + S--; + } + } + } + } + System.out.println(""Case #"" + i + "": "" + result); + } + } +}" +A20714,"import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + +public class DancingProblem { + + private static final String INPUT_FILE_NAME = ""/home/rponnu/codebase/codejam/first_round/data/input.txt""; + private static final String OUTPUT_FILE_NAME = ""/home/rponnu/codebase/codejam/first_round/data/output.txt""; + + public static void main(String args[]) throws IOException { + List lines = readFile(INPUT_FILE_NAME); + Integer noOfInputs = readInputData(lines.get(0)).get(0); + System.out.println(""No of Inputs:""+ noOfInputs); + + + List outputLines = new ArrayList(); + + for(int index=1;index<=noOfInputs.intValue();index++){ + List inputData = readInputData(lines.get(index)); + outputLines.add(""Case #""+index+"": ""+getNoOfBestResult(inputData)); + } + File f = new File(OUTPUT_FILE_NAME); + FileUtils.writeLines(f,outputLines); + } + + private static int getNoOfBestResult(List inputData) { + Iterator iterator = inputData.iterator(); + Integer noOfPlayers = iterator.next(); + Integer noOfSurprises = iterator.next(); + Integer bestResult = iterator.next(); + + int noOfMaxScores = 0; + int count= 0; + int noOfMaxScoresWithSurprises = 0; + + int maxValueForScore = getMaxValueForScore(bestResult); + int maxValueForScoreWithSurprises = getMaxValueForScoreWithSurprises(bestResult); + + while (iterator.hasNext()){ + int scoreSum = iterator.next(); + if(scoreSum >= maxValueForScore) { + noOfMaxScores ++; + } else if( (maxValueForScore != maxValueForScoreWithSurprises) && scoreSum >= maxValueForScoreWithSurprises){ + noOfMaxScoresWithSurprises ++; + } + } + + count = noOfMaxScores; + + if (noOfMaxScoresWithSurprises >= noOfSurprises) { + count += noOfSurprises; + } else if (noOfMaxScoresWithSurprises < noOfSurprises){ + count += noOfMaxScoresWithSurprises; + } + + return count; + } + + private static int getMaxValueForScore(int bestScore){ + int maxValue = bestScore; + if(bestScore-1 > 0) { + maxValue += 2 *(bestScore-1); + } + return maxValue; + } + + private static int getMaxValueForScoreWithSurprises(int bestScore){ + int maxVal = bestScore; + if(bestScore -2 > 0){ + maxVal +=2 *(bestScore-2); + } + return maxVal; + } + + + + private static List readInputData(String line){ + List values = new ArrayList(); + StringTokenizer stringTokenizer = new StringTokenizer(line.trim()); + while(stringTokenizer.hasMoreElements()){ + values.add(Integer.parseInt((String) stringTokenizer.nextElement())); + } + return values; + } + + + private static List readFile(String path) throws IOException { + List lines = FileUtils.readLines(new File(path)); + return lines; + } +} +" +A22936,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class Dance { + public static void main(String[] args) throws FileNotFoundException{ + + Scanner scan = new Scanner (new File(""C:\\Users\\kffong\\Desktop\\JAVA_workspace\\DanceGoogler\\input.txt"")); + // Scanner scan = new Scanner(new File(""C:\\Users\\kffong\\Desktop\\JAVA_workspace\\DanceGoogler\\input.txt"")); + // System.out.print(scan.nextLine()); + int numberOfCase = scan.nextInt(); + scan.nextLine(); + + for(int k=0 ; k=p){ + result++; + } + else if(best==p-1 && total[i]%3!=1 &&total[i]!=0){ + possibleIncrease++; + } + + } + // System.out.println(""possibleIncrease=""+possibleIncrease+"" ;result=""+result); + + + if (possibleIncrease<=surprise){ + result = result+possibleIncrease; + } + else{ + result = result+surprise; + } + System.out.println(""Case #""+(k+1)+"": ""+result); + + + //System.out.println(""====================""); + + if(scan.hasNextLine()){ + scan.nextLine(); + } + + } + + } +} +" +A22945,"package y2012.quals; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(""B.in"")); + PrintWriter out = new PrintWriter(new File(""B.out"")); + int nTestCase = in.nextInt(); + for (int testCase = 0; testCase < nTestCase; testCase++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] a = new int[n]; + for (int i = 0; i < n; i++) + a[i] = in.nextInt(); + int res = 0; + int rl = p + p - 1 + p - 1, sl = p + p - 2 + p - 2; + if (p == 0) { + rl = 0; + sl = 0; + } else if (p == 1) + sl = 1; + for (int i = 0; i < n; i++) + if (a[i] >= rl) + res++; + else if (a[i] >= sl && s > 0) { + res++; + s--; + } + + out.println(""Case #"" + (testCase + 1) + "": "" + res); + } + in.close(); + out.close(); + } +} +" +A20925,"import java.util.Scanner; + + +public class Dancing { + + public static void main(String[] args) { + + int t, n, s, p, y; + int[] ti; + + Scanner scan = new Scanner(System.in); + + t = scan.nextInt(); + + for(int i=1; i<=t; i++){ + + y = 0; + int surprised = 0; + + n = scan.nextInt(); + s = scan.nextInt(); + p = scan.nextInt(); + + ti = new int[n]; + + for(int j=0; j= (limiteInf + 2)){ + y++; + //System.out.println(""Entrou 1: "" + ti[j]); + }else if(ti[j] >= limiteInf && ti[j] < (limiteInf + 2) && surprised < s){ + y++; + surprised++; + //System.out.println(""Entrou 2: "" + ti[j]); + } + } + + + + System.out.println(""Case #"" + i + "": "" + y); + } + } + +} +" +A21046,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.falidae; + +import java.util.*; +import java.io.*; + +/** + * + * @author LittleRock + */ +public class DancingWithTheGooglers { + + public DancingWithTheGooglers() { + } + + public void init() { + } + + public int solve(int[] scores, int s, int p) { + int reval = 0; + for (int score : scores) { + int[] a = this.ananlys(score); + if (a[0] >= p) { + reval++; + } else if (s > 0 && a[1] >= p) { + reval++; + s--; + } + } + return reval; + } + + public int[] ananlys(int score) { + int[] reval = new int[2]; + int d = score / 3; + int r = score % 3; + if (r == 0) { + reval[0] = d; + if (d != 0) { + reval[1] = d + 1; + } else { + reval[1] = d; + } + } else if (r == 1) { + reval[0] = d + 1; + reval[1] = d + 1; + } else { + reval[0] = d + 1; + reval[1] = d + 2; + } + return reval; + } + + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(new FileReader(""in.txt"")); + PrintWriter out = new PrintWriter(new FileWriter(""out.txt"")); + DancingWithTheGooglers solver = new DancingWithTheGooglers(); + + int testCount = in.nextInt(); + for (int i = 0; i < testCount; i++) { + solver.init(); + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] scores = new int[n]; + for (int j = 0; j < n; j++) { + scores[j] = in.nextInt(); + } + printIndex(i, out); + out.print(solver.solve(scores, s, p)); + out.println(); + } + + in.close(); + out.flush(); + out.close(); + } + + private static void printIndex(int i, PrintWriter out) { + out.printf(""Case #%d: "", i + 1); + } +}" +A22256,"import java.io.*; +import java.util.*; + +public class ProB +{ + public static void main(String args[]) + { + try + { + BufferedReader br = new BufferedReader(new FileReader(""E:\\test.txt"")); + int n; + n= Integer.parseInt(br.readLine()); + + //System.out.println(n); + + int casen=0,noofg,spec,max,i; + String temp; + String outp; + outp=""""; + String nos[]; + int tmp; + int count; + + while( casen < n ) + { + temp = br.readLine(); + nos = temp.split("" ""); + outp += ""Case #""+(casen+1)+"": ""; + + noofg = Integer.parseInt(nos[0]); + spec = Integer.parseInt(nos[1]); + max = Integer.parseInt(nos[2]); + + count = 0; + + for(i=0;i= max ) + count++; + else if( tmp%3 == 1 && (tmp/3)+(tmp%3) >= max) + { + System.out.println(""here2:"" + tmp); + count++; + } + else if( tmp%3 == 2 && spec > 0 && (tmp%3)+(tmp/3) >= max ) + { + System.out.println(""here: "" + tmp); + count++; + spec--; + } + else if( tmp%3 == 2 && ((tmp/3)+((tmp/3)+1)*2) == tmp && (tmp/3)+1>=max ) + { + System.out.println(""here3: "" + tmp); + count++; + } + else if( tmp!=0 && tmp%3 == 0 && spec > 0 && (tmp/3)+1 >= max ) + { + System.out.println(""here1: "" + tmp); + count++; + spec--; + } + } + outp += count; + if( casen != n-1 ) + outp += ""\n""; + casen++; + } + System.out.println(outp); + + BufferedWriter bw = new BufferedWriter( new FileWriter(""E:\\result.txt"")); + bw.write(outp); + bw.close(); + br.close(); + } + catch( Exception e ) + { + e.printStackTrace(); + } + } +} +" +A20517,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package one.codejam.b; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class DancingGooglers { + + private int T;//number of testcases + private int N;//number of googlers + private int S;//number of surprising triplets of scores + private int p;//best result for each case + private int[] scores; + private int ti;//score for each googler + private Scanner input; + //method to calculate maximum number of googlers + + public void openFile() { + Scanner cin = new Scanner(System.in); + System.out.println(""Enter File Path containing test data: ""); + String filePath = cin.nextLine(); + try { + input = new Scanner(new File(filePath)); + } catch (FileNotFoundException ex) { + System.err.println(""Error opening file!""); + System.exit(1); + Logger.getLogger(DancingGooglers.class.getName()).log(Level.SEVERE, null, ex); + } + } +//small input + + public void readFile() { + + if (input.hasNext()) { + //read number of test cases + T = input.nextInt(); + //enforce T limit + + //move to first case + int test_count = 0; + input.nextLine(); + //for each test case read N, S, p, and N values to array ti and call output method + while (input.hasNext() && (test_count <= T)) { + test_count++; + N = input.nextInt(); + //proceed for this input + S = input.nextInt(); + p = input.nextInt(); + scores = new int[N]; + //populate scores + for (int i = 0; i < N; i++) { + scores[i] = input.nextInt(); + } + Arrays.sort(scores); + //call output method + output(test_count, S, p, scores); + } + + } + } + + public void closeFile() { + input.close(); + } + + public void output(int test_case, int surprises, int best_result, int[] scores) { + if (p > 1) { + int q = p * 3 - 2; + int s = p * 3 - 4; + int count = 0; + int pt = N - 1; + + for (int i = N - 1; i >= 0; i--) { + if (scores[i] >= q) { + count++; + pt--; + } + } + while (pt >= 0 && scores[pt] >= s && S > 0) { + count++; + pt--; + S--; + } + System.out.println(""Case #"" + test_case + "": "" + count); + } else if (p == 1) { + int j = 0; + for (j = 0; j < N; j++) { + if (scores[j] > 0) { + break; + } + + } + System.out.println(""Case #"" + test_case + "": "" + (N - j)); + } else if (p == 0) { + System.out.println(""Case #"" + test_case + "": "" + N); + } + } + + public static void main(String[] str) { + DancingGooglers dG = new DancingGooglers(); + dG.openFile(); + dG.readFile(); + dG.closeFile(); + } +} +" +A22317,"import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; + + +public class DancingGooglers { + + /** + * Google Code Jam 2012: Problem B. Dancing With the Googlers + * @author hullarb + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader input = new BufferedReader(new FileReader(args[0])); + OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(args[0].contains(""in"")?args[0].replace(""in"", ""out""):args[0] + "".out"")); + int testCases = Integer.parseInt(input.readLine()); + for(int i = 0; i < testCases; i++) { + String[] parts = input.readLine().split("" ""); + int N = Integer.parseInt(parts[0]); + int S = Integer.parseInt(parts[1]), p = Integer.parseInt(parts[2]); + // System.out.println(""N: "" + N + "" S: "" + S + "" p: "" +p); + int t[] = new int[N]; + int bests[] = new int[N]; + for(int j = 0; j < N; j++) { + t[j] = Integer.parseInt(parts[3 + j]); + bests[j] = notSurp(t[j]); + //System.out.println(""NotSurp("" +t[j] + ""): "" + bests[j]); + } + for(int j = 0; j < N; j++) { + if(S == 0) + break; + if((t[j] > 1 && t[j] < 29) && (bests[j] == -1 || + bests[j] < p)) { + int ns = surp(t[j]); + //System.out.println(""Surp("" +t[j] + ""): "" + ns); + if(bests[j] == -1 && ns == -1) { + System.err.print(""Something went wrong with t: "" + t[j]); + continue; + } + if(ns >= p) { + bests[j] = ns; + S--; + }else{ + if(bests[j] == -1){ + S--; + } + } + } + } + int result = 0; + for(int j = 0; j < N; j++) + if(bests[j] >= p) + result++; + out.write(""Case #"" + (i + 1) + "": "" + result + ""\n""); + } + out.close(); + input.close(); + } + + private static int surp(int i) { + if(i == 2) + return 2; + if((i - 2) % 3 == 0) + return (i - 2) / 3 + 2; + if((i - 3) % 3 == 0) + return (i - 3) / 3 + 2; + if(i > 3 && (i - 4) % 3 == 0) + return (i - 4) / 3 + 2; + return -1; + } + + private static int notSurp(int i) { + if(i == 0) + return 0; + if(i < 3 ) + return 1; + if((i - 2) % 3 == 0) + return (i - 2) / 3 + 1; + if((i - 1) % 3 == 0) + return (i - 1) / 3 + 1; + if(i % 3 == 0) + return i / 3; + return -1; + } + +} +" +A21407,"import java.awt.List; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + try{ + BufferedReader bf=null; + try { + int T; + bf = new BufferedReader(new FileReader(""src/com/codejam/input/B-large.in"")); + T = Integer.parseInt(bf.readLine()); + + for(int i=0;i > googlers = new HashMap >(); + ArrayList googlers = new ArrayList(); + + String line = bf.readLine(); + String[] numbers = line.split("" ""); + int N = Integer.parseInt(numbers[0]); + int S = Integer.parseInt(numbers[1]); + int P = Integer.parseInt(numbers[2]); + + for(int index=3;index triplets= getTripletList(numbers[index],P); + + if(triplets!=null) + googlers.add(new Googler(numbers[index],triplets)); + //googlers.put(numbers[index],triplets); + } + + + + + int count = 0; + int surprising = 0; + + for(Googler g:googlers){ + boolean isNotSurprisingfound = false; + for(Triplet tr:g.getTriplets()){ + if(tr.isSurprising()==false){ + isNotSurprisingfound = true; + count++; + break; + } + + } + if(!isNotSurprisingfound){ + surprising++; + } + } + + if(surprising getTripletList(String total,int best){ + ArrayList triplets=null; + + for(int s1=0;s1<11;s1++){ + for(int s2=0;s2<11;s2++){ + for(int s3=0;s3<11;s3++){ + if( (s1+s2+s3)==Integer.parseInt(total) && Math.abs(s1-s2)<=2 && Math.abs(s1-s3)<=2 && Math.abs(s2-s3)<=2 ){ + + Triplet tr = new Triplet(s1,s2,s3); + if(tr.getMax()>=best){ + if(triplets==null) + triplets=new ArrayList(); + + triplets.add(tr); + } + + } + } + } + } + + if(triplets !=null) + Collections.sort(triplets); + + return triplets; + } + +} + + +" +A22365,"package inam.qual; + +import java.io.File; +import java.io.FileInputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class B { + public void go() { + Scanner in = new Scanner(System.in); + int cc = in.nextInt(); + for (int c = 1; c <= cc; c++) { + int val = 0; + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + for (int i = 0; i < n; i++) { + int x = in.nextInt(); + if (x / 3 >= p) { + val += 1; + } else if (x % 3 == 1 && (x / 3) + 1 >= p) { + val += 1; + } else if (x % 3 == 2 && (x / 3) + 1 >= p) { + val += 1; + } else if (x % 3 == 2 && (x / 3) + 2 >= p && s > 0) { + val += 1; + s -= 1; + } else if (x % 3 == 0 && x != 0 && (x / 3) + 1 >= p && s > 0) { + val += 1; + s -= 1; + } + } + System.out.println(""Case #"" + c + "": "" + val); + } + } + public static void main(String[] args) { + try { + String p = ""B-large""; + String r = ""qual""; + System.setIn(new FileInputStream(new File(r, p + "".in""))); + if (1 == 1) { + System.setOut(new PrintStream(new File(r, p + "".out""))); + } + new B().go(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A21336,"import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.List; + + +public class Jam2 +{ + + public static String dancers(int g, int s, int best, List totals){ + + int couldbe = 0; + int s_left = s; + for(int i=0; i < totals.size(); i++){ + int total = totals.get(i); + + int check = total - (best*3); + + //p(""check: "" + check + "" best: "" + best + "" total: "" + total); + + if(total < best) + continue; + if(check >= -2){ + couldbe++; + continue; + } + if((check ==-4 || check==-3) && s_left>0){ + couldbe++; + s_left--; + } + + + + } + + + return """"+couldbe; + } + + public static String solveLine(String in){ + String[] s = in.split("" ""); + int dancers = Integer.parseInt(s[0]); + int surp = Integer.parseInt(s[1]); + int bestresult = Integer.parseInt(s[2]); + List totals = new ArrayList(); + for(int i=3; i= p) { + testCaseResult++; + } else if (score > 0 && p <= score && (p - maxScore == 1) && (maxScore * 3 - score < 2)) { + nbPossibleSurprisingTriplet++; + } + } + testCaseResult += Math.min(nbSurprisingTriplet, nbPossibleSurprisingTriplet); + + output += ""Case #"" + (testCaseNumber+1) + "": "" + testCaseResult + ""\n""; + } + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////// + + public void init() throws Exception { + File temp = new File(""output/""); + if (!temp.exists()) { + temp.mkdir(); + } + // Output file + outputWriter = new FileWriter(""output/output.txt"", false); + // Input file + scanner = new Scanner(new File(""resources/"" + INPUT_FILE_NAME)); + } + + public void stop() throws Exception { + // Closing files + outputWriter.write(output, 0, output.length()); + scanner.close(); + outputWriter.close(); + } + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + B instance = new B(); + long start = System.currentTimeMillis(); + + instance.init(); + instance.run(); + instance.stop(); + + System.out.println(""Finished in "" + (System.currentTimeMillis() - start) + "" ms""); + } + +} +" +A22413,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2012; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Scanner; +import java.util.TreeSet; + +/** + * + * @author Rumal + */ +public class QB { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); +// TreeSet +// for (int i = 0; i <= 10; i++) { +// for (int j = Math.max(i-1,0); j < 10 && j<=i+1 ; j++) { +// for (int k = Math.max(i-1,0); k < 10 && k<=i+1 ; k++) { +// +// } +// } +// } +// + + + + int T = sc.nextInt(); + for (int t = 1; t <= T; t++) { + int ans = 0; + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] gg = new int[N]; + for (int i = 0; i < N; i++) { + gg[i] = sc.nextInt(); + } + Arrays.sort(gg); + //System.out.println(Arrays.toString(gg)); + int minSc = (2) * (p - 1) + p; + int minSp = (2) * (p - 2) + p; + minSc = Math.max(minSc, 0); + minSp = Math.max(minSp, 2); + //System.out.println(minSc+"" ""+minSp); + for (int i : gg) { + if (i >= minSc) { + //System.out.println(i); + ans++; + continue; + } + if (i >= minSp && S-- > 0) { + //System.out.println(""*""+i); + ans++; + continue; + } + //System.out.println(i); + } + + + System.out.println(""Case #"" + t + "": "" + ans); + } + } +} +" +A21318,"import java.util.*; + +public class B { + public static void main(String[] args) { + B b = new B(); + b.solve(); + } + + public void solve() { + Scanner in = new Scanner(System.in); + int t = in.nextInt(); + for(int ii = 1; ii <= t; ++ii) { + int num = in.nextInt(); + int surprising = in.nextInt(); + int points = in.nextInt(); + int[][] bests = new int[num][2]; //[i][0] best, not surprising. [i][1], best, surprising + for(int i = 0; i < num; ++i) { + int score = in.nextInt(); + if(score <= 1) { + bests[i][0] = score; + bests[i][1] = score; + } + else if(score % 3 == 0) { + bests[i][0] = score/3; + bests[i][1] = bests[i][0] + 1; + } else if(score % 3 == 1) { + bests[i][0] = score/3 + 1; + bests[i][1] = bests[i][0]; + } else { + bests[i][0] = score/3 + 1; + bests[i][1] = bests[i][0] + 1; + } + //System.out.printf(""With a total of %d, best non: %d, best with: %d\n"", score, bests[i][0], bests[i][1]); + } + int total = 0; + for(int i = 0; i < num; ++i) { //check all not suprising stuffs + if(bests[i][0] >= points) { + ++total; + bests[i][1] = -1; + } + } + for(int i = 0; i < num && surprising > 0; ++i) { + if(bests[i][1] >= points) { + ++total; + --surprising; + } + } + System.out.printf(""Case #%d: %d\n"", ii, total); + } + } +}" +A22670,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class E2 { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + Scanner sc = null; + + //sc = new Scanner(System.in); + + try { + sc = new Scanner(new File(""E2.txt"")); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + int fases = sc.nextInt(); + + + for(int j=1; j<=fases; ++j){ + + int N = sc.nextInt(); // players + int S = sc.nextInt(); // surprising + int P = sc.nextInt(); + + int casos = 0; + + for(int i=0; i= P){ + casos++; + } + else if(S > 0 && base > 0 && base + 1 >= P){ + casos++; + S--; + } + + } + else if(t == 1){ + if(base + 1 >= P){ + casos++; + } + else if(S > 0 && base + 1 >= P){ + casos++; + S--; + } + } + else{ + if(base + 1 >= P){ + casos++; + } + else if(S > 0 && base + 2 >= P){ + casos++; + S--; + } + } + } + + System.out.println(""Case #"" + j + "": "" + casos); + } + } + +} +" +A20431,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DancingWithTheGooglers { + + public static int count(int N, int S, int p, int[] num){ + int sureCount = 0; + int possibleCount = 0; + + for(int i = 0 ; i < num.length ; i ++){ + int n = num[i]; + int average = n / 3; + + if(n % 3 == 0){ + if(average >= p && average >= 0 && average <= 10) + sureCount ++; + else if(average + 1 >= p && average - 1 >= 0 && average + 1 <= 10) + possibleCount ++; + }else if(n % 3 == 1){ + if(average + 1 >= p && average >= 0 && average + 1 <= 10) + sureCount ++; + }else{ + if(average + 1 >= p && average >= 0 && average + 1 <= 10) + sureCount ++; + else if(average + 2 >= p && average >= 0 && average + 2 <= 10){ + possibleCount ++; + } + } + } + + if(possibleCount > S){ + return sureCount + S; + }else{ + return sureCount + possibleCount; + } + } + public static void main(String args[]) throws IOException{ + BufferedReader reader = new BufferedReader(new FileReader(new File(""input.txt""))); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""output.txt""))); + String line = reader.readLine(); + int T = Integer.parseInt(line); + for(int i = 0 ; i < T ; i ++){ + line = reader.readLine(); + String tokens[] = line.split(""\\s+""); + int N = Integer.parseInt(tokens[0]); + int S = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int[] num = new int[N]; + for(int j = 3 ; j < 3 + N ; j ++){ + num[j - 3] = Integer.parseInt(tokens[j]); + } + int count = count(N , S , p , num); + writer.write(""Case #"" + (i + 1) + "": "" + count + ""\r\n""); + } + reader.close(); + writer.close(); + } + +} +" +A22186,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +public class Solution { + + boolean debug = true; + boolean writeToFile = true; + + BufferedReader reader = null; + BufferedWriter writer = null; + + public Solution() throws Exception { + InputStream inputStream; + if (debug) { + inputStream = new FileInputStream(""in.txt""); + } else { + inputStream = System.in; + } + reader = new BufferedReader(new InputStreamReader(inputStream)); + + OutputStream outputStream; + if (debug && writeToFile) { + outputStream = new FileOutputStream(""out.txt""); + } else { + outputStream = System.out; + } + writer = new BufferedWriter(new OutputStreamWriter(outputStream)); + + readInput(); + process(); + + reader.close(); + writer.close(); + } + + private void readInput() throws Exception { + int T = Integer.parseInt(reader.readLine()); + for (int i=0; i=min) { + count++; + } else if ((S>0) && (ti>=P) && (ti>=min-2)) { + S--; + count++; + } + } + writer.write(""Case #"" + (i+1) + "": "" + count + ""\n""); + } + } + + private void process() { + + } + + public static void main(String[] args) throws Exception { + new Solution(); + } + +} +" +A22640,"import java.util.Arrays; +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) { + Scanner r = new Scanner(System.in); + + int T = r.nextInt(); + int caseNumber = 1; + while(T-- > 0){ + int N = r.nextInt(); + int S = r.nextInt(); + int P = r.nextInt(); + + int[] a = new int[N]; + for(int i = 0; i < N; i++) + a[i] = r.nextInt(); + + Arrays.sort(a); + + int ret = 0; + for(int i = N - 1; i >= 0; i--){ + boolean need = true; + for(int x = 0; x <= 10; x++) + for(int y = 0; y <= 10; y++){ + int z = a[i] - x - y; + if(z > 10 || z < 0)continue; + + int max = Math.max(x, Math.max(y, z)); + if(max >= P && (Math.abs(x - y) <= 1 && Math.abs(x - z) <= 1 && Math.abs(y - z) <= 1)){ + need = false; + } + } + + if(!need)ret++; + else{ + if(S > 0){ + boolean can = false; + + for(int x = 0; x <= 10; x++) + for(int y = 0; y <= 10; y++){ + int z = a[i] - x - y; + if(z > 10 || z < 0)continue; + + int max = Math.max(x, Math.max(y, z)); + if(max >= P && (Math.abs(x - y) <= 2 && Math.abs(x - z) <= 2 && Math.abs(y - z) <= 2)){ + can = true; + } + } + + if(can){ + S--; + ret++; + } + } + } + } + System.out.printf(""Case #%d: %d\n"", caseNumber++, ret); + } + } +} +" +A21748,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class B { + + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(new File(""B-large.in"")); + FileWriter fw = new FileWriter(""B-large.out""); + + int T = in.nextInt(); + + for (int tc = 1; tc <= T; tc++) { + int count = 0; + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] totalScores = new int[N]; + int special = 0; + for(int i = 0; i < N; i++) { + totalScores[i] = in.nextInt(); + if(totalScores[i] >= 3) { + int remainder = totalScores[i] % 3; + int mid = totalScores[i] / 3; + + if(remainder == 0) {//mid mid mid or mid-1 mid mid+1; + if(mid >= p) + count++; + else if(mid+1 >= p && special < S) { + special++; + count++; + } + } else if(remainder == 1) {//mid mid mid+1 or mid-1 mid+1 mid+1 + if(mid >= p) + count++; + else if(mid+1 >= p) + count++; + + } else {//mid mid+1 mid+1 or mid mid mid+2 + if(mid >= p) + count++; + else if(mid+1 >= p) + count++; + else if(mid+2 >= p && special < S) { + special++; + count++; + } + } + } else { + if((totalScores[i] == 0 && p == 0) || (totalScores[i] == 1 && p <= 1)) + count++; + else if(totalScores[i] == 2) { + if(p <=1) { + count++; + } else if(p == 2 && special < S) { + special++; + count++; + } + } + } + + } + + fw.write (""Case #"" + tc + "": "" + count + ""\n""); + } + fw.flush(); + fw.close(); + } + +} +" +A21760," +import java.util.Scanner; + +public abstract class ProgrammingProblem +{ + + protected static final Scanner sc = new Scanner(System.in); + + protected static boolean DEBUG = false; + protected abstract void print(); + + protected abstract void readInput(); + + protected abstract String execute(); + + protected static void main(@SuppressWarnings(""rawtypes"") Class myclass) throws InstantiationException, IllegalAccessException + { + int T = sc.nextInt(); + + for (int i = 0; i < T; i++) + { + ProgrammingProblem m = (ProgrammingProblem) myclass.newInstance(); + m.readInput(); + if (DEBUG) + { + m.print(); + } + + System.out.println(""Case #"" + (i+1) + "": "" + m.execute()); + } + + } + + protected static ProgrammingProblem getTestCase() + { + return null; + } + + public ProgrammingProblem() + { + super(); + } + +}" +A20556,"package codejam2012.qualification.b; + +public final class Triplet { + + public final int a; + public final int b; + public final int c; + public final int total; + public final boolean surprising; + + private Triplet(int a, int b, int c, int total) { + this.a = a; + this.b = b; + this.c = c; + this.total = total; + surprising = Math.abs(a - b) > 1 || Math.abs(a - c) > 1 || Math.abs(b - c) > 1; + } + + public static Triplet of(int a, int b, int c, int total) { + return new Triplet(a, b, c, total); + } + + public boolean hasAtLeast(int p) { + return a >= p || b >= p || c >= p; + } + + @Override + public String toString() { + return String.format(""(%d,%d,%d)%s = %d"", a, b, c, surprising ? ""*"" : """", total); + } +} +" +A22994,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package IO; + +/** + * + * @author dannocz + */ +public class TestCase { + + private int noGooglers; + private int p; + private Googler[] googlers; + + public TestCase(String testCase) { + String[] cads=testCase.split("" ""); + noGooglers = Integer.parseInt(cads[0]); + int surprisedCases = Integer.parseInt(cads[1]); + p = Integer.parseInt(cads[2]); + googlers= new Googler[noGooglers]; + + for (int i = 0; i < noGooglers; i++) { + int score=Integer.parseInt(cads[i+3]); + googlers[i]=new Googler(score, surprisedCases); + buildTripplets(googlers[i]); + } + + } + + + public TestCase(int noGooglers, int surprisedCases, int p) { + this.noGooglers = noGooglers; + this.p = p; + this.googlers= new Googler[noGooglers]; + } + + + + public int result(){ + int total=0; + for (Googler googler : googlers) { + if(googler.result(p)) + total++; + } + + return total; + } + + private void buildTripplets(Googler googler) { + + int score = googler.getScore(); + for(int hp = p; hp<=10; hp++) + { + int x= score-hp; + for(int y1=0;y1<=hp;y1++){ + //for(int y1=hp;y1>=hp-2;y1--){ + int y2 = x-y1; + if(validTripplet(score,hp,y1,y2)) + googler.addTriplet(new Triplet(hp,y1,y2)); + } + } + } + + private boolean validTripplet(int score,int hp, int y1, int y2) { + + return (hp+y1+y2)==score && + validPair(hp,y1) && validPair(hp,y2) && validPair(y1,y2); + + } + + private boolean validPair(int y1, int y2){ + + if(y1<0 || y2<0 || y1>10 || y2>10) + return false; + + int r= y1-y2; + return (r<=2 && r>=-2); + } +}" +A22539,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import java.util.*; +import java.math.*; + +/** + * + * @author . + */ +public class B { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = Integer.parseInt(in.nextLine()); + + int N, S, p; + int[] googlers; + + for (int kase = 1; kase <= T; kase++) { + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + + googlers = new int[N]; + + for (int i = 0; i < N; i++) { + googlers[i] = in.nextInt(); + } + + Arrays.sort(googlers); + + //------------------------------- + int max = 0; + + int temp = 3 * p - 2; // first check for all unsurprising results + + int position; + + for (position = N - 1; position >= 0; position--) { + if (googlers[position] >= temp) { + max++; + } else { + break; + } + } + + if (temp == 1) { + temp = 1; + } else { + temp = 3 * p - 4; + } + + while (position >= 0 && S > 0) { + if (googlers[position] >= temp) { + max++; + S--; + } else { + break; + } + position--; + } + + //----------------------------- + + pl(""Case #"" + kase + "": "" + max); + + } + } + + public static void pf(String s, Object... o) { + System.out.printf(s, o); + } + + public static void pl(Object o) { + System.out.println(o); + } + + public static void pr(Object o) { + System.out.print(o); + } +} +" +A21276,"package codejam; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + +public class Util { + public int testcases; + BufferedReader br; + public Util(String file) throws FileNotFoundException { + FileInputStream fstream = new FileInputStream(file); + Reader r = new BufferedReader(new InputStreamReader(fstream)); + //while(st.nextToken()) + DataInputStream in = new DataInputStream(fstream); + br = new BufferedReader(new InputStreamReader(in)); + String str=""""; + try { + str = br.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + testcases = Integer.parseInt(str); + } + + public String nextLine() throws IOException { + return br.readLine(); + } + + protected void finalize() { + try {br.close();}catch(IOException e){} + } +} +" +A22774,"package com.menzus.gcj._2012.qualification.b; + +import com.menzus.gcj.common.Input; + +public class BInput implements Input { + private int surprisingTripletsNumber; + private int limit; + private int[] googlerScores; + + public int getSurprisingTripletsNumber() { + return surprisingTripletsNumber; + } + + public void setSurprisingTripletsNumber(int surprisingTripletsNumber) { + this.surprisingTripletsNumber = surprisingTripletsNumber; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public int[] getGooglerScores() { + return googlerScores; + } + + public void setGooglerScores(int[] googlerScores) { + this.googlerScores = googlerScores; + } +} +" +A22088,"import java.util.*; + +public class QB { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); in.nextLine(); + for(int cas=0; cas=p && score>=3*p-2) + ans++; + else if(score>=p && score>=3*p-4 && s>0) { + ans++; + s--; + } + } + System.out.println(""Case #""+(cas+1)+"": ""+ans); + } + } +}" +A22657,"import java.util.ArrayList; +import java.util.Scanner; + + +public class GooglersDancing { + + public static int[][] array = new int[11][4]; + + public void generateArray() { + for (int i=0;i<=10; i++) { + array[i][0] = Integer.MAX_VALUE; + array[i][2] = Integer.MAX_VALUE; + array[i][1] = Integer.MIN_VALUE; + array[i][3] = Integer.MIN_VALUE; + //ArrayList possibleList = new ArrayList(); + for (int j=i-2; j<=i+2 ; j++) { + if (j>=0 && j<=10) { + if (Math.abs(j-i) < 2) { + if (array[i][2] > (j+j)) { + array[i][2] = j+j; + } + else if (array[i][3] < (j+j)) { + array[i][3] = j+j; + } + if (array[i][0] > (j+j)) { + array[i][0] = j+j; + } + else if (array[i][1] < (j+j)) { + array[i][1] = j+j; + } + } + else { + if (array[i][0] > (j+j)) { + array[i][0] = j+j; + } + else if (array[i][1] < (j+j)) { + array[i][1] = j+j; + } + } + } + } + } + } + + public static void main(String[] args) { + GooglersDancing g = new GooglersDancing(); + g.generateArray(); + for (int i=0; i<=10; i++) { + System.out.println(i + "":"" + array[i][0] + ""*"" + array[i][1] + ""*"" + array[i][2] + ""*"" + array[i][3] + ""*""); + } + + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + int cases=1; + while (cases <= T) { + int N,S,p, count=0; + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + while (N-->0) { + boolean inRange=false, outRange=false; + int t = in.nextInt(); + int p2 = p; + while (p2<=10) { + int sum = t-p2; + if (sum >= array[p2][2] && sum <= array[p2][3]) { + inRange = true; + break; + } + else if (sum >= array[p2][0] && sum <= array[p2][1]) { + outRange = true; + } + p2++; + } + if (inRange) { + count++; + } + else if (outRange && S>0) { + count++; + S--; + } + } + System.out.println(""Case #"" + cases + "": "" + count); + cases++; + } + } + +} +" +A22800,"import java.io.*; +import java.util.*; +public class dance +{ + public static void main(String[] args) throws Exception + { + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File(""dance.in"")))); + PrintStream out = new PrintStream(new File(""dance.out"")); + int cases = Integer.parseInt(in.readLine()); + StringTokenizer s1; + int quant, surp, score, specnum1, specnum2, total, surpcount, with, without; + int[] scores; + for(int x = 0; x < cases; x++){ + s1 = new StringTokenizer(in.readLine(), "" ""); + quant = Integer.parseInt(s1.nextToken()); + surp = Integer.parseInt(s1.nextToken()); + score = Integer.parseInt(s1.nextToken()); + scores = new int[quant]; + total = 0; + surpcount = 0; + for(int y = 0; y < quant; y++){ + scores[y] = Integer.parseInt(s1.nextToken()); + with = maxWith(scores[y]); + without = maxWithout(scores[y]); + if(without >= score) + total++; + else if(surpcount < surp){ + if(with >= score){ + total++; + surpcount++; + } + } + } + out.println(""Case #"" + (x+1) + "": "" + total); + } + } + public static int maxWith(int num) + { + int base = num/3; + int rem = num%3; + if(num == 0) + return 0; + else if(rem == 0) + return (base+1); + else if(rem == 1) + return (base+1); + else + return (base+2); + } + public static int maxWithout(int num) + { + int base = num/3; + int rem = num%3; + if(rem == 0) + return base; + else + return (base+1); + } +}" +A22015,"import java.util.Scanner; +import java.io.OutputStream; +import java.io.IOException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.io.FileInputStream; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + * @author Prabu + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream; + try { + inputStream = new FileInputStream(""IO/B-large.in""); + } catch (IOException e) { + throw new RuntimeException(e); + } + OutputStream outputStream; + try { + outputStream = new FileOutputStream(""IO/B-large.out""); + } catch (IOException e) { + throw new RuntimeException(e); + } + Scanner in = new Scanner(inputStream); + PrintWriter out = new PrintWriter(outputStream); + CJ2012QR_Dancing solver = new CJ2012QR_Dancing(); + int testCount = Integer.parseInt(in.next()); + for (int i = 1; i <= testCount; i++) + solver.solve(i, in, out); + out.close(); + } +} + +class CJ2012QR_Dancing { + public void solve(int testNumber, Scanner in, PrintWriter out) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int ti, base, remainder; + int result = 0; + + for(int i = 0; i < N; i++) { + ti = in.nextInt(); + base = ti / 3; + if(base >= p) { + result++; + continue; + } + + remainder = ti % 3; + if(remainder > 0 && (base+1) >= p) { + result++; + continue; + } + + remainder = (remainder == 0 && ti != 0)? 1: remainder; + if(S > 0 && (base+remainder) >= p) { + S--; + result++; + continue; + } + } + out.printf(""Case #%d: %d\n"", testNumber, result); + } +} + +" +A22135,"/** + * + */ +package asem.googe.codejam.qround; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * @author A.Alathwari + * + * Problem B : + * + */ +public class ProblemB implements Runnable { + + asem.core.util.InputReader fin; + java.io.PrintWriter fout; + + /** + * @param fin + * @param fout + */ + public ProblemB(asem.core.util.InputReader fin, PrintWriter fout) { + this.fin = fin; + this.fout = fout; + } + + /** + * @param fin + * @param fout + * @throws IOException + * @throws FileNotFoundException + */ + public ProblemB(String fin, String fout) throws FileNotFoundException, IOException { + this.fin = new asem.core.util.InputReader(new FileReader(fin)); + this.fout = new PrintWriter(System.out); + } + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // TODO Auto-generated method stub + try { + + for (int tNum = 1, inT = fin.readInt(); tNum <= inT; tNum++) { + + int N = fin.readInt(); + int S = fin.readInt(); + int P = fin.readInt(); + + int [] googlers = new int [N]; + int y = 0; + + for (int i = 0; i < N; i++) { + googlers[i] = fin.readInt(); + + if (googlers[i] == 0) { + if (P == 0) + y++; + continue; + } + + if ((Math.ceil((double)googlers[i] / 3) >= P)) { + y++; + continue; + } + + if (S > 0 && (Math.ceil((double)(googlers[i]-1) / 3) >= (P-1))) { + y++; + S--; + } + } + + System.out.println(""Case #"" + tNum + "": "" + y); + } + + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +}" +A21213,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; + + +public class ProblemaB { + + /** + * @param args + */ + public static void main(String[] args)throws Exception { + int couldHaveBeenQuantity = 0; + int couldHaveBeenSurprinsinglyQuantity = 0; + PrintWriter pw = new PrintWriter (""C:\\Users\\Rodrigo\\Downloads\\B-large.out""); + BufferedReader reader = new BufferedReader(new FileReader (new File (""C:\\Users\\Rodrigo\\Downloads\\B-large.in""))); + int cases = Integer.parseInt(reader.readLine()); + for (int i = 1; i <= cases; i++){ + couldHaveBeenQuantity = 0; + couldHaveBeenSurprinsinglyQuantity = 0; + String linha = reader.readLine(); + String [] tokens = linha.split("" ""); + int N = Integer.parseInt(tokens[0]); + int S = Integer.parseInt (tokens[1]); + int p = Integer.parseInt (tokens[2]); + for (int j = 3; j < tokens.length; j++){ + + int total = Integer.parseInt(tokens[j]); + if (couldHaveBeenNormally(total, p)){ + couldHaveBeenQuantity++; + } + else if (couldHavebeenSurprisingly(total, p)){ + couldHaveBeenSurprinsinglyQuantity++; + } + } + int allThatCould = couldHaveBeenQuantity + (couldHaveBeenSurprinsinglyQuantity <= S ? couldHaveBeenSurprinsinglyQuantity : S); + System.out.println(""Case #"" + i + "": "" + allThatCould); + pw.println(""Case #"" + i + "": "" + allThatCould); + } + pw.close(); + + } + static boolean couldHaveBeenNormally (int total, int p){ + //if (total < p) + //return false; + //if (total == p) + //return false; + switch (p){ + case 10: + if (total >= 28) + return true; + return false; + + case 9: + if (total >= 25) + return true; + return false; + case 8: + if (total >= 22) + return true; + return false; + case 7: + if (total >= 19) + return true; + return false; + case 6: + if (total >= 16) + return true; + return false; + case 5: + if (total >= 13) + return true; + return false; + case 4: + if (total >= 10) + return true; + return false; + case 3: + if (total >= 7) + return true; + return false; + case 2: + if (total >= 4) + return true; + return false; + case 1: + if (total >= 1) + return true; + return false; + default: + return true; + } + + } + static boolean couldHavebeenSurprisingly (int total, int p){ + //if (total < p) + //return false; + //if (total == p) + //return false; + switch (p){ + case 10: + if (total >= 26) + return true; + return false; + case 9: + if (total >= 23) + return true; + return false; + case 8: + if (total >= 20) + return true; + return false; + case 7: + if (total >= 17) + return true; + return false; + case 6: + if (total >= 14) + return true; + return false; + case 5: + if (total >= 11) + return true; + return false; + case 4: + if (total >= 8) + return true; + return false; + case 3: + if (total >= 5) + return true; + return false; + case 2: + if (total >=2) + return true; + return false; + case 1: + if (total >= 1) + return true; + return false; + default: + return true; + + + } + } +} +" +A22505,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.util.Scanner; + +public class DancingWithTheGooglersLarge { + + public static void main(String[] args) { + + File file = new File(""/Users/NoK/Desktop/B-large.in""); + int counter = 1; + + try { + Scanner sc = new Scanner(file); + + int numOfCases = sc.nextInt(); + + sc.nextLine(); + + for (int i = 0; i < numOfCases; i++) { + int numOfGooglers = sc.nextInt(); + int numOfSupTrip = sc.nextInt(); + int bestScores = sc.nextInt(); + int maxBestGooglers = 0; + + for (int j = 0; j < numOfGooglers; j++) { + int googlerPoint = sc.nextInt(); + if (googlerPoint == 0) { + if (bestScores == 0) { + maxBestGooglers++; + } + continue; + } else if (googlerPoint == 1) { + if ((bestScores == 0) || (bestScores == 1)) { + maxBestGooglers++; + } + continue; + } else if (googlerPoint == 2) { + if ((bestScores == 0) || (bestScores == 1)) { + maxBestGooglers++; + } else if (bestScores == 2) { + if (numOfSupTrip > 0) { + maxBestGooglers++; + numOfSupTrip--; + } + } + continue; + } + if (googlerPoint % 3 == 0) { + if (googlerPoint / 3 >= bestScores) { + maxBestGooglers++; + } else { + if (numOfSupTrip > 0) { + if ((googlerPoint/3)+1 == bestScores) { + maxBestGooglers++; + numOfSupTrip--; + } + } + } + } else if (googlerPoint % 3 == 1) { + if ((googlerPoint/3)+1 >= bestScores) { + maxBestGooglers++; + } + } else if (googlerPoint % 3 == 2) { + if ((googlerPoint/3)+1 >= bestScores) { + maxBestGooglers++; + } else { + if (numOfSupTrip > 0) { + if ((googlerPoint/3)+2 == bestScores) { + maxBestGooglers++; + numOfSupTrip--; + } + } + } + } + } + + try { + FileWriter fw = new FileWriter(""/Users/NoK/Desktop/B-large.out"", true); + BufferedWriter bw = new BufferedWriter(fw); + System.out.println(""Case #"" + counter + "": "" + maxBestGooglers); + bw.write(""Case #"" + counter + "": "" + maxBestGooglers); + bw.newLine(); + bw.close(); + counter++; + } catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + + } + + } catch (FileNotFoundException e ) { + e.printStackTrace(); + } + + } + +}" +A22199,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +/** + * @author Andrey Zarubin + */ +public class Dancing { + public static void main(String... args) throws IOException { + String fileName = args[0]; + BufferedReader r = new BufferedReader(new FileReader(fileName)); + PrintWriter w = new PrintWriter(fileName.split(""\\."")[0] + "".out.txt""); + int T = Integer.parseInt(r.readLine()); + for (int x = 0; x < T; x++) { + Scanner sc = new Scanner(r.readLine()); + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) + t[i] = sc.nextInt(); + Arrays.sort(t); + int y = 0; + if (p == 0) { + w.println(""Case #"" + (x + 1) + "": "" + n); + continue; + } + for (int i = n - 1; i >= 0; i--) { + if (t[i] == 0) + break; + if (t[i] == 1) { + if (p > 1) + break; + y++; + continue; + } + if ((t[i] - 1) / 3 + 1 >= p) { + y++; + continue; + } + if (s > 0 && (t[i] - 2) / 3 + 2 >= p) { + s--; + y++; + continue; + } + break; + } + w.println(""Case #"" + (x + 1) + "": "" + y); + } + r.close(); + w.close(); + } +} +" +A20680,"import java.sql.ResultSet; +import java.util.Arrays; +import java.util.Scanner; + + +public class B { + + public int s = 0; + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int t = scanner.nextInt(); + + for (int i = 0; i < t; i++) { + B b = new B(); + int y = 0; + int n = scanner.nextInt(); + b.s = scanner.nextInt(); + int p = scanner.nextInt(); + int[] points = new int[n]; + for (int j = 0; j < n; j++) { + points[j] = scanner.nextInt(); + } +// +// for (int j = 0; j < n; j++) { +// +// if(3*p < ) +// int[] results = new int[3]; +// results[0] = p; +// results[1] = (points[j] - p)/2; +// results[2] = points[j] - results[0] - results[1]; +// +// while(results[0] <= 10 && results) { +// +// if(b.isValid(results, p)) { +// System.out.println(points[j] + "" - "" + results[0] + "", "" + results[1]+ "", "" + results[2]); +// y++; +// break; +// } +// results[0]++; +// results[1]--; +// } +// } +// +// System.out.println(""Case #""+(i+1)+"": ""+y); +// } +// +// +// } +// +// public boolean isValid(int[] results, int p) { +// if(Math.abs(results[0]-results[1]) < 2 && Math.abs(results[0]-results[2]) < 2) { //testo (Math.abs(results[1]-results[2]) ? +// return true; +// } +// else { +// if((Math.abs(results[0]-results[1]) <= 2 || Math.abs(results[0]-results[2]) <= 2) && s > 0) { +// s--; +// return true; +// } +// } +// return false; +// } + + + + Arrays.sort(points); + for (int j = 0; j < points.length; j++) { + + int maxToDrop = p + 2*(p - 2); + + if(p <= 1) { + maxToDrop = p; + } + + + if(points[j] < maxToDrop) { + continue; + } + + int minToPass = maxToDrop + 2; + + if(maxToDrop == 0) { + minToPass = 0; + } + + if(points[j] >= minToPass) { + y++; + continue; + } + + if(b.s > 0) { + b.s--; + y++; + continue; + } + + } + + System.out.println(""Case #""+(i+1)+"": ""+y); + } + } + +// public static boolean isLimitMax(int point, int p) { +// if(point >= 3 * p) { +// return true; +// } +// return false; +// } +// +// public static boolean isLimitMin(int point, int p) { +// if(point >= 4) { +// return true; +// } +// return false; +// } + +} +" +A20393,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +public class Dancing { + + public static void main(String[] args) throws IOException { + if (args.length < 2) { + System.err + .println(""Please enter the Valid I/O Paths in the argument ""); + System.err.println(""First Input , then OutPut ""); + System.exit(0); + } + File inFile = new File(args[0]); + File outFile = new File(args[1]); + BufferedReader in = new BufferedReader(new InputStreamReader( + new FileInputStream(inFile))); + PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); + String myLine = in.readLine(); + int t = Integer.parseInt(myLine); + int caseNum = 1; + int n, s, p; + while (t-- > 0) { + myLine = in.readLine(); + String[] myStr = myLine.split("" ""); + n = Integer.parseInt(myStr[0]); + s = Integer.parseInt(myStr[1]); + p = Integer.parseInt(myStr[2]); + + int[] arr = new int[n]; + int min = (p - 2) * 3 + 2 > 0 ? (p - 2) * 3 + 2 : p; + int min1 = 3*p - 2; + int rem2 = 0; + int normal = 0; + int result = 0; + if (p > 0) { + for (int i = 0; i < arr.length; i++) { + arr[i] = Integer.parseInt(myStr[i + 3]); + if (arr[i] >= min && arr[i] < min1) + rem2++; + else if (arr[i] >= min1) + normal++; + } + result = normal + (rem2 >= s ? s : rem2); + } else { + result = n; + } + out.println(""Case #"" + (caseNum) + "": "" + result); + caseNum++; + } + out.close(); + } +} +" +A20220,"import java.net.*; +import java.io.*; +import java.lang.*; + +public class DancingWiththeGooglers { + public static int highestStable(int x){ + if(x == 0) + return 0; + else if(x % 3 == 0) + return x/3; + else + return x/3 + 1; + } + public static int highestUnstable(int x){ + int temp = 0; + if(x == 0) + temp = 0; + else if(x % 3 == 0) + temp = x/3 + 1; + else if(x % 3 == 1) + temp = x/3 + 1; + else + temp = x/3 + 2; + + if(temp > 10) + temp = 10; + return temp; + } + public static void main(String[] args) throws IOException { + String[] spl; + int counter =1; + int output; + int n,s,p; + int low=0, med=0, high=0; + int[] nArr = new int[100]; + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String input; + while((input = in.readLine()) != null){ + //int l = input.length(); + spl = input.split("" ""); + n = Integer.parseInt(spl[0]); + s = Integer.parseInt(spl[1]); + p = Integer.parseInt(spl[2]); + //System.out.println(""n:"" + n + "" s:"" + s + "" p:"" + p ); + for(int i=0; i= p) + high++; + else if(highestUnstable(nArr[i]) < p) + low++; + else + med++; + } + //System.out.println(""high:"" + high + "" low:"" + low + "" med:"" + med + '\n' ); + if(s>=med){ + output = med + high; + System.out.println(""Case #"" + counter + "": "" + output ); + } + else{ + output = s + high; + System.out.println(""Case #"" + counter + "": "" + output ); + } + counter++; + low=0; med=0; high=0; + } + } +} + +" +A22956,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Scanner; + + +public class Q2DancingWithGooglers { + + public static void main(String[] args) throws IOException { + + Scanner scanner = new Scanner(new File(""q2.input"")); + + FileWriter writer = new FileWriter(""q2.output""); + + int cases = scanner.nextInt(); + + for (int i = 1; i <= cases; i++) { + + int n = scanner.nextInt(); + int s = scanner.nextInt(); + final int p = scanner.nextInt(); + + List cantBeSurprising = new ArrayList(n); + List canBeSurprising = new ArrayList(n); + + for (int j = 0; j < n; j++) { + int t = scanner.nextInt(); + if (canBeSurprising(t)) { + canBeSurprising.add(t); + } else { + cantBeSurprising.add(t); + } + } + + Collections.sort(canBeSurprising, new Comparator() { + + @Override + public int compare(Integer o1, Integer o2) { + return getPriority(o1).compareTo(getPriority(o2)); + } + + private Integer getPriority(Integer o1) { + if (getSurprisingP(o1) >= p && getNormalP(o1) < p) { + return 0; + } + + if (getSurprisingP(o1) >= p) { + return 1; + } + + return 2; + } + }); + + int response = 0; + + for (int j = 0; j < s; j++) { + if (getSurprisingP(canBeSurprising.get(j)) >= p) { + response++; + } + } + + for (int j = s; j < canBeSurprising.size(); j++) { + if (getNormalP(canBeSurprising.get(j)) >= p) { + response++; + } + } + + for (Integer t : cantBeSurprising) { + if (getNormalP(t) >= p) { + response++; + } + } + + writer.write(""Case #"" + i + "": "" + response + ""\n""); + } + + writer.close(); + + } + + + + private static boolean canBeSurprising(int n) { + if (n == 30 || n == 0 || n == 29) { + return false; + } + return true; + } + + private static Integer getSurprisingP(int n) { + if (n % 3 <= 1) { + return n / 3 + 1; + } + if (n % 3 == 2) { + return n / 3 + 2; + } + + return 0; + } + + private static Integer getNormalP(int n) { + if (n % 3 == 0) { + return n / 3; + } + return n / 3 + 1; + } + +} +" +A20276,"package Problem2; + +import java.util.ArrayList; + +public class DancingGooglers { + + //3 1 5 15 13 11 + + // tab[0] = numbe of dancers + // tab[1] = number of * + // tab[2] = threshold p + + public static int[] Assign_Stars(int allowed_stars, int[] sumratingtab, int threshold){ + + int a= allowed_stars; + int n=sumratingtab.length; + int[] maxrates= new int[n]; + int i; + + if (a>0){ + for (i=0;i0) && (sumratingtab[i] % 3 == 2) && ( ((sumratingtab[i]-2)/3 + 1)= threshold)){ + + // if ((sumratingtab[i]>=0) && (sumratingtab[i] % 3 == 2)){ + if (a>0){ + maxrates[i]= (sumratingtab[i]-2)/3 + 2; + System.out.println(""etoile gaspillee pour :"" + maxrates[i] + "" reste :"" +(a-1) ); + sumratingtab[i]=-1; + a--; + } + } + } + } + + if (a>0){ + for (i=0;i0) && (sumratingtab[i] % 3 == 0) && (((sumratingtab[i])/3 ) = threshold) ){ + // if ((sumratingtab[i]>=0) && (sumratingtab[i] % 3 == 0) ){ + if (a>0){ + + maxrates[i]= sumratingtab[i]/3 + 1 ; + System.out.println(""etoile gaspillee pour :"" + maxrates[i] + "" reste :"" +a); + sumratingtab[i]=-1; + a--; + } + } + } + } + +// if (a>0){ +// for (i=0;i0) && (sumratingtab[i] % 3 == 0) ){ +// if (a>0){ +// +// maxrates[i]= ((sumratingtab[i]/3)) + 1 ; +// sumratingtab[i]=-1; +// a--; +// } +// +// } +//// if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 1) ){ +//// if (a>0){ +//// +//// maxrates[i]= (((sumratingtab[i]-1)/3)) + 1 ; +//// sumratingtab[i]=-1; +//// a--; +//// } +//// } +// if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 2) ){ +// if (a>0){ +// +// maxrates[i]= (((sumratingtab[i]-2)/3)) + 2 ; +// sumratingtab[i]=-1; +// a--; +// } +// } +// } +// +// } + + + for (i=0;i0) && (sumratingtab[i] % 3 == 0) ){ + + maxrates[i]= ((sumratingtab[i]/3)) ; + sumratingtab[i]=-1; + + } + if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 1) ){ + + maxrates[i]= (((sumratingtab[i]-1)/3)) + 1 ; + sumratingtab[i]=-1; + } + if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 2) ){ + maxrates[i]= (((sumratingtab[i]-2)/3)) + 1 ; + sumratingtab[i]=-1; + + } + } + return maxrates; + } + + public static int countmorethanp(int[] maxrates ,int p){ + int n=maxrates.length; + int i; + int count=0; + for (i=0;i=p){ + count++; + } + } + return count; + } + +// public static void main(String[] args){ +// +// int[] tab = {8,0}; +// // 2 1 1 8 0 +// // 6 8 +// int[] tab2 = Assign_Stars(1, tab, 1); +// int i=0; +// for (i=0;i ArS){ + + int[] Ars_res = new int[ArS.size()]; + int i=0; + int n =ArS.size(); + + for(i=0;i= max) + evalid = 2; + else + evalid = 1; + } + + /*Case: x x x+1*/ + if( (x = findX(0,0,1, score))!= -1 && evalid !=2) + { + y=x; + z=x+1; + if(z >= max) + evalid = 2; + else + evalid = 1; + } + + /*Case: x x+1 x+1*/ + if( (x = findX(0,1,1, score))!= -1 && evalid != 2) + { + y=x+1; + z=x+1; + if(z >= max) + evalid = 2; + else + evalid = 1; + } + return evalid; + } + + public static int findSurprised(int score, int max) { + int x=-1, y=-1,z=-1; + int evalid = 0; + /*Case: x x x+2*/ + if( (x = findX(0,0,2, score))!= -1 && evalid != 2) + { + y=x; + z=x+2; + if(z >= max) + evalid = 2; + else + evalid = 1; + } + + /*Case: x x+1 x+2*/ + if( (x = findX(0,1,2, score))!= -1 && evalid !=2) + { + y=x+1; + z=x+2; + if(z >= max) + evalid = 2; + else + evalid = 1; + } + + /*Case: x x+2 x+2*/ + if( (x = findX(0,2,2, score))!= -1 && evalid != 2) + { + y=x+2; + z=x+2; + if(z >= max) + evalid = 2; + else + evalid = 1; + } + return evalid; + } + + public static void fillOptions(int[] scores, int[] valid, int[]surprised, int max ) + { + for(int i = 0; i< scores.length; i++) + { + valid[i] = findValid(scores[i], max); + surprised[i] = findSurprised(scores[i], max); + valid[i] = valid[i]*10 + surprised[i]; + } + } + + public static int findNextSerprised(int[] valid) + { + int val =0; + Arrays.sort(valid); + int index = Arrays.binarySearch(valid, 2); + if(index < 0) + index = Arrays.binarySearch(valid, 12); + if(index < 0) + index = Arrays.binarySearch(valid, 22); + if(index < 0) + index = Arrays.binarySearch(valid, 01); + if(index < 0) + index = Arrays.binarySearch(valid, 11); + if(index < 0) + index = Arrays.binarySearch(valid, 21); + if(index >= 0) + { + val = valid[index]; + valid[index] = 0; + } + return val; + } + + public static void runCase (int[] scores, int S, int max, int caseNum) + { + int[] valid = new int[scores.length]; + int[] surprised = new int[scores.length]; + int count =0; + fillOptions(scores, valid, surprised, max); + for(int i =0; i< S; i++) + { + int val = findNextSerprised(valid); + if(val%10 == 2) + count++; + } + for(int i=0; i< scores.length; i++) + if(valid[i] >= 20) + count++; + System.out.print(""Case #"" +caseNum + "": ""+ count + ""\n""); + } + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + if(args.length != 1) + { + System.out.print(""Please enter file name!\n""); + return; + } + File fileName = new File(args[0]); + Scanner inFile = new Scanner(fileName); + int T = inFile.nextInt(); + for(int i=0; i < T; i++) + { + int N = inFile.nextInt(); + int S = inFile.nextInt(); + int max = inFile.nextInt(); + + int[] scores = new int[N]; + for(int j=0; j lines){ + Long[] arrL = new Long[lines.size()]; + for(int i=0;i= max) { + output++; + found = true; + } + } + if (!found) { + for (int j2 = 0; j2 < 3 && !found && sur > 0; j2++) { + if (calc[j][j2] + 1 >= max) { + if(sum[j]>2&& sum[j]%3!=1) + { + output++; + sur--; + found = true; + } + } + } + } + } + out.println(""Case #""+(i+1)+"": ""+output); + } + out.close(); + f.close(); + } + +} +" +A22819,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Dancing_With_the_Googlers { + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""input.in"")); + //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + FileWriter fw = new FileWriter(""output.txt""); + int t = Integer.parseInt(in.readLine()); + int num = 1; + while (t-- > 0) { + String[] a = in.readLine().split("" ""); + int n = Integer.parseInt(a[0]); + int s = Integer.parseInt(a[1]); + int p = Integer.parseInt(a[2]); + Integer[] inp = new Integer[n]; + for (int i = 0; i < inp.length; i++) { + inp[i] = Integer.parseInt(a[i + 3]); + } + Arrays.sort(inp); + int c = 0; + for (int i = 0; i < inp.length; i++) { + int first = inp[i] / 3; + int rem = inp[i] - first; + int second = rem / 2; + int third = rem - (rem / 2); + + if (first == second && second == third) { + if (first >= p) { + c++; + } else if (s > 0 && first > 0 && first + 1 >= p) { + c++; + s--; + } + } else if (first == second && second == third - 1) { + if (third >= p) + c++; + } else if (second == third) { + if (third >= p) { + c++; + } else if (third > 0 && third + 1 >= p && s > 0) { + c++; + s--; + } + } + } + fw.write(""Case #"" + num++ + "": "" + c + ""\n""); + } + fw.flush(); + fw.close(); + } +} +" +A21145,"package codejam; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; + +public class _Q_B_small { + public static void main(String[] args) throws Exception { + String input_file = ""B-large.in""; + String output_file = ""_Q_B_large_out.txt""; + + BufferedReader in = new BufferedReader(new FileReader(input_file)); + PrintStream out = new PrintStream(new FileOutputStream(output_file)); + + in.readLine(); + String line; + int case_num = 1; + while ((line=in.readLine()) != null) { + String[] line_str = line.split("" ""); + int n = Integer.parseInt(line_str[0]); + int s = Integer.parseInt(line_str[1]); + int p = Integer.parseInt(line_str[2]); + int[] t = new int[n]; + for (int i = 0; i < n; ++i) + t[i] = Integer.parseInt(line_str[i+3]); + + int[] base = new int[n]; + int[] remain = new int[n]; + + for (int i = 0; i < n; ++i) { + base[i] = t[i]/3; + remain[i] = t[i]%3; + } + + // Filter by p + ArrayList valid_index = new ArrayList(); + for (int i = 0; i < n; ++i) { + if (base[i] >= p - 1 || base[i] + remain[i] >= p) + valid_index.add(i); + } + + int s_consumed = 0; + int result = 0; + for (Integer i : valid_index) { + if (remain[i] == 0) { + if (base[i] < p) { + if (base[i] > 0 && s_consumed < s) { + ++s_consumed; + ++result; + } + } else { + ++result; + } + } + } + + for (Integer i : valid_index) { + if (remain[i] == 1) { + ++result; + } else if (remain[i] == 2){ + if (base[i] < p - 1) { + if (s_consumed < s) { + ++s_consumed; + ++result; + } + } else { + ++result; + } + } + } + + out.println(""Case #"" + case_num + "": "" + result); + ++case_num; + } + } +} +" +A22593,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +public class SecondQuestions { + + + private static long getLeastScore(long maxScore, long subtract) { + return (maxScore - subtract) < 0 ? 0 : (maxScore - subtract); + } + + public static void main(String[] args) throws Exception { + try { + Scanner sc = new Scanner(new File(""B-large.in"")); + BufferedWriter bufferedWriter = null; + bufferedWriter = new BufferedWriter(new FileWriter(""output.txt"")); + long totalCases = sc.nextLong(); + for (int i = 1; i <= totalCases; i++) { + long numContestants = sc.nextLong(); + long numSurprises = sc.nextLong(); + long maxScore = sc.nextLong(); + long minSurpriseTotalScore = maxScore + getLeastScore(maxScore, 2) + getLeastScore(maxScore, 2); + long minTotalScore = maxScore + getLeastScore(maxScore, 1) + getLeastScore(maxScore, 1); + long qualifiers = 0; + for (int j = 0; j < numContestants; j++) { + long nextScore = sc.nextLong(); + if ((nextScore >= minTotalScore)) { + qualifiers++; + } else if (((nextScore < minTotalScore) && ((nextScore >= minSurpriseTotalScore) && (numSurprises > 0)))) { + qualifiers++; + numSurprises--; + } + } + bufferedWriter.append(""Case #"" + i + "": ""); + bufferedWriter.append(String.valueOf(qualifiers)); + bufferedWriter.append(""\n""); + } + bufferedWriter.flush(); + bufferedWriter.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + +} +" +A20493,"import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintStream; + +import java.io.IOException; +import java.io.InputStreamReader; + +public class Dance { + private int[][] inputFin; + private int ArraySize; + private boolean surpriseLeftFlag; + private int caseCount=0; + /** + * @param args + * @throws IOException + */ + + public int[][] getInput() throws IOException { + boolean iFlag = false; + + FileInputStream rawfstream = new FileInputStream( + ""C:/Documents and Settings/Family/Desktop/B-small-attempt0.in""); + + DataInputStream in = new DataInputStream(rawfstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + // Print the content on the console + + if (!iFlag) { + iFlag = true; + strLine = br.readLine(); + ArraySize = Integer.parseInt(strLine); + + // print the triangular array (same as above really) + + inputFin = new int[ArraySize + 1][]; + inputFin[0] = new int[1]; + inputFin[0][0] = ArraySize; + + } + if (iFlag) { + int iCount1 = 1; + int iCount2 = 0; + while ((iCount1 <= ArraySize)) { + + String[] itemp = br.readLine().split("" ""); + + inputFin[iCount1] = new int[itemp.length]; + for (iCount2 = 0; iCount2 < itemp.length; iCount2++) { + + inputFin[iCount1][iCount2] = Integer + .parseInt(itemp[iCount2]); + // System.out.println( inputFin [iCount1][iCount2]); + + } + iCount1 = iCount1 + 1; + } + } + + this.setOutput(inputFin); + return inputFin; + + } + + public void setOutput(int[][] in) throws IOException { + int[] caseCountFinal=new int[ArraySize]; + for (int iCount = 1; iCount <= ArraySize; iCount++) { + getPossibleTriplet(iCount); + caseCountFinal[iCount-1]=caseCount; + } + printOutput (caseCountFinal, ArraySize); + } + + public int[][] getPossibleTriplet(int iCount) { + int googlers = inputFin[iCount][0]; + int supriseLeft = inputFin[iCount][1]; + int maxPoint = inputFin[iCount][2]; + int triplets[][] = new int[googlers][3]; + int iCount3 = -1; + int incre=googlers+3; + caseCount=0; + for (int iCount2 = 3; iCount2 < (incre ); iCount2++) { + iCount3 = iCount3 + 1; + //System.out.println(iCount2+""iCount2""); + + float temp = (inputFin[iCount][iCount2]); + // System.out.println(temp); + float temp2 = temp / 3; + // System.out.println(temp2); + //System.out.println(googlers); + if ((((temp2 % Math.round(temp2)) == 0)) && ((temp != 0))) { + + triplets[iCount3][0] = (int) temp2; + triplets[iCount3][1] = (int) temp2; + triplets[iCount3][2] = (int) temp2; + triplets = checkMax(triplets, supriseLeft, iCount3, maxPoint, + googlers); + googlers = googlers - 1; + if ((surpriseLeftFlag)&&(supriseLeft!=0)) { + supriseLeft = supriseLeft - 1; + surpriseLeftFlag = false; + + } + + } else { + temp = temp + 1; + temp2 = temp / 3; + // System.out.println(temp2); + if ((temp2 % Math.round(temp2)) == 0) { + triplets[iCount3][0] = (int) temp2; + triplets[iCount3][1] = (int) temp2; + triplets[iCount3][2] = (((int) (temp2)) - 1); + triplets = checkMax(triplets, supriseLeft, iCount3, + maxPoint, googlers); + googlers = googlers - 1; + if ((surpriseLeftFlag)&&(supriseLeft!=0)) { + supriseLeft = supriseLeft - 1; + surpriseLeftFlag = false; + + + } + + } else { + temp = temp - 2; + temp2 = temp / 3; + // System.out.println(temp2); + if ((temp2 % Math.round(temp2)) == 0) { + triplets[iCount3][0] = (int) temp2; + triplets[iCount3][1] = (int) temp2; + triplets[iCount3][2] = (((int) (temp2)) + 1); + triplets = checkMax(triplets, supriseLeft, iCount3, + maxPoint, googlers); + googlers = googlers - 1; + if ((surpriseLeftFlag) &&(supriseLeft!=0)){ + supriseLeft = supriseLeft - 1; + surpriseLeftFlag = false; + + } + + } else { + triplets = checkMax(triplets, supriseLeft, iCount3, + maxPoint, googlers); + googlers = googlers - 1; + if ((surpriseLeftFlag)&&(supriseLeft!=0)) { + supriseLeft = supriseLeft - 1; + surpriseLeftFlag = false; + + } + } + } + + } + + + } + /*for (int r = 0; r < triplets.length; r++) { + for (int c = 0; c < triplets[r].length; c++) { + System.out.print("" "" + triplets[r][c]); + } + System.out.println(""""); + + }*/ + System.out.println(""supriseLeft"" + supriseLeft); + return null; + + } + + public int[][] checkMax(int[][] triplets, int supriseLeft, int iCount3, + int maxPoint, int googlers) { + + if (((triplets[iCount3][0] >= maxPoint) + || (triplets[iCount3][1] >= maxPoint) || (triplets[iCount3][2] >= maxPoint)) + && (googlers != supriseLeft)) { + + caseCount=caseCount+1; + return triplets; + } else if ((((triplets[iCount3][0]) + 1) >= maxPoint) + && (supriseLeft != 0) && ((triplets[iCount3][0] != 10)) + && ((triplets[iCount3][1] != 0))) { + triplets[iCount3][0] = triplets[iCount3][0] + 1; + triplets[iCount3][0 + 1] = triplets[iCount3][0 + 1] - 1; + caseCount=caseCount+1; + surpriseLeftFlag = true; + } else if ((googlers == supriseLeft)&&((triplets[iCount3][1] != 0))) { + triplets[iCount3][0] = triplets[iCount3][0] + 1; + triplets[iCount3][0 + 1] = triplets[iCount3][0 + 1] - 1; + + surpriseLeftFlag = true; + } + else if(((googlers == supriseLeft)&&(supriseLeft!=0))) { + for(int iCount6=1;iCount6= target + 2 * Math.max(target - 1, 0)) { + ok++; + } else if (cur >= target + 2 * Math.max(target - 2, 0)) { + possible++; + } + } + + System.out.println(""Case #"" + i + "": "" + (ok + Math.min(suprising, possible))); + } + } finally { + fin.close(); + fout.close(); + } + } +} +" +A20024,"import java.util.ArrayList; +import java.util.HashSet; + + +public class DancingWithTheGooglers { +private static String inputFile = ""C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Input.txt""; +private static String outputFile = ""C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Output.txt""; +public static void main(String[] args) { + InputReader ir = new InputReader(inputFile); + OutputWriter ow = new OutputWriter(outputFile); + ArrayList lines = ir.loadLines(); + for(int i=1;i al = new ArrayList(); + for(int j=3;j=score || scoresArr[1] >=score ||scoresArr[2] >=score){ + count++; + }else if(remainder!=1 ){ + al.add(scoresArr); + } + } + for(int p=0;p 0; t--) { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + + int res = 0; + for (int i = 0; i < n; i++) { + int r = nextInt(); + if (r < p || (r - p) / 2 < p - 2) { + continue; + } + + if ((r - p) / 2 == p - 2 && s > 0) { + s--; + res++; + } else if ((r - p) / 2 > p - 2) { + res++; + } + } + + Case++; + println(""Case #"" + Case + "": "" + res); + } + } + + private String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + return tokenizer.nextToken(); + } + + private int nextInt() throws NumberFormatException, IOException { + return Integer.parseInt(nextToken()); + } + + private double nextDouble() throws NumberFormatException, IOException { + return Double.parseDouble(nextToken()); + } + + private long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + private void print(Object o) { + writer.print(o); + } + + private void println(Object o) { + writer.println(o); + } + + private void printf(String format, Object... o) { + writer.printf(format, o); + } + + public static void main(String[] args) { + long time = System.currentTimeMillis(); + Locale.setDefault(Locale.US); + new B().run(); + System.err.printf(""%.3f\n"", 1e-3 * (System.currentTimeMillis() - time)); + } + + BufferedReader reader; + StringTokenizer tokenizer; + PrintWriter writer; + + private void run() { + try { + reader = new BufferedReader(new InputStreamReader(System.in)); + writer = new PrintWriter(System.out); + reader = new BufferedReader(new FileReader(TASKNAME + "".in"")); + writer = new PrintWriter(TASKNAME + "".out""); + solve(); + reader.close(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(13); + } + } +} +" +A21850,"package Utils; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class FileHelper { + + private String path; + private int totalSize; + private List inputList; + private List outputList; + + public FileHelper(String path) { + this.path = path; + this.inputList = readFile(path); + this.totalSize = Integer.parseInt(inputList.get(0)); + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public int getTotalSize() { + return totalSize; + } + + public void setTotalSize(int totalSize) { + this.totalSize = totalSize; + } + + public List getInputList() { + return inputList; + } + + public void setInputList(List inputList) { + this.inputList = inputList; + } + + public List getOutputList() { + return outputList; + } + + public void setOutputList(List outputList) { + this.outputList = outputList; + } + + public static List readFile(String filepath) { + List rstList = new ArrayList(); + + try { + FileInputStream fstream = new FileInputStream(filepath); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + String strLine; + + // Read File Line By Line + while ((strLine = br.readLine()) != null) { + rstList.add(strLine); + } + + // Close the input stream + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + return rstList; + } + + public static void writeFile(String filepath, + List resList) { + try { + + FileWriter fstream = new FileWriter(filepath); + BufferedWriter out = new BufferedWriter(fstream); + for(int i = 0 ; i< resList.size();++i){ + out.write(resList.get(i)); + System.out.println(resList.get(i)); + if( i != resList.size() - 1) + out.newLine(); + } + // Close the output stream + out.close(); + + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + +} + + + + public int getInputTotalSize() { + + + return 0; + } + + public void init(String[] inputStr) { + for(int i = 1; i< this.inputList.size(); ++i ){ + inputStr[i - 1] = inputList.get(i); + } + } + + +} +" +A20409,"package MyAllgoritmicLib; + +public class NOK { + public static int lcm (int a, int b) + { + return a * b / NOD.gcd (a, b); + } + + public static long lcm (long a, long b) + { + return a * b / NOD.gcd (a, b); + } + + public static double lcm (double a, double b) + { + return a * b / NOD.gcd (a, b); + } +} +" +A20437,"/* +ID: yourID +LANG: JAVA +TASK: Dancing_With_the_Googlers +*/ +import java.io.*; +import java.math.*; +import java.util.*; +/*public class Dancing_With_the_Googlers { + +} + */ +public class Dancing_With_the_Googlers implements Runnable { + // based on Petr's template + boolean localDebug = false; + + private void solve() throws IOException { + int n = this.nextInt(); + int s = this.nextInt(); + int p = this.nextInt(); + int res = 0; + for ( int i = 0; i < n; i ++ ){ + int in = this.nextInt(); + if ( in >= p * 3 - 2 ){ + res ++; + continue; + } + if ( p < 2 ) + continue; + if ( in >= p * 3 - 4 && s > 0 ){ + res ++; + s --; + } + } + writer.println( res ); + } + + public static void main(String[] args) { + new Dancing_With_the_Googlers().run(); + } + + BufferedReader reader; + StringTokenizer tokenizer; + PrintWriter writer; + + public void run() { + try { + if (localDebug) { + reader = new BufferedReader(new InputStreamReader(System.in)); + writer = new PrintWriter(new OutputStreamWriter(System.out)); + } else { + writer = new PrintWriter(new BufferedWriter(new FileWriter( + ""B-large.out""))); + reader = new BufferedReader(new FileReader( + ""B-large.in"")); + } + tokenizer = null; + int t = this.nextInt(); + for ( int i = 1; i <= t; i ++ ){ + writer.print( ""Case #"" + i + "": "" ); + solve(); + } + reader.close(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + boolean hasNext() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + String nextLine = reader.readLine(); + if (nextLine == null) + return false; + tokenizer = new StringTokenizer(nextLine); + } + + return true; + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + String nextLine() throws IOException { + return reader.readLine(); + } + + String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + + return tokenizer.nextToken(); + } + + BigInteger nextBigInteger() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + + return new BigInteger(tokenizer.nextToken()); + } +}" +A22713,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class Dance { + static int no_Test_Cases =0; //number of test cases + static String input_Array[]; //to read input file + static int output_Array[]; // to write the t output lines + + public static void main(String[] args) { + readFile(); + + + for (int i = 0; i< no_Test_Cases; i++ ){ + googler_Dance(i); + } + + writeFile(); + } + + public static void readFile(){ + + try{ + FileInputStream fstream = new FileInputStream(""C:/sarab/input.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + String strLine; + + strLine = br.readLine(); + no_Test_Cases = Integer.parseInt(strLine); + + input_Array = new String[no_Test_Cases]; + output_Array = new int[no_Test_Cases]; + + for (int i = 0; i< no_Test_Cases; i++){ + strLine = br.readLine(); + input_Array[i] = strLine; + } + //Close the input stream + in.close(); + } + + catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + } + + public static void googler_Dance(int i){ + + String s1 = input_Array[i]; + + String s2[] = s1.split("" ""); + + int no_Googler = Integer.parseInt(s2[0]); + int no_Surprise = Integer.parseInt(s2[1]); + int best_Score = Integer.parseInt(s2[2]); + int counter = 0; // to count the no of googler getting more than best_Score + + + for (int i1 = 0; i1= best_Score) + counter++; + else { + if (no_Surprise > 0){ + if (x-1 >= 0 && x+1 <=10){ + if (x >= best_Score -1){ + counter++; + no_Surprise--; + } + } + } + } + break; + + case 1: + if (x >= best_Score -1) + counter++; + + break; + + case 2: + if (x >= best_Score -1) + counter++; + else { + if (no_Surprise > 0){ + if (x+2 <= 10){ + if (x >= best_Score -2){ + counter++; + no_Surprise--; + } + } + } + } + break; + + } + } + output_Array[i]= counter; + } + + + public static void writeFile(){ + String forOutput; + try{ + + FileWriter fstream = new FileWriter(""C:/sarab/output.txt""); + BufferedWriter out = new BufferedWriter(fstream); + for (int i=0; i 0) + ++count; + } + System.out.printf(""Case #%d: %d\n"", t, count); + } + } +} +" +A22675,"import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * @author Max Loewenthal + */ +public class B { + + public void solve(Scanner input, StringBuilder buffer) { + int N = input.nextInt(); + int surprisingScores = input.nextInt(); + int p = input.nextInt(); + + int candidates = 0; + int surprisingCandidates = 0; + + for (int i = 0; i = 3*p - 2 && total >= p) { + candidates = candidates + 1; + } + else if (total >= 3*p - 4 && total >= p) { + surprisingCandidates = surprisingCandidates + 1; + } + } + + buffer.append(Integer.toString(candidates + Math.min(surprisingCandidates, surprisingScores))); + } + + public static void main(String[] args) { + try { + InputStream input = System.in; + OutputStream output = System.out; + + if (args.length > 0) { + input = new FileInputStream(new File(args[0])); + } + + if (args.length > 1) { + File outputFile = new File(args[1]); + + if (outputFile.exists()) { + throw new Exception(""Output file already exists""); + } + + output = new FileOutputStream(new File(args[1])); + } + + Scanner scanner = new Scanner(input); + PrintWriter writer = new PrintWriter(output); + + B a = new B(); + + int count = scanner.nextInt(); + scanner.nextLine(); + + for (int i = 0; i < count; i++) { + StringBuilder result = new StringBuilder(); + a.solve(scanner, result); + + + writer.println(""Case #"" + (i + 1) + "": "" + result.toString()); + } + + writer.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A21433,"package com.google.jam.eaque.stub; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class InputFileManager { + + private BufferedReader br; + + public InputFileManager(String filePath) throws NumberFormatException, + IOException { + br = new BufferedReader(new FileReader(filePath)); + } + + public void close() throws IOException { + br.close(); + } + + public String readLine() throws IOException { + return br.readLine(); + } + + public long readLong() throws NumberFormatException, IOException { + return Long.parseLong(br.readLine()); + } + + public String[] readAndSplit() throws IOException { + return br.readLine().split("" ""); + } +} +" +A21439,"package template; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.util.ArrayList; + +public class TestCaseIO { + + public static ArrayList loadFromFile(String infile) { + //inc checks on #lines, length of splits, etc. + BufferedReader br = Utils.newBufferedReader(infile); + ArrayList tcList = new ArrayList<>(); + + //first line is N, the number of test cases + Integer N = Utils.readInteger(br); + + //cycle through N test cases + for (int x = 0; x < N; x++) { + TestCase tc = new TestCase(); + tc.setRef(x + 1); + + /////////////////////////////////////////////////////////// + //load properties - the bit to customise per problem + ArrayList l = Utils.readIntegerList(br); + tc.setIntegerList(""props"", l); + + /////////////////////////////////////////////////////////// + + tcList.add(tc); + } + + //confirm end of file + if (Utils.readLn(br) != null) { + Utils.die(""Unexpected text at end of infile""); + } + + return tcList; + } + + public static ArrayList mockUp() { + + ArrayList tcList = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + TestCase tc = new TestCase(); + tc.setRef(i); + + int[] xs = Utils.randomIntegerArray(100, -50, 50, i * 2); + int[] ys = Utils.randomIntegerArray(100, -50, 50, i * 2 + 1); + tc.setIntegerList(""xs"", Utils.arrayToArrayList(xs)); + tc.setIntegerList(""ys"", Utils.arrayToArrayList(ys)); + + tcList.add(tc); + } + return tcList; + } + + public static void writeSolutions(ArrayList tcList, String outfile) { + + BufferedWriter bw = Utils.newBufferedWriter(outfile, false); + + for (int i = 0; i < tcList.size(); i++) { + TestCase tc = tcList.get(i); + Object solution = tc.getSolution(); + String line = ""Case #"" + (i + 1) + "": "" + solution.toString(); + Utils.writeLn(bw, line); + } + + Utils.closeBw(bw); + + } +} +" +A22497,"package com.google.code.jam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class B { + public static int Case,N,S,p; + public static int[] Ti = new int[102]; + +// public static final String inputfileName = ""B-small.in""; +// public static final String outputfileName = ""B-small.out""; +// public static final String inputfileName = ""B-small-attempt6.in""; +// public static final String outputfileName = ""B-small-attempt6.out""; + public static final String inputfileName = ""B-large.in""; + public static final String outputfileName = ""B-large.out""; + + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + Scanner s = null; + PrintWriter outputStream = null; + + try{ + s = new Scanner(new BufferedReader( + new FileReader(inputfileName))); + outputStream = new PrintWriter( + new BufferedWriter(new FileWriter(outputfileName))); + Case = s.nextInt(); + for(int i=0;i=p){ + if(p==2){ + cntS++;rst++; + } + else if(p<2){ + rst++; + } + } + continue; + } + if(Ti[i]==5){ + if(p<=2){ + rst++; + } + else if(p==3){ + rst++;cntS++; + } + continue; + } + if(Ti[i]==4){ + if(p<=2){ + rst++; + } + continue; + } + if(Ti[i]==3){ + if(p<=1){ + rst++; + } + else if(p==2){ + rst++;cntS++; + } + continue; + } + if(Ti[i]%tmp==0){ + if(tmp>=p){ + rst++; + } + else if(tmp+1==p){ + rst++;cntS++; + } + } + else if(Ti[i]%tmp==1){ + if(tmp+1>=p){ + rst++; + } + }else{ + + if(tmp+1>=p){ + rst++; + } + else if(tmp+2>=p){ + rst++;cntS++; + } + } + } + //System.out.println(N); + if(cntS-S>0){ + rst -= cntS-S; + } + return rst; + } +} +" +A20089,"import java.util.Scanner; +import java.io.File; +import java.io.PrintWriter; + +public class B { + + + public static void main(String args[]){ + + try{ + File ifile = new File(args[0]); + File ofile = new File(args[1]); + + Scanner in = new Scanner(ifile); + PrintWriter out = new PrintWriter(ofile); + + int T = in.nextInt(); + + for(int ti=0;ti= (p*3)) res++; + else if( ((total+4) >= (p*3)) && S>0 && total!=0) {res++;S--;} + } + + out.format(""Case #%d: %d\n"", ti+1, res); + //out.println(""Case #"" + (i+1) + "": "" + t); + + } + out.flush(); + in.close(); + out.close(); + }catch(Exception e){e.printStackTrace();} + } +} +" +A20237,"package qualification; +import java.io.*; +import java.util.*; +import java.math.*; + +public class B +{ + //static String PROBLEM_NAME = ""b-practice""; + //static String PROBLEM_NAME = ""b-small-0""; + //static String PROBLEM_NAME = ""b-small-1""; + //static String PROBLEM_NAME = ""b-small-2""; + //static String PROBLEM_NAME = ""b-small-3""; + //static String PROBLEM_NAME = ""b-small-4""; + static String PROBLEM_NAME = ""b-large-0""; + + public int[] max = {-1,-1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,-1,-1}; + public int[] min = {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; + + public void solveCase() throws Exception + { + int N = INT(); + int S = INT(); + int P = INT(); + + int b = 0; + for(int i=0; i= P ) + b++; + else if( S > 0 && max[t] >= P ) + { + b++; + S--; + } + } + + println( b ); + } + + + + // ************************************************************************************* + // ****************** FRAMEWORK (borrowed from eireksten and modified) ***************** + // ************************************************************************************* + + public static File input; + public static FileReader inputreader; + public static BufferedReader in; + + public static File output; + public static FileWriter outputwriter; + public static BufferedWriter out; + + public static StringTokenizer st; + + public static void main(String[] args) throws Exception { + setInput(""problems/""+ PROBLEM_NAME +"".in""); + setOutput(""problems/""+ PROBLEM_NAME +"".out""); + B b = new B(); + int cases = INT(); + for(int cc = 1;cc<=cases;cc++) { + + print(""Case #""+cc+"": ""); + b.solveCase(); + } + + close(); + } + + // **************** HELPERS **************************** + + public static double[] converDoubleArray(ArrayList n){double[] ret=new double[n.size()];for(int i=0;i convertDoubleArray(double[] n){ArrayList arr = new ArrayList();for(int i=0; i n){long[] ret=new long[n.size()];for(int i=0;i convertLongArray(long[] n){ArrayList arr = new ArrayList();for(int i=0; i n){int[] ret=new int[n.size()];for(int i=0;i convertIntArray(int[] n){ArrayList arr = new ArrayList();for(int i=0; i void print( T[] array, String spacer){for(int i=0; i void println( T[] array, String spacer){print(array,spacer);println("""");} + + @SuppressWarnings(""unchecked"") + public static void print( List list ){print(list, "" "");} + @SuppressWarnings(""unchecked"") + public static void print( List list, String spacer ){int doSpace=0;for( Object obj : list ){ if( doSpace != 0 )print(spacer);print( obj );doSpace++;}} + + @SuppressWarnings(""unchecked"") + public static void println( List list ){println(list, "" "");} + @SuppressWarnings(""unchecked"") + public static void println( List list, String spacer ){int doSpace=0;for( Object obj : list ){ if( doSpace != 0 )print(spacer);print( obj );doSpace++;} println("""");} + + + + // ******************** INPUT DECLARATION ****************** + public static void setInput(String filename) throws IOException {input = new File(filename);inputreader = new FileReader(input);in = new BufferedReader(inputreader);} + public static void setOutput(String filename) throws IOException {output = new File(filename);outputwriter = new FileWriter(output);out = new BufferedWriter(outputwriter);} + public static void close() throws IOException {if(in!=null)in.close();if(inputreader!=null)inputreader.close();if(out!=null)out.flush();if(out!=null)out.close();if(outputwriter!=null)outputwriter.close();} + + // ************************** INPUT READING ***************** + static String LINE() throws IOException { return in.readLine(); } + static String TOKEN() throws IOException {while (st == null || !st.hasMoreTokens())st = new StringTokenizer(LINE());return st.nextToken();} + static int INT() throws IOException {return Integer.parseInt(TOKEN());} + static long LONG() throws IOException {return Long.parseLong(TOKEN());} + static double DOUBLE() throws IOException {return Double.parseDouble(TOKEN());} + static BigInteger BIGINT() throws IOException {return new BigInteger(TOKEN());} + + + //**************** PERMUTATIONS ********************** +// new Permutation(20) will create 20 objects +// and steps through the different orderings + // +// .hasMore() .getTotal() .getNumLeft() +// .getNext() .reset() + //--------------------------------- + class Permutation { + private int[] a; private long numLeft; private long total; + public Permutation(int n) { a = new int[n]; total = getFactorial (n); reset (); } + public void reset () {for (int i = 0; i < a.length; i++) { a[i] = i; } numLeft = total; } + public long getNumLeft () { return numLeft; } public long getTotal () { return total; } public boolean hasMore () { return numLeft > 0; } + private long getFactorial (int n) { long fact = 1;for (int i = n; i > 1; i--) {fact *= i; } return fact; } + public int[] getNext () { if ( numLeft == total) { numLeft--; return a; } int temp; + int j = a.length - 2; while (a[j] > a[j+1]) { j--; } int k = a.length - 1; while (a[j] > a[k]) { k--; } + temp = a[k]; a[k] = a[j]; a[j] = temp; int r = a.length - 1; int s = j + 1; while (r > s) { temp = a[s]; a[s] = a[r]; a[r] = temp; r--; s++; } + numLeft--; return a; } + } + + //**************** COMBINATIONS ********************** + //new Combination(24,5) will create 24 objects + //and chooses 5 at a time + // + //.hasMore() .getTotal() .getNumLeft() + //.getNext() .reset() + //--------------------------------- + class Combination { + private int[] a; private int n; private int r;private long numLeft;private long total; + public Combination (int n, int r) { + this.n = n;this.r = r;a = new int[r]; + BigInteger nFact = getFactorial (n);BigInteger rFact = getFactorial (r);BigInteger nminusrFact = getFactorial (n - r);total = nFact.divide (rFact.multiply (nminusrFact)).longValue();reset ();} + + public void reset () {for (int i = 0; i < a.length; i++) {a[i] = i;}numLeft=total;} + public long getNumLeft () {return numLeft;} public boolean hasMore () {return numLeft > 0;} public long getTotal () {return total;} + private BigInteger getFactorial (int n) {BigInteger fact = BigInteger.ONE;for (int i = n; i > 1; i--) {fact = fact.multiply (new BigInteger (Integer.toString (i)));}return fact;} + public int[] getNext () {if (numLeft == total) {numLeft--; return a;}int i = r - 1;while (a[i] == n - r + i) {i--;}a[i] = a[i] + 1; + for (int j = i + 1; j < r; j++) { a[j] = a[i] + j - i;} numLeft--; return a;} + } + + //**************** Coloring ********************** + //new Coloring(24,5) will create 24 objects + //and color each up to 5 different ways. + // + //.hasMore() .getTotal() .getNumLeft() + //.getNext() .reset() + //--------------------------------- + class Coloring { + private int[] a;private int r;private long numLeft; private long total; + public Coloring (int n, int r){this.r = r;a = new int[n];total = (long) Math.pow(r, n); reset();} + public void reset(){for(int i=0;i 0;} + public long getTotal () {return total;} + public int[] getNext () {numLeft--;a[0]++;int j=0;while(a[j]==r){a[j]=0;a[j+1]++;j++;}return a;} + } + +}" +A20579,"import java.io.*; +import java.util.StringTokenizer; +public class Dancing +{ + public static void main(String[] args) + { + + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + + int tc,data[],result[],nog,sc,exno; + int av,rem,count; + String s,s1; + StringTokenizer st; + + try + { + tc=Integer.parseInt(br.readLine()); + result=new int[tc]; + for(int i=0;i=exno) + { + count++; + continue; + } + + if(rem==0&&sc!=0&&av+1>=exno&&data[k]>exno) + { + sc--; + count++; + continue; + } + + if(rem==1&&(av+rem)>=exno) + { + count++; + continue; + } + + if(rem==2) + { + if(av+1>=exno) + { + count++; + continue; + } + if(sc!=0&&av+2>=exno) + { + count++; + sc--; + } + } + + + } + + result[i]=count; + + + } + + for(int i=0;i= testCase.scoreToBeat) { + System.out.println(""1 processing score: "" + score); + possibleGooglers++; + } else if (tripletScore == 0 && testCase.scoreToBeat> 0) { + //continue; + System.out.println(""2 processing score: "" + score); + } else if (quotient + 2 < testCase.scoreToBeat) { + //continue; + System.out.println(""3 processing score: "" + score); + } else if (quotient + 2 == testCase.scoreToBeat && modulus == 2 && usedSurprises < testCase.surprises) { + possibleGooglers++; + usedSurprises++; + System.out.println(""3A processing score: "" + score); + } else if (quotient + 2 == testCase.scoreToBeat ) { + //continue + System.out.println(""4 processing score: "" + score); + } else if (modulus > 0) { + possibleGooglers++; + System.out.println(""5 processing score: "" + score); + } else if (modulus == 0 && usedSurprises < testCase.surprises) { + possibleGooglers++; + usedSurprises++; + System.out.println(""6 processing score: "" + score); + } else if (modulus == 0 && usedSurprises >= testCase.surprises) { + //continue + System.out.println(""7 processing score: "" + score); + } else { + throw new IllegalArgumentException(""couldn't handle score: "" + score); + } + } + + testCase.setAnswer(possibleGooglers); + } + + public static DancingTestCase parseString(final int testCaseNumber, final String s) { + StringTokenizer tokenizer = new StringTokenizer(s); + String dancerString = tokenizer.nextToken(); + int numberOfDancers = Integer.parseInt(dancerString); + String surpriseString = tokenizer.nextToken(); + int surprises = Integer.parseInt(surpriseString); + String scoreString = tokenizer.nextToken(); + int scoreToBeat = Integer.parseInt(scoreString); + ArrayList scores = new ArrayList(numberOfDancers); + while (tokenizer.hasMoreTokens()) { + scores.add(tokenizer.nextToken()); + } + return new DancingTestCase(testCaseNumber, numberOfDancers, surprises, scoreToBeat, scores ); + } + + + static class DancingTestCase implements Comparable { + final int testCaseNumber; + final int numberOfDancers; + final int surprises; + final int scoreToBeat; + final List totalScores; + private int answer; + + public DancingTestCase(int testCaseNumber, int numberOfDancers, int surprises, int scoreToBeat, List totalScores) { + this.testCaseNumber = testCaseNumber; + this.numberOfDancers = numberOfDancers; + this.surprises = surprises; + this.scoreToBeat = scoreToBeat; + + this.totalScores = totalScores; + } + + public int compareTo(Object o) { + return 0; + } + + public int getAnswer() { + return answer; + } + + public void setAnswer(int answer) { + this.answer = answer; + } + } +} +" +A21717,"package codejam; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Arrays; + +public class Googler +{ + + public static void main(String[] args) throws Exception + { + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""/home/ankush/Downloads/B-large.in""))); + int i =1; + int n = Integer.parseInt(reader.readLine()); + PrintWriter pw = new PrintWriter(""2.out""); + for(; i<=n; i++) + { + String input = reader.readLine(); + pw.print(""Case #"" + i + "": ""); + String[] sp = input.split("" ""); + int numData = Integer.parseInt(sp[0]); + int s = Integer.parseInt(sp[1]); + int p = Integer.parseInt(sp[2]); + + int[] data = new int[numData]; + for(int j=0; j=0 && s>=0; i--) + { + if(data[i] % 3 == 0) + { + if(data[i]/3 >= p) + { + count++; + continue; + } + else if(data[i]/3 + 1 >=p && s>0 && data[i]/3 -1 >=0) + { + count++; + s--; + continue; + } + else + { + break; + } + } + else if(data[i] % 3 == 2) + { + if((data[i]/3 >= p) || data[i]/3 + 1 >=p) + { + count++; + continue; + } + else if(data[i]/3 + 2 >=p && s>0) + { + count++; + s--; + continue; + } + else + { + break; + } + } + else + { + if((data[i]/3 >= p) || data[i]/3 + 1 >=p) + { + count++; + continue; + } + else if(data[i]/3 - 1 >=p && s>0 && data[i]/3 - 1>=0) + { + count++; + s--; + continue; + } + else + { + break; + } + } + } + + return count; + } + +} +" +A20746,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + + +public class DacingScore { + + public static String SMALL_IN_FILE_NAME = ""./B-large.txt""; + static PrintStream out = null; + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + File smallIn = new File(SMALL_IN_FILE_NAME); + BufferedReader br = new BufferedReader(new FileReader(smallIn)); + String s = br.readLine(); + int caseCount = Integer.parseInt(s); + File smallOut = new File(""./output.txt""); + smallOut.createNewFile(); + out = new PrintStream(smallOut); +// out = System.out; + + for (int i = 0; i < caseCount; i ++) { + out.printf(""Case #%d: "", i+1); + s = br.readLine(); + TestCase t = new TestCase(s); + out.println(solveTestCase(t)); + } + System.out.println(""Done""); + } + private static int solveTestCase(TestCase t) { + int p = t.getpScore(); + int sCount = t.getSuprisingCount(); + ArrayList triplets = t.getTriplets(); + ArrayList normal = new ArrayList(); + ArrayList candidate = new ArrayList(); + ArrayList failed = new ArrayList(); + int sNormal = 0, sCandidate = 0, sFailed = 0; + for (Triplet triplet : triplets) { + if (triplet.getBest(false) >= p) { + normal.add(triplet); + if (triplet.isSuprisable()) { + sNormal ++; + } + } else if (triplet.getBest(true) >= p) { + candidate.add(triplet); + sCandidate++; + } else { + failed.add(triplet); + if (triplet.isSuprisable()) { + sFailed++; + } + } + } + int result = -1; + if (candidate.size() >= sCount) { + // plenty of candidates + result = normal.size() + sCount; + } else { + result = normal.size() + candidate.size(); + } + return result; + } +} +" +A21179,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +public class B { + Map mapLenguaje; + + public static void main(String arg[]) { + try { + StringBuffer line; + + File file = new File(""C:/Documents and Settings/jjmamby/Mis documentos/Descargas/B-large.in""); + int T = 0, N = 0, S = 0, maxP, t, bestResult, p; + StringBuilder output = new StringBuilder(); + if (file.exists()) { + BufferedReader input = new BufferedReader(new FileReader(file)); + + T = Integer.valueOf((input.readLine())); + for (int i = 0; i < T; i++) { + line = new StringBuffer(input.readLine()); + StringTokenizer st = new StringTokenizer(line.toString(), "" ""); + N = Integer.valueOf(st.nextToken()); + S = Integer.valueOf(st.nextToken()); + maxP = Integer.valueOf(st.nextToken()); + p = 0; + for(int j = 0; j < N; j++){ + t = Integer.valueOf(st.nextToken()); + int aux1 = t / 3 ; + bestResult = aux1; + int aux2 = (t - aux1) / 2 ; + + if(aux2>bestResult){ + bestResult = aux2; + } + int aux3 = (t - aux1 - aux2) ; + if(aux3>bestResult){ + bestResult = aux3; + } + + if(maxP<=aux3){ + p++; + }else if (t > 2 && t < 28){ + aux2--; + aux3++; + if(maxP<=aux3&& S>0 ){ + S--; + p++; + } + } + } + output.append(""Case #""); + output.append((i+1)); + output.append("": ""); + output.append(p); + output.append(""\n""); + } + System.out.println(output.toString()); + }else{ + output.append(""No hay Archivo""); + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} +" +A22090,"package q2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWiththeGooglers { + public static void main(String[] args) throws Exception { + String input = ""B-large.in""; + String output = ""B-large.out""; + + Scanner scan = new Scanner(new BufferedReader(new FileReader(input))); + PrintWriter pw = new PrintWriter(new BufferedWriter( + new FileWriter(output))); + + int T = Integer.parseInt(scan.nextLine()); + for (int t = 1; t <= T; t++) { + String[] info = scan.nextLine().split("" ""); + int N = Integer.parseInt(info[0]); + int S = Integer.parseInt(info[1]); + int p = Integer.parseInt(info[2]); + int[] score = new int[N]; + for (int i = 0; i < N; i++) + score[i] = Integer.parseInt(info[3 + i]); + int countp = 0; + int counts = 0; + int must = p + 2 * Math.max(0, p - 1); + int might = p + 2 * Math.max(0, p - 2); + for (int i = 0; i < N; i++) + if (score[i] >= must) + countp++; + else if (score[i] >= might) + counts++; + int res = countp + Math.min(counts, S); + pw.println(""Case #"" + t + "": "" + res); + } + + scan.close(); + pw.close(); + } + +} +" +A20400,"package qualification.taskA; + +import java.util.Map; + +public class Task { + + private Map dictionary ; + + public Task(Map dictionary ) { + this.dictionary = dictionary; + } + + public String execute(String original) { + StringBuilder result = new StringBuilder(); + for(int i = 0; i < original.length(); i++){ + result.append(dictionary.get(original.charAt(i))); + } + return result.toString(); + } + +} +" +A22311,"import java.io.*; +import java.util.*; +import java.util.regex.*; + +public class jam02 { + + /** + * @param args + */ + + public static void main1(){ + // scalar product problem + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + + int number_test; + Scanner sc = new Scanner(System.in); + number_test = sc.nextInt(); + for(int j=1;j<=number_test;j++) { + int numOfGooglers = sc.nextInt(); + int numOfSurprises = sc.nextInt(); + int surPrisingNum = sc.nextInt(); + int[] googlers = new int[numOfGooglers]; + for(int i=0;i= (surPrisingNum*3)-2) + { + finalGuys++; + } + else if(numOfSurprises !=0 && googlers[i] !=0 && googlers[i] >= (surPrisingNum*3)-4) + { + finalGuys++; + numOfSurprises--; + } + } + System.out.println(finalGuys); + + } +} +" +A22011,"import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + + +public class Main extends AbstractCodeJam { + + @Override + protected Problem readProblem(Scanner scan) { + ProblemSample pb = new ProblemSample(); + int N = scan.nextInt(); + pb.setS(scan.nextInt()); + pb.setP(scan.nextInt()); + List scores = new ArrayList(); + for (int i = 0; i < N; i++) { + scores.add(scan.nextInt()); + } + pb.setScores(scores); + return pb; + } + + /** + * @param args + */ + public static void main(String[] args) { + new Main().solveProblems(System.in, System.out); + } + +} +" +A22695,"package google.codejam; + + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class Main { + private static boolean debug = false; + + public static void main(String [] args){ + if(args!=null && args.length==2){ + FileInputStream fstream = null; + try { + fstream = new FileInputStream(args[0]); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + File file = new File(args[1]); + + FileWriter fstreamOut = new FileWriter(file.getAbsolutePath()); + BufferedWriter out = new BufferedWriter(fstreamOut); + + + int lineNum = Integer.parseInt(br.readLine()); + + GoogleSolver solver = new DanceGoogler(); + //GooglereseSolver.calcualteMapping(); + + + for(int i=0 ; i"" + resultStr); + }else{ + String output = ""Case #""+(i+1) +"": "" + resultStr; + System.out.println (output); + out.write(output+""\n""); + } + } + + out.close(); + in.close(); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + } +} +" +A22405,"import java.util.Scanner; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.File; + +public class B_Small { + static int[][] table = { {0}, {1}, {1,2}, {1,2}, {2}, {2,3}, {2,3}, {3}, {3,4}, {3,4}, {4}, {4,5}, {4,5}, {5}, {5,6}, {5,6}, {6}, {6,7}, {6,7}, {7}, {7,8}, {7,8}, {8}, {8,9}, {8,9}, {9}, {9,10}, {9,10}, {10}, {10}, {10}}; + public static void main(String[] args) { + try { + FileWriter writer = new FileWriter(""B-large-attempt.out""); + BufferedWriter out = new BufferedWriter(writer); + String current, result; + result = """"; + Scanner sc = new Scanner(new File(""B-large.in"")); + int x = Integer.parseInt(sc.nextLine()); + for (int k = 0; k < x; k++) { + result = ""Case #"" + (k+1) + "": ""; + current = sc.nextLine(); + int count = 0; + String[] cur = current.split("" ""); + int z = Integer.parseInt(cur[0]); + int s = Integer.parseInt(cur[1]); + int p = Integer.parseInt(cur[2]); + for (int t = 3; t < cur.length; t++) { + int score = Integer.parseInt(cur[t]); + int[] special = table[score]; + if (special[0] >= p) { + count++; + } else if (s > 0 && special.length > 1) { + if (special[1] >=p) { + count++; + s--; + } + } + } + result += count; + out.write(result); + out.newLine(); + } + out.close(); + } catch (Exception e) { + System.out.println(""error""); + } + } + +} +" +A21473,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package gcj_b; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author kay + */ +public class Generate { + + private BufferedReader reader; + private StringTokenizer token; + + public void do_processing(String filename) { + String current_line; + int no_of_cases; + try { + reader = new BufferedReader(new FileReader(filename)); + FileWriter fstream = new FileWriter(""G:/b_out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + no_of_cases = Integer.parseInt(reader.readLine()); + + for (int i = 1; i <= no_of_cases; i++) { + current_line = reader.readLine(); + out.write(""Case #"" + i + "": ""); + out.write(String.valueOf(do_generate(current_line))); + //out.write(String.valueOf(3)); + System.out.println(""outputttttttttttttttt "" + do_generate(current_line)); + out.newLine(); + //Close the output stream + } + out.close(); + reader.close(); + } catch (Exception ex) { + Logger.getLogger(Generate.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public int do_generate(String line) { + int max_num = 0, temp, remain, max=0, min=10, output = 0; + Boolean contains = false; + int googlers, surprises, best_value; + token = new StringTokenizer(line); + int triplet[] = new int[3]; + + googlers = Integer.parseInt(token.nextToken()); + surprises = Integer.parseInt(token.nextToken()); + best_value = Integer.parseInt(token.nextToken()); + int scores[] = new int[googlers]; + + for (int i = 0; i < scores.length; i++) { + scores[i] = Integer.parseInt(token.nextToken()); + } + + for (int i = 0; i < scores.length; i++) { + contains = false; + if (scores[i] == 0){ + if(best_value ==0){ + output++; + } + }else{ + temp = scores[i] / 3; + for (int j = 0; j < triplet.length; j++) { + triplet[j] = temp; + } + remain = scores[i] - (temp * 3); + System.out.print(""remain "" + remain + "" ""); + for (int k = 0; k < remain; k++) { + triplet[k] += 1; + } + for (int k = 0; k < triplet.length; k++) { + System.out.print(triplet[k] + "" ""); + } + System.out.println(); + + for (int k = 0; k < triplet.length; k++) { + if (triplet[k] >= best_value){ + contains = true; + } + } + if (surprises > 0 && !contains){ + if (remain == 1) { + triplet[1] -= 1; + triplet[2] += 1; + } else { + triplet[0] -= 1; + triplet[1] += 1; + } + } + + for (int k = 0; k < triplet.length; k++) { + System.out.print(triplet[k] + "" ""); + } + System.out.println(); + + max = 0; min = 10; contains = false; + for (int k = 0; k < triplet.length; k++) { + if(triplet[k] > max) + max = triplet[k]; + if(triplet[k] < min) + min = triplet[k]; + } + System.out.println(""max "" + max); + System.out.println(""min "" + min); + + for (int k = 0; k < triplet.length; k++) { + if (triplet[k] >= best_value){ + contains = true; + } + } + if ((max - min == 2) && contains){ + surprises--; + output++; + System.out.println(""output increase ""); + } else if(contains){ + System.out.println(""contains ""); + output++; + } + + } + + } + System.out.println(""output: "" + output); + + + + + return output; + } + + public void set_suprises() { + } +} +" +A22818,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Locale; +import java.util.StringTokenizer; + +public class Main { + FileScanner in; + PrintWriter out; + String Filename = ""trie""; + + public static void main(String[] args) throws Exception { + new Main().run(); + } + + public void run() throws Exception { + Locale.setDefault(Locale.US); + in = new FileScanner(""input""); + out = new PrintWriter(""output""); + + solve(); + + out.close(); + } + + void solve() throws Exception { + int n = in.nextInt(); + for (int i = 0; i < n; i++) { + out.print(""Case #"" + (i + 1) + "": ""); + int num = in.nextInt(); + int sup = in.nextInt(); + int p = in.nextInt(); + int ans = 0; + int mayBe = 0; + for (int j = 0; j < num; j++) { + int temp = in.nextInt(); + if (temp % 3 == 0) { + if (temp / 3 >= p) { + ans++; + continue; + } + if ((temp / 3 + 1 >= p) && (temp / 3 - 1 >= 0)) { + mayBe++; + continue; + } + continue; + } + + if (temp % 3 == 1) { + if (temp / 3 + 1 >= p) { + ans++; + continue; + } + continue; + } + + if (temp % 3 == 2) { + if (temp / 3 + 1 >= p) { + ans++; + continue; + } + if ((temp / 3 + 2 >= p) && (temp / 3 + 2 < 11)) { + mayBe++; + continue; + } + continue; + } + } + ans += Math.min(sup, mayBe); + out.println(ans); + } + } + + class FileScanner { + BufferedReader br; + StringTokenizer st; + + public FileScanner(String File) throws Exception { + br = new BufferedReader(new FileReader(File)); + } + + String nextLine() throws Exception { + return br.readLine(); + } + + String next() throws Exception { + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(br.readLine()); + } + return st.nextToken(); + } + + public int nextInt() throws Exception { + return Integer.parseInt(next()); + } + + public long nextLong() throws Exception { + return Long.parseLong(next()); + } + } +}" +A21697,"package cw.codejam; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.Stack; + +class Dance_B { + List cases = new ArrayList<>(); + + private static class Bcase{ + int targetScore, surprises; + List totals = new ArrayList<>(); + int answer; + } + + public static void main(String[] args) { + Dance_B dance = new Dance_B(); + + File infile = new File(args[0]); + File outfile = new File(infile.getParent(), ""b.out.txt""); + + dance.parse(infile); + dance.solve(); + dance.output(outfile); + } + + /** + * Pop the highest sorted totals. Utilize surprise scores to achieve max spread for max results + */ + void solve() { + for(Bcase bcase : cases){ + //e.g.: desire 8, score=8 7 7 + int minBaseline = Math.max(bcase.targetScore * 3 - 2, 0); + + //e.g.: desire 8, score = 8 6 6 + int minSurpriseBaseline = Math.max(bcase.targetScore * 3 - 4, 0); + + //sort and build stack + Collections.sort(bcase.totals); + Stack stack = new Stack<>(); + for(int i: bcase.totals){ + stack.push(i); + } + + while(!stack.isEmpty()){ + //highest total on the stack + int aScore = stack.pop(); + + //special case for 0 total. A 0 total means each vote is 0 + if(aScore == 0 ){ + if(bcase.targetScore == 0){ + bcase.answer++; + } + } else if(aScore >= minBaseline){ + //done, easy spread + bcase.answer++; + } else if (bcase.surprises > 0){ + //attempt to use a surprise score + if(aScore >= minSurpriseBaseline){ + bcase.surprises--; + bcase.answer++; + } + } + } + } + } + + void parse(File infile) { + try (Scanner scanner = new Scanner(infile)) { + int numCases = Integer.parseInt(scanner.nextLine()); + for (int i = 0; i < numCases; i++) { + Bcase bcase = new Bcase(); + final int n = scanner.nextInt(); + bcase.surprises = scanner.nextInt(); + bcase.targetScore = scanner.nextInt(); + + for(int x=0; x0) && haveSurprisingNoteOverP(points,p)) { + s--; + maxNoteContestants++; + } + } + writer.write(""Case #""+test+"": ""+maxNoteContestants+""\n""); + } + } + + private boolean haveSurprisingNoteOverP(int points, int p) { + int note = points / 3; + int modulo = points % 3; + if ((modulo == 0) && (note+1<=10) && (note-1>=0) && (note+1>=p)) { + return true; + } + else if ((modulo == 2) && (note+2 <= 10) && ( note+2>=p)) { + return true; + } + return false; + } + + private boolean haveNormalNoteOverP(int points, int p) { + int note = points / 3; + int modulo = points % 3; + if (((modulo == 0) && (note>=p)) || ((modulo>0) && (note+1>=p))) { + return true; + } + return false; + } + + public QualificationB2012(String inputFile, String outputFile) { + this.inputFile = inputFile; + this.outputFile = outputFile; + } + + private void closeFiles() { + try { + reader.close(); + writer.close(); + } + catch (Exception e) { + throw new RuntimeException(); + } + + } + + private void openFiles() { + try { + reader = new BufferedReader(new FileReader(inputFile)); + writer = new BufferedWriter(new FileWriter(outputFile)); + } + catch (Exception e) { + throw new RuntimeException(""File initialization failed""); + } + } +} +" +A22751,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class Runner { + + /** + * @param args + */ + public static void main(String[] args) { + new Runner().run(); + } + + +void printHelloWorld(String x) +{ + System.out.println(""Print Hello World For ,"" + x); +} + +void run() +{ + File file = new File(""input.in""); + + Scanner input; + FileWriter fstream = null; + + try { + input = new Scanner(file); + + int numberOfTestCases = input.nextInt(); + fstream = new FileWriter(""out.out""); + BufferedWriter out = new BufferedWriter(fstream); + + for(int i = 0 ; i < numberOfTestCases ; i++){ + + int numberOfGooglers = input.nextInt(); + int surprisingAllowed = input.nextInt(); + int limitScore = input.nextInt(); + + int numberOfAddedSuperrised = 0; + int numberOfMayUsedSurprisedGooglers = 0; + int totalNumberOfGoolgersPassedLimit = 0; + + for (int j = 0; j < numberOfGooglers; j++) { + + int googlerTotalScore = input.nextInt(); + int division = googlerTotalScore / 3; + + if(googlerTotalScore % 3 == 0 ){ + + if(division >= limitScore){ + totalNumberOfGoolgersPassedLimit++; + }else{ + if(division != 0 && division+1 >= limitScore){ + numberOfMayUsedSurprisedGooglers++; + } + } + + }else if(googlerTotalScore % 3 == 1 ) { + + if(division+1 >= limitScore){ + totalNumberOfGoolgersPassedLimit++; + } + + }else if(googlerTotalScore % 3 == 2 ){ + + if(division+1 >= limitScore){ + totalNumberOfGoolgersPassedLimit++; + }else if(division+2 >= limitScore){ + numberOfMayUsedSurprisedGooglers++; + } + + } + } + + numberOfAddedSuperrised = (numberOfMayUsedSurprisedGooglers > surprisingAllowed) ? surprisingAllowed : numberOfMayUsedSurprisedGooglers; + totalNumberOfGoolgersPassedLimit += numberOfAddedSuperrised; + out.write(""Case #"" + (i+1) +"": ""+ totalNumberOfGoolgersPassedLimit +""\n""); + } + + + input.close(); + out.close(); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + +} + +} +" +A20858,"package utils; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Fabien Renaud + */ +public class File { + + public static boolean delete(String filename) { + java.io.File f = new java.io.File(filename); + if (f != null) { + return f.delete(); + } + return false; + } + + public static String[] readAllLines(String filename) { + return readAllLines(new java.io.File(filename)); + } + + public static String[] readAllLines(java.io.File file) { + List list = new ArrayList(); + + try { + BufferedReader input = new BufferedReader(new FileReader(file)); + try { + String line = null; + + while ((line = input.readLine()) != null) { + list.add(line); + } + } finally { + input.close(); + } + } catch (IOException ex) { + Logger.getLogger(File.class.getName()).log(Level.SEVERE, null, ex); + } + + String[] s = new String[list.size()]; + return list.toArray(s); + } + + public static String readAllText(String filename) { + return readAllText(new java.io.File(filename)); + } + + public static String readAllText(java.io.File file) { + StringBuilder content = new StringBuilder(); + String lf = System.getProperty(""line.separator""); + + try { + BufferedReader input = new BufferedReader(new FileReader(file)); + try { + String line = null; + + while ((line = input.readLine()) != null) { + content.append(line); + content.append(lf); + } + } finally { + input.close(); + } + } catch (IOException ex) { + Logger.getLogger(File.class.getName()).log(Level.SEVERE, null, ex); + } + + return content.toString(); + } + + public static byte[] readAllBytes(String filename) { + return readAllBytes(new java.io.File(filename)); + } + + public static byte[] readAllBytes(java.io.File file) { + byte[] bytes = new byte[0]; + InputStream is = null; + try { + is = new FileInputStream(file); + long length = file.length(); + if (length > Integer.MAX_VALUE) { + // File is too large + } + + bytes = new byte[(int) length]; + int offset = 0; + int numRead = 0; + while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { + offset += numRead; + } + if (offset < bytes.length) { + throw new IOException(""Could not completely read file "" + file.getName()); + } + is.close(); + } catch (Exception ex) { + Logger.getLogger(File.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + is.close(); + } catch (IOException ex) { + Logger.getLogger(File.class.getName()).log(Level.SEVERE, null, ex); + } + } + return bytes; + } + + public static void writeAllLines(String filename, String[] lines) { + writeAllLines(new java.io.File(filename), lines); + } + + public static void writeAllLines(java.io.File file, String[] lines) { + String lf = System.getProperty(""line.separator""); + + try { + FileWriter fw = new FileWriter(file); + for (String l : lines) { + fw.write(l); + fw.write(lf); + fw.flush(); + } + fw.close(); + } catch (IOException ex) { + Logger.getLogger(File.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static void writeAllText(String filename, String text) { + writeAllText(new java.io.File(filename), text); + } + + public static void writeAllText(java.io.File file, String text) { + String lf = System.getProperty(""line.separator""); + + try { + FileWriter fw = new FileWriter(file); + fw.write(text); + fw.flush(); + fw.close(); + } catch (IOException ex) { + Logger.getLogger(File.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static void writeAllBytes(String filename, byte[] bytes) { + writeAllBytes(new java.io.File(filename), bytes); + } + + public static void writeAllBytes(java.io.File file, byte[] bytes) { + try { + FileOutputStream fos = new FileOutputStream(file); + fos.write(bytes); + fos.close(); + } catch (Exception ex) { + Logger.getLogger(File.class.getName()).log(Level.SEVERE, null, ex); + } + } +} +" +A22904,"package Q2; +public class ChooseCalc { + private long[][] chooseCache; + + public ChooseCalc(int cacheSize, boolean readyCache) { + chooseCache = new long[cacheSize][cacheSize]; + for(int i=0;iMath.max(k, n-k);i--){ + $ *= i; + } + for(int i=1;i<=Math.min(k, n-k);i++){ + $ /= i; + } + return $; + } + + public long choose(int k, int n) { + if(chooseCache[n][k] == -1) chooseCache[n][k] = perm(n, k); + return chooseCache[n][k]; + } + + public long cached(int k, int n){ + return chooseCache[n][k]; + } + + public long choosewithRep(int k, int n){ + return choose(k, n)*(n-k); + } +} +" +A21797,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Apr 14, 2012  + * @author parisel + * GGJ - Qualification Round + */ +public class B { + private static final int TEST= 0, SMALL= 1, LARGE= 2; + private static final String[] infile= { ""-test.in"", ""-small.in"", ""-large.in""}; + private static final String[] outfile= {""-test.out"", ""-small.out"", ""-large.out""}; + java.io.BufferedReader br; + java.io.PrintWriter out; + String[] tok; + + private String[] getTok() throws IOException {return br.readLine().split("" "");} + private int getInt() throws IOException {return Integer.valueOf(br.readLine());} + private int[] getInt(int N) throws IOException { + int[] data= new int[N]; tok= br.readLine().split("" ""); + for (int i=0; isurprisingBestScore[sum]) + surprisingBestScore[sum]= max; + } else { + if (max>normalBestScore[sum]) + normalBestScore[sum]= max; + } + } + } + } + } + } + + private boolean isValid(int i, int j, int k) { + return (Math.abs(i-j)<=2) && (Math.abs(i-k)<=2) && (Math.abs(j-k)<=2); + } + + private boolean isSurpring(int i, int j, int k) { + return (Math.abs(i-j)==2) || (Math.abs(i-k)==2) || (Math.abs(j-k)==2); + } + + private int max(int i, int j, int k) { + return Math.max(i, Math.max(j, k)); + } + + int N, S, p; + int[] t; + + private int answer() { + int i, countNormal= 0, countSurprising= 0; + for (i=0; i= p) ++countNormal; + if (normalBestScore[t[i]]< p && surprisingBestScore[t[i]]>=p) ++countSurprising; + } + return countNormal + Math.min(S, countSurprising); + } + + public void solve() throws IOException { + int i,j,k; + String s; + + int MODE= LARGE; + br = new BufferedReader (new FileReader(""B""+infile[MODE])); + out = new PrintWriter(new BufferedWriter(new FileWriter(""B""+outfile[MODE]))); + + generateBestScores(); + + int C= Integer.valueOf(br.readLine()); + for (int c=1; c<=C; c++) { + // read + tok= getTok(); + N= toInt(tok[0]); + S= toInt(tok[1]); + p= toInt(tok[2]); + t= new int[N]; + for (i=0; i= p){ + numreach++; + } else if(mat[scores[j]][0] + 1 >= p && mat[scores[j]][1] == 1){ + numcould++; + } + } + numreach += Math.min(numcould, S); + + fout.println(""Case #"" + (i + 1) + "": "" + numreach); + fout.flush(); + s = fin.readLine(); + } + } +} + +" +A22812,"import java.io.BufferedReader; +import java.io.IOException; +import java.util.ArrayList; + + + +public class TestCaseReader { + public ArrayList read(BufferedReader r) throws NumberFormatException, IOException + { + ArrayList s = new ArrayList(); + int n = Integer.parseInt(r.readLine()); + for (int i = 0 ; i < n ; i ++ ) + s.add(r.readLine()); + return s; + } +} +" +A21518,"package quiz2012.quiz2; + +import java.util.ArrayList; +import java.util.List; + +import domain.QuizSolver; +import domain.QuizTestCaseInput; +import domain.QuizTestCaseOutput; + +public class Quiz2Solver implements QuizSolver { + private static final int NUMBER_OF_JUDGES = 3; + + @Override + public QuizTestCaseOutput solve(QuizTestCaseInput testCaseInput) { + Quiz2TestCaseInput input = (Quiz2TestCaseInput) testCaseInput; + System.out.println(input); + int numberOfGooglers = input.getNumberOfGooglers(); + int numberOfSurprising = input.getNumberOfSurprising(); + int minBestResult = input.getMinBestResult(); + int[] totalPoints = input.getTotalPoints(); + List surprisePossibleGooglers = new ArrayList(); + int numberOfGooglersHavingMinBestResultWithoutSurprising = 0; + for (int i = 0; i < numberOfGooglers; i++) { + int q = totalPoints[i] / NUMBER_OF_JUDGES; + int r = totalPoints[i] % NUMBER_OF_JUDGES; + Googler googler = new Googler(q, r); + if (googler.getBestResult() >= minBestResult) { + numberOfGooglersHavingMinBestResultWithoutSurprising++; + } else { + if (totalPoints[i] >= 2 && totalPoints[i] <= 28) { + googler.setSurprising(true); + surprisePossibleGooglers.add(googler); + } + } + } + + int numberOfPossibleGooglersHavingMinBestResultWithSurprise = 0; + for (Googler googler : surprisePossibleGooglers) { + if (googler.getBestResult() >= minBestResult) { + numberOfPossibleGooglersHavingMinBestResultWithSurprise++; + } + } + + int numberOfGooglersHavingMinBestResultWithSurprise = Math.min( + numberOfSurprising, + numberOfPossibleGooglersHavingMinBestResultWithSurprise); + + int numberOfGooglersHavingMinBestResult = numberOfGooglersHavingMinBestResultWithoutSurprising + + numberOfGooglersHavingMinBestResultWithSurprise; + + System.out.println(numberOfSurprising + "", "" + + numberOfPossibleGooglersHavingMinBestResultWithSurprise + + "", "" + numberOfGooglersHavingMinBestResultWithSurprise + "", "" + + numberOfGooglersHavingMinBestResultWithoutSurprising + "", "" + + numberOfGooglersHavingMinBestResult); + return new Quiz2TestCaseOutput(numberOfGooglersHavingMinBestResult); + } +} + +class Googler { + private final int q; + private final int r; + private boolean surprising; + + public Googler(int q, int r) { + this.q = q; + this.r = r; + } + + public void setSurprising(boolean surprising) { + this.surprising = surprising; + } + + public Integer getBestResult() { + switch (r) { + case 0: + return q + (surprising ? 1 : 0); + + case 1: + return q + 1; + + case 2: + return q + 1 + (surprising ? 1 : 0); + } + throw new IllegalStateException(""r must be 0, 1, or 2: "" + r); + } + + @Override + public String toString() { + return ""Googler [q="" + q + "", r="" + r + "", surprising="" + surprising + + ""]""; + } +}" +A20209,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package gcj.base; + +import java.util.regex.Pattern; + +/** + * + * @author jalves + */ +public class ProbB { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + new ProbB(args).DoIt(); + } + + Console io; + private ProbB(String[] args) { + boolean ovwr = false; + String in = null; + String out = null; + + for (int i = 0; i < args.length; i++) { + if (args[i].startsWith(""-i"")) { + in = args[i].substring(2); + if (in.length() == 0) { + in = args[++i]; + } + } else if (args[i].startsWith(""-o"")) { + out = args[i].substring(2); + if (out.length() == 0) { + out = args[++i]; + } + } if (args[i].equals(""-f"")) { + ovwr = true; + } + } + + io = new Console(in, out, ovwr); + } + + private void DoIt() { + long startTime, remain; + long nCases; + io.logt(""Starting...""); + try { + nCases = io.getLong(); + io.log(""There are "" + nCases + "" cases to process\n""); + startTime = System.currentTimeMillis(); + remain = 20000; // just some value + for (long i = 1; i <= nCases; i++) { + io.log(""\rProcessing test case "" + i + ""/"" + nCases + "" : Remaining "" + String.format(""%.2fs "", remain/1000.0)); + + DoCase(i); + + remain = (long)((System.currentTimeMillis() - startTime) * ((double)nCases/(double)i - 1)); + } + io.log(""\n""); + } catch (Exception ex) { + io.logt(""\n\nERROR: "" + ex); + throw new RuntimeException(""Error while executing main loop"", ex); + } + io.logt(""Done!""); + } + + private void DoCase(long caseNum) throws Exception { + String input; + int result; + + io.print(""Case #"" + caseNum + "": ""); + + int N = (int)io.getLong(); + int surprising = (int)io.getLong(); + int bestScore = (int)io.getLong(); + + if (bestScore == 0) { + result = N; + for (int i = 0; i < N; i++) { + io.getLong(); + } + } else { + result = 0; + + int regularThreshold = bestScore * 3 - 3; + if (regularThreshold < 0) { + regularThreshold = 0; + } + int surpriseThreshold = regularThreshold - 2; + if (surpriseThreshold < 1) { + surpriseThreshold = 1; + } + + int score; + for (int i = 0; i < N; i++) { + score = (int)io.getLong(); + if (score > regularThreshold) { + result++; + } else if (score > surpriseThreshold) { + if (surprising > 0) { + surprising--; + result++; + } + } + } + } + + io.println(String.valueOf(result)); + } +} +" +A21604," +package Qualification; +import Practice.*; +import java.util.*; +import java.io.*; + +public class B { + + public void ejecutar() throws Exception { + Scanner sc = new Scanner(new FileReader(""/home/gomezluisj/Descargas/B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""/home/gomezluisj/Descargas/B-large.out"")); + int caseCnt = sc.nextInt(); + for (int caseNum = 0; caseNum < caseCnt; caseNum++) { + pw.print(""Case #"" + (caseNum + 1) + "": ""); + int contestants=sc.nextInt(); + + int surprising=sc.nextInt(); + int calculate=sc.nextInt(); + int res=0; + int[][] arr=new int[contestants+1][2]; + for (int i = 0; i < contestants; i++) { + int triplet=sc.nextInt(); + if(triplet==0)arr[i][0]=0; + else arr[i][0]=triplet/3; + arr[i][1]=triplet%3; + } + int i=0; + while(surprising>0&&i2||arr[i][0]==0) i=i+1; + else{ + if((c==1&&arr[i][1]==0)||(c==2&&arr[i][1]==2)) { + surprising=surprising-1; + res=res+1; + } + i=i+1; + } + } + for (int j = 0; j < contestants; j++) { + int c=calculate-arr[j][0]; + if(c<1) res=res+1; + if((c==1&&arr[j][1]==1)||(c==1&&arr[j][1]==2)) res=res+1; + } + pw.println(res); + System.out.print(res); + } + pw.flush(); + pw.close(); + sc.close(); + } + + + public static void main(String[] args) throws Exception { + new B().ejecutar(); + } +} +" +A23027,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class DancingWithGooglers { + + /** + * @param args + */ + private final static String WRITE_DEST = ""C:\\Users\\mkobit\\Documents\\GoogleCodeJam2012\\Dancing With the Googlers\\out.txt""; + public static void main(String[] args) { + int T; // T test cases + int N; // number of Googlers + int S; // surprising number of scores + int p; // best result score + int howManyP = 0; + BufferedReader in; + PrintWriter outfile; + try { + in = new BufferedReader(new FileReader(args[0])); + outfile = new PrintWriter(new FileWriter(WRITE_DEST)); + String text = in.readLine(); + T = Integer.parseInt(text); + for (int i = 0; i < T; i++) { + // for each test case + howManyP = 0; + text = in.readLine(); + //System.out.println(text); + StringTokenizer token = new StringTokenizer(text, "" ""); + N = Integer.parseInt(token.nextToken()); + S = Integer.parseInt(token.nextToken()); + p = Integer.parseInt(token.nextToken()); + //System.out.println(N); + //System.out.println(S); + //System.out.println(""case="" + (i+1) + "" p="" + p + "" strange="" + S); + while (token.hasMoreTokens()) { + String s = token.nextToken(); + //System.out.print(s + "" ""); + int score = Integer.parseInt(s); + Googler goog = new Googler(score); + if (goog.hasHighScore(p)) { + //System.out.print(goog + "" ""); + howManyP++; + } else if (S > 0 && goog.weirdHighScore(p)) { + //System.out.print(goog + "" ""); + howManyP++; + S--; + } else { + //System.out.print(goog + "" ""); + } + } + //System.out.println(""withp="" + howManyP); + // write output to file + String s = String.format(""Case #%d: %d\n"", i + 1, howManyP); + outfile.write(s); + //System.out.println(howManyP); + } + in.close(); + outfile.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} +" +A20563,"///// put all imports here ///////// + +import java.io.*; +import java.util.*; // for system.out n stuff +import static java.lang.Math.*; + +/////////////////////////////////////////// + +public class Dancing { + public static void main(String[] args) throws FileNotFoundException{ + + // handy scanner that everyone uses + // nextInt() nextLong() ect. + // these actually return int and long + // happy coding + Scanner in = new Scanner(System.in); + + + int NumCases = in.nextInt(); + for(int CasesDone=0; CasesDone < NumCases; CasesDone++){ + + + + + //dont forget to delete the last output from GoogleOut + System.setOut(new PrintStream(new FileOutputStream(""/Users/NathanBreitsch/Desktop/GoogleOut/StoreCreditOut"", true))); + + + + + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + + int P1 = Math.max(0, P-1); + int P2 = Math.max(0, P-2); + + + PriorityQueue t= new PriorityQueue(20, new Comparator(){ + public int compare(Integer o1, Integer o2){ + return o2 - o1; + } + }); + + + + for (int i = 0; i < N; i++){ + t.add(in.nextInt()); + } + + int sup = 0; + int max = 0; + while((sup < S) && (!t.isEmpty())){ + + + + if (P + 2*(P1) <= t.peek()){ + max++; + } + else if(P + 2*(P2) <= t.peek()){ + max ++; + sup ++; + } + + t.poll(); + } + + + while(! t.isEmpty()){ + + + + if (P + 2*(P1) <= t.peek()){ + max++; + } + + t.poll(); + } + + + //In Europe, the first floor is numbered zero. + //But this is America! Hence the +1 + System.out.print(""Case #"" + (CasesDone+1) + "": ""); + + System.out.print(max); + + System.out.println(); + + + } + } +} +" +A21072,"package jam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; + +public class Dance { + + public static void main(String[] x)throws IOException{ + File file=new File(""A.in""); + Writer output = null; + File out=new File(""A.out""); + output = new BufferedWriter(new FileWriter(out)); + BufferedReader fileIn = new BufferedReader(new FileReader(file)); + String fileLine,delims,outs; + String[] tokens; + int cases,num,surprise,goal,ans,indA,indB,i; + int [] items; + + fileLine=fileIn.readLine(); + cases = Integer.parseInt(fileLine); + delims = ""[ ]+""; + System.out.println(""Cases = ""+cases); + for (i=0;iacc) + { + ++out; + } + else if(items[i]>=rej&&s>0) + { + ++out; + --s; + } + else + { + + } + } + return out; + } + + +private static void transfer(int[] items, String[] tokens) { + + int size = tokens.length; + int i = 3; + for(i = 3;i puede ser caso especial y no + * 15 --> 5 5 5 ó 4 5 6 + * el resto es 1 --> puede ser caso especial y no + * 16 --> 4 6 6 ó 5 5 6 + * el resto es 2 --> puede ser caso especial y no + * 17 --> 5 7 7 ó 5 6 6 + */ + +public class B { + public static void main(String[] args) { + final int JUDGES = 3; + final int MINSCORE = 0; + Scanner in = new Scanner(System.in); + int t = in.nextInt(); + for (int i = 1; i <= t; i++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int success = 0; + for (int j = 0; j < n; j++) { + int totalScores = in.nextInt(); + int score = totalScores / JUDGES; + int rest = totalScores % JUDGES; + if (totalScores==MINSCORE) { + if (p==MINSCORE) { + success++; + } + } else if (score >= p || (score+1>=p && rest>=1)) { + success++; + } else if (score + 1 >= p && rest < 1 && s > 0) { + success++; + s--; + } else if (score + 2 >= p && rest == 2 && s > 0) { + success++; + s--; + } + } + System.out.format(""Case #%d: %d\n"", i, success); + } + } +}" +A22161,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * Dancing + * Jason Bradley Nel + * 16287398 + */ +import java.io.*; + +public class Dancing { + + public static void main(String[] args) { + + In input = new In(""input.txt""); + int T = Integer.parseInt(input.readLine()); + + for (int i = 0; i < T; i++) { + System.out.printf(""Case #%d: "", i + 1); + int N = input.readInt(); + int s = input.readInt(); + int p = input.readInt(); + int c = 0;//counter for >=p cases + //System.out.printf(""N: %d, S: %d, P: %d, R: "", N, s, p); + + for (int j = 0; j < N; j++) { + + int score = input.readInt(); + int q = score / 3; + int m = score % 3; + //System.out.printf(""%2d (%d, %d) "", scores[j], q, m); + + switch (m) { + case 0: + if (q >= p) { + c++; + } else if (((q + 1) == p) && (s > 0) && (q != 0)) { + c++; + s--; + } + break; + case 1: + if (q >= p) { + c++; + } else if ((q + 1) == p) { + c++; + } + break; + case 2: + if (q >= p) { + c++; + } else if ((q + 1) == p) { + c++; + } else if (((q + 2) == p) && (s > 0)) { + c++; + s--; + } + break; + } + } + //System.out.printf(""Best result of %d or higher: "", p); + System.out.println(c); + } + + + } +} +" +A21444,"package World2012_01; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Scanner; + +public class B { + public static final String in = ""/Users/vickcy/Downloads/B-large.in.txt""; + public static final String out = ""outB.txt""; + + public static void main(String[] args) throws Exception { + Writer writer = new OutputStreamWriter(new FileOutputStream(out)); + Scanner sc = new Scanner(new File(in)); + int T = sc.nextInt(); + for (int i = 1; i <= T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int result = 0; + + if (p == 0) { + result = N; + while (N-- > 0) sc.nextInt(); + } else { + while (N-- > 0) { + int ti = sc.nextInt(); + if (ti >= p * 3 - 2) { + ++result; + } else if (p == 1) { + result += ti > 0 ? 1 : 0; + } else if (ti >= p * 3 - 4) { + if (S > 0) { + --S; + ++result; + } + } + } + } + writer.write(""Case #"" + i + "": "" + result + ""\n""); + } + writer.close(); + } + +} +" +A21064,"import java.util.Scanner; + + +public class JuanjeProblemaB +{ + /* + * Juan Jesus Gutierrez + * Solucion al problema - B + */ + public static void main(String[] args) + { + //lector de la entrada + Scanner in = new Scanner(System.in); + //in.nextLine(); + //numero de frases en Googlerese + int T = in.nextInt(); + in.nextLine(); + for(int con = 1; con <=T; con++) + { + String concurso = in.nextLine(); + int result = tratarConcurso(concurso); + System.out.format(""Case #%d: %d\n"", con, result); + } + } + + public static int tratarConcurso(String concurso) + { + int result = 0; + //System.out.println(concurso); + String[] datos = concurso.split("" ""); + int N = Integer.parseInt(datos[0]); + int s = Integer.parseInt(datos[1]); + int p = Integer.parseInt(datos[2]); + int[] puntuaciones = new int[N]; + for(int i = 3; i= p) + { + result++; + } + else + { + if(PmaxS[i] >= p && s>0) + { + result++; + s--; + } + } + } + return result; + } + + public static int maximoPosible(int total) + { + if(total == 0) return 0; + if(total == 30) return 10; + int d = (int) total / 3; + int resto = total % 3; + if(resto == 0) return d; + return d+1; + } + public static int maximoPosibleConSorpresa(int total) + { + if(total == 0) return 0; + if(total == 30) return 10; + int d = (int) total / 3; + int resto = total % 3; + if(resto == 2) return d+2; + return d+1; + } +} +" +A20928,"package br.com; + +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Scanner; + +public class ProblemaB { + static String caminho = ""/home/mateus/""; + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(caminho + ""entrada.txt"")); + FileWriter writer = new FileWriter(new File(""/home/mateus/saida.txt""), false); + + int cases = sc.nextInt(); + + for (int i = 1; i <= cases; i++) { + if (i == 3) { + System.out.println(""""); + } + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int resposta = 0; + ArrayList triplas = new ArrayList(); + + for (int j = 0; j < n; j++) { + triplas.add(new Tripla(sc.nextInt())); + } + for (int w = triplas.size() - 1; w >= 0; w--) { + if (triplas.get(w).maximaPontuacao() >= p) { + resposta++; + triplas.remove(w); + } + } + + for (int w = 0; w < triplas.size() && s > 0; w++) { + if (triplas.get(w).maximaPontuacaoEspecial() >= p) { + s--; + resposta++; + } + } + writer.append(criarCase(i, resposta + """")); + } + writer.flush(); + writer.close(); + } + + public static String criarCase(int i, String s) { + return ""Case #"" + i + "": "" + s + ""\n""; + } +} +" +A22143," +public class Dancing +{ + public static void main(String[] args) + { + int T = StdIn.readInt(); + + for (int tr = 1; tr <= T; tr++) + { + int N = StdIn.readInt(); + int S = StdIn.readInt(); + int p = StdIn.readInt(); + + int numP = 0; + int numS = 0; + + for (int i = 0; i < N; i++) + { + int tripSum = StdIn.readInt(); + int doubSum = tripSum - p; + + if(p == 0) + { + numP++; + continue; + } + + + if (doubSum >= 2*(p-1)) + numP++; + else if (doubSum >= 2*(p-2) && p > 1) + numS++; + } + + int total = numP + Math.min(numS, S); + + StdOut.println(""Case #"" + tr + "": "" + total); + } + } +} +" +A22462,"import util.CombinationGenerator; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class SetUtil { + public static long getOne(int n) { + return 1< getList(long set, int n) { + ArrayList integers = new ArrayList<>(); + for (int i=0;ilong getForList(Map positions, List objs) { + long res = 0L; + for (T obj : objs) { + int pos = positions.get(obj); + res |= getOne(pos); + } + return res; + } + + public static void cycleSubsets(int num, SubsetCallBack callBack) { + callBack.run(0, 0); + for (int i = 1; i<=num; i++) { + CombinationGenerator generator = new CombinationGenerator(num,i); + + while (generator.hasMore()) { + long n = 0; + int[] next = generator.getNext(); + for (int i1 : next) { + n |= getOne(i1); + } + callBack.run(n,i); + } + } + + } + + public static interface SubsetCallBack { + void run(long subset, int i); + } +} +" +A23064,"import java.util.ArrayList; +import java.util.Arrays; +public class Problem2 +{ + public int countResults(String[] nums){ + int googlers = Integer.parseInt(nums[0]); + int surprising = Integer.parseInt(nums[1]); + int min = Integer.parseInt(nums[2]); + int count = 0; + int[] possible = new int[googlers]; + System.out.println(""Min: ""+min+"", Surprising: ""+surprising); + for(int i = 3; i=min){ + count+=1; + } + break; + case 1: + if(curr/3+1>=min){ + count+=1; + } + break; + case 2: + if(curr/3+1>=min){ + count+=1; + } + else if(curr/3+2>=min){ + possible[i-3]=1; + } + } + System.out.println(""Count: ""+count+"", possible: ""+possible[i-3]); + } + Arrays.sort(possible); + for(int j=0;j input = rw.readFile(""B-large.in""); + ArrayList ans = new ArrayList(); + int num; + boolean first = true; + int count=0; + for(String s : input){ + if(first){ + num=Integer.parseInt(s); + first=false; + } + else{ + String[] nums = s.split("" ""); + ans.add(""Case #""+count+"": ""+countResults(nums)); + } + count++; + } + rw.writeFile(ans, ""output2.txt""); + } +} +" +A21107,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Scanner; + + +public class B { + + public static void main(String[] args) { + + try { + Scanner in = new Scanner(new File(""smallB.in"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""smallB.out""))); + + int T = in.nextInt(); + in.nextLine(); + + for (int i=0; i 0) { + + Arrays.sort(array); + + for (int j=N-1; j>=0; j--) { + if ((3*p - 2) <= array[j]) { + res++; + } + else if ((3*p-4 <= array[j]) && (S > 0) && !(p==1 && array[j] == 0)) { + res++; + S--; + } + } + + //} + + writer.append(""Case #"" + (i+1) + "": "" + res + ""\n""); + } + + writer.close(); + + } + catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} +" +A21212,"import java.io.IOException; +import java.io.PrintWriter; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +/* run with JDK7 */ +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + List input = Files.readAllLines(Paths.get(""K:/B-large.in""), Charset.defaultCharset()); + PrintWriter output = new PrintWriter(""K:/B-large.out""); + int testCount = Integer.parseInt(input.get(0)); + for (int i = 1; i <= testCount; ++i) { + String[] parts = input.get(i).split("" ""); + int n = Integer.parseInt(parts[0]); + int s = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + int[] t = new int[n]; + for (int j = 0; j < n; ++j) + t[j] = Integer.parseInt(parts[3 + j]); + // solution + int alwaysCount = 0, surpriseCount = 0; + for (int j=0; j= p) { + return c - a == 2 ? Result.SURPRISE : Result.ALWAYS; + } + return null; + } + + public enum Result { + ALWAYS, + SURPRISE, + NEVER, + } +} +" +A22546,"import java.io.*; +import java.util.Arrays; +import java.util.Locale; + +/** + * @author Yuri Denison + * @date 14.04.12 + */ +public class GoogleCodeJamTaskB { + private static void solve() throws IOException { + final int t = rInt(); + for (int i = 1; i <= t; i++) { + final int n = rInt(); + final int s = rInt(); + final int p = rInt(); + int[] results = new int[n]; + for (int j = 0; j < n; j++) { + results[j] = rInt(); + } + Arrays.sort(results); + + if (p == 0) { + out.println(String.format(""Case #%d: %d"", i, n)); + continue; + } + int bestGooglers; + int count1 = 0; + int count2 = 0; + + final int limit1 = p + 2 * (p - 1); + final int limit2 = (p > 1) ? p + 2 * (p - 2) : p; + + for (int j = 0; j < n; j++) { + if (results[j] >= limit1) { + count1 = results.length - j; + break; + } + } + for (int j = 0; j < n; j++) { + if (results[j] >= limit2) { + count2 = results.length - j; + break; + } + } + final int abs = count2 - count1; + bestGooglers = count1 + ((s < abs) ? s : abs); + + out.println(String.format(""Case #%d: %d"", i, bestGooglers)); + } + } + + public static void main(String[] args) throws IOException { + Locale.setDefault(Locale.US); + + BufferedReader br; + try { + final String fileName = ""B-large""; + br = new BufferedReader(new FileReader(fileName + "".in"")); + out = new PrintWriter(new FileWriter(fileName + "".out"")); + } catch (Exception e) { + br = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(new OutputStreamWriter(System.out)); + } + st = new StreamTokenizer(br); + + solve(); + + br.close(); + out.close(); + } + + private static StreamTokenizer st; + private static PrintWriter out; + + static String rNext() throws IOException { + st.nextToken(); + return st.sval; + } + + static int rInt() throws IOException { + st.nextToken(); + return (int) st.nval; + } +} +" +A20777,"package com.skidson.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingWithTheGooglers { + private static final File inFile = new File(""input""); + private static final File outFile = new File(""output""); + + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(inFile)); + BufferedWriter out = new BufferedWriter(new FileWriter(outFile)); + int numTests = Integer.parseInt(in.readLine()); + + for (int x = 0; x < numTests; x++) { + String[] params = in.readLine().split("" ""); + int N = Integer.parseInt(params[0]); + int S = Integer.parseInt(params[1]); + int p = Integer.parseInt(params[2]); + int y = 0; + + int[] t = new int[N]; + for (int j = 3; j < params.length; j++) + t[j-3] = Integer.parseInt(params[j]); + + int[][] scores = new int[N][]; + for (int i = 0; i < N; i++) { + scores[i] = new int[]{p, p, p}; + + if (sumArray(scores[i]) <= t[i]) { + y++; + continue; + } + + boolean valid = true; + while (valid && sumArray(scores[i]) != t[i]) { + /* Decrement an element of the array, prioritizing not consuming an S: + * p p p + * p-1 p p + * p-1 p-1 p + * p-2 p-1 p ... if sum is hit here or after, must consume S (S--) + * p-2 p-2 p ... if sum is not hit by now, this cannot meet our criteria + */ + if (p-scores[i][0] >= 2 && p-scores[i][1] >= 2) { + valid = false; + } else if (scores[i][1] == scores[i][0]) { + if (--scores[i][0] < 0) + valid = false; + } else { + if (--scores[i][1] < 0) + valid = false; + } + } + + if (valid) { + // scores[i][0] will always be smallest, scores[i][2] largest + if (scores[i][2] - scores[i][0] == 2) { + if (S > 0) { + S--; + y++; + } + } else { + y++; + } + } + } + out.write(""Case #"" + (x+1) + "": "" + y + ""\n""); + } + out.flush(); + out.close(); + } + + private static int sumArray(int[] array) { + int sum = 0; + for (int i : array) + sum += i; + return sum; + } + +} +" +A22748,"package com.google.code.p_b; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class Main { + + private static final String fromFile = ""D:\\hobbies & work\\programing\\CodeJamTextFiles\\2012\\B-large.in""; + private static final String toFile = ""D:\\hobbies & work\\programing\\CodeJamTextFiles\\2012\\B-large.out""; + + + /** + * @param args + */ + public static void main(String[] args) + { + System.out.println(""Problem B start""); + + try { + + FileInputStream fstream = new FileInputStream(fromFile); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter fstreamout = new FileWriter(toFile); + BufferedWriter out = new BufferedWriter(fstreamout); + + String strLine; + boolean firstLine = true; + int i = 1; + while ((strLine = br.readLine()) != null) + { + if (!firstLine) + { + System.out.println(strLine); + System.out.println(""Case #"" + i + "": "" + ansForLine(strLine) + ""\n""); + + out.write(""Case #"" + i + "": "" + ansForLine(strLine) + ""\n""); + i++; + } + else + { + firstLine = false; + } + } + out.close(); + in.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + + System.out.println(""Problem B end""); + } + + + private static int ansForLine(String strLine) + { + String [] splitedLine = strLine.split("" ""); + int nRes = Integer.parseInt(splitedLine[0]); + int nSurprises = Integer.parseInt(splitedLine[1]); + int nMax = Integer.parseInt(splitedLine[2]); + System.out.println(""res: "" + nRes + "", surprises: "" + nSurprises +"", max: "" + nMax); + + int count = 0; + + for (int i = 3; i < splitedLine.length; i++) + { + int j = Integer.parseInt(splitedLine[i]); + int avg = j / 3; + int m = j % 3; + + if (j == 0) + { + if (nMax == 0) + count ++; + continue; + } + + if (avg >= nMax) + { + count ++; + } + else if (avg + 1 >= nMax) + { + if (m == 0 && nSurprises > 0) + { + count ++; + nSurprises --; + } + else if (m == 1 || m == 2) + { + count ++; + } + } + else if (avg + 2 >= nMax) + { + if (m == 2 && nSurprises > 0) + { + count ++; + nSurprises --; + } + } + } + + return count; + } + +} +" +A21629,"import java.util.*; + +public class B { + public static void main(String[] args){ + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); + for(int zz = 1; zz <= T;zz++){ + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int ok = 0; + int maybe = 0; + + for (int i=0;i=p) ok++; + else if (best+1==p && best>0) maybe++; + } + + System.out.format(""Case #%d: %d\n"", zz, Math.min(ok + Math.min(maybe, s),n)); + } + } +} +" +A20230,"import java.io.*; +import java.util.*; +import java.text.*; + +public class Main implements Runnable{ + + /** + * @param args + */ + private StringTokenizer stReader; + private BufferedReader bufReader; + private PrintWriter out; + public static void main(String[] args) { + // TODO Auto-generated method stub + (new Main()).run(); + } + + @Override + public void run() { + // TODO Auto-generated method stub + bufReader = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(new OutputStreamWriter(System.out)); + stReader = null; + Solves(); + out.flush(); + } + public String ReadLine() { + String result = null; + + try { + result = bufReader.readLine(); + } catch (IOException e) { + } + return result; + } + public String NextString(){ + if (stReader == null || !stReader.hasMoreTokens()){ + stReader = new StringTokenizer(ReadLine(),""\n\r ""); + } + return stReader.nextToken(); + } + public int NextInt(){ + return Integer.parseInt(NextString()); + } + public long NextLong(){ + return Long.parseLong(NextString()); + } + public double NextDouble(){ + return Double.parseDouble(NextString()); + } + void Solves(){ + int n = NextInt(); + for(int i =0; i < n; i++){ + out.print(""Case #"" +(i + 1) + "": ""); + Solve(); + out.println(); + //out.flush(); + } + out.flush(); + } + void Solve(){ + int N = NextInt(); + int S = NextInt(); + int p = NextInt(); + int result = 0; + for(int i =0; i < N; i++){ + int val = NextInt(); + if (val < p) continue; + int n = val /3; + int k = val % 3; + if (n >= p || (k > 0 && n + 1 >= p)) result++; + else { + if ((k == 2 && n + 2 >= p && S > 0) || (k == 0 && n + 1 >= p && S > 0)) { + result++; + S--; + } + } + } + out.print(result); + } + +} +" +A20770,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +public class Fattom2012B { + private final String _PROBLEM_NO = ""201201B""; + private final String _FILE_DIRECTORY = ""K:/Dropbox/workspace/codejam/"" + _PROBLEM_NO + ""/""; + private final String _FILE_PATH = _FILE_DIRECTORY + ""B-large""; + + public static void main(String[] args) throws IOException { + Locale.setDefault(Locale.US); + new Fattom2012B().execute(); + } + + public void execute() { + BufferedReader br = null; + PrintWriter pw = null; + + try { + br = new BufferedReader(new FileReader(_FILE_PATH + "".in"")); + pw = new PrintWriter(_FILE_PATH + "".out""); + + //main + int caseno = Integer.parseInt(br.readLine()); + + for (int count = 1; count <= caseno; count++) { + pw.print(""Case #"" + count + "": ""); + System.out.print(""Case #"" + count + "": ""); + + String line = br.readLine(); + + String[] splits = line.split("" ""); + int N = Integer.parseInt(splits[0]); + int S = Integer.parseInt(splits[1]); + int P = Integer.parseInt(splits[2]); + int r = 0; + for(int j=0;j= -2) { + r++; + } + else if(S > 0 && ((t == -3) || (t == -4))) { + r++;S--; + } + } + pw.print(r); + System.out.print(r); + + + pw.print(""\n""); + System.out.print(""\n""); + } + + //end + + + br.close(); + pw.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + finally { + try { + if(pw != null) pw.close(); + } catch(Exception e) {} + try { + if(br != null) br.close(); + } catch(Exception e) {} + } + } + +} +" +A22983,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author akila + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + // TODO code application logic here + ArrayList testCases = new ArrayList(); + boolean isCaseNo = true; + int testCount = 0; + FileReader fr = new FileReader(""B-large.in""); + BufferedReader br = new BufferedReader(fr); + String s; + + while ((s = br.readLine()) != null) { + if (isCaseNo) { + testCount = Integer.parseInt(s); + isCaseNo = false; + } else { + testCases.add(s); + } + } + fr.close(); + Solve(testCount, testCases); + } + + public static void Solve(int testCount, ArrayList testCases) throws IOException { + + + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + for (int i = 0; i < testCount; i++) { + ArrayList googlers = new ArrayList(); + String s = testCases.get(i); + String[] ar = s.split("" ""); + + int noOfGooglers = 0, sup = 0, min = -1, count = 0; + noOfGooglers = Integer.parseInt(ar[0]); + sup = Integer.parseInt(ar[1]); + min = Integer.parseInt(ar[2]); + + for (int j = 3; j < noOfGooglers + 3; j++) { + Googler g = new Googler(); + googlers.add(g); + for (int a = 0; a <= 10; a++) { + if (a > Integer.parseInt(ar[j])) { + break; + } + for (int b = 0; b <= 10; b++) { + if (a + b > Integer.parseInt(ar[j])) { + break; + } + for (int c = 0; c <= 10; c++) { + if (a + b + c == Integer.parseInt(ar[j])) { + if ((Math.abs(a - b) <= 2) + && (Math.abs(a - c) <= 2) + && (Math.abs(b - c) <= 2)) { + if ((Math.abs(a - b) == 2) + || (Math.abs(a - c) == 2) + || (Math.abs(b - c) == 2)) { + + Scores sc = new Scores(); + sc.A = a; + sc.B = b; + sc.C = c; + g.sup.add(sc); + g.hasSup = true; + + } else { + Scores sc = new Scores(); + sc.A = a; + sc.B = b; + sc.C = c; + g.normal.add(sc); + } + } + } else if (a + b + c > Integer.parseInt(ar[j])) { + break; + } + } + } + } + } + ArrayList removed = new ArrayList(); + for (int j = 0; j < googlers.size(); j++) { + Googler googler = googlers.get(j); + if (googler.hasSup && googler.normal.isEmpty() && sup > 0) { + if (googler.hasMinInSup(min)) { + count++; + } + sup--; + removed.add(googler); + } + } + googlers.removeAll(removed); + + for (int j = 0; j < googlers.size(); j++) { + Googler googler = googlers.get(j); + if (googler.hasMinInNorm(min)) { + count++; + } else if (sup > 0 && googler.hasMinInSup(min)) { + count++; + sup--; + } + } + + out.write(""Case #"" + (i + 1) + "": "" + count + ""\n""); + } + out.close(); + } +} + +class Scores { + public int A = -1, B = -1, C = -1; + + public boolean hasMin(int min) { + return A >= min || B >= min || C >= min; + } +} + +class Googler { + + public ArrayList normal = new ArrayList(); + public ArrayList sup = new ArrayList(); + public boolean hasSup = false; + + public boolean hasMinInSup(int min) { + for (int i = 0; i < sup.size(); i++) { + if (sup.get(i).hasMin(min)) + return true; + } + return false; + } + + public boolean hasMinInNorm(int min) { + for (int i = 0; i < normal.size(); i++) { + if (normal.get(i).hasMin(min)) + return true; + } + return false; + } +} +" +A21858,"import java.util.Arrays; +import java.util.Scanner; + + +public class B { + + int N; + int S; + int p; + int[] A = new int[100]; + + int[][] memo = new int[100][100]; + + boolean[][] normal = new boolean[11][31]; + boolean[][] surprise = new boolean[11][31]; + + B() { + for (int a=0; a<=10; ++a) { + for (int b=a; b<=10 && b<=a+2; ++b) { + for (int c=b; c<=10 && c<=a+2; ++c) { + if (c-a<=1) + normal[c][a+b+c]=true; + else + surprise[c][a+b+c]=true; + } + } + } + + Scanner in=new Scanner(System.in); + for (int T=in.nextInt(),TC=1; T-->0; ++TC) { + N=in.nextInt(); + S=in.nextInt(); + p=in.nextInt(); + for (int i=0; i-1) + return memo[at][sur]; + + int res=0; + for (int max=0; max<=10; ++max) { + int add=max>=p?1:0; + if (normal[max][A[at]]) + res=Math.max(res,add+go(at+1,sur)); + if (sur ""); + return; + } + + /******************************************************************* + * + * Declaring all variables + * + *******************************************************************/ + + FileInputStream fstream; + DataInputStream in; + BufferedReader br; + + int testCases = 1; + String firstLine, strLine; + List inputList = new LinkedList(); + // List splitArr = new LinkedList(); + + int N = 0; + int S = 0; + int p = 0; + List t = new LinkedList(); + List h = new LinkedList(); + int noOfWinningCases = 0; + int c = 0 ; + + String outputStr = """"; + List outputList = new LinkedList(); + FileWriter f_write_stream; + BufferedWriter out; + + /******************************************************************* + * + * Code for reading the INPUT + * + *******************************************************************/ + + + try + { + //""G:/Programming/GOOGLE Code Jam/GCJ_StoreCredits/src/gcj_storecredits/input.in"" + fstream = new FileInputStream(args[0]); + in = new DataInputStream(fstream); + br = new BufferedReader(new InputStreamReader(in)); + + + firstLine = br.readLine(); + testCases = Integer.parseInt(firstLine); + //System.out.println(testCases); + + int counter=0; + while((strLine = br.readLine())!= null) + { + inputList.add(strLine); + //System.out.println(inputList.get(counter) + ""Counter#: "" + counter); + ++counter; + } + + in.close(); + } + catch (Exception e) + { + System.err.println(""Error: "" + e.getMessage()); + } + + + for (int i=0; i p) + { + h.set(k, (t.get(k)/3)+1); + ++c; + } + } + else if (t.get(k)%3 == 1 ) + { + h.add((t.get(k)/3)+1); + } + else if (t.get(k)%3 == 2 ) + { + h.add((t.get(k)/3)+2); + ++c; + if ((t.get(k)/3) < p-2 && (t.get(k)/3) >= p) + { + h.set(k,(t.get(k)/3)+1); + --c; + } + } + } + // System.out.println(""Case#"" + (i+1) +"":\t T: "" + t + ""\t\t H: "" + // + h +""\t ST: "" + S + ""\t WT: "" + noOfWinningCases); + + if (c < S) + { + for (int k=0; k S) + { + for (int k=0; kS; k++) + { + if (t.get(k)%3 == 0 ) + { + if (h.get(k)- (t.get(k)/3) == 1) + { + h.set(k, (t.get(k)/3)); + --c; + } + } + else if (t.get(k)%3 == 2 ) + { + if (h.get(k)- (t.get(k)/3) == 2) + { + h.set(k, (t.get(k)/3)+1); + --c; + } + } + } + } + + for (int k=0; k= p) + ++noOfWinningCases; + } + + //System.out.println(""H: "" + h +""\nST: "" + S + ""\t WT: "" + noOfWinningCases); + // System.out.println(""Case#"" + (i+1) +"":\t T: "" + t + ""\t\t H: "" + // + h +""\t ST: "" + S + ""\t WT: "" + noOfWinningCases); + outputStr = noOfWinningCases+""""; + /****************************************************************** + * + * Code for printing the OUTPUT + * + ******************************************************************/ + + outputList.add(""Case #"" + (i+1) + "": "" + outputStr); + } + + /****************************************************************** + * + * Code for writing the OUTPUT to the output file + * + ******************************************************************/ + + try + { + //""G:/Programming/GOOGLE_Code_Jam/GCJ_StoreCredits/src/Output/output.in"" + f_write_stream = new FileWriter(args[1]); + out = new BufferedWriter(f_write_stream); + for (int count=0; count=sureCountScore){ + counter++; + }else if (new Integer(elements[i])>0&&numberOfSuprisings>0&& new Integer(elements[i])>=surprisingCountScore){ + counter++; + numberOfSuprisings--; + } + } + + return """"+counter; + } + + private static void output(BufferedWriter out, int zz, String formattedString) throws IOException { + // TODO Auto-generated method stub + String outputLine = String.format(""Case #%d: %s\n"", zz, + formattedString); + System.out.format(outputLine); + out.write(outputLine); + } + +} +" +A21207,"import java.util.ArrayList; +import java.util.List; + +public class ProblemSample implements Problem { + + private int solution; + + private int googlers; + + private int surprises; + + private int note; + + private List sums = new ArrayList(); + + @Override + public void solve() { + + int resultat = 0; + + for (int i = 0; i < sums.size(); i++) { + + if (note == 0) { + // Ils ont tous eu au moins 0... + resultat = this.googlers; + } else if (note == 1) { + // Tous ceux qui ont eu au moins 1 ont eu au moins la note de 1. + if (sums.get(i) >= 1) { + resultat++; + } + } else { + if ((sums.get(i) == 3 * note - 4 || sums.get(i) == 3 * note - 3) && sums.get(i) > note) { + // S'ils sont tout juste, ils ont utilisé une surprise. + surprises--; + // Et on les compte que si il restait des surprises à consommer + if (surprises >= 0) { + resultat++; + } + } + if (sums.get(i) >= 3 * note - 2 && sums.get(i) > note) { + // Ok sans surprise. + resultat++; + } + } + } + this.setSolution(resultat); + } + + @Override + public void print() { + System.out.println(googlers + "" "" + surprises + "" "" + note + "" "" + sums.toString()); + } + + @Override + public Object getSolution() { + return solution; + } + + public void setSolution(int solution) { + this.solution = solution; + } + + public int getGooglers() { + return googlers; + } + + public int getSurprises() { + return surprises; + } + + public int getNote() { + return note; + } + + public List getSums() { + return sums; + } + + public void setGooglers(int googlers) { + this.googlers = googlers; + } + + public void setSurprises(int surprises) { + this.surprises = surprises; + } + + public void setNote(int note) { + this.note = note; + } + + public void setSums(List sums) { + this.sums = sums; + } + +}" +A21095,"// Problem B + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; +import java.util.Scanner; + +public class B { + + private void processInput() throws IOException { + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); + + for (int testCase = 1; testCase <= T; testCase++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] arr = new int[N]; + for (int j = 0; j < N; j++) { + arr[j] = in.nextInt(); + } + + int res = go(N, S, p, arr); + + System.out.printf(Locale.ENGLISH, ""Case #%d: %d\n"", testCase, res); + } + + in.close(); + } + + private int go(int N, int S, int p, int[] arr) { + + int res = 0; + int s = S; + + for (int i = 0; i < N; i++) { + int rr = -1; + for (int P = p; P <= 10; P++) { + int diff = arr[i] - P; + if (diff >= 0) { + int v1 = diff / 2; + int v2 = diff - v1; + if (P >= v1 && P >= v2) { + if (P - v1 <= 1 && P - v2 <= 1) { + rr = 0; + } else if (P - v1 <= 2 && P - v2 <= 2) { + if (rr == -1) { + rr = 1; + } + } + + } + } + } + if (rr == 0) { + res++; + } else if (rr == 1 && s > 0) { + s--; + res++; + } + } + + return res; + } + + + public static void main(String[] args) throws Exception { + B temp = new B(); + temp.processInput(); + } +} +" +A21595,"import java.io.*; +import java.util.ArrayList; + + +public class inpOutHandler { + + public testCase readInput(String fname, int linesInTestCase){ + testCase allCases; + ArrayList lineList = new ArrayList(); + BufferedReader rd = null; + try { + rd = new BufferedReader(new FileReader(fname)); + while (true) { + String line = rd.readLine(); + if (line == null) break; + lineList.add(line); + } + rd.close(); + } catch (IOException ex) { + System.out.println(""Can't open that file.""); + } + //for(int i=0;i""); + + int N = Integer.parseInt(lineList.get(0)); + //int N=100; + allCases = new testCase(N); + int index=1; + for(int i=0;i= 0; --i ) { + + int t = G[ i ]; + + if ( maxNormal[ t ] >= p ) { + + ++results; + + continue; + } + + if ( S > 0 && maxSurprise[ t ] >= p ) { + + ++results; + + --S; + + continue; + } + break; + } + + return results; + } + + + public Dance( String input ) throws Exception { + + init(); + + FileInputStream fstream = new FileInputStream(input); + + DataInputStream in = new DataInputStream(fstream); + + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + int t = Integer.parseInt( br.readLine() ); + + for( int i = 1; i <= t; i++ ) { + + String test = br.readLine(); + + String[] tokens = test.split( "" "" ); + + int N = Integer.parseInt( tokens[0] ); + + int S = Integer.parseInt( tokens[1] ); + + int p = Integer.parseInt( tokens[2] ); + + int[] G = new int[N]; + + for( int j = 0; j < N; ++j ) { + + G[ j ] = Integer.parseInt( tokens[ 3 + j ] ); + } + + java.util.Arrays.sort( G ); + + System.out.print( ""Case #"" ); + + System.out.print( i ); + + System.out.print( "": "" ); + + System.out.println( run( S, p, G ) ); + } + + in.close(); + } + + + public static void main( String[] args ) throws Exception { + + new Dance( ""dance-test.in"" ); + } +} +" +A20716,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class Googlers { + + static int T = 0; + + public static void main(String[] args) { + Googlers c = new Googlers(); + c.parseInput(); + } + + private void parseInput() + { + try{ + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + FileWriter fwstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fwstream); + + if((strLine = br.readLine()) != null) + T = Integer.parseInt(strLine); + + for( int ctr = 1; ctr <= T; ctr++ ) + { + if(ctr > 1 ) + out.newLine(); + + int N = 0; + int S = 0; + int p = 0; + String strLine2; + + if((strLine2 = br.readLine()) != null) + { +// System.out.println(strLine2); + } + + String [] numberStrings = strLine2.split("" ""); + N = Integer.parseInt(numberStrings[0]); + S = Integer.parseInt(numberStrings[1]); + p = Integer.parseInt(numberStrings[2]); + + int answer = 0; + + // run for each player + for( int i = 0; i < N; i++ ) + { + int score = Integer.parseInt(numberStrings[3+i]); + + int triple = p*3; + if(triple == 0) { + answer++; + }else if(score == 0) { + continue; + } else if(score >= triple-2) { + answer++; + } else if((S > 0) && (score >= triple-4)) { + S--; + answer++; + } + + } +// System.out.println(answer); + out.write(""Case #"" + ctr +"": "" + answer); + } + in.close(); + out.close(); + }catch (Exception e) + { + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A21891,"package codejam2012; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.PrintStream; + +public class ProblemB +{ + public static void main(String[] args) throws Exception + { + BufferedReader in = new BufferedReader(new FileReader(""in.txt"")); + PrintStream out = System.out; + out = new PrintStream(""out.txt""); + + int T = Integer.parseInt(in.readLine()); + + for (int t = 0; t < T; t++) + { + String[] tok = in.readLine().split("" ""); + int N = Integer.parseInt(tok[0]); + int S = Integer.parseInt(tok[1]); + int p = Integer.parseInt(tok[2]); + +// BRUTE FORCE +// int ans = 0; +// +// for (int s1 = 0; s1 <= 10; s1++) +// for (int s2 = s1; s2 <= s1+2; s2++) +// for (int s3 = s2; s3 <= s1+2; s3++) +// for (int s4 = 0; s4 <= 10; s4++) +// for (int s5 = s4; s5 <= s4+2; s5++) +// for (int s6 = s5; s6 <= s4+2; s6++) +// for (int s7 = 0; s7 <= 10; s7++) +// for (int s8 = s7; s8 <= s7+2; s8++) +// for (int s9 = s8; s9 <= s7+2; s9++) +// { +// int p1 = Integer.parseInt(tok[3]); +// int p1s = (s1+2 == s3) ? 1 : 0; +// int p1t = (s3 >= p) ? 1 : 0; +// if (s1+s2+s3 != p1) continue; +// +// if (N > 1) +// { +// int p2 = Integer.parseInt(tok[4]); +// int p2s = (s4+2 == s6) ? 1 : 0; +// int p2t = (s6 >= p) ? 1 : 0; +// if (s4+s5+s6 != p2) continue; +// +// if (N > 2) +// { +// int p3 = Integer.parseInt(tok[5]); +// int p3s = (s7+2 == s9) ? 1 : 0; +// int p3t = (s9 >= p) ? 1 : 0; +// if (s7+s8+s9 != p3) continue; +// if (p1s+p2s+p3s != S) continue; +// if (p1t+p2t+p3t > ans) ans = p1t+p2t+p3t; +// } +// else +// { +// if (p1s+p2s != S) continue; +// if (p1t+p2t > ans) ans = p1t+p2t; +// } +// } +// else +// { +// if (p1s != S) continue; +// if (p1t > ans) ans = p1t; +// } +// } +// END BRUTE FORCE + + int with = 0, without = 0, either = 0, other = 0; + for (int i = 3; i < tok.length; i++) + { + int total = Integer.parseInt(tok[i]); + + if (total == 0) + { + if (p == 0) without++; + } + else if (total == 1) + { + if (p <= 1) without++; + } + else if (total < 29) + { + if (total >= 3*p-2) either++; + else if (total >= 3*p-4) with++; + else other++; + } + else without++; + } + + int ans = with + without + either; + if (with > S) ans = S + without + either; + else if (S > with + either + other) ans = 0; + out.printf(""Case #%d: %d\n"", t+1, ans); + } + + if (out != System.out) out.close(); + } +} +" +A22442,"import java.io.*; + +public class B extends CodeJammer { + + public void process() throws IOException { + int[] input = reader.readArray(); + int n = input[0]; + int s = input[1]; + int p = input[2]; + int auto =0; //scores that reach p automatically + int poss = 0; //scores that can reach p with surprise + for (int i=3; i= p) auto++; + else if (def == p-1 && def > 0 && mod != 1) poss++; + } + if (poss > s) poss = s; //cap number of surprising scores that reach p + output(auto+poss); + } + + public static void main(String[] args) { + B b = new B(); + b.run(args); + } + +} +" +A21869,"package gjc.googledancer; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + +public class Solution { + + /** + * @param args + */ + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""B-large.txt"")); + int nTestCases = Integer.parseInt(br.readLine()); + for (int i=0; i=threshold) { + result++; + } else if (surpriseValue>=threshold && nSurprise>0) { + result++; + nSurprise--; + } + } + + // Display the results. + bw.write(""Case #""+(i+1)+"": ""); + bw.write(result+""\n""); + } + bw.close(); + } + +} +" +A21943,"package com.codejam.y2012.qual; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws Exception { + String file = ""src/com/codejam/y2012/qual/B-large.in""; + Scanner scanner = new Scanner(new FileReader(file)); + StringBuilder sb = new StringBuilder(); + int caseCount = scanner.nextInt(); + scanner.nextLine(); + for (int caseNum = 1; caseNum <= caseCount; caseNum++) { + sb.append(""Case #"").append(caseNum).append("": ""); + solve(scanner, sb); + sb.append(""\n""); + } + + PrintWriter pw = new PrintWriter(new FileWriter(file.replace(""in"", ""out""))); + String output = sb.toString(); + System.err.println(output); + pw.write(output); + pw.flush(); + pw.close(); + scanner.close(); + } + + private static void solve(Scanner sc, StringBuilder sb) { + int count = sc.nextInt(); + int surprise = sc.nextInt(); + int p = sc.nextInt(); + int answer = 0; + for (int i = 0; i < count; i++) { + int goog = sc.nextInt(); + if (p == 0) { + answer++; + continue; + } + int min = goog / 3; + int rest = goog % 3; + if (min >= p) { + answer++; + continue; + } else if (goog == 0) { + continue; + } else if (min + 1 == p && rest > 0) { + answer++; + continue; + } else if (min + 1 == p && rest == 0 && surprise > 0) { + surprise--; + answer++; + continue; + } else if (min + 2 == p && rest == 2 && surprise > 0) { + surprise--; + answer++; + } + } + sb.append(answer); + } +} +" +A20414,"package MyAllgoritmicLib; + +public class SimpleNumbers { + public static boolean[] masInt; + + public static void initSimpleInt(int n) { // âõîäíûå äàííûå + masInt = new boolean[n + 1]; + for(int i=0; i<=n;i++){ + masInt[i] = true; + } + masInt[0] = masInt[1] = false; // åñëè êòî-òî áóäåò èñïîëüçîâàòü ýòè + // çíà÷åíèÿ + for (int i = 2; i <= n; ++i) { + if (masInt[i]) { + for (int j = i + i; j < n; j += i) { + masInt[j] = false; + } + } + } + } + + public static void main(String[] args) { + initSimpleInt(1000000); + int col = 0; + int max = 0; + for (int i = 0; i < 1000000; i++) { + if (masInt[i]) { + col++; + max = i; + } + } + System.out.println(max); + System.out.println(col); + } +} +" +A22087,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DancingWiththeGooglers { + + public static void main(String[] args) { + List lines = getline(""C:\\Users\\Ami\\Downloads\\B-large.in""); + System.out.println(""number Of Test Cases-->"" + lines.remove(0)); + ProcessTestCases(lines); + } + + private static void ProcessTestCases(List lines) { + int k = 1; + for (String line : lines) { + String[] strings = line.split("" ""); + int S = Integer.valueOf(strings[1]); + int p = Integer.valueOf(strings[2]); + int j = 0; + List lst = new ArrayList(); + for (int i = 3; i < strings.length; i++) { + lst.add(Integer.valueOf(strings[i])); + } + Collections.sort(lst); + for (int i : lst) { + if (S > 0) { + int eqCmp = i / 3; + if (eqCmp >= p) { + j++; + } else { + int remin = i % 3; + if (remin > 0) { + if (eqCmp > 0 && remin == 1 && eqCmp + 1 >= p) { + j++; + } else if (eqCmp > 0 && remin == 2) { + if (eqCmp + 1 >= p) { + j++; + } else if (eqCmp + 2 >= p) { + S--; + j++; + } + + } + } else if (eqCmp > 0 && eqCmp + 1 >= p) { + j++; + S--; + } else { + if (eqCmp == 0) { + if (remin == 2) { + if (p == 2) { + j++; + S--; + } else { + j++; + } + } else if (remin == 1) { + if (p == 1 || p == 0) { + j++; + } + } + } + } + } + } else { + int eqCmp = i / 3; + int remin = i % 3; + if (eqCmp >= p) { + j++; + } else { + if (remin > 0 && eqCmp > 0 + && (eqCmp + (remin == 1 ? 1 : 1)) >= p) { + j++; + } else if ((remin == 1 || remin == 2) && p == 1 + && eqCmp == 0) { + j++; + } + } + } + } + System.out.println(""Case #"" + k + "": "" + j); + k++; + } + } + + private static List getline(String path) { + List ls = new ArrayList(); + try { + FileInputStream fstream = new FileInputStream(path); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + while ((strLine = br.readLine()) != null) { + ls.add(strLine); + } + in.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + return ls; + } +} +" +A21954,"import java.io.*; +import java.util.Arrays; +import java.util.NoSuchElementException; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream; + try { + inputStream = new FileInputStream(""module/src/b.in""); + } catch (IOException e) { + throw new RuntimeException(e); + } + OutputStream outputStream; + try { + outputStream = new FileOutputStream(""module/src/b.txt""); + } catch (IOException e) { + throw new RuntimeException(e); + } + MyScanner in = new MyScanner(inputStream); + PrintWriter out = new PrintWriter(outputStream); + ProblemB solver = new ProblemB(); + int testCount = Integer.parseInt(in.next()); + for (int i = 1; i <= testCount; i++) + solver.solve(i, in, out); + out.close(); + } +} + +class ProblemB { + static int[] maxWhenSurprise; + static int[] maxWhenNotSurprise; + public void solve(int testNumber, MyScanner in, PrintWriter out) { + if(maxWhenNotSurprise == null){ + maxWhenNotSurprise = new int[31]; + maxWhenSurprise = new int[31]; + Arrays.fill(maxWhenSurprise,-1); + Arrays.fill(maxWhenNotSurprise,-1); + for (int a = 0; a < 11; a++) for (int b = 0; b < 11; b++) for (int c = 0; c < 11; c++){ + int m = Math.max(Math.max(Math.abs(a - b), Math.abs(b - c)), Math.abs(c - a)); + int sum = a+b+c; + if(m<=2){ + if(m==2)maxWhenSurprise[sum] = Math.max(Math.max(Math.max(a,b),c),maxWhenSurprise[sum]); + else maxWhenNotSurprise[sum] = Math.max(Math.max(Math.max(a, b), c),maxWhenNotSurprise[sum]); + } + } + } + int N=in.nextInt(); + int S=in.nextInt(); + int p=in.nextInt(); + int[][] dp = new int[N+1][S+1]; + ArrayUtils.fill(dp,-1); + dp[0][0] = 0; + for(int i=0;i= 0){ + if(maxWhenNotSurprise[score]>=0){ + dp[i+1][j] = Math.max(dp[i+1][j],dp[i][j] + (maxWhenNotSurprise[score]>=p ? 1 : 0)); + } + if(maxWhenSurprise[score]>=0 && j+1=p ? 1 : 0)); + } + } + } + out.println(""Case #""+testNumber+"": ""+dp[N][S]); + } +} + +class MyScanner { + private final InputStream in; + public MyScanner(InputStream in){ + this.in = in; + } + + char[] buf = new char[2000000]; + int strLen; + public String next() { + try { + strLen = 0; + int c; + do{ + c = in.read(); + if(c==-1)throw new NoSuchElementException(); + }while(Character.isWhitespace(c)); + do { + buf[strLen++] = (char)c; + c = in.read(); + } while (c!=-1 && !Character.isWhitespace(c)); + return new String(buf,0,strLen); + } catch (IOException e) { + throw new NoSuchElementException(); + } + } + + public int nextInt(){ + try{ + int c=in.read(); + if(c==-1) return c; + while(c!='-'&&(c<'0'||'9' 2)continue; + + if(i3 >= p) { + if(i3 - i1 == 2) { + isUnsure = true; + } else { + isUnsure = isSure = true; + break m; + } + + } + } + } + + if(isSure)countSure++; + if(isUnsure)countUnsure++; + } + + out.println(Math.min(countSure + s, countUnsure)); + + } + + public static void main(String[] args) throws Exception { + int t = Integer.parseInt(inB.readLine()); + for(int _ = 0; _= p) + cnt++; + } else { + if (ti % 3 == 0) { + if (ti / 3 >= p) { + cnt++; + } else if (ti != 0 && s > 0 && ti / 3 + 1 == p) { + cnt++; + s--; + } + } + if (ti % 3 == 2) { + if (ti / 3 + 1 >= p) { + cnt++; + } else if (s > 0 && ti / 3 + 2 == p) { + cnt++; + s--; + } + } + } + } + out.printf(""Case #%d: %d"", (i+1), cnt); + out.println(); + } + out.flush(); + } +} +" +A21807,"import java.io.*; +import java.util.*; + +public class B{ + public static ArrayList cases = new ArrayList(); + public static void main (String [] args){ + + parseFile(); + for(int i=0; i al = null; + StringTokenizer st = null; + + for(int i=0; i(); + st = new StringTokenizer(br.readLine()); + while (st.hasMoreTokens()) { + al.add(st.nextToken()); + } + + Case c = new Case(); + c.n = Integer.parseInt(al.get(0)); + c.s = Integer.parseInt(al.get(1)); + c.p = Integer.parseInt(al.get(2)); + for(int j=3; j0 && total == 0){continue;} + if(c.p ==1 && total>0){ans ++; continue;} + //System.out.println(""total=""+total); + if(total>= nLimit){ + ans ++; + }else if((total == (nLimit-1))||(total == (nLimit-2))){ + if (c.s <=0){ + }else{ + ans ++; + c.s --; + } + } + } + return ans; + } + + static class Case{ + int n; + int s; + int p; + ArrayList totals = new ArrayList (); + } +} +" +A21906,"import java.util.Scanner; + +//""c:\Program Files\Java\jdk1.6.0_25\bin\javac.exe"" a.java +//""c:\Program Files\Java\jdk1.6.0_25\bin\java.exe"" a test.out +public class B { + + public static String meth1 (String s){ + String res = """"; + res=res+s; + + return res; + } + //""c:\Program Files\Java\jdk1.6.0_25\bin\javac.exe"" A.java + //""c:\Program Files\Java\jdk1.6.0_25\bin\java.exe"" A test.out + static Scanner sc = new Scanner(System.in); + public static void main(String[] args) { + int cases ; + int res=0; + + // String [] inputs; + + cases = Integer.parseInt(sc.nextLine()); + int N=0; + int S = 0; + int P =0; + int p = 0; + int [] t; + for(int id = 1; id <= cases; id++){ + res=0; + N = sc.nextInt(); + S = sc.nextInt(); + P = sc.nextInt(); + + p = 3*P; + t = new int[N]; + for(int i=0;i=P){ + if (t[i]+2>=p){ + res++; + } + else{ + if (t[i]+4>=p&&S>0){ + res++; + S--; + } + } + } + } + // for (int i = 0;i0 ) + { + strReturnValue += "" ""; + } + char strChars[] = strGooglereseWords[i].toCharArray(); + + for(int j=0;j=0 && k<=10 && Math.abs(k-i)<=2 && Math.abs(k-j)<=2) { + if (i>=p || j>=p || k>=p) { + if (sup(i,j,k)) { + ret[0] = true; + } else { + ret[1] = true; + } + } else if (sup(i,j,k)) { + ret[2] = true; + } else { + ret[3] = true; + } + } + } + } + } + return ret; + } + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + int i,j; + for (i=1;i<=T;i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int overp = 0; + int condp = 0; + int result; + for (j=0;j(p-1)*3) { + overp++; + } else if (x<3*p-4 || p==1) { + } else { + condp++; + } + } + result = Math.min(S, condp) + overp; + System.out.println(""Case #""+i+"": ""+result); + } + } + +} +" +A21823,"package qual; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class Googlers { + public static void main(String[] args) throws IOException { + new Googlers().run(); + } + int solve(int s, int p, int[] scores) { + Arrays.sort(scores); + for (int i = 0; i < scores.length / 2; i++) { + int t = scores[i]; + scores[i] = scores[scores.length - 1 - i]; + scores[scores.length - 1 - i] = t; + } + int count = 0; + for (int i = 0; i < scores.length; i++) { + int cur = scores[i]; + int a, b, c; + if (cur % 3 == 0) { + a = cur / 3; + b = cur / 3; + c = cur / 3; + } else if (cur % 3 == 1) { + a = cur / 3 + 1; + b = cur / 3; + c = cur / 3; + } else { + a = cur / 3 + 1; + b = cur / 3 + 1; + c = cur / 3; + } + + if (a >= p) + count++; + else { + if (a == b && b > 0 && s > 0) { + a++; + b--; + if (a >= p) { + count++; + s--; + } + } + } + } + return count; + } + public void run() throws IOException { + Scanner in = new Scanner(System.in); + PrintWriter out = new PrintWriter(System.out); + + int testsCount = in.nextInt(); + for (int t = 0; t < testsCount; t++) { + int n = in.nextInt(), s = in.nextInt(), p = in.nextInt(); + int[] scores = new int[n]; + for (int i = 0; i < n; i++) { + scores[i] = in.nextInt(); + } + int ans = solve(s, p, scores); + out.printf(""Case #%d: %d\n"", t + 1, ans); + } + + out.close(); + } +} +" +A20248,"import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + + + + +public class Dancers { + + @SuppressWarnings(""deprecation"") + private static void solveProblem() { + // Stream to read file + FileInputStream fin; + // Stream to write file + FileOutputStream fout; + + try + { + // Open an input stream + // fin = new FileInputStream (""B-large.in""); + fin = new FileInputStream (""input.txt""); + // Open an output stream + fout = new FileOutputStream (""output.txt""); + // reader + DataInputStream reader = new DataInputStream(fin); + // writer + PrintStream writer = new PrintStream(fout); + + int numCases = Integer.parseInt(reader.readLine()); + + String line = """"; + for (int i = 1; i <= numCases; i++) + { + line = ""Case #"" + i + "": "" + solveCase(reader); + writer.println(line); + System.out.println(line); + } + + // Close our input stream + fin.close(); + // Close our output stream + fout.close(); + } + // Catches any error conditions + catch (IOException e) + { + System.err.println (""Unable to read from file""); + System.exit(-1); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SuppressWarnings(""deprecation"") + public static String solveCase(DataInputStream reader) throws Exception, IOException + { + return getMaxDancers(reader.readLine().split("" "")); + } + + private static String getMaxDancers(String[] values) + { + int numGooglers = Integer.parseInt(values[0]); + int numSurprising = Integer.parseInt(values[1]); + int value = Integer.parseInt(values[2]); + int minCriticalValue = value + 2*(value-2); + minCriticalValue = minCriticalValue < 0 ? value : minCriticalValue ; + int maxCriticalValue = minCriticalValue + 1; + if(value == 0) maxCriticalValue = -1; + + int score, maxDancers = 0; + for (int i = 3; i < 3+numGooglers; i++) + { + score = Integer.parseInt(values[i]); + if ( score > maxCriticalValue + || score >= minCriticalValue && numSurprising-- > 0) + maxDancers++; + } + + return maxDancers + """"; + } + + public static void main(String[] args) + { + solveProblem(); + } +} +" +A22370,"import java.io.*; +import java.util.Scanner; + +public class Dance +{ + public static void main(String[] args) + throws IOException + { + //new FileReader(""dancing.in"") + Scanner input = new Scanner(System.in); + int next = Integer.parseInt(input.nextLine()); + // PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(""dancing.out""))); + + for (int i = 1; i <= next; i++) + { + + System.out.print(""Case #"" + i + "": ""); + int totalNums = input.nextInt(); + int numSurprises = input.nextInt(); + int bestScore = input.nextInt(); + + int recordedSurprisesWithP = 0; + int notSurprisesWithP = 0; + for (int k = 0; k < totalNums; k++) + { + int temp = input.nextInt(); + if (temp == ((3 * bestScore) - 3) || temp == ((3 * bestScore) - 4)) + { + if (bestScore != 1) + recordedSurprisesWithP++; + } + else if (temp > (3 * bestScore) - 3) + notSurprisesWithP++; + } + + System.out.println(notSurprisesWithP + Math.min(numSurprises, recordedSurprisesWithP)); + } + } +}" +A23015,"package tr0llhoehle.cakemix.utility.googleCodeJam; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Scanner; + +/** + * {@link IOManager} is used to manage all input and output operations needed + * for your java-solution of a Google codejam problem. + * + * It uses the class/interface {@link Problem} and {@link Solver}. + * + * @author Cakemix + * + * @param + * The type of your concrete Solver-implementation which solves the + * Problem P. + * @param

+ * The type of your concrete Problem. + * @see Problem + * @see Solver + */ +public class IOManager, P extends Problem> { + + private S solver; + private Class

clazz; + private LinkedList

problems; + + /** + * Creates a new IOManager. + * + * @param solver + * The solver-instance which is to be used for solving the + * problems. + * @param clazz + * A Class object of one exemplary concrete Problem P. This is + * needed to correctly instantiate new concrete Problems. + */ + public IOManager(S solver, Class

clazz) { + this.clazz = clazz; + this.solver = solver; + } + + private P createProblem() throws InstantiationException, + IllegalAccessException { + return clazz.newInstance(); + } + + /** + * Starts the IO-operations and solves the Problems contained in the file + * pointed to by the filePath. + * + * @param filePath + * A String describing the location of an input-file (usually + * *.in) + * @throws IOException + * @throws ParseException + */ + public void start(String filePath) throws IOException, ParseException { + int amountOfProblems; + File out; + Scanner lineScanner; + File in = new File(filePath); + Scanner scanner; + FileWriter writer; + + System.out.print(""Creating files... ""); + if (filePath.length() >= 3 + && filePath.substring(filePath.length() - 3).equals("".in"")) { + filePath = filePath.substring(0, filePath.length() - 3); + } + filePath += "".out""; + + out = new File(filePath); + out.createNewFile(); + System.out.println(""Done!""); + + System.out.print(""Creating file reader and writers... ""); + scanner = new Scanner(in); + writer = new FileWriter(out); + System.out.println(""Done!""); + + System.out.print(""Parsing the input file... ""); + amountOfProblems = scanner.nextInt(); + scanner.nextLine(); + problems = new LinkedList

(); + for (int probID = 0; probID < amountOfProblems; probID++) { + P problem = null; + try { + problem = createProblem(); + SupportedTypes[] probTypes = problem.getTypes(); + for (SupportedTypes t : probTypes) { + switch (t) { + case INT: + lineScanner = new Scanner(scanner.nextLine()); + problem.addValue(lineScanner.nextInt()); + break; + case DOUBLE: + lineScanner = new Scanner(scanner.nextLine()); + problem.addValue(lineScanner.nextDouble()); + break; + case BOOLEAN: + lineScanner = new Scanner(scanner.nextLine()); + problem.addValue(lineScanner.nextBoolean()); + break; + case STRING: + problem.addValue(scanner.nextLine()); + break; + case LIST_INT: + lineScanner = new Scanner(scanner.nextLine()); + ArrayList ints = new ArrayList(); + while (lineScanner.hasNext()) { + ints.add(lineScanner.nextInt()); + } + problem.addValue(ints); + break; + case LIST_DOUBLE: + lineScanner = new Scanner(scanner.nextLine()); + ArrayList doubles = new ArrayList(); + while (lineScanner.hasNext()) { + doubles.add(lineScanner.nextDouble()); + } + problem.addValue(doubles); + break; + case LIST_BOOLEAN: + lineScanner = new Scanner(scanner.nextLine()); + ArrayList booleans = new ArrayList(); + while (lineScanner.hasNext()) { + booleans.add(lineScanner.nextBoolean()); + } + problem.addValue(booleans); + break; + case LIST_STRING: + lineScanner = new Scanner(scanner.nextLine()); + ArrayList strings = new ArrayList(); + while (lineScanner.hasNext()) { + strings.add(lineScanner.next()); + } + problem.addValue(strings); + break; + default: + System.err + .print(""Default case! This is not a good sign... ""); + } + } + } catch (IllegalAccessException e) { + System.err.println(""Couldn't instantiate the problem!""); + e.printStackTrace(); + } catch (InstantiationException e) { + System.err.println(""Couldn't instantiate the problem!""); + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (problem != null) { + problems.add(problem); + } + } + System.out.println(""Done!""); + + System.out.print(""Closing the input file... ""); + scanner.close(); + System.out.println(""Done!""); + + System.out.print(""Solving the problems... ""); + for (int i = 0; i < problems.size(); i++) { + writer.append(""Case #"" + (i+1) + "": "" + solver.solve(problems.get(i)) + + System.getProperty(""line.separator"")); + } + System.out.println(""Done!""); + + System.out.print(""Closing the writer... ""); + writer.close(); + System.out.println(""Done!""); + + System.out.println(""Shutting down, output lies here:""); + System.out.println(filePath); + } +} +" +A21787,"package dancers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Arrays; + +public class DancerEvaluation { + + private final int numberOfGooglers; + private int surpriseCount; + private final int bestScore; + private final int[] lstOfPoints; + + public DancerEvaluation(int numberOfGooglers, int surpriseCount, int bestScore, int[] lstOfPoints) { + this.numberOfGooglers = numberOfGooglers; + this.surpriseCount = surpriseCount; + this.bestScore = bestScore; + this.lstOfPoints = lstOfPoints; + + } + + public int solve() { + int countOfTotalDancers = 0; + for (int i = 0; i < lstOfPoints.length; i++) { + int avg_point = lstOfPoints[i]/3; + int x = avg_point; + int y = avg_point; + int z = avg_point; + + int leftOver = lstOfPoints[i] % 3; + + switch (leftOver) { + case 0: + if(avg_point + 1 == bestScore && surpriseCount > 0 && avg_point > 0){ + z = z + 1; + x = x - 1; + surpriseCount--; + } + + break; + case 1: + z = z + 1; + break; + case 2: + if(surpriseCount > 0 && (z + 2) <= 10 && (z + 2) == bestScore){ + z = z + 2; + surpriseCount--; + }else { + z = z+1; + y = y+1; + } + break; + } + + if(Math.max(Math.max(x, y), z) >= bestScore){ + countOfTotalDancers++; + } + + } + + return countOfTotalDancers; + } + + public static void main(String[] args) throws Exception{ + BufferedReader reader = new BufferedReader(new FileReader(new File(""C:\\Users\\maheshsa\\Desktop\\input.txt""))); + int numOfTestCases = Integer.parseInt(reader.readLine()); + FileWriter fw = new FileWriter(new File(""C:\\Users\\maheshsa\\Desktop\\output.txt"")); + for (int i = 1; i <= numOfTestCases; i++) { + String[] inputAsString = reader.readLine().split("" ""); + int[] input = new int[inputAsString.length]; + for (int j = 0; j < inputAsString.length; j++) { + input[j] = Integer.parseInt(inputAsString[j]); + } + int numberOfDancers = input[0]; + int surpriseCount = input[1]; + int bestScore = input[2]; + int[] scores = Arrays.copyOfRange(input, 3, input.length); + fw.append(""Case #"" + i + "": "" + new DancerEvaluation(numberOfDancers, surpriseCount, bestScore, scores).solve() + ""\n""); + } + + fw.flush(); + + reader.close(); + fw.close(); + + } + +} +" +A22448,"import java.io.IOException; +import java.util.*; + +public class AlienLanguage extends JamProblem { + private int wordsC; + private int wordsL; + List words = new ArrayList(); + TreeNode startNode; + + public static void main(String[] args) throws IOException { + AlienLanguage p = new AlienLanguage(); + p.go(); + } + + @Override + void parseFirstLine(List file) { + int[] firstLine = JamUtil.parseIntList(file.get(0), 3); + caseCount = firstLine[2]; + wordsC = firstLine[1]; + wordsL = firstLine[0]; + startNode = new TreeNode(null); + for (int i=0; i curr = new HashSet<>(); + curr.add(startNode); + List> pattern = cas.pattern; + for (int i = 0; i < pattern.size(); i++) { + Set characters = pattern.get(i); + Set next = new HashSet<>(); + for (Character ch : characters) { + for (TreeNode node : curr) { + if (node.childred.containsKey(ch)) { + next.add(node.childred.get(ch)); + } + } + } + curr = next; + } + return """" + curr.size(); + } + + @Override + JamCase parseCase(List file, int lineI) { + ALCase cas = new ALCase(); + cas.lineCount = 1; + String line = file.get(lineI); + boolean inGroup = false; + char[] chars = line.toCharArray(); + Set current = new HashSet<>(); + for (int i = 0; i < chars.length; i++) { + char ch = chars[i]; + switch (ch) { + case '(': + inGroup = true; + current = new HashSet<>(); + cas.pattern.add(current); + break; + case ')': + inGroup = false; + break; + default: + if (inGroup) { + current.add(ch); + } else { + current = new HashSet<>(); + cas.pattern.add(current); + current.add(ch); + } + } + } + return cas; + } + + void buildTree(String str, TreeNode node) { + char c = str.charAt(0); + String remain = str.substring(1); + if (node.childred.get(c) == null) { + TreeNode newNode = new TreeNode(c); + node.childred.put(c,newNode); + } + if (!remain.isEmpty()) { + buildTree(remain,node.childred.get(c)); + } + } +} + +class ALCase extends JamCase { + TreeNode startNode = new TreeNode(null); + List> pattern = new ArrayList>(); +} + +class TreeNode { + TreeNode(Character ch) { + this.ch = ch; + } + + Character ch; + Map childred = new HashMap(); +} + + +" +A21482,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class QualificationB { + + public static void main(String[] args) { + try { + FileReader input = new FileReader(args[0]); + BufferedReader in = new BufferedReader(input); + FileWriter output = new FileWriter(""QualificationB.out""); + BufferedWriter out = new BufferedWriter(output); + + String line; + int count = 1; + + line = in.readLine(); + int cases = Integer.parseInt(line); + line = in.readLine(); + + while (line != null && count <= cases) { + if (count != 1) { + out.write(""\n""); + } + + String outStr = ""Case #"" + count + "": "" + getMaxGooglers(line); + System.out.println(outStr); + out.write(outStr); + + line = in.readLine(); + count++; + } + + out.close(); + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static int getMaxGooglers(String line) { + String[] lineArr = line.split("" ""); + final int N = Integer.parseInt(lineArr[0]); // Number of Googlers + final int S = Integer.parseInt(lineArr[1]); // Number of surprising triplets of scores + final int p = Integer.parseInt(lineArr[2]); // Minimum total score + + int googlerCount = 0; + int sCount = 0; + + for (int i = 3; i < lineArr.length && i <= N + 3; i++) { + int score = Integer.parseInt(lineArr[i]); + + if (((score + 2) / 3) >= p) { + googlerCount++; + } else if (((score + 4) / 3) >= p && sCount < S && p > 1) { + googlerCount++; + sCount++; + } + } + + return googlerCount; + } + +} +" +A22432,"import java.io.*; +import java.util.*; + +public class DancingWithGooglers { + public static void main(String[] args) { + try { + FileWriter output = new FileWriter(new File(""output.txt"")); + Scanner s = new Scanner(new File(""input.txt"")); + int trials = s.nextInt(); + s.nextLine(); + for (int i = 0; i < trials; i++) { + int n = s.nextInt(); + int numSupr = s.nextInt(); + int minScore = s.nextInt(); + int cutOff = minScore + Math.max((minScore - 1), 0) * 2; + int suprisingCutOff = minScore + Math.max((minScore - 2), 0) + * 2; + int totalCount = 0; + int numSuprising = 0; + for (int b = 0; b < n; b++) { + int num = s.nextInt(); + if (num >= cutOff) + totalCount++; + else if (num >= suprisingCutOff) { + numSuprising++; + } + } + output.write(""Case #"" + (i + 1) + "": ""); + output.write("""" + + (totalCount + Math.min(numSuprising, numSupr))); + output.write('\n'); + } + s.close(); + output.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A21948,"package qualB; + +import java.util.*; + +public class Dancing { + + private static int cases; + + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + if (input.hasNextInt()) { + cases = input.nextInt(); + } + + for (int i = 0; i < cases; i++) { + System.out.println(""Case #"" + (i+1) + "": "" + getBest(input)); + } + } + + + /* If n is 0, 1, 29 or 30 then there is no special case.. otherwise: + * if (n%3 == 0) + * normal case: [(n/3), (n/3), (n/3)] + * special case: [(n/3)-1, (n/3), (n/3)+1] + * + * if (n%3 == 1) + * normal case: [(n/3), (n/3), (n/3)+1] + * special case: [(n/3)-1, (n/3)+1, (n/3)+1] + * + * if (n%3 == 2) + * normal case: [(n/3), (n/3)+1, (n/3)+1] + * special case: [(n/3), (n/3), (n/3)+2] + * + */ + public static int getBest(Scanner input) { + int googlers = 0; + int surprising = 0; + int scoreWanted = 0; + int counter = 0; + + if (input.hasNextInt()) { + googlers = input.nextInt(); + } + if (input.hasNextInt()) { + surprising = input.nextInt(); + } + if (input.hasNextInt()) { + scoreWanted = input.nextInt(); + } + + Integer[] scores = new Integer[googlers]; + for (int i = 0; i < scores.length; i++) { + if (input.hasNextInt()) { + scores[i] = input.nextInt(); + } + } + + for (int i = 0; i < scores.length; i++) { + int n = scores[i]; + + //0, 1, 29 and 30 don't have special cases.. + if (n == 0) { + if (0 >= scoreWanted) { + counter++; + } + } else if (n == 1) { + if (1 >= scoreWanted) { + counter++; + } + } else if (n == 29 || n == 30) { + if (10 >= scoreWanted) { + counter++; + } + } else { + + + if (n % 3 == 0) { + //case 1: + + if ((n / 3) >= scoreWanted) { + //normal case + counter++; + } else { + //special case..? + if (surprising > 0 && ((n / 3)+1 >= scoreWanted)) { + counter++; + surprising--; + } + } + + } else if (scores[i] % 3 == 1) { + //case 2: + + if ((n / 3)+1 >= scoreWanted) { + //normal case and special case in this case.. + counter++; + } + + } else { + //case 3: + + if ((n / 3)+1 >= scoreWanted) { + //normal case + counter++; + } else { + //special case..? + if (surprising > 0 && ((n / 3)+2 >= scoreWanted)) { + counter++; + surprising--; + } + } + } + } + + } + return counter; + } +}" +A20800,"package knucle.y2012.B; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class B { + + public static void main(String[] args) throws Exception { + FileReader fr = new FileReader(""B-large.in""); + BufferedReader br = new BufferedReader(fr); + + BufferedWriter bw = new BufferedWriter(new FileWriter(""output.txt"")); + + int currentCase = 1; + int caseNum = Integer.parseInt(br.readLine()); + + for(currentCase=1; currentCase<=caseNum; currentCase++){ + String line = br.readLine(); + + String[] inputs = line.split("" ""); + + int itemNum = Integer.parseInt(inputs[0]); + int end = itemNum + 3; + int suprisingNum = Integer.parseInt(inputs[1]); + int minScore = Integer.parseInt(inputs[2]); + + int minTotalScore = Math.max(minScore*3 - 2, minScore); + int minSuprisingTotalScore = Math.max(minScore*3 - 4, minScore); + + int qualifiedNum = 0; + for(int i=3; i= minTotalScore){ + qualifiedNum++; + } else if(suprisingNum > 0 && totalScore >= minSuprisingTotalScore){ + qualifiedNum++; + suprisingNum--; + } + } + + + bw.write(""Case #""); + bw.write(Integer.toString(currentCase)); + bw.write("": ""); + + bw.write(Integer.toString(qualifiedNum)); + + bw.write('\n'); + } + + br.close(); + bw.close(); + } + +} +" +A20252,"package files; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +public class Googler3 { + + + public static void main(String[] args) { + try + { + //BufferedReader br = new BufferedReader(new FileReader(""/Users/Sush/Documents/workspace1/CJ/src/files/Input.txt"")); + BufferedReader br = new BufferedReader(new FileReader(""/Users/Sush/Downloads/B-large.in.txt"")); + String line; + StringBuffer sb = new StringBuffer(); + while((line= br.readLine())!= null) + { + sb = sb.append(line + ""\n""); + } + String[] cases = sb.toString().split(""\n""); + String data = """"; + for(int i= 1;i=min) + { + count = count +1; + } + + } + else + { + int upper = p + (p-1) + (p-1); + int lower = p + (p-2) + (p-2); + if (p==1) + { + lower = 1; + } + if (n >= upper) + { + count = count +1; + } + else if(n>=lower && n < upper && track >0) + { + count = count + 1; + track = track - 1; + } + + } + + + } + + data = data + ""Case #""+i+"": ""+count+""\n""; + System.out.print(""Case #""+i+"": ""+count+""\n""); + + } + File ff = new File(""Output3.txt""); + if (ff.exists()) + { + ff.delete(); + } + BufferedWriter bw = new BufferedWriter(new FileWriter(ff, true)); + bw.write(data); + bw.close(); + } + catch(Exception e) + { + System.out.println(e); + } + + } + +} +" +A21857,"import java.io.*; +import java.math.*; +class Main{ + public static void main(String[] args)throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String u=br.readLine(); + int i,j,t,n,s,p,tp,a,c; + t=Integer.valueOf(u); + for(i=1;i<=t;i++){ + String v=br.readLine(); + String[] vs=v.split("" ""); + n=Integer.valueOf(vs[0]); + s=Integer.valueOf(vs[1]); + p=Integer.valueOf(vs[2]); + a=0; + c=0; + for(j=3;jscores) { + int result = 0; + int fit = 0; + int maybefit = 0; + + for(int score:scores) { + if(score >= p) { + if(score + 2 >= 3*p) + fit++; + else if(score + 4 >= 3*p) + maybefit++; + } + } + if(S < maybefit) + maybefit = S; + + result = fit + maybefit; + + return result; + } + + public void go() throws FileNotFoundException { + Scanner in = new Scanner(new File(""inout\\B-large.in"")); + PrintWriter out = new PrintWriter(""inout\\B-large.out""); + int numTests = in.nextInt(); + //in.nextLine(); //eat end line + + for(int i=0;i scores = new ArrayList(); + for(int j=0;j lines = ir.loadLines(); + for(int i=1;i hs = new HashSet(); + String[] sNums = lines.get(i).split("" "",lines.get(i).length()); + Long[] minMaxArr = GCJUtils.getLongArray(sNums); + for(long l=((minMaxArr[0]<12)?12:minMaxArr[0]);l<=minMaxArr[1];l++){ + String sCurrVal = Long.toString(l); + for(int j=sCurrVal.length()-1;j>0;j--){ + String sTmp = sCurrVal.substring(j)+ sCurrVal.substring(0,j); + Long sLong = Long.parseLong(sTmp); + if(sLong>l && sLong<=minMaxArr[1]){ + hs.add(sLong+""-""+l); + } + } + } + ow.writeCaseLine(hs.size()+""""); + } + ow.flushAndClose(); +} +} +" +A20983,"package fixjava; + +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * A work queue that allows the work queue to continue to increase in size if it is discovered that subdivision of work is + * necessary. Call hasIdleWorkers() to see if there are idle workers, and have the worker subdivide their work further by calling + * enqueueWork(). + */ +public class ParallelWorkQueueDynamic { + + private int numThreads; + private ExecutorService threadPool; + private CompletionService completionService; + + private int numWorkUnitsEnqueued = 0; + private Object lock = new Object(); + + public ParallelWorkQueueDynamic(int numThreads) { + this.numThreads = numThreads; + threadPool = Executors.newFixedThreadPool(numThreads); + completionService = new ExecutorCompletionService(threadPool); + } + + /** + * Enqueue work. Called by the main thread to start processing, and can also be called by workers to subdivide their work. + */ + public void enqueueWork(Callable workUnit) { + synchronized (lock) { + numWorkUnitsEnqueued++; + } + completionService.submit(workUnit); + } + + /** + * Test if there are any idle workers. Should only be called from within a worker so that the total number of workers is greater + * than zero (to avoid a race). + */ + public boolean hasIdleWorkers() { + return numWorkUnitsEnqueued < numThreads; + } + + /** + * Wait for all work submitted by workers to be completed. Throws IllegalArgumentException if any of the worker threads throw an + * exception (this causes an ExecutionException). + */ + public void waitForAllWorkersToQuit() { + try { + while (numWorkUnitsEnqueued > 0) { + // .take() waits for completion of next task and returns a Future for it + completionService.take().get(); + synchronized (lock) { + numWorkUnitsEnqueued--; + } + } + } catch (InterruptedException e) { + e.printStackTrace(); + throw new IllegalArgumentException(""waitForAllWorkersToQuit() failed with "" + e.getMessage(), e); + } catch (ExecutionException e) { + e.printStackTrace(); + throw new IllegalArgumentException(""waitForAllWorkersToQuit() failed with "" + e.getMessage(), e); + } + } + + public void shutdown() { + threadPool.shutdown(); + } +} +" +A22689,"import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Second { + + int surprises; + boolean isSurprisesLeft = false; + + int min; + int[] scores; + + int result; + + public Second(String[] input) { + + scores = new int[Integer.valueOf(input[0])]; + surprises = Integer.valueOf(input[1]); + if (surprises > 0) { + isSurprisesLeft = true; + } + + min = Integer.valueOf(input[2]); + + for (int i = 3; i < input.length; i++) { + scores[i - 3] = Integer.valueOf(input[i]); + } + } + + public static void main(String[] args) throws IOException { + + List result = new ArrayList<>(); + for (String input : FileRW.readFile(""input.txt"")) { + result.add(new Second(input.split(""\\s"")).process()); + } + FileRW.writeOutput(""output.txt"", result); + } + + private String process() { + for (int i = 0; i < scores.length; i++) { + if (suites(scores[i])) { + result++; + } + } + return String.valueOf(result); + } + + public boolean suites(int n) { + + if(min == 0){ + return true; + } + + + n = n - min; + + if(n < 0){ + return false; + } + + int avg = n / 2; + + if (avg >= min - 1) { + return true; + } else if (isSurprisesLeft && (avg >= (min - 2))) { + surprises--; + checkSupr(); + return true; + } else { + return false; + } + } + + private void checkSupr() { + if (surprises == 0) { + isSurprisesLeft = false; + } + } + +} +" +A22235,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.*; +import java.util.*; + +/** + * + * @author jgao + */ +public class CodeJam { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + String file = ""B-large.in""; + List input; + try { + input = readFile(file); + } catch(Exception e) { + return; + } + + for (int i=1; i=thgo) { + go++; + } else if (score>=thsgo) { + sgo++; + } + } + + System.out.println(go+(p==1?0:Math.min(sgo,S))); + } + } + + public static List readFile(String file) throws Exception { + List content = new ArrayList(); + BufferedReader in = new BufferedReader(new FileReader(file)); + for (String line=in.readLine(); line!=null; line=in.readLine()) { + content.add(line); + } + in.close(); + return content; + } +} +" +A21815,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.*; + +/** + * @author Seitaro Sakoda + * + */ +public class DancingWithTheGooglers { + public static void main(String[] args) throws Exception { + DataReader dr = new DataReader(); + int NoT = dr.readInt(); + ArrayList ans = new ArrayList(); + for(int not=0;not=p) nc++; + if(ns[i]

=p) sc++; + } + return nc + (sc > S ? S : sc); + } + + + + + + + static class DataReader { + public BufferedReader br; + + public DataReader(String filename) throws Exception { + br = new BufferedReader(new FileReader(filename)); + } + + public DataReader() throws Exception { + this(""data.in""); + } + + private String readLine() throws Exception { + return br.readLine(); + } + + public int readInt() throws Exception { + return Integer.parseInt(readLine()); + } + + public int[] readInts() throws Exception { + String[] tmp = readLine().split("" ""); + int[] ret = new int[tmp.length]; + for(int i=0;i { + int score1; + int score2; + int score3; + int total; + int id; + int modulus; + int added; + + public Googler(int id,int totalArg){ + this.id = id; + total = totalArg; + score1=score2=score3=total/3; + modulus = total%3; + if(modulus>0){ + score1++; + modulus--; + } + if(modulus>0){ + score2++; + modulus--; + } + added =0; + } + + public boolean passes(int base){ + if(score1 >= base || score2 >= base || score3 >= base) + return true; + return false; + } + + public void modify(){ + if(total>1 ){ + if(score1 == score2){ + score1++; + score2--; + added=1; + } + } + } + @Override + public int compareTo(Googler arg0) { + if(this.score12){ + return false; + } + + if(score1-score3>2){ + return false; + + } + if(score2-score3>2){ + return false; + } + return true; + } +} +" +A20976,"package fixjava; + +import java.util.Map; +import java.util.Map.Entry; + +public class Join { + + // TODO: write a join-of-joins (2D join) that joins lists-of-lists without the complexity of using a lambda. + + public static String join(Iterable list, String delim) { + if (list == null) + return null; + StringBuilder buf = new StringBuilder(); + int idx = 0; + for (T item : list) { + if (idx++ > 0) + buf.append(delim); + buf.append(item.toString()); + } + return buf.toString(); + } + + public static String join(Iterable list, String delim, Lambda customToString) { + if (list == null) + return null; + StringBuilder buf = new StringBuilder(); + int idx = 0; + for (T item : list) { + if (idx++ > 0) + buf.append(delim); + buf.append(customToString.apply(item)); + } + return buf.toString(); + } + + public static String join(T[] array, String delim) { + if (array == null) + return null; + StringBuilder buf = new StringBuilder(); + for (int i = 0, n = array.length; i < n; i++) { + if (i > 0) + buf.append(delim); + buf.append(array[i].toString()); + } + return buf.toString(); + } + + public static String join(int[] array, String delim) { + if (array == null) + return null; + StringBuilder buf = new StringBuilder(); + for (int i = 0, n = array.length; i < n; i++) { + if (i > 0) + buf.append(delim); + buf.append(array[i]); + } + return buf.toString(); + } + + public static String join(float[] array, String delim) { + if (array == null) + return null; + StringBuilder buf = new StringBuilder(); + for (int i = 0, n = array.length; i < n; i++) { + if (i > 0) + buf.append(delim); + buf.append(array[i]); + } + return buf.toString(); + } + + public static String join(double[] array, String delim) { + if (array == null) + return null; + StringBuilder buf = new StringBuilder(); + for (int i = 0, n = array.length; i < n; i++) { + if (i > 0) + buf.append(delim); + buf.append(array[i]); + } + return buf.toString(); + } + + public static String join(char[] array, String delim) { + if (array == null) + return null; + StringBuilder buf = new StringBuilder(); + for (int i = 0, n = array.length; i < n; i++) { + if (i > 0) + buf.append(delim); + buf.append(array[i]); + } + return buf.toString(); + } + + public static String join(Iterable list) { + return join(list, """"); + } + + public static String join(T[] array) { + return join(array, """"); + } + + public static String join(Iterable list, String delim, String prefix, String suffix) { + return prefix + join(list, """") + suffix; + } + + public static String join(T[] array, String prefix, String suffix) { + return prefix + join(array, """") + suffix; + } + + /** Recursively join an Iterable that may optionally consist of Iterables. If the items within the Iterable are of type Entry, they are joined as ""key : value"". If value is an Iterable, it is recursed upon. */ + @SuppressWarnings(""rawtypes"") + public static String joinRecursive(Iterable iterable, String delim, String prefix, String suffix) { + if (iterable == null) + return null; + StringBuilder buf = new StringBuilder(); + buf.append(prefix); + int idx = 0; + for (Object item : iterable) { + if (idx++ > 0) + buf.append(delim); + if (item instanceof Iterable) { + buf.append(joinRecursive((Iterable) item, delim, prefix, suffix)); + } else if (item instanceof Entry) { + Entry ent = (Entry) item; + buf.append(ent.getKey().toString()); + buf.append("" : ""); + Object val = ent.getValue(); + if (val instanceof Iterable) + buf.append(joinRecursive((Iterable) val, delim, prefix, suffix)); + else + buf.append(val.toString()); + } else { + buf.append(item.toString()); + } + } + buf.append(suffix); + return buf.toString(); + } + + /** Join a map and recursively join values in the map */ + public static String joinRecursive(Map map, String delim, String prefix, String suffix) { + return joinRecursive(map.entrySet(), delim, prefix, suffix); + } +} +" +A22918,"package qualification_round; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.*; + +public class DancingWithGooglers { + + + public static void main(String[] args) throws IOException + { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""input2.txt""))); + int inputSize = Integer.parseInt(br.readLine()); + + + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""output2.txt""))); + for(int x = 1 ; x <= inputSize ; x++ ) + { + + String line = br.readLine(); + String[] lineArray = line.split("" ""); + int n = Integer.parseInt(lineArray[0]); + int s = Integer.parseInt(lineArray[1]); + int p = Integer.parseInt(lineArray[2]); + int array[] = new int[n]; + for (int i = 0 ; i< n ; i++) + { + array[i] = Integer.parseInt(lineArray[i + 3]); + } + bw.write(""Case #""+x+"": ""+findP(n,s,p,array)+""\n""); + } + bw.flush(); + bw.close(); + br.close(); + + + int j[] = {15, 13, 11}; + int i = findP(3,1,5,j); + System.out.println(i); + } + + public static int findP(int numberOfGooglers, int surprisingTriplets, int p, int totalScores[]) + { + int answer = 0; + + int border0 = 0; + int border1 = 0 ; + int border2 = 0; + + int totalScore, best; + if (p == 0) + { + return numberOfGooglers; + } + else + { + for(int i = 0 ; i < numberOfGooglers ; i ++) + { + totalScore = totalScores[i]; + if (totalScore == 0) + {/*do nothing*/} + else if( totalScore % 3 == 0 ) + { + best = totalScore / 3; + if (best >= p) + answer += 1; + else if(best == (p-1) ) + border0 += 1; + } + else if( totalScore % 3 == 1 ) + { + best = ( totalScore + 2) / 3; + if (best >= p) + answer += 1; + else if(best == (p-1) ) + border1 += 1; + } + else + { + best = (totalScore + 1) / 3; + if (best >= p) + answer += 1; + else if(best == (p-1) ) + border2 += 1; + } + + } + } + + + if(border0 >= surprisingTriplets) + { + border0 -= surprisingTriplets; + answer += surprisingTriplets; + surprisingTriplets = 0; + } + else + { + answer += border0; + surprisingTriplets -= border0; + border0 = 0; + } + + if(border2 >= surprisingTriplets) + { + border2 -= surprisingTriplets; + answer += surprisingTriplets; + surprisingTriplets = 0; + } + else + { + answer += border2; + surprisingTriplets -= border2; + border2 = 0; + } + + return answer; + } + +} +" +A21146,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package competition; + +/** + * + * @author Sriram + */ + +import java.util.Scanner; +import java.io.FileInputStream; +import java.io.PrintStream; + +public class DancingWithGooglers_GCJ_2012 { + + public static void main(String args[]) throws Exception + { + Scanner in = new Scanner(new FileInputStream(""f:\\input.in"")); + PrintStream out = new PrintStream(""f:\\output.out""); + int T = in.nextInt(); + for(int i=0;i1) + { + p1 = (3*p)-4; + p2 = p1+1; + } + else + { + p1 = p2 = p; + } + for(int j=0;j0);j++) + { + if(scores[j]==p1) + { + result++; + S--; + } + } + for(int j=0;(j0);j++) + { + if(scores[j]==p2) + { + result++; + S--; + } + } + for(int j=0;jp2) + { + result++; + } + } + if(p == 0) + result = scores.length; + out.printf(""Case #%d: %d\n"",(i+1),result); + + } + } +} +" +A22176,"import java.io.*; + +public class Dance { + public static void main(String[] args) { + try { + InputStreamReader inReader = new InputStreamReader(new FileInputStream(""input.txt"")); + BufferedReader br = new BufferedReader(inReader); + + File out = new File(""output.txt""); + Writer output = new BufferedWriter(new FileWriter(out)); + + int amount = Integer.parseInt(br.readLine()); + + for (int i=0; i < amount; i++) { + output.write(""Case #"" + (i+1) + "": ""); + String line = br.readLine(); + String[] values = line.split("" ""); + + int dancers = Integer.parseInt(values[0]); + int surprise = Integer.parseInt(values[1]); + int minPoints = Integer.parseInt(values[2]); + + int minResultSur = (minPoints-2)*2 + minPoints; + int minResult = (minPoints-1)*2 + minPoints; + int endResult = 0; + + minResultSur = (minResultSur < 0) ? minPoints : minResultSur; + minResult = (minResult < 0) ? minPoints : minResult; + + for (int j=0; j < dancers; j++) { + int tmpResult = Integer.parseInt(values[3+j]); + if (tmpResult >= minResult) + endResult++; + else if (tmpResult >= minResultSur && surprise > 0) { + surprise--; + endResult++; + } + } + + output.write(endResult + ""\n""); + } + + output.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +}" +A20219,"import java.util.Scanner; + +public class B2 { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int nbrCases = sc.nextInt(); + for (int i = 1; i <= nbrCases; ++i) { + sc.nextLine(); + System.out.print(""Case #"" + i + "": ""); + + int nbrGooglers = sc.nextInt(); + int nbrSurprising = sc.nextInt(); + int atLeast = sc.nextInt(); + + // The lowest value of a triplet which isn't surprising with + // at least N is a triplet with the values N, N-1 and N-1 + int lowestNonSurprisingSum = 3 * atLeast - 2; + // The lowest value of a triplet which is surprising with + // at least N is a triplet with the values N, N-2 and N-2 + int lowestSurprisingSum = 3 * atLeast - 4; + // Base cases + if (atLeast == 0) { + lowestNonSurprisingSum = 0; + lowestSurprisingSum = 0; + } else if (atLeast == 1) { + lowestNonSurprisingSum = 1; + lowestSurprisingSum = 1; + } + + int nbrNonSurprisingFound = 0; + int nbrSurprisingFound = 0; + for (int j = 0; j < nbrGooglers; ++j) { + int score = sc.nextInt(); + if (score >= lowestNonSurprisingSum) { + ++nbrNonSurprisingFound; + } else if (score >= lowestSurprisingSum) { + ++nbrSurprisingFound; + } + } + + int max = nbrNonSurprisingFound + Math.min(nbrSurprisingFound, nbrSurprising); + System.out.println(max); + } + } +} +" +A21008,"package fixjava; + +import java.util.ArrayList; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import fixjava.ParallelWorkQueue.CallableFactory; + + + +public class ParallelWorkQueueTest { + + /** + * @param args + */ + public static void main(String[] args) { + ArrayList inputs = new ArrayList(); + for (int i = 100; i < 120; i++) + inputs.add(i); + + ParallelWorkQueue.CallableFactory callableFactory = new CallableFactory() { + @Override + public Callable newInstance(final Integer input) { + return new Callable() { + @Override + public String call() throws Exception { + Thread.sleep((int) (Math.random() * 4000)); + System.out.println("" Input: "" + input); + return ""***"" + (input + 1); + } + }; + } + }; + + try { + for (Future result : new ParallelWorkQueue(4, inputs, callableFactory)) + System.out.println(""Got : "" + result.get()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + } +} +" +A21683,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Shell { + + private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + private static final String ERROR = ""Error!""; + + private static final String ERROR_INVALID_INT = + ""Ungueltige Integer-Zahl! (Nochmal eingeben) ""; + + private static int numberOfCases = Integer.MAX_VALUE; + + public static void main(String[] args) { + System.out.println(""Input integer!""); + numberOfCases = readInt(); + int x = 0; + while (x < numberOfCases) { + String[] tokens = getTokens(); + int n = Integer.parseInt(tokens[0]); + int s = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int[] googlers = new int[n]; + int index = 0; + while (index < n) { + googlers[index] = Integer.parseInt(tokens[index + 3]); + index++; + } + int y = judge(s, p, googlers); + x++; + System.out.println(""Case #"" + x + "": "" + y); + } + + } + + private static String[] getTokens() { + String line; + try { + line = in.readLine(); + } catch (IOException e) { + throw new Error(e); + } + if (line == null) { + System.err.println(ERROR); + return null; + } else { + return line.split(""\\s""); + } + } + + private static int readInt() { + while (true) { + for (String token : getTokens()) { + try { + return Integer.parseInt(token); + } catch (NumberFormatException e) { + System.err.println(ERROR_INVALID_INT); + } + } + } + } + + private static int judge(int s, int p, int[] googlers) { + int judgedPoint = 0; + int indexOfGooglers = 0; + int googlersLength = googlers.length; + while (indexOfGooglers < googlersLength) { + if (withoutSurprise(s, p, googlers[indexOfGooglers])) { + judgedPoint++; + } else if (needSurprise(s, p, googlers[indexOfGooglers])) { + s--; + judgedPoint++; + } + indexOfGooglers++; + } + + + return judgedPoint; + } + + private static boolean needSurprise(int s, int p, int googler) { + int surprisePointLeft = googler % 3; + int normalPoint = googler / 3; + if (normalPoint == 0 && surprisePointLeft == 0) { + return false; + } + int difference = p - normalPoint; + if (difference < 3 && surprisePointLeft == 2 && s > 0) { + return true; + } else if (difference < 2 && s > 0) { + return true; + } + + return false; + } + + private static boolean withoutSurprise(int s, int p, int googler) { + int surprisePointLeft = googler % 3; + int normalPoint = googler / 3; + int difference = p - normalPoint; + if (normalPoint >= p) { + return true; + } else if (difference < 2 && (surprisePointLeft == 2 || surprisePointLeft == 1)) { + return true; + } + + return false; + } + +} +" +A21988,"import java.util.Scanner; +public class Dancing { + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + int numCases = sc.nextInt(); + + for (int i = 0; i < numCases; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int S_counter = S; + int p = sc.nextInt(); + int numPassed = 0; + int minSurprise; + int minNoSurprise; + + //special cases + if (p == 0) { + minSurprise = 0; + minNoSurprise = 0; + } + else if (p == 1) { + minSurprise = 1; + minNoSurprise = 1; + } + else { + minSurprise = p + 2*(p - 2); + minNoSurprise = p + 2*(p - 1); + } + + if (minNoSurprise < 0) minNoSurprise = 0; + for (int j = 0; j < N; j++) { + int t = sc.nextInt(); + if (t < minSurprise) continue; + else if (t < minNoSurprise && + t >= minSurprise && + S_counter <= 0) continue; + else if (t < minNoSurprise && + t >= minSurprise && + S_counter > 0) { + numPassed++; + S_counter--; + } + else if (t >= minNoSurprise) + numPassed++; + else + System.out.println(""Something Broke""); + } + System.out.println(""Case #"" + (i + 1) + "": "" + numPassed); + } + } +} + " +A20128,"import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Scanner; +import java.util.Set; +import java.util.TreeSet; + +public class Main { + + class Pair { + int a; + int b; + + Pair(int a, int b) { + this.a = a; + this.b = b; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + getOuterType().hashCode(); + result = prime * result + a; + result = prime * result + b; + return result; + } + + @Override + public boolean equals(Object o) { + Pair second = (Pair) o; + if (second == null) { + return false; + } + return this.a == second.a && this.b == second.b || this.a == second.b && this.b == second.b; + } + + private Main getOuterType() { + return Main.this; + } + + } + + Scanner in; + PrintWriter out; + + void asserT(boolean e) { + if (!e) { + throw new Error(); + } + } + + int maxDigitAtSurprise[] = new int[31]; + int maxDigitAtNotSurprise[] = new int[31]; + + void solve() { + + for (int sum = 0; sum <= 30; sum++) { + for (int c = 0; c <= 10; c++) { + for (int p = 0; p <= 10; p++) { + if (2 * c + p + 1 == sum && c + 1 <= 10 && Math.abs(c - p) <= 1 && Math.abs(c + 1 - p) <= 1) { + maxDigitAtNotSurprise[sum] =Math.max(maxDigitAtNotSurprise[sum],Math.max(c + 1, p)); + } + if (3*c==sum){ + maxDigitAtNotSurprise[sum] =Math.max(maxDigitAtNotSurprise[sum],c); + } + } + } + for (int c = 0; c <= 10; c++) { + for (int p = 0; p <= 10; p++) { + if (2 * c + p + 2 == sum && c + 2 <= 10 && Math.abs(c - p) <= 2 && Math.abs(c + 2 - p) <= 2) { + maxDigitAtSurprise[sum] =Math.max( maxDigitAtSurprise[sum], Math.max(c + 2, p)); + } + } + } + } + int nTests = in.nextInt(); + for (int i = 1; i <= nTests; i++) { + out.println(""Case #"" + i + "": "" + solveOne()); + } + } + + long solveOne() { + int n = in.nextInt(); + int nSurp = in.nextInt(); + int minMax = in.nextInt(); + Set surpIds = new TreeSet(); + Set notSuriIds = new TreeSet(); + Set bad = new TreeSet(); + int cnt = 0; + int nums[] = new int[n]; + for (int i = 0; i < n; i++) { + nums[i] = in.nextInt(); + int sum = nums[i]; + if (maxDigitAtNotSurprise[sum] >= minMax && maxDigitAtSurprise[sum] >= minMax) { + cnt++; + }else if (maxDigitAtSurprise[sum]>=minMax){ + surpIds.add(i); + }else if (maxDigitAtNotSurprise[sum]>=minMax){ + notSuriIds.add(i); + }else{ + bad.add(i); + } + } + + cnt+=Math.min(surpIds.size(),nSurp )+notSuriIds.size(); + + return cnt; + + } + + void run() { + try { + in = new Scanner(new FileReader(""B-large.in"")); + // in = new Scanner(System.in); + out = new PrintWriter(""output.txt""); + } catch (Exception e) { + // TODO: handle exception + } + try { + solve(); + } finally { + out.close(); + } + } + + public static void main(String[] args) { + new Main().run(); + } +}" +A22151,"import java.util.LinkedList; + + +public class Triplet +{ + public Triplet() + { + + } + + public static int triplete(LinkedList t_i, int p, int s) + { + int res = 0; + int a,b,c; + + for(Integer i : t_i) + { + a = p; b = p-1; c = p-2; + if(a+b+c < i) + { + c++; + } + if(a+b+c < i) + { + b++; + } + if(a+b+c < i) + { + c++; + } + if(a+b+c > i) + { + b--; + } + while(a+b+c < i) + { + if(a+b+c < i) + { + b++; + } + if(a+b+c < i) + { + c++; + } + if(a+b+c < i) + { + a++; + } + } + + int prue = a + b + c; + if(a >= 0 && b >= 0 && c >= 0) + { + if(prue == i && a <= 10 && b <= 10 && c <= 10 && (a - b != 2 && a - c != 2 && b - c != 2)) + { + res++; + + } + else if(prue == i &&(a - b == 2 || a - c == 2 || b - c == 2) && s > 0) + { + res++; + s--; + } + } + + + } + + return res; + } +} +" +A21395," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException + { + Scanner scan = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new File(""out.txt"")); + + int cases = scan.nextInt(); + for (int r = 1; r <= cases; r++) + { + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + + int ok = 3 * p - 2; + int sur = Math.max(3 * p - 4, 1); + + int ret = 0; + int ss = 0; + for (int i = 0; i < n; i++) + { + int a = scan.nextInt(); + if (a >= ok) + ret++; + else if (a >= sur) + ss++; + } + + out.println(""Case #"" + r + "": "" + (ret + Math.min(s, ss))); + } + + out.close(); + scan.close(); + } + +} +" +A22764,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package google_code_jam; + + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +/** + * + * @author lenovo + */ +public class B { + + + public static void main(String[] args) throws IOException { + // TODO code application logic here + + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(""B.out"" ); + StringTokenizer st=new StringTokenizer(br.readLine()); + // System.out.println(st); + int x = Integer.parseInt(st.nextToken()); + a1:for (int i = 0; i < x; i++) { + st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken());// number of players + int s = Integer.parseInt(st.nextToken());//number of surprising + int p = Integer.parseInt(st.nextToken());// best degree required + int count=0;// + for (int j = 0; j < n; j++) { + int temp=Integer.parseInt(st.nextToken()); + int rem=temp%3; + int div=temp/3; + if(temp==0 && p!=0)continue; + else if(temp==0 && p==0){ + count++; + continue; + } + if(rem==0){ + if(div>=p){ + count++; + continue; + } + else if(div+1>=p && s>0){ + count++; + s--; + continue; + } + }// end of this condition + else{ + if(rem==1){ + if(div+1 >=p)count++; + } + else if(rem==2){ + if(div+1 >= p)count++; + else if (div+2 >=p && s>0){ + count++; + s--; + continue; + } + } + } + }// End of converting + pw.append(""Case #""+(i+1)+"": ""+count+""\n""); + } + pw.close(); + } + +} + +" +A20031,"import java.util.Scanner; + + +class DancingWithGooglers { + + Scanner s = new Scanner(System.in); + + public static void main(String args[]) { + DancingWithGooglers p = new DancingWithGooglers(); + p.run(); + } + + void run() { + prepare(); + int nCases = s.nextInt(); + for (int i=0; i= P) { + count++; + } else if (S>0 && mTable[score][1]>=P) { + count++; + S--; + } + } + return count; + } + +}" +A22937,"import java.util.Scanner; + +public class GooglerDance { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int size = in.nextInt(); + int count = 0; + while (count < size) { + int maxNum = 0; + int googlers = in.nextInt(); + int[][] judges = new int[googlers][3]; + int[] scores = new int[googlers]; + boolean[] ishigher = new boolean[googlers]; + int s = in.nextInt(); + int p = in.nextInt(); + for (int i = 0; i < scores.length; i++) {// getting scores + scores[i] = in.nextInt(); + } + // computing scores + for (int i = 0; i < scores.length; i++) { + int ceil = scores[i] / 3; + if ((scores[i] % 3) > 0) { + ceil++; + } + if (ceil >= p) { + ishigher[i] = true; + maxNum++; + } + if ((3 * ceil) == scores[i]) { + judges[i][0] = ceil; + judges[i][1] = ceil; + judges[i][2] = ceil; + if (!ishigher[i] && (p - ceil) == 1 && s > 0 + && (ceil - 1) > 0) { + judges[i][0] = ceil + 1; + judges[i][1] = ceil; + judges[i][2] = ceil - 1; + maxNum++; + s--; + } + } else if ((3 * ceil) == (scores[i] + 1)) { + judges[i][0] = ceil; + judges[i][1] = ceil; + judges[i][2] = ceil - 1; + if (!ishigher[i] && (p - ceil) == 1 && s > 0 + && (ceil - 1) > 0) { + judges[i][0] = ceil + 1; + judges[i][1] = ceil - 1; + judges[i][2] = ceil - 1; + maxNum++; + s--; + } + } else if ((3 * ceil) == (scores[i] + 2)) { + judges[i][0] = ceil; + judges[i][1] = ceil - 1; + judges[i][2] = ceil - 1; + + } else { + System.out.println(""Error in Algorithm""); + } + } + System.out.format(""Case #%d: %d\n"", count + 1, maxNum); + count++; + } + } +} +" +A22193,"import java.io.File; +import java.io.PrintWriter; +import java.util.*; +import java.util.jar.JarEntry; + +/** + * Created with IntelliJ IDEA. + * User: vitaly + * Date: 4/14/12 + * Time: 9:24 AM + * To change this template use File | Settings | File Templates. + */ +public class Main { + + public static Map createMap(int dif) { + Map map = new HashMap(); + for(int i = 0; i <= 10; i++) { + for(int j = 0; j <= 10; j++) { + for(int k = 0; k <= 10; k++) { + int min = Math.min(i, Math.min(j, k)); + int max = Math.max(i, Math.max(j, k)); + int sum = i + j + k; + if((max - min) <= dif) { + Integer val = map.get(sum); + if(val == null || val < max) { + map.put(sum, max); + } + } + } + } + } + return map; + } + + public static void main(String[] args) throws Exception { + + Map map1 = createMap(1); + Map map2 = createMap(2); + + + Scanner scanner = new Scanner(new File(""B-large.in"")); + PrintWriter pw = new PrintWriter(new File(""google.out"")); + + int n = scanner.nextInt(); + for(int i = 0; i < n; i++) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int count = 0; + for(int k = 0; k < N; k++) { + int sum = scanner.nextInt(); + if(map1.get(sum) >= p) { + count++; + } else if(map2.get(sum) >= p && S > 0) { + count++; + S--; + } + } + pw.print(String.format(""Case #%d: %d%n"", i + 1, count)); + } + + + scanner.close(); + pw.close(); + + + } + +} +" +A20873," +/** + * Name: Shivam99 + * email: shivthedestroyer99@gmail.com + */ + +import java.io.*; + +public class ProblemB +{ + public static void main(String[] args) throws IOException{ + FileReader fr=new FileReader(args[0]); + BufferedReader br=new BufferedReader(fr); + String str=br.readLine(); + int t=Integer.parseInt(str); + String ss=""""; + int c=1; + while(c<=t){ + str=br.readLine(); + int n=0,s=0,p=0,surp=0,count=0,ans=0; + int arr[]=new int[100]; + String word=""""; + + for(int ind=0;ind=p && arr[ind]>=min) + ans++; + if(arr[ind]==(min) || arr[ind]==(min+1)) + if(arr[ind]>1) + surp++; + } + + if(s normal; + private Map surprising; + private List normals; + public DancingGooglers() { + int i=0; + normal = new TreeMap(); + surprising = new TreeMap(); + normals = new ArrayList(); + normal.put(0, 0); + surprising.put(0, 0); + for(i=MIN_TOTAL+1;i<=MAX_TOTAL;i++) { + int base = i/3; + int mod = i%3; + List scores = new ArrayList(); + switch(mod) { + case 0: + scores.add(base); + normal.put(i, Collections.max(scores)); + scores.add(Math.max(0, base-1)); + scores.add(Math.min(10, base+1)); + surprising.put(i, Collections.max(scores)); + break; + case 1: + scores.add(base); + scores.add(Math.min(10, base+1)); + normal.put(i, Collections.max(scores)); + scores.add(Math.max(0, base-1)); + surprising.put(i, Collections.max(scores)); + break; + case 2: + scores.add(base+1); + scores.add(Math.max(0, base)); + normal.put(i, Collections.max(scores)); + scores.add(Math.min(10, base+2)); + surprising.put(i, Collections.max(scores)); + break; + } + if(surprising.get(i).equals(normal.get(i))) { + normals.add(i); + } + } + System.out.println(normal); + System.out.println(surprising); + System.out.println(normals); + } + public List surprising(List numbers, int p) { + List surprising = new ArrayList(); + for (Integer n : numbers) { + if(!normals.contains(n) && this.surprising.get(n)>=p && this.normal.get(n) numbers, int S, int p) { + int result = 0; + List listSS = surprising(numbers,p); + int SS = listSS.size(); + Iterator i = numbers.iterator(); + if(SS==S || S>SS) { // take all the surprising + while(i.hasNext()) { + int n = i.next(); + if(listSS.contains(n) && surprising.get(n)>=p) { + System.out.println(""score: ""+surprising.get(n)); + result++; + } + else if(normal.get(n)>=p) { + System.out.println(""score: ""+normal.get(n)); + result++; + } + else { + System.out.println(""score: ""+normal.get(n)); + } + } + } + else if(S=p) { + result++; + } + } + }else if(S==0) { // take all as normals + while(i.hasNext()) { + int n = i.next(); + if(normal.get(n)>=p) { + result++; + } + } + } + return result; + } + public static void main(String[] args) throws Exception { + DancingGooglers dg = new DancingGooglers(); + LineNumberReader in = new LineNumberReader(new FileReader(args[0]+"".in"")); + String line = null; + line = in.readLine(); + if(line==null||line.length()==0) + return; + int T = 0; + T = Integer.parseInt(line); + PrintStream out = new PrintStream(args[0]+"".out""); + for(int i=1; i<=T; i++){ + line = in.readLine(); + String[] data = line.split("" ""); + int N = Integer.valueOf(data[0]); + int S = Integer.valueOf(data[1]); + int p = Integer.valueOf(data[2]); + List numbers = new ArrayList(); + for(int j=0; j { + + @Override + public BOutputEntry produceOutput(BInput input) { + int avaragesAboveLimit = 0; + int avaragesBelowLimitIfTheyWereSuprising = 0; + for (int i = 0; i < input.getGooglerScores().length; i++) { + if (maximumNotSurprisingScoreOfTotalScore(input.getGooglerScores()[i]) >= input.getLimit()) { + avaragesAboveLimit++; + } else if (maximumSurprisingScoreOfTotalScore(input.getGooglerScores()[i]) >= input.getLimit()) { + avaragesBelowLimitIfTheyWereSuprising++; + } + } + BOutputEntry outputEntry = new BOutputEntry(); + outputEntry.setMaximumGooglersNumber(avaragesAboveLimit + + Math.min(avaragesBelowLimitIfTheyWereSuprising, input.getSurprisingTripletsNumber())); + return outputEntry; + } + + private int maximumNotSurprisingScoreOfTotalScore(int totalScore) { + if (totalScore % 3 == 0) { + return totalScore / 3; + } else { + return totalScore / 3 + 1; + } + } + + private int maximumSurprisingScoreOfTotalScore(int totalScore) { + int maximumNotSurprisingScoreOfTotalScore = maximumNotSurprisingScoreOfTotalScore(totalScore); + if (maximumNotSurprisingScoreOfTotalScore == 0) { + return maximumNotSurprisingScoreOfTotalScore; + } else { + return maximumNotSurprisingScoreOfTotalScore + 1; + } + } +} +" +A20537,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws FileNotFoundException { + Scanner scan = new Scanner(new File(""B-large.in"")); + System.setOut(new PrintStream(""B-large.out"")); + + int t = scan.nextInt(); + for (int c = 0; c < t; c++) { + int n = scan.nextInt(); // num + int s = scan.nextInt(); // surprising + int p = scan.nextInt(); // best result cutoff + int[] totalPoints = new int[n]; + for (int i = 0; i < n; i++) + totalPoints[i] = scan.nextInt(); + + int sUsed = 0; + int ans = 0; + for (int i = 0; i < n; i++) { + int pts = totalPoints[i]; + // can it be done normal? + if (pts >= p + (p - 1) * 2) + ans++; + // can it be done surp? + else if (pts >= p + Math.max(p - 2, 0) * 2) + if (sUsed < s) { + ans++; + sUsed++; + } + } + + System.out.printf(""Case #%d: %d%n"", c + 1, ans); + } + } +}" +A22156,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + try { + System.setIn(new FileInputStream(""../B-small-attempt0.in"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.exit(0); + } + + InputStreamReader inp = new InputStreamReader(System.in); + BufferedReader br = new BufferedReader(inp); + + String line = """"; + int inputs = 0; + + try{ + line = br.readLine(); + inputs = Integer.parseInt( line ); + } catch(Exception x){ + System.err.println(x); + System.exit(1); + } + + String[] stringdata = {}; + for(int i=0; i < inputs; i++){ + + try{ + line = br.readLine(); + stringdata = line.split("" ""); + } catch(Exception x){ + System.err.println(x); + System.exit(1); + } + + int[] data = new int[stringdata.length]; + for(int j=0; j < stringdata.length; j++){ + data[j] = Integer.parseInt(stringdata[j]); + } + + int n = data[0]; + int s = data[1]; + int p = data[2]; + int count = 0; + + for(int k=3; k < data.length; k++){ + + int score = data[k]; + //double x = Math.ceil(score / 3.0); + + if(score >= p && score >= (p*3)-2){ + count++; + } else if(score >= p && score >= (p*3)-4 && s > 0){ + s--; + count++; + } + } + + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } + +} +" +A20123,"import java.io.*; +import java.util.Scanner; +import java.util.Arrays; +import java.lang.StringBuilder; + + +public class B{ + //STAES3307 + + + public static void main(String[] args){ + //get the char value of 'a', use that to index into the letters array when replacing characters + try{ + //BufferedReader reader = new BufferedReader(new FileReader(new File(""A-small-attempt0.in""))); + Scanner scan = new Scanner(new File(""B-large.in"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""B.out""))); + int lines = scan.nextInt(); + for(int i = 0; i < lines; i++){ + //System.out.println(""Case "" + i); + int t = scan.nextInt(); + int s = scan.nextInt(); + int s_used = 0; + int p = scan.nextInt(); + int[] scores = new int[t]; + int count = 0; + for(int j = 0; j < t; j++){ + scores[j] = scan.nextInt(); + } + Arrays.sort(scores); + for(int j = t-1; j >= 0; j--){ + int score = scores[j]; + int maxPos = (int)Math.ceil(score/3) + 2; + //System.out.println(score + "" "" + maxPos); + // cases...list probably doesn't contain everything... + // not cleanest approach...obviously + + + if(maxPos - 2 >= p){ + if(3*maxPos == score || ((maxPos - 1 >= 0) && ((2*maxPos + (maxPos - 1)) == score || (maxPos + 2*(maxPos - 1)) == score || 3*(maxPos - 1) == score || ((maxPos - 2 >= 0) && ((2*(maxPos - 1) + (maxPos - 2)) == score || ((maxPos - 1) + 2*(maxPos - 2)) == score || 3*(maxPos -2) == score || (2*(maxPos - 2) + (maxPos - 3)) == score))))) count++; + else if(s_used < s){ + // score can be ""surprising"" + if((maxPos - 2 >= 0) && ((maxPos + (maxPos - 1) + (maxPos - 2)) == score || (maxPos + 2*(maxPos - 2)) == score || ((maxPos - 3 >= 0) && (((maxPos - 1) + 2*(maxPos - 3)) == score || (2*(maxPos - 1) + (maxPos - 3)) == score || ((maxPos - 1) + (maxPos - 2) + (maxPos - 3)) == score)))){ + count++; + s_used++; + } + + } + }else if(maxPos - 1 >= p){ + if(3*maxPos == score || ((maxPos - 1 >= 0) && ((2*maxPos + (maxPos - 1)) == score || (maxPos + 2*(maxPos - 1)) == score || 3*(maxPos - 1) == score || ((maxPos - 2 >= 0) && ((2*(maxPos - 1) + (maxPos - 2)) == score || ((maxPos - 1) + 2*(maxPos - 2)) == score))))) count++; + else if(s_used < s){ + // score can be ""surprising"" + if((maxPos - 2 >= 0) && ((maxPos + (maxPos - 1) + (maxPos - 2)) == score || (maxPos + 2*(maxPos - 2)) == score || ((maxPos - 3 >= 0) && (((maxPos - 1) + 2*(maxPos - 3)) == score || (2*(maxPos - 1) + (maxPos - 3)) == score || ((maxPos - 1) + (maxPos - 2) + (maxPos - 3)) == score)))){ + count++; + s_used++; + } + + } + /*if(3*maxPos == score || (2*maxPos + (maxPos - 1)) == score || (maxPos + 2*(maxPos - 1)) == score || 3*(maxPos - 1) == score || (2*(maxPos - 1) + (maxPos - 2)) == score || ((maxPos - 1) + 2*(maxPos - 2)) == score) count++; + else if(s_used < s){ + // score can be ""surprising"" + if((maxPos + (maxPos - 1) + (maxPos - 2)) == score || (maxPos + 2*(maxPos - 2)) == score || ((maxPos - 1) + 2*(maxPos - 3)) == score || (2*(maxPos - 1) + (maxPos - 3)) == score || ((maxPos - 1) + (maxPos - 2) + (maxPos - 3)) == score){ + count++; + s_used++; + } + + }*/ + }else if(maxPos >= p){ + if(3*maxPos == score || ((maxPos - 1 >= 0) && ((2*maxPos + (maxPos - 1)) == score || (maxPos + 2*(maxPos - 1)) == score))) count++; + else if(s_used < s){ + // score can be ""surprising"" + if((maxPos - 2 >= 0) && ((maxPos + (maxPos - 1) + (maxPos - 2)) == score || (maxPos + 2*(maxPos - 2)) == score)){ + count++; + s_used++; + } + + } + /*if(3*maxPos == score || (2*maxPos + (maxPos - 1)) == score || (maxPos + 2*(maxPos - 1)) == score) count++; + else if(s_used < s){ + // score can be ""surprising"" + if((maxPos + (maxPos - 1) + (maxPos - 2)) == score || (maxPos + 2*(maxPos - 2)) == score){ + count++; + s_used++; + } + + }*/ + } + + } + writer.write(""Case #"" + (i+1) + "": "" + count + ""\n""); + + } + writer.close(); + }catch(Exception e){e.printStackTrace();} + + + } + + +} +" +A21086,"package _2012.QualificationRound.B; + +import java.util.ArrayList; + +import Utils.InputFile; +import Utils.OutputFile; + +public class B { + + + + + + private static void solve(InputFile inputFile, OutputFile outputFile){ + + int nbCases = Integer.parseInt(inputFile.getNextLine()); + + for(int caseNumber = 0; caseNumber < nbCases; caseNumber++){ + String[] line = inputFile.getNextLine().split("" ""); + int nbGooglers = Integer.parseInt(line[0]); + int nbSurprising = Integer.parseInt(line[1]); + int noteSeuil = Integer.parseInt(line[2]); + int result = 0; + + for(int i = 3; i < 3+nbGooglers; i++){ + int totalNote = Integer.parseInt(line[i]); + int maxWithoutSurprise = -1; + int maxWithSurprise = -1; + + if(totalNote == 0){ + maxWithoutSurprise = 0; + maxWithSurprise = -1; + } + else if(totalNote == 1){ + maxWithoutSurprise = 1; + maxWithSurprise = -1; + } + else if(totalNote == 2){ + maxWithoutSurprise = 1; + maxWithSurprise = 2; + } + else if(totalNote == 3){ + maxWithoutSurprise = 1; + maxWithSurprise = 2; + } + else if(totalNote == 4){ + maxWithoutSurprise = 2; + maxWithSurprise = 2; + } + else if(totalNote == 5){ + maxWithoutSurprise = 2; + maxWithSurprise = 3; + } + else if(totalNote == 6){ + maxWithoutSurprise = 2; + maxWithSurprise = 3; + } + else if(totalNote == 7){ + maxWithoutSurprise = 3; + maxWithSurprise = 3; + } + else if(totalNote == 8){ + maxWithoutSurprise = 3; + maxWithSurprise = 4; + } + else if(totalNote == 9){ + maxWithoutSurprise = 3; + maxWithSurprise = 4; + } + else if(totalNote == 10){ + maxWithoutSurprise = 4; + maxWithSurprise = 4; + } + else if(totalNote == 11){ + maxWithoutSurprise = 4; + maxWithSurprise = 5; + } + else if(totalNote == 12){ + maxWithoutSurprise = 4; + maxWithSurprise = 5; + } + else if(totalNote == 13){ + maxWithoutSurprise = 5; + maxWithSurprise = 5; + } + else if(totalNote == 14){ + maxWithoutSurprise = 5; + maxWithSurprise = 6; + } + else if(totalNote == 15){ + maxWithoutSurprise = 5; + maxWithSurprise = 6; + } + else if(totalNote == 16){ + maxWithoutSurprise = 6; + maxWithSurprise = 6; + } + else if(totalNote == 17){ + maxWithoutSurprise = 6; + maxWithSurprise = 7; + } + else if(totalNote == 18){ + maxWithoutSurprise = 6; + maxWithSurprise = 7; + } + else if(totalNote == 19){ + maxWithoutSurprise = 7; + maxWithSurprise = 7; + } + else if(totalNote == 20){ + maxWithoutSurprise = 7; + maxWithSurprise = 8; + } + else if(totalNote == 21){ + maxWithoutSurprise = 7; + maxWithSurprise = 8; + } + else if(totalNote == 22){ + maxWithoutSurprise = 8; + maxWithSurprise = 8; + } + else if(totalNote == 23){ + maxWithoutSurprise = 8; + maxWithSurprise = 9; + } + else if(totalNote == 24){ + maxWithoutSurprise = 8; + maxWithSurprise = 9; + } + else if(totalNote == 25){ + maxWithoutSurprise = 9; + maxWithSurprise = 9; + } + else if(totalNote == 26){ + maxWithoutSurprise = 9; + maxWithSurprise = 10; + } + else if(totalNote == 27){ + maxWithoutSurprise = 9; + maxWithSurprise = 10; + } + else if(totalNote == 28){ + maxWithoutSurprise = 10; + maxWithSurprise = 10; + } + else if(totalNote == 29){ + maxWithoutSurprise = 10; + maxWithSurprise = -1; + } + else if(totalNote == 30){ + maxWithoutSurprise = 10; + maxWithSurprise = -1; + } + if(maxWithoutSurprise >= noteSeuil){ + result++; + } else if(maxWithSurprise >= noteSeuil && nbSurprising > 0){ + result++; + nbSurprising--; + } + + } + + + String resultString = """" + result; + + outputFile.writeResult(resultString); + + } + + + + + + } + + + + + + + + + + + + + + + + + + + + public static void main(String[] args) { + + InputFile inputFile = new InputFile(""B"", ""large""); + OutputFile outputFile = new OutputFile(inputFile); + solve(inputFile, outputFile); + outputFile.endFile(); + + } + + + +} +" +A22929,"package com.vp.fact; + +import com.vp.iface.Problem; +import com.vp.impl.DancingWithGooglers; +import com.vp.impl.SpeakGooglerese; + +public class SolutionFactory { + + public static Problem getInstance(int problem) + { + Problem s = null; + + switch(problem) + { + case 1: s= new SpeakGooglerese(); + break; + case 2: s= new DancingWithGooglers(); + break; + } + + return s; + } + + +} +" +A22741,"package GCJ_2012.QualifiactionRound; + +import java.io.*; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + static int[] scores; + static int p; + static int[][] dp; + static int inf = 10000000; + + public static int solve(int idx, int remSurprising) { + if (idx == scores.length) { + if (remSurprising == 0) + return 0; + return -inf; + } + if (dp[idx][remSurprising] != -1) + return dp[idx][remSurprising]; + if (scores[idx] % 3 == 0) { + if (remSurprising > 0 && scores[idx] / 3 != 0) { + int maxOpt1 = scores[idx] / 3 + 1; + int maxOpt2 = scores[idx] / 3; + int opt1, opt2; + if (maxOpt1 >= p) { + opt1 = 1 + solve(idx + 1, remSurprising - 1); + } else { + opt1 = solve(idx + 1, remSurprising - 1); + } + if (maxOpt2 >= p) { + opt2 = 1 + solve(idx + 1, remSurprising); + } else { + opt2 = solve(idx + 1, remSurprising); + } + return dp[idx][remSurprising] = Math.max(opt1, opt2); + } else { + int max = scores[idx] / 3; + if (max >= p) { + return dp[idx][remSurprising] = 1 + solve(idx + 1, + remSurprising); + } else { + return dp[idx][remSurprising] = solve(idx + 1, + remSurprising); + } + } + } else if (scores[idx] % 3 == 1) { + if (remSurprising > 0 && scores[idx] / 3 != 0) { + int maxOpt1 = scores[idx] / 3 + 1; + int maxOpt2 = scores[idx] / 3 + 1; + int opt1, opt2; + if (maxOpt1 >= p) { + opt1 = 1 + solve(idx + 1, remSurprising - 1); + } else { + opt1 = solve(idx + 1, remSurprising - 1); + } + if (maxOpt2 >= p) { + opt2 = 1 + solve(idx + 1, remSurprising); + } else { + opt2 = solve(idx + 1, remSurprising); + } + return dp[idx][remSurprising] = Math.max(opt1, opt2); + } else { + int max = scores[idx] / 3 + 1; + if (max >= p) { + return dp[idx][remSurprising] = 1 + solve(idx + 1, + remSurprising); + } else { + return dp[idx][remSurprising] = solve(idx + 1, + remSurprising); + } + } + } else { + if (remSurprising > 0) { + int maxOpt1 = scores[idx] / 3 + 2; + int maxOpt2 = scores[idx] / 3 + 1; + int opt1, opt2; + if (maxOpt1 >= p) { + opt1 = 1 + solve(idx + 1, remSurprising - 1); + } else { + opt1 = solve(idx + 1, remSurprising - 1); + } + if (maxOpt2 >= p) { + opt2 = 1 + solve(idx + 1, remSurprising); + } else { + opt2 = solve(idx + 1, remSurprising); + } + return dp[idx][remSurprising] = Math.max(opt1, opt2); + } else { + int max = scores[idx] / 3 + 1; + if (max >= p) { + return dp[idx][remSurprising] = 1 + solve(idx + 1, + remSurprising); + } else { + return dp[idx][remSurprising] = solve(idx + 1, + remSurprising); + } + } + } + } + + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(new FileReader(""C:/Users/Mostafa/Downloads/B-large.in"")); + //Scanner sc = new Scanner(System.in); + FileWriter fw = new FileWriter(""D:/output.txt""); + PrintWriter out = new PrintWriter(System.out); + int cases = sc.nextInt(); + for (int i = 0; i < cases; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + p = sc.nextInt(); + scores = new int[N]; + for (int j = 0; j < N; j++) { + scores[j] = sc.nextInt(); + } + dp = new int[N][S + 1]; + for (int j = 0; j < N; j++) + Arrays.fill(dp[j], -1); + int res = solve(0, S); + fw.write(""Case #"" + (i + 1) + "": "" + res + ""\n""); + out.print(""Case #"" + (i + 1) + "": "" + res + ""\n""); + } + fw.flush(); + out.flush(); + } +} +" +A21936,"package jp.funnything.competition.util; + +import java.util.Arrays; +import java.util.List; + +import com.google.common.collect.Lists; +import com.google.common.primitives.Ints; +import com.google.common.primitives.Longs; + +public class Prime { + public static class PrimeData { + public int[] list; + public boolean[] map; + + private PrimeData( final int[] values , final boolean[] map ) { + list = values; + this.map = map; + } + } + + public static long[] factorize( long n , final int[] primes ) { + final List< Long > factor = Lists.newArrayList(); + + for ( final int p : primes ) { + if ( n < p * p ) { + break; + } + + while ( n % p == 0 ) { + factor.add( ( long ) p ); + n /= p; + } + } + + if ( n > 1 ) { + factor.add( n ); + } + + return Longs.toArray( factor ); + } + + public static PrimeData prepare( final int n ) { + final List< Integer > primes = Lists.newArrayList(); + + final boolean[] map = new boolean[ n ]; + Arrays.fill( map , true ); + + map[ 0 ] = map[ 1 ] = false; + + primes.add( 2 ); + for ( int composite = 2 * 2 ; composite < n ; composite += 2 ) { + map[ composite ] = false; + } + + for ( int value = 3 ; value < n ; value += 2 ) { + if ( map[ value ] ) { + primes.add( value ); + for ( int composite = value * 2 ; composite < n ; composite += value ) { + map[ composite ] = false; + } + } + } + + return new PrimeData( Ints.toArray( primes ) , map ); + } +} +" +A23019,"package tr0llhoehle.cakemix.googleCodejam; + +import tr0llhoehle.cakemix.utility.googleCodeJam.Solver; + +public class DWGSolver implements Solver { + + @Override + public String solve(DWGProblem p) { + int numberOfBestResult = 0; + int surprising = 0; + + /* + * for (int sum : p.getDancerSums()) { int[] triplet = new int[3]; + * boolean done = false; int remainder = sum % 3; + * + * for (int i : triplet) { i = sum / 3; + * + * if (remainder > 0) { i++; remainder--; } // not-surprising triplets + * generated. + * + * if (i >= p.getBorder()) { numberOfBestResult++; done = true; break; } + * } + * + * if (!done && sum > 1 && surprising < p.getNumberOfSuprisingTriplets() + * && triplet[0] + 1 >= p.getBorder()) { numberOfBestResult++; + * surprising++; + * + * } } + */ + + for (int sum : p.getDancerSums()) { + int avg = sum / 3; + int remainder = sum % 3; + + if (sum == 0) { + if (p.getBorder() <= 0) { + numberOfBestResult++; + } + } else if (sum == 1) { + if (p.getBorder() <= 1) { + numberOfBestResult++; + } + } else { // sum >= 2 + switch (remainder) { + case 0: + if (avg >= p.getBorder()) { + numberOfBestResult++; + } else if (surprising < p.getNumberOfSuprisingTriplets() + && avg + 1 >= p.getBorder()) { + numberOfBestResult++; + surprising++; + } + break; + case 1: + if (avg + 1 >= p.getBorder()) { + numberOfBestResult++; + } + break; + case 2: + if (avg + 1 >= p.getBorder()) { + numberOfBestResult++; + } else if (surprising < p.getNumberOfSuprisingTriplets() + && avg + 2 >= p.getBorder()) { + numberOfBestResult++; + surprising++; + } + break; + } + } + } + + return numberOfBestResult + """"; + } +} +" +A22081,"import java.util.Scanner; + + +public class B { + + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int i = 0; i < T ; i++) + { + int N = sc.nextInt(); + int S = sc.nextInt(); + int P = sc.nextInt(); + int tCounter = 0; + int tCount = 0; + + for (int j = 0; j < N; j++) + { + int num = sc.nextInt(); + if (num >= P * 3 -2 ) + { + tCount ++; + } + else if ((P * 3)-num > 4) + { + continue; + } + else + { + if(num == 0 || tCounter == S) + continue; + else + { + tCount ++; + tCounter ++; + } + } + } + System.out.format(""Case #%d: %d\n"",i+1,tCount); + } + + } + +} +" +A22410,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class google_2 { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + FileInputStream fstream = new FileInputStream(""D:/Rilsikane/Google2/src/B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + String s=""""; + while ((strLine = br.readLine()) != null) { + s+=(strLine); + s+=""\n""; + } + String x =""2 1 1 8 0""; + compute(s); + } + + + public static void compute(String x) throws IOException{ + String temp[] = x.split(""\n""); + + int size = Integer.parseInt(temp[0]); + FileWriter fstream = new FileWriter(""D:/Rilsikane/Google2/src/B-large_output.txt""); + BufferedWriter out = new BufferedWriter(fstream); + for(int k=1;k<=size;k++){ + int result = 0; + int n = 0; + int s = 0; + int p = 0; + int[] score = new int[10]; + for(int j=0;j= p) { + result++; + } else { + if (s > 0 && base > 0 && (base + 1) >= p) { + s--; + result++; + } + } + break; + case 1: + + if (base >= p || base + 1 >= p) { + result++; + } else { + if (p > 0 && (base + 1) >= p) { + s--; + result++; + } + } + + break; + case 2: + + if (base >= p || base + 1 >= p) { + result++; + } else { + if (s > 0 && (base + 2) >= p) { + s--; + result++; + } + } + break; + } + index++; + } +// System.out.println(""Result: "" + result); + + return result; + } + +} +" +A22036,"import java.io.*; + +public class Main { + + static private int getNonSuprising(int sum) { + if (sum == 0) return 0; + int ret = (int) Math.floor((double) (sum+2) /3); + + if (ret <= 10) return ret; + else return 10; + } + + static private int getSuprising(int sum) { + if (sum == 0) return 0; + if (sum == 1) return 1; + int ret = (int) Math.ceil( (double) (sum-1) / 3) + 1; + + if (ret <= 10) return ret; + else return 10; + } + + static private int handleCase(String line) { + String[] tokens = line.split("" ""); + int[] values = new int[tokens.length]; + + for (int i=0; i < tokens.length; i++) { + values[i] = Integer.parseInt(tokens[i]); + } + + int n = values[0]; + int s = values[1]; + int p = values[2]; + + int count = 0; + for (int j=0;j= p) + count++; + else if (suprising >= p && s > 0) { + s--; + count++; + } + + } + + return count; + } + + static public void main(String args[]) { + + try{ + FileWriter fstream = new FileWriter(""output.out""); + BufferedWriter out = new BufferedWriter(fstream); + + try { + BufferedReader input = new BufferedReader(new FileReader(new File(args[0]))); + try { + String line = null; + + line = input.readLine(); + int count = Integer.parseInt(line); + + for (int i =0; i= 2? 1: 0][c >= p? 1: 0] = true; + } + } + } + } + int dp[] = new int[m + 1]; + for (int j = 1; j <= m; ++ j) { + dp[j] = Integer.MIN_VALUE; + } + for (int i = 0; i < n; ++ i) { + int ti = nextInt(); + int dp2[] = new int[m + 1]; + for (int j = 0; j <= m; ++ j) { + dp2[j] = Integer.MIN_VALUE; + for (int x = 0; x < 2; ++ x) { + for (int y = 0; y < 2; ++ y) { + if (v[ti][x][y] && j >= x) { + dp2[j] = Math.max(dp2[j], dp[j - x] + y); + } + } + } + } + dp = dp2; + } + System.out.printf(""Case #%d: %d\n"", test, dp[m]); + } + } catch (Exception e) { + } + } + + String nextToken() throws IOException { + while (!tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + return tokenizer.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + public static void main(String args[]) { + new Thread(new Main()).run(); + } +} +" +A20412,"package MyAllgoritmicLib; + +public class Hungary { + + int INF = 1000*1000*1000; + + int n; + int[][] a; + int[] xy, yx; + boolean[] vx, vy; + int[] minrow, mincol; + + public Hungary(int[][] a) { + // TODO Auto-generated constructor stub + this.a = a.clone(); + } + + private boolean dotry (int i) { + if (vx[i]) return false; + vx[i] = true; + for (int j=0; j1) + surprise++; + } + if(surprise>=S) + if(normal+S>N) + total=N; + else + total=normal+S; + else + total=normal+surprise; + + + es.println(total); + } + es.close(); + } + catch(FileNotFoundException error) + { + System.out.println(""no se encuentra el archivo""); + } + catch (EOFException e) + { + System.out.println(""Final de Stream""); + } + + } +}" +A22228,"package teardrop.jam2012.qr.dancing; + +import java.io.IOException; +import java.io.Reader; +import java.io.StreamTokenizer; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +public class CaseSolver { + private final Reader reader; + private final Writer writer; + + public CaseSolver(Reader reader, Writer writer) { + this.reader = reader; + this.writer = writer; + } + + public void solve() throws IOException { + StreamTokenizer tokenizer = new StreamTokenizer(reader); + + int tokenType = tokenizer.nextToken(); + assert tokenType == StreamTokenizer.TT_NUMBER; + int googlersCount = (int) tokenizer.nval; + + tokenType = tokenizer.nextToken(); + assert tokenType == StreamTokenizer.TT_NUMBER; + int surprisingTripletCount = (int) tokenizer.nval; + + tokenType = tokenizer.nextToken(); + assert tokenType == StreamTokenizer.TT_NUMBER; + int minimalGoodScore = (int) tokenizer.nval; + + int goodScores = 0; + int possiblyGoodScores = 0; + for (int i = 0; i < googlersCount; i++) { + tokenType = tokenizer.nextToken(); + assert tokenType == StreamTokenizer.TT_NUMBER; + int totalScore = (int) tokenizer.nval; + + int maxNonSurprisingScore = (totalScore + 2) / 3; + if (maxNonSurprisingScore >= minimalGoodScore) { + goodScores++; + } else { + int maxSurprisingScore = totalScore == 0 ? 0 : (totalScore + 4) / 3; + if (maxSurprisingScore >= minimalGoodScore) { + possiblyGoodScores++; + } + } + } + + int answer = goodScores + Math.min(possiblyGoodScores, surprisingTripletCount); + writer.write(String.valueOf(answer)); + } +} +" +A22697,"import static java.lang.Double.parseDouble; +import static java.lang.Integer.parseInt; +import static java.lang.Long.parseLong; +import static java.lang.System.exit; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class B { + + static BufferedReader in; + static PrintWriter out; + static StringTokenizer tok; + static int test; + + static void solve() throws Exception { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int ans = 0; + for (int i = 0; i < n; i++) { + int t = nextInt(); + if ((t + 2) / 3 >= p) { + ++ans; + } else if (s > 0 && t > 0 && (t + 4) / 3 >= p) { + --s; + ++ans; + } + } + printCase(); + out.println(ans); + } + + static void printCase() { + out.print(""Case #"" + test + "": ""); + } + + static void printlnCase() { + out.println(""Case #"" + test + "":""); + } + + static int nextInt() throws IOException { + return parseInt(next()); + } + + static long nextLong() throws IOException { + return parseLong(next()); + } + + static double nextDouble() throws IOException { + return parseDouble(next()); + } + + static String next() throws IOException { + while (tok == null || !tok.hasMoreTokens()) { + tok = new StringTokenizer(in.readLine()); + } + return tok.nextToken(); + } + + public static void main(String[] args) { + try { + in = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(new OutputStreamWriter(System.out)); + int tests = nextInt(); + for (test = 1; test <= tests; test++) { + solve(); + } + in.close(); + out.close(); + } catch (Throwable e) { + e.printStackTrace(); + exit(1); + } + } +}" +A20189,"package com.kingter; + +import java.io.FileReader; +import java.io.LineNumberReader; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class GoogleDancer { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + //read + List resultList = new ArrayList(); + +// LineNumberReader lin = new LineNumberReader(new FileReader(""./B-small-attempt0.in"")); + LineNumberReader lin = new LineNumberReader(new FileReader(""./B-large.in"")); + + String line = null; + while ((line = lin.readLine()) != null) { + System.out.println(""Process #""+lin.getLineNumber()+"":""+line); + if (lin.getLineNumber() == 1) continue; + String[] testCaseStr = line.split("" ""); + int N = Integer.parseInt(testCaseStr[0]); + int S = Integer.parseInt(testCaseStr[1]); + int p = Integer.parseInt(testCaseStr[2]); + + List tl = new ArrayList(testCaseStr.length - 3); + for (int i = 3; i < testCaseStr.length; i++) { + tl.add(Integer.parseInt(testCaseStr[i])); + } + resultList.add(count(N, S, p, tl)); + + } + + //write + +// PrintWriter out = new PrintWriter(""./B-small-attempt0.out""); + PrintWriter out = new PrintWriter(""./B-large.out""); + try{ + int i = 1; + for (Iterator it = resultList.iterator(); it.hasNext();) { + int count = it.next(); + System.out.println(""Case #""+i+"": ""+count); + out.println(""Case #""+i+"": ""+count); + i++; + } + } finally { + out.close(); + } + + } + public static int count(int N, int S, int p, List tl) { + System.out.print(""N=""+N+"",""); + System.out.print(""S=""+S+"",""); + System.out.println(""p=""+p+"",""); + System.out.println(""tl=""+tl); + + //count + int count = 0; + int best = Math.max(S, (p * 3) - 2); + int supBest = Math.max(S, best -2); + + for (Iterator it = tl.iterator(); it.hasNext();) { + int result = it.next(); + if (result >= best) { + count++; + continue; + } + if (result >= supBest && S >= 1) { + count++; + S--; + } + } + System.out.println(""count=""+count); + + return count; + } + +} +" +A22536,"import java.io.FileInputStream; +import java.util.*; +import java.math.*; + +public class Main { + + public static void main(String[] args) throws Exception{ + Scanner scan = new Scanner(System.in); + //Scanner scan = new Scanner(new FileInputStream(""C:\\Users\\wd\\Desktop\\"")); + char[] map = ""yhesocvxduiglbkrztnwjpfmaq"".toCharArray(); + int taskCount = scan.nextInt(); + scan.nextLine(); + for (int taskIndex = 1; taskIndex <= taskCount; taskIndex++) { + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int result = 0; + for (int i = 0; i < N; i++) { + int val = scan.nextInt(); + if (val < 3 * p - 4) { + continue; + } + else if (val >= 3 * p - 2) { + result++; + } + else if (val >= p) { + if (S > 0) { + result++; + S--; + } + } + } + System.out.println(""Case #"" + taskIndex + "": "" + result); + } + } +}" +A20837,"import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Collections; +import java.util.HashMap; + + +public class tongue { + + static HashMap translationMap = new HashMap(); + private static void init() { + translationMap.put(""a"", ""y""); + translationMap.put(""b"", ""h""); + translationMap.put(""c"", ""e""); + translationMap.put(""d"", ""s""); + translationMap.put(""e"", ""o""); + translationMap.put(""f"", ""c""); + translationMap.put(""g"", ""v""); + translationMap.put(""h"", ""x""); + translationMap.put(""i"", ""d""); + translationMap.put(""j"", ""u""); + translationMap.put(""k"", ""i""); + translationMap.put(""l"", ""g""); + translationMap.put(""m"", ""l""); + translationMap.put(""n"", ""b""); + translationMap.put(""o"", ""k""); + translationMap.put(""p"", ""r""); + translationMap.put(""q"", ""z""); + translationMap.put(""r"", ""t""); + translationMap.put(""s"", ""n""); + translationMap.put(""t"", ""w""); + translationMap.put(""u"", ""j""); + translationMap.put(""v"", ""p""); + translationMap.put(""w"", ""f""); + translationMap.put(""x"", ""m""); + translationMap.put(""y"", ""a""); + translationMap.put(""z"", ""q""); + translationMap.put("" "", "" ""); + + } + /** + * @param args + */ + public static void main(String[] args) { + init(); + String inputFilePath = args[0]; + try { + File inputFile = new File(inputFilePath); + FileInputStream fis = new FileInputStream(inputFile); + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + +// translate(br); + findScore(br); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private static void findScore(BufferedReader br) throws NumberFormatException, IOException { + String line = null; + Integer numberOfLines = Integer.valueOf(br.readLine()); + if( !(1<=numberOfLines && numberOfLines<=100)){ + throw new IllegalArgumentException(""Not valid number of lines""); + } + + for(int i=1; i<=numberOfLines; i++){ + line = br.readLine(); + String[] values = line.split("" ""); + + + int res = computeResult(values); // line.substring(5).trim()); + System.out.println(""Case #""+i+"": "" +res); + } + + } + + + private static int computeResult(String[] values) { + int peopleCount = Integer.valueOf(values[0].trim()); + int surprisingCount = Integer.valueOf(values[1].trim()); + int minScore = Integer.valueOf(values[2].trim()); + + int foundCases =0; + for (int i=3; i=minScore){ + foundCases++; + } + else if(surprisingCount>0 && base>0 && base+1>=minScore){ + surprisingCount--; + foundCases++; + } + break; + case 1: + // normal case + if(base>=minScore || (base+1)>=minScore){ + foundCases++; + } + // suprise use case + else if(surprisingCount>0 && (base+1)>=minScore){ + foundCases++; + surprisingCount--; + } + break; + case 2: + // normal case + if(base>=minScore || (base+1)>=minScore){ + foundCases++; + } + // surprise case + else if(surprisingCount>0 && (base+2)>=minScore){ + foundCases++; + surprisingCount--; + } + break; + } + + } + return foundCases; + } + + + private static void translate(BufferedReader br) throws IOException { + String line = null; + StringBuffer result = new StringBuffer(); + Integer numberOfLines = Integer.valueOf(br.readLine()); + if( !(1<=numberOfLines && numberOfLines<=30)){ + throw new IllegalArgumentException(""Not valid number of lines""); + } + for(int i=1; i<=numberOfLines; i++){ + line = br.readLine(); + result.append(translateLine(line)); + System.out.println(""Case #""+i+"": "" +result); + result = new StringBuffer(); + } + } + + private static StringBuffer translateLine(String line) { + StringBuffer translatedLine = new StringBuffer(); + for (int i=0; i < line.length(); i++) { + translatedLine.append(translateChar(line.charAt(i))); + } + return translatedLine; + } + + private static String translateChar(char charAt) { + return translationMap.get(new Character(charAt).toString()); + } + +} +" +A21517,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + + +public class Googlers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + BufferedReader read=new BufferedReader(new InputStreamReader(System.in)); + String l; + l=read.readLine(); + int a=Integer.parseInt(l); + for (int i = 0; i < a; i++) { + Scanner scn=new Scanner(read.readLine()); + int n=scn.nextInt(); + int s=scn.nextInt(); + int p=scn.nextInt(); + int sum=0; + for (int j = 0; j < n; j++) { + int m=scn.nextInt(); + if(m >= p+Math.max(0,(p-1)+(p-1))) + { + sum++; + //System.out.println(m+""..""); + }else{ + if(s>0) + { + if(m>=p+Math.max(0,(p-2)+(p-2))) + { + s--; + sum++; + //System.out.println(m+"" ""+p); + } + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+sum); + } + } + +} +" +A22524,"import util.Runner; + + +public class DancingWithTheGooglers extends Runner{ + + @Override + public String dealWithCase(String line) { + String[] splits = line.split("" "", -1); + int noOfDancers = Integer.parseInt(splits[0]); + int noOfSurprises = Integer.parseInt(splits[1]); + int minimumScore = Integer.parseInt(splits[2]); + int needSurpriseMinimum = minimumScore * 3 - 4; + int noNeedForSurpriseMinimum = minimumScore * 3 - 2; + if (minimumScore == 0) { + needSurpriseMinimum = 0; + noNeedForSurpriseMinimum = 0; + } else if (minimumScore == 1) { + needSurpriseMinimum = 1; + noNeedForSurpriseMinimum = 1; + } + int needSurpriseCount = 0; + int noNeedForSurpriseCount = 0; + for (int i=3;i= noNeedForSurpriseMinimum) { + noNeedForSurpriseCount++; + } else if (currentTotal >= needSurpriseMinimum) { + needSurpriseCount++; + } + } + int result = noNeedForSurpriseCount + (noOfSurprises < needSurpriseCount ? noOfSurprises : needSurpriseCount); + return String.valueOf(result); + } + + public static void main(String[] args) throws Exception { + DancingWithTheGooglers runner = new DancingWithTheGooglers(); + runner.run(args); + } + +} +" +A22991,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package IO; + +import java.util.HashSet; +import java.util.Iterator; + +/** + * + * @author dannocz + */ +public class Googler { + + private int score; //A score per googler + private HashSet triplets; //A set of triplets per score + private int surprisedCases; + + public Googler(int score, int surprisedCases) { + this.score = score; + this.surprisedCases=surprisedCases; + this.triplets= new HashSet(); + } + + public void addTriplet(Triplet triplet) + { + triplets.add(triplet); + } + + public boolean result(int p){ + Iterator iterator=triplets.iterator(); + + while (iterator.hasNext()) { + Triplet triplet = (Triplet)iterator.next(); + if(triplet.compliesWithP(p) && triplet.surprised()) + return true; + } + + iterator=triplets.iterator(); + while (iterator.hasNext()) { + Triplet triplet = (Triplet)iterator.next(); + if(triplet.compliesWithP(p) && !triplet.surprised() && surprisedCases>0) + { + surprisedCases--; + return true; + } + } + return false; + } + + public int getScore() { + return score; + } + + public void setScore(int score) { + this.score = score; + } + + public HashSet getTriplets() { + return triplets; + } + + public void setTriplets(HashSet triplets) { + this.triplets = triplets; + } + + +} +" +A21398," import java.util.*; + import java.io.*; + public class Dancing + { + public static void main(String[] args) + { + try + { + Scanner scan = new Scanner(new File(""Dancing.in"")); + int x = Integer.parseInt(scan.nextLine()); + for(int y=0;y=3*c-2) + total++; + else if(temp>=3*c-4 && temp != 0) + { + if(b>0) + { + b--; + total++; + } + } + } + return total; + } + }" +A20452,"import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +public class SolutionDance { + static DataInputStream in = new DataInputStream(new BufferedInputStream(System.in)); + static BufferedReader din = new BufferedReader( new InputStreamReader(in)); + public static void main(String args[]){ + int t = parseInt(getLine()); + String[] g = new String[t]; + int n, s, p; int [] part; String out = ""Case #""; + + for(int i = 0;i=0){ + if(2*p-part[q] <=2){ + count++; + }else{ + if(2*p-part[q] <=4){ + if(s>0){ + s--; + count++; + } + } + } + } + } + out = out+(i+1)+"": "" +count; + soutln(out); + } + } + + private static int[] getPart(String[] spl, int n, int p) { + int [] part = new int [n]; + for(int i = 0;i= 3*p) + { + maxResult++; + } + else if(scores[i] < p) + { + continue; + } + else if((scores[i]>=(3*p - 2)) && (scores[i]<= (3*p -1))) + { + maxResult++; + } + else if((scores[i]>=(3*p - 4)) && (3*p - 4) > 0) + { + if(numSuprising > 0) + { + maxResult ++; + numSuprising--; + } + } + else + { + continue; + } + } + System.out.println(""Case #""+index+"": ""+maxResult); + out.write(""Case #""+index+"": ""+"" ""+maxResult); + out.newLine(); + out.flush(); + } + + } + +} +" +A20351,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DancingWithTheGooglers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + + BufferedReader reader = new BufferedReader(new FileReader(new File(""B-large.in""))); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""out""))); + + int T = Integer.parseInt(reader.readLine()); + + for(int i = 0;i= not_sp){ + result ++; + } + else if(num >= sp_down&&num<=sp_up&&num>=p){ + if(S>0){ + result ++; + S--; + } + } + } + + writer.write(""Case #""+(i+1)+"": ""+result+""\n""); + writer.flush(); + } + + + } + +} +" +A22990,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package exercises; + +import IO.Input; + +/** + * + * @author dannocz + */ +public class Exercise2 { + public static void run(Input input){ + +// for (String st : input.getTestCases()) { +// input.addResultCase(Parser.parse(st)); +// } +// + input.printResultCases(); + + + } +} +" +A21564," +import java.io.BufferedInputStream; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.Writer; + +public class ProblemB { + + public static void main(String[] args) { + try { + File input = new File(""B-small-attempt1.in""); + Writer fin = null; + File output = new File(""b2.txt""); + fin = new BufferedWriter(new FileWriter(output)); + FileInputStream fis = null; + BufferedInputStream bis = null; + DataInputStream dis = null; + String out = """"; + fis = new FileInputStream(input); + bis = new BufferedInputStream(fis); + dis = new DataInputStream(bis); + int t = Integer.parseInt(dis.readLine()); + for (int i = 0; i < t; i++) { + out += ""Case #"" + (i + 1) + "": ""; + String h = dis.readLine(); + String[] a = h.split("" ""); + int result = 0; + int n = Integer.parseInt(a[0]); + int s = Integer.parseInt(a[1]); + int p = Integer.parseInt(a[2]); + for (int j = 3; j < a.length; j++) { + int v1 = Integer.parseInt(a[j]); + int v2 = v1 / 3; + int v3 = v1 % 3; + if ((v2 >= p) || (v3 >= 1 && v2 + 1 >= p)) { + result++; + } else if (v3 == 2 && v2 + 2 >= p && s > 0) { + result++; + s--; + } else if (v3 == 0 && v2 > 0 && v2 + 1 >= p && s > 0) { + result++; + s--; + } + } + out += result; + fin.write(out); + out = ""\n""; + } + fis.close(); + bis.close(); + dis.close(); + fin.close(); + } catch (Exception ex) { + } + } +} +" +A22210,"package gcj.main; + +import java.io.BufferedReader; +import java.io.BufferedWriter; + +public interface Case { + + public void init(int caseNum, BufferedReader br) throws Exception; + + public void solve() throws Exception; + + public void generateOutput(BufferedWriter bw, boolean needBR) throws Exception; + +} +" +A20298,"package googlecodejam; + +import java.util.ArrayList; + +/** + * + * @author Matej + */ +public class ProblemB { + + int googlers; + int surprises; + int targetScore; + ArrayList scores = new ArrayList<>(); + + public ProblemB(int g, int s, int t, ArrayList l) { + googlers = g; + surprises = s; + scores = l; + targetScore = t; + } + + public int solve() { + int result = 0; + for (int score : scores) { + int last2scores = score - targetScore; + if (last2scores >= 0) { + if (last2scores >= (targetScore - 1) * 2) { + result++; + } else if (surprises > 0 && last2scores >= (targetScore - 2) * 2) { + surprises--; + result++; + } + } + } + + return result; + } +} +" +A22484,"import java.util.*; +import java.io.*; + +public class Googlers { + public static void main(String[] args) throws IOException { + BufferedReader f = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""Googlers_large.out""))); + StringTokenizer st; + + st = new StringTokenizer(f.readLine()); + + int T = Integer.parseInt(st.nextToken()); + + int N, S, p; + int i, j; + int tempTotal; + int[] result = new int[T]; + for(i = 0; i< T; i++) { + st = new StringTokenizer(f.readLine()); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + for(j = 0; j < N; j++) { + tempTotal = Integer.parseInt(st.nextToken()); + if(tempTotal >= (3 * p - 2)) + result[i]++; + else if(tempTotal >= p + 2*Math.max(p - 2, 0)) { + if(S > 0) { + result[i]++; + S--; + } + } + } + } + + for(i = 0; i < T; i++) { + out.println(""Case #"" + (i + 1) + "": "" + result[i]); + } + + out.close(); + } +} +" +A21681,"import java.util.*; +import java.io.*; + +public class DancingWithGooglers { + public void translate() throws Exception { + Scanner sc = new Scanner(new FileReader(""C:\\Users\\i047312\\Desktop\\B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""C:\\Users\\i047312\\Desktop\\output_large_B.txt"")); + //Translator + int t = sc.nextInt(); + for (int i = 0; i < t; i++) { + pw.print(""Case #"" + (i + 1) + "": ""); + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[][] l = new int[n][3]; + for (int j = 0; j < n; j++) { + int score = sc.nextInt(); + int q = score / 3; + int r = score % 3; + if (r == 1) { + l[j][0] = q; + l[j][1] = q; + l[j][2] = q + 1; + } else if (r == 2) { + l[j][2] = q; + l[j][0] = q + 1; + l[j][1] = q + 1; + } else { + l[j][0] = q; + l[j][1] = q; + l[j][2] = q; + } + } + int s1 = 0; + int count = 0; + for (int j = 0; j < l.length; j++) { + if (l[j][0] >= p || l[j][1] >= p || l[j][2] >= p) { + count++; + continue; + } else if (s1 < s && p > 1) { + if ((l[j][0] == p-1 && l[j][1] == p-1) || (l[j][2] == p-1 && l[j][1] == p-1) || (l[j][0] == p-1 && l[j][2] == p-1)) { + count++; + s1++; + continue; + } + } + } + pw.println(count); + } + + pw.flush(); + pw.close(); + sc.close(); + } + + public static void main(String[] args) throws Exception { + new DancingWithGooglers().translate(); + } +} +" +A20901,"package qualification.problemb; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ProblemB { + + private class Data { + + private int surpricing; + private int minPoints; + private List points = new ArrayList(); + + public int getSurpricing() { + return surpricing; + } + public void setSurpricing(int surpricing) { + this.surpricing = surpricing; + } + public int getMinPoints() { + return minPoints; + } + public void setMinPoints(int minPoints) { + this.minPoints = minPoints; + } + public List getPoints() { + return points; + } + public void setPoints(List points) { + this.points = points; + } + + } + + private List readFile(File f) { + String nextLine = null; + List result = null; + + try { + BufferedReader reader = new BufferedReader(new FileReader(f)); + + while ((nextLine = reader.readLine()) != null) { + if (result == null) { + result = new ArrayList(); + } else { + String[] line = nextLine.split("" ""); + Data d = new Data(); + d.setSurpricing(Integer.parseInt(line[1])); + d.setMinPoints(Integer.parseInt(line[2])); + + List points = new ArrayList(); + for(int i = 0; i < Integer.parseInt(line[0]); i++) { + d.getPoints().add(Integer.parseInt(line[i + 3])); + } + + result.add(d); + } + } + + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return result; + + } + + private List solve(List data) { + List winners = new ArrayList(); + for(Data d : data) { + winners.add(getMaxWinnerForList(d)); + } + + return winners; + } + + private int getMaxWinnerForList(Data data) { + int winners = 0; + int surpricing = 0; + + for(int point : data.getPoints()) { + if(point < data.getMinPoints()) { + continue; + } + + if(point >= 3 * data.getMinPoints() - 2) { + winners++; + } else if(point >= 3 * data.getMinPoints() - 4) { + surpricing++; + } + } + + winners += Math.min(data.getSurpricing(), surpricing); + + return winners; + } + + private void writeToDisk(List output) { + File f = new File(""outputBlarge.txt""); + + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(f)); + int counter = 1; + for(int s : output) { + writer.write(""Case #"" + counter + "": "" + s + ""\n""); + counter++; + } + writer.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + + public static void main(String[] args) { + ProblemB c = new ProblemB(); + List structures = c.readFile(new File(args[0])); + List longs = c.solve(structures); + c.writeToDisk(longs); + } + + +} +" +A20182,"import java.io.*; +import java.util.*; + +public class surprise +{ + + public static StringTokenizer st; + + public static void main(String[] args) + { + try + { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""B-large.in""))); + PrintWriter pw = new PrintWriter(new FileWriter(""output.out"")); + int T = Integer.parseInt(br.readLine()); + int t = 1; + while (t <= T) + { + st = new StringTokenizer(br.readLine(), "" "", false); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + + int tot = 0; + if (p == 0) tot = N; + else + { + for (int i = 0; i < N; i++) + { + int s = Integer.parseInt(st.nextToken()); + if (s >= p+2*(p-1)) tot++; + else if (S > 0 && p >= 2 && s >= p+2*(p-2)) + { + tot++; + S--; + } + } + } + + pw.println(""Case #""+t+"": ""+tot); + t++; + } + pw.flush(); + pw.close(); + br.close(); + } + catch (IOException ie) + { + ie.printStackTrace(); + } + } + +}" +A22155,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(new FileReader(""input.txt"")); + PrintWriter pw = new PrintWriter(new FileWriter(""output.txt"")); + int tn = sc.nextInt(); + sc.nextLine(); + for(int i = 0; i < tn; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int cnt = 0; + int cnts = 0; + for(int j = 0; j < n; j++) { + int oppa = sc.nextInt(); + if(oppa >= Math.max(p - 1, 0) * 2 + p) + cnt++; + else if(oppa >= Math.max(p - 2, 0) * 2 + p) + cnts++; + } + + pw.print(""Case #"" + (i + 1) + "": "" + (cnt + Math.min(s, cnts))); + pw.println(); + } + pw.close(); + } +} +" +A20344,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package solution; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Vector; + +/** + * + * @author Aditya + */ + +//A simple observation is: +// +class TestCase{ + int N; + int S; + + int p; + + int[] scores; + boolean[] ok; + + + public TestCase(String line){ + int[] ia=getAsIntegerArray(line); + + N=ia[0]; + S=ia[1]; + p=ia[2]; + + scores=new int[ia.length-3]; + ok=new boolean[ia.length-3]; + + for(int i=3;i""+scores[i]+"" "" + S + "" ""+ p); + //case 1: + if((scores[i]/3) >= p){ + System.out.println((scores[i]/3)+"" ""+(scores[i]/3) + "" ""+ (scores[i]/3)); + ok[i]=true; + } + //cases 2 and 3: + else if(((scores[i]%3) > 0) && (((scores[i]/3) +1)>=p)){ + if(scores[i]%3==1) + System.out.println((scores[i]/3+1)+"" ""+(scores[i]/3) + "" ""+ (scores[i]/3)); + else + System.out.println((scores[i]/3+1)+"" ""+(scores[i]/3 +1) + "" ""+ (scores[i]/3)); + ok[i]=true; + + } + + //case 4: + else if(((scores[i]%3) == 0) && (((scores[i]/3)+1)>=p)){ + if(S>0 && (scores[i]/3>0)){ + S--; + System.out.println((scores[i]/3+1)+"" ""+(scores[i]/3-1) + "" ""+ (scores[i]/3) + "" *""); + + ok[i]=true; + } + } + + //case 5: + else if(((scores[i]%3) == 2) && (((scores[i]/3)+2)>=p)){ + if(S>0){ + S--; + System.out.println((scores[i]/3+2)+"" ""+(scores[i]/3) + "" ""+ (scores[i]/3) + "" *""); + + ok[i]=true; + } + } + } + System.out.println(""---------------------------------------------------""); + } + + public int getNumOks(){ + int ret=0; + for(int i=0;i cases= new Vector(); + + public static BufferedReader br ; + + public static void readInput(){ + String s; + try{ + br=new BufferedReader(new FileReader(""f:\\test\\asdasd.in"")); + if((s=br.readLine())!=null) + numInputs=Integer.parseInt(s); + while((numInputs-->0) && (s=br.readLine())!=null){ + cases.add(new TestCase(s)); + } + }catch(IOException ioex){ + ; + } + } + + public static void process(){ + for(TestCase t:cases){ + t.setOk(); + } + } + + public static void printOutput(){ + for(int i=0;i N when it's unsurprising? If so, count it. + * If not, + * -- do we have a surprising score left? + * --can we get above N by making it surprising? + * If so, use up a 'surprising' point and make it so. + * you don't have to backtrack. there are at most 100 googlers + * so performance should be easy? + */ + + public static void main(final String[] args) { + new DancingWith().start(); + } + + private void start() { + final Scanner s = new Scanner(System.in); + final int numTests = s.nextInt(); + for (int i = 0; i < numTests; i++) { + // deb(""Case "" + (i + 1) + ""---------""); + final int numGooglers = s.nextInt(); //<= 100 + final int numSurprises = s.nextInt(); + final int scoreRequired = s.nextInt(); + + //output and calculation variables + int surprisesLeft = numSurprises; + int matchesFound = 0; + for (int g = 0; g < numGooglers; g++) { //for each googler + final int score = s.nextInt(); + if (highEnough(score, scoreRequired, false)) { + matchesFound++; + } else if (surprisesLeft > 0 && highEnough(score, scoreRequired, true)) { + surprisesLeft--; + matchesFound++; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + matchesFound); + } + } + + //we have the sum of three scores, at most 1 apart. + //[todo] There are only 30 possible scores so we could precalc or cache these. + //this code keeps the value of the middle score as low as possible. + private boolean highEnough(final int score, final int scoreRequired, final boolean surprising) { + final int range = surprising ? 2 : 1; + int one = score; //only decreases + int two = 0; //only increases + int three = 0; //only increases + while (one - three > range) { + //three can't increase above two - keep the order. + if (three < two) { + one--; + three++; + } else { + one--; + two++; + } + } + // deb(three + "" "" + two + "" "" + one + (one >= scoreRequired ? ""*"" : """") + (surprising ? "" S"" : """")); + return (one >= scoreRequired); + } + + // private void deb(final String value) { + // System.out.println(value.toString()); + // } + +} +" +A21828,"import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.IOException; +import java.util.InputMismatchException; +import java.math.BigInteger; + +public class Dancing { + static InputReader in; + static PrintWriter out; + + public static void main(String[] args) + { + try { + System.setIn(new FileInputStream(args[0])); + System.setOut(new PrintStream(new FileOutputStream(args[0].replace("".in"","".out"")))); + } catch (FileNotFoundException e) { + throw new RuntimeException(); + } + in = new InputReader(System.in); + out = new PrintWriter(System.out); + + int T = in.readInt(); + + for (int t = 0; t < T; t++) { + int N = in.readInt(); + int S = in.readInt(); + int p = in.readInt(); + + int[] points = new int[N]; + for (int i = 0; i < N; i++) { + points[i] = in.readInt(); + } + + int count = 0; + for (int i = 0; i < N; i++) { + int average = points[i] / 3; + int r = points[i] - (average * 3); + System.err.println(""-----""+i+""-----""+r); + if (r == 1) { + if (average + 1 >= p) { + count++; + } + } else if (r == 2) { + if (average + 1 >= p) { + count++; + } else { + if (S > 0 && average + 2 >= p) { + count++; + S--; + } + } + } else { + if (average >= p) { + count++; + } else { + if (average > 0 && S > 0 && average + 1 >= p) { + count++; + S--; + } + } + } + } + out.print(""Case #""+(t+1)+"": ""); + out.println("""" + count); + } + out.close(); + } + + private static class InputReader { + private InputStream stream; + private byte[] buf = new byte[1000]; + private int curChar, numChars; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + private int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public long readLong() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + long res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + private boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + private String readLine0() { + StringBuffer buf = new StringBuffer(); + int c = read(); + while (c != '\n' && c != -1) { + buf.appendCodePoint(c); + c = read(); + } + return buf.toString(); + } + + public String readLine() { + String s = readLine0(); + while (s.trim().length() == 0) + s = readLine0(); + return s; + } + + public String readLine(boolean ignoreEmptyLines) { + if (ignoreEmptyLines) + return readLine(); + else + return readLine0(); + } + + public BigInteger readBigInteger() { + try { + return new BigInteger(readString()); + } catch (NumberFormatException e) { + throw new InputMismatchException(); + } + } + + public char readCharacter() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + return (char) c; + } + + public double readDouble() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + double res = 0; + while (!isSpaceChar(c) && c != '.') { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } + if (c == '.') { + c = read(); + double m = 1; + while (!isSpaceChar(c)) { + if (c < '0' || c > '9') + throw new InputMismatchException(); + m /= 10; + res += (c - '0') * m; + c = read(); + } + } + return res * sgn; + } + } +}" +A22589,"package google.codejam.dancingwithgooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + + +public class Main { + + public static void main(String[] args) throws Exception { + String[] files = { + ""Data/B-large"" + }; + + + for (int f = 0; f < files.length; f++) { + BufferedReader in = new BufferedReader(new FileReader(files[f] + "".in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(files[f] + "".out"")); + + int T = Integer.parseInt(in.readLine()); // number of test cases + + for (int i = 1; i <= T; i++) { + String[] input = in.readLine().split("" ""); + int googlers = Integer.parseInt(input[0]); + int suprizing = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + int [] t = new int[googlers]; + + for (int j = 0; j < input.length - 3; j++) + t[j] = Integer.parseInt(input[j+3]); + + int m = getBest(googlers, suprizing, p, t); + + + out.write(String.format(""Case #%d: %d\n"", i, m)); + } + + out.close(); + in.close(); + + } + + } + + private static int getBest(int N, int S, int p, int[] t) { + int output = 0; + + + for (int i = 0; i < t.length; i++) { + + if (t[i] >= (3*p - 2) && t[i] > 0 || p == 0) output++; + else if (t[i] >= (3*p - 4) && t[i] > 0 && S > 0) + { + S--; + output++; + } + + } + + return output; + + } + +} +" +A20600,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.*; + +/** + * + * @author wijebandara + */ +public class DancingWithTheGooglers { + + public static void main(String[] args) throws FileNotFoundException, IOException { + + //java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + java.io.BufferedReader in=new java.io.BufferedReader(new java.io.FileReader(""/home/wijebandara/Desktop/B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""/home/wijebandara/Desktop/B-large.out""))); + + int n = Integer.parseInt(in.readLine()); + java.util.StringTokenizer st; + for (int i = 0; i < n; i++) { + st = new java.util.StringTokenizer(in.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + int answer = 0; + for (int j = 0; j < a; j++) { + int hold = Integer.parseInt(st.nextToken()); + int s = check(hold, c); + if (s == 1) { + answer++; + } + if (s == 2 && b > 0) { + b--; + answer++; + } + } + System.out.print(""Case #"" + (i + 1) + "": ""); + out.print(""Case #"" + (i + 1) + "": ""); + System.out.println(answer); + out.println(answer); + } + out.close(); + System.exit(0); + + } + + static int check(int x, int y) // 0-no,1 yes no *,2 yes yes * + { + if (x % 3 == 0) { + if (x / 3 >= y) { + // System.out.println(""1""); + return 1; + } + } + if ((x - 1) % 3 == 0) { + int hold = (x - 1) / 3; + if (hold >= 0 && hold + 1 >= y) { + //System.out.println(""2""); + return 1; + } + } + if ((x - 2) % 3 == 0) { + int hold = (x - 2) / 3; + + if (hold >= 0 && hold + 1 >= y) { + //System.out.println(""3""); + return 1; + } + if (hold >= 0 && hold + 2 >= y) { + //System.out.println(""4""); + return 2; + } + } + if ((x - 3) % 3 == 0) { + int hold = (x - 3) / 3; + + if (hold >= 0 && hold + 2 >= y) { + // System.out.println(""5""); + return 2; + } + } + if ((x - 4) % 3 == 0) { + int hold = (x - 4) / 3; + + if (hold >= 0 && hold + 2 >= y) { + //System.out.println(""6""); + return 2; + } + } + return 0; + } +} +" +A20907,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class codejamp2 { + public static char[] map; + public static void main(String[] args) throws IOException{ + readFile(); + } + + public static String getResult(String input){ + int resultInt = 0; + String[] splitResult = input.split("" ""); + int dancerCount = Integer.parseInt(splitResult[0]); + int suprising = Integer.parseInt(splitResult[1]); + int max = Integer.parseInt(splitResult[2]); + for(int i = 3; i < dancerCount + 3; i++){ + int current = Integer.parseInt(splitResult[i]); + int ave = current/3; + int remain = current - 3*ave; + int currentmax = ave + remain; + if(remain == 0 && (max - currentmax == 1) && current!= 0){ + if(suprising > 0){ + suprising--; + resultInt++; + } + } + if(currentmax >= max){ + if(remain<=1){ + resultInt++; + } + else if(remain == 2){ + if(max - ave<=1){ + resultInt++; + } + else if(suprising > 0){ + suprising--; + resultInt++; + } + } + } + } + return """"+resultInt; + } + public static void readFile() throws IOException{ + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + FileReader input = new FileReader(""in.txt""); + BufferedReader bufRead = new BufferedReader(input); + String line = bufRead.readLine(); + String current = getResult(line); + int i = 1; + out.write(""Case #"" + i + "": "" + current); + line = bufRead.readLine(); + while (line != null){ + i++; + System.out.println(""Case #"" + i + "": "" + getResult(line)); + out.write('\n' + ""Case #"" + i + "": "" + getResult(line)); + line = bufRead.readLine(); + } + bufRead.close(); + out.close(); + } +} +" +A20168,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class GoogleDancing { + public static void main(String [] args) throws IOException { + Scanner fileScan = new Scanner(new File(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""B-large.out"")); + + int n = Integer.parseInt(fileScan.nextLine()); + for (int i = 0; i < n; i++) { + int numDancers = fileScan.nextInt(); + int surprises = fileScan.nextInt(); + int p = fileScan.nextInt(); + int max = 0; + + for (int j = 0; j < numDancers; j++) { + int score = fileScan.nextInt(); + if (score >= p*3-2) { + max++; + } + else if (score > 0 && score >= p*3-4 && surprises > 0) { + surprises--; + max++; + } + } + + int temp = i + 1; + out.write(""Case #"" + temp + "": "" + max + ""\n""); + } + + out.close(); + } +} +" +A20430,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class ProblemB { + + ProblemB() throws IOException { + + Scanner reader = new Scanner(new File(""input.txt"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""output.txt"")); + + int cases = reader.nextInt(); + + for(int i = 1; i <= cases; i++) { + int n = reader.nextInt(); + int s = reader.nextInt(); + int p = reader.nextInt(); + int result = 0; + for(int j = 0; j < n; j++) { + int score = reader.nextInt(); + int max = (score+2)/3; + if(max>=p) + result++; + else if(max==p-1 && score>1 && score<29 && score%3!=1 && s>0) { + s--; + result++; + } + } + + writer.write(""Case #""+i+"": ""+result); + writer.newLine(); + } + + reader.close(); + writer.close(); + } + + public static void main(String[] args) throws IOException { + new ProblemB(); + } +} +" +A22495,"import java.io.*; +import java.util.*; + +public class DanceGooglers { + static String name = ""B-large""; + + public static void main(String args[]) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(name + "".in"")); + PrintWriter out = new PrintWriter(name + "".out""); + int t = Integer.parseInt(in.readLine()), caseN = 1; + while (caseN <= t) { + int ans = 0; + StringTokenizer tok = new StringTokenizer(in.readLine()); + int n = Integer.parseInt(tok.nextToken()), s = Integer.parseInt(tok + .nextToken()), p = Integer.parseInt(tok.nextToken()); + +// System.out.println(n + "" "" + s + "" "" + p); + for (int i = 0; i < n; i++) { + int total = Integer.parseInt(tok.nextToken()); +// System.out.println(total); + if (total < p) + continue; + + if (total >= p * 3 - 2) { + ans++; + continue; + } + + if (total >= p * 3 - 4 && s > 0) { + s--; + ans++; + } + } + out.print(""Case #""); + out.print(caseN++); + out.print("": ""); + out.println(ans); +// System.out.println(caseN - 1 + "" ans "" + ans); + } + out.flush(); + } +}" +A21096,"import java.io.*; +import java.util.*; + +public class B implements Runnable +{ + //private String IFILE = ""input.txt""; + //private String IFILE = ""B-small-attempt0.in""; + private String IFILE = ""B-large.in""; + + private Scanner in; + private PrintWriter out; + + public void Run() throws IOException + { + in = new Scanner(new File(IFILE)); + out = new PrintWriter(""output.txt""); + + int ntest = in.nextInt(); + for(int test = 1; test <= ntest; test++) + { + out.print(""Case #"" + test + "": ""); + int n = in.nextInt(); + int m = in.nextInt(); + int p = in.nextInt(); + int[] mas = new int[n]; + for(int i = 0; i < n; i++) + mas[i] = in.nextInt(); + + int[] max1 = new int[31]; + for(int i = 1; i <= 10; i++) + max1[Math.max(0, Math.min(30, 3 * i - 2))] = i; + int[] max2 = new int[31]; + for(int i = 1; i <= 10; i++) + max2[Math.max(1, Math.min(30, 3 * i - 4))] = i; + for(int i = 1; i <= 30; i++) + max1[i] = Math.max(max1[i], max1[i - 1]); + for(int i = 1; i <= 30; i++) + max2[i] = Math.max(max2[i], max2[i - 1]); + + int n1 = 0; + int n2 = 0; + for(int i = 0; i < n; i++) + { + if (max1[mas[i]] >= p) + n1++; + else if (max2[mas[i]] >= p) + n2++; + } + + out.println(n1 + Math.min(n2, m)); + } + + in.close(); + out.close(); + } + + public void run() + { + try + { + Run(); + } + catch(IOException e) + { + + } + } + + public static void main(String[] args) throws IOException + { + new B().Run(); + //new Thread(new XXX()).start(); + } + +} +" +A21546,"package com.jp.common; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintStream; +import java.util.Scanner; + +public class InputOutputProcessor { + + private int numberOfCases; + private boolean doesInputHaveDataSetLines; + private int indexOfDataSetLine; + private int numberOfDataSetLines; + private final static String DELIMITER = "" ""; + + private Scanner scanInput; + + public void initializeInput(String strInputFileName) { + readInput(strInputFileName); + numberOfCases = Integer.parseInt(scanInput.nextLine()); + } + + /* + * read input + */ + private void readInput(String strInputFileName) { + try { + scanInput = new Scanner(new BufferedReader(new FileReader( + strInputFileName))); + } + + catch (Exception exp) { + // exp.printStackTrace(); + System.out.println("" Please provide File Name with proper location ""); + } + } + + public String[] getDataSet() throws Exception { + String[] dataSet; + String strDataSetLine = """"; + + strDataSetLine = scanInput.nextLine(); + + if (doesInputHaveDataSetLines) { + String[] DataSetLineArray = strDataSetLine.split(DELIMITER); + numberOfDataSetLines = Integer + .parseInt(DataSetLineArray[indexOfDataSetLine]); + } + + dataSet = new String[numberOfDataSetLines]; + dataSet[0] = strDataSetLine; + + for (int i = 1; i < numberOfDataSetLines; i++) { + dataSet[i] = scanInput.nextLine(); + } + return dataSet; + } + + /** + * * @return Returns the numberOfDataSetLines. + */ + public int getNumberOfDataSetLines() { + return numberOfDataSetLines; + } + + /** + * @param numberOfDataSetLines + * The numberOfDataSetLines to set. + */ + public void setNumberOfDataSetLines(int numberOfDataSetLines) { + this.numberOfDataSetLines = numberOfDataSetLines; + } + + /** + * * @return Returns the numberOfCases. + */ + public int getNumberOfCases() { + return numberOfCases; + } + + /** + * * @return Returns the doesInputHaveDataSetLines. + */ + public boolean isDoesInputHaveDataSetLines() { + return doesInputHaveDataSetLines; + } + + /** + * @param doesInputHaveDataSetLines + * The doesInputHaveDataSetLines to set. + */ + public void setDoesInputHaveDataSetLines(boolean doesInputHaveDataSetLines) { + this.doesInputHaveDataSetLines = doesInputHaveDataSetLines; + } + + /** + * * @return Returns the indexOfDataSetLine. + */ + public int getIndexOfDataSetLine() { + return indexOfDataSetLine; + } + + /** + * @param indexOfDataSetLine + * The indexOfDataSetLine to set. + */ + public void setIndexOfDataSetLine(int indexOfDataSetLine) { + this.indexOfDataSetLine = indexOfDataSetLine; + } + + public void closeScanner() { + scanInput.close(); + } + + public void writeOutput(String outputFileName, String[] resultArray) { + PrintStream out = null; + try { + out = new PrintStream(new FileOutputStream(outputFileName)); + for (int i = 0; i < resultArray.length; i++) { + out.print(resultArray[i]); + out.print(""\n""); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(0); + } + + } + +} +" +A22481," +import java.util.*; +import java.io.*; + +import javax.xml.ws.handler.MessageContext.Scope; + +public class Googlers{ + + public static List processed=new ArrayList(); + public static List scores; + + public static void main(String[] args){ + + String fn = ""C:\\Users\\Ashu\\Desktop\\B-small-attempt0(1).in""; + String fnOut = toFnOut(fn); + String out=null; + try{ + //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader br = new BufferedReader(new FileReader(fn)); + BufferedWriter bw = new BufferedWriter(new FileWriter(fnOut)); + String line = null; + int NCase = Integer.valueOf(br.readLine()); + int suprise=0; + int bestScore=0; + int noOfGooglers=0; + + for(int icase=0;icase(); + StringTokenizer st=new StringTokenizer(line); + if(st.hasMoreTokens()){ + noOfGooglers=Integer.valueOf(st.nextToken()); + suprise=Integer.valueOf(st.nextToken()); + bestScore=Integer.valueOf(st.nextToken()); + for(int i=0;i scores){ + int result=0; + int surpriseCount=0; + int minTotalBestScore=(bestScore-1)*3+1; + if(minTotalBestScore<0){ + result=scores.size(); + return result; + } + for(int i=0;i=minTotalBestScore) + result++; + } + if(surprise>0 && (minTotalBestScore-2)>0){ + for(int i=0;i=(minTotalBestScore-2) && scores.get(i)<(minTotalBestScore)){ + result++; + surpriseCount++; + } + + if(surpriseCount==surprise) + break; + } + } + return result; + } + + + static String toFnOut(String fn){ + if(fn.lastIndexOf('.')!=-1){ + return fn.substring(0,fn.lastIndexOf('.'))+"".out""; + }else return fn + "".out""; + } +} +" +A20079,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + + +public class Problem2 { + BufferedReader br ; + PrintWriter pw; + + public static void main (String [] args) throws IOException{ + new Problem2().startProcessing(); + } + public void startProcessing () throws IOException { + br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(""/tmp/codejam/A-small-practice.in"")))); + pw = new PrintWriter(new File(""/home/peeyushk/tmp/output.ou"")); + startReading(); + pw.flush(); + pw.close(); + br.close(); + + } + + void startReading() throws IOException { + int numTestCase=0; + int numPeople=0; + int specialCases=0; + int p=0; + String numTestCaseLine = br.readLine().trim(); + numTestCase = Integer.parseInt(numTestCaseLine.trim()); + + for( int i=0; i=1) { + result++; + } + } else if (p>1 ) { + if ( t>lowerLimit ) { + result++; + } else if (t == lowerLimit || t==lowerLimit-1) { + if (specialCasesUsed currentScore) + { + + //If that doesn't work, we have no choice but to + //try and use a 'surprise' score. + + if(surprises > 0) + { + if(minSurprise > currentScore) + { + hits--; + }else + { + surprises--; + } + }else + { + hits--; + } + } + + } + + //Done! Now print out the result: + System.out.print(hits); + System.out.println(); + + //Reset things for next case; + hits = 0; + surprises = 0; + + + }while(currentCase < totalCases); + } +} +" +A20760,"import java.io.*; +import java.util.*; + +class JamB +{ + +public static void main(String args[])throws Exception +{ + +FileReader fr = new FileReader(""B-large.in""); +BufferedReader br = new BufferedReader(fr); + +FileWriter fw= new FileWriter(""out.txt""); + +BufferedWriter bw=new BufferedWriter(fw); +PrintWriter pw= new PrintWriter(bw); + +int t=Integer.parseInt(br.readLine()); +int n=0,s=0,p=0,ans=0,scount=0;String str=""""; + +for(int i=0;i(p-1)*3)ans++; +else if(a>=(p-1)*3-1&&scount= 0) + dp[pos+1][sur+nSur] = Math.max(dp[pos+1][sur+nSur], dp[pos][sur] + (maxBest[tot[pos]][nSur] >= p ? 1 : 0)); + + pw.println(dp[N][S]); + } + + public static void main(String[] args) throws Exception { + preprocess(); + + Scanner sc = new Scanner(new FileReader(WORK_DIR + ""input.txt"")); + PrintWriter pw = new PrintWriter(new FileWriter(WORK_DIR + ""output.txt"")); + int caseCnt = sc.nextInt(); + for (int caseNum=0; caseNum= p) { + y++; + } else if (total2best_scores[t[i]][SURPRISING] == p) { + if (s > 0) { + s--; + y++; + } + } + } + return y; + } +} +" +A22737,"package er.dream.codejam.helpers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +public class FileHandler { + + BufferedReader read; + BufferedWriter write; + + public File[] listFiles(){ + return new File(""data"").listFiles(); + } + + public void loadFile(File file){ + try { + read = new BufferedReader(new FileReader(file)); + write = new BufferedWriter(new FileWriter(new File(""output/""+file.getName().replace("".in"", "".out"")))); + } catch (IOException e) { + throw new IllegalStateException(""Couldn't load file: ""+file.getName(),e); + } + } + + public void closeConnection(){ + try { + read.close(); + write.close(); + } catch (IOException e) { + throw new IllegalStateException(""Couldn't close connection"",e); + } + } + + public void writeOutput(List outputData){ + int line = 1; + for(String entry:outputData){ + try { + write.write(""Case #""+line+"": ""+entry+""\n""); + } catch (IOException e) { + throw new IllegalStateException(""Error while writing output"",e); + } + line++; + } + } + + public String readString(){ + try { + return read.readLine(); + } catch (IOException e) { + throw new IllegalStateException(""Error while reading input"",e); + } + } + + public int readInt(){ + return Integer.parseInt(readString()); + } + + public long readLong(){ + return Long.parseLong(readString()); + } + + public double readDouble(){ + return Double.parseDouble(readString()); + } + + public String[] readStringArray(){ + return readString().split("" ""); + } + + public int[] readIntArray(){ + String[] strings = readStringArray(); + int[] ints = new int[strings.length]; + for(int i=0;i0) + { + sub--; + res++; + } + continue; + } + // System.out.println(v+"" ""+res); + if(v%3==0) + { + if(v/3-1>=p||v/3>=p) + res++; + else if(v/3+1>=p&&sub>0) + { + sub--; + res++; + } + + } + if(v%3==1) + { + if(v/3>=p||v/3+1>=p) + res++; + + } + if(v%3==2) + { + if(v/3+1>=p||v/3>=p) + res++; + else if(v/3+2>=p&&sub>0) + { + sub--; + res++; + } + + } + } + + out.write(""Case #""+(i+1)+"": ""+res+""\n""); + } + out.close(); + } +} +" +A20825,"package twentytwelve.qualification.b; + +import java.util.Scanner; + +public final class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int cases = sc.nextInt(); + for (int no = 1; no <= cases; no++) { + System.out.print(""Case #"" + no + "": ""); + // googlers + int N = sc.nextInt(); + // surprises + int S = sc.nextInt(); + // best result + int p = sc.nextInt(); + + // unnecessary calculations + int p2 = 3 * p - 2; + int p4 = p2 - 2; + + int max = 0; + for (int triplet = 0; triplet < N; triplet++) { + int score = sc.nextInt(); + if (score >= p) { + if (score >= p2) { + max++; + } else if (score < p2 && score >= p4 && S > 0) { + max++; + S--; + } + } + } + System.out.println(max); + } + } +} +" +A22181,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""input.txt""))); + String line = br.readLine(); + BufferedWriter out = new BufferedWriter(new FileWriter(""output.txt"")); + int tests = Integer.valueOf(line.trim()); + for (int i = 0; i < tests; i++) { + String[] number = br.readLine().split("" ""); + int n = Integer.valueOf(number[0]); + int s = Integer.valueOf(number[1]); + int p = Integer.valueOf(number[2]); + int result = 0; + for (int j = 3; j < 3 + n; j++) { + int total = Integer.valueOf(number[j]); + int avg = total/3; + if (avg >= p || (avg == p-1 && total % 3 > 0)) { + result++; + } + else if (s > 0 && (avg == p-2 && total % 3 == 2 || avg == p-1 && avg != 0)) { + s--; + result++; + } + } + out.write(""Case #""+ (i + 1) +"": "" + result + ""\n""); + } + out.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}" +A21996,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + + +public class dancing { + public static void main(String[] args) { + dancing dance = new dancing(); + dance.readFile(""test.txt""); + } + + public void readFile(String filename){ + int i = 1; + BufferedReader reader = null; + try { + reader = new BufferedReader(new + FileReader(filename)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + String newLine; + try { + newLine = reader.readLine(); + while ((newLine = reader.readLine()) != null) { + evalline(newLine,i); + i++; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public void evalline(String line,int casenum){ + int len = line.length(); + Scanner sc = new Scanner(line); + int n = sc.nextInt(); + int s= sc.nextInt(); + int score = sc.nextInt(); + int good = 0; + int maybe = 0; + int minscore = 2 * (score-1) + score; + int minscorespecial = minscore - 2; + System.out.print(""Case #"" + casenum + "": ""); + while(sc.hasNextInt()){ + int curr = sc.nextInt();; + if(curr >= score){ + if(curr >= minscore){ + good++; + } + else if(curr >= minscorespecial){ + maybe++; + } + } + } + int tot = good + Math.min(maybe, s); + System.out.println(tot); + + + } +} + +" +A22854,"package qualification.q1; + +import com.sun.deploy.net.proxy.StaticProxyManager; +import qualification.common.InputReader; +import qualification.common.OutputWriter; + +/** + * Created by IntelliJ IDEA. + * User: ofer + * Date: 14/04/12 + * Time: 17:36 + * To change this template use File | Settings | File Templates. + */ +public class Q1Sim { + + public static void main(String[] args){ + String inputFile = ""input.txt""; + String outPutFile = ""output.txt""; + String[] lines = InputReader.getInputLines(inputFile); + Q1Solver solver = new Q1Solver(); + int numOfTests = Integer.parseInt(lines[0]); + String[] output = new String[numOfTests]; + for (int i = 0 ; i < numOfTests ; i++){ + String decrypted = solver.convertString(lines[i+1]); + output[i] = ""Case #"" + (i+1) + "": "" + decrypted; + } + OutputWriter.writeOutput(outPutFile,output); + } +} +" +A20822,"package jam2012.qround; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class PB { + public static void main(String args[]) + { + int line = 0; + try{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""B-large.out"")); + String str; + String[] strIn; + System.out.println(Integer.parseInt(br.readLine())); + while ((str = br.readLine()) != null){ + strIn = str.split("" ""); + int i=0; + int N = Integer.parseInt(strIn[i++]); + int S = Integer.parseInt(strIn[i++]); + float p = Integer.parseInt(strIn[i++]); + int cases = 0; + while(N>0){ + float score = Integer.parseInt(strIn[i++]); + N--; + if (score >= (3*p-2)) + cases++; + else + if (score >= (3*p-4) && S>0 && score >=2){ + cases++; + S--; + } + } + line++; + System.out.println(""Case #""+line+"": ""+cases); + bw.write(""Case #""+line+"": ""+cases); + bw.newLine(); + } + br.close(); + bw.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A21893,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +/** + * @(#)codejam2.java + * + * codejam2 application + * + * @author + * @version 1.00 2012/4/14 + */ + import java.util.Scanner; +import java.io.*; +import java.util.StringTokenizer; +public class codejam2012B { + + public static void main(String[] args) throws IOException { + Scanner scan = new Scanner(new File(""C:\\Users\\Eren\\Desktop\\B-large.in"")); + // System.out.println(scan.nextLine()); + int N = Integer.parseInt(scan.nextLine()); + String line; + int count; + int result; + int surprise; + int p; + int temp; + int temp1; + StringTokenizer tokenizer; + + for ( int i = 0 ; i < N ; i ++) { + result = 0; + line = scan.nextLine(); + tokenizer = new StringTokenizer(line); + count = Integer.parseInt(tokenizer.nextToken()); + surprise = Integer.parseInt(tokenizer.nextToken()); + p = Integer.parseInt(tokenizer.nextToken()); + + for ( int j = 0; j < count; j++) + { + temp = Integer.parseInt(tokenizer.nextToken()); + temp1 = temp; + temp = 3*p -temp; + if (temp1 == 0 ) + { + if ( p == 0) + result++; + } + else if ( temp1 == 1 ) + { + if(p == 0 || p == 1) + result++; + } + else if ( temp <= 2 ) + result++; + else if ( (temp == 4 || temp == 3) && surprise > 0 ) + { + result++; + surprise--; + } + + } + System.out.println(""Case #"" + (i+1) + "": "" + result); + } + } +} +" +A22722,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Array; +import java.util.Arrays; + + +public class Dancing { + public static void main(String[] args) throws IOException { +BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); +String x=reader.readLine(); +String result=""""; +String input=""""; +long cases=Long.parseLong(x); +int size=0; +int sur=0; +int max=0; +int current=0; +int curmax=0; +int last=0; +int[]array1; +for(int j=0;j=max){ + curmax++; + } + }else{ + if(current%3==2){ + if(last=max)){ + if((current/3+2)>=max){ + curmax++; + } + last++; + }else{ + if((current/3+1)>=max){ + curmax++; + } + } + }else{ + if(last=max)&&(current/3-1)>=0){ + curmax++; + last++; + } + } + } +}else{ + curmax++; +} +} +result+=""Case #""+(j+1)+"": ""+curmax+""\n""; +} +System.out.println(result); + } +}" +A20808,"package be.mokarea.gcj.googledancers; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; + +import be.mokarea.gcj.common.TestCaseReader; + +public class GoogleDancerTestCaseReader extends + TestCaseReader { + private final LineNumberReader lineReader; + private final int NUMBER_TEST_CASE; + private int currentCaseNumber; + + public GoogleDancerTestCaseReader(InputStream inputStream) throws NumberFormatException, IOException { + lineReader = new LineNumberReader(new InputStreamReader(inputStream)); + NUMBER_TEST_CASE = Integer.parseInt(lineReader.readLine()); + currentCaseNumber = 0; } + + @Override + public GoogleDancerTestCase nextCase() throws Exception { + String line = lineReader.readLine(); + if (line != null) { + currentCaseNumber++; + String[] tokens = line.split("" ""); + final int numberOfGooglers = Integer.parseInt(tokens[0]); + final int numberOfSurprisingTripletsOfScores = Integer.parseInt(tokens[1]); + final int scoreLowerBoundary = Integer.parseInt(tokens[2]); + + final int scores[] = new int[numberOfGooglers]; + for (int i = 3, j = 0 ; i < tokens.length ; i++, j++) { + scores[j] = Integer.parseInt(tokens[i]); + } + return new GoogleDancerTestCase(currentCaseNumber, numberOfGooglers, numberOfSurprisingTripletsOfScores, scoreLowerBoundary, scores); + } + return null; } + + @Override + public int getMaxCaseNumber() { + return NUMBER_TEST_CASE; + } + +} +" +A22295,"/* + * Program Name :- B.java + * Author :- Happy Mittal + * Created on 14 April, 2012 + * + * + */ + +package googlecodejam11; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class B { + /** Creates a new instance of B */ + public B() { + try{ + // Open the input file + //FileInputStream finstream = new FileInputStream(""E:\\B-small-attempt0.in""); + FileInputStream finstream = new FileInputStream(""E:\\B-large.in""); + //FileInputStream finstream = new FileInputStream(""E:\\test-input.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(finstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + // Create a output file + //FileWriter foutstream = new FileWriter(""E:\\B-small-output.in""); + FileWriter foutstream = new FileWriter(""E:\\B-large-output.in""); + //FileWriter foutstream = new FileWriter(""E:\\test-output.in""); + BufferedWriter bw = new BufferedWriter(foutstream); + + br.readLine(); // read the first line it contains no of cases + String strLine; + int caseno = 1; + //Read File Line By Line + // strLine = br.readLine(); + while ((strLine = br.readLine()) != null) { + // Print the content on the console + // System.out.println (strLine); + strLine = strLine.trim(); + int result = NoOFTriplets(strLine); + //System.out.println (result); + String netresult = ""Case #"" + caseno + "": "" + result ; + bw.write(netresult); + bw.newLine(); + caseno ++; + } + + + //Close the input stream + in.close(); + //Close the output stream + bw.close(); + + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + public static void main(String[] args) { + // TODO code application logic here + B b1 = new B(); + } + public int NoOFTriplets(String str){ + String input[] = str.split("" ""); + int MaxGooglers = 0 ; + int N = Integer.parseInt(input[0]); + int S = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + // int value[] = new int[N]; + for(int i=0;i= p) MaxGooglers ++; + continue; + } + int div = score / 3 ; + int rem = score % 3; + //System.out.println (""Values "" + div + "" -- "" + rem); + if(rem != 0 ) div ++; + if (div >= p) + { + MaxGooglers ++; + // System.out.println (""Hello1""); + } + else if(S > 0 && rem != 1 && div + 1 >= p ) + { + // System.out.println (S + ""Hello2""); + MaxGooglers ++; + S--; + } + } + + return MaxGooglers; + } +} +" +A20421,"package se.pathed.codejam.practice.dansingwithgooglers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +public class DancingWithGooglers { + + public File getFileFromDisk(String fileName){ + String dataFolder = ""C:\\Users\\Patrik\\workspaces\\codejam\\Practis\\data\\""; + return new File(dataFolder + fileName); + } + + public static void main(String[] args) throws IOException{ + new DancingWithGooglers().run(); + } + + public static class Problem { + int numDancers; + int numSupprises; + int searched; + int solution; + int[] scores; + } + + public Problem[] parseInput() throws IOException{ + File f = getFileFromDisk(""B-large.in""); + FileReader fReader = new FileReader(f); + BufferedReader reader = new BufferedReader(fReader); + + int numCases = Integer.parseInt(reader.readLine()); + Problem[] probs = new Problem[numCases]; + + for( int i = 0; i < numCases; i++){ + Problem p = new Problem(); + String[] strInp = reader.readLine().split("" ""); + p.numDancers = Integer.parseInt(strInp[0]); + p.numSupprises = Integer.parseInt(strInp[1]); + p.searched = Integer.parseInt(strInp[2]); + + p.scores = new int[p.numDancers]; + for( int x = 3; x < strInp.length; x++){ + p.scores[x-3] = Integer.parseInt(strInp[x]); + } + probs[i] = p; + } + + return probs; + } + + private void run() throws IOException { + Problem[] problems = parseInput(); + + File outputFile = getFileFromDisk(""out.txt""); + if( outputFile.exists()) outputFile.delete(); + PrintWriter outFile = new PrintWriter(outputFile); + + for( int i = 0; i < problems.length; i++){ + Problem p = problems[i]; + + int lowestScore = ( p.searched * 3) -2; + int lowestSuppriseScore = lowestScore - 2; + + int possibleScore = 0; + int possibleSupprise = 0; + + for( int sc : p.scores ){ + if( sc >= lowestScore){ + possibleScore++; + } else if( sc >= lowestSuppriseScore && sc > 0){ + possibleSupprise++; + } + } + + p.solution = possibleScore + (possibleSupprise > p.numSupprises ? p.numSupprises : possibleSupprise); + + outFile.println(""Case #"" + (1+i) + "": "" + p.solution); + } + outFile.flush(); + } +} +" +A22218,"package qr2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Arrays; +import java.util.HashMap; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + public static void main(String[] args) throws Exception { + String fileName = args[0]; + DancingWithTheGooglers obj = new DancingWithTheGooglers(); + obj.solve(fileName); + } + + public void solve(String fileName) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(fileName)); + BufferedWriter bw = new BufferedWriter( + new FileWriter(fileName + "".out"")); + + int T = Integer.parseInt(br.readLine()); + for (int i = 0; i < T; i++) { + String str = br.readLine(); + + StringTokenizer token = new StringTokenizer(str, "" ""); + + int N = Integer.parseInt(token.nextToken()); + int S = Integer.parseInt(token.nextToken()); + int p = Integer.parseInt(token.nextToken()); + int[] t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = Integer.parseInt(token.nextToken()); + } + + // Arrays.sort(t); + + int cnt = 0; + int scnt = 0; + + for (int j = N - 1; j >= 0; j--) { + if (t[j] >= 3 * p - 2) { + cnt += 1; + } else if (t[j] >= 3 * p - 4 && t[j] >= 2 && scnt < S) { + cnt += 1; + scnt += 1; + } + } + + bw.write(""Case #"" + (i + 1) + "": ""); + bw.write("""" + cnt); + bw.write(""\r\n""); + } + bw.close(); + br.close(); + } +} +" +A22867,"100 +6 2 8 29 20 8 18 18 21 +48 25 0 29 19 2 6 4 19 19 14 24 22 2 16 4 23 26 2 30 3 16 23 28 30 20 2 4 16 9 6 4 12 12 19 8 28 26 23 30 28 22 27 15 30 8 16 22 30 6 25 +38 7 6 0 3 9 17 28 19 12 1 7 6 17 23 6 19 19 6 23 24 13 29 2 23 1 1 19 4 4 4 7 19 20 7 10 13 11 16 5 15 +72 28 9 25 11 21 23 24 23 17 1 21 20 23 23 12 28 4 5 23 23 23 28 23 30 21 24 26 24 8 18 12 23 24 24 8 23 30 24 23 24 23 4 24 24 24 23 1 23 23 8 23 24 24 23 2 0 13 14 15 24 24 23 24 23 25 8 19 23 23 8 24 24 23 24 +83 35 10 3 25 7 3 18 0 29 25 6 4 14 21 25 28 26 22 0 6 6 12 10 25 10 19 11 7 9 17 19 7 0 17 23 9 22 27 15 4 28 12 21 23 22 20 13 7 14 9 15 13 3 24 2 27 22 28 26 10 27 13 26 16 8 13 19 3 2 28 14 22 5 28 16 10 4 1 12 23 30 4 22 18 30 +15 2 6 15 14 18 25 22 25 15 15 17 26 9 30 12 29 20 +67 67 3 23 11 21 12 14 13 25 13 28 9 10 14 9 8 2 22 24 27 12 9 4 9 13 8 2 8 16 13 13 14 14 5 25 24 2 10 8 27 21 11 20 9 5 15 9 13 5 12 22 23 2 13 5 12 25 16 21 9 20 15 4 16 12 16 17 27 19 +31 5 2 3 2 2 2 3 3 7 8 2 3 7 3 2 3 2 2 15 3 14 25 2 26 3 24 23 25 2 22 15 2 2 +54 4 2 3 23 17 15 3 2 3 5 12 4 8 2 2 15 2 6 6 2 3 3 6 6 22 3 3 2 2 3 6 30 25 2 3 2 3 19 4 1 3 3 13 3 23 3 5 9 3 3 5 2 2 2 27 3 +24 1 6 15 14 15 14 9 14 15 14 15 14 20 14 26 1 14 21 15 15 8 12 10 5 30 15 +51 38 4 4 28 23 20 15 15 5 27 10 26 25 3 3 9 1 23 17 23 17 28 13 23 23 17 29 28 23 21 4 27 21 7 16 21 27 27 30 19 15 27 19 6 26 8 15 25 0 21 25 18 22 +96 6 7 17 17 28 5 1 0 18 18 17 9 0 18 7 18 16 10 21 12 12 22 12 18 17 12 17 21 12 18 14 18 17 9 18 11 17 18 11 20 17 27 18 1 17 18 19 26 17 11 18 14 19 27 28 17 24 18 0 2 17 17 17 18 17 18 17 30 17 12 18 20 17 18 2 8 7 18 17 18 10 18 17 17 17 10 17 10 23 18 18 17 6 18 17 18 23 18 +79 15 4 8 28 24 7 24 8 8 0 9 9 9 18 8 26 9 8 30 12 9 8 8 9 8 8 9 29 3 25 8 8 9 8 7 8 8 0 9 2 25 2 8 20 12 9 9 4 7 9 30 7 29 8 1 22 9 8 28 4 15 8 10 26 17 27 8 2 2 26 18 12 8 9 20 26 12 8 18 9 0 +85 70 5 7 9 23 26 25 1 8 12 12 7 10 26 20 9 17 27 4 17 18 8 13 0 4 28 23 15 2 29 24 18 30 4 3 0 20 22 7 6 29 25 23 9 2 23 7 8 3 25 7 17 7 0 22 6 1 0 4 3 2 24 15 30 3 1 17 14 5 4 8 2 15 18 5 9 6 26 18 5 13 2 30 29 11 1 1 +11 0 5 5 26 0 23 1 27 0 30 29 23 12 +10 2 7 24 22 10 12 25 7 30 12 1 13 +29 8 9 23 15 28 24 23 14 24 13 23 11 30 24 24 16 23 13 16 26 23 26 2 29 24 23 23 27 16 26 24 +19 19 2 15 10 11 13 20 27 5 5 13 23 4 23 2 27 15 17 24 2 11 +9 2 2 3 3 3 3 8 3 8 21 4 +2 0 10 18 12 +50 32 5 28 27 4 26 30 24 0 24 27 7 19 3 20 6 11 14 10 14 20 25 12 14 5 7 15 26 24 3 18 27 3 8 18 17 21 25 11 8 14 1 4 2 11 0 7 29 14 9 21 22 +42 8 5 9 25 26 17 18 16 6 14 15 3 22 8 0 7 10 19 9 23 30 21 17 5 6 15 29 1 10 22 29 0 12 27 19 5 23 10 11 30 18 6 21 19 +77 49 3 14 6 16 16 28 23 16 12 19 5 6 24 23 6 30 25 6 27 27 30 1 12 26 17 21 5 9 9 30 26 19 9 8 8 8 29 30 8 2 24 28 17 20 7 12 22 5 11 26 19 28 23 6 9 18 25 19 3 12 4 28 4 1 24 21 13 17 3 12 22 14 3 21 22 15 8 30 +65 10 6 30 13 27 18 29 10 18 17 22 21 14 0 10 4 26 15 10 7 3 0 12 26 26 7 3 5 2 23 15 20 19 20 1 5 2 18 13 10 5 24 21 10 25 11 10 13 14 18 5 14 23 13 28 25 7 28 26 13 2 1 28 13 4 21 18 +14 10 0 17 18 8 18 30 7 10 0 28 20 10 30 23 21 +18 12 6 15 24 29 1 1 13 12 17 17 26 2 26 19 28 0 10 3 2 +44 26 7 4 5 6 1 3 30 1 6 22 26 5 0 13 11 28 3 0 26 2 25 24 9 13 25 4 30 7 19 7 17 20 30 28 28 3 1 28 1 8 5 8 23 17 10 +46 25 6 19 14 10 17 11 7 15 30 27 30 10 2 30 0 20 16 12 30 14 25 21 23 23 25 6 13 2 16 23 23 16 24 19 17 1 10 5 29 1 25 3 15 12 9 30 22 +81 8 6 14 8 14 15 14 15 14 30 25 15 14 14 14 0 9 15 6 23 15 15 14 14 15 15 20 14 15 25 23 15 8 28 14 8 21 14 11 14 15 24 0 14 14 15 14 1 16 14 8 20 15 14 19 14 14 15 27 15 30 15 15 15 24 3 4 15 15 14 14 14 26 2 15 16 14 11 25 15 20 22 15 +82 29 8 1 8 2 20 21 0 0 21 21 4 15 21 14 25 21 20 20 21 3 12 21 21 20 21 21 17 21 12 20 21 20 16 12 6 21 20 25 16 28 21 11 18 27 5 16 20 5 21 21 11 19 12 21 3 20 21 21 23 16 6 20 23 11 20 0 20 24 21 27 27 0 3 20 1 1 4 20 6 21 29 21 7 +21 21 2 16 3 3 15 14 5 16 4 14 7 11 14 9 6 14 2 23 23 17 23 4 +71 23 9 4 24 26 9 8 6 20 11 7 18 12 21 20 4 30 22 14 26 4 8 20 12 1 9 20 20 28 20 5 19 7 27 2 29 7 27 11 6 23 27 9 29 22 22 2 3 21 11 20 11 16 9 9 9 10 25 0 28 20 15 5 1 14 10 22 26 24 26 12 25 19 +64 34 6 12 9 12 11 17 10 20 27 13 12 11 29 16 11 28 14 21 9 8 3 0 17 11 22 6 1 2 27 28 13 11 18 7 25 3 15 16 25 4 27 5 5 8 1 28 25 21 7 30 22 7 12 14 18 25 14 7 1 23 24 30 29 21 5 +91 12 7 23 7 2 8 6 29 17 3 14 8 5 27 30 26 29 16 12 12 22 28 18 11 12 30 2 21 7 29 24 29 20 3 18 19 9 20 13 25 6 17 18 30 10 5 20 9 25 19 21 20 20 5 6 18 7 30 30 27 9 23 23 28 3 18 14 1 20 22 23 10 10 20 29 1 14 16 16 18 18 16 21 28 24 20 29 9 4 4 18 9 6 +21 20 1 8 6 12 24 9 3 12 12 17 17 3 16 19 0 4 9 2 28 8 16 15 +42 6 8 20 21 17 14 30 15 10 20 9 17 21 20 20 19 27 20 20 21 28 29 12 20 20 21 20 21 25 18 11 20 24 11 24 30 21 6 0 21 21 18 21 20 +87 8 6 8 12 30 29 3 9 26 15 14 8 15 15 14 30 15 7 14 15 28 15 26 15 15 15 5 14 20 28 0 14 14 14 27 14 12 29 14 3 17 25 15 3 15 14 15 15 15 24 15 15 14 19 14 13 12 15 9 18 7 13 11 14 5 15 8 14 14 24 15 15 29 26 19 24 27 27 14 15 4 14 14 10 16 15 14 15 14 +79 26 4 25 8 20 9 24 9 9 8 12 13 5 9 10 16 12 0 4 13 9 22 13 5 9 9 8 8 9 26 8 8 9 20 28 8 8 9 9 9 27 8 22 9 8 9 9 4 18 20 22 6 23 9 8 18 9 8 8 9 19 17 25 9 8 8 15 9 8 9 23 9 9 8 4 8 8 9 8 8 9 +56 10 6 14 5 22 27 1 14 2 6 17 3 23 29 18 26 22 30 3 12 1 0 14 11 1 23 22 29 25 5 5 1 30 29 20 12 13 29 4 2 16 18 30 1 14 11 18 3 10 17 4 29 26 3 24 9 22 27 +84 84 3 3 14 10 7 3 5 2 28 4 22 6 20 8 26 15 24 14 18 5 4 21 15 22 16 17 27 20 19 17 20 15 3 7 16 12 7 24 10 5 9 24 19 18 10 16 9 13 5 11 6 2 23 19 21 5 3 12 8 3 5 10 10 23 28 16 21 10 5 21 13 21 21 14 21 17 5 17 23 3 23 17 10 11 20 +50 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +100 16 4 21 19 4 21 28 0 28 14 5 4 20 0 6 25 18 4 10 13 16 20 11 12 8 20 11 2 20 18 27 1 5 10 11 22 29 3 23 4 20 20 23 20 28 5 11 5 25 27 5 9 2 29 24 8 22 15 13 4 17 24 21 28 27 30 12 21 5 13 23 14 15 25 30 29 22 17 12 25 27 1 1 28 27 16 15 2 6 13 16 9 8 28 16 17 11 1 22 10 1 10 +63 1 10 27 26 23 26 26 9 26 27 6 6 26 23 26 24 26 27 27 26 27 2 26 27 16 22 27 26 29 26 26 27 27 6 16 13 8 27 8 1 23 25 18 28 19 0 4 5 27 26 26 26 23 27 27 27 23 26 26 12 20 27 8 6 3 +84 24 7 17 17 14 2 14 17 17 10 17 10 18 17 13 17 18 17 18 29 17 29 23 2 10 17 17 5 18 29 20 17 24 0 22 18 17 18 18 0 17 25 23 6 18 5 9 21 18 17 8 7 12 18 13 2 18 17 17 18 17 5 2 18 30 18 26 18 18 11 14 6 18 18 18 18 21 1 17 30 15 16 11 17 17 8 +22 10 8 7 17 1 17 28 8 3 13 3 8 23 16 1 15 12 29 2 23 30 22 25 15 +39 19 4 8 9 9 8 10 30 9 8 8 24 8 17 15 27 9 22 8 8 5 8 8 8 9 9 23 9 19 30 27 9 8 9 26 8 9 9 5 8 0 +59 49 8 24 6 11 26 1 12 8 1 14 28 1 8 13 4 12 10 20 10 3 22 21 9 12 9 1 11 20 15 6 28 11 11 4 17 8 10 7 4 3 5 23 3 22 2 11 8 18 5 8 20 15 24 12 20 20 24 21 20 7 +66 29 9 3 14 25 2 24 20 15 18 30 3 30 18 29 9 26 18 26 12 25 12 23 23 15 3 3 28 17 28 20 29 16 7 5 25 0 25 7 10 14 10 27 3 11 4 12 18 30 13 12 10 13 6 3 4 4 17 3 18 13 17 16 2 11 6 1 27 +96 31 10 15 30 0 7 24 2 16 21 11 23 30 9 2 4 13 7 1 28 27 20 28 13 14 8 26 21 0 22 23 30 27 27 8 8 16 12 13 16 11 11 27 2 16 28 11 18 17 17 27 11 8 12 22 0 24 30 19 30 1 22 22 8 29 23 30 29 10 9 6 20 1 20 8 24 3 23 4 13 12 30 5 22 13 25 5 17 2 27 0 27 11 0 19 12 18 27 +58 0 7 30 12 12 18 18 11 26 17 4 17 20 17 1 26 30 18 18 18 18 17 8 7 11 1 26 18 18 17 17 17 23 24 7 25 18 14 20 17 18 8 27 17 18 18 15 17 17 18 24 6 5 17 17 18 17 18 18 25 +63 38 4 20 18 8 29 22 17 8 8 15 8 29 20 24 28 1 10 21 14 18 21 30 22 13 26 11 5 24 5 30 8 22 17 18 6 17 20 7 27 18 15 14 19 28 1 17 14 13 24 15 10 14 26 0 8 23 23 14 26 13 9 9 11 25 +48 48 8 22 6 23 12 7 2 13 10 14 9 20 16 13 6 8 21 24 12 19 12 11 19 5 8 7 20 19 13 27 10 20 27 26 12 8 18 21 4 26 6 15 26 12 25 2 24 16 3 +1 0 8 26 +39 11 6 15 14 15 12 13 11 18 18 15 15 7 15 7 15 9 15 14 14 8 20 14 14 14 15 12 15 14 25 17 15 22 14 14 14 15 11 29 15 15 +29 0 8 0 21 20 21 2 21 17 20 20 20 21 22 21 21 26 30 20 21 21 30 21 28 20 20 20 21 21 8 23 +88 22 7 17 9 10 17 17 14 19 17 9 17 17 22 18 28 17 18 6 7 17 17 18 3 12 17 18 17 18 17 18 0 18 17 17 16 17 22 18 17 18 30 18 18 18 18 17 17 16 28 18 18 18 17 12 0 17 18 6 29 14 26 13 21 15 8 17 17 17 18 6 7 17 17 18 18 10 4 1 18 16 28 18 17 20 17 17 16 3 17 +59 13 7 21 16 18 8 17 12 17 23 15 24 10 2 17 17 17 7 22 19 0 26 5 30 18 12 8 18 18 17 28 18 17 17 17 17 15 20 25 17 20 17 18 22 17 24 27 9 30 17 11 17 4 9 17 12 17 25 18 18 2 +21 21 7 27 26 16 25 4 5 24 11 25 18 3 26 23 12 12 22 19 11 26 28 11 +10 10 1 21 25 6 21 11 20 23 13 11 16 +78 25 1 18 14 6 28 29 23 1 6 16 25 30 2 29 23 14 12 3 17 26 30 4 16 18 22 28 17 0 26 24 24 14 26 11 2 3 15 12 1 30 24 22 25 11 30 9 17 14 30 10 30 21 13 20 9 16 0 27 5 9 13 3 26 13 6 11 28 20 22 6 6 20 11 27 11 15 5 29 6 +20 2 6 12 19 15 24 15 21 12 29 20 0 14 28 30 25 4 14 25 2 24 28 +47 0 3 15 27 1 12 0 28 11 4 23 18 10 23 27 20 26 6 18 5 30 4 17 11 7 22 15 19 0 3 28 20 21 17 6 2 23 21 2 22 13 29 7 1 21 13 15 23 18 +38 38 7 21 15 20 6 27 20 2 20 12 27 9 2 9 20 24 23 17 20 6 19 14 5 16 11 21 11 24 8 6 5 6 22 17 15 24 16 4 4 +33 27 9 24 17 5 22 10 0 30 29 14 29 20 4 6 26 1 2 7 26 25 16 4 22 26 2 10 3 19 26 13 4 18 12 0 +37 0 9 6 25 22 23 24 1 18 9 29 9 25 8 28 7 7 7 18 29 10 0 21 16 3 24 24 7 3 7 22 11 13 15 20 4 18 7 3 +43 43 0 2 28 24 16 24 19 18 6 19 13 18 28 12 11 22 13 4 17 19 21 16 10 8 17 19 20 3 22 13 18 4 22 9 24 22 17 15 25 9 10 8 8 15 +8 3 2 3 3 27 3 16 2 2 2 +45 8 2 20 2 26 11 28 3 12 7 20 15 2 23 21 17 13 0 2 8 12 26 29 0 5 11 9 19 11 27 17 9 24 27 26 15 0 30 26 13 0 29 25 10 19 1 30 +48 9 8 12 21 20 14 30 21 8 21 25 20 4 20 12 27 20 0 16 29 4 4 22 28 4 26 20 14 1 24 13 21 21 16 4 21 20 19 2 12 20 28 14 20 20 19 20 13 21 27 +71 29 7 0 0 0 28 1 11 3 4 12 3 4 8 20 20 15 22 25 11 21 4 27 29 19 12 22 11 26 11 8 9 27 9 7 23 4 30 3 6 29 24 8 23 5 27 1 17 14 5 20 6 8 13 1 4 17 4 24 6 10 2 20 29 20 8 5 2 8 20 2 8 8 +78 4 7 22 27 24 17 3 16 17 29 27 12 18 10 6 17 18 18 17 12 17 27 18 17 18 18 11 7 18 17 21 3 18 29 17 18 18 18 1 28 18 17 21 18 17 2 29 29 17 26 30 18 12 18 12 15 28 0 16 18 16 14 18 18 1 20 18 27 18 8 17 17 18 18 12 17 18 30 13 7 +14 0 0 14 28 11 28 14 8 17 13 24 18 21 4 21 26 +81 30 3 29 2 30 0 21 10 16 25 16 10 22 8 26 8 19 21 8 30 17 21 22 12 19 18 24 14 14 25 4 16 8 22 0 15 12 26 9 21 29 18 13 20 29 5 28 25 22 6 24 24 25 18 9 9 9 2 4 16 21 25 20 24 3 12 17 10 8 5 27 4 16 7 17 10 26 26 19 10 23 2 27 +49 25 7 23 29 22 15 1 19 7 28 11 29 5 19 9 15 1 15 23 13 0 9 2 11 27 18 5 1 24 22 2 15 18 10 22 29 10 26 30 3 4 7 1 23 19 30 4 16 17 14 29 +38 0 5 22 0 18 13 1 10 9 0 19 4 26 1 3 13 15 21 25 29 1 5 17 3 19 25 19 8 10 23 12 24 9 10 10 10 5 22 20 9 +11 11 7 28 2 23 5 24 6 24 2 19 26 3 +85 0 7 25 7 27 25 16 9 4 10 30 30 21 21 18 20 19 12 11 10 24 14 25 12 23 20 25 8 13 27 4 19 21 14 25 19 5 18 0 18 11 21 2 20 22 15 1 22 6 19 13 14 21 16 25 17 15 19 18 7 9 5 15 13 11 7 16 25 11 12 21 12 23 29 27 27 24 22 17 8 1 5 30 20 13 23 9 +98 28 4 8 10 9 10 24 9 4 3 27 9 26 9 12 28 4 8 8 7 20 28 9 8 7 15 8 12 8 8 5 29 8 9 21 9 16 21 16 8 17 29 30 9 11 30 28 8 9 11 18 8 26 8 8 9 9 29 9 9 8 12 13 9 9 28 9 9 24 8 29 9 9 9 8 5 9 8 9 8 8 4 25 15 8 8 8 10 6 9 1 9 29 8 8 5 9 4 9 9 +32 0 10 21 8 14 30 29 9 9 27 21 10 27 9 3 17 10 23 12 27 17 12 19 15 13 12 8 29 24 18 18 26 20 0 +79 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 +34 34 2 21 10 15 19 9 20 23 4 20 10 15 12 15 26 21 18 19 15 8 12 22 27 4 22 6 22 2 7 2 19 7 16 13 12 +89 33 7 17 21 17 18 18 9 17 0 17 17 17 18 2 30 25 17 20 24 1 17 12 18 17 0 18 18 8 17 18 8 24 30 5 8 17 17 28 18 9 12 17 4 8 7 25 17 17 12 0 12 17 17 25 7 17 18 18 2 28 19 5 18 18 7 21 18 20 4 17 8 17 24 18 17 17 12 18 4 9 17 17 10 18 18 4 17 18 26 18 +44 5 6 1 15 14 14 17 15 1 15 13 15 15 8 14 14 15 15 15 10 16 2 22 21 15 16 18 14 14 15 9 24 14 29 16 14 15 6 14 14 13 3 15 24 8 15 +17 9 5 16 0 20 26 22 1 1 17 13 28 2 9 1 3 28 13 30 +39 27 3 8 23 25 16 7 15 21 4 1 21 7 12 2 21 19 8 29 13 28 1 24 1 30 3 11 20 8 1 7 9 28 24 1 1 15 15 25 1 28 +72 51 9 27 20 20 28 25 8 4 17 23 7 15 27 9 6 26 14 15 19 19 5 4 7 7 27 4 4 18 6 3 1 8 9 16 1 1 2 14 26 29 26 11 3 30 15 6 5 16 7 26 23 2 2 0 15 26 2 12 21 7 8 0 26 10 0 23 22 15 15 1 29 8 13 +98 0 10 4 25 12 12 8 8 27 14 2 28 15 28 1 15 6 4 11 28 2 12 15 8 23 25 27 19 8 0 8 25 16 10 9 24 28 27 14 4 13 23 12 12 0 3 29 3 14 22 13 20 28 0 16 16 8 29 6 28 0 0 20 26 8 27 5 22 11 25 26 30 1 30 23 12 9 19 9 9 25 1 1 23 30 7 19 26 29 3 28 30 30 6 8 3 29 18 22 23 +59 10 10 20 30 3 29 0 30 2 24 29 9 24 17 12 16 11 17 30 12 29 28 0 4 12 11 12 5 8 23 15 21 20 4 15 14 30 6 0 30 24 15 11 14 16 17 3 19 12 26 6 29 14 26 16 9 30 5 14 9 30 +77 44 2 8 0 6 9 17 30 13 27 17 8 21 22 8 12 28 11 0 8 23 23 29 25 7 12 15 7 26 18 11 30 6 16 10 30 29 15 0 7 18 28 16 12 28 18 20 11 8 29 2 6 0 20 1 26 3 27 9 8 24 4 1 5 28 10 15 27 4 6 5 22 12 28 5 22 5 19 4 +71 38 8 28 17 28 27 8 4 15 23 24 19 11 27 2 13 2 22 13 24 0 6 16 24 17 25 21 21 24 26 3 17 5 22 23 26 24 1 13 14 3 2 3 29 17 27 14 9 14 1 3 7 8 30 25 15 6 17 26 14 22 16 30 2 30 5 23 28 28 13 1 1 23 +27 0 7 14 18 7 17 28 18 17 18 5 14 17 22 14 18 11 21 0 17 18 17 17 16 18 17 21 25 17 +45 4 10 26 6 25 10 21 16 13 27 21 1 22 17 14 8 19 17 17 15 6 21 18 28 15 7 26 10 9 0 6 12 22 25 30 23 19 29 8 19 21 8 25 4 11 4 9 +39 6 5 19 8 29 14 17 29 17 4 2 28 0 29 9 2 22 5 27 26 10 29 10 20 12 20 27 7 10 18 7 14 19 2 3 17 27 27 19 10 28 +86 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +79 28 10 26 27 27 11 26 10 27 27 7 26 27 28 17 26 27 26 17 27 28 12 27 7 13 5 26 20 8 27 29 26 26 8 12 26 27 5 27 18 27 27 14 7 26 26 14 11 10 9 27 27 16 26 27 26 21 5 27 0 26 27 6 26 26 27 26 6 26 27 9 8 18 26 27 11 28 1 27 27 26 +68 49 7 18 30 30 2 23 15 21 5 28 6 4 13 3 29 3 25 11 8 10 10 2 21 15 27 16 9 20 17 3 26 19 10 6 29 26 5 10 29 5 11 20 12 1 26 18 26 3 3 20 9 17 12 19 15 5 14 14 20 14 21 21 10 8 1 11 17 30 27 +27 0 10 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 +42 12 9 5 27 4 24 19 21 29 25 16 7 25 17 11 28 13 27 30 14 1 1 10 24 23 25 13 24 0 24 16 16 12 27 4 14 5 14 25 26 24 0 15 29 +57 11 3 6 5 5 17 30 22 0 6 19 5 9 4 5 6 28 6 6 5 17 6 24 22 19 5 26 29 6 5 5 6 5 26 6 28 16 16 27 6 6 10 6 6 22 6 11 4 5 3 14 28 20 29 6 6 3 5 5 +87 7 7 23 18 8 12 15 21 17 17 17 24 26 25 18 3 28 17 28 11 17 16 26 18 18 17 16 8 18 6 11 17 20 18 4 18 18 17 18 18 2 17 5 18 24 17 20 17 11 17 18 22 6 18 18 17 25 5 18 18 25 17 18 6 24 2 1 18 8 18 17 17 18 5 18 17 24 17 17 18 18 17 21 17 10 17 29 11 23 +" +A21607,"package googlejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class DancingWithGooglers { + + private static int N; + private static int S; + private static int p; + private static int[] ts; + private static int[][] memo; + private static int[] maxSupr; + private static int[] maxNotSupr; + + public static void main(String[] args) throws FileNotFoundException { + Scanner sc = new Scanner(new File(""inputB.txt"")); + PrintWriter pw = new PrintWriter(""outputB.txt""); + int T = sc.nextInt(); + + maxSupr = new int[31]; + Arrays.fill(maxSupr, -1); + maxNotSupr = new int[31]; + Arrays.fill(maxNotSupr, -1); + + for (int a = 0; a <= 10; a++) { + for (int b = 0; b <= 10; b++) { + for (int c = 0; c <= 10; c++) { + int s = a + b + c; + if (Math.abs(a - b) <= 2 && Math.abs(b - c) <= 2 && Math.abs(c - a) <= 2) { + int max = Math.max(a, Math.max(b, c)); + if (Math.abs(a - b) == 2 || Math.abs(b - c) == 2 || Math.abs(c - a) == 2) { + maxSupr[s] = Math.max(maxSupr[s], max); + } else { + maxNotSupr[s] = Math.max(maxNotSupr[s], max); + } + } + } + } + } + + for (int t = 1; t <= T; t++) { + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + ts = new int[N]; + for (int i = 0; i < ts.length; i++) { + ts[i] = sc.nextInt(); + } + + memo = new int[N + 1][S + 1]; + for (int[] m : memo) { + Arrays.fill(m, -1); + } + + int max = getMax(0, S); + pw.println(""Case #"" + t + "": "" + max); + } + pw.flush(); + pw.close(); + } + + public static int getMax(int index, int surpr) { + int res = memo[index][surpr]; + if (res == -1) { + if (index == N) { + if (surpr == 0) { + res = 0; + } else { + res = -1000; + } + } else { + // not suprised + res = (maxNotSupr[ts[index]] >= p ? 1 : 0) + getMax(index + 1, surpr); + + if (surpr > 0 && maxSupr[ts[index]] != -1) { + // suprised + res = Math.max(res, (maxSupr[ts[index]] >= p ? 1 : 0) + getMax(index + 1, surpr - 1)); + } + + } + memo[index][surpr] = res; + } + return res; + } +} +" +A21554,"import java.util.Scanner; +import java.io.File; + +public class ScoreAnalyzer + { + + public void analyzeInputFile(String fileName) throws Exception + { + Scanner fileScanner = new Scanner (new File (fileName) ); + + String line; + + line = fileScanner.nextLine(); + + int numberOfTestCases = Integer.parseInt(line.trim()); + + int N,S,p; + + for(int i = 1; i<= numberOfTestCases ; i++) + { + line = fileScanner.nextLine(); + + Scanner lineScanner = new Scanner(line); + + N = Integer.parseInt(lineScanner.next().trim()); + S = Integer.parseInt(lineScanner.next().trim()); + p = Integer.parseInt(lineScanner.next().trim()); + + // System.out.println(""N= ""+N+ "" S = ""+S + "" p = ""+p); + + int noSurpriseLowerLimitScore; + int surpriseLowerLimitScore; + int surpriseHigherLimitScore; + + noSurpriseLowerLimitScore = 3*p - 2; + surpriseLowerLimitScore = 3*p - 4; + surpriseHigherLimitScore = 3*p - 3; + + // System.out.println(""3p-2 = ""+noSurpriseLowerLimitScore); + // System.out.println(""3p-4 = ""+surpriseLowerLimitScore); + // System.out.println(""3p-3 = ""+surpriseHigherLimitScore); + + + int googlersWithBestResultOfAtLeastP = 0; + int numberOfSurpriseScoresLeft = S; + + for(int j=1; j<=N ; j++) + { + int googlerScore = Integer.parseInt(lineScanner.next().trim()); + + if(googlerScore >= p) + { + + // System.out.println(""googlerScore = ""+googlerScore+"" ""); + + if(googlerScore >= noSurpriseLowerLimitScore) + { + googlersWithBestResultOfAtLeastP++; + continue; + } + + if(numberOfSurpriseScoresLeft > 0 ) + { + if(googlerScore >= surpriseLowerLimitScore && googlerScore <= surpriseHigherLimitScore) + { + googlersWithBestResultOfAtLeastP++; + numberOfSurpriseScoresLeft--; + } + } + } + } + + System.out.println(""Case #""+i+"": ""+googlersWithBestResultOfAtLeastP); + } + } + + + + public static void main(String[] args) throws Exception + { + ScoreAnalyzer SA = new ScoreAnalyzer(); + String inputFile = ""B-large.in""; + + SA.analyzeInputFile(inputFile); + } + }" +A22335,"import java.io.*; +import java.util.*; + +/** + * @author OleGG + */ +public class QualTaskB { + public static void main(String[] args) throws Throwable { + StreamTokenizer st = new StreamTokenizer(new BufferedReader(new FileReader(""B-large.in.txt""))); + PrintWriter pw = new PrintWriter(new FileWriter(""B-large.out.txt"")); + //StreamTokenizer st = new StreamTokenizer(new InputStreamReader(System.in)); + st.nextToken(); + int t = (int)st.nval; + + for (int test = 1; test <= t; ++test) { + st.nextToken(); + int n = (int)st.nval; + st.nextToken(); + int s = (int)st.nval; + st.nextToken(); + int p = (int)st.nval; + + int[] val = new int[n]; + for (int i = 0; i < n; ++i) { + st.nextToken(); + val[i] = (int)st.nval; + } + + int[][] dyn = new int[n + 1][s + 1]; + for (int i = 0; i <= n; ++i) { + Arrays.fill(dyn[i], 0); + } + + for (int i = 0; i < n; ++i) { + dyn[i + 1][0] = dyn[i][0]; + if ((val[i] + 2) / 3 >= p) { + ++dyn[i + 1][0]; + } + + for (int j = 0; j < s; ++j) { + int add = (val[i] + 2) / 3 >= p ? 1 : 0; + int addS = Integer.MIN_VALUE; + if (val[i] >= 2 && val[i] <= 28) { + switch (val[i] % 3) { + case 0: + case 1: + addS = val[i] / 3 + 1 >= p ? 1 : 0; + break; + case 2: + addS = val[i] / 3 + 2 >= p ? 1 : 0; + break; + } + } + dyn[i + 1][j + 1] = Math.max(dyn[i][j+1] + add, dyn[i][j] + addS); + } + } + pw.printf(""Case #%d: %d\n"", test, dyn[n][s]); + } + pw.close(); + } +} +" +A21771,"package googleJam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class GoogleDancers +{ + + public static void main(String[] args) + { + Scanner scan = null; + try + { + scan = new Scanner(new File(args[0])); + } + catch (FileNotFoundException e) + { + System.err.println(""File not found!""); + return; + } + if (!scan.hasNext()) + { + System.err.println(""Nothing in File!""); + return; + } + int testCases = Integer.parseInt(scan.nextLine()); + String[] line; + String str; + int theFabulousGoogleDancers; + int soManySurprises; + int whoIsBetterThanMe; + int itsAStretch; + int noSurpriseNeeded; + int iAmBetterThanYou; + int canReachWithSurprise; + int number = 1; + int combined; + while (scan.hasNext()) + { + System.out.print(""Case #"" + number + "": ""); + iAmBetterThanYou = 0; + itsAStretch = 0; + str = scan.nextLine(); + line = str.split("" ""); + theFabulousGoogleDancers = Integer.parseInt(line[0]); + soManySurprises = Integer.parseInt(line[1]); + whoIsBetterThanMe = Integer.parseInt(line[2]); + noSurpriseNeeded = (whoIsBetterThanMe + (whoIsBetterThanMe-1) + (whoIsBetterThanMe-1)); + canReachWithSurprise = (whoIsBetterThanMe + (whoIsBetterThanMe-2) + (whoIsBetterThanMe - 2)); + if (whoIsBetterThanMe == 1) + { + noSurpriseNeeded = 1; + canReachWithSurprise = 1; + } + if (whoIsBetterThanMe == 0) + { + noSurpriseNeeded = 0; + canReachWithSurprise = 0; + } + for (int score = 3; score < line.length; score++) + { + if ((Integer.parseInt(line[score])) >= canReachWithSurprise && Integer.parseInt(line[score]) < noSurpriseNeeded) + { + itsAStretch++; + } + else if (Integer.parseInt(line[score]) >= noSurpriseNeeded) + { + iAmBetterThanYou++; + } + } + if (itsAStretch <= soManySurprises) + { + combined = iAmBetterThanYou + itsAStretch; + } + else + { + combined = iAmBetterThanYou + soManySurprises; + } + + System.out.print(combined); + if(scan.hasNext()) + { + System.out.println(); + } + number++; + } + } + +} +" +A21478,"package pl.helman.codejam.dancing; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class Dancing { + + public static void main(String[] args) throws IOException { + + FileReader fr = new FileReader(""d:\\dancing.in""); + BufferedReader br = new BufferedReader(fr); + String line = br.readLine(); + + FileWriter f0 = new FileWriter(""d:\\dancing.out""); + + // number of cases + int t = Integer.parseInt(line.trim()); + + for (int c = 1; c <= t; c++) { + System.out.println(); + + line = br.readLine(); + String[] elems = line.split("" ""); + + // number of dancers + int n = Integer.parseInt(elems[0]); + + // number od surprises + int s = Integer.parseInt(elems[1]); + + // points + int p = Integer.parseInt(elems[2]); + + System.out.println("" n:""+n+"" p:""+p+"" s:""+s); + + int ret = 0; + + for (int i = 0; i < n; i++) { + int w = Integer.parseInt(elems[3 + i]); + + + // max not surprising note + int m = (w + 2) / 3; + + System.out.print("" w:""+w+"" m:""+m+"" m%3:""+m%3+"" s:""+s); + + if (m >= p) { + ret++; + System.out.print("" +1""); + } else if (w>0 && (m == p - 1) && ((w % 3) != 1) && (s > 0)) { + s--; + ret++; + System.out.print("" +2""); + } + System.out.println(); + + } + + + + System.out.println(""Case #"" + c + "": "" + ret); + f0.write(""Case #"" + c + "": "" + ret + ""\r\n""); + } + + fr.close(); + f0.close(); + + } + +} +" +A20917,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; + + +public class Writer { + private String fileName; + private BufferedWriter writer; + private int i = 1; + + public Writer(String fileName){ + this.fileName = fileName; + } + + public void open() throws Exception{ + writer = new BufferedWriter(new FileWriter(new File(fileName))); + } + + public void close() throws Exception{ + writer.close(); + } + + public void write(String erg) throws Exception{ + writer.write(""Case #"" + i +"": "" + erg + ""\n""); + i++; + } +} +" +A20562,"import java.util.*; +import java.io.*; + +public class B { + public static int solve(int T, int P) { + int[] score = new int[3]; + + score[0] = T/3; + score[1] = (T-score[0]) / 2; + score[2] = (T-score[0]-score[1]); + + Arrays.sort(score); + int dif = score[2] - score[0]; + + if (dif > 2) { + System.err.println(""ERROR""); + System.exit(-1); + } + //System.err.println(""BEFORE ARRANGE NUM ""+T+"": ""+score[0]+"" ""+score[1]+"" ""+score[2]); + + if (score[2] >= P) { + if (dif == 2) return 1; + else return 0; + } + + // try to make it interesting + if (dif < 2) { + score[2]++; + score[1]--; + Arrays.sort(score); + dif = score[2] - score[0]; + } + + if (score[0] < 0 || score[0] > 10 || score[1] < 0 || score[1] > 10 || score[2] < 0 || score[2] > 10 || dif > 2) { + return -1; + } + + //System.err.println(""AFTER ARRANGE NUM ""+T+"": ""+score[0]+"" ""+score[1]+"" ""+score[2]); + + if (score[2] >= P) { + if (dif == 2) return 1; + else return 0; + } + + return -1; + } + + public static void main(String[] args) throws Exception{ + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + int N, S, P, used, can; + + for(int caseNo = 1;caseNo <= T; caseNo++) { + N = in.nextInt(); + S = in.nextInt(); + P = in.nextInt(); + used = 0; + can = 0; + + for(int i=0;i= p){ + max++; + continue; + } + if(avg == p - 1 && mod > 0){ + max++; + continue; + } + if(mod == 1){ + continue; + } + if(avg == p - 2 && mod == 2 && s > 0 && ges >= 2){ + max++; + s--; + continue; + } + if(avg == p - 1 && mod == 0 && s > 0 && ges >= 2){ + max++; + s--; + continue; + } + } + writer.write("""" + max); + } + reader.close(); + writer.close(); + } +} +" +A21746,"package com.gdacarv.codejam; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class ProblemB { + + public static void main(String [ ] args){ + + try{ + FileInputStream fstream = new FileInputStream(""input_problemB.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String input = new String(); + String line; + while ((line = br.readLine()) != null) + input += line + '\n'; + System.out.println(input); + System.out.println(solveProblemB(input)); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + } + + private static String solveProblemB(String input) { + String result = new String(); + String[] lines = input.split(""\n""), numbers; + int len = Integer.parseInt(lines[0]); + int N, S, p, qt, num; + for(int i = 1; i <= len; i++){ + result += ""Case #"" + i + "": ""; + numbers = lines[i].split("" ""); + N = Integer.parseInt(numbers[0]); + S = Integer.parseInt(numbers[1]); + p = Integer.parseInt(numbers[2]); + qt = 0; + for(int j = 3; j < 3+N; j++){ + num = Integer.parseInt(numbers[j]); + if(p == 0){ + qt++; + }else if(p == 1){ + if(num > 0) + qt++; + }else if(num / p >= 3 || (num-1) / (p-1) >= 3){ + qt++; + }else if(S > 0 && num - p - 2*(p-2) >= 0){ + qt++; + S--; + } + } + result += qt + ""\n""; + } + return result; + } +} +" +A22037,"import java.util.Scanner; + +public class Dancing_With_the_Googlers { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int T = 0; + while (scanner.hasNextInt()) { + T = scanner.nextInt(); + break; + } + + for (int t = 0; t <= T; t++) { + if (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (!line.isEmpty()) { + String[] g = line.split("" ""); + int N = Integer.parseInt(g[0]); + int s = Integer.parseInt(g[1]); + int p = Integer.parseInt(g[2]); + + int minS = p + (p - 2) + (p - 2); + int noS = p + (p - 2) + (p - 2) + 2; + + int output = 0; + int total = 0; + + for (int i = 3; i <= N + 2; i++) { + if (Integer.parseInt(g[i]) >= noS) { + output++; + } else if (Integer.parseInt(g[i]) < noS && Integer.parseInt(g[i]) >= minS) { + if(Integer.parseInt(g[i])==0){ + continue; + } + total++; + } + } + if (total == s) { + output += total; + } + else if(s==0){ + + }else if (total >=s) { + if(output==0) + output=s; + else + output += (total - s); + }else if (total 2) { + // Check if this is doable at all + if (difference > 4) { + // No way, this is not doable + solution = false; + }else { + // Can't do without lifeline. Check if lifeline is available + if (noOfSurprisingTripletsAllowed > 0) { + // Uselifeline and done. + noOfSurprisingTripletsAllowed --; + solution = true; + }else { + // No lifeline available + solution = false; + } + } + }else { + // Can do without lifeline + solution = true; + } + } + + return solution; + } + + public int solveTestCase(String input) { + + System.out.println(""\n\n\n\nWill solve input string :: "" + input); + + StringTokenizer tokenizer = new StringTokenizer(input, "" ""); + + int noOfGooglers = -1; + int bestScore = -1; + int solution = 0; + + int tokenCount = 0; + while (tokenizer.hasMoreElements()) { + tokenCount ++; + + String token = (String) tokenizer.nextElement(); + if (tokenCount == 1) { + lifelineAvailable = true; + noOfGooglers = Integer.parseInt(token); + System.out.println(""no of googlers :: "" + noOfGooglers); + }else if (tokenCount == 2) { + noOfSurprisingTripletsAllowed = Integer.parseInt(token); + System.out.println(""no of surprising triplets allowed :: "" + noOfSurprisingTripletsAllowed); + }else if (tokenCount == 3) { + bestScore = Integer.parseInt(token); + System.out.println(""required best score :: "" + bestScore); + }else { + // This is a googlers score. Check if it meets criteria + int perfectTotal = bestScore * 3; + int score = Integer.parseInt(token); + boolean didMeetCriteria = false; + + if (perfectTotal == score) { + didMeetCriteria = true; + }else if(perfectTotal > score) { + didMeetCriteria = checkIfTotalScoreMeetsCriteria(Integer.parseInt(token), bestScore); + }else if (perfectTotal < score) { + int difference = score - perfectTotal; + while(difference > 4) { + perfectTotal += 3; + difference = score - perfectTotal; + } + didMeetCriteria = checkIfTotalScoreMeetsCriteria(Integer.parseInt(token), bestScore); + } + + System.out.println(""check if score meets criteria :: "" + score); + + if (didMeetCriteria) { + solution ++; + System.out.println(""Criteria met, solution count :: "" + solution); + }else { + System.out.println(""Didnt meet criteria""); + } + } + } + + return solution; + } + + /** + * @param args + */ + public static void main(String[] args) { + + if (args.length < 2) { + System.out.println(""Not enough command line arguments specified. Need 2 (Input and output file paths)""); + return; + } + + String inputFilePath = args[0]; + try { + // String buffer for storing the output + StringBuffer output = new StringBuffer(); + + // Instantiate object to use non static methods + DancingWithGooglers dance = new DancingWithGooglers(); + + // read and parse input file + FileInputStream fstream = new FileInputStream(inputFilePath); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + int lineNumber = 0; + int noOfTestCases = -1; + int activeTestCaseNumber = 0; + while ((strLine = br.readLine()) != null) { + + if (lineNumber == 0) { + noOfTestCases = Integer.parseInt(strLine); + } else { + noOfTestCases ++; + activeTestCaseNumber ++; + // Now that a test case has been parsed, compute output for + // this test case + + // Invoke algorithm here + int solutionToTestCase = dance.solveTestCase(strLine); + + // Prepare output string + System.out.println(solutionToTestCase); + output.append(""Case #"" + activeTestCaseNumber + "": "" + solutionToTestCase); + output.append(""\n""); + } + lineNumber++; + } + + in.close(); + + // Pass output string to method to write to file + dance.writeOutputToFile(output.toString(), args[1]); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + // File read cleanup + } + } +}" +A22967,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Dance { + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + for (int i = 0; i < t; i++) { + String[] str = br.readLine().split("" ""); + int n = Integer.parseInt(str[0]); + int s = Integer.parseInt(str[1]); + int p = Integer.parseInt(str[2]); + int[] tis = new int[n]; + for (int j = 0; j < tis.length; j++) { + tis[j] = Integer.parseInt(str[3+j]); + } + + System.out.println(""Case #"" + (i + 1) + "": "" + find(n,s,p,tis)); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static int find(int n, int s, int p, int[] tis) { + Arrays.sort(tis); + int normalScore = Math.max(3*p-2, 0); + int surpriseScore = 3*p-4; + if (surpriseScore < 0) surpriseScore = normalScore; + int ind = tis.length-1; + for (; ind >= 0 && tis[ind] >= normalScore; ind--); + for (int i=0; ind >= 0 && i < s && tis[ind] >= surpriseScore; ind--, i++); + return n-ind-1; + } +} +" +A22351," +import java.util.Scanner; +import java.io.*; +import java.util.LinkedList; + +/** + * A program to simulate a Snapper + * + * + * @see Google CodeJam + * + * @since 8 may 2010 + * @version 1.0 + * @author ididi, Jeroen van Oorschot + */ +public class Dancers { + + Scanner sc; + String fileName = ""B-large""; + File file = new File(fileName + "".in""); + FileWriter out; + PrintWriter output; + /* the snapper checker + * + * @pre true + * @post true + */ + + public void snapper() { + try { + sc = new Scanner(file); + } catch (FileNotFoundException e) { + System.out.println(""no input file found""); + System.out.println(fileName + "".in""); + } + try { + out = new FileWriter(fileName + "".out""); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + output = new PrintWriter(out); + int tries = sc.nextInt(); + sc.nextLine(); + for (int i = 1; i <= tries; i++) { + output.print(""Case #"" + i + "": ""); + run(); + output.println(); + } + try { + out.close(); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + + + } + + public void run() { + int n = sc.nextInt(); + int s = sc.nextInt(); + final int p = sc.nextInt(); + int ans = 0; + for (int i = 0; i < n; i++) { + int t = sc.nextInt(); + if (t / 3 >= p) { + ans++; + } else if (t / 3 == p - 2 && t % 3 == 2 && s > 0) { + ans++; + s--; + } else if (t / 3 == p - 1) { + if (t % 3 == 2 || t % 3 == 1) { + ans++; + } else if (s > 0 && t > 0) { + ans++; + s--; + } + } + } + output.print(ans); + } + + public static void main(String[] args) { + new Dancers().snapper(); + } +} +" +A20293,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + + +public class DancingwithGooglers { + public static void main(String args[]) throws IOException{ + String inputFile = args[0]; + String outputFile = args[1]; + BufferedReader input = new BufferedReader(new FileReader(inputFile)); + PrintWriter output = new PrintWriter(outputFile); + + int testcases = Integer.valueOf(input.readLine()); + int testcase = 0; + while (testcase++ < testcases) { + int result = 0; + String newline = input.readLine(); + String[] tokens = newline.split("" ""); + int N = Integer.valueOf(tokens[0]); + int S = Integer.valueOf(tokens[1]); + int p = Integer.valueOf(tokens[2]); + int i; + for (i = 0; i < N; i++) { + int score = Integer.valueOf(tokens[i + 3]); + int highest = (score + 2) / 3; + int possible = (score + 4) / 3; + if (highest >= p) + result++; + else if (possible >= p && possible <= score && S > 0) { + result++; + S--; + } + } + + output.printf(""Case #%d: %d\n"", testcase, result); + } + + output.close(); + } +} +" +A22019,"import java.util.*; + +public class Dancing { + static int[] topS; + static int[] topN; + public static void main(String[] args){ + Scanner reader = new Scanner(System.in); + fill(); + int times = reader.nextInt(); + for(int k = 1; k <= times; k++){ + int n = reader.nextInt(); + int s = reader.nextInt(); + int p = reader.nextInt(); + + int[] t = new int[n]; + for(int i = 0; i < n; i++) + t[i] = reader.nextInt(); + + int cnt = 0; + for(int i = 0; i < n; i++){ + if(topN[t[i]] >= p){ + cnt++; + }else if(topS[t[i]] >= p && s > 0){ + cnt++; + s--; + } + } + + System.out.println(""Case #""+k+"": ""+cnt); + } + } + + public static void fill(){ + topS = new int[31]; + topN = new int[31]; + Arrays.fill(topS, -1); + for(int n = 0; n <= 30; n++) + for(int i = 0; i <= 10; i++) + for(int j = i; j <= Math.min(i+2,10) && i+j <= n && n-i-j <= 10; j++){ + if((Math.abs(i-(n-i-j)) <= 2 && Math.abs(j-(n-i-j)) <= 2) && (Math.abs(i-(n-i-j)) == 2 || Math.abs(j-(n-i-j)) == 2 || j-i==2)){ + topS[n] = Math.max(topS[n], Math.max(i,Math.max(j,n-i-j))); + }else if(Math.abs(i-(n-i-j)) <= 2 && Math.abs(j-(n-i-j)) <= 2){ + topN[n] = Math.max(topN[n], Math.max(i,Math.max(j,n-i-j))); + } + } + } +} +" +A22730,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; + + +public class GoogleDancers { + + public static void main(String[] args){ + + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(args[0]); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + int numTest = Integer.parseInt(br.readLine()); + for(int i = 0; i < numTest; i ++){ + String str = br.readLine(); + String numbers[] = str.split("" ""); + int num = Integer.parseInt(numbers[0]); + ArrayList scoreIntegers = new ArrayList(); + for(int sc = 3; sc < numbers.length; sc++){ + scoreIntegers.add(new Integer(numbers[sc])); + } + int surpriseScorers= Integer.parseInt(numbers[1]); + int bestScore= Integer.parseInt(numbers[2]); + int currentSurpriseScorers = 0; + int currentBestScorers = 0; + int answer = 0; + ArrayList canBeTurnedToSurprise = new ArrayList(); + ArrayList canBeTurnedToBestScore = new ArrayList(); + + ArrayList tupleScores = bestResult(scoreIntegers); + for(JudgeScoreTuple tuple : tupleScores){ + JudgeScores jsNonSurprise = tuple.getNonSurprise(); + if(jsNonSurprise!=null){ + if(jsNonSurprise.getMaxScore() >= bestScore){ + currentBestScorers ++; + if(tuple.getSurprise()!=null){ + canBeTurnedToSurprise.add(tuple); + } + } + } + else{ + if(tuple.getSurprise().getMaxScore() >= bestScore){ + currentBestScorers++; + } + currentSurpriseScorers++; + } + if(!canBeTurnedToSurprise.contains(tuple)){ + JudgeScores jsSurprise = tuple.getSurprise(); + if(jsSurprise!=null){ + if(jsSurprise.getMaxScore()>=bestScore){ + canBeTurnedToBestScore.add(tuple); + } + } + } + + } + + if(currentSurpriseScorers == surpriseScorers){ + answer = currentBestScorers; + } + + + if(currentSurpriseScorers < surpriseScorers){ + answer = currentBestScorers + Math.min(surpriseScorers, canBeTurnedToBestScore.size()); + } + + int x = i + 1; + System.out.println(""Case #"" + x + "": "" + answer); + + + } + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + + } + + public static ArrayList bestResult(ArrayList scoreIntegers){ + ArrayList possibleJudgeScores = new ArrayList(); + for(Integer i : scoreIntegers){ + int sumJudgeScore = i.intValue(); + JudgeScores jc1 = null; + JudgeScores jc2 = null; + if(sumJudgeScore % 3 == 0){ + jc1 = new JudgeScores(sumJudgeScore/3, sumJudgeScore/3, sumJudgeScore/3); + if(sumJudgeScore/3 + -1 >=0 && sumJudgeScore/3 + 1 <= 10) + jc2 = new JudgeScores(sumJudgeScore/3 -1 , sumJudgeScore/3, sumJudgeScore/3 + 1, true); + } + if(sumJudgeScore % 3 == 1){ + if(sumJudgeScore/3 + 1 <= 10){ + jc1 = new JudgeScores(sumJudgeScore/3, sumJudgeScore/3, sumJudgeScore/3 + 1); + if(sumJudgeScore/3 + -1 >=0) + jc2 = new JudgeScores(sumJudgeScore/3 +1 , sumJudgeScore/3 + 1, sumJudgeScore/3 -1, true); + } + } + if(sumJudgeScore % 3 == 2){ + if(sumJudgeScore/3 + 1 <= 10) + jc1 = new JudgeScores(sumJudgeScore/3 +1 , sumJudgeScore/3 + 1, sumJudgeScore/3 ); + if(sumJudgeScore/3 + 2 <= 10) + jc2 = new JudgeScores(sumJudgeScore/3, sumJudgeScore/3, sumJudgeScore/3 + 2, true); + + } + possibleJudgeScores.add(new JudgeScoreTuple(jc1, jc2)); + } + + return possibleJudgeScores; + } + + +} + +" +A20933,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + + +public class Dancing { + public static void main(String...args) throws IOException { + //the result file + PrintWriter writer = new PrintWriter(new FileWriter(""c:\\jam\\B-large.out"")); + //reading input file the file + BufferedReader reader = new BufferedReader(new FileReader(""c:\\jam\\B-large.in"")); + //Reading cases number + int count = Integer.parseInt(reader.readLine()); + //Iterating over the cases + for(int k=1;k value3){ + res++; + } + } else if(numberS >= surprisingT){ + if(score > value2){ + res++; + } + } + } + writer.println(""Case #"" + k + "": "" + res); + } + + reader.close(); + writer.close(); + } +} +" +A21074,"package code_jam_quali; + +import java.util.Scanner; + +/** + * + * @author sansarun + */ +public class Dancing { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int caseNum = sc.nextInt(); + + for (int currentCase = 1; currentCase <= caseNum; currentCase++) { + int googlers = sc.nextInt(); + int surprise = sc.nextInt(); + int p = sc.nextInt(); + + int alreadyPass = 0; + int canHelp = 0; + + for (int i = 0; i < googlers; i++) { + int totalScore = sc.nextInt(); + int maxCompound = findMaxCompound(totalScore); + int fragment = totalScore % 3; + + if (totalScore < 3) { + if(findMaxCompound(totalScore) >= p) { + alreadyPass++; + } + } else { + switch (fragment) { + case 1: + if (maxCompound >= p) { + alreadyPass++; + } + break; + case 0: + case 2: + if (maxCompound >= p) { + alreadyPass++; + } else if (maxCompound + 1 >= p) { + canHelp++; + } + break; + } + } + } + int totalPass = alreadyPass + (canHelp > surprise ? surprise : canHelp); + System.out.println(String.format(""Case #%d: %d"", currentCase, totalPass)); + } + } + + private static int findMaxCompound(int n) { + return (int) Math.round(Math.ceil(n / 3.0)); + } +} +" +A23016,"package tr0llhoehle.cakemix.utility.googleCodeJam; + +/** + * Describes all Types currently supported. + * + * @author Cakemix + * + */ +public enum SupportedTypes { + INT, DOUBLE, BOOLEAN, STRING, LIST_INT, LIST_DOUBLE, LIST_BOOLEAN, LIST_STRING +} +" +A22649,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package CodeJam2012; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * + * @author asha.j + */ +public class DancingGooglers { + + + public static void main(String[] args) throws IOException { + String filename= ""B-large""; + Scanner scanner= new Scanner(new File(""D:\\codejam\\""+filename+"".in"")); + BufferedWriter writer= new BufferedWriter(new FileWriter(""D:\\codejam\\""+filename+"".out"")); + int numOfCases = scanner.nextInt(); + int noOfGooglers; + int surpriseScoreCount; + int p; + int countAboveP=0; + ArrayList list= new ArrayList(); + for(int i=1;i<=numOfCases;i++){ + list.clear(); + countAboveP=0; + noOfGooglers= scanner.nextInt(); + surpriseScoreCount= scanner.nextInt(); + p= scanner.nextInt(); + for(int m=0;m list,int surprising, int p){ + //System.out.println(""processCase:""+list+"" sur:""+surprising+"" p:""+p); + int third; + int reminder; + int countAboveP=0; + for(int score: list){ + third= score/3; + reminder= score%3; + if(score==0){ + if(p==0){ + ++countAboveP; + } + continue; + } + if(third>=p){ + ++countAboveP; + }else if(reminder==0){ + if(third+1 >=p && surprising>0){ + --surprising; + ++countAboveP; + } + }else if(reminder==1){ + if(third+1 >=p){ + ++countAboveP; + } + }else if(reminder==2){ + if(third+1 >=p){ + ++countAboveP; + }else if(third+2 >=p && surprising>0){ + --surprising; + ++countAboveP; + } + } + } + return countAboveP; + } +} +" +A21205,"import java.util.*; +import java.lang.*; +import java.io.*; +import static java.lang.System.*; + +public class Dancing{ + static int bestScore(int s){ + int[] arr = {10, 10, 10}; + int idx = 0; + for(int sum = 30; sum!=s; sum--, idx++){ + arr[idx%3]--; + } + return arr[2]; + } + static int bestSurprisingScore(int s){ + int S = s-2; + int a, b = 0; + for(a=8; a>=0 ; a--){ + b = S-2*a; + if(b>=a && b<=(a+2)){ + break; + } + } + if(b(a+2)){ + return -1; + } + return a+2; + } + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + int xx = Integer.parseInt(br.readLine()); + for(int yy=0; yy arr = new ArrayList(); + for(int i=0; i=p){ + nbest++; + }else if(arr.get(i).sbest>=p){ + nsbest++; + } + } + if(nsbest<=s){ + out.printf(""Case #%d: %d\n"", yy+1, nbest+nsbest); + }else{ + out.printf(""Case #%d: %d\n"", yy+1, nbest+s); + } + } + } + static class Googler{ + int best; + int sbest; + Googler(int best, int sbest){ + this.best = best; + this.sbest = sbest; + } + public String toString(){ + return String.format(""Best: %d SBest: %d"", best, sbest); + } + } +}" +A21331,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.PriorityQueue; + + +/* + * constraints + * input: + * testcases 1<= T <= 100 + * surprising triplets 0<=S<=N + * desired at least result p 0<=p<=10 + * total points for each googler 0<=ti<= 30 + * + * small + * N is between 1 and 3 + * large + * N is between 1 and 100 + */ +public class DancingScores { + + public int numTestCases = -1; + public ArrayList contestants=null; + public int numGooglers = -1; + public int surpriseTrips = -1; + public int p=-1; + public ArrayList answer; + /** + * @param args + */ + public static void main(String[] args) throws IOException{ + + DancingScores ds = new DancingScores(); +// ds.parse(""B-small-attempt4.in""); + ds.parse(""B-large.in""); + } + + public void parse(String filename) throws IOException{ + FileReader inputStream = null; + FileWriter outputStream = null; + BufferedReader br = null; + PrintWriter pw = null; + try{ + inputStream = new FileReader(filename); + outputStream = new FileWriter(""result.txt""); + br = new BufferedReader(inputStream); + pw = new PrintWriter(outputStream); + numTestCases = Integer.parseInt(br.readLine()); + + for(int i=1;i<=numTestCases;i++){ + String inputLine = br.readLine(); + pw.println(""Case #""+i+"": ""+solve(inputLine)); +// pw.println(inputLine); +// +// for(Googler g: contestants){ +// pw.print(g.score1>=p); +// pw.print("" ""); +// pw.print(g); +// } +// +// pw.println(); + } + } + finally{ + if(inputStream != null){ + inputStream.close(); + } + if(outputStream != null){ + outputStream.close(); + } + } + } + + public int solve(String inputLine){ + String[] tokens = inputLine.split(""[ ]+""); + + numGooglers = Integer.parseInt(tokens[0]); + surpriseTrips = Integer.parseInt(tokens[1]); + p = Integer.parseInt(tokens[2]); + contestants = new ArrayList(numGooglers); + + for(int j=3;j pass = new ArrayList(); + PriorityQueue fail = new PriorityQueue(); + + //separate those that already pass + for(Googler person: contestants){ + if(person.passes(p)) + pass.add(person); + else + fail.offer(person); + } + + //sort failed based on their best result (want highest to add) + //use remaining surprises to try and make them match + while(fail.peek()!=null && surpriseTrips>0){ + Googler next = fail.peek(); + next.modify(); + if(next.passes(p)){ + pass.add(next); + + } + surpriseTrips--; + fail.remove(); + } + +// for(Googler goog: pass){ +// //System.out.println(goog); +// } +// for(Googler goog:contestants){ +// if(goog.checkState()) +// System.out.println(""true""); +// else +// System.out.println(""false""); +// } +// answer = pass; + return pass.size(); + } + +} +" +A21120,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package leider.ken; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Callable; + + + + +/** + * + * @author ken + */ +class DancingAlgorithm implements Callable { + private final int caseNumber; + private final long surprises; + private final long minScore; + private final List totals; + + public DancingAlgorithm(int caseNumber, long surprises, long minScore, List totals) { + this.caseNumber = caseNumber; + this.surprises = surprises; + this.minScore = minScore; + this.totals = totals; + + } + + + public String call() throws Exception { + long meetsCount = 0; + long meetsWithSurpriseCount = 0; + + for (Long total : totals) { + double avgOther = (total - minScore)/ 2.0; + long min = (long) Math.floor(avgOther); + if (min < 0) continue; + if (min + 1 >= minScore) { + meetsCount++; + } else if (min + 2 >= minScore) { + meetsWithSurpriseCount++; + } + } + + long retval = meetsCount + Math.min(meetsWithSurpriseCount, surprises); + return String.format(""Case #%d: %d"", caseNumber, retval); + } + + @Override + public String toString() { + return totals.toString(); + } + + +} +" +A20764,"package dancing_with_googlers; + + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.IOException; +import java.util.*; + +public class ReadWriteTextFile { + + public static ArrayList doReadTextFile(String filename) { + String inLine = null; + ArrayList inLines = new ArrayList(); + try { + + // Create FileReader Object + FileReader inputFileReader = new FileReader(filename); + + // Create Buffered/PrintWriter Objects + BufferedReader inputStream = new BufferedReader(inputFileReader); + + + while ((inLine = inputStream.readLine()) != null) { + inLines.add(inLine); + } + inputStream.close(); + } catch (IOException e) { + System.out.println(""IOException:""); + e.printStackTrace(); + } + + return inLines; + } + + public static void doWriteTextFile(ArrayList result) { + try { + // output file names + String outputFileName = ""B-large.out""; + + // Create FileReader Object + FileWriter outputFileReader = new FileWriter(outputFileName); + + // Create Buffered/PrintWriter Objects + PrintWriter outputStream = new PrintWriter(outputFileReader); + + int i = 1; + for (String s: result) { + outputStream.print(""Case #"" + i + "": ""); + if (i scores = new LinkedList(); + for(int i = 0; i < N; i++) + scores.add(data.nextInt()); + HashMap map = createMap(P); + //int ans = DFS(map, scores, S, P); + int ans = count(map, scores, S); + String caseout = String.format(""Case #%d: %d\n"", caseNum++, ans); + output.append(caseout); + System.out.print(caseout); + + } while (data.isNotDepleted()); + + //System.out.print(output); + PrintWriter writer = new PrintWriter(new File(inputName+"".output"")); + writer.print(output); + writer.flush(); + writer.close(); + } + + public static int count(HashMap map, LinkedList scores, int S) + { + int yes = 0; + int surprise = 0; + for(Integer score : scores) + { + HitScore hit = map.get(score); + if(hit == HitScore.Yes) + yes++; + if(hit == HitScore.Surprise) + surprise++; + } + if(surprise >= S) + yes += S; + else + yes += surprise; + return yes; + } + + public static HashMap createMap(int P) + { + HashMap map = new HashMap(); + for(int i = 0; i <= 30; i++) + { + map.put(i, didit(i, P)); + } +// int min = 3*P-4; +// min = (int)Math.max(0, min); +// int max = 3*P+4; +// max = (int)Math.min(30, max); +// for(int i = 0; i <= 30; i++) +// { +// if(i < min || i ==0) +// map.put(i, HitScore.No); +// else if(i > max) +// map.put(i, HitScore.Yes); +// else +// map.put(i, HitScore.Surprise); +// } + return map; + } + + public static HitScore didit(int score, int P) + { + //if(score >= 3*P-2) + // return HitScore.Yes; + boolean foundSuprise = false; + while(P <= 10 && P <= score) + { + if(score == 29) + P = P; + int rem = (int)Math.abs(P-score); + + for(int i = 0; i <= rem; i++) + { + int a = i; + int b = rem - i; + + int r1 = (int)Math.abs(a-b); + int r2 = (int)Math.abs(P-b); + int r3 = (int)Math.abs(P-a); + if( r1 <= 2 && r2 <= 2 && r3 <= 2 ) + { + if(r1 < 2 && r2 < 2 && r3 < 2) + return HitScore.Yes; + foundSuprise = true; + } + } + P++; + } + if(foundSuprise) + return HitScore.Surprise; + else + return HitScore.No; + } + + + public static int DFS(HashMap map, LinkedList scores, int S, int P ) + { + if(scores.size() <= 0) + { + //if(S == 0) + return 0; + //else + // return Integer.MIN_VALUE; + } + Integer score = scores.removeFirst(); + + HitScore hit = map.get(score); + int max = Integer.MIN_VALUE; + if(hit == HitScore.No) + max = Math.max(max, 0+DFS(map,scores, S, P)); + else if(hit == HitScore.Surprise) + { + max = Math.max(max, 0+DFS(map,scores, S, P)); + if(S > 0) + max = Math.max(max, 1+DFS(map,scores, S-1, P)); + } + else if(hit == HitScore.Yes) + max = Math.max(max, 1+DFS(map,scores, S, P)); + + + + scores.addFirst(score); + + return max; + } +} + +enum HitScore { No, Surprise, Yes } + + + +/** + * Makes parsing input from Uva problems easy. + */ +class QueueMagic{ + + private Queue data; + private BufferedReader in; + private String delimiter; + private String secondary_delimiter; + /** + * The default delimiter is \\s+ + * This is at least one or more white space characters + */ + public final static String DEFAULT_DELIMITER = ""\\s+""; + public final static String DEFUALT_SECONDARY_DELIMITER = ""\\s+""; + /** + * Defaults to reading System.in + * Defaults to using the following delimiter: \\s+ + * @throws IOException + */ + public QueueMagic() throws IOException + { + this(new InputStreamReader(System.in), DEFAULT_DELIMITER); + } + + /** + * Build QueueMagic from any reader + * Defaults to using the following delimiter: \\s+ + * @param reader + * @throws IOException + */ + public QueueMagic(Reader reader) throws IOException + { + this(reader, DEFAULT_DELIMITER); + } + + /** + * Defaults to reading from System.in + * @param delimiter + * @throws IOException + */ + public QueueMagic(String regex) throws IOException + { + this(new InputStreamReader(System.in), regex); + } + + public QueueMagic(Reader reader, String regex) throws IOException + { + this.in = new BufferedReader(reader); + this.delimiter = regex; + readData(); + } + + + /** + * Reads in all bytes in the stream and splits it into string tokens based on the delimiter. + * @throws IOException + */ + private void readData() throws IOException + { + CharBuffer buf = CharBuffer.allocate(10000); + StringBuilder input = new StringBuilder(10000); + do + { + this.in.read(buf); + input.append(buf.flip().toString()); + }while(this.in.ready()); + String [] parts = input.toString().split(this.delimiter); + this.data = new LinkedList(Arrays.asList(parts)); + close(); + } + + /** + * Returns the next string + * @return + */ + public String next() + { + return data.poll(); + } + + public Integer nextInt() + { + return Integer.parseInt(next()); + } + + public Short nextShort() + { + return Short.parseShort(next()); + } + + public Byte nextByte() + { + return Byte.parseByte(next()); + } + + public Long nextLong() + { + return Long.parseLong(next()); + } + + public Float nextFloat() + { + return Float.parseFloat(next()); + } + + public Double nextDouble() + { + return Double.parseDouble(next()); + } + + public BigInteger nextBigInt() + { + return new BigInteger(next()); + } + + public BigDecimal nextBigDec() + { + return new BigDecimal(next()); + } + + /** + * Returns the next token split by the secondary delimiter. + * @return + */ + public String [] arrayString() + { + return next().split(this.secondary_delimiter); + } + + /** + * Split by the secondary delimiter + * @return + */ + public Byte [] arrayByte() + { + String [] parts = arrayString(); + Byte [] vals = new Byte[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = Byte.parseByte(parts[i]); + } + return vals; + } + /** + * Split by the secondary delimiter + * @return + */ + public Short [] arrayShort() + { + String [] parts = arrayString(); + Short [] vals = new Short[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = Short.parseShort(parts[i]); + } + return vals; + } + + /** + * Split by the secondary delimiter + * @return + */ + public Integer [] arrayInt() + { + String [] parts = arrayString(); + Integer [] vals = new Integer[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = Integer.parseInt(parts[i]); + } + return vals; + } + + /** + * Split by the secondary delimiter + * @return + */ + public Long [] arrayLong() + { + String [] parts = arrayString(); + Long [] vals = new Long[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = Long.parseLong(parts[i]); + } + return vals; + } + + /** + * Split by the secondary delimiter + * @return + */ + public Float [] arrayFloat() + { + String [] parts = arrayString(); + Float [] vals = new Float[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = Float.parseFloat(parts[i]); + } + return vals; + } + + /** + * Split by the secondary delimiter + * @return + */ + public Double [] arrayDouble() + { + String [] parts = arrayString(); + Double [] vals = new Double[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = Double.parseDouble(parts[i]); + } + return vals; + } + + /** + * Split by the secondary delimiter + * @return + */ + public BigInteger [] arrayBigInteger() + { + String [] parts = arrayString(); + BigInteger [] vals = new BigInteger[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = new BigInteger(parts[i]); + } + return vals; + } + + /** + * Split by the secondary delimiter + * @return + */ + public BigDecimal[] arrayBigDecimal() + { + String [] parts = arrayString(); + BigDecimal [] vals = new BigDecimal[parts.length]; + for (int i = 0; i < vals.length; i++) { + vals[i] = new BigDecimal(parts[i]); + } + return vals; + } + + public ArrayList listString() + { + return new ArrayList(Arrays.asList(arrayString())); + } + + public ArrayList listByte() + { + return new ArrayList(Arrays.asList(arrayByte())); + } + + public ArrayList listShort() + { + return new ArrayList(Arrays.asList(arrayShort())); + } + + public ArrayList listInt() + { + return new ArrayList(Arrays.asList(arrayInt())); + } + + public ArrayList listLong() + { + return new ArrayList(Arrays.asList(arrayLong())); + } + + public ArrayList listFloat() + { + return new ArrayList(Arrays.asList(arrayFloat())); + } + + public ArrayList listDouble() + { + return new ArrayList(Arrays.asList(arrayDouble())); + } + + public ArrayList listBigInteger() + { + return new ArrayList(Arrays.asList(arrayBigInteger())); + } + + public ArrayList listBigDecimal() + { + return new ArrayList(Arrays.asList(arrayBigDecimal())); + } + + + /** + * @return true if there is no more data + */ + public boolean isDepleted() + { + return this.data.isEmpty(); + } + + /** + * + * @return true if there is data + */ + public boolean isNotDepleted() + { + return !isDepleted(); + } + + /** + * The primary delimiter is used to split the data into tokens + * @return + */ + public String getDelimter() + { + return this.delimiter; + } + + /** + * The primary delimiter is used to split the data into tokens + * @param regex + */ + public void setDelimiter(String regex) + { + this.delimiter = regex; + } + + /** + * The secondary delimiter is used to split tokens into lists/arrays + * @return + */ + public String getSecondaryDelimiter() + { + return this.secondary_delimiter; + } + + /** + * The secondary delimiter is used to split tokens into lists/arrays + * @param regex + */ + public void setSecondaryDelimiter(String regex) + { + this.secondary_delimiter = regex; + } + + public void close() throws IOException + { + if(this.in != null) + { + in.close(); + } + } +}" +A21800,"import java.util.Scanner; + + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + String line = scanner.nextLine().trim(); + int totalCase = Integer.parseInt(line); + + for (int i = 1; i <= totalCase; i++) { + line = scanner.nextLine().trim(); + String parts[] = line.split("" +""); + + int numOfGooglers = Integer.parseInt(parts[0]); + int numOfSuprises = Integer.parseInt(parts[1]); + int bestResult = Integer.parseInt(parts[2]); + + String output = ""Case #"" + i + "": ""; + int possible = 0; + int impoosible = 0; + for (int count = 0; count < numOfGooglers; count++) { + int index = 3+count; + int totalPoints = Integer.parseInt(parts[index]); + if (totalPoints < bestResult) { + impoosible++; + continue; + } + + int sumOfTwo = totalPoints - bestResult; + float avgOfTwo = sumOfTwo / 2.0f; + + int num2 = (int)Math.floor(avgOfTwo); + int num3 = (int)Math.ceil(avgOfTwo); + + int diff1 = bestResult - num2; + int diff2 = bestResult - num3; + + if (diff1 <= 1 && diff2 <= 1) { + possible++; + } else if (diff1 >= 3 || diff2 >= 3) { + impoosible++; + } + } + + int googlersLeft = numOfGooglers - possible; + int possibleGooglers = (googlersLeft - impoosible > numOfSuprises ? numOfSuprises : googlersLeft - impoosible); + + int p = possible + possibleGooglers; + + output += p; + System.out.println(output); + } + + System.exit(0); + } + +} +" +A20554,"package codejam2012.qualification.b; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class Round { + + private static Logger log = LoggerFactory.getLogger(Round.class); + + private final List totals; + private final Memory memory; + + public Round(List totals, Memory memory) { + this.totals = totals; + this.memory = memory; + } + + public int run(int s, int p) { + int count = 0; + + for (Integer total : totals) { + List triplets = memory.data.get(total); + if (triplets.isEmpty()) { + throw new IllegalStateException(); + } + + log.debug(""for total: {} triplets are: {}"", total, triplets); + boolean has = false; + boolean hasNotSurprising = false; + + for (Triplet triplet : triplets) { + if (triplet.hasAtLeast(p)) { + has = true; + if (!triplet.surprising) { + hasNotSurprising = true; + } + } + } + + log.debug(""--> has: {} hasNotSurprising: {}"", has, hasNotSurprising); + + if (has) { + if (hasNotSurprising) { + ++count; + } else { + if (s > 0) { + --s; + ++count; + } + } + } + } + + return count; + } + +} +" +A22050,"import java.io.*; +import java.util.*; +import java.lang.*; +public class problemB +{ + public static void main(String args[])throws Exception + { + Scanner cin=new Scanner(System.in); + int numcases = cin.nextInt(); + int N,S,P,T; + double avg,s; + int v; + for(int i=0;i= P){ + v++; + }else if(S > 0 && T >= P){ + avg = ((double)(T + 4.0)/3.0); + if(avg >= P){ + S--; + v++; + } + } + } + System.out.println(""Case #""+ (i+1) + "": "" + v); + } + } + +} +" +A22592,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Hashtable; + +public class TestGoogle2 { + + public TestGoogle2() { + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + int line = -1; + int curline = 0; + // Read File Line By Line + while ((strLine = br.readLine()) != null) { + // Print the content on the console + if (line == -1) + line = Integer.parseInt(strLine); + else if (curline < line) { + System.out.print(""Case #"" + ++curline + "": ""); + System.out.println(this.calculate(strLine)); + } + } + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + } + + public int calculate(String input) { + + String[] result = input.split(""\\s""); + int n = Integer.parseInt(result[0]); + int s = Integer.parseInt(result[1]); + int p = Integer.parseInt(result[2]); + + int count = 0; + for (int x = 3; x < result.length; x++) { + int temp = Integer.parseInt(result[x]); + // System.out.println(result[x]); + + if (p == 0) { + count++; + } else if (temp > 0 && temp >= (p * 3 - 2)) { + count++; + } else if (temp > 0 && (temp == (p * 3 - 3) || temp == (p * 3 - 4)) + && s > 0) { + s--; + count++; + } + } + return count; + } + + /** + * @param args + */ + public static void main(String[] args) { + new TestGoogle2(); + + } + +} +" +A22830,"package mgg.problems; + +import java.util.List; + +import mgg.utils.FileUtil; +import mgg.utils.StringUtils; + +/** + * @author manolo + * @date 14/04/12 + */ +public class ProblemC { + + public final static String EXAMPLE_IN = ""C-example.in""; + public final static String EXAMPLE_OUT = ""C-example.out""; + + public final static String C_SMALL_IN = ""C-small-attempt0.in""; + public final static String C_SMALL_OUT = ""C-small-attempt0.out""; + + public final static String C_LARGE_IN= ""C-large.in""; + public final static String C_LARGE_OUT = ""C-large.out""; + + public final static String delim = "" ""; + + public static String solve(FileUtil util) { + + String line = util.getLine(); + List listOfArgs = StringUtils.stringWithIntegersToList(line, delim); + + final int A = listOfArgs.get(0); + //System.out.println(""\tA = "" + A); + + final int B = listOfArgs.get(1); + //System.out.println(""\tB = "" + B); + + //ArrayList solution = new ArrayList(); + int found = 0; + for(int i = A; i < B ; i++){ + for(int j = A + 1; j <= B ; j++){ + if(i 0){ + n = n / 10; + result++; + } + return result; + } + + private static int moveCiphersToFront(int number, int howManyCiphers, int numCiphers) { + String num = """" + number; + + String newNumber = num.substring(numCiphers-howManyCiphers, numCiphers) + + num.substring(0, numCiphers-howManyCiphers); + + //System.out.println(""new number: "" + newNumber); + + return Integer.parseInt(newNumber); + } + +} +" +A21720,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; + +public class DancingWithTheGoolers { + int[][] judgeScoresCache = new int[31][]; + + public DancingWithTheGoolers() { + } + + public int solveFromString(String input) { + String[] tokens = input.split("" ""); + int playerNum = Integer.parseInt(tokens[0]); + int surprisingTriplets = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int[] totalScores = new int[playerNum]; + for (int i = 0; i < playerNum; ++i) { + totalScores[i] = Integer.parseInt(tokens[i + 3]); + } + return solve(surprisingTriplets, p, totalScores); + } + + public int solve(int surprisingTriplets, int p, int[] totalScores) { + Arrays.sort(totalScores); + int qualifiedPlayerCnt = 0; + int[] judgeScores; + for (int i = totalScores.length - 1; i >= 0; --i) { + judgeScores = getJudgeScores(totalScores[i]); + if (judgeScores[2] >= p) { + qualifiedPlayerCnt++; + continue; + } + if (surprisingTriplets > 0) { + if (canBeSurprised(totalScores[i])) { + // check if max score can be better than b with surprising triplets + int maxScore = maxScoreOfSurprisingTriplets(judgeScores); + if (maxScore >= p) { + qualifiedPlayerCnt++; + surprisingTriplets--; + } + } + } + } + + return qualifiedPlayerCnt; + } + + // return not surprised judge scores + public int[] getJudgeScores(int totalScore) { + if (judgeScoresCache[totalScore] != null) { + return judgeScoresCache[totalScore]; + } + int[] scores = new int[3]; + scores[0] = totalScore / 3; + scores[1] = (totalScore - scores[0]) / 2; + scores[2] = totalScore - scores[0] - scores[1]; + Arrays.sort(scores); + judgeScoresCache[totalScore] = scores; + return scores; + } + + public int maxScoreOfSurprisingTriplets(int[] scores) { + if (scores[2] == scores[1]) { + return scores[2] + 1; + } + return scores[2]; + } + + public boolean canBeSurprised(int totalScore) { + if (totalScore < 2 || totalScore > 28) + return false; + return true; + } + + public static void main(String[] args) throws IOException { + DancingWithTheGoolers solver = new DancingWithTheGoolers(); + // System.out.println(solver.solveFromString(""6 2 8 29 20 8 18 18 21"")); + File folder = new File("".""); + for (File f : folder.listFiles()) { + if (!f.getName().endsWith(""in"") || !f.isFile()) { + continue; + } + System.out.println(f.getName()); + String outFileName = f.getName().replace(""in"", ""out""); + + BufferedReader reader = new BufferedReader(new FileReader(f)); + String str; + int lineNum = 0, caseNum = 1; + BufferedWriter writer = new BufferedWriter(new FileWriter(outFileName)); + lineNum = Integer.valueOf(reader.readLine()); + while ((str = reader.readLine()) != null) { + writer.write(String.format(""Case #%d: %s\n"", caseNum++, + solver.solveFromString(str))); + } + if (lineNum != caseNum - 1) { + System.err.println(""Case Number is not matched to input file.""); + } + writer.flush(); + writer.close(); + } + } + +} +" +A22879,"package codeJam; + +import java.util.Scanner; +import java.util.StringTokenizer; + +public class DancingWiththeGooglers { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int cases = Integer.parseInt(scan.nextLine()); + for (int i = 0; i < cases; i++) { + String temp = scan.nextLine(); + StringTokenizer token = new StringTokenizer(temp); + int N = Integer.parseInt(token.nextToken()); + int S = Integer.parseInt(token.nextToken()); + int P = Integer.parseInt(token.nextToken()); + int[] total = new int[N]; + for (int j = 0; j < total.length; j++) { + total[j] = Integer.parseInt(token.nextToken()); + } + System.out.println(""Case #"" + (i + 1) + "": "" + solve(total, S, P)); + + } + + } + + private static int solve(int[] total, int s, int p) { + int ser = s; + int numberOfWinners = 0; + for (int i = 0; i < total.length; i++) { + if (total[i] == 0) { + if (p == 0) + numberOfWinners++; + } else if (total[i] == 1) { + if (p <= 1) + numberOfWinners++; + } else if (total[i] == 2) { + if (p <= 1) + numberOfWinners++; + else if (p == 2 && ser > 0) { + numberOfWinners++; + ser--; + } + } else { + int k = total[i] % 3; + if (k == 0) { + if (total[i] / 3 >= p) + numberOfWinners++; + else if (((total[i] / 3) + 1) >= p && ser > 0) { + numberOfWinners++; + ser--; + } + } else if (k == 2) { + int sum = (total[i] / 3) + 1; + if (sum >= p) + numberOfWinners++; + else if ((sum + 1) >= p && ser > 0) { + numberOfWinners++; + ser--; + } + + } else if (k == 1) { + int sum = (total[i] / 3) + 1; + if (sum >= p) + numberOfWinners++; + } + } + } + return numberOfWinners; + + } +} +" +A21241,"import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; + + +public class Dance { + +/* private static int maxScore(int total, boolean isSurprise) { + int base = total / 3; + if (isSurprise) { + switch ( total % 3 ) { + case 0: return base + 1; + case 1: return base + 1; + case 2: return base + 2; + } + } else { + switch ( total % 3 ) { + case 0: return base; + case 1: return base + 1; + case 2: return base + 1; + } + } + return -1; + }*/ + + private static int[] noSurpriseList={ 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9,10,10,10}; + private static int[] surpriseList={ -1, -1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9,10,10,10,-1, -1}; + + /* + 0 : 0 , X + 1 : 1 , X + 2 : 1 , 2 + 3 : 1 , 2 + 4 : 2 , 2 + 5 : 2 , 3 + 6 : 2 , 3 + 7 : 3 , 3 + 8 : 3 , 4 + 9 : 3 , 4 + 10 : 4 , 4 + 11 : 4 , 5 + 12 : 4 , 5 + 13 : 5 , 5 + 14 : 5 , 6 + 15 : 5 , 6 + 16 : 6 , 6 + 17 : 6 , 7 + 18 : 6 , 7 + 19 : 7 , 7 + 20 : 7 , 8 + 21 : 7 , 8 + 22 : 8 , 8 + 23 : 8 , 9 + 24 : 8 , 9 + 25 : 9 , 9 + 26 : 9 , 10 + 27 : 9 , 10 + 28 : 10 , 10 + 29 : 10 , XX + 30 : 10 , XX + */ + + /** + * @param args + */ + public static void main(String[] args) { + + +/* for (int i=0;i<=30;i++) { + System.out.printf(""%2d,"", maxScore(i, true)); + } + + System.exit(0);*/ + + + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int t=1;t<=T;t++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int ret = 0; + ArrayList nums = new ArrayList(); + for(int n=0;n=p) ret++; + } else if (s>=p) { + nums.add(tn); + } + } + Collections.sort(nums, new Comparator() { + + public int compare(Integer o1, Integer o2) { + return surpriseList[o1] - surpriseList[o2]; + } + + }); + + //System.out.println(""X: "" + nums); + if (nums.size()>=S) { + ret+=S; + for(int i=S;i=p) ret++; + } + } else { + ret+=nums.size(); + } + System.out.println(""Case #"" + t + "": "" + ret); + } + } +} +" +A22617,"import java.util.List; +import java.util.Map; + + +public class Dwtg { + List>> input; + + public Dwtg(List>> input){ + this.input = input; + } + + public void solve(){ + int googlers; + int surprise; + int p; + int res; + + int scoreOk; + int nbOk; + int potentialSurp; + int nbSurp; + for(int i = 0; i < input.size(); i++){ + googlers = Integer.parseInt(input.get(i).get(0).get(0)); + surprise = Integer.parseInt(input.get(i).get(0).get(1)); + p = Integer.parseInt(input.get(i).get(0).get(2)); + res = 0; + scoreOk = p*3; + + nbOk = 0; + potentialSurp = 0; + nbSurp = 0; + if(p == 0){ + System.out.println(""Case #"" + (i+1) + "": "" + googlers); + } + else{ + for(int x = 3; x < googlers + 3; x++){ + int score = Integer.parseInt(input.get(i).get(0).get(x)); + if( (score > 0) && (score >= (scoreOk - 2)) ){ + nbOk++; + } + else if( (score > 0) && (score >= (scoreOk - 4)) ){ + potentialSurp++; + } + } + nbSurp = Math.min(potentialSurp, surprise); + res = nbOk + nbSurp; + System.out.println(""Case #"" + (i+1) + "": "" + res); + } + } + } +} +" +A20001,"import java.io.*; +import java.util.*; + +public class Qual2 { + + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(""B-large.in"")); + FileWriter fw = new FileWriter(""B-output.txt""); + int total = sc.nextInt(); + for(int i = 1; i <= total; i++) { + int n = sc.nextInt(), s = sc.nextInt(), p = sc.nextInt(); + int[] scores = new int[n]; + for(int j = 0; j < n; j++) scores[j] = sc.nextInt(); + int count = 0; + for(int j = 0; j < n; j++) { + int div = scores[j] / 3, rem = scores[j] % 3; + if(rem == 0) { + if(div >= p) count++; + else if(div == p-1 && div > 0 && s > 0) { + s--; + count++; + } + } + else if(rem == 1) { + if(div + 1 >= p) count++; + } + else if(rem == 2) { + if(div + 1 >= p) count++; + else if(div + 2 >= p && s > 0) { + s--; + count++; + } + } + } + fw.write(""Case #"" + i + "": "" + count + ""\n""); + System.out.println(""Case #"" + i + "": "" + count); + } + fw.close(); + } + +} +" +A21231,"package ponder.CodeJamQualify; + +import java.io.*; +import java.util.StringTokenizer; + +/** + * @author: sg Date: 15.04.12 + */ +public class TaskB +{ + static int calc(final int p, final int strangeOrig, final int[] marks) + { + int cnt = 0; + int strange = strangeOrig; + for (int total : marks) + { + int max = total / 3; + if ((total % 3) != 0) + max += 1; + + if (max >= p) + { + cnt++; + continue; + } + + if (total <= 1) + continue; + + if (((total % 3) != 1) && (strange > 0) && (max == p - 1)) + { + cnt++; + strange--; + } + } + return cnt; + } + + public static void main(String[] args) throws IOException + { + final long start = System.currentTimeMillis(); + +// PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(""taskB.out""))); +// BufferedReader reader = new BufferedReader(new FileReader(""taskB.in"")); + +// PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(""B-small-attempt0.out""))); +// BufferedReader reader = new BufferedReader(new FileReader(""B-small-attempt0.in"")); + + PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); + + String inLine; + int caseIndex = 0; + inLine = reader.readLine(); + while (null != (inLine = reader.readLine())) + { + StringTokenizer st = new StringTokenizer(inLine); + final int n = Integer.parseInt(st.nextToken()); + final int s = Integer.parseInt(st.nextToken()); + final int p = Integer.parseInt(st.nextToken()); + int[] marks = new int[n]; + for (int i = 0; i < n; i++) + marks[i] = Integer.parseInt(st.nextToken()); + caseIndex++; + int cnt = calc(p, s, marks); + writer.printf(""Case #%d: %d\r\n"", caseIndex, cnt); + } + + writer.close(); + + + final long finish = System.currentTimeMillis(); + final long dur = finish - start; + System.err.println(dur); + } +} +" +A20282,"import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + File input = new File(""files/B-large.in.txt""); + File output = new File(""files/B-large.out.txt""); + PrintWriter pw = new PrintWriter(output); + Scanner sc = new Scanner(input); + int T = sc.nextInt(); + for (int i = 0; i < T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[N]; + for (int j = 0; j < t.length; j++) { + t[j] = sc.nextInt(); + } + int answer = solve(N, S, p, t); + pw.println(String.format(""Case #%d: %d"", i + 1, answer)); + } + pw.close(); + sc.close(); + } + + static int solve(int n, int s, int p, int[] t) { + if (p == 0) { + return t.length; + } + + int count = 0; + for (int i = 0; i < t.length; i++) { + if (t[i] >= (3 * p) - 2) { + count++; + } else if (s > 0 && t[i] > 0 && t[i] >= (3 * p) - 4) { + count++; + s--; + } + } + return count; + } +} +" +A21837,"import java.util.Scanner; +import java.util.StringTokenizer; + +/** + * + * @author rama + */ +public class Codejam1 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int n=Integer.parseInt(in.nextLine()); + for(int i=1;i<=n;++i) + //trans(in.nextLine()); + System.out.println(""Case #""+i+"": ""+trans(in.nextLine())); + //String input = reader.readLine(); + } + + public static int trans(String ss){ + int ans=0; + int temp; + int ok=0,srp=0; + StringTokenizer tok=new StringTokenizer(ss,"" ""); + int n=Integer.parseInt(tok.nextToken()); + int s=Integer.parseInt(tok.nextToken()); + int p=Integer.parseInt(tok.nextToken()); + for(int i=1;i<=n;++i){ + temp=Integer.parseInt(tok.nextToken()); + int l=temp-(3*p); + if(l>=-2) + ++ok; + if(l<-2&&l>=-4&&temp>=2) + ++srp; + } + ans=ok+Math.min(srp,s); + return ans; + } +} + +" +A22777,"package lt.kasrud.gcj.ex2; + +import lt.kasrud.gcj.common.io.Reader; +import lt.kasrud.gcj.common.io.Writer; + +import java.io.IOException; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + List iData = Reader.readFile(""B-large.in""); + Writer.writeFile(""out2.txt"", process(iData.subList(1, iData.size()))); + } + + private static List process(List data) { + List result = new ArrayList(data.size()); + for(String record : data){ + List tokens = Arrays.asList(record.trim().split("" "")); + result.add(calculate(Integer.valueOf(tokens.get(1)), Integer.valueOf(tokens.get(2)), tokens.subList(3, tokens.size()))); + } + + return result; + } + + private static String calculate(Integer surpCnt, Integer maxValue, List totPoints) { + int cnt = 0; + int minDiff = maxValue > 0 ? 1 : maxValue; + int maxDiff = maxValue > 1 ? 2 : maxValue; + int maxTotal = maxValue * 3 - 2 * minDiff; + int surpTotal = maxValue * 3 - 2 * maxDiff; + for (String t : totPoints) { + int total = Integer.valueOf(t); + if (total >= maxTotal){ + cnt++; + }else if(total >= surpTotal && surpCnt > 0){ + cnt++; + surpCnt--; + } + } + + return String.valueOf(cnt); + } +} +" +A23021,"package probs; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + +public class Problem2 { + + public static void main(String[] args) { + + try { + + String filePath = ""in-large-2.txt""; + + List input = readInput(filePath); + int[] output = process(input); + writeOutput(output); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static int[] process(List input) { + + int[] result = new int[input.size()]; + int count = 0; + for (String eachLine : input) { + String[] split = eachLine.split("" ""); + int googlers = Integer.parseInt(split[0]); + int surprisesAllowed = Integer.parseInt(split[1]); + int criteriaBestScore = Integer.parseInt(split[2]); + int[] totals = new int[googlers]; + for (int i = 0; i < googlers; i++) { + totals[i] = Integer.parseInt(split[i + 3]); + } + int maxGooglersWithAtleaseRequiredBestResult = processEachTestCase(surprisesAllowed, criteriaBestScore, totals); + result[count] = maxGooglersWithAtleaseRequiredBestResult; + + count++; + } + + return result; + } + + private static int processEachTestCase(int surprisesAllowed, + int bestScore, int[] totals) { + + int result = 0; + + final int max=10; + final int doubleMax = max*2; + + int maxRange = 2*(bestScore+1); + int minRange = 2*(bestScore-1); + if (maxRange>doubleMax) { + maxRange=doubleMax; + } + if (minRange<0) { + minRange=0; + } + + int furtherMaxRange = 2*(bestScore+2); + int furtherMinRange = 2*(bestScore-2); + if (furtherMaxRange>doubleMax) { + furtherMaxRange=doubleMax; + } + if (furtherMinRange<0) { + furtherMinRange=0; + } + + int surpriseCounter=0; + + for (int i = 0; i < totals.length; i++) { + + int eachTotal = totals[i]; + + if (eachTotal>=3*bestScore) { // 333 to infinity + result++; + }else{ + if(eachTotal>=(bestScore+minRange) && eachTotal<=(bestScore+maxRange)){ // 322 to 344 + result++; + }else{ + if(eachTotal<(bestScore+minRange) && eachTotal>=(bestScore+furtherMinRange)){ // 311 to 321 + if (surpriseCounter(bestScore+maxRange) && eachTotal<=(bestScore+furtherMaxRange)){ // 345 to 355 + if (surpriseCounter readInput(String filePath) + throws FileNotFoundException { + + List list = new ArrayList(); + + File file = new File(filePath); + Scanner scanner = new Scanner(file); + if (scanner.hasNextLine()) { + String line = scanner.nextLine(); + int testCases = Integer.parseInt(line); + + } + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + //System.out.println(line); + list.add(line); + } + + return list; + } + + private static void writeOutput(int[] list) { + + int n = list.length; + + for (int i = 0; i < n; i++) { + System.out.println(""Case #"" + (i + 1) + "": "" + list[i]); + } + } + +} +" +A21685," + +import java.awt.Point; +import java.io.*; +import java.math.BigInteger; +import java.util.*; + +import static java.lang.Math.*; + +public class ProblemB_Qual_2012 implements Runnable{ + + BufferedReader in; + PrintWriter out; + StringTokenizer tok = new StringTokenizer(""""); + + void init() throws FileNotFoundException{ + in = new BufferedReader(new FileReader(""B-large.in"")); + out = new PrintWriter(""output.txt""); + } + + String readString() throws IOException{ + while(!tok.hasMoreTokens()){ + try{ + tok = new StringTokenizer(in.readLine()); + }catch (Exception e){ + return null; + } + } + return tok.nextToken(); + } + + int readInt() throws IOException{ + return Integer.parseInt(readString()); + } + + long readLong() throws IOException{ + return Long.parseLong(readString()); + } + + double readDouble() throws IOException{ + return Double.parseDouble(readString()); + } + + public static void main(String[] args){ + new Thread(null, new ProblemB_Qual_2012(), """", 256 * (1L << 20)).start(); + } + + long timeBegin, timeEnd; + + void time(){ + timeEnd = System.currentTimeMillis(); + System.err.println(""Time = "" + (timeEnd - timeBegin)); + } + + long memoryTotal, memoryFree; + + + void memory(){ + memoryFree = Runtime.getRuntime().freeMemory(); + System.err.println(""Memory = "" + ((memoryTotal - memoryFree) >> 10) + "" KB""); + } + + void debug(Object... objects){ + if (DEBUG){ + for (Object o: objects){ + System.err.println(o.toString()); + } + } + } + + public void run(){ + try{ + timeBegin = System.currentTimeMillis(); + memoryTotal = Runtime.getRuntime().freeMemory(); + init(); + solve(); + out.close(); + time(); + memory(); + }catch (Exception e){ + e.printStackTrace(System.err); + System.exit(-1); + } + } + + boolean DEBUG = false; + + void solve() throws IOException{ + int[] a = new int[3]; + + int t = readInt(); + for (int it = 1; it <= t; it++){ + out.print(""Case #"" + it + "": ""); + + int count = 0; + + int n = readInt(); + int s = readInt(); + int p = readInt(); + + int[] b = new int[n]; + for (int i = 0; i < n; i++){ + b[i] = readInt(); + } + Arrays.sort(b); + + boolean[] used = new boolean[n]; + + for (int i = 0; i < n; i++){ + int x = b[i]; + + for (int j = 0; j < 3; j++){ + a[j] = x / 3; + } + + x %= 3; + for (int j = 2; x > 0; j--, x--){ + a[j]++; + } + + if (a[2] >= p){ + count++; + continue; + } + + if (a[2] == a[1]){ + if (s > 0 && a[2] == p - 1 && a[1] > 0 && a[2] < 10){ + used[i] = true; + s--; + count++; + } + } + } + + if (s > 0){ + for (int i = 0; i < n && s > 0; i++){ + if (used[i]) continue; + + int x = b[i]; + + for (int j = 0; j < 3; j++){ + a[j] = x / 3; + } + + x %= 3; + for (int j = 2; x > 0; j--, x--){ + a[j]++; + } + + if (a[2] == a[1]){ + if (a[2] < 10 && a[1] > 0){ + used[i] = true; + s--; + } + }else if (a[1] == a[0]){ + if (a[1] < 10 && a[0] > 0){ + used[i] = true; + s--; + } + } + } + } + + if (s > 0){ + System.err.println(""AHTUNG!!!!! TEST #"" + it); + } + out.println(count); + } + } +} + +" +A22322,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + + +public class CodeJamSolverDancing { + + public static HashMap> valueToIndexMap=new HashMap>(); + public static void main(String[] args) { + + + int numTestCases=0; + int numLinePerTestCase=1; + int currentCase=0; + String inputFileName=""B-large.in""; + //String inputFileName=""input.in""; + + BufferedReader br=null; + StringBuilder solutionString=new StringBuilder(); + + int lineCount=0; + try{ + String line; + br=new BufferedReader(new FileReader(inputFileName)); + while((line=br.readLine())!=null){ + lineCount++; + if(lineCount==1){ + numTestCases=Integer.parseInt(line); + continue; + } + + int[] splittedLine=getIntArrayFromStringLine(line); + int numGoogler=splittedLine[0]; + int numSurprises=splittedLine[1]; + int bestResult=splittedLine[2]; + ArrayList scoresList=new ArrayList(); + for(int i=3;i scoresList) { + + int tentativeScoreWOS=0; + int tentativeScoreWS=0; + int tentativeScoreWS2=0; + if(bestResult==0){ + tentativeScoreWOS=0; + tentativeScoreWS=0; + tentativeScoreWS2=0; + } + else if(bestResult==1){ + tentativeScoreWOS=1; + tentativeScoreWS=1; + tentativeScoreWS2=1; + } + else{ + tentativeScoreWOS=bestResult+bestResult-1+bestResult-1; + tentativeScoreWS=bestResult+bestResult-2+bestResult-2; + tentativeScoreWS2=bestResult+bestResult-1+bestResult-2; + } + + int maxGooglers=0; + for(int eachScore:scoresList){ + if(eachScore=tentativeScoreWS && tentativeScoreWS>1 && numSurprises>0){ + maxGooglers++; + numSurprises--; + continue; + } + else if(eachScore>=tentativeScoreWS2 && tentativeScoreWS2>1 && numSurprises>0){ + maxGooglers++; + numSurprises--; + continue; + } + } + return maxGooglers+""""; + } + + + + private static int[] getIntArrayFromStringLine(String line) { + String[] stringArray=line.split(""\\s+""); + int length=stringArray.length; + int intArray[]=new int[length]; + valueToIndexMap=new HashMap>(); + for(int i=0;i indicesList=new ArrayList(); + if(valueToIndexMap.containsKey(intArray[i])){ + indicesList=valueToIndexMap.get(intArray[i]); + } + indicesList.add(i); + valueToIndexMap.put(intArray[i], indicesList); + } + return intArray; + } + public static void writeTextToFile(String fileName, String textToWrite){ + try{ + BufferedWriter bw= new BufferedWriter( + new FileWriter(fileName)); + bw.write(textToWrite); + bw.close(); + } + catch(IOException ex){ + System.out.println(""Unable to write to file!""); + ex.printStackTrace(); + + } + } + +} + +" +A23048," +import java.io.*; +import java.util.*; + +class triple{ + static int p; + int a , b, c; + + public triple(int i ,int j ,int k){ + a = i; + b = j; + c = k; + } + boolean isSurprise(){ + return a - c == 2; + } + boolean isP(){ + return a >= p; + } + +} +public class QualB{ + + private BufferedReader in; + private StringTokenizer st; + private PrintWriter out; + + + void solve() throws IOException{ + + ArrayList[] s = new ArrayList[31]; + for (int i = 0; i < s.length; i++) { + s[i] = new ArrayList(); + } + HashSet h = new HashSet(); + for (int i = 0; i <= 10; i++) { + for (int j = Math.max(0, i-2); j <= Math.min(i+2, 10); j++) { + for (int k = Math.max(0, i-2); k <= Math.min(i+2, 10); k++) { + if(Math.abs(k-j) > 2) continue; + int [] a = {i,j,k}; + Arrays.sort(a); + String str = a[0]+"",""+a[1]+"",""+a[2]; + if(!h.contains(str)){ + h.add(str); + triple t = new triple(a[2],a[1],a[0]); + s[i+j+k].add(t); + } + } + } + } + int kases = nextInt(); + int kase = 0; + while(kases-->0){ + kase++; + out.print(""Case #""+kase+"": ""); + int n = nextInt(); + int sp = nextInt(); + int p = nextInt(); + triple.p = p; + int []vals = new int[n]; + for (int i = 0; i < vals.length; i++) { + vals[i] = nextInt(); + } + int ans = 0; + int P = 0; + int PnotS = 0; + for (int i = 0; i < vals.length; i++) { +// System.out.println(vals[i]); +// System.out.print(s[vals[i]].get(0).a+"" ""); +// System.out.print(s[vals[i]].get(0).b+"" ""); +// System.out.println(s[vals[i]].get(0).c); +// if(s[vals[i]].size() > 1){ +// System.out.print(s[vals[i]].get(1).a+"" ""); +// System.out.print(s[vals[i]].get(1).b+"" ""); +// System.out.println(s[vals[i]].get(1).c); +// } +// System.out.println(""-------------------------------""); + if(s[vals[i]].size() == 1){ + if(s[vals[i]].get(0).isP() && s[vals[i]].get(0).isSurprise()) P++; + if(s[vals[i]].get(0).isP() && !s[vals[i]].get(0).isSurprise()) ans++; + } + else{ + boolean a = s[vals[i]].get(0).isP(); + boolean b = s[vals[i]].get(1).isP(); + if(a&&b){ + ans++; + } + else if( a || b){ + int j = a?0:1; + if(s[vals[i]].get(j).isP() && s[vals[i]].get(j).isSurprise()) P++; + if(s[vals[i]].get(j).isP() && !s[vals[i]].get(j).isSurprise()) PnotS++; + } + } + } +// System.out.println(ans); +// System.out.println(P); +// System.out.println(PnotS); + if(sp > P){ + ans += P; + sp -= P; + PnotS -= sp; + PnotS = Math.max(0, PnotS); + ans += PnotS; + } + else{ + ans += sp + PnotS; + } +// ans += Math.min(sp, P); + out.println(ans); + } + } + + + QualB() throws IOException { + in = new BufferedReader(new FileReader(""input.txt"")); + out = new PrintWriter(new FileWriter(""output.txt"")); + eat(""""); + solve(); + out.close(); + } + + private void eat(String str) { + st = new StringTokenizer(str); + } + + String next() throws IOException { + while (!st.hasMoreTokens()) { + String line = in.readLine(); + if (line == null) { + return null; + } + eat(line); + } + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + long nextLong() throws IOException { + return Long.parseLong(next()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + public static void main(String[] args) throws IOException { + new QualB(); + } + + int gcd(int a,int b){ + if(b>a) return gcd(b,a); + if(b==0) return a; + return gcd(b,a%b); + } + +} +" +A20948,"package org.moriraaca.codejam; + +public interface TestCase { +} +" +A20071,"/** + * @(#)Text1.java + * + * + * @author + * @version 1.00 2012/4/14 + */ + +import java.util.*; +import java.io.*; + +public class B { + + public static int diff(int a, int b, int c) { + int max = 0; + if(Math.abs(a-b) > max) max = Math.abs(a-b); + if(Math.abs(b-c) > max) max = Math.abs(b-c); + if(Math.abs(c-a) > max) max = Math.abs(c-a); + return max; + } + + public static int max(int a, int b, int c) { + return Math.max(Math.max(a, b), c); + } + + public static int combo(int score, int best) { + double avg = score/3.0; + int min = 3; + for(int i = 0; i <= 11; i++) { + for(int j = 0; j <= 11; j++) { + for(int k = 0; k <= 11; k++) { + if(i + j + k == score && max(i, j, k) >= best) { + int s = diff(i, j, k); + //System.out.println("" S: "" + score + "" B: "" + best + "" (""+i+"", ""+j+"", ""+k+"")"" + "" "" + s); + + if(s < min) min = s; + if(min == 0 || min == 1) return min; + } + } + } + } + //System.out.println("" MIN: "" + min); + return min; + + } + + + public static void main(String [] argz) throws IOException { + Scanner reader = new Scanner(new File(""B-large.in"")); + int numCases = reader.nextInt(); + reader.nextLine(); + + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + + for(int i = 0; i < numCases; i++) { + ArrayList scores = new ArrayList(); + Scanner lineReader = new Scanner(reader.nextLine()); + while(lineReader.hasNext()) scores.add(lineReader.nextInt()); + int googlers = scores.remove(0); + int surprising = scores.remove(0); + int best = scores.remove(0); + int amount = 0; + + //System.out.println(""\n\n\nCase #"" + (i+1) + "" best: "" + best); + for(int j = 0; j < scores.size(); j++) { + int current = combo(scores.get(j), best); + if(current == 2 && surprising > 0) { + amount++; + surprising--; + } + if(current == 1 || current == 0) amount++; + //System.out.println(""AMT: "" + amount + "" SUR: "" + surprising); + } + //System.out.println(); + out.write(""Case #"" + (i+1) + "": "" + amount + ""\n""); + + } + out.close(); + } +}" +A20664,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class SolutionJamB { + + /** + * @param args + */ + public static void main(String[] args) + { + try + { + FileInputStream fisEntrada = new FileInputStream(""src/entrada2.in""); + FileWriter fwSalida = new FileWriter(""src/salida5.out""); + BufferedWriter bwSalida = new BufferedWriter(fwSalida); + DataInputStream disEntrada = new DataInputStream(fisEntrada); + String sEntrada; + String arrsEntrada[]; + String sSalida; + int participantes; + int sorpresas; + int pMinimo; + int resultado; + int resultadoIndividual; + int cocienteResultado; + int residuoResultado; + StringBuilder sbParteSalida; + BufferedReader brEntrada = new BufferedReader(new InputStreamReader(disEntrada)); + int contador; + + try + { + contador = Integer.parseInt(brEntrada.readLine()); + for(int i = 1; i<=contador; i++) + { + sEntrada = brEntrada.readLine(); + arrsEntrada = sEntrada.split("" ""); + participantes = Integer.parseInt(arrsEntrada[0]); + sorpresas = Integer.parseInt(arrsEntrada[1]); + pMinimo = Integer.parseInt(arrsEntrada[2]); + resultado = 0; + for(int j = 1; j <= participantes; j++) + { + resultadoIndividual = Integer.parseInt(arrsEntrada[2+j]); + cocienteResultado = (int)Math.floor(resultadoIndividual / 3 ); + residuoResultado = (pMinimo * 3) - resultadoIndividual; + + if(cocienteResultado >= pMinimo) + { + resultado++; + } + else if( residuoResultado <= 2 && resultadoIndividual != 0) + { + resultado++; + } + else if( sorpresas > 0 ) + { + if(residuoResultado <= 4 && resultadoIndividual != 0) + { + resultado++; + sorpresas--; + } + } + + } + sSalida = ""Case #"" + i + "": "" + resultado + ""\n""; + bwSalida.write(sSalida); + } + bwSalida.close(); + } + catch(Exception e) + { + e.getMessage(); + bwSalida.close(); + } + } + catch(Exception e) + { + e.getMessage(); + } + } + +} +" +A21878," +import java.util.*; +import java.io.*; +import java.lang.*; + +public class RQQ2 { + + public static void main(String[] args) + { + try + { + HashMap map = new HashMap(); + Scanner s = new Scanner(new File(""B-large.in"")); + FileWriter o = new FileWriter(new File(""out.txt"")); + + Integer lines = Integer.parseInt(s.nextLine()); + String str; + Integer sup; + Integer googlers; + Integer p; + StringTokenizer st; + + for (int i = 0; i < lines; i++) + { + o.write(""Case #"" + ( i + 1) + "": ""); + str = s.nextLine(); + st = new StringTokenizer(str, "" ""); + googlers = Integer.parseInt(st.nextToken()); + sup = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + int even = 0; + int max = 0; + + for (int j = 0; j < googlers; j++) + { + int total = Integer.parseInt(st.nextToken()); + if ( Math.ceil((double)total / 3.0) >= p ) + { + max++; + } + else if ( total != 0 && Math.ceil((double)total/3.0 + 2.0/3.0) >= p) + { + even++; + } + } + max += Math.min(even, sup); + o.write("""" + max + ""\n""); + } + + s.close(); + o.close(); + + } + catch(Exception e) + { + System.out.println(e.getMessage()); + e.printStackTrace(System.out); + } + } +} +" +A20241," +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Formatter; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author milen.chechev + */ +public class Dancing { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(""input.txt"")); + Formatter out = new Formatter(new File(""output.txt"")); + + int t = in.nextInt(); + for(int k = 0; k < t ; k++){ + int n = in.nextInt(); + int surprizing = in.nextInt(); + int limit = in.nextInt(); + int accum = 0; + for(int i = 0 ; i < n ; i ++){ + int sum = in.nextInt(); + if(sum/3 >= limit){ + accum ++; + }else if( sum%3 == 0 ){ + if(sum/3> 0 && sum/3+1 >=limit && surprizing>0){ + accum ++; + surprizing--; + } + }else if ( sum%3==1){ + if(sum/3+1 >=limit){ + accum++; + }else if(sum/3> 0 && surprizing > 0 && sum/3+2 >=limit){ + accum++; + surprizing--; + } + }else if(sum%3==2){ + if(sum/3+1 >=limit){ + accum++; + }else if(surprizing >0 && sum/3+2 >=limit){ + accum++; + surprizing--; + } + } + } + out.format(""Case #%d: %d\n"",k+1,accum); + } + out.close(); + } + +} +" +A21427,"package wangshu.codejam.google.com; + +import java.io.File; +import java.io.FileWriter; +import java.util.*; +import java.util.regex.*; + +public class QB { + + /** + * @param args + */ + public static int calculateNumber(int S, int p, int[] t){ + + int yes=0, maybe=0; + int temp; // temp is the higher value of p-1 or p-2 compared with 0; + + // For each Googler, calculate result + for(int i=0; i0) ? p-1:0; + if (t[i]-p-temp*2 >= 0){ + yes++; + }else{ + temp = ((p-2)>0) ? p-2:0; + if (t[i]-p-temp*2 >=0) + maybe++; + } + } + + if(maybe > S){ + maybe = S; + } + + return yes+maybe ; + } + + public static void main(String[] args) throws java.lang.Exception{ + + Scanner sc_line = new Scanner(new File(""qb_in_large.txt"")); // Line scanner for input file + Scanner sc_int; // Integer scanner for each line + sc_line.useDelimiter(Pattern.compile(""[\\p{javaWhitespace}]+"")); + String line; + int T; // Number of test cases + int N, S, p; + int[] t; + FileWriter outputFile = new FileWriter(""qb_out_large.txt""); // Output file + + // Read number of test cases + T = sc_line.nextInt(); + sc_line.nextLine(); + + // Read each test case + for(int i=0; i 0 ? p + (p - 1) + (p - 1) : 0; + int totalS = p > 1 ? p + (p - 2) + (p - 2) : total; +// System.out.println(N + "","" + S + "","" + p + "","" + +// total + "","" + totalS); + for(int i = 3; i < N + 3; i++) { + int now = Integer.parseInt(s[i]); + if(now >= total || (now >= totalS && S-- > 0)) { + result++; + } + } + return result; + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""src/B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""src/B-large.out"")); + int T = Integer.parseInt(br.readLine()); + for(int i = 0; i < T; i++) { + bw.write(""Case #"" + (i+1) + "": "" + + judgeGooglersNum(br.readLine())); + bw.newLine(); + } + bw.flush(); + bw.close(); + br.close(); + } +} +" +A21742,"package com.google.codejam2011.dancing; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class Runner { + + public ArrayList output = new ArrayList(); + + public class DancingEvent { + private ArrayList scoreList; + private int surprisingCount; + private int maxValue; + + public ArrayList getScoreList() { + return scoreList; + } + + public void setScoreList(ArrayList scoreList) { + this.scoreList = scoreList; + } + + public int getSurprisingCount() { + return surprisingCount; + } + + public void setSurprisingCount(int surprisingCount) { + this.surprisingCount = surprisingCount; + } + + public int getMaxValue() { + return maxValue; + } + + public void setMaxValue(int maxValue) { + this.maxValue = maxValue; + } + } + + private class Score { + private final static int JURY_COUNT = 3; + private int values[] = new int[JURY_COUNT]; + private int sum; + private int max; + private int maxSurprise; + + public Score(int pSum) { + this.sum = pSum; + } + + public void calcValues() { + if (this.sum == 0) { + max = 0; + maxSurprise = 0; + } else { + int base = this.sum / JURY_COUNT; + int rest = this.sum % JURY_COUNT; + + for (int i = 0; i < values.length; i++) { + values[i] = base; + if (rest != 0) { + values[i]++; + rest--; + } + } + + rest = this.sum % JURY_COUNT; + + if (rest == 0) { + max = base; + maxSurprise = base + 1; + } else { + max = base + 1; + if (rest == 1) + maxSurprise = base + 1; + else + maxSurprise = base + 2; + } + } + } + + public boolean isBigger(int p) { + if (this.max >= p) + return true; + else + return false; + } + + public boolean isSurpriseBigger(int p) { + if (this.maxSurprise >= p) + return true; + else + return false; + } + } + + public class InputParser { + private BufferedReader br; + + public InputParser(String path, ArrayList dances) { + try { + br = new BufferedReader(new FileReader(new File(path))); + + String inputLine; + int T = 0, N, S, P, counter = 0; + int countBase = 0, counterSurprise = 0; + try { + while ((inputLine = br.readLine()) != null) { + if (T == 0) { + T = new Integer(inputLine); + } else { + String input[] = inputLine.split("" ""); + N = new Integer(input[0]); + S = new Integer(input[1]); + P = new Integer(input[2]); + countBase = 0; + counterSurprise = 0; + ArrayList scores = new ArrayList(); + + for (int i = 3; i < input.length; i++) { + Score tmpScore = new Score( + new Integer(input[i])); + tmpScore.calcValues(); + scores.add(tmpScore); + + if (tmpScore.isBigger(P)) + countBase++; + else if (tmpScore.isSurpriseBigger(P)) + counterSurprise++; + } + + DancingEvent dance = new DancingEvent(); + dance.setMaxValue(P); + dance.setScoreList(scores); + dance.setSurprisingCount(S); + dances.add(dance); + output.add(""Case #""+ counter + "": "" + + ((Integer) Math.min( + counterSurprise, S) + (Integer) countBase)); + } + counter++; + } + } catch (NumberFormatException e) { + e.printStackTrace(); + System.out.println(""Could not parse Numbers""); + } catch (IOException e) { + e.printStackTrace(); + System.out.println(""Could not Read Lines""); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.out.println(""Could not open file""); + } + + } + } + + public void writeOutput(String path){ + BufferedWriter bw; + try { + bw = new BufferedWriter( new FileWriter(new File(path))); + for(String s : output) + try { + bw.write(s + ""\r\n""); + } catch (IOException e) { + e.printStackTrace(); + System.out.println(""Could not write in file""); + } + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + System.out.println(""Could not open file""); + } + + } + + public static void main(String args[]) { + Runner r = new Runner(); + ArrayList dances = new ArrayList(); + r.new InputParser(""src/com/google/codejam2011/dancing/input.txt"", + dances); + r.writeOutput(""src/com/google/codejam2011/dancing/output.txt""); + } +} +" +A21315,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + + +public class B { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader br= new BufferedReader(new FileReader(args[0])); + BufferedWriter bw= new BufferedWriter(new FileWriter(args[0]+"".out"")); + String line= br.readLine(); + int cases= Integer.parseInt(line); + for (int i= 0; i != cases; i++) { + line= br.readLine(); + Scanner sc= new Scanner(line); + List list= new ArrayList(); + while (sc.hasNextInt()) { + int a= sc.nextInt(); + list.add(a); + } + int[] params= new int[list.size()]; + for (int j= 0; j != params.length; j++) { + params[j]= list.get(j).intValue(); + } + bw.write(""Case #""+(i+1)+"": ""+max(params)+""\n""); + } + br.close(); + bw.close(); + } + + public static int max(int[] params) { + int n= params[0]; + int s= params[1]; + int p= params[2]; + + int normal= 0; + int surprising= 0; + + for (int i= 0; i != n; i++) { + if ((params[3+i]+2)/3 >= p) normal++; + else if ((params[3+i]+4)/3 >= p && params[3+i] >= 2) surprising++; + } + + return normal + Math.min(surprising, s); + } + +} +" +A20765,"package dancing_with_googlers; + +import java.io.IOException; +import java.util.ArrayList; + +public class FindNumber { + + public static Integer start (String casus) { + + String[] splitInput = casus.split("" ""); + + ArrayList intinput = new ArrayList(); + for (String s: splitInput) { + intinput.add(Integer.parseInt(s)); + System.out.print(s + "" ""); + } + System.out.println(); + + int nr=0; + + int googlers = intinput.get(0); + int surprise = intinput.get(1); + int p = intinput.get(2); + + for(int i=0; i<3; i++) { + intinput.remove(0); + } + + for(int i=0; i0) { + if ((intinput.get(i)/3)>=p) { + passtest=true; + System.out.println(""Integer "" + intinput.get(i) + "" was devided by three and the result was bigger or equal to "" + p); + } + else if (((intinput.get(i)-p)/2)>=(p-1)){ + passtest=true; + System.out.println(""Integer "" + intinput.get(i) + "" was deminished by "" + p + "" and the result was devided by two. The result of this was bigger or equal to "" + (p-1)); + } + else if (((intinput.get(i)-p)/2)>=(p-2)&&surprise>0) { + passtest=true; + surprise--; + System.out.println(""Integer "" + intinput.get(i) + "" was deminished by "" + p + "" and the result was devided by two. The result of this was bigger or equal to "" + (p-2) + "" and we still had some surprises left.""); + } + } + if (passtest) nr++; + System.out.println("" nr is now set to "" + nr); + } + + return nr; + } +} +" +A20750,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class Dance { + private static final String inFile = ""B-large.in""; + private static final String outFile = ""output.txt""; + + private static final int CONTESTANTS = 0; + private static final int SURPRISES = 1; + private static final int WINNERS = 2; + private static final int POINTS_START = 3; + + public static void main(String[] args) throws IOException { + /* * * Initialization -- START * * */ + BufferedReader iStream = new BufferedReader(new FileReader(inFile)); + BufferedWriter oStream = new BufferedWriter(new FileWriter(outFile)); + + int contestants = 0; + int surprises = 0; + int threshold = 0; + int total = 0; + int winners = 0; + + List scores = null; + String[] elements = null; + /* * * Initialization -- END * * */ + + + total = new Integer(iStream.readLine()); + + for(int i = 0; i < total; i++) { + String line = iStream.readLine(); + + scores = new ArrayList(); + winners = 0; + + elements = line.split("" ""); + + // Grab over-head data + contestants = new Integer( elements[CONTESTANTS] ); + surprises = new Integer( elements[SURPRISES] ); + threshold = new Integer( elements[WINNERS] ); + + // Allocate the scores + for(int j = 0; j < contestants; j++) { + int value = new Integer( elements[POINTS_START+j] ); + scores.add( new Scores(value) ); + } + + // Order from highest total to lowest + Collections.sort(scores, Collections.reverseOrder()); + + // Tally the contestants that are above the threshold + for(int k = 0; k < scores.size(); k++) { + if(scores.get(k).getHighest() >= threshold) + winners += 1; + else if(surprises > 0){ //Skew if available + scores.get(k).skew(); + + if(scores.get(k).getHighest() >= threshold) + winners += 1; + + surprises -= 1; + } + } + + oStream.write(""Case #"" + (i+1) + "": "" + winners); + oStream.newLine(); + } + + iStream.close(); + oStream.close(); + } +} +" +A21912,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + int t = -1, s = 0, p = 0, n = 1, cont = 0, aux = 0, aux_res = 0, num_lin = 1; + List ti = new ArrayList(); + List puntajesNoElegidos = new ArrayList(); + try{ + FileInputStream fstream = new FileInputStream(""C:\\Users\\Joel\\Desktop\\B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + FileWriter fwstream = new FileWriter(""C:\\Users\\Joel\\Desktop\\out.txt""); + BufferedWriter out = new BufferedWriter(fwstream); + + String strLine; + while ((strLine = br.readLine()) != null) { + s = 0; + p = 0; + n = 1; + cont = 0; + aux_res = 0; + ti = new ArrayList(); + puntajesNoElegidos = new ArrayList(); + if(t == -1){ + t = Integer.valueOf(strLine); + } + else{ + for(String str : strLine.split("" "")){ + switch (cont) { + case 0: + n = Integer.valueOf(str); + break; + case 1: + s = Integer.valueOf(str); + break; + case 2: + p = Integer.valueOf(str); + break; + default: + ti.add(Integer.valueOf(str)); + break; + } + cont ++; + } + + for(Integer total : ti){ + aux = total / 3; + if(aux > p){ + aux_res++; + } + else{ + if(total % 3 == 0){ + if(aux == p){ + aux_res++; + } + else{ + puntajesNoElegidos.add(total); + } + } + else{ + if(aux == p || aux + 1 == p){ + aux_res++; + } + else{ + puntajesNoElegidos.add(total); + } + } + } + } + for(Integer total : puntajesNoElegidos){ + aux = total / 3; + if(s == 0){ + break; + } + else if(total % 3 == 0 && aux != 0){ + if(aux + 1 == p){ + aux_res++; + s--; + } + } + else if(total % 3 == 2){ + if(aux + 2 == p && aux != 0){ + aux_res++; + s--; + } + } + } + + out.write(""Case #"" + num_lin + "": "" + aux_res); + out.newLine(); + num_lin++; + } + } + in.close(); + out.close(); + } + catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + } +} + +" +A20010,"import java.util.Scanner; + + +public class B { + + int answer (int N, int S, int p, int[] T) { + int num = 0; + + for (int t: T) { + int avg = t/3; + + boolean canBeSurprising = false; + boolean cleanWin = false; + for (int a=avg-2; a<=avg+3; a++) { + for (int b=avg-2; b<=avg+3; b++) { + int c = t-a-b; + + if (a<0 || b<0 || c<0) + continue; + + if (Math.abs(Math.max(Math.max(a, b),c) - Math.min(Math.min(a, b),c))<=1) { + if (Math.max(Math.max(a, b),c)>=p) + cleanWin=true; + } else if (Math.abs(Math.max(Math.max(a, b),c) - Math.min(Math.min(a, b),c))<=2) { + if (Math.max(Math.max(a, b),c)>=p) + canBeSurprising=true; + } + } + } + + if (cleanWin) + num++; + else if (canBeSurprising && S>0) { + num++; S--; + } + } + + return num; + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + B b = new B(); + int T = Integer.parseInt(sc.nextLine()); + for (int i=0; i map = new HashMap(); + map.put(0, new Integer[] {0, 0, 0}); + map.put(1, new Integer[] {1, 0, 0}); + map.put(2, new Integer[] {1, 1, 0}); + map.put(3, new Integer[] {1, 1, 1}); + map.put(4, new Integer[] {2, 1, 1}); + map.put(5, new Integer[] {2, 2, 1}); + map.put(6, new Integer[] {2, 2, 2}); + map.put(7, new Integer[] {3, 2, 2}); + map.put(8, new Integer[] {3, 3, 2}); + map.put(9, new Integer[] {3, 3, 3}); + map.put(10, new Integer[] {4, 3, 3}); + map.put(11, new Integer[] {4, 4, 3}); + map.put(12, new Integer[] {4, 4, 4}); + map.put(13, new Integer[] {5, 4, 4}); + map.put(14, new Integer[] {5, 5, 4}); + map.put(15, new Integer[] {5, 5, 5}); + map.put(16, new Integer[] {6, 5, 5}); + map.put(17, new Integer[] {6, 6, 5}); + map.put(18, new Integer[] {6, 6, 6}); + map.put(19, new Integer[] {7, 6, 6}); + map.put(20, new Integer[] {7, 7, 6}); + map.put(21, new Integer[] {7, 7, 7}); + map.put(22, new Integer[] {8, 7, 7}); + map.put(23, new Integer[] {8, 8, 7}); + map.put(24, new Integer[] {8, 8, 8}); + map.put(25, new Integer[] {9, 8, 8}); + map.put(26, new Integer[] {9, 9, 8}); + map.put(27, new Integer[] {9, 9, 9}); + map.put(28, new Integer[] {10, 9, 9}); + map.put(29, new Integer[] {10, 10, 9}); + map.put(30, new Integer[] {10, 10, 10}); + line = br.readLine(); + int cases = Integer.parseInt(line); + for (int i=1; i<=cases;i++){ + line = br.readLine(); + String[] values = line.split("" ""); + int N = Integer.parseInt(values[0]); + int S = Integer.parseInt(values[1]); + int p = Integer.parseInt(values[2]); + Integer[] scores = new Integer[N]; + for (int j = 0; j< N; j++){ + scores[j] = Integer.parseInt(values[3+j]); + } + Arrays.sort(scores, Collections.reverseOrder()); + int total=0; + for (int j = 0; j< N; j++){ + Integer[] triplet = map.get(scores[j]).clone(); + if(triplet[0]>=p){ + total++; + } + else{ + if (S > 0){ + if(surprising(triplet,scores[j])){ + if(triplet[0]>=p){ + S--; + total++; + } + } + } + } + } + out.println(""Case #""+i+"": ""+total); + + } + in.close(); + out.close(); + } catch (Exception e) {//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + private static boolean surprising(Integer[] triplet, int score) { + if(score < 2 || score> 27) + return false; + else{ + if(triplet[0]==triplet[1]){ + triplet[0]++; + triplet[1]--; + Arrays.sort(triplet,Collections.reverseOrder()); + return true; + } + else{ + triplet[1]++; + triplet[2]--; + Arrays.sort(triplet,Collections.reverseOrder()); + return true; + } + } + } + +}" +A20420," +public class codejam { + public static void main(String argv[]) throws Exception{ + DancingWiththeGooglers dancingWiththeGooglers=new DancingWiththeGooglers(); + dancingWiththeGooglers.start(); + } +} +" +A20569,"package ProblemSolvers; +import Controller.IO; + +public abstract class ProblemSolver { + + protected IO io; + protected int cases; + + public ProblemSolver(String filePath) { + io = new IO(filePath); + } + + public abstract void process(); + +} +" +A21638,"import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +public class QrB { + private CodeJamTextInputReader input = null; + private CodeJamTextOutputWriter output = null; + + public static void main(String args[]) { + // CodeJamUtils.initLineEndings(); + try { + QrB qrA = new QrB(); + qrA.run(new File(args[0]), new File(args[1])); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvalidInputException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public QrB() { + } + + public void run(File outputFile, File inputFile) + throws InvalidInputException, IOException { + try { + input = new CodeJamTextInputReader(inputFile); + output = new CodeJamTextOutputWriter(outputFile); + + actualRun(); + } finally { + if (input != null) { + input.close(); + } + if (output != null) { + output.close(); + } + } + } + + private void actualRun() throws IOException { + while (input.hasNextTestCase()) { + String in = input.readNextLine(); + final int textCaseNum = input.getLastReadTestCaseNumber(); + + output.outputTestCase(textCaseNum, singleTestCase(in)); + } + } + + private String singleTestCase(String in) { + CodeJamLineParser parser = new CodeJamLineParser(in); + final int numOfParticipants = parser.readNextInt(); + final int numOfSurprising = parser.readNextInt(); + final int bestAtLeast = parser.readNextInt(); + final int[] totalScores = parser.readNextIntList(numOfParticipants); + + Arrays.sort(totalScores); + + int surprisingRemaining = numOfSurprising; + int numOfCountedParticipants = 0; + + // Go from highest to lowest + for (int i = numOfParticipants - 1; i >= 0; --i) { + int curTotalScore = totalScores[i]; + if (bestScore(curTotalScore, false) >= bestAtLeast) { + ++numOfCountedParticipants; + } else if (surprisingRemaining > 0 && canBeSurprising(curTotalScore) + && bestScore(curTotalScore, true) >= bestAtLeast) { + ++numOfCountedParticipants; + --surprisingRemaining; + } + } + + return Integer.toString(numOfCountedParticipants); + } + + boolean canBeSurprising(int totalScore) { + // 0 and 1 are special cases. + return totalScore >= 2; + } + + int bestScore(int totalScore, boolean surprising) { + int mod3 = totalScore % 3; + int div3 = totalScore / 3; + + if (mod3 == 0) { + return surprising ? (div3 + 1) : div3; + } else if (mod3 == 1) { + return div3 + 1; + } else { + return surprising ? (div3 + 2) : (div3 + 1); + } + } +} +" +A20352,"package jam2012; +import java.io.*; +import java.util.*; + +// Marian G Olteanu +public class QB +{ + public static void main(String[] args) + throws Exception + { + BufferedReader inputFile = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); + int cases = Integer.parseInt(inputFile.readLine()); + + PrintStream outFile = new PrintStream(new FileOutputStream(args[1])); + for (int i = 1; i <= cases; i++) + { + String lineT[] = tokenize(inputFile.readLine()); + int N = Integer.parseInt(lineT[0]); + int S = Integer.parseInt(lineT[1]); + int p = Integer.parseInt(lineT[2]); + + int thresholdAlways = 3 * p - 2; + int thresholdSurprise = Math.max(1, 3 * p - 4);// if p = 1, score of 0 is not good for surprise + + int cntAlways = 0; + int cntNeedSurprise = 0; + for (int j = 3; j < lineT.length; j++) + { + int value = Integer.parseInt(lineT[j]); + if (value >= thresholdAlways) + cntAlways++; + else if (value >= thresholdSurprise) + cntNeedSurprise++; + } + + int out = cntAlways + Math.min(S, cntNeedSurprise); + + outFile.println(""Case #"" + i + "": "" + out); + } + + + outFile.close(); + inputFile.close(); + } + + + + + public static String[] tokenize(String input) + { + StringTokenizer st = new StringTokenizer(input); + String[] k = new String[st.countTokens()]; + for (int i = 0; i < k.length; i++) + k[i] = st.nextToken(); + return k; + } + public static String[] tokenize(String input, String sep) + { + StringTokenizer st = new StringTokenizer(input , sep); + String[] k = new String[st.countTokens()]; + for (int i = 0; i < k.length; i++) + k[i] = st.nextToken(); + return k; + } + +} + +" +A21813,"package com.udit.codeJam; + +import java.io.*; + + +public class Gogglers +{ + static DataInputStream in = new DataInputStream(new + BufferedInputStream(System.in)); + static BufferedReader din = new BufferedReader( new InputStreamReader(in)); + + + public static void main(String[] args) + { + int [] normal = new int[31]; + int [] surprise = new int[31]; + for(int i=0;i<31;i++){ + if(i%3 == 0){ + normal[i] = i/3; + surprise[i] = i/3+1; + } else { + normal[i] = i/3 +1; + if(i%3 ==1){ + surprise[i] = i/3+1; + } else { + surprise[i] = i/3+2; + } + } + } + surprise[0]=0; + surprise[29] = 10; + surprise[30] = 10; + int T = parseInt(getLine()); + String[] arr = new String[T]; + for(int i=0;i 0 && scoresRequired <= surprise[parseInt(inputs[j + 3])]) { + count++; + surpriseNum--; + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + count); + } + + } + + + public static String getLine(){ + String input = """"; + try { + input = din.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return input; + } + + public static void printArray(int[][] b, int m, int n) { + for(int i = 0;i < m;i++){ + System.out.println(); + for(int j = 0;j < n;j++){ + System.out.print((b[i][j] + "" "")); + } + } + } + + public static int parseInt(String s){ + return Integer.parseInt(s); + } + public static double parseDouble(String s){ + return Double.parseDouble(s); + } + public static void sout(Object n){ + System.out.print(n); + } + public static void soutln(Object n){ + System.out.println(n); + } +} +" +A22189,"package com.parijat; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Sol2 { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""./input.txt""))); + FileOutputStream fos = new FileOutputStream(""output.txt""); + int testcases = Integer.parseInt(reader.readLine()); + for(int i=0; i< testcases; i++) { + String[] temp = reader.readLine().split("" ""); + int dancers = Integer.parseInt(temp[0]); + int surprises = Integer.parseInt(temp[1]); + int min_best_score = Integer.parseInt(temp[2]); + + int t = min_best_score - 2; + if(t< 0) { + t = 0; + } + int min_score_with_surprise = min_best_score + 2*t; + + t = min_best_score - 1; + if(t< 0) { + t = 0; + } + int min_score_normal = min_best_score + 2*t; + + int success = 0; + for(int j=3; j= min_score_normal) { + success++; + } else if(score >= min_score_with_surprise && surprises > 0) { + surprises--; + success++; + } + } + fos.write((""Case #"" + (i+1) + "": "" + success + ""\n"").getBytes()); + } + + } + +} +" +A21767,"import java.util.*; + +public class Dancers { + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + int times = sc.nextInt(); + + for (int c = 1; c <= times; c++) { + int players = sc.nextInt(); + int surprises = sc.nextInt(); + int best = sc.nextInt(); + + int count = 0; + + int[] scores = new int[] { 0, 0, 0 }; + + for (int i = 0; i < players; i++) { + + int score = sc.nextInt(); + + scores[0] = scores[1] = scores[2] = score / 3; + + if (score / 3 >= best) { + count++; + } + + else { + int difference = score - scores[0]*3; + switch (difference) { + case 0: { + if (surprises > 0) { + if (scores[0] > 0 && scores[0] + 1 >= best) { + count++; + surprises--; + } + } + break; + } + + case 1: { + if (scores[0] + 1 >= best) { + count++; + } else if (surprises > 0) { + + if (scores[0] + 1 >= best) { + count++; + surprises--; + } + } + break; + } + + case 2: { + if (scores[0] + 1 >= best) { + count++; + } else if (surprises > 0) { + + if (scores[0] + 2 >= best) { + count++; + surprises--; + } + } + break; + } + + default: + break; + } + } + + } + + System.out.println(""Case #""+c+"": ""+count); + } + + } + +} +" +A21621,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package test2; + +import java.util.LinkedList; + +/** + * + * @author Student + */ +public class Best { + + public static LinkedList scores(int som) { + LinkedList res = new LinkedList(); + int x = som / 3; + switch (som % 3) { + case 0: { + res.add(new Score(x, x, x,!true)); + res.add(new Score(x - 1, x + 1, x,!false)); + break; + } + case 1: { + res.add(new Score(x, x, x + 1,!true)); + res.add(new Score(x - 1, x + 1, x + 1,!false)); + break; + } + case 2: { + res.add(new Score(x, x, x+2,!false)); + res.add(new Score(x, x + 1, x+1,!true)); + break; + } + } + if(!res.getFirst().isValid()) res.removeFirst(); + if(!res.getLast().isValid()) res.removeLast(); + return res; + } + + public static int opt(int n,int s,int p,LinkedList l){ + LinkedList lg=new LinkedList<>(); + int restofs=s; + for(Integer i:l){ + LinkedList xxx=scores(i); + switch(xxx.size()){ + case 1: { + if(xxx.getFirst().isbetter(p)) lg.add(xxx.getFirst()); + break; + } + + case 2: { + if(xxx.getFirst().isSurprising()){ + if(xxx.getFirst().isbetter(p)&& restofs!=0&&!xxx.getLast().isbetter(p)){ + lg.add(xxx.getFirst()); + restofs--; + break; + } + } + if(xxx.getLast().isSurprising()){ + if(xxx.getLast().isbetter(p)&& restofs!=0&&!xxx.getFirst().isbetter(p)){ + lg.add(xxx.getLast()); + restofs--; + break; + } + } + if(xxx.getLast().isbetter(p)&&!xxx.getLast().isSurprising()){ + lg.add(xxx.getLast()); + break; + } + if(xxx.getFirst().isbetter(p)&&!xxx.getFirst().isSurprising()){ + lg.add(xxx.getFirst()); + break; + } + } + } + + } + + return lg.size(); + + } +}" +A21559,"package codejam2012Qualification; +import java.io.*; +import java.util.*; +public class B { + public static void main(String[] args)throws IOException { + boolean large = false; + large = true; + String dir = ""C://Users//Aayush//Desktop//""; + String InputFile = dir + (large ? ""B-large.in"" : ""B-small-attempt0.in""); + String OutputFile = dir + (large ? ""B-large.out"" : ""B-small.out""); + File file = new File(InputFile); + Scanner st = new Scanner(file); + FileWriter fw = new FileWriter(OutputFile); + int T = st.nextInt(); + for(int cases = 1; cases <= T; cases++){ + int N = st.nextInt(); + int S = st.nextInt(); + int p = st.nextInt(); + int[] t = new int[N]; + for(int i = 0; i < N; i++){ + t[i] = st.nextInt(); + } + int count = 0; + for(int i = 0; i < N; i++){ + //a, b and are the scores allotted to googler a <= b <= c + int a = t[i] / 3; + int b = t[i] / 3; + int c = t[i] / 3; + if(t[i] % 3 == 0){ + if(c >= p)count++; + else if(b > 0 && c == p - 1 && S > 0){ + S--; + count++; + } + }else if(t[i] % 3 == 1){ + c += 1; + if(c >= p)count++; + }else if(t[i] % 3 == 2){ + c += 1; + b += 1; + if(c >= p)count++; + else if(b > 0 && c == p - 1 && S > 0){ + S--; + count++; + } + } + } + System.out.print(""Case #"" + cases + "": "" + count); + fw.write(""Case #"" + cases + "": "" + count); + + System.out.println(); + fw.write(""\n""); + + } + fw.flush(); + fw.close(); + + } +} +" +A21703,"package gcj.y2012.qual; +import java.io.*; +import java.util.*; + +public class B { + private static String fileName = B.class.getSimpleName().replaceFirst(""_.*"", """").toLowerCase(); + private static String inputFileName = fileName + "".in""; + private static String outputFileName = fileName + "".out""; + private static Scanner in; + private static PrintWriter out; + + int couldGetAtLeastP(int total, int p) { + int best = (total + 2) / 3; + if (best >= p) { + return 2; + } + int bestSurprising = (total + 4) / 3; + if (bestSurprising >= p && total >= 2 && total <= 28) { + return 1; + } + return 0; + } + + private void solve() { + int n = in.nextInt(); + int surprising = in.nextInt(); + int p = in.nextInt(); + int[] count = new int[3]; + for (int i = 0; i < n; i++) { + int total = in.nextInt(); + count[couldGetAtLeastP(total, p)]++; + } + out.println(count[2] + Math.min(count[1], surprising)); + } + + public static void main(String[] args) throws IOException { + Locale.setDefault(Locale.US); + if (args.length >= 2) { + inputFileName = args[0]; + outputFileName = args[1]; + } + in = new Scanner(new FileReader(inputFileName)); + out = new PrintWriter(outputFileName); + int tests = in.nextInt(); + in.nextLine(); + for (int t = 1; t <= tests; t++) { + out.print(""Case #"" + t + "": ""); + new B().solve(); + System.out.println(""Case #"" + t + "": solved""); + } + in.close(); + out.close(); + } +} +" +A22554,"package y2012; + +import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + +public class QR2 { + + public static void main(String[] args) throws Exception { + Scanner inputFile=new Scanner(new File(args[0])); + PrintWriter outputFile=new PrintWriter(new File(args[1])); + + int t=Integer.parseInt(inputFile.nextLine()); + for(int i=0;i= p) { + result = result + 1; + } else if( scoreboard[j][2] == p-1 //diff with 1 score + && numSurprising > 0 //still has suprise quota + && scoreboard[j][1] != 1 //suprise-able? + && (scoreboard[j][0] >= 3 && scoreboard[j][0] <= 27) //suprise-able? + ) { + result = result + 1; + numSurprising = numSurprising - 1; + } + } + + outputFile.println(""Case #""+(i+1)+"": "" + result); + System.out.println(""Case #""+(i+1)+"": "" + result); + } + + inputFile.close(); + outputFile.close(); + } + +} +" +A20828,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.List; + +public class Googlers { + + public static void main(String[] args) throws Exception { + String srcFile = ""C:"" + File.separator + ""Documents and Settings"" + + File.separator + ""rohit"" + File.separator + ""My Documents"" + + File.separator + ""Downloads"" + File.separator + + ""A-small-attempt0.in""; + String destFile = ""C:"" + File.separator + ""Documents and Settings"" + + File.separator + ""rohit"" + File.separator + ""My Documents"" + + File.separator + ""Downloads"" + File.separator + + ""A-small-attempt0.out""; + File file = new File(srcFile); + List readData = new ArrayList(); + FileReader fileInputStream = new FileReader(file); + BufferedReader bufferedReader = new BufferedReader(fileInputStream); + StringBuilder stringBuilder = new StringBuilder(); + String line = null; + while ((line = bufferedReader.readLine()) != null) { + readData.add(line); + } + stringBuilder.append(generateOutput(readData)); + File writeFile = new File(destFile); + if (!writeFile.exists()) { + writeFile.createNewFile(); + } + FileWriter fileWriter = new FileWriter(writeFile); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + bufferedWriter.write(stringBuilder.toString()); + bufferedWriter.close(); + System.out.println(""output"" + stringBuilder); + } + + /** + * @param number + * @return + */ + private static String generateOutput(List number) { + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < number.size(); i++) { + if (i == 0) { + continue; + } else { + String tempString = number.get(i); + stringBuilder.append(""Case #"" + i + "": ""); + stringBuilder.append(testMethod(tempString)); + stringBuilder.append(""\n""); + } + } + if (stringBuilder.length() > 0) { + stringBuilder.deleteCharAt(stringBuilder.length() - 1); + } + return stringBuilder.toString(); + } + + private static List probability(int total) { + List val = new ArrayList(); + int n1, n2, n3, n; + n = total / 3; + n1 = n2 = n3 = n; + if (n1 + n2 + n3 == total) { + n1 = n2 = n3 = n; + } + if (n1 + n2 + n3 + 1 == total) { + n1 = n1 + 1; + } + if (n1 + n2 + n3 + 2 == total) { + n1 = n1 + 1; + n2 = n2 + 1; + } + val.add(n1); + val.add(n2); + val.add(n3); + return val; + } + + private static List probabilityWithSurp(int total) { + List val = new ArrayList(); + int n1, n2, n3, n; + n = total / 3; + n1 = n2 = n3 = n; + if (total % 3 == 0) { + n1 = n1 - 1; + n3 = n3 + 1; + } else if (total % 3 == 1) { + n1 = n1 + 1; + n2 = n2 + 1; + n3 = n3 - 1; + } else if (total % 3 == 2) { + n3 = n3 + 2; + } + val.add(n1); + val.add(n2); + val.add(n3); + return val; + } + + private static String testMethod(String test) { + String[] testArr = test.split("" ""); + int noOfG = Integer.valueOf(testArr[0]); + int supR = Integer.valueOf(testArr[1]); + int freQ = Integer.valueOf(testArr[2]); + List val = new ArrayList(); + int count = 0; + for (int i = 3; i < noOfG + 3; i++) { + int no = Integer.valueOf(testArr[i]); + val = probability(no); + System.out.println(i + "" "" + val.toString()); + boolean isFreqPresent = testIsPresent(val, freQ); + if (isFreqPresent) { + count++; + } else { + if (supR > 0 && no >= 2 && no <= 28) { + val = probabilityWithSurp(no); + System.out.println(i + "" "" + val.toString()); + if (testIsPresent(val, freQ)) { + count++; + supR--; + } + } + } + + } + + return String.valueOf(count); + } + + private static boolean testIsPresent(List valInsideList, int freQ) { + boolean isFreq = false; + for (Integer valInside : valInsideList) { + if (valInside >= freQ) { + isFreq = true; + break; + } + } + return isFreq; + } +}" +A22580,"package dancers; +import java.io.BufferedReader; +import java.io.FileReader; +public class Dancing { + static int solve(int N, int S, int p, int[] ts) { + int good = 0, improveable = 0; + for (int i = 0; i < ts.length; ++i) { + int total = ts[i]; + int simple=0, special=0; + if (total % 3 == 0) { + simple = total/3; + if (simple > 0 && simple < 10) special = simple+1; + } else if (total % 3 == 1) { + simple = total/3+1; + if (total/3 > 0) special = simple; + } else if (total % 3 == 2) { + simple = total/3+1; + special = simple+1; + } + if (simple >= p) ++good; + else if (special >= p) ++improveable; + } + return good + Math.min(improveable,S); + } + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(args[0])); + String line = in.readLine(); + int X = Integer.parseInt(line); + for (int i = 0; i < X; ++i) { + line = in.readLine(); + String[] toks = line.split("" ""); + int N = Integer.parseInt(toks[0]); + int S = Integer.parseInt(toks[1]); + int p = Integer.parseInt(toks[2]); + int[] ts = new int[N]; + for (int j = 0; j < N; ++j) { + ts[j] = Integer.parseInt(toks[3+j]); + } + System.out.println(""Case #""+(i+1)+"": ""+solve(N,S,p,ts)); + } + } +}" +A22927,"package com.vp.common; + +public class CommonUtility { + + public static int[] convertStringArraytoIntArray(String[] sarray) { + if (sarray != null) { + int intarray[] = new int[sarray.length]; + for (int i = 0; i < sarray.length; i++) { + intarray[i] = Integer.parseInt(sarray[i]); + } + return intarray; + } + + return null; + } + + public static float[] convertStringArraytoFloatArray(String[] sarray) { + if (sarray != null) { + float floatArray[] = new float[sarray.length]; + for (int i = 0; i < sarray.length; i++) { + floatArray[i] = Float.parseFloat(sarray[i]); + } + return floatArray; + } + + return null; + } + + public static double[] convertStringArraytoDoubleArray(String[] sarray) { + if (sarray != null) { + double darray[] = new double[sarray.length]; + for (int i = 0; i < sarray.length; i++) { + darray[i] = Double.parseDouble(sarray[i]); + } + return darray; + } + + return null; + } + + public static long[] convertStringArraytoLongArray(String[] sarray) { + if (sarray != null) { + long longarray[] = new long[sarray.length]; + for (int i = 0; i < sarray.length; i++) { + longarray[i] = Long.parseLong(sarray[i]); + } + return longarray; + } + + return null; + } + + + public static void print(int a[]) + { + System.out.print(""[ ""); + for (int i = 0; i < a.length; i++) { + System.out.print(a[i] + "", ""); + } + System.out.print("" ]""); + System.out.println(""""); + } + + public static void printWithoutExtrLine(int a[]) + { + System.out.print(""[ ""); + for (int i = 0; i < a.length; i++) { + System.out.print(a[i] + "", ""); + } + System.out.print("" ]""); + } + + + public static void print(float a[]) + { + System.out.print(""[ ""); + for (int i = 0; i < a.length; i++) { + System.out.print(a[i] + "", ""); + } + System.out.print("" ]""); + System.out.println(""""); + } + + public static void print(double a[]) + { + System.out.print(""[ ""); + for (int i = 0; i < a.length; i++) { + System.out.print(a[i] + "", ""); + } + System.out.print("" ]""); + System.out.println(""""); + } + + + public static void print(long a[]) + { + System.out.print(""[ ""); + for (int i = 0; i < a.length; i++) { + System.out.print(a[i] + "", ""); + } + System.out.print("" ]""); + System.out.println(""""); + } + + public static void print(String a[]) + { + System.out.print(""[ ""); + for (int i = 0; i < a.length; i++) { + System.out.print(a[i] + "", ""); + } + System.out.print("" ]""); + System.out.println(""""); + } + +} +" +A23038,"package qualification.b; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class Core { + + public static void main(String[] args) { + int t, n, s, p; + + try { + Scanner scan = new Scanner(new File(args[0])); + + t = scan.nextInt(); + for (int i = 1; i <= t; i++) { + n = scan.nextInt(); + s = scan.nextInt(); + p = scan.nextInt(); + + System.out.println(solve(i, n, s, p, scan)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public static String solve(int caseNumber, int n, int s, int p, Scanner scan) { + int rangeMin, rangeMax; + rangeMin = p + (2 * Math.max(0, p - 2)); // inc + rangeMax = p + (2 * Math.max(0, p - 1)); // exc + + List aboveP = new ArrayList(); + int score, used; + used = 0; + for (int i = 0; i < n; i++) { + score = scan.nextInt(); + + if (score < rangeMin) + continue; + else if (score >= rangeMax) + aboveP.add(score); + else if (((score - rangeMin) <= 1) && (used < s)) { + used++; + aboveP.add(score); + } + } + + return ""Case #"" + caseNumber + "": "" + aboveP.size(); + } +}" +A22652,"import java.io.BufferedReader; +import java.io.InputStreamReader; + +import org.junit.Assert; + +public class DancingWithTheGooglers { + + public static void main( final String[] args ) throws Exception { + final BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) ); + final int T = Integer.parseInt( br.readLine() ); + for ( int ii = 0; ii < T; ++ii ) { + final String[] parts = br.readLine().split( "" "" ); + final int N = Integer.parseInt( parts[ 0 ] ); + final int S = Integer.parseInt( parts[ 1 ] ); + final int p = Integer.parseInt( parts[ 2 ] ); + final int[] t = new int[N]; + for ( int i = 0; i < N; ++i ) { + t[ i ] = Integer.parseInt( parts[ i + 3 ] ); + } + System.out.printf( ""Case #%d: %d\n"", ii + 1, solve( N, S, p, t ) ); + } + } + + private static int solve( final int n, int s, final int p, final int[] t ) { + int cnt = 0; + for ( int i = 0; i < t.length; ++i ) { + final int k = t[ i ] / 3; + final int mod = t[ i ] % 3; + if ( k + ( mod > 0 ? 1 : 0 ) >= p ) { + ++cnt; + } else if ( s > 0 ) { + // k + k + k -> k+1 + k + k-1 + if ( mod == 0 && k - 1 >= 0 && k + 1 >= p ) { + ++cnt; + --s; + } + + // k+1 + k + k -> k+1 + k+1 + k-1 (not enough) || k+2 + k + k-1 (not ok) + + // k+1 + k+1 + k -> k+2 + k + k + if ( mod == 2 && k + 2 >= p ) { + ++cnt; + --s; + } + } + } + return cnt; + } + + @org.junit.Test + public void statement1() { + final int[] t = { 15, 13, 11 }; + Assert.assertEquals( 3, solve( 3, 1, 5, t ) ); + } + + @org.junit.Test + public void statement2() { + final int[] t = { 23, 22, 21 }; + Assert.assertEquals( 2, solve( 3, 0, 8, t ) ); + } + + @org.junit.Test + public void statement3() { + final int[] t = { 8, 0 }; + Assert.assertEquals( 1, solve( 2, 1, 1, t ) ); + } + + @org.junit.Test + public void statement4() { + final int[] t = { 29, 20, 8, 18, 18, 21 }; + Assert.assertEquals( 3, solve( 6, 2, 8, t ) ); + } + +} +" +A21373,"import java.util.*; +import java.io.*; + +public class Dance +{ + public static void main(String zaga[]) throws FileNotFoundException + { + Scanner input = new Scanner(System.in); + File file = new File(""out.txt""); + PrintStream writer = new PrintStream(file); + + int T = input.nextInt(); + + ArrayList ans = new ArrayList(); + + for(int t = 0; t < T; t++) + { + int N = input.nextInt(); + + int S = input.nextInt(); + + int P = input.nextInt(); + + ArrayList scores = new ArrayList(); + + for(int i = 0; i < N; i++) + { + scores.add(input.nextInt()); + } + + int s = 1; + + for(int i = 0; i < scores.size(); i++) + { + int num = scores.get(i); + + int first = P; + + if((scores.get(i) - P) >= P * 2 ) + { + continue; + } + + if(scores.get(i) - P < 0) + { + scores.remove(i); + --i; + continue; + } + + if(((scores.get(i) - P) / 2) + 1 == P) + { + continue; + } + + if(num - P >= 0) + { + int second = (num - P) / 2; + int third = second; + + if((num - P) % 2 == 1) + { + ++third; + } + + if(second + 2 >= P && third + 2 >= P) + { + if(s <= S) + { + ++s; + continue; + } + else + { + scores.remove(i); + --i; + continue; + } + } + else + { + scores.remove(i); + --i; + continue; + } + + } + else + { + scores.remove(i); + --i; + continue; + } + } + + ans.add(scores.size()); + } + + for(int i = 0; i < ans.size(); i++) + { + writer.print(""Case #""+(i+1)+"": ""+ans.get(i)); + + if(!(i + 1 == ans.size())) + { + writer.print(""\n""); + } + } + + } +}" +A22075,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class DancingWithGooglers_1B_QualGCJ12 { + public static void main(String[] args) { + try{ + BufferedReader br = new BufferedReader(new FileReader(""E:\\Code\\Algorithmz\\src\\myFiles\\B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""E:\\Code\\Algorithmz\\src\\myFiles\\B-large.out"")); + int T=Integer.parseInt(br.readLine()); + for(int currTest=1;currTest<=T;currTest++){ + String currentTestCase[] = br.readLine().split("" ""); + int N=Integer.parseInt(currentTestCase[0]); + int S=Integer.parseInt(currentTestCase[1]); + int p=Integer.parseInt(currentTestCase[2]); + int possibleCount=0; + for(int currentDancer=3,totalDancers=currentTestCase.length;currentDancer=(3*p - 2)) + possibleCount++; + else if (currentTotal>=(3*p -4) && --S>=0) + possibleCount++; + } + bw.write(""Case #""+(currTest)+"": "" + possibleCount+""\n""); + } + bw.close(); + }catch(Exception e){ + e.printStackTrace(); + } + System.err.println(""Done""); + } + +} +" +A21897,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Scanner; + +public class Solution { + HashMap map = new HashMap<>(); + + Solution() throws Exception { + setupIO(""B-large.in""); + } + + String solve() throws Exception { + int n = in.nextInt(); + int surprising = in.nextInt(); + int p = in.nextInt(); + int[] scores = new int[n]; + for (int i = 0; i < n; i ++) + scores[i] = in.nextInt(); + in.nextLine(); + + int numberOfP = 0; + for (int score : scores) { + if (noSurprise(score) >= p) + numberOfP ++; + else if (surprising > 0 && surprise(score) >= p) { + surprising --; + numberOfP ++; + } + } + + return """" + numberOfP; + } + + private int surprise(int score) { + if (score < 2 || score > 28) + return 0; + if (score % 3 == 0) + return score / 3 + 1; + if (score % 3 == 1) + return 0; + return score / 3 + 2; + } + + private int noSurprise(int score) { + if (score % 3 > 0) + return score / 3 + 1; + return score / 3; + } + + void solveAll() throws Exception { + int cases = in.nextInt(); + in.nextLine(); + for (int i = 1; i <= cases; i++) { + String solution = ""Case #"" + i + "": "" + solve(); + System.out.println(solution); + out.println(solution); + } + out.flush(); + } + + // ----------------------------------------------------------------------- + + static Scanner in; + static PrintWriter out; + + static void setupIO() { + in = new Scanner(System.in); + out = new PrintWriter(System.out); + } + + static void setupIO(String filename) throws Exception { + in = new Scanner(new FileReader(filename)); + out = new PrintWriter(new FileWriter(filename + "".out"")); + } + + public static void main(String[] args) throws Exception { + new Solution().solveAll(); + } +} +" +A20869,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.StringTokenizer; + + +public class DancingWithTheGooglers { + + public static HashMap mappings = new HashMap(); + + public static void main(String[] args) throws FileNotFoundException, IOException { + File inFile = new File(""/Users/johannesvietze/Desktop/B-large.in""); + + //read + StringTokenizer tok = new StringTokenizer(getContents(inFile),""\n""); + tok.nextToken(); //delete first token + + String result = """"; + int counter = 1; + + + //compute + while(tok.hasMoreTokens()){ + String in = tok.nextToken(); //next line + + StringTokenizer current = new StringTokenizer(in, "" ""); + int n,s,p, min, safe, occ; + n = Integer.parseInt(current.nextToken()); + s = Integer.parseInt(current.nextToken()); + p = Integer.parseInt(current.nextToken()); + min = p + 2 * (p-2); + safe = p + 2 * (p-1); + occ = 0; + + if(p > 1){ //regular + while(current.hasMoreTokens()){ + int cur = Integer.parseInt(current.nextToken()); + if(safe <= cur) {occ++;} else //got p as max for sure + if(min <= cur) {if(s>0){occ++;s--;}} //got p as max if surprises are still available + } + }else if(p == 1){ //special case p == 1 + while(current.hasMoreTokens()){ + int cur = Integer.parseInt(current.nextToken()); + if(cur > 0){occ++;} + } + }else{ //special case p < 1 + occ = n; + } + result += ""Case #"" + counter++ + "": ""; + result += occ; + result += ""\n""; + } + + //write + File outFile = new File(""/Users/johannesvietze/Desktop/B-large.out""); + setContents(outFile, result); + + } + + + public static String getContents(File aFile) { + StringBuilder contents = new StringBuilder(); + try { + BufferedReader input = new BufferedReader(new FileReader(aFile)); + try { + String line = null; + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty(""line.separator"")); + } + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + + return contents.toString(); + } + + public static void setContents(File aFile, String aContents) throws FileNotFoundException, IOException { + Writer output = new BufferedWriter(new FileWriter(aFile)); + try { + output.write( aContents ); + } + finally { + output.close(); + } + } +} +" +A22887,"import java.io.*; +import java.util.Scanner; + +/** + * Created by IntelliJ IDEA. + * User: Veniversum + * Date: 4/15/12 + * Time: 1:37 AM + */ +public class Q2 { + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""in.txt""))); + int cases = Integer.parseInt(br.readLine()); + int out[] = new int[cases]; + for (int i = 0; i < cases; i++) { + Scanner sc = new Scanner(br.readLine()); + int contestants = sc.nextInt(); + int surprise = sc.nextInt(); + int min = sc.nextInt(); + int max = 0; + for (int j =0; j 0 && score >= (3*min-4) && score != 0){ + //use surprise + surprise--; + max++; + } + } else { + max++; + } + } + out[i] = max; + } + PrintWriter outp = new PrintWriter(new FileOutputStream(""out.txt"")); + for (int i = 0; i= p) + count++; + break; + default: + if(t[n] > midTop){ + count++; + } + else if(t[n] >= midBot && S > 0){ + S--; + count++; + } + } + } + System.out.println(String.format(""%d"", count)); + bufferedWriter.write(String.format(""%d\n"", count)); + } + bufferedWriter.close(); + fileWriter.close(); + } +} +" +A21818,"import java.io.*; +import java.util.Arrays; +public class GoogleCodeJam2 +{ + public static void main(String[] args) throws IOException + { + FileInputStream fstreami = new FileInputStream(""input.txt""); + DataInputStream in = new DataInputStream(fstreami); + FileWriter fstreamo = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fstreamo); + int testCases = Integer.parseInt(in.readLine()); + int i = 0; + while(i < testCases) + { + String test = in.readLine(); + String [] testInput = test.split("" ""); + int [] input = new int[testInput.length-3]; + int googlers = Integer.parseInt(testInput[0]); + int allowed = Integer.parseInt(testInput[1]); + int max = Integer.parseInt(testInput[2]); + int possible = 0; + for (int j = 0; j < testInput.length-3; j++) + input[j] = Integer.parseInt(testInput[3+j]); + Arrays.sort(input); + for (int j = googlers-1; j >= 0; j--) + { + if (input[j]%3 == 0) + { + if (input[j]/3 >= max) + possible++; + else if ((input[j]+3)/3 >= max && allowed>=1 && input[j]>=3) + { + possible++; + allowed--; + } + else ; + } + else if (input[j]%3 == 1) + { + if (((input[j]+2)/3) >= max && input[j]>=1) + possible++; + else ; + } + else + { + if (((input[j]+1)/3) >= max && input[j]>=2) + possible++; + else if (((input[j]+4)/3) >= max && allowed>=1 && input[j]>=2) + { + possible++; + allowed--; + } + else ; + } + } + // System.out.println(""Done""); + out.write(""Case #"" + (i+1) + "": "" + possible + ""\n""); + i++; + } + in.close(); + out.close(); + } +}" +A21618,"import java.util.Scanner; +import java.io.OutputStream; +import java.io.IOException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.io.FileInputStream; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream; + try { + inputStream = new FileInputStream(""input.txt""); + } catch (IOException e) { + throw new RuntimeException(e); + } + OutputStream outputStream; + try { + outputStream = new FileOutputStream(""output.txt""); + } catch (IOException e) { + throw new RuntimeException(e); + } + Scanner in = new Scanner(inputStream); + PrintWriter out = new PrintWriter(outputStream); + B solver = new B(); + int testCount = Integer.parseInt(in.next()); + for (int i = 1; i <= testCount; i++) + solver.solve(i, in, out); + out.close(); + } +} + +class B { + public void solve(int testNumber, Scanner in, PrintWriter out) { + int N = in.nextInt(), S = in.nextInt(), p = in.nextInt(); + int[] ts = IOUtils.readIntArray(in, N); + int cnt = 0; + boolean[] used = new boolean[N]; + int noSurpriseScoreMin = Math.max(p * 3 - 2, 0); + int surpriseScoreMin = Math.max(p * 3 - 4, 2); + for (int i = 0; i < ts.length; ++i) + if (ts[i] >= noSurpriseScoreMin) { + used[i] = true; + cnt++; + } + for (int i = 0; i < ts.length; ++i) + if (!used[i] && S > 0 && ts[i] >= surpriseScoreMin) { + cnt++; + S--; + } + out.print(String.format(""Case #%d: %d\n"", testNumber, cnt)); + } +} + +class IOUtils { + public static int[] readIntArray(Scanner in, int size) { + int[] array = new int[size]; + for (int i = 0; i < size; i++) + array[i] = in.nextInt(); + return array; + } + + } + +" +A20331,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlers; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author Calido + */ +public class Googlers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + int t,n,s,p,ti,cnt; + try + { + Scanner scnr=new Scanner(new File(args[0])); + PrintWriter out=new PrintWriter(new File(args[1])); + t=scnr.nextInt(); + System.out.println(""T: ""+t); + for(int i=1;i<=t;i++) + { + cnt=0; + n=scnr.nextInt();//reading number of googlers + s=scnr.nextInt();//reading special case + p=scnr.nextInt();//reading point + for(int j=0;j=(p+(2*(p-1)))) + { + cnt++; + } + else if(ti>=(p+(2*(p-2)))) + { + if(ti>=2 && ti<=28) + { + if(s>0) + { + cnt++; + s--; + } + } + } + } + + //output to File + out.println(""Case #""+i+"": ""+cnt); + System.out.println(""Case #""+i+"": ""+cnt); + } + out.close(); + } + catch(FileNotFoundException fnfe) + { + System.out.println(""File Not Found.""); + } + + } +} +" +A20020,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + + +public class OutputWriter { +private BufferedWriter bw = null; +private long counter = 1; + + public OutputWriter(String fileName) { + try { + bw = new BufferedWriter(new FileWriter(new File(fileName))); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void writeCaseLine(String output) { + try { + bw.write(""Case #"" + counter + "": "" + output+""\n""); + } catch (IOException e) { + e.printStackTrace(); + } + counter++; + } + + public void flushAndClose() { + try { + bw.flush(); + + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +} +} +" +A22068,"package hk.polyu.cslhu.codejam.solution.impl; + +import hk.polyu.cslhu.codejam.solution.Solution; + +import java.util.ArrayList; +import java.util.List; + +public class StoreCredit extends Solution { + private int amountOfCredits, numOfItems; + private List priceList; + + @Override + public void setProblem(List testCase) { + this.initial(testCase); + } + + private void initial(List testCase) { + // TODO Auto-generated method stub + this.amountOfCredits = Integer.valueOf(testCase.get(0)); + this.numOfItems = Integer.valueOf(testCase.get(1)); + this.setPriceList(testCase.get(2)); + } + + private void setPriceList(String string) { + // TODO Auto-generated method stub + String[] splitArray = string.split("" ""); + + if (splitArray.length != numOfItems) + logger.error(""The price list does not include all items ("" + + splitArray.length + + ""/"" + this.numOfItems + "")""); + + this.priceList = new ArrayList(); + for (String price : splitArray) { + this.priceList.add(Integer.valueOf(price)); + } + } + + @Override + public void solve() { + for (int itemIndex = 0; itemIndex < this.priceList.size() - 1; itemIndex++) { + for (int anotherItemIndex = itemIndex + 1; anotherItemIndex < this.priceList.size(); anotherItemIndex++) { + if (this.priceList.get(itemIndex) + this.priceList.get(anotherItemIndex) == this.amountOfCredits) { + this.result = (itemIndex + 1) + "" "" + (anotherItemIndex + 1); + break; + } + } + } + } + + @Override + public String getResult() { + return this.result; + } +} +" +A21723,"public class Googler { + int total; + boolean prizeSurprise = false; + boolean prizeNoSurprise = false; + boolean failSurprise = false; + boolean failNoSurprise = false; + boolean used = false; + int trueCounter = 0; + + public Googler poss(int total, int prize){ + this.used = false; + this.total = total; + for (int i=10; i>-1; i--){ + if (total>=i){ + int twoA = total - (2*i); + if (twoA >=0 && twoA<= i){ + if (twoA == i || twoA == i-1){ + if (i>=prize){ + if (prizeNoSurprise == false){trueCounter++;} + prizeNoSurprise = true; + } else { + if (failNoSurprise == false){trueCounter++;} + failNoSurprise = true; + } + } + if (twoA == i-2){ + if (i>=prize){ + if (prizeSurprise == false){trueCounter++;} + prizeSurprise = true; + } else { + if (failSurprise == false){trueCounter++;} + failSurprise = true; + } + } + } + int oneA = total - i - (i-1); + if (oneA >=0 && oneA<= i){ + if (oneA == i ||oneA == i-1){ + if (i>=prize){ + if (prizeNoSurprise == false){trueCounter++;} + prizeNoSurprise = true; + } else { + if (failNoSurprise == false){trueCounter++;} + failNoSurprise = true; + } + } + if (oneA == i-2){ + if (i>=prize){ + if (prizeSurprise == false){trueCounter++;} + prizeSurprise = true; + } else { + if (failSurprise == false){trueCounter++;} + failSurprise = true; + } + } + } + int splitA = total - i - (i-2); + if (splitA >=0 && oneA<= i){ + if (splitA == i ||oneA == i-1 || splitA== i-2){ + if (i>=prize){ + if (prizeSurprise == false){trueCounter++;} + prizeSurprise = true; + } else { + if (failSurprise == false){trueCounter++;} + failSurprise = true; + } + } + } + } + } + return this; + } + +} +" +A21337,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + + +public class ProblemB { + public static void main (String[] args) throws Exception{ + BufferedReader fin = new BufferedReader(new FileReader(""E:/B-large.in"")); + String line = fin.readLine(); + BufferedWriter out = new BufferedWriter(new FileWriter(""E:/B-large.out"")); + int ln = 1; + while ((line = fin.readLine()) != null && line.length() != 0){ + line = line.trim(); + String[] parts = line.split(""\\s+""); + int[] list = new int[parts.length]; + for (int i = 0; i < parts.length; i++){ + list[i] = Integer.parseInt(parts[i]); + } + int player = list[0]; + int s = list[1]; + int p = list[2]; + int gre = 0; + int mid = 0; + for (int i = 3; i < list.length; i++){ + if (list[i] >= (p * 3 - 2)) + gre++; + else if (list[i] >= (p * 3 - 4) && list[i] >= 1) + mid++; + } + int result = gre; + if (mid > s) + result += s; + else + result += mid; + out.write(""Case #"" + ln + "": "" + result); + out.write(""\n""); + ln++; + } + fin.close(); + out.close(); + } +}" +A21275,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class B { + public static void main(String[] args) throws FileNotFoundException { + Scanner read = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new File(""b-large.out"")); + int numberOfTests = Integer.parseInt(read.nextLine()); + for (int i = 1; i <= numberOfTests; i++) { + int result = 0; + int n = read.nextInt(); + int countSurp = read.nextInt(); + int minScore = read.nextInt(); + int[] totalScores = new int[n]; + for (int j = 0; j < n; j++) { + totalScores[j] = read.nextInt(); + } + double[] avg = new double[n]; + for (int j = 0; j < n; j++) { + avg[j] = totalScores[j] / 3.0; + } + for (int j = 0; j < n; j++) { + if (avg[j] >= minScore) { + result++; + } else if (Math.abs(avg[j] - minScore) >= 1.5) { + continue; + } else if (Math.abs(avg[j] - Math.round(avg[j])) < 0.3) { + long t1 = Math.round(avg[j]); + long t2 = t1; + long t3 = t2; + if (countSurp > 0 && t2 >=1) { + t2--; + t3++; + countSurp--; + result++; + } + } else if (avg[j] - Math.round(avg[j]) > 0) { + long t1 = Math.round(avg[j]); + long t2 = t1; + long t3 = t2 + 1; + if (t3 == minScore) { + result++; + } + } else { + long t1 = Math.round(avg[j]) - 1; + long t2 = t1 + 1; + long t3 = t2; + if (t3 == minScore) { + result++; + } else { + if (countSurp > 0 && t2 >= 1) { + countSurp--; + result++; + t2--; + t3++; + } + } + } + } + out.println(String.format(""Case #%d: %d"", i, result)); + } + out.close(); + } +} +" +A21598,"package qualifiers12.b; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; + +public class Dancing { + + public static Set[] combs; + + public static class Triple { + protected final int total; + protected final int v1; + protected final int v2; + protected final int v3; + + public Triple(int total, int v1, int v2, int v3) { + this.total = total; + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + } + + public int getMax() { + return max2(max2(v1, v2), v3); + } + + private int max2(int n1, int n2) { + return (n1 > n2) ? n1 : n2; + } + + public int getTotal() { + return v1 + v2 + v3; + } + + public boolean isTriplet() { + if (v1 < 0 || v2 < 0 || v3 < 0) { + return false; + } + if (Math.abs(v1 - v2) > 2 || Math.abs(v1 - v3) > 2 || Math.abs(v2 - v3) > 2) { + return false; + } + return v1 + v2 + v3 == total; + } + + public boolean isSurprising() { + return Math.abs(v1 - v2) == 2 || Math.abs(v1 - v3) == 2 || Math.abs(v2 - v3) == 2; + } + + @Override + public String toString() { + return total + ""("" + v1 + "","" + v2 + "","" + v3 + "")""; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + list.add(v1); + list.add(v2); + list.add(v3); + Collections.sort(list); + return list.get(0) * 100 + list.get(1) * 10 + list.get(2); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Triple) { + Triple that = (Triple) obj; + if ((this.v1 == that.v1 || this.v1 == that.v2 || this.v1 == that.v3) + && (this.v2 == that.v1 || this.v2 == that.v2 || this.v2 == that.v3) + && (this.v3 == that.v1 || this.v3 == that.v2 || this.v3 == that.v3)) { + return true; + } else { + return false; + } + } else { + return false; + } + } + } + + public static void computeCombination(int k, int total) { + int avgPart = Math.round((total + 0.0f) / 3.0f); + for (int i = -1; i < 2; i++) { + computeCombinationGiven(k, total, avgPart + i); + } + } + + private static void computeCombinationGiven(int k, int total, int part) { + int missing = total - part; + int avgPart = Math.round((missing + 0.0f) / 2.0f); + + for (int i = -1; i < 2; i++) { + computeWithOne(k, total, part, avgPart + i, avgPart); + } + } + + private static void computeWithOne(int k, int total, int part1, int part2, int lastAvg) { + for (int i = -1; i < 2; i++) { + Triple triple = new Triple(total, part1, part2, lastAvg + i); + if (triple.isTriplet()) { + combs[k].add(triple); + } + } + } + + public static void main(String[] args) throws IOException { + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String s = in.readLine(); + + int cases = Integer.parseInt(s); + + for (int i = 0; i < cases; i++) { + s = in.readLine(); + StringTokenizer tokenizer = new StringTokenizer(s, "" ""); + + int[] totals = new int[Integer.parseInt(tokenizer.nextToken())]; + combs = new Set[totals.length]; + for (int k = 0; k < combs.length; k++) { + combs[k] = new HashSet(); + } + int surprising = Integer.parseInt(tokenizer.nextToken()); + int p = Integer.parseInt(tokenizer.nextToken()); + + int k = 0; + while (tokenizer.hasMoreTokens()) { + totals[k] = Integer.parseInt(tokenizer.nextToken()); + computeCombination(k, totals[k]); + k++; + } + + // for (k = 0; k < combs.length; k++) { + // + // String tmp = """"; + // for (Triple triple : combs[k]) { + // tmp += triple.toString() + "" ""; + // } + // System.out.println(tmp); + // + // } + + int usedSurprising = 0; + for (k = 0; k < combs.length; k++) { + + if (containsSurprisingSequence(combs[k])) { + Triple triple = containsNonSurprisingAboveOrEqualP(combs[k], p); + if (triple != null) { + combs[k].clear(); + combs[k].add(triple); + } else if (usedSurprising < surprising) { + triple = containsSurprisingAboveOrEqualP(combs[k], p); + if (triple != null) { + combs[k].clear(); + combs[k].add(triple); + usedSurprising++; + } + } else { + Iterator iter = combs[k].iterator(); + while (iter.hasNext()) { + triple = iter.next(); + if (triple.isSurprising()) { + continue; + } + combs[k].clear(); + combs[k].add(triple); + break; + } + } + } else { + // choose one above P, otherwise random one + Triple triple = containsNonSurprisingAboveOrEqualP(combs[k], p); + if (triple != null) { + combs[k].clear(); + combs[k].add(triple); + } else { + Iterator iter = combs[k].iterator(); + while (iter.hasNext()) { + triple = iter.next(); + if (triple.isSurprising()) { + continue; + } + combs[k].clear(); + combs[k].add(triple); + break; + } + } + } + } + + int res = 0; + for (k = 0; k < combs.length; k++) { + for (Triple triple : combs[k]) { + if (triple.getMax() >= p) { + res++; + } + } + } + + String result = ""Case #"" + (i + 1) + "": "" + res; + System.out.println(result); + } + + } + + private static boolean containsSurprisingSequence(Set triples) { + for (Triple triple : triples) { + if (triple.isSurprising()) { + return true; + } + } + return false; + } + + private static Triple containsSurprisingAboveOrEqualP(Set triples, int p) { + for (Triple triple : triples) { + if (triple.isSurprising()) { + if (triple.getMax() >= p) { + return triple; + } + } + } + return null; + } + + private static Triple containsNonSurprisingAboveOrEqualP(Set triples, int p) { + for (Triple triple : triples) { + if (!triple.isSurprising()) { + if (triple.getMax() >= p) { + return triple; + } + } + } + return null; + } +} +" +A20963,"import java.util.Scanner; +import java.io.*; +class dance +{ + public static void main (String[] args) throws IOException + { + File inputData = new File(""B-large.in""); + File outputData= new File(""Bloutput.txt""); + Scanner scan = new Scanner( inputData ); + PrintStream print= new PrintStream(outputData); + + int t; + int n,s,p,pi; + t= scan.nextInt(); + for(int i=1;i<=t;i++) + { + n=scan.nextInt(); s=scan.nextInt(); p=scan.nextInt(); + int supTrip=0, notsupTrip=0; + + for(int j=0;j(3*p-3)) + notsupTrip++; + else if((pi>=(3*p-4))&&(pi<=(3*p-3))&&(pi>2)) + supTrip++; + } + + if(s<=supTrip) + notsupTrip=notsupTrip+s; + else if(s>supTrip) + notsupTrip= notsupTrip+supTrip; + print.println(""Case #""+i+"": ""+notsupTrip); + } + } +}" +A21776,"import java.util.Scanner; +import java.io.*; +import java.util.ArrayList; +public class Main2 +{ + public static void main(String[] args) throws IOException + { + String line = "" ""; + String line2 = "" ""; + String line3 = "" ""; + FileReader reader = new FileReader(""B-large.in""); + Scanner in = new Scanner(reader); + ArrayList list = new ArrayList(); + ArrayList list2 = new ArrayList(); + int number = 0; + int numb = 0; + int index = 0; + + int c; + int N; + int nprob; + int hnum; + int calc; + boolean suc; + int p; + int[] num = new int[103]; + + int count = in.nextInt(); + in.nextLine(); + + for(int i = 0; i < count; i++) + { + line = in.nextLine(); + list.add(line); + } + + while(count > 0) + { + p = 0; + line2 = list.get(numb); + number = 0; + + while(line2.length() > 0) + { + index = line2.indexOf(' '); + if(index > 0) + { + line = line2.substring(0,index); + num[number] = Integer.parseInt(line); + line2 = line2.substring(index); + line2 = line2.trim(); + } + else if(index == -1) + { + num[number] = Integer.parseInt(line2); + line2 = """"; + } + number++; + } + + + + N = num[0]; + nprob = num[1]; + hnum = num[2]; + suc = false; + + for(int j = 0; j < N; j++) + { + c = 3; + calc = num[j+3]; + while(c > 0) + { + calc -= hnum; + c--; + } + + if(calc >= 0) + suc = true; + else if(calc == -1) + suc = true; + else if(calc == -2) + suc = true; + else if(nprob > 0 && calc == -3 && num[j+3] > 0) + { + suc = true; + nprob--; + } + else if(nprob > 0 && calc == -4 && num[j+3] > 0) + { + suc = true; + nprob--; + } + else + suc = false; + + if(suc) + p++; + } + + + line3 = ""Case #"" + (numb+1) + "": "" + p; + list2.add(line3); + count--; + numb++; + + } + + for(String a : list2) + System.out.println(a); + + + } +}" +A20036,"package SolnB; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.*; +public class ProbB { + + /** + * @param args + */ + public static void main(String[] args) throws IOException{ + // TODO Auto-generated method stub + + Scanner sc = new Scanner(System.in); + FileOutputStream out = new FileOutputStream(""out.txt""); + int loop = sc.nextInt(); + for (int i =0;i =l) + c++; + } + else{ + if (scr[j]>=(l+l-1+l-1)){ + c++; + // System.out.println(c); + } + else if (s>0 && (scr[j]>=(3*l-4))){ + // System.out.println(s); + c++; + s--; + } + } + } + //System.out.println(); + out.write(String.format(""Case #%d: %d\n"", i+1, c).getBytes()); + } + } + +} +" +A21206,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +public class Scores { + private String fileName; + private FileReader file; + private FileWriter fileOutput; + private PrintWriter pw; + private BufferedReader br; + private int NbGog; + private int NbSurp; + private int maxScore; + private int nbTest; + private boolean verbose; + + + public Scores (String[] args){ + + try{ + fileName =(args[0]); + + file = new FileReader(fileName); + br = new BufferedReader(file); + fileOutput=new FileWriter(fileName+""_sol.txt""); + pw = new PrintWriter(fileOutput); + + } catch (Exception e) { + e.printStackTrace(); + } + nbTest=1; + verbose=true; + } + + + public int readNum(String line, int startPos, int [] endPos) { + String s=""""; + int i=0; + while(startPos ""); + + for(int j=0; j=maxScore) + { + float gogAvgDec= gogAvg-gobAvgInt; + + if(gogAvgDec<0.3 && gobAvgInt>=maxScore) //NO * + { + if(verbose) + System.out.println(""eq.0""); + total++; + } + else if( gogAvgDec<0.3 && gobAvgInt-1>=0 && gobAvgInt+1<=10&& gobAvgInt+1>=maxScore&& NbSurp>0) // * + { + if(verbose) + System.out.println(""eq.0_S""); + total++; + NbSurp--; + } + else if(gogAvgDec>=0.3 && gogAvgDec<0.6 && gobAvgInt+1<=10 && gobAvgInt+1>=maxScore) + { + if(verbose) + System.out.println(""eq.33""); + total++; + } + else if(gogAvgDec>=0.6 && gobAvgInt+1>=maxScore && gobAvgInt+1<=10) + { + if(verbose) + System.out.println(""eq.66""); + total++; + } + else if(gogAvgDec>=0.6 && gobAvgInt+2>=maxScore && gobAvgInt+2<=10 && NbSurp>0) + { + if(verbose) + System.out.println(""eq.66_S""); + total++; + NbSurp--; + + } + else if(verbose) + + System.out.println(""NO""); + + } + } + //if(verbose) + System.out.println(""Case #""+nbTest+"": "" +total); + pw.println(""Case #""+nbTest+"": "" +total); + + } + + } + + public static void main(String[] args) throws IOException { + + if(args.length!=1) + { + System.out.println(""Usage: java AlphabetSoup.java ""); + System.exit(0); + } + Scores scores= new Scores(args); + scores.dealWithFile(); + if(scores.verbose) + System.out.println(""End""); + + scores.file.close(); + scores.fileOutput.close(); + + } +}" +A20483,"package dom.zar.jam.qualifications; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int inputLines = in.nextInt(); + for (int i = 0; i < inputLines;) { + int googlersAmount = in.nextInt(); + int suprising = in.nextInt(); + int minPoints = in.nextInt(); + + final int[] googlers = new int[googlersAmount]; + for (int k = 0; k < googlersAmount; ++k) { + googlers[k] = in.nextInt(); + } + + System.out.println(""Case #"" + ++i + "": "" + + result(suprising, minPoints, googlers)); + } + } + + private static int result(int suprising, int minPoints, + int[] googlers) { + + final List filtered = new ArrayList(); + for (int points : googlers) { + boolean hasMin = (points / 3) >= minPoints; + boolean oneLessThanMin + = ((points - minPoints) >> 1) == (minPoints - 1); + + if (!(hasMin || oneLessThanMin)) { + filtered.add(points); + } + } + + int probable = 0; + for (Integer points : filtered) { + if (points - minPoints < 0) continue; + int restPoints = (points - minPoints) >> 1; + if (Math.abs(restPoints - minPoints) <= 2) + probable++; + } + probable = Math.min(probable, suprising); + + return googlers.length - filtered.size() + probable; + } +} +" +A22489,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class ProbB { + + private static final String FILEPATH = ""C:\\Users\\abhineet\\desktop\\codeJam""; + private static final String INFILE_NAME = ""b.in""; + private static final String OUTFILE_NAME = ""b.out""; + + + private static int noOfGooglers = 0; + private static int noOfSurprises = 0; + private static int p = 0; + private static List lstScores = null; + + public ProbB() { + super(); + } + +// private static void cleanVars(){ +// noOfGooglers = 0; +// noOfSurprises = 0; +// p = 0; +// lstScores = null; +// } + + public static void main(String[] args) { + List inList = readFile(FILEPATH +File.separator +INFILE_NAME); + List outList = new ArrayList(); + int numTestCases = Integer.parseInt(inList.get(0)); + System.out.println(""Number of Test Case : "" +numTestCases); + for(int i = 0; i < numTestCases; i++){ + formatInput(inList.get(i+1)); + int pMax = processData(); + outList.add(""Case #"" +(i+1) +"": "" +pMax); + } + writeToFile(FILEPATH+ File.separator +OUTFILE_NAME, outList); + for(String str : outList){ + System.out.println(str); + } + } + + private static int processData(){ + int sMin = 3 * p - 4; + int sMax = 3 * p - 2; + int noOFSurprisesPossible = min(noOfSurprises, getNoofSurprisesPossible(sMin, sMax)); + return noOFSurprisesPossible + getNonSurpriseSurpriseVals(sMax); + } + + private static int getNonSurpriseSurpriseVals(int sMax){ + int retVal = 0; + for (int val :lstScores){ + if (val >= sMax && val >= p){ + retVal++; + }else{ + // do nothing + } + } + return retVal; + } + + private static int getNoofSurprisesPossible(int sMin, int sMax){ + int retVal = 0; + for(int val : lstScores){ + if (val < sMax && val >= sMin && val >= p ){ + retVal++; + }else{ + //do nothing + } + } + return retVal; + } + + private static int min(int a ,int b){ + if (a <= b){ + return a; + }else{ + return b; + } + + } + + private static void formatInput(String str){ + lstScores = new ArrayList(); + String[] arrStr = str.split("" ""); + System.out.println(arrStr); + noOfGooglers = Integer.parseInt(arrStr[0]); + noOfSurprises = Integer.parseInt(arrStr[1]); + p = Integer.parseInt(arrStr[2]); + for (int i =0; i < noOfGooglers; i++){ + lstScores.add(Integer.parseInt(arrStr[i+3])); + } + Collections.sort(lstScores,Collections.reverseOrder()); + System.out.println(""Input Formatted...""); + System.out.println(""No of Googlers : "" +noOfGooglers); + System.out.println(""No of Surprises : "" +noOfSurprises); + System.out.println(""P : "" +p); + System.out.println(""Sorted Scores: "" +lstScores); + } + + private static List readFile(String filePath) { + List retList = new ArrayList(); + try { + // Open the file that is the firstS + // command line parameter + FileInputStream fstream = new FileInputStream(filePath); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = null; + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + // Print the content on the console + retList.add(strLine); + } + //Close the input stream + in.close(); + return retList; + } catch (Exception e) { //Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + return null; + } + + private static void writeToFile(String filePath, List inputLines) { + BufferedWriter bufferedWriter = null; + try { + + //Construct the BufferedWriter object + bufferedWriter = new BufferedWriter(new FileWriter(filePath)); + + //Start writing to the output stream + for (String str : inputLines) { + bufferedWriter.write(str); + bufferedWriter.newLine(); + } + + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + //Close the BufferedWriter + try { + if (bufferedWriter != null) { + bufferedWriter.flush(); + bufferedWriter.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } +} +" +A21876,"package QualificationB; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Arrays; + +public class ProblemB2 { + + + + public static void main(String args[]) throws Exception{ +// System.out.println(args[0]); + FileReader fr = new FileReader(args[0]); + BufferedReader br = new BufferedReader(fr); + + int T = Integer.parseInt(br.readLine()); + +// System.out.println(T); + for(int t=0;t= mintotal) { + result++; + } else if (total >= surprisetotal && sp > 0) { + result++; + sp--; + } else { + continue; + } + } + System.out.println(""Case #""+ (t+1) + "": "" + result); +// System.out.println(""-----""); + } + } +} +" +A21326,"package com.teamg9.codejam; + +import java.io.File; + +public class DancingWithTheGooglers extends Solver { + + public static void main(String...args) { + DancingWithTheGooglers solver = new DancingWithTheGooglers(); +// solver.solve(new File(""inouts/DancingWithTheGooglers/B-sample.in"")); +// solver.solve(new File(""inouts/DancingWithTheGooglers/B-small-attempt2.in"")); + solver.solve(new File(""inouts/DancingWithTheGooglers/B-large.in"")); +// System.out.println(solver.solve(""3 1 5 15 13 11"")); +// System.out.println(solver.solve(""3 0 8 23 22 21"")); +// System.out.println(solver.solve(""2 1 1 8 0"")); +// System.out.println(solver.solve(""6 2 8 29 20 8 18 18 21"")); + } + + @Override + public String evaluate() { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + + int c = 0; + for(int i=0; i0) { + if(t>1 && p<=(t-2)/3+2) { + s--; + c++; + } + } + } + + return String.valueOf(c); + } + + +} +" +A21528,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.StringTokenizer; + +public class Cj2012_qr_b_java { + // + // private static final String IN_FILE = ""test.in""; + // private static final String IN_FILE = ""test_small.in""; + private static final String IN_FILE = ""test_large.in""; + private static final String OUT_FILE = IN_FILE + "".out""; + private static final DateFormat DATE_FORMAT = new SimpleDateFormat(""HH:mm.ss""); + + private static long lBeginTimeMillis; + private static BufferedReader bufferedReader; + private static PrintWriter printWriter; + + private static int nNbCases, nIndexCase; + // + + // + private static int N, S, p, t[] = new int[100], nP; + + // + + private static void begin() throws Exception { + // + lBeginTimeMillis = System.currentTimeMillis(); + System.out.println(Cj2012_qr_b_java.class.toString()); + System.out.println(""Begin: "" + + DATE_FORMAT.format(new Date(lBeginTimeMillis)) + "".""); + + bufferedReader = new BufferedReader(new FileReader(IN_FILE)); + printWriter = new PrintWriter(new BufferedWriter(new FileWriter(OUT_FILE))); + // + + // + nNbCases = Integer.parseInt(bufferedReader.readLine()); + // + } + + private static void end() throws Exception { + // + // ... + // + + // + bufferedReader.close(); + printWriter.close(); + + long lEndTimeMillis = System.currentTimeMillis(); + System.out.println(""End: "" + DATE_FORMAT.format(new Date(lEndTimeMillis)) + + "".""); + System.out.println((lEndTimeMillis - lBeginTimeMillis) + "".""); + // + } + + private static void readCase() throws Exception { + // + StringTokenizer strTokenizer = new StringTokenizer( + bufferedReader.readLine(), "" ""); + + N = Integer.parseInt(strTokenizer.nextToken()); + S = Integer.parseInt(strTokenizer.nextToken()); + p = Integer.parseInt(strTokenizer.nextToken()); + + for (int i = 0; i < N; i++) + t[i] = Integer.parseInt(strTokenizer.nextToken()); + // + } + + private static void processCase() { + // + Arrays.sort(t, 0, N); + + nP = 0; + for (int i = N - 1; i >= 0; i--) { + int n = t[i] / 3; + if (n >= p) + nP++; + else { + int n1 = t[i] % 3; + switch (n1) { + case 0: + if (t[i] > 0 && n + 1 >= p && n + 1 <= 10 && S > 0) { + nP++; + S--; + } + break; + case 1: + if (n + 1 >= p && n + 1 <= 10) { + nP++; + } + else if (n + 1 >= p && n + 1 <= 10 && S > 0) { + nP++; + S--; + } + break; + case 2: + if (n + 1 >= p && n + 1 <= 10) { + nP++; + } + else if (n + 2 >= p && n + 2 <= 10 && S > 0) { + nP++; + S--; + } + break; + } + } + } + // + } + + private static void writeCase(int nIndexCase) throws Exception { + // + printWriter.print(""Case #""); + printWriter.print(nIndexCase + 1); + printWriter.print("":""); + // + + // + printWriter.print("" ""); + printWriter.print(nP); + printWriter.println(); + // + } + + public static void main(String[] args) throws Exception { + // + begin(); + for (nIndexCase = 0; nIndexCase < nNbCases; nIndexCase++) { + readCase(); + processCase(); + writeCase(nIndexCase); + } + end(); + // + } +} +" +A20110,"import java.io.*; +import java.util.Scanner; + +public class DancinWithGooglers { + + public static void main(String[] args) { + try { + Scanner input = new Scanner(new File(""input.txt"")); + PrintStream output = new PrintStream(new FileOutputStream(""output.txt"")); + solveTask(input, output); + } catch (FileNotFoundException e) { + System.out.println(""input.txt not found""); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + private static void solveTask(Scanner input, PrintStream output) { + + int testsCount = input.nextInt(); + + for (int test=1; test<=testsCount; test++) { + + int dancersCount = input.nextInt(); + int surprises = input.nextInt(); + int bestResult = input.nextInt(); + int scoreNeeded = bestResult*3-2; + + int gotResultAnywayCount = 0; + int gotResultConditionallyCount = 0; + + for (int i=0; i= scoreNeeded) { + gotResultAnywayCount++; + } else if (score > 1 && score < 29 && score >= scoreNeeded-2) { + gotResultConditionallyCount++; + } + } + + int total = gotResultAnywayCount + Math.min(gotResultConditionallyCount, surprises); + + System.out.print(""Case #""+test+"": ""); + System.out.println(total); + output.print(""Case #""+test+"": ""); + output.println(total); + } + } + +} +" +A21764,"import java.io.File; +import java.io.FileReader; +import java.io.IOException; + + +public class FileIn { + + private StringBuilder sb = new StringBuilder(""""); + + /** + * コンストラクタ. + * @param filename 読み込むファイル名 + */ + + public FileIn(String filename) { + File f = new File(filename); + FileReader fr = null; + try { + fr = new FileReader(f); + int c; + while ((c = fr.read()) != -1) { + this.sb.append((char)c); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + fr.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + } + + /** + * ファイルの文字列を返す. + * @return + */ + public String getString() { + return this.sb.toString(); + } +}" +A20258,"package _2012._0.b_dancers; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.LineNumberReader; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + + +public class DancingWithGooglers +{ + public static int countMaxMinScores (int[] totalScores, int i, int numSurprises, int minDesiredPoints, int cabeSurprise) + { + if (i >= totalScores.length) { + if (numSurprises > cabeSurprise) { + return cabeSurprise - numSurprises; + } else { + return 0; + } + } + + int newCount = 0; + +System.out.print (totalScores[i] + "" ("" + minDesiredPoints + ""): ""); + if (((minDesiredPoints * 3) - 0) <= totalScores[i]) { +System.out.println(""a""); + newCount = 1; +// if ((((minDesiredPoints * 3) - 4) > 0) || (totalScores[i] <= 8)) { + if ((totalScores[i] >= 2) && (totalScores[i] <= 28)) { + cabeSurprise++; + } + + } else if ((((minDesiredPoints * 3) - 2) <= totalScores[i]) && (minDesiredPoints >= 1)) { +System.out.println(""b""); + newCount = 1; + if ((totalScores[i] >= 2) && (totalScores[i] <= 28)) { + //if ((((minDesiredPoints * 3) - 4) > 0) || (totalScores[i] <= 8)) { + cabeSurprise++; + } + + } else if ((((minDesiredPoints * 3) - 4) <= totalScores[i]) && (numSurprises > 0) && (minDesiredPoints >= 2)) { +System.out.println(""c""); + newCount = 1; + numSurprises = numSurprises - 1; + } else { + if (totalScores[i] >= 2) cabeSurprise++; +System.out.println(""NO""); + } + + return newCount + countMaxMinScores (totalScores, i+1, numSurprises, minDesiredPoints, cabeSurprise); + } + + + /** + * @param args + */ + public static void main(String[] args) + throws Exception + { + long t0 = System.currentTimeMillis(); + String sIn = ""src/_2012/_0/b_dancers/B-large.in""; + if (args.length > 0) sIn = args[0]; + String sOut = sIn; + if (sOut.endsWith ("".in"")) sOut = sOut.substring (0, sOut.length() - 3); + sOut = sOut + "".out""; + + LineNumberReader in = new LineNumberReader (new FileReader (sIn)); + PrintWriter out = new PrintWriter (new FileWriter (sOut)); + + String linea0 = in.readLine(); + int numCasos = Integer.parseInt (linea0); + + for (int i=0; i 0){ + n[i]+=0; + } + else if(sum >= (P + (P-1) + P)){ + //System.out.println(""aasdf""); + //System.out.println(""1""); + n[i]++; + } + else if(sum >= P + P + P){ + n[i]++; + //System.out.println(""2""); + } + else if(sum >= P + 1 + P + 1 + P + 1){ + n[i]++; + //System.out.println(""3""); + } + else if(sum >= P + 2 + P + 2 + P + 2){ + n[i]++; + //System.out.println(""4""); + } + else if(sum >= (P-1) + (P-1) + P){ + n[i]++; + //System.out.println(""5""); + } + else if(sum >= (P+1) + (P+1) + P){ + n[i]++; + //System.out.println(""6""); + } + else if(sum >= (P+1) + P + P){ + n[i]++; + //System.out.println(""7""); + } + else if((sum >= (P+1) + (P-1) + P) && S > 0){ + n[i]++; + S--; + //System.out.println(""8""); + } + else if((sum >= (P + (P-1) + (P-2))) && S > 0){ + n[i]++; + S--; + //System.out.println(""9""); + } + else if((sum >= (P + (P-2) + (P-2))) && S > 0){ + n[i]++; + S--; + //System.out.println(""10""); + } + else if((sum >= (P + (P+1) + (P-1))) && S > 0){ + n[i]++; + S--; + //System.out.println(""11""); + } + else if((sum >= (P + (P+2) + (P+2))) && S > 0){ + n[i]++; + S--; + //System.out.println(""12""); + } + else if((sum >= (P + (P+2) + P)) && S > 0){ + n[i]++; + S--; + //System.out.println(""13""); + } + else if((sum >= (P + (P+1) + (P+2))) && S > 0){ + n[i]++; + S--; + //System.out.println(""14""); + } + + /* + else if(Math.abs((resta / 2) - P) == 2){ + if(S > 0){ + S--; + n[i]++; + //System.out.println(""s""); + } + } + else if((resta / 2) - P == 0 || Math.abs(resta / 2 - P) ==1){ + n[i]++; + //System.out.println(""parejo""); + }*/ + } + } + //} + for(int i = 0; i < T; i++){ + System.out.println(""Case #"" + (i+1) + "": "" + n[i]); + } + } +} +" +A20724,"//import java.io.*; +import java.util.*; + +public class ProblemB { + public static void main(String[] args) { + /* + try { + System.setIn(new FileInputStream(""b-example.in"")); + } catch (Exception e) {} + */ + new ProblemB(); + } + + public ProblemB() { + Scanner input = new Scanner(System.in); + int cases = input.nextInt(); + for (int n = 0; n < cases; n++) { + int total = input.nextInt(); + int surprising = input.nextInt(); + int limit = input.nextInt(); + int[] score = new int[total]; + for (int i = 0; i < total; i++) { + score[i] = input.nextInt(); + } + int[][] triplet = new int[total][3]; + int[] tripletMax = new int[total]; + int[] tripletMin = new int[total]; + for (int i = 0; i < total; i++) { + int tempScore = score[i]; + triplet[i][0] = tempScore / 3; + tempScore -= triplet[i][0]; + triplet[i][1] = tempScore / 2; + tempScore -= triplet[i][1]; + triplet[i][2] = tempScore; + tripletMax[i] = Math.max(Math.max(triplet[i][0], triplet[i][1]), triplet[i][2]); + tripletMin[i] = Math.min(Math.min(triplet[i][0], triplet[i][1]), triplet[i][2]); + } + int max = 0; + int tempSurprising = surprising; + List secondPass = new ArrayList(); + for (int i = 0; i < total; i++) { + secondPass.add(i); + } + for (int i = 0; i < total; i++) { + if (tripletMax[i] >= limit) { + max++; + } else if ((score[i] >= 2) && (tempSurprising > 0)) { + if (tripletMax[i] >= (limit - 1)) { + if ((tripletMax[i] - tripletMin[i]) == 1) { + if ((tripletMax[i] == triplet[i][0] && tripletMax[i] == triplet[i][1] && tripletMin[i] == triplet[i][2]) || + (tripletMax[i] == triplet[i][0] && tripletMin[i] == triplet[i][1] && tripletMax[i] == triplet[i][2]) || + (tripletMin[i] == triplet[i][0] && tripletMax[i] == triplet[i][1] && tripletMax[i] == triplet[i][2])) { + max++; + tempSurprising--; + secondPass.remove(secondPass.indexOf(i)); + } + } else { + if (triplet[i][0] == triplet[i][1] && triplet[i][1] == triplet[i][2]) { + max++; + tempSurprising--; + secondPass.remove(secondPass.indexOf(i)); + } + } + } + } + } + if (tempSurprising > 0) { + for (int i : secondPass) { + if (tempSurprising > 0) { + if ((tripletMax[i] >= limit) || (score[i] >= 2)) { + tempSurprising--; + } + } + } + } + System.out.println(""Case #"" + (n+1) + "": "" + max); + } + } +} +" +A21034,"package gcj2012; + +import java.io.FileInputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws Exception { + new B().run(); + } + + void run() throws Exception { + Scanner in = new Scanner(System.in); + in = new Scanner(new FileInputStream(""B-large.in"")); + PrintStream out = System.out; + out = new PrintStream(""B-large.out""); + + int T = in.nextInt(); + for (int x = 1; x <= T; x++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int t[] = new int[N]; + for (int i = 0; i < t.length; i++) + t[i] = in.nextInt(); + out.printf(""Case #%d: %d\n"", x, countAtLeastP(t, p, S)); + } + + } + + int countAtLeastP(int[] t, int p, int s) { + int canN = 0; + int canS = 0; + for (int i : t) + if (canAtLeastPNonSurprising(i, p)) canN++; + else if (canAtLeastPSurprising(i, p)) canS++; + return (canN ) + Math.min(canS, s); + } + + // min total score with best ind score of p is p + (p-1) + (p-1) + boolean canAtLeastPNonSurprising(int s, int p) { + return s >= 3 * p - 2; + } + + // min surp total score with best ind score of p is p + (p-2) + (p-2) + boolean canAtLeastPSurprising(int s, int p) { + if (s < 2) return false; + return s >= 3 * p - 4; + } + +} +" +A22951,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package problemb; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +/** + * + * @author Dr. Reda M. Hussien + */ +public class ProblemB { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + // TODO code application logic here + String DataFile = ""E:\\B-small-attempt5.in""; + FileReader fileReader; + fileReader = new FileReader(DataFile); + BufferedReader br = new BufferedReader(fileReader); + int N, S, P, ti, x, r, googlers, surprise; + String[] values; + String nextLine = br.readLine(); + int T = Integer.parseInt(nextLine); + for (int i = 0; i < T; i++) { + googlers = 0; + surprise = 0; + values = br.readLine().split("" ""); + N = Integer.parseInt(values[0]); + S = Integer.parseInt(values[1]); + P = Integer.parseInt(values[2]); + for (int n = 3; n < N + 3; n++) { + ti = Integer.parseInt(values[n]); + + x = ti / 3; + r = ti % 3; + switch (r) { + case 0: + if (x >= P) { + + googlers++; + } else { + // check for surprise case: + if (S > 0 && x > 0 && x + 1 >= P) { + googlers++; + S--; + } + } + + + break; + case 1: + if (x >= P || x + 1 >= P) { + googlers++; + + } else { + // surprise case: + if (S > 0 && x + 1 >= P) { + + googlers++; + S--; + } + } + + + break; + case 2: + if (x + 1 >= P || x >= P) + { + + googlers++; + } + else + { + if (S > 0 && x + 2 >= P) + { + + googlers++; + S--; + } + } + + + break; + + } + + + } + System.out.println(""Case #"" + (i + 1) + "": "" + googlers); + } + } +} +" +A20585," + +///REMOVE ALL OUTPUT AND USE STRINGTOKENIZER! + + +/* +ID: mfranzs1 +LANG: JAVA +TASK: DancingWithTheGooglers +*/ +import java.io.*; +import java.util.*; + +public class DancingWithTheGooglers { + static BufferedReader f; + public static void main (String [] args) throws IOException { + long unixTime = System.currentTimeMillis(); + // Use BufferedReader rather than RandomAccessFile; it's much faster + f = new BufferedReader(new FileReader(""DancingWithTheGooglers.in"")); + // input file name goes above + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""DancingWithTheGooglers.out""))); + + + int lines=Integer.parseInt(f.readLine()); + + for(int i=0;i=p){ + bestOfAtLeastP++; + }else{ + //Has to be suprising + if(total>=p){ + if(suprisingLeft>0){ + if((total-p)/2D>=p-2){ + suprisingLeft--; + bestOfAtLeastP++; + } + } + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+bestOfAtLeastP); + out.println(""Case #""+(i+1)+"": ""+bestOfAtLeastP); + } + + out.close(); // close the output file + + //System.out.println(""Time elapsed (ms): ""+(System.currentTimeMillis()-unixTime)); + + System.exit(0); // don't omit this! + } +}" +A20644,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DancingGoogle { + + /** + * @param args + * @throws IOException + */ + + + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + BufferedReader in = new BufferedReader(new FileReader(""./test2.txt"")); + FileWriter fstream = new FileWriter(""./out2.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + String str,str2; + + int i = 0; + + DancingGoogle mydg = new DancingGoogle(); + + int numTestCase = Integer.parseInt(in.readLine()); + while ((str = in.readLine()) != null) { + str2=""""; + int numOK = 0; + String[] toks; + toks = str.split("" ""); + int numGoogles = Integer.parseInt(toks[0]); + int numSP = Integer.parseInt(toks[1]); + int criteria = Integer.parseInt(toks[2]); + for(int j =3;j= criteria) { + numOK++; + continue; + } + int diff = criteria - temp; + if(rm > diff){ + numOK++; + continue; + } + else if( rm == 1 && diff == 1) + { + numOK++; + continue; + } + else if(rm == 2 && diff == 2 && numSP > 0) + { + numOK++; + numSP--; + continue; + } + else if(rm < diff && diff ==1 && numSP > 0 && temp-diff >=0) + { + numOK++; + numSP--; + continue; + } + + } + str2 = ""Case #"" + (++i) + "": "" + numOK + ""\n""; + out.append(str2); + System.out.print(str2); + } + in.close(); + out.close(); + } + +} +" +A21388,"package de.hg.codejam.tasks.dance.domain; + +public class Case { + private final byte[] totalPoints; + private final int numberOfSurprisingTriplets; + private final int numberOfGooglers; + private final short bestResult; + + public Case(short bestResult, int numberOfSurprisingTriplets, + byte[] totalPoints) { + this.totalPoints = totalPoints; + this.numberOfSurprisingTriplets = numberOfSurprisingTriplets; + this.bestResult = bestResult; + + numberOfGooglers = totalPoints.length; + } + + public byte[] getTotalPoints() { + return totalPoints; + } + + public int getNumberOfSurprisingTriplets() { + return numberOfSurprisingTriplets; + } + + public int getNumberOfGooglers() { + return numberOfGooglers; + } + + public short getBestResult() { + return bestResult; + } + + public static Case parse(String inputString) { + String[] splitted = inputString.split("" ""); + + int numberOfGooglers = Integer.parseInt(splitted[0]); + int numberOfSurprisingTriplets = Integer.parseInt(splitted[1]); + short bestResult = Short.parseShort(splitted[2]); + + byte[] totalPoints = new byte[numberOfGooglers]; + for (int i = 0; i < numberOfGooglers; i++) + totalPoints[i] = Byte.parseByte(splitted[i + 3]); + + return new Case(bestResult, numberOfSurprisingTriplets, totalPoints); + } + + @Override + public String toString() { + String s = ""CASE[Number of Googlers: "" + numberOfGooglers + + "", Number of surprising Scores: "" + + numberOfSurprisingTriplets + "", Best result at least: "" + + bestResult + "", Scores: ""; + + for (int i = 0; i < totalPoints.length; i++) + s += totalPoints[i] + (i < (numberOfGooglers - 1) ? "" "" : """"); + + s += ""]""; + + return s; + } +} +" +A21324,"package Codejam; + +import java.util.HashMap; +import java.util.Scanner; + +public class CodeJamB { + public static void main(String args[]){ + + Scanner scn = new Scanner(System.in); + int t = scn.nextInt(); + int n; + int s; + int p; + int triplet; + int result; + int score; + + + for(int i = 0; i < t; i++){ + n = scn.nextInt(); + s = scn.nextInt(); + p = scn.nextInt(); + triplet = 0; + result = 0; + + for(int j = 0; j < n; j++){ + score = scn.nextInt(); + if(score > ((p * 3) - 3)){ + result ++; + }else if(score > 2 && score > ((p * 3) - 5) && triplet < s){ + result ++; + triplet ++; + } + + + } + + System.out.println(""Case #"" + ( i + 1 ) + "": "" + result); + + } + } +} +" +A23042,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +public class ProblemB { + +/** +* @param args +*/ +public static void main(String[] args) { +BufferedReader br = null; +BufferedWriter bw = null; +String input[] = null; +String output = null; +try { +br = new BufferedReader(new FileReader(new File(""E:/B-large.in""))); +bw = new BufferedWriter(new FileWriter(""output.txt"")); +int count = Integer.parseInt(br.readLine()); +for (int i = 0; i < count; i++) { +input = br.readLine().split("" ""); +int noOfScores = Integer.parseInt(input[0]); +int noOfSuprises = Integer.parseInt(input[1]); +int expectedScore = Integer.parseInt(input[2]); +int noOfSolutions=0; +int scores[]=new int[noOfScores]; +for(int j=0;j=expectedScore) + { + noOfSolutions++; + } + }else { + if((scores[j]%3)==0) + { + int probScore=(int)(scores[j]/3); + if(probScore>=expectedScore) + { + noOfSolutions++; + } else { + if(((probScore+1)>=expectedScore)&&((probScore-1)>=0)&&noOfSuprises!=0) + { + noOfSolutions++; + noOfSuprises--; + } + } + } + else + { + int probScore=(int)(scores[j]/3)+1; + if(probScore>=expectedScore) + { + noOfSolutions++; + } else { + if(((probScore+1)>=expectedScore)&&noOfSuprises!=0) + { + noOfSolutions++; + noOfSuprises--; + } + } + } + } +} +output = new String(""Case #"" + (i + 1) + "": ""+noOfSolutions); +bw.write(output); +bw.newLine(); +//logic here +} +bw.close(); +} catch (Exception e) { +e.printStackTrace(); +} + +} + +} + " +A21455,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +/** + * + * Google Code Jam 2012 Qualification Round - Problem B. Dancing With the Googlers + * + * @author matlock + * + */ +public class DancingGooglers { + + public static void main(String[] args) { + DancingGooglers g = new DancingGooglers(); + g.goGo(); + } + + public void goGo() { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + try { + int testCases = Integer.parseInt(in.readLine()); + + for (int i = 1; i <= testCases; i++) { + String inputText = in.readLine(); + String[] valueParse = inputText.split("" ""); + int index = 0; + int numGooglers = Integer.valueOf(valueParse[index++]); + int numSurprising = Integer.valueOf(valueParse[index++]); + int targetVal = Integer.valueOf(valueParse[index++]); + List scores = new ArrayList(); + + for (int k = 0; k < numGooglers; k++) { + scores.add(Integer.valueOf(valueParse[index++])); + } + + int result = runTestCase(scores, numSurprising, targetVal); + + System.out.println(""Case #"" + i + "": "" + result); + } + } catch (IOException e) { + System.out.println(""Exception: "" + e.getMessage()); + } + } + + private int runTestCase(List scoreList, int numSurprising, int targetVal) { + Collections.sort(scoreList); + int targetCount = 0; + + if (targetVal == 0) { // if target score is 0 then all work + return scoreList.size(); + } + + for (int score : scoreList) { + if ((score - targetVal) / 2 < (targetVal - 2) || (score <= 0)) { + continue; // skip impossible score + } + // process surprising score + if (((score - targetVal) / 2 >= (targetVal - 2)) && (numSurprising > 0)) { + targetCount++; + numSurprising--; + // all of these scores should be valid, within 1 + } else if ((score - targetVal) / 2 >= (targetVal - 1)) { + targetCount++; + } else { + // skip + } + } + + return targetCount; + } + +} +" +A20257,"package Qualification; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class ProblemB { + + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(System.in); + String output = ""./result.txt""; + BufferedWriter writer = new BufferedWriter(new FileWriter(output)); + int T = in.nextInt(); + + for (int numCase = 1; numCase <= T; numCase++) { + int N = in.nextInt(); // num of googlers + int S = in.nextInt(); // num of surprising triplets + int p = in.nextInt(); // threshold + int[] totalPts = new int[N]; + for (int i = 0; i < N; i++) + totalPts[i] = in.nextInt(); + + int count = 0; + for (int total : totalPts) { + int minPt = total/3; + int remainder = total % 3; + if (minPt >= p || (remainder > 0 && minPt + 1 >= p)) { + count++; + continue; + } + + // might be a surprising triplets + if (S > 0 && remainder >= 2 && minPt + 2 >= p) { + count++; + S--; + continue; + } + + if (S > 0 && remainder == 0 && minPt + 1 >= p && minPt > 0) { + count++; S--; + continue; + } + } + String toPrint = ""Case #"" + numCase + "": "" + count; + System.out.println(toPrint); + writer.write(toPrint + ""\r\n""); + } + writer.flush(); + writer.close(); + } +} +" +A22202,"package qualification.round.atual; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class Googlers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + File f = new File(""B-large-practice.in""); + FileInputStream fis = new FileInputStream(f); + Scanner scanner = new Scanner(fis); + + File fOut = new File(""B-large-practice.out""); + Writer out = new BufferedWriter(new FileWriter(fOut)); + + try { + int t = Integer.parseInt(scanner.nextLine()); + + for (int i = 1; i <= t; i++) { + out.write(""Case #"" + i + "": "" + + getNumberOfBestResults(scanner.nextLine()) + ""\n""); + } + + } finally { + scanner.close(); + out.close(); + } + + } + + private static int getNumberOfBestResults(String line) { + int number = 0; + String elements[] = line.split("" ""); + int n = Integer.parseInt(elements[0]); + int s = Integer.parseInt(elements[1]); + int p = Integer.parseInt(elements[2]); + + int i = 1; + while (i <= n) { + int total = Integer.parseInt(elements[i + 2]); + i++; + List bests = getBestsGreaterThanP(p, total); + for (String best : bests) { + String[] values = best.split("" ""); + int v1 = Integer.parseInt(values[0]); + int v2 = Integer.parseInt(values[1]); + int v3 = Integer.parseInt(values[2]); + + if (v1 - v2 <= 1 && v2 - v1 <= 1 && v2 - v3 <= 1 + && v3 - v2 <= 1 && v1 - v3 <= 1 && v3 - v1 <= 1) { + number++; + break; + } else if (s > 0) { + s--; + number++; + break; + } + } + } + + return number; + } + + private static List getBestsGreaterThanP(int p, int total) { + List list = new ArrayList(); + + if (total % 3 == 0) { + int c = total / 3; + if (c >= p) { + list.add(c + "" "" + c + "" "" + c); + } else if (c + 1 >= p && c - 1 >= 0 && c + 1 <= 10) { + list.add((c - 1) + "" "" + c + "" "" + (c + 1)); + } + } else { + int c = (int) Math.floor(total / 3); + + if (total % 3 == 1) { + if (c + 1 >= p && c + 1 <= 10) { + list.add(c + "" "" + c + "" "" + (c + 1)); + } + if (c + 1 >= p && c - 2 >= 0 && c + 1 <= 10) { + list.add((c - 2) + "" "" + (c + 1) + "" "" + (c + 1)); + } + } else { + if (c + 1 >= p && c + 1 <= 10) { + list.add((c + 1) + "" "" + c + "" "" + (c + 1)); + } + if (c + 2 >= p && c + 2 <= 10) { + list.add(c + "" "" + c + "" "" + (c + 2)); + } + } + } + + return list; + } +}" +A20957,"import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; + +public class MaxDancers { + + public static void main(String[] args)throws IOException { + + String fichierentree= ""/home/marwen/Téléchargements/B-large.in""; + String fichiersortie= ""/home/marwen/Bureau/output.in""; + + BufferedWriter wr= new BufferedWriter(new FileWriter(fichiersortie)); + DataInputStream rd= new DataInputStream(new FileInputStream(fichierentree)); + + //Reading number of cases + String ligne = rd.readLine(); + int cases = Integer.valueOf(ligne); + + int k; + for (k=1;k<=cases;k++) + { + //Reading ligne by ligne + ligne = rd.readLine(); + ligne=ligne+"" ""; + + // Reading length of the table and filling in it with numbers + + int taille = Integer.valueOf(ligne.substring(0, ligne.indexOf("" ""))); + int [] T1= new int [3+taille]; + T1[0]=taille; + int i,val; + for (i=1;i<3+taille;i++) + { + ligne=ligne+"" ""; + ligne = ligne.substring(ligne.indexOf("" "") + 1); + val = Integer.valueOf(ligne.substring(0, ligne.indexOf("" ""))); + T1[i]=val; + } + + // End of Reading table from ligne + + //Solving the problem for each Line + + int s,p,nb,l; + s=T1[1]; + p=T1[2]; + nb=0; + l=T1.length; + for(i=3;i=p) + { + if (T1[i]>=3*p-2) {nb++;} + else {if ((T1[i]>=3*p-3)||(T1[i]>=3*p-4)){if (s>0){nb++;s--;}}} + } + } + + //Writing into the output file before moving to the next Line + wr.write(""Case #""+k+"": ""+nb); + wr.newLine(); + } + + wr.close(); + rd.close(); + } +} +" +A22112,"package codejam; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class ProblemB_DancingWithTheGooglers { + public static void main(String[] args) throws IOException + { + Scanner scan = new Scanner(new File(""c:/B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""Googlers.out""))); + + + int N = Integer.valueOf(scan.nextLine()); + int id =1; + while(scan.hasNextLine()) + { + String letters = scan.nextLine(); + String[] letter = letters.split("" ""); + + int peopleNum = Integer.valueOf(letter[0]); + int superiNum = Integer.valueOf(letter[1]); + int score = Integer.valueOf(letter[2]); + int[] scores = new int[peopleNum]; + for(int i=0;i= highScores) + num ++; + else + { + if(superiNum > 0) + { + if(item >= lowScores) + { + num++; + superiNum --; + } + } + } + } + + return num; + } + +} +" +A21824,"import java.util.Scanner; + + +public class Problem2 { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int lineNo = scan.nextInt(); + + for(int i = 0 ; i < lineNo ; i++) { + int googlerNo = scan.nextInt(); + int surpriseNo = scan.nextInt(); + int point = scan.nextInt(); + +// int googlerPoint[] = new int[googlerNo]; + Googler[] googlers = new Googler[googlerNo]; + + int maxGoogler = 0; + for(int j = 0 ; j < googlerNo ; j++) { + googlers[j] = new Googler(); + + googlers[j].setPoint(scan.nextInt()); + + if(googlers[j].maxPoint >= point) + maxGoogler++; + + else if(googlers[j].canSurprise + && googlers[j].maxPoint+1 == point + && surpriseNo > 0) { + + maxGoogler++; + surpriseNo--; + } + } + + System.out.println(""Case #"" + (i+1) + "": "" + maxGoogler); + + + } + } +} + +class Googler { + int point; + + int minPoint; + int maxPoint; + + boolean canSurprise; + + void setPoint(int point) { + this.point = point; + + if(point == 0 || point % 3 == 1) canSurprise = false; + else canSurprise = true; + + minPoint = point / 3; + maxPoint = point % 3 == 0 ? minPoint : minPoint + 1; + } +} + " +A22165,"import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by IntelliJ IDEA. + * User: Leonid + * Date: 4/14/12 + * Time: 2:41 PM + * Dancing With Googlers solution + */ +public class DancingWithGooglers { + public static void main(String[] args) { + FilesManager fileManager = FilesManager.getFilesManager(); + while (fileManager != null) { + produceSolution(fileManager); + fileManager = FilesManager.getFilesManager(); + } + + } + + private static void produceSolution(FilesManager filesManager) { + FileCommunicationManager fileComManager = new FileCommunicationManager(filesManager); + List input = fileComManager.convertInputToStrings(); + List parsedInput = CaseInterpreter.parseInput(input); + List output = new ArrayList(); + + for (int i = 0; i < parsedInput.size(); i++) { + OutputInfo outputInfo = solve(parsedInput.get(i)); + output.add(CaseInterpreter.composeOutputLine(outputInfo, i + 1)); + } + + fileComManager.convertStringsToOutput(output); + } + + private static OutputInfo solve(InputInfo inputInfo) { + OutputInfo outputInfo = new OutputInfo(); + + int surpriseThreshold = inputInfo.p * 3 - 4; + int regularThreshold = inputInfo.p * 3 - 2; + int surpriseCounter = 0; + int regularCounter = 0; + + for (int totalResult : inputInfo.results) { + if (totalResult >= regularThreshold) { + regularCounter++; + } else if (totalResult >= surpriseThreshold && totalResult!=0) { + surpriseCounter++; + } + } + outputInfo.result = regularCounter + (surpriseCounter > inputInfo.s ? inputInfo.s : surpriseCounter); + + return outputInfo; + } + + private static class InputInfo { + int n, s, p; + int[] results; + } + + private static class OutputInfo { + int result; + + public String toString() { + return Integer.toString(result); + } + + } + + private static class CaseInterpreter { + private static final int CASE_NUMBER_OF_LINES = 1; + + public static List parseInput(List input) { + List parsedInput = new ArrayList(); + for (int i = 0; i < input.size(); i += CASE_NUMBER_OF_LINES) { + parsedInput.add(parseCase(input.subList(i, i + CASE_NUMBER_OF_LINES))); + } + + return parsedInput; + } + + private static InputInfo parseCase(List caseLines) { + InputInfo inputInfo = new InputInfo(); + List ints = strToInts(caseLines.get(0)); + + inputInfo.n = ints.get(0); + inputInfo.s = ints.get(1); + inputInfo.p = ints.get(2); + + inputInfo.results = new int[inputInfo.n]; + for (int i = 0; i < inputInfo.n; i++) { + inputInfo.results[i] = ints.get(i + 3); + } + + return inputInfo; + } + + public static String composeOutputLine(OutputInfo output, int caseNumber) { + String outputString = ""Case #"" + caseNumber + "": "" + output.toString(); + + return outputString; + } + + private static List strToInts(String str) { + List ints = new ArrayList(); + String[] strs = str.split("" ""); + for (String s : strs) { + ints.add(Integer.parseInt(s)); + } + return ints; + } + } + + private static class FilesManager { + File inputFile; + File outputFile; + private static List inputFiles; + private static int inputFilesIt = 0; + + static { + File f = new File("".""); + inputFiles = getInputFiles(f.list()); + } + + private static List getInputFiles(String[] fileNames) { + List inputFileNames = new ArrayList(); + + for (String fileName : fileNames) { + String[] splitFileName = fileName.split(""\\.""); + if (splitFileName.length == 2) { + if (splitFileName[1].equals(""IN"") || splitFileName[1].equals(""In"") || splitFileName[1].equals(""in"")) { + inputFileNames.add(fileName); + } + } + } + return inputFileNames; + } + + private static String generateOutputFileName(String inputFileName) { + String[] stlitFileName = inputFileName.split(""\\.""); + return stlitFileName[0] + ""-output.txt""; + } + + FilesManager(String inputFileName, String outputFileName) { + inputFile = new File(inputFileName); + assert (inputFile.exists()); + outputFile = new File(outputFileName); + try { + outputFile.createNewFile(); + } catch (IOException ex) { + System.out.println(""Exception while trying to create an output file""); + } + } + + public static FilesManager getFilesManager() { + if (inputFilesIt >= inputFiles.size()) { + return null; + } + String inputFileName = inputFiles.get(inputFilesIt++); + String outputFileName = generateOutputFileName(inputFileName); + return new FilesManager(inputFileName, outputFileName); + } + + + File getInputFile() { + return inputFile; + } + + File getOutputFile() { + return outputFile; + } + } + + private static class FileCommunicationManager { + File inputFile; + File outputFile; + + FileCommunicationManager(FilesManager filesManager) { + inputFile = filesManager.getInputFile(); + outputFile = filesManager.getOutputFile(); + } + + List convertInputToStrings() { + List linesList = new ArrayList(); + + try { + FileReader fr = new FileReader(inputFile); + BufferedReader bufReader = new BufferedReader(fr); + int numOfCases = Integer.parseInt(bufReader.readLine()); + + for (int i = 0; i < numOfCases; i++) { + linesList.add(bufReader.readLine()); + } + + } catch (IOException e) { + System.out.println(""Error reading from the file""); + } + + return linesList; + } + + void convertStringsToOutput(List linesList) { + BufferedWriter bufWriter = null; + try { + bufWriter = new BufferedWriter(new FileWriter(outputFile)); + + for (String line : linesList) { + bufWriter.write(line); + bufWriter.newLine(); + } + + } catch (IOException e) { + System.out.println(""Error reading from the file""); + } finally { + //Close the BufferedWriter + try { + if (bufWriter != null) { + bufWriter.flush(); + bufWriter.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } +} +" +A22350,"import java.io.*; +import javax.swing.*; +import java.util.*; +import java.awt.event.*; +import java.awt.*; +import java.math.*; +import java.text.*; + + +public class Gjam{ + +static int _pow(int num, int power) +{ + int product=1; + for(int i=0;i=p) ++res; + else if(ave+1>=p) + { + if(s>0) + { + --s; + ++res; + } + } + break; + + case 1: + if(ave+1>=p) ++res; + break; + + case 2: + if(ave+1>=p) ++res; + else if(ave+2>=p) + { + if(s>0) + { + --s; + ++res; + } + } + break; + } + + } + } + if(p==0) res = n; + + //output + String out = ""Case #"" + (i+1) + "": "" + res +""\n""; + output += out; + System.out.print(out); + } + //DecimalFormat df = new DecimalFormat (""0.0""); + //double sdds = 5312341.082491924125979175;System.out.println(df.format(sdds) ); + //end coding + /******************************************************************/ + + output = output.trim(); + + input.close(); + + createFile( outputFileName, output); + + //System.out.print(output); + + //System.out.print(""\n\n

For writing to standard output, the output methods in this class pretty much + * duplicate the functionality of System.out, and System.out can be used interchangeably with them. + *

This class does not use optimal Java programming practices. It is designed specifically to be easily + * usable even by a beginning programmer who has not yet learned about objects and exceptions. Therefore, + * everything is in a single source file that compiles into a single class file, all the methods are + * static methods, and none of the methods throw exceptions that would require try...catch statements. + * Also for this reason, all exceptions are converted into IllegalArgumentExceptions, even when this + * exception type doesn't really make sense. + *

This class requires Java 5.0 or higher. (A previous version of TextIO required only Java 1.1; + * this version should work with any source code that used the previous version, but it has some new + * features, including the type of formatted output that was introduced in Java 5 and the ability to + * use files and streams.) + */ +public class TextIO { + + /* Modified November 2007 to empty the TextIO input buffer when switching from one + * input source to another. This fixes a bug that allows input from the previous input + * source to be read after the new source has been selected. + */ + + /** + * The value returned by the peek() method when the input is at end-of-file. + * (The value of this constant is (char)0xFFFF.) + */ + public final static char EOF = (char)0xFFFF; + + /** + * The value returned by the peek() method when the input is at end-of-line. + * The value of this constant is the character '\n'. + */ + public final static char EOLN = '\n'; // The value returned by peek() when at end-of-line. + + + /** + * After this method is called, input will be read from standard input (as it + * is in the default state). If a file or stream was previously the input source, that file + * or stream is closed. + */ + public static void readStandardInput() { + if (readingStandardInput) + return; + try { + in.close(); + } + catch (Exception e) { + } + emptyBuffer(); // Added November 2007 + in = standardInput; + inputFileName = null; + readingStandardInput = true; + inputErrorCount = 0; + } + + /** + * After this method is called, input will be read from inputStream, provided it + * is non-null. If inputStream is null, then this method has the same effect + * as calling readStandardInput(); that is, future input will come from the + * standard input stream. + */ + public static void readStream(InputStream inputStream) { + if (inputStream == null) + readStandardInput(); + else + readStream(new InputStreamReader(inputStream)); + } + + /** + * After this method is called, input will be read from inputStream, provided it + * is non-null. If inputStream is null, then this method has the same effect + * as calling readStandardInput(); that is, future input will come from the + * standard input stream. + */ + public static void readStream(Reader inputStream) { + if (inputStream == null) + readStandardInput(); + else { + if ( inputStream instanceof BufferedReader) + in = (BufferedReader)inputStream; + else + in = new BufferedReader(inputStream); + emptyBuffer(); // Added November 2007 + inputFileName = null; + readingStandardInput = false; + inputErrorCount = 0; + } + } + + /** + * Opens a file with a specified name for input. If the file name is null, this has + * the same effect as calling readStandardInput(); that is, input will be read from standard + * input. If an + * error occurs while trying to open the file, an exception of type IllegalArgumentException + * is thrown, and the input source is not changed. If the file is opened + * successfully, then after this method is called, all of the input routines will read + * from the file, instead of from standard input. + */ + public static void readFile(String fileName) { + if (fileName == null) // Go back to reading standard input + readStandardInput(); + else { + BufferedReader newin; + try { + newin = new BufferedReader( new FileReader(fileName) ); + } + catch (Exception e) { + throw new IllegalArgumentException(""Can't open file \"""" + fileName + ""\"" for input.\n"" + + ""(Error :"" + e + "")""); + } + if (! readingStandardInput) { // close current input stream + try { + in.close(); + } + catch (Exception e) { + } + } + emptyBuffer(); // Added November 2007 + in = newin; + readingStandardInput = false; + inputErrorCount = 0; + inputFileName = fileName; + } + } + + /** + * Puts a GUI file-selection dialog box on the screen in which the user can select + * an input file. If the user cancels the dialog instead of selecting a file, it is + * not considered an error, but the return value of the subroutine is false. + * If the user does select a file, but there is an error while trying to open the + * file, then an exception of type IllegalArgumentException is thrown. Finally, if + * the user selects a file and it is successfully opened, then the return value of the + * subroutine is true, and the input routines will read from the file, instead of + * from standard input. If the user cancels, or if any error occurs, then the + * previous input source is not changed. + *

NOTE: Calling this method starts a GUI user interface thread, which can continue + * to run even if the thread that runs the main program ends. If you use this method + * in a non-GUI program, it might be necessary to call System.exit(0) at the end of the main() + * routine to shut down the Java virtual machine completely. + */ + public static boolean readUserSelectedFile() { + if (fileDialog == null) + fileDialog = new JFileChooser(); + fileDialog.setDialogTitle(""Select File for Input""); + int option = fileDialog.showOpenDialog(null); + if (option != JFileChooser.APPROVE_OPTION) + return false; + File selectedFile = fileDialog.getSelectedFile(); + BufferedReader newin; + try { + newin = new BufferedReader( new FileReader(selectedFile) ); + } + catch (Exception e) { + throw new IllegalArgumentException(""Can't open file \"""" + selectedFile.getName() + ""\"" for input.\n"" + + ""(Error :"" + e + "")""); + } + if (!readingStandardInput) { // close current file + try { + in.close(); + } + catch (Exception e) { + } + } + emptyBuffer(); // Added November 2007 + in = newin; + inputFileName = selectedFile.getName(); + readingStandardInput = false; + inputErrorCount = 0; + return true; + } + + /** + * After this method is called, output will be written to standard output (as it + * is in the default state). If a file or stream was previously open for output, it + * will be closed. + */ + public static void writeStandardOutput() { + if (writingStandardOutput) + return; + try { + out.close(); + } + catch (Exception e) { + } + outputFileName = null; + outputErrorCount = 0; + out = standardOutput; + writingStandardOutput = true; + } + + + /** + * After this method is called, output will be sent to outputStream, provided it + * is non-null. If outputStream is null, then this method has the same effect + * as calling writeStandardOutput(); that is, future output will be sent to the + * standard output stream. + */ + public static void writeStream(OutputStream outputStream) { + if (outputStream == null) + writeStandardOutput(); + else + writeStream(new PrintWriter(outputStream)); + } + + /** + * After this method is called, output will be sent to outputStream, provided it + * is non-null. If outputStream is null, then this method has the same effect + * as calling writeStandardOutput(); that is, future output will be sent to the + * standard output stream. + */ + public static void writeStream(PrintWriter outputStream) { + if (outputStream == null) + writeStandardOutput(); + else { + out = outputStream; + outputFileName = null; + outputErrorCount = 0; + writingStandardOutput = false; + } + } + + + /** + * Opens a file with a specified name for output. If the file name is null, this has + * the same effect as calling writeStandardOutput(); that is, output will be sent to standard + * output. If an + * error occurs while trying to open the file, an exception of type IllegalArgumentException + * is thrown. If the file is opened successfully, then after this method is called, + * all of the output routines will write to the file, instead of to standard output. + * If an error occurs, the output destination is not changed. + *

NOTE: Calling this method starts a GUI user interface thread, which can continue + * to run even if the thread that runs the main program ends. If you use this method + * in a non-GUI program, it might be necessary to call System.exit(0) at the end of the main() + * routine to shut down the Java virtual machine completely. + */ + public static void writeFile(String fileName) { + if (fileName == null) // Go back to reading standard output + writeStandardOutput(); + else { + PrintWriter newout; + try { + newout = new PrintWriter(new FileWriter(fileName)); + } + catch (Exception e) { + throw new IllegalArgumentException(""Can't open file \"""" + fileName + ""\"" for output.\n"" + + ""(Error :"" + e + "")""); + } + if (!writingStandardOutput) { + try { + out.close(); + } + catch (Exception e) { + } + } + out = newout; + writingStandardOutput = false; + outputFileName = fileName; + outputErrorCount = 0; + } + } + + /** + * Puts a GUI file-selection dialog box on the screen in which the user can select + * an output file. If the user cancels the dialog instead of selecting a file, it is + * not considered an error, but the return value of the subroutine is false. + * If the user does select a file, but there is an error while trying to open the + * file, then an exception of type IllegalArgumentException is thrown. Finally, if + * the user selects a file and it is successfully opened, then the return value of the + * subroutine is true, and the output routines will write to the file, instead of + * to standard output. If the user cancels, or if an error occurs, then the current + * output destination is not changed. + */ + public static boolean writeUserSelectedFile() { + if (fileDialog == null) + fileDialog = new JFileChooser(); + fileDialog.setDialogTitle(""Select File for Output""); + File selectedFile; + while (true) { + int option = fileDialog.showSaveDialog(null); + if (option != JFileChooser.APPROVE_OPTION) + return false; // user canceled + selectedFile = fileDialog.getSelectedFile(); + if (selectedFile.exists()) { + int response = JOptionPane.showConfirmDialog(null, + ""The file \"""" + selectedFile.getName() + ""\"" already exists. Do you want to replace it?"", + ""Replace existing file?"", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + if (response == JOptionPane.YES_OPTION) + break; + } + else { + break; + } + } + PrintWriter newout; + try { + newout = new PrintWriter(new FileWriter(selectedFile)); + } + catch (Exception e) { + throw new IllegalArgumentException(""Can't open file \"""" + selectedFile.getName() + ""\"" for output.\n"" + + ""(Error :"" + e + "")""); + } + if (!writingStandardOutput) { + try { + out.close(); + } + catch (Exception e) { + } + } + out = newout; + writingStandardOutput = false; + outputFileName = selectedFile.getName(); + outputErrorCount = 0; + return true; + } + + + /** + * If TextIO is currently reading from a file, then the return value is the name of the file. + * If the class is reading from standard input or from a stream, then the return value is null. + */ + public static String getInputFileName() { + return inputFileName; + } + + + /** + * If TextIO is currently writing to a file, then the return value is the name of the file. + * If the class is writing to standard output or to a stream, then the return value is null. + */ + public static String getOutputFileName() { + return outputFileName; + } + + + // *************************** Output Methods ********************************* + + /** + * Write a single value to the current output destination, using the default format + * and no extra spaces. This method will handle any type of parameter, even one + * whose type is one of the primitive types. + */ + public static void put(Object x) { + out.print(x); + out.flush(); + if (out.checkError()) + outputError(""Error while writing output.""); + } + + /** + * Write a single value to the current output destination, using the default format + * and outputting at least minChars characters (with extra spaces added before the + * output value if necessary). This method will handle any type of parameter, even one + * whose type is one of the primitive types. + * @param x The value to be output, which can be of any type. + * @param minChars The minimum number of characters to use for the output. If x requires fewer + * then this number of characters, then extra spaces are added to the front of x to bring + * the total up to minChars. If minChars is less than or equal to zero, then x will be printed + * in the minumum number of spaces possible. + */ + public static void put(Object x, int minChars) { + if (minChars <= 0) + out.print(x); + else + out.printf(""%"" + minChars + ""s"", x); + out.flush(); + if (out.checkError()) + outputError(""Error while writing output.""); + } + + /** + * This is equivalent to put(x), followed by an end-of-line. + */ + public static void putln(Object x) { + out.println(x); + out.flush(); + if (out.checkError()) + outputError(""Error while writing output.""); + } + + /** + * This is equivalent to put(x,minChars), followed by an end-of-line. + */ + public static void putln(Object x, int minChars) { + put(x,minChars); + out.println(); + out.flush(); + if (out.checkError()) + outputError(""Error while writing output.""); + } + + /** + * Write an end-of-line character to the current output destination. + */ + public static void putln() { + out.println(); + out.flush(); + if (out.checkError()) + outputError(""Error while writing output.""); + } + + /** + * Writes formatted output values to the current output destination. This method has the + * same function as System.out.printf(); the details of formatted output are not discussed + * here. The first parameter is a string that describes the format of the output. There + * can be any number of additional parameters; these specify the values to be output and + * can be of any type. This method will throw an IllegalArgumentException if the + * format string is null or if the format string is illegal for the values that are being + * output. + */ + public static void putf(String format, Object... items) { + if (format == null) + throw new IllegalArgumentException(""Null format string in TextIO.putf() method.""); + try { + out.printf(format,items); + } + catch (IllegalFormatException e) { + throw new IllegalArgumentException(""Illegal format string in TextIO.putf() method.""); + } + out.flush(); + if (out.checkError()) + outputError(""Error while writing output.""); + } + + // *************************** Input Methods ********************************* + + /** + * Test whether the next character in the current input source is an end-of-line. Note that + * this method does NOT skip whitespace before testing for end-of-line -- if you want to do + * that, call skipBlanks() first. + */ + public static boolean eoln() { + return peek() == '\n'; + } + + /** + * Test whether the next character in the current input source is an end-of-file. Note that + * this method does NOT skip whitespace before testing for end-of-line -- if you want to do + * that, call skipBlanks() or skipWhitespace() first. + */ + public static boolean eof() { + return peek() == EOF; + } + + /** + * Reads the next character from the current input source. The character can be a whitespace + * character; compare this to the getChar() method, which skips over whitespace and returns the + * next non-whitespace character. An end-of-line is always returned as the character '\n', even + * when the actual end-of-line in the input source is something else, such as '\r' or ""\r\n"". + * This method will throw an IllegalArgumentException if the input is at end-of-file (which will + * not ordinarily happen if reading from standard input). + */ + public static char getAnyChar() { + return readChar(); + } + + /** + * Returns the next character in the current input source, without actually removing that + * character from the input. The character can be a whitespace character and can be the + * end-of-file character (specified by the constant TextIO.EOF).An end-of-line is always returned + * as the character '\n', even when the actual end-of-line in the input source is something else, + * such as '\r' or ""\r\n"". This method never causes an error. + */ + public static char peek() { + return lookChar(); + } + + /** + * Skips over any whitespace characters, except for end-of-lines. After this method is called, + * the next input character is either an end-of-line, an end-of-file, or a non-whitespace character. + * This method never causes an error. (Ordinarily, end-of-file is not possible when reading from + * standard input.) + */ + public static void skipBlanks() { + char ch=lookChar(); + while (ch != EOF && ch != '\n' && Character.isWhitespace(ch)) { + readChar(); + ch = lookChar(); + } + } + + /** + * Skips over any whitespace characters, including for end-of-lines. After this method is called, + * the next input character is either an end-of-file or a non-whitespace character. + * This method never causes an error. (Ordinarily, end-of-file is not possible when reading from + * standard input.) + */ + private static void skipWhitespace() { + char ch=lookChar(); + while (ch != EOF && Character.isWhitespace(ch)) { + readChar(); + if (ch == '\n' && readingStandardInput && writingStandardOutput) { + out.print(""? ""); + out.flush(); + } + ch = lookChar(); + } + } + + /** + * Skips whitespace characters and then reads a value of type byte from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static byte getlnByte() { + byte x=getByte(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads a value of type short from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static short getlnShort() { + short x=getShort(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads a value of type int from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static int getlnInt() { + int x=getInt(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads a value of type long from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static long getlnLong() { + long x=getLong(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads a value of type float from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static float getlnFloat() { + float x=getFloat(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads a value of type double from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static double getlnDouble() { + double x=getDouble(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads a value of type char from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). Note that the value + * that is returned will be a non-whitespace character; compare this with the getAnyChar() method. + * When using standard IO, this will not produce an error. In other cases, an error can occur if + * an end-of-file is encountered. + */ + public static char getlnChar() { + char x=getChar(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads a value of type boolean from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + *

Legal inputs for a boolean input are: true, t, yes, y, 1, false, f, no, n, and 0; letters can be + * either upper case or lower case. One ""word"" of input is read, using the getWord() method, and it + * must be one of these; note that the ""word"" must be terminated by a whitespace character (or end-of-file). + */ + public static boolean getlnBoolean() { + boolean x=getBoolean(); + emptyBuffer(); + return x; + } + + /** + * Skips whitespace characters and then reads one ""word"" from input, discarding the rest of + * the current line of input (including the next end-of-line character, if any). A word is defined as + * a sequence of non-whitespace characters (not just letters!). When using standard IO, + * this will not produce an error. In other cases, an IllegalArgumentException will be thrown + * if an end-of-file is encountered. + */ + public static String getlnWord() { + String x=getWord(); + emptyBuffer(); + return x; + } + + /** + * This is identical to getln(). + */ + public static String getlnString() { + return getln(); + } + + /** + * Reads all the characters from the current input source, up to the next end-of-line. The end-of-line + * is read but is not included in the return value. Any other whitespace characters on the line are retained, + * even if they occur at the start of input. The return value will be an empty string if there are no + * no characters before the end-of-line. When using standard IO, this will not produce an error. + * In other cases, an IllegalArgumentException will be thrown if an end-of-file is encountered. + */ + public static String getln() { + StringBuffer s = new StringBuffer(100); + char ch = readChar(); + while (ch != '\n') { + s.append(ch); + ch = readChar(); + } + return s.toString(); + } + + /** + * Skips whitespace characters and then reads a value of type byte from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static byte getByte() { + return (byte)readInteger(-128L,127L); + } + + /** + * Skips whitespace characters and then reads a value of type short from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static short getShort() { + return (short)readInteger(-32768L,32767L); + } + + /** + * Skips whitespace characters and then reads a value of type int from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static int getInt() { + return (int)readInteger(Integer.MIN_VALUE, Integer.MAX_VALUE); + } + + /** + * Skips whitespace characters and then reads a value of type long from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static long getLong() { + return readInteger(Long.MIN_VALUE, Long.MAX_VALUE); + } + + /** + * Skips whitespace characters and then reads a single non-whitespace character from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error. In other cases, an IllegalArgumentException will be thrown if an end-of-file + * is encountered. + */ + public static char getChar() { + skipWhitespace(); + return readChar(); + } + + /** + * Skips whitespace characters and then reads a value of type float from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static float getFloat() { + float x = 0.0F; + while (true) { + String str = readRealString(); + if (str == null) { + errorMessage(""Floating point number not found."", + ""Real number in the range "" + (-Float.MAX_VALUE) + "" to "" + Float.MAX_VALUE); + } + else { + try { + x = Float.parseFloat(str); + } + catch (NumberFormatException e) { + errorMessage(""Illegal floating point input, "" + str + ""."", + ""Real number in the range "" + (-Float.MAX_VALUE) + "" to "" + Float.MAX_VALUE); + continue; + } + if (Float.isInfinite(x)) { + errorMessage(""Floating point input outside of legal range, "" + str + ""."", + ""Real number in the range "" + (-Float.MAX_VALUE) + "" to "" + Float.MAX_VALUE); + continue; + } + break; + } + } + inputErrorCount = 0; + return x; + } + + /** + * Skips whitespace characters and then reads a value of type double from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + */ + public static double getDouble() { + double x = 0.0; + while (true) { + String str = readRealString(); + if (str == null) { + errorMessage(""Floating point number not found."", + ""Real number in the range "" + (-Double.MAX_VALUE) + "" to "" + Double.MAX_VALUE); + } + else { + try { + x = Double.parseDouble(str); + } + catch (NumberFormatException e) { + errorMessage(""Illegal floating point input, "" + str + ""."", + ""Real number in the range "" + (-Double.MAX_VALUE) + "" to "" + Double.MAX_VALUE); + continue; + } + if (Double.isInfinite(x)) { + errorMessage(""Floating point input outside of legal range, "" + str + ""."", + ""Real number in the range "" + (-Double.MAX_VALUE) + "" to "" + Double.MAX_VALUE); + continue; + } + break; + } + } + inputErrorCount = 0; + return x; + } + + /** + * Skips whitespace characters and then reads one ""word"" from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. A word is defined as + * a sequence of non-whitespace characters (not just letters!). When using standard IO, + * this will not produce an error. In other cases, an IllegalArgumentException will be thrown + * if an end-of-file is encountered. + */ + public static String getWord() { + skipWhitespace(); + StringBuffer str = new StringBuffer(50); + char ch = lookChar(); + while (ch == EOF || !Character.isWhitespace(ch)) { + str.append(readChar()); + ch = lookChar(); + } + return str.toString(); + } + + /** + * Skips whitespace characters and then reads a value of type boolean from input. Any additional characters on + * the current line of input are retained, and will be read by the next input operation. When using standard IO, + * this will not produce an error; the user will be prompted repeatedly for input until a legal value + * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. + *

Legal inputs for a boolean input are: true, t, yes, y, 1, false, f, no, n, and 0; letters can be + * either upper case or lower case. One ""word"" of input is read, using the getWord() method, and it + * must be one of these; note that the ""word"" must be terminated by a whitespace character (or end-of-file). + */ + public static boolean getBoolean() { + boolean ans = false; + while (true) { + String s = getWord(); + if ( s.equalsIgnoreCase(""true"") || s.equalsIgnoreCase(""t"") || + s.equalsIgnoreCase(""yes"") || s.equalsIgnoreCase(""y"") || + s.equals(""1"") ) { + ans = true; + break; + } + else if ( s.equalsIgnoreCase(""false"") || s.equalsIgnoreCase(""f"") || + s.equalsIgnoreCase(""no"") || s.equalsIgnoreCase(""n"") || + s.equals(""0"") ) { + ans = false; + break; + } + else + errorMessage(""Illegal boolean input value."", + ""one of: true, false, t, f, yes, no, y, n, 0, or 1""); + } + inputErrorCount = 0; + return ans; + } + + // ***************** Everything beyond this point is private implementation detail ******************* + + private static String inputFileName; // Name of file that is the current input source, or null if the source is not a file. + private static String outputFileName; // Name of file that is the current output destination, or null if the destination is not a file. + + private static JFileChooser fileDialog; // Dialog used by readUserSelectedFile() and writeUserSelectedFile() + + private final static BufferedReader standardInput = new BufferedReader(new InputStreamReader(System.in)); // wraps standard input stream + private final static PrintWriter standardOutput = new PrintWriter(System.out); // wraps standard output stream + + private static BufferedReader in = standardInput; // Stream that data is read from; the current input source. + private static PrintWriter out = standardOutput; // Stream that data is written to; the current output destination. + + private static boolean readingStandardInput = true; + private static boolean writingStandardOutput = true; + + private static int inputErrorCount; // Number of consecutive errors on standard input; reset to 0 when a successful read occurs. + private static int outputErrorCount; // Number of errors on standard output since it was selected as the output destination. + + private static Matcher integerMatcher; // Used for reading integer numbers; created from the integer Regex Pattern. + private static Matcher floatMatcher; // Used for reading floating point numbers; created from the floatRegex Pattern. + private final static Pattern integerRegex = Pattern.compile(""(\\+|-)?[0-9]+""); + private final static Pattern floatRegex = Pattern.compile(""(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?""); + + private static String buffer = null; // One line read from input. + private static int pos = 0; // Position of next char in input line that has not yet been processed. + + private static String readRealString() { // read chars from input following syntax of real numbers + skipWhitespace(); + if (lookChar() == EOF) + return null; + if (floatMatcher == null) + floatMatcher = floatRegex.matcher(buffer); + floatMatcher.region(pos,buffer.length()); + if (floatMatcher.lookingAt()) { + String str = floatMatcher.group(); + pos = floatMatcher.end(); + return str; + } + else + return null; + } + + private static String readIntegerString() { // read chars from input following syntax of integers + skipWhitespace(); + if (lookChar() == EOF) + return null; + if (integerMatcher == null) + integerMatcher = integerRegex.matcher(buffer); + integerMatcher.region(pos,buffer.length()); + if (integerMatcher.lookingAt()) { + String str = integerMatcher.group(); + pos = integerMatcher.end(); + return str; + } + else + return null; + } + + private static long readInteger(long min, long max) { // read long integer, limited to specified range + long x=0; + while (true) { + String s = readIntegerString(); + if (s == null){ + errorMessage(""Integer value not found in input."", + ""Integer in the range "" + min + "" to "" + max); + } + else { + String str = s.toString(); + try { + x = Long.parseLong(str); + } + catch (NumberFormatException e) { + errorMessage(""Illegal integer input, "" + str + ""."", + ""Integer in the range "" + min + "" to "" + max); + continue; + } + if (x < min || x > max) { + errorMessage(""Integer input outside of legal range, "" + str + ""."", + ""Integer in the range "" + min + "" to "" + max); + continue; + } + break; + } + } + inputErrorCount = 0; + return x; + } + + + private static void errorMessage(String message, String expecting) { // Report error on input. + if (readingStandardInput && writingStandardOutput) { + // inform user of error and force user to re-enter. + out.println(); + out.print("" *** Error in input: "" + message + ""\n""); + out.print("" *** Expecting: "" + expecting + ""\n""); + out.print("" *** Discarding Input: ""); + if (lookChar() == '\n') + out.print(""(end-of-line)\n\n""); + else { + while (lookChar() != '\n') // Discard and echo remaining chars on the current line of input. + out.print(readChar()); + out.print(""\n\n""); + } + out.print(""Please re-enter: ""); + out.flush(); + readChar(); // discard the end-of-line character + inputErrorCount++; + if (inputErrorCount >= 10) + throw new IllegalArgumentException(""Too many input consecutive input errors on standard input.""); + } + else if (inputFileName != null) + throw new IllegalArgumentException(""Error while reading from file \"""" + inputFileName + ""\"":\n"" + + message + ""\nExpecting "" + expecting); + else + throw new IllegalArgumentException(""Error while reading from inptu stream:\n"" + + message + ""\nExpecting "" + expecting); + } + + private static char lookChar() { // return next character from input + if (buffer == null || pos > buffer.length()) + fillBuffer(); + if (buffer == null) + return EOF; + else if (pos == buffer.length()) + return '\n'; + else + return buffer.charAt(pos); + } + + private static char readChar() { // return and discard next character from input + char ch = lookChar(); + if (buffer == null) { + if (readingStandardInput) + throw new IllegalArgumentException(""Attempt to read past end-of-file in standard input???""); + else + throw new IllegalArgumentException(""Attempt to read past end-of-file in file \"""" + inputFileName + ""\"".""); + } + pos++; + return ch; + } + + private static void fillBuffer() { // Wait for user to type a line and press return, + try { + buffer = in.readLine(); + } + catch (Exception e) { + if (readingStandardInput) + throw new IllegalArgumentException(""Error while reading standard input???""); + else if (inputFileName != null) + throw new IllegalArgumentException(""Error while attempting to read from file \"""" + inputFileName + ""\"".""); + else + throw new IllegalArgumentException(""Errow while attempting to read form an input stream.""); + } + pos = 0; + floatMatcher = null; + integerMatcher = null; + } + + private static void emptyBuffer() { // discard the rest of the current line of input + buffer = null; + } + + private static void outputError(String message) { // Report an error on output. + if (writingStandardOutput) { + System.err.println(""Error occurred in TextIO while writing to standard output!!""); + outputErrorCount++; + if (outputErrorCount >= 10) { + outputErrorCount = 0; + throw new IllegalArgumentException(""Too many errors while writing to standard output.""); + } + } + else if (outputFileName != null){ + throw new IllegalArgumentException(""Error occurred while writing to file \"""" + + outputFileName+ ""\"":\n "" + message); + } + else { + throw new IllegalArgumentException(""Error occurred while writing to output stream:\n "" + message); + } + } + +} // end of class TextIO +" +A20749,"public class Scores implements Comparable{ + private int first; + private int second; + private int third; + + public Scores(int total) { + first = second = third = total / 3; + + if( (total % 3) == 1 ) { + first += 1; + } + else if( (total % 3) == 2 ) { + first += 1; + second += 1; + } + } + + public Scores(int first, int second, int third) { + this.first = first; + this.second = second; + this.third = third; + } + + public int compareTo(Scores otherScores) { + return this.getTotal() - otherScores.getTotal(); + } + + public int getHighest() { + if(first >= second && first >= third) + return first; + else if(second >= first && second >= third) + return second; + else + return third; + } + + public int getScore(int position) { + switch(position) { + case 1: + return first; + case 2: + return second; + case 3: + return third; + default: + return -1; + } + } + + public int getTotal() { + return first + second + third; + } + + public void minMax(int positionToGain, int positionToLose) { + if( positionToGain == 1 ) { + if( positionToLose == 2 ) { + first += 1; + second -= 1; + } + else if( positionToLose == 3 ) { + first += 1; + third -= 1; + } + } + else if( positionToGain == 2 ) { + if( positionToLose == 1 ) { + second += 1; + first -= 1; + } + else if( positionToLose == 3 ) { + second += 1; + third -= 1; + } + } + else if( positionToGain == 3 ) { + if( positionToLose == 1 ) { + third += 1; + first -= 1; + } + else if( positionToLose == 2 ) { + third += 1; + second -= 1; + } + } + } + + public void skew() { + if( getTotal() <= 2 ) + return; + + if( (getTotal() % 3) == 0 ) { // All equal + minMax(1, 2); + } + else if( (getTotal() % 3) == 1 ) { // 2 Small + minMax(2, 3); + } + else if( (getTotal() % 3) == 2 ) { // 2 Big + minMax(1, 2); + } + } +} +" +A21200,"import java.io.*; + +public class Dancing{ + + public static void main(String args[]){ + + try{ + + FileInputStream fstream = new FileInputStream(args[0]); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + PrintWriter out = new PrintWriter(args[0] + ""_out""); + + String strLine = br.readLine(); + int cases = Integer.parseInt(strLine); + + for (int i = 0; i < cases; i++){ + + strLine = br.readLine(); + String[] this_literals = strLine.split("" ""); + int[] this_line = new int[this_literals.length]; + for (int j = 0; j < this_literals.length; j++) this_line[j] = Integer.parseInt(this_literals[j]); + + int number_of_googlers = this_line[0]; + int number_of_surprises = this_line[1]; + int best_result = this_line[2]; + + int candidates = 0; + + for (int googler = 0; googler < number_of_googlers; googler++){ + + int unsurprising = 0; + int surprising = 0; + + for (int score1 = 0; score1 <= 10; score1++){ + for (int score2 = 0; score2 <= 10; score2++){ + for (int score3 = 0; score3 <= 10; score3++){ + + if (score1 + score2 + score3 == this_line[googler+3] && + score1 - score2 < 2 && score1 - score2 > -2 && + score2 - score3 < 2 && score2 - score3 > -2 && + score1 - score3 < 2 && score1 - score3 > -2){ + System.out.println(""case "" + i + "" googler "" + googler + "" score1 "" + score1 + "" score2 "" + score2 + "" score3 "" + score3); + if (Math.max(score1,Math.max(score2,score3)) >= best_result) unsurprising++; + } + + if (score1 + score2 + score3 == this_line[googler+3] &&( + ((score1 - score2 == 2 | score1 - score2 == -2) && + score2 - score3 < 2 && score2 - score3 > -2 && + score1 - score3 < 2 && score1 - score3 > -2) + | + (score1 - score2 < 2 && score1 - score2 > -2 && + (score2 - score3 == 2 | score2 - score3 == -2) && + score1 - score3 < 2 && score1 - score3 > -2) + | + (score1 - score2 < 2 && score1 - score2 > -2 && + score2 - score3 < 2 && score2 - score3 > -2&& + (score1 - score3 == 2 | score1 - score3 == -2))) + + | + + ( + ((score1 - score2 == 2 | score1 - score2 == -2) && + (score2 - score3 == 2 | score2 - score3 == -2) && + score1 - score3 < 2 && score1 - score3 > -2) + | + (score1 - score2 < 2 && score1 - score2 > -2 && + (score2 - score3 == 2 | score2 - score3 == -2) && + (score1 - score3 == 2 | score1 - score3 == -2)) + | + ((score1 - score2 == 2 | score1 - score2 == -2) && + score2 - score3 < 2 && score2 - score3 > -2&& + (score1 - score3 == 2 | score1 - score3 == -2)))){ + System.out.println(""case "" + i + "" googler "" + googler + "" score1 "" + score1 + "" score2 "" + score2 + "" score3 "" + score3 + ""(*)""); + if (Math.max(score1,Math.max(score2,score3)) >= best_result) surprising++; + } + + + } + } + } + + if (unsurprising > 0) candidates++; + else if (surprising > 0 && number_of_surprises > 0){ + candidates++; + number_of_surprises--; + } + + } + + out.println(""Case #"" + (i+1) + "": "" + candidates); + + } + + + + in.close(); + out.close(); + + } + + catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + + } + +} + +" +A20312,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class Dancing { + + public static void main(String[] args) { + try{ + FileInputStream fstream = new FileInputStream(""in.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter ostream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(ostream); + int count = Integer.parseInt(br.readLine()); + for(int i=0;i= p) { + ++ccc; + } + + else { + if(p-c == 1) { + if(r > 0) + ++ccc; + else { + if(s > 0 && (c-1 >=0)) { + ++ccc; + --s; + } + } + } + if(p - c == 2) { + if(s > 0) { + if(r == 2) { + ++ccc; + --s; + } + } + } + } + } + out.write(""Case #""+(i+1)+"": "" + ccc); + out.write(""\r\n""); + System.out.println(""Case #""+(i+1)+"": "" + ccc); + } + //Close the input stream + in.close(); + out.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A20255," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Arrays; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Alex + */ +public class Dancing { + private class Data { + public int N; + public int S; + public int p; + public int[] totalScores; + public int[][] scores; + + public Data(String s) { + String[] parts = s.trim().split("" ""); + N = Integer.parseInt(parts[0]); + S = Integer.parseInt(parts[1]); + p = Integer.parseInt(parts[2]); + totalScores = new int[N]; + scores = new int[N][3]; + for (int i=0;i 0 && ++i scores[i][1]) //it's like 3,3,4 therefore can't fix it + continue; + if (scores[i][1] == 0) //can't decrease + continue; + scores[i][1]--; + scores[i][2]++; + S--; + } + } + if (S > 0) { + System.err.println(""What the fuck""); + //return; + } + + int above = 0; + for (i=0; i= p) + above++; + } + return above; + } + } + + private static String IN = "".\\B-large.in""; + private static String OUT = "".\\B-large.out""; + + private Data[] datas; + + private void go() { + File file = new File(IN); + System.out.println(file.getAbsolutePath()); + File fo = new File(OUT); + try { + if (!fo.createNewFile()) { + fo.delete(); + fo.createNewFile(); + } + BufferedReader br = new BufferedReader(new FileReader(file)); + BufferedWriter bw = new BufferedWriter(new FileWriter(fo)); + String line; + int num = Integer.parseInt(br.readLine()); + datas = new Data[num]; + int i = 0; + while ((line = br.readLine()) != null && num-->0) { + datas[i] = new Data(line); + int solv = datas[i].Solve(); + String ss = ""Case #""+(i+1)+"": ""+solv+""\n""; + System.out.print(ss); + bw.write(ss); + i++; + } + br.close(); + bw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Dancing() { + go(); + //test(); + } + + public void test() { + int N = 3; //num of googlers + int S = 1; //num surprising scores + int p = 5; //greater high score than 5 + int[] ns = new int[]{15,13,11}; + + int[][] scores = new int[3][3]; + + for (int i=0; i 0 && i scores[i][1]) //it's like 3,3,4 therefore can't fix it + continue; + scores[i][1]--; + scores[i][2]++; + S--; + } + i++; + } + if (S > 0) { + System.err.println(""What the fuck""); + return; + } + + int above = 0; + for (i=0; i= p) + above++; + } + System.out.println(""The answer is "" + above); + } + + public void comb(int total) { + + } + + public static void main(String[] args) { + new Dancing(); + } +} +" +A21679,"package gcj2012.qr; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class ProblemB { + public static void main(String[] args) throws FileNotFoundException, IOException{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""B-large.out"")); + int t = Integer.parseInt(br.readLine()); + int n, surpresas, melhor; + for (int i=1; i<=t; i++){ + String campos[] = br.readLine().split("" ""); + n = Integer.parseInt(campos[0]); + surpresas = Integer.parseInt(campos[1]); + melhor = Integer.parseInt(campos[2]); + int total = 0; + for (int j=0; j= melhor){ + total++; + }else if (sobra >= 1 && media + 1 <= 10 && media + 1 >= melhor){ + total++; + }else if (sobra == 2 && surpresas > 0 && media + 2 <= 10 && media + 2 >= melhor){ + total++; + surpresas--; + }else if (media >= 1 && media + 1 <= 10 && surpresas > 0 && media + 1 >= melhor){ + total++; + surpresas--; + } + } + bw.write(""Case #"" + i + "": "" + total + ""\n""); + } + br.close(); + bw.close(); + } +} +" +A21537,"import java.io.*; + +public class Test2 { + + final static String INPUT_FILE_NAME = ""input2""; + + int T = 0; + int q = 0; + + public static void main(String args[]) { + try { + Test2 tst = new Test2(); + tst.getInput(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + private void getInput() throws Exception { + File file = new File(INPUT_FILE_NAME); + FileReader fis = new FileReader(file); + BufferedReader br = new BufferedReader(fis); + String strT = br.readLine(); + T = getInt(strT); + + for (int i=0; i= P) { + count++; + } else if ((t[i]/3 >= (P-1)) && S>0) { + S--; + count++; + } + } else if (mod3 ==2) { + if (t[i]/3 >= P-1) { + count++; + } else if ((t[i]/3 >= (P-2)) && S>0) { + S--; + count++; + } + } else { + if (t[i]/3 >= P-1) { + count++; + } + } + } + + + System.out.println(""Case #""+(num+1)+"": ""+count); + //System.out.println(""Hello WorldI""); + } + + private int getInt(String a) { + return Integer.parseInt(a, 10); + } + + private int getIntx(String a) { + if (a.equals(""."")) { + return 0; + } + return 1; + } + +} +" +A20012,"import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Scanner; + +/** + * Google Code Jam 2012 - Qualification Round + * Google Code Jam 2012 Name - SamCoding + * @author Sameer Abdul - Purdue University + */ +public class DancingGooglers { + + FileOutputStream out = null; + + public DancingGooglers() { + out = null; + try { + out = new FileOutputStream(""out.txt""); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + } + + public void print(char[][] array) + { + for(int i = 0; i < array.length; i++) + { + for(int j = 0; j < array.length; j++) + { + System.out.print(array[i][j] + "" ""); + } + System.out.println(); + } + System.out.println(); + } + + public void output(int casenum, String s) + { + String print = ""Case #"" + casenum + "": "" + s + ""\n""; + try { + out.write(print.getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public boolean valid(int one, int two, int three) + { + int sum1 = two-one; + int sum2 = three-one; + int sum3 = three-two; + sum1 = Math.abs(sum1); + sum2 = Math.abs(sum2); + sum3 = Math.abs(sum3); + if( sum1 > 2 || sum2 > 2 || sum3 > 2) + return false; + if( one < 0 || two < 0 || three < 0) + return false; + return true; + } + + public static void main(String[] args) { + DancingGooglers dg = new DancingGooglers(); + Scanner sc = new Scanner(System.in); + int cases = sc.nextInt(); +// System.out.println(""Cases = "" + cases); + int casenum = 0; + while(cases-- != 0) + { + int result = 0; + + int googlers = sc.nextInt(); + int surprising = sc.nextInt(); + int p = sc.nextInt(); +// System.out.print(""Googlers = "" + googlers); +// System.out.print("" p = "" + p); +// System.out.print(""; Surprising = "" + surprising + "" Cases: ""); + int scores[][] = new int[googlers][3]; + for(int i = 0; i < googlers; i++) + { + int total = sc.nextInt(); + //split + int remainder = total%3; + scores[i][0] = total/3; + scores[i][1] = total/3; + scores[i][2] = total/3; + if(remainder == 1) + { + scores[i][0]++; + } + if(remainder == 2) + { + scores[i][0]++; + scores[i][1]++; + } + } +// System.out.println(); + + // Real code + // torture + for(int i = 0; i < googlers; i++) + { + if(surprising == 0) + { + if(scores[i][0] >= p) + result++; + } + else + { + int one = scores[i][0]; + int two = scores[i][1]; + int three = scores[i][2]; + + if(one >= p) + { + result++; + } + else + { + if(one+1 >= p) + { + if(dg.valid(one+1, two-1, three)) + { + scores[i][0]++; + scores[i][1]--; + surprising--; + result++; + } + } + } + } + //System.out.println(scores[i][0] + "" "" + scores[i][1] + "" "" + scores[i][2] + ""; ""); + } + //dg.out.write(""Case #"" + ++casenum + "": "" + result + ""\n""); + System.out.println(""Case #"" + ++casenum + "": "" + result); + } + } +} +" +A20327,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class dancing { + public static void main(String args[]) throws Exception{ + FileInputStream fs = new FileInputStream(""in2.txt""); + DataInputStream in = new DataInputStream(fs); + BufferedReader br=new BufferedReader(new InputStreamReader(in)); + FileWriter fstream = new FileWriter(""out3.txt""); + BufferedWriter out = new BufferedWriter(fstream); + int T=Integer.parseInt(br.readLine()); + for(int i=0;i=test){ + count++; + } + else if((id>=test2)&& id>0){ + count2++; + } + } + if(S>=count2){ + count=count+count2; + } + else{ + count=count+S; + } + out.write(""Case #""+(i+1)+"": ""+count); + out.newLine(); + } + out.close(); + br.close(); + } +} +" +A22566,"package qualifying; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class B { + + public static String solve(int N, int S, int p, int[] t) { + + int cnt = 0; + + for(int i=0; i=2*Math.max(p-1,0)+p) cnt++; + if(t[i]<2*Math.max(0,p-1)+p && t[i]>=2*Math.max(0,p-2)+p) { + if(S>0) { + cnt++; + S--; + } + } + } + + + return Integer.toString(cnt); + } + + + public static void main(String[] args) throws Exception { + + String fs_in = ""/Users/ctynan/Downloads/test.txt""; + String fs_out = ""/Users/ctynan/Documents/B-out.txt""; + String line; + BufferedReader br = new BufferedReader(new FileReader(fs_in)); + BufferedWriter bw = new BufferedWriter(new FileWriter(fs_out)); + + line=br.readLine(); + line=line.toLowerCase(); + int tst = Integer.valueOf(line); + + for(int ii=0;ii doubtful = new ArrayList(); + for (int j = 3; j < data.length; j++) { + int totalPoints = Integer.parseInt(data[j]); + if (totalPoints >= NUM_JUDGES * MAX_SCORE - 1) { // 29 30 + topGooglers++; // bestResult = 10, not surprise + } else if (totalPoints <= MIN_SCORE + 1) { // 0 1 + if (totalPoints >= minBestResult) { + topGooglers++; // bestResult = totalPoints, not surprise + } + } else { // we can choose between surprise or not surprise + int bestResult = (totalPoints + (NUM_JUDGES - 1) * MAX_DIFF) / NUM_JUDGES; + if ((totalPoints - 1) % NUM_JUDGES == 0) { // 4 7 10 13 16 19 22 25 28 + either++; // same bestResult + if (bestResult >= minBestResult) { + topGooglers++; + } + } else { + doubtful.add(bestResult - 1); // if we choose surprise -> bestResult++ + } + } + } + if (either + doubtful.size() < numSurprises) { // not enough surprises + writer.println(""Case #"" + i + "": 0""); + } else { + Collections.sort(doubtful); + Collections.reverse(doubtful); // we want the best first + int surprises = 0; + for (int bestResult: doubtful) { + if (bestResult < minBestResult && surprises < numSurprises) { // we haven't reached numSurprises yet + surprises++; // we can afford to add one surprise + bestResult++; // and +1 bestResult + } + if (bestResult >= minBestResult) { + topGooglers++; + } + } + writer.println(""Case #"" + i + "": "" + topGooglers); + } + } + reader.close(); + writer.close(); + } + +}" +A21450,"package Qualification; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; +import java.util.StringTokenizer; + +public class ProblemB { + int good; + int needsSuprise; + int bad; + int p; + public ProblemB() throws IOException { + BufferedWriter out = new BufferedWriter(new FileWriter(new File(""out.txt""))); + //Scanner scanner = new Scanner(System.in); + Scanner scanner = new Scanner(new File(""in.txt"")); + int T = Integer.parseInt(scanner.nextLine()); + for(int i=1;i<=T;i++) { + good = needsSuprise = bad = 0; + StringTokenizer tokens = new StringTokenizer(scanner.nextLine()); + int numGooglers = Integer.parseInt(tokens.nextToken()); + int suprises = Integer.parseInt(tokens.nextToken()); + p = Integer.parseInt(tokens.nextToken()); + for(int j=0;j=p || diffScore>=p) { + good++; + return; + } + if(totalPoints>=2 && (score+1>=p || diffScore+1>=p)) { + needsSuprise++; + return; + } + bad++; + } + + public static void main(String args[]) throws IOException { + new ProblemB(); + } +} +" +A20864,"package codejam; + +import codejam.y11.round0.CandySplitting; +import codejam.y12.round0.DancingGooglers; +import codejam.y12.round0.SpeakingInTongues; +import utils.Jam; + +/** + * + * @author Fabien Renaud + */ +public class MainEntryPoint { + public static void main(String[] args) { + Jam j = new DancingGooglers(""/home/fabien/B-large.in""); + j.run(); + } +} +" +A22562,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package topcoder; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Scanner; +import java.util.StringTokenizer; + +/** + * + * @author ahmet + */ +public class codeJam { + + + public static void main(String[] args) throws FileNotFoundException, IOException + { + Scanner scan = new Scanner(System.in); + + + int T = scan.nextInt(); + + for(int i = 0; i < T; i++) + { + ArrayList list = new ArrayList(); + int howMany = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + + for(int ii = 0; ii < howMany; ii++) + { + list.add(scan.nextInt()); + } + Collections.sort(list); + System.out.println(""Case #"" + (i + 1) + "": "" + analiz(list, S, p)); + } + } + + public static String analiz( ArrayList a, int S, int p) + { + int count = 0; + for(int i = 0; i < a.size(); i++) + { + if(a.get(i)/3 >= p) + { + a.set(i, -1); + count++; + } + } + for(int i = 0; i < a.size(); i++) + { + if(a.get(i) == -1) + { + a.remove(i); + i=0; + } + } + while(S >= 0 && a.size() > 0 && a.get(a.size() - 1 ) > 0) + { + if(a.get(a.size() - 1 )%3 == 0 ) + { + if(a.get(a.size() - 1)/3 + 1 >= p && S != 0) + { + count++; + S--; + } + else + break; + } + else if(a.get(a.size() - 1 ) % 3 == 1) + { + if(a.get(a.size() - 1)/3 + 1 >= p) + { + count++; + } + else + break; + + } + else if(a.get(a.size() - 1 ) % 3 == 2) + { + if(a.get(a.size() - 1) /3 + 1 >= p) + { + count++; + } + else if(a.get(a.size() - 1)/3 + 2 >= p && S != 0) + { + count++; + S--; + } + else + break; + } + a.remove(a.size() - 1 ); + } + + return """" + count; + } + +} +" +A20113,"package source; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class DancingGooglers { + + /** + * @param args + */ + public static void main(String[] args) throws IOException{ + Scanner scan = new Scanner(new File(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""B-large.out"")); + + int testCases = scan.nextInt(); + Map mapa = new HashMap(); + mapa.put(3d,2); + mapa.put(6d,3); + mapa.put(9d,4); + mapa.put(12d,5); + mapa.put(15d,6); + mapa.put(18d,7); + mapa.put(21d,8); + mapa.put(24d,9); + mapa.put(27d,10); + + for(int i=0; i < testCases; i++){ + int googlers = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int bestResults = 0; + + for(int j=0; j < googlers; j++){ + double qual = scan.nextInt(); + + double firstSecond = Math.round(qual/3d); + double third = qual-(firstSecond*2); + + if(firstSecond >= p || third >= p) { + bestResults++; + } else if(s > 0 && p-third <= 2 && third <= firstSecond && !(((third+2)-(firstSecond-1)) > 2) && (third+2) <= 10) { + bestResults++; + s--; + } else if(third == firstSecond && mapa.get(qual) != null && mapa.get(qual) >= p && s > 0){ + bestResults++; + s--; + } + } + + bw.write(""Case #""+(i+1)+"": ""+bestResults+""\n""); + } + bw.flush(); + bw.close(); + } + +} +" +A22418,"package googlecodejam; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class GoogleCodeJam { + + public static int calcGooglers(int p, int s, int[] g) { + int avg = p*3; + int n = g.length; + int cont = 0; + for (int i = 0; i< n; i++) { + if (g[i] >= avg ) { + cont++; + } else if (avg == 0){ + cont++; + } else if (g[i] >= avg-2 && avg-2 >= p) { + cont++; + } else if (g[i] >= avg-4 && avg-4 >= p) { + if (s > 0) { + cont++; + s--; + } + } + } + return cont; + } + + public static void doIt() throws Exception { + Scanner sc = new Scanner(new FileReader(""/home/fuelusumar/input.txt"")); + PrintWriter pw = new PrintWriter(new FileWriter(""/home/fuelusumar/output.txt"")); + int caseCnt = sc.nextInt(); + for (int caseNum = 0; caseNum < caseCnt; caseNum++) { + pw.print(""Case #"" + (caseNum + 1) + "": ""); + /***********************************************/ + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] g = new int[n]; + for (int googler = 0; googler < n; googler++) { + g[googler] = sc.nextInt(); + } + /***********************************************/ + pw.println(calcGooglers(p,s,g)); + } + pw.flush(); + pw.close(); + sc.close(); + } + + + public static void main(String[] args) throws Exception { + doIt(); + } +} +" +A21143,"import java.util.*; + +public class Main{ + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + + int T = sc.nextInt(); + int caseNum = 0; + + while(caseNum++0; j--){ + triplet[i][tmp++]++; + } + } + + int ans = 0; + for(int i=0; i=p && triplet[i][0]!=triplet[i][1]){ + ans++; triplet[i][0] = -1; + } + else if(triplet[i][0]!=triplet[i][1]){ + triplet[i][0] = -1; + } + else if(triplet[i][0]>=p){ + ans++; triplet[i][0] = -1; + } + else if(triplet[i][1]>0){ + triplet[i][0]++; triplet[i][1]--; + } + } + + int count = 0; + for(int i=0; i=p){count++;} + } + if(count>=s){ans += s;} + else {ans += count;} + + System.out.println(""Case #""+caseNum+"": ""+ans); + } + } +} +" +A21533,"import java.util.*; +import static java.lang.Math.*; + +public class B { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int zz = 1; zz <= T; zz++) { + System.err.println(zz); + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + int num11 = 0; + int num10 = 0; + int num01 = 0; + int num00 = 0; + for (int i = 0; i < N; i++) { + int sum = in.nextInt(); + boolean reg = false; + boolean sup = false; + for(int a = 0; a <= 10; a++) { + for(int b = 0; b <= 10; b++) { + for(int c = 0; c <= 10; c++) { + int min = min(a, min(b, c)); + int max = max(a, max(b, c)); + if (max-min > 2 || a + b + c != sum || max < P) + continue; + if (max-min == 2) + sup = true; + else + reg = true; + } + } + } + if (sup && reg) + num11++; + else if (!sup && reg) + num01++; + else if(sup && !reg) + num10++; + else + num00++; + } +// System.out.println(num00+ "" ""+num10+"" ""+num01+"" ""+num11); + int ans = 0; + for(int a = 0; a <= num11; a++) { + for(int b = 0; b <= num10; b++) { + for(int c = 0; c <= num01; c++) { + int d = S - (a + b + c); + if (d > num00 || d < 0) + continue; + ans = max(ans, num11 + b + num01-c); + } + } + } + + System.out.format(""Case #%d: %d\n"", zz, ans); + } + } +} +" +A21801,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; + + +public class Dancers { + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(new File(""B-large.in""))); + BufferedWriter out = new BufferedWriter(new FileWriter(new File(""outputL""))); + + String line = in.readLine(); + int T = Integer.parseInt(line); + + for(int i = 0; i < T && in.ready(); i++) { + line = in.readLine(); + + StringTokenizer tokenizer = new StringTokenizer(line); + + int N = Integer.parseInt(tokenizer.nextToken()); + int S = Integer.parseInt(tokenizer.nextToken()); + int p = Integer.parseInt(tokenizer.nextToken()); + + int numReg = 0; + int numSurprise = 0; + + int min = 3*p - 2; + int max = 3*p + 2; + int sMin = min - 2; + int sMax = max + 2; + + for(int j = 0; j < N && tokenizer.hasMoreTokens(); j++) { + int score = Integer.parseInt(tokenizer.nextToken()); + + if (score == 0) { + if (p == 0) + numReg++; + continue; + } + + if (score == 1) { + if (p <= 1) + numReg++; + continue; + } + + if (score >= min) { + numReg++; + continue; + } + + if (score >= sMin) + numSurprise++; + } + + numSurprise = Math.min(numSurprise, S); + int num = numReg + numSurprise; + + //System.out.println(""Case #"" + (i+1) + "": "" + num + "", reg: "" + numReg + "", surp: "" + numSurprise); + + out.write(""Case #"" + (i+1) + "": "" + num); + out.newLine(); + + } + + out.close(); + } +} +" +A22285,"import java.util.*; +import java.io.*; + + +public class problem2 +{ + private final Scanner sc; + private static final boolean debug = true; + + static void debug(Object ... objects) + { + if(debug) + System.err.println(Arrays.toString(objects)); + } + + problem2() + { + sc = new Scanner(new BufferedInputStream(System.in)); + } + + public static void main(String [] args) + { + (new problem2()).solve(); + } + + + void solve() + { + int T = sc.nextInt(); + int cs = 0; + while(cs < T) + { + cs++; + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int ans = 0; + for(int i=0;i=p) + { + ans++; + continue; + } + int m = x%3; + if(m == 1) continue; + if(maxVal == p-1 && s>0) + { + if(maxVal+1<=10&&maxVal-1>=0) + { + ans++; + s--; + } + } + } + + + System.out.println(""Case #"" + cs+ "": ""+ ans); + } + + } +} +" +A20843," + import java.io.*; + import java.util.Arrays; + import java.util.HashMap; + import java.util.Scanner; +import java.util.regex.Pattern; + + /** Parse the movie database. + * + * The format of this database is one movie per line, with movie fields + * separated by a "","". The format is: + * + * title,category + * + * Note that there is no space before or after the "","". + */ + public class Round2 + { + private String[] Google; + private FileReader x; + + public static void main(String[] argv) + throws FileNotFoundException + { + FileReader fr = new FileReader(argv[0]); + + Round2 x = new Round2(fr); + + String[] g = x.getStrings(); + for (int i = 0; i < g.length; i ++){ + System.out.println(""Case #""+(i+1)+"": ""+g[i]); + } + } + + /** Parse all lines from the database. + * + * @param fr The FileReader object from which to read the database. + */ + public Round2(FileReader fr) + { try { + if (fr.ready()){ + Scanner g_reader = new Scanner(fr); + int y = 0; + if (g_reader.hasNextLine()){ + y = new Integer(g_reader.nextLine()); + } + Google = new String[y]; + parseAll(g_reader); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** Return a copy of the array of movies + */ + public String[] getStrings() + { return Arrays.copyOf(Google, Google.length); + } + + /** Parse all lines from the database. + * + * @param scn The Scanner object from which to read the database. + */ + private void parseAll(Scanner scn) + { int i = 0; + while (scn.hasNextLine()){ + Google[i] = parseOne(scn.nextLine()); + i++; + } + } + + /** Parse one line from the database. + * + * @param line One line from the movie database, without the newline + * character. + * @throws ParseError + */ + private String parseOne(String line) + { String[] x = line.split("" ""); + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++){ + y[i] = Integer.parseInt(x[i]); + } + return """"+Translate(y); + } + + + + + private int Translate(int[] x){ + + int numG = x[0]; + int numS = x[1]; + int P = x[2]; + int w = 0; + Arrays.sort(x, 3, x.length); + for (int i = 3; i < x.length; i++){ + if (P*3 -2 <= x[i] && P <= x[i]){ + w++; + } + else if(P*3 -4 <= x[i] && numS > 0 && P <= x[i]){ + w++; + numS --; + } + } + return w; + } +} +" +A20126,"import java.util.*; +public class Main { + public static void main(String[] args){ + int t; + Scanner s = new Scanner(System.in); + t=s.nextInt(); + for(int k=0;k3*p-3) count++; + else{ + if(S>0) { + count++; + S--; + } + } + } + System.out.println(""Case #""+(k+1)+"": ""+count); + } + } +} +" +A21062,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Joel + */ +import java.io.*; +import java.util.*; +public class GoogleDance +{ + public static void main(String[] args) + { + try + { + FileWriter output = new FileWriter(""C:\\Users\\Joel\\Documents\\CSCI 221\\Netbeans Projects\\Google CodeJam\\src\\B-large.out""); + BufferedWriter out = new BufferedWriter(output); + FileReader reader = new FileReader(""C:\\Users\\Joel\\Documents\\CSCI 221\\Netbeans Projects\\Google CodeJam\\src\\B-large.in""); + BufferedReader in = new BufferedReader(reader); + ArrayList scores = new ArrayList(); + int count = 0; + int t = Integer.parseInt(in.readLine()); + for (int i = 0; i < t; i++) + { + StringBuilder nums = new StringBuilder(in.readLine()); + int n = Integer.parseInt(nums.substring(0, nums.indexOf("" ""))); + nums.delete(0, (nums.indexOf("" "") + 1)); + int s = Integer.parseInt(nums.substring(0, nums.indexOf("" ""))); + nums.delete(0, (nums.indexOf("" "") + 1)); + int p = Integer.parseInt(nums.substring(0, nums.indexOf("" ""))); + nums.delete(0, (nums.indexOf("" "") + 1)); + for (int j = 0; j < (n - 1); j++) + { + scores.add(Integer.parseInt(nums.substring(0, nums.indexOf("" "")))); + nums.delete(0, (nums.indexOf("" "") + 1)); + } + scores.add(Integer.parseInt(nums.substring(0))); + Collections.sort(scores); + int next = 0; + if (p == 0) + count = scores.size(); + else if (p == 1) + { + for (int k : scores) + if (k != 0) + count++; + } + else + { + while (s > 0 && (next != scores.size())) + { + if (scores.get(next) >= (p + (2 * (p - 2)))) + { + count++; + next++; + s--; + } + else + next++; + } + while (next != (scores.size())) + { + if (scores.get(next) >= (p + (2 * (p - 1))) && next != scores.size()) + { + count++; + next++; + } + else + next++; + } + } + out.write(""Case #"" + (i + 1) + "": "" + count + ""\n""); + count = 0; + next = 0; + scores.clear(); + } + out.close(); + } + catch (IOException e) + { + + } + } +} +" +A23055,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Googler implements Runnable { + int[] isSuprisingMaxScore = new int[31]; + int[] isNotSuprisingMaxScore = new int[31]; + boolean[] canSuprising = new boolean[31]; + private void solve() throws IOException { + // long time = System.currentTimeMillis(); + int test = nextInt(); + Arrays.fill(canSuprising, true); + canSuprising[0] = false; + canSuprising[1] = false; + for (int i = 4; i <= 30 ; i += 3) + canSuprising[i] = false; + int maxScore = 2; + for (int i = 2; i <= 30; i += 3) { + for (int j = i ; j <= Math.min(i + 2, 30); j++) + isSuprisingMaxScore[j] = maxScore; + maxScore++; + } + maxScore = 1; + for (int i = 1; i <= 30; i += 3) { + for (int j = i ; j <= Math.min(i + 2, 30); j++) + isNotSuprisingMaxScore[j] = maxScore; + maxScore++; + } + + for (int i = 1; i <= test; i++) { + solveTest(i); + } + writer.close(); + // writer.println(""Running time: "" + (System.currentTimeMillis() - + // time)); + } + + private void solveTest(int test) throws IOException { + // TODO Auto-generated method stub + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] scores = new int[n+1]; + for (int i = 1; i <= n; i++) + scores[i] = nextInt(); + int result = 0; + for (int i = 1; i <= n; i++) { + if (isNotSuprisingMaxScore[scores[i]] >= p) { + result++; + continue; + } + if (isSuprisingMaxScore[scores[i]] >= p && s >= 1) { + result++; + s--; + } + } + writer.write(""Case #"" + test + "": "" + result + ""\n""); + } + + public static void main(String[] args) { + new Googler().run(); + } + + BufferedReader reader; + StringTokenizer tokenizer; + PrintWriter writer; + String fileName = ""Googler""; + public void run() { + try { + reader = new BufferedReader(new FileReader(fileName + "".in"")); + tokenizer = null; + writer = new PrintWriter(new FileWriter(fileName + "".out"")); + solve(); + reader.close(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + return tokenizer.nextToken(); + } +}" +A22980,"package dancingwiththegooglers.codejam; + +import java.util.Scanner; + + +public class Case { + String str; + int n, s, p; + int[] t; + Case(Scanner in){ + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + t = new int[n]; + for (int i=0; i= p){ + if(t[i] >= minNotSuprInRange) + y++; + else if(t[i] >= minSuprInRange){ + if(numOfSupr < s){ + numOfSupr++; + y++; + } + } + } + + } + return String.valueOf(y); + } + +} +" +A21655,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class G2012B { + + public static void main(String[] args) throws IOException { + G2012B trans = new G2012B(); + trans.doMe(); + } + + private static final String ID = ""practice""; + private static final String SIZE = ""small""; + private static final String CODE = ""A""; + + private static final String NAME = CODE + ""-"" + SIZE + ""-"" + ID; + + public void doMe() throws IOException { + //File file = new Fil(""test.txt""); + File file = new File(""B-large.in""); + BufferedWriter out = new BufferedWriter(new FileWriter(""output.out"")); + try { + //use buffering, reading one line at a time + //FileReader always assumes default encoding is OK! + BufferedReader input = new BufferedReader(new FileReader(file)); + try { + String line = input.readLine(); + int count = Integer.parseInt(line); + + for (int i = 0; i < count; i++) { + line = input.readLine(); + //System.out.println(line); + int str = this.proccessLine(line.trim()); + out.write(""Case #"" + (i + 1) + "": "" + str); + if (i < count - 1) + out.write(System.getProperty(""line.separator"")); + System.out.println(str); + } + } finally { + input.close(); + out.flush(); + out.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + int proccessLine(String line) { + String st[] = line.split("" ""); + int n = Integer.parseInt(st[0]); + int s = Integer.parseInt(st[1]); + int p = Integer.parseInt(st[2]); + int sol = 0; + for (int i = 3 ; i < st.length; i++) { + int u = calc(Integer.parseInt(st[i]), p); + if (u==1) sol++; + if (u==2 && s>0) { + sol++; + s--; + } + } + return sol; + } + + public int calc(int n, int t) { + if(n==0) { + if (t==0) return 1; + else return 0; + } + if(n==1) { + if (t<=1) return 1; + else return 0; + } + if (n==2) { + if (t==2) return 2; + if (t<=1) return 1; + return 0; + } + + if (t<=1) return 1; + n -= t; + if ((t-1)*2<=n) { + return 1; + } + if ((t-2)*2<=n) { + return 2; + } + return 0; + } +} +" +A20354,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; + +public class DancingWithGooglers { + + + public static void main(String[] args) throws IOException { + File in = new File(""c:\\temp\\input.txt""); + File out = new File(""c:\\temp\\output.txt""); + BufferedWriter w = new BufferedWriter(new FileWriter(out)); + Scanner sc = new Scanner(in); + int testCases = Utils.readIntegerLine(sc); + for (int i = 1; i <= testCases; i++) { + int googlers = Utils.readInteger(sc); + int surprising = Utils.readInteger(sc); + int minBestResult = Utils.readInteger(sc); + int[] totalPoints = new int[googlers]; + for(int j = 0; j < googlers; j++) { + totalPoints[j] = Utils.readInteger(sc); + } + int maxGooglersWithBestResults = solve(googlers, surprising, minBestResult, totalPoints); + String result = String.format(""Case #%d: %d"", i, maxGooglersWithBestResults); + w.write(result); + System.err.println(result); + w.newLine(); + } + w.close(); + + } + + static int minTotalPointsForBestScore(int b, boolean s) { + switch (b) { + case 0: return s ? 2 : 0; + case 1: return s ? 2 : 1; + default: return s ? Math.max(2, b + b - 2 + b - 2) : b + b - 1 + b - 1; + } + } + + static int maxTotalPointsForBestScore(int b, boolean s) { + return s ? 28 : 30; + } + + + static boolean canBeSurprising(int total) { + return total >= 2 && total <= 28; + } + + + private static int solve(int googlers, int surprising, int minBestResult, + int[] totalPoints) { + int n = googlers; + // Arrays.sort(totalPoints); + + Set canBeSurprising = new HashSet(); + Set okIfSurprising = new HashSet(); + Set okIfNotSurprising = new HashSet(); + Set areSurprising = new HashSet(); + int i = 0; + for (int points : totalPoints) { + int minPoints = 0; + int maxPoints = 0; + if (canBeSurprising(points)) { + canBeSurprising.add(i); + // assume surprising + minPoints = minTotalPointsForBestScore(minBestResult, true); + maxPoints = maxTotalPointsForBestScore(minBestResult, true); + if (points >= minPoints && points <= maxPoints) { + okIfSurprising.add(i); + } + } + + + // assume not surprising + minPoints = minTotalPointsForBestScore(minBestResult, false); + maxPoints = maxTotalPointsForBestScore(minBestResult, false); + if (points >= minPoints && points <= maxPoints) { + okIfNotSurprising.add(i); + } + i++; + } + + + int count = 0; + _outer: + + while (surprising > 0) { + for(int j = 0; j < googlers; j++) { + if (canBeSurprising.contains(j)) { + if (okIfSurprising.contains(j) && !okIfNotSurprising.contains(j)) { + surprising--; + areSurprising.add(j); + canBeSurprising.remove(j); + continue _outer; + } + } + } + for(int j = 0; j < googlers; j++) { + if (canBeSurprising.contains(j)) { + if (!okIfSurprising.contains(j) && okIfNotSurprising.contains(j)) { + surprising--; + areSurprising.add(j); + canBeSurprising.remove(j); + continue _outer; + } + } + } + for(int j = 0; j < googlers; j++) { + if (canBeSurprising.contains(j)) { + if (okIfSurprising.contains(j)) { + surprising--; + areSurprising.add(j); + canBeSurprising.remove(j); + continue _outer; + } + } + } + for(int j = 0; j < googlers; j++) { + if (canBeSurprising.contains(j)) { + surprising--; + areSurprising.add(j); + canBeSurprising.remove(j); + continue _outer; + } + } + } + + for(int j = 0; j < googlers; j++) { + if (okIfSurprising.contains(j) && areSurprising.contains(j)) { + count++; + } else + if (okIfNotSurprising.contains(j) && !areSurprising.contains(j)) { + count++; + } + } + + return count; + } + +} + +" +A22346,"import java.io.BufferedReader; +import java.io.FileReader; + import java.io.IOException; + import java.io.InputStreamReader; + import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Random; +import java.util.StringTokenizer; + + public class Test { + static BufferedReader reader; + static StringTokenizer tokenizer; + static PrintWriter writer; + + static int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + static long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + static double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + static String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + return tokenizer.nextToken(); + } + + public static void main(String[] args) throws IOException { + reader = new BufferedReader(new FileReader(""txt.in"")); + tokenizer = null; + writer = new PrintWriter(""System.out""); + solve(); + reader.close(); + writer.close(); + } + + private static void solve() throws IOException { + int T=nextInt(); + + for (int j=0;j1) + k=3*p-4; + else + { + for (int i=0;i=p) + an++; + } + ans+=Integer.toString(an); + if(j!=T-1) + writer.println(ans); + else + writer.print(ans); + continue; + } + + + for (int i=0;i0) + { + an++; + S--; + } + if (tt>k+1) + an++; + } + ans+=Integer.toString(an); + + if(j!=T-1) + writer.println(ans); + else + writer.print(ans); + } + + } + + }" +A20005,"import java.util.Scanner; + +public class Main{ + public static void main(String[] args) { + Scanner in= new Scanner(System.in); + int T= in.nextInt(); int n,t,s,answer=0; + for (int i = 0; i < T; i++) { + n=in.nextInt(); t=in.nextInt(); s=in.nextInt(); + for (int j = 0; j < n; j++) { + int x=in.nextInt(); int nashti=x%3; + if(x==0 && s!=0) continue; + if(x/3>=s){ answer++; continue;} + if(x/3==(s-1)){ + if(nashti>0){answer++; continue;} + if(t>0){t--; answer++; continue;} + } + if(x/3==(s-2)){ + if(nashti>=2 && t>0){t--; answer++; continue;} + } + } + System.out.println(""Case #""+(i+1)+"": ""+answer); + answer=0; + } + } +} +" +A22965,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.StringTokenizer; + + +public class Googlers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + + + String fichier =""C:\\result.txt""; + int compteurlignes = 0; + int nombreCas ; + ArrayList googlers = new ArrayList(); + ArrayList results = new ArrayList(); + //lecture du fichier texte + try + { + InputStream ips=new FileInputStream(fichier); + InputStreamReader ipsr=new InputStreamReader(ips); + BufferedReader br=new BufferedReader(ipsr); + String ligne; + while ((ligne=br.readLine())!=null){ + compteurlignes++; + //System.out.println(ligne); + if (compteurlignes ==1) + { + nombreCas = Integer.valueOf(ligne); + } + else + { + googlers.add(ligne); + //System.out.println(ligne); + } + + } + br.close(); + + + + + //traitement par ligne + ArrayList nombres = new ArrayList(); + for(int i = 0; i < googlers.size();i++) + { + ligne = googlers.get(i); + + + //get numbers + StringTokenizer st = new StringTokenizer(ligne, "" ""); + while (st.hasMoreTokens()) + { + nombres.add(st.nextToken()); + + } + + int numberGooglers = Integer.parseInt(nombres.get(0)); + int surprises = Integer.parseInt(nombres.get(1)); + int chiffre = Integer.parseInt(nombres.get(2)); + int value = 0; + + int totalNumber = chiffre *3; + + for(int x = 0; x < numberGooglers; x++) + { + int totalMark = Integer.parseInt(nombres.get(x+3)); + + if(totalNumber ==0) + { + value++; + } + else if(totalMark <= totalNumber+2 && totalMark >= totalNumber-2) + { + value++; + } + else if(totalMark == totalNumber-3 || totalMark == totalNumber-4) + { + if (surprises >0 && totalMark != 0) + { + surprises--; + value++; + } + } + else if(totalMark >= totalNumber+3) value++; + } + + results.add(String.valueOf(value)); + System.out.println(""result : ""+value); + //clean arrayList + nombres = new ArrayList(); + } + + + + } + catch (Exception e) + { + System.out.println(e.toString()); + + } + + + + + + //écrire dans le fichier + try + { + FileWriter fw = new FileWriter (fichier); + BufferedWriter bw = new BufferedWriter (fw); + PrintWriter fichierSortie = new PrintWriter (bw); + for (int w =0; w=p || y>=p || z>=p) + return true; + return false; + } + + @Override + public boolean equals(Object object){ + Triplet triplet2= (Triplet)object; + + return (this.x==triplet2.x && this.y==triplet2.y && this.z==triplet2.z); + + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + this.x; + hash = 47 * hash + this.y; + hash = 47 * hash + this.z; + return hash; + } + + + public String toString(){ + return x+"",""+y+"",""+z; + } + + public boolean surprised() { + return validPair(x,y) && validPair(y,z) && validPair(x,z); + } + + public boolean validPair(int y1, int y2){ + int r= y1-y2; + return (r<=1 && r>=-1); + } + +} +" +A20954,"package ch.socaciu.andrei.codejam; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Andrei Socaciu + */ +public class Dancing { + + public static void main(String[] args) throws Exception { + String in = ""data/Dancing-large.in.txt""; + String out = ""data/Dancing-large.out.txt""; + String line = null; + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(in))); + List lines = new ArrayList(); + while ((line = reader.readLine()) != null) { + lines.add(line); + } + reader.close(); + int tests = Integer.parseInt(lines.get(0)); + List res = new ArrayList(); + int k = 1; + for (int i = 1; i <= tests; i++) { + line = lines.get(k++); + String[] parts = line.split("" ""); + int n = Integer.parseInt(parts[0]); + int[] scores = new int[n]; + int s = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + for (int j = 0; j < n; j++) { + scores[j] = Integer.parseInt(parts[3+j]); + } + int result = solve(scores, s, p); + res.add(""Case #"" + i + "": "" + result); + } + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out))); + for (String re : res) { + writer.write(re); + writer.write(""\n""); + } + writer.close(); + } + + private static int solve(int[] scores, int s, int p) { + int count = 0; + int special = s; + for (int score : scores) { + if (score / 3 >= p) { + //avg. larger than p, at least one score will be >= p + count++; + } else if (score == 3*p - 1 || score == 3*p - 2) { + //these are covered by the not-special cases + count++; + } else if (special > 0) { + //try to see if a special case matches + if (score % 3 == 0) { //s-1,s,s+1 + if (score / 3 + 1 >= p && score / 3 - 1 >= 0) { + count++; + special--; + } + } else if (score % 3 == 1) {//s,s,s-2 + if ((score + 2) / 3 >= p) { + count++; + special--; + } + } else {//s,s,s+2 + if ((score - 2) / 3 + 2 >= p) { + count++; + special--; + } + } + } + } + return count; + } + +} +" +A21619,"import java.util.*; + +public class Main { + + public static void main(String args[]) { + (new Main()).solve(); + } + + void solve() { + + Scanner cin = new Scanner(System.in); + int T = cin.nextInt(); + + for(int C=1; C<=T; ++C) { + + int N = cin.nextInt(); + int S = cin.nextInt(); + int P = cin.nextInt(); + + int arr[] = new int[N]; + for(int i=0; i 10 ) { continue; } + int rest = V - k - k - d; + if( k <= rest && rest <= (k + d) ) { + int gain = (k + d >= P) ? 1 : 0; + int s = d == 2 ? 1 : 0; + dp[i + 1][j + s] = Math.max(dp[i + 1][j + s], dp[i][j] + gain); + } + } + } + } + } + + System.out.println(""Case #"" + C + "": "" + dp[N][S]); + + } + + } + +} +" +A20726,"import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class DancingWithGooglers { + + public static void main(String[] args) { + Scanner problem = new Scanner(System.in); + int T = problem.nextInt(); + for (int i = 0; i < T; i++) { + int answer = 0; + int N = problem.nextInt(); + int S = problem.nextInt(); + int p = problem.nextInt(); + List googlers = new ArrayList(); + for (int j = 0; j < N; j++) { + googlers.add(new Triplet(problem.nextInt())); + } + int possibleSurprises = 0; + for (Triplet triplet : googlers) { + if (triplet.minMax() >= p) { + answer++; + continue; + } + if (triplet.maxMax() >= p) { + possibleSurprises++; + } + } + answer += possibleSurprises >= S ? S : possibleSurprises; + System.out.println(String.format(""Case #%s: %s"", i + 1, answer)); + } + } + +} + +class Triplet { + + private int totalScore; + + public Triplet(int totalScore) { + this.totalScore = totalScore; + } + + private int min() { + return new BigDecimal(totalScore).divide(new BigDecimal(3), RoundingMode.FLOOR).intValue(); + } + + public int minMax() { + return new BigDecimal(totalScore).divide(new BigDecimal(3), RoundingMode.CEILING).intValue(); + } + + public int maxMax() { + int lalala = this.totalScore % 3; + if (lalala == 0) { + lalala = 1; + } + if (this.totalScore == 0) { + lalala = 0; + } + return this.min() + lalala; + } +} +" +A22982,"import java.io.*; +import java.util.*; +class codejam2 +{ +public static void main(String args[])throws IOException +{ +Scanner sc=new Scanner(new FileReader(""C:\\Users\\chotu\\Desktop\\B-large.in"")); + +PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(""C:\\Users\\chotu\\Desktop\\out.txt""))); + +int t=sc.nextInt(); +int n,p,x,sur,nsur,s,c; +for(int i=0;ix) +c--; +} +else if(x>=2&&x<=28) +{ +if(sur

=p && nsur0) +{ +s--; +} +else +c--; +} +} +} + +out.println(""Case #""+(i+1)+"": ""+c); +c=0; +sur=0;nsur=0; +} +out.flush(); +} +}" +A22005,"package qualif.problem2; + +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public int testCaseNb = 0; + private Scanner casesScanner; + + public DancingWithTheGooglers(Scanner input){ + + try{ + String nextLine = input.nextLine(); + testCaseNb = new Integer(nextLine); + } finally{ + + } + this.casesScanner = input; + } + + public String[] process(){ + String[] outputs = new String[testCaseNb]; + int testFound = 0; + try{ + while ( casesScanner.hasNextLine() ){ + String result = processLine( casesScanner.nextLine() ); + outputs[testFound] = result; + testFound+=1; + } + }finally{ + casesScanner.close(); + } + if(testFound==testCaseNb){ + System.out.println(""THIS WAS A SUCCESS""); + } else{ + System.out.println(""!!!! FAILURE""); + } + + return outputs; + } + + private String processLine(String line){ + String[] inputData = line.split("" ""); + + int dancersNb = new Integer(inputData[0]); + int surprizingTripletsNb = new Integer(inputData[1]); + int atLeastBestResult = new Integer(inputData[2]); + + int[] totalPointsPerDancer = new int[dancersNb]; + + for(int i = 0 ; i < dancersNb; i++){ + totalPointsPerDancer[i] = new Integer(inputData[i+3]); + } + + return findNumberOfBestDancer(surprizingTripletsNb,atLeastBestResult,totalPointsPerDancer); + } + + private String findNumberOfBestDancer(int surprizingTripletsNb, int atLeastBestResult,int[] totalPointsPerDancer){ + Integer nbOfBestResult = 0; + + int nbOfPotentialSurprize = 0; + for(int danceResult:totalPointsPerDancer){ + if(canReachBestResult(danceResult,atLeastBestResult)){ + if(isAboveBestAnyway(danceResult,atLeastBestResult)){ + nbOfBestResult+=1; + } else{ + nbOfPotentialSurprize+=1; + } + } + } + + nbOfBestResult += Math.min(nbOfPotentialSurprize,surprizingTripletsNb); + return nbOfBestResult.toString(); + } + + private boolean isAboveBestAnyway(int total, int best) { + return total>=best && total >= (best + 2*(best-1)); + } + + private boolean canReachBestResult(int total,int best){ + return total>=best && total >= (best + 2*(best-2)); + } +} +" +A21038,"package qualification; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class ProblemB { + + /** + * @param args + */ + public static String input = ""B-large.in""; + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + //Scanner in = new Scanner(System.in); + Scanner in = new Scanner(new FileReader(input)); + int t = in.nextInt(); + PrintWriter out = new PrintWriter(new FileWriter(""out"")); + for(int test = 0;test = 3*p-2){ + canHaveSurprising++; + } + else if(totalScore[i] < 3*p-2 && totalScore[i]>=3*p-4){ + if(3*p-4>=0){ + mustHaveSurprising++; + } + } + else { + notHaveSurprising++; + } + } + int result = canHaveSurprising+Math.min(mustHaveSurprising, s); + out.println(""Case #""+(test+1)+"": ""+result); + out.flush(); + } + out.close(); + } + +} +" +A22316,"package codejam.dancingwiththegooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; + +import codejam.common.AbstractProblemSolver; + +public class DancingScoresProblemSolver extends + AbstractProblemSolver { + + @Override + public DancingScores readProblem(BufferedReader reader) throws IOException { + return new DancingScores(reader.readLine()); + } + + @Override + public Integer solveProblem(DancingScores problem) { + return problem.maxNumberScoresAboveThreshold(); + } + + @Override + public void writeSolution(int solutionNumber, Integer solution, + BufferedWriter writer) throws IOException { + writer.append(""Case #"" + solutionNumber + "": ""); + writer.append(solution.toString()); + writer.newLine(); + } + + public static void main(String[] args) { + new DancingScoresProblemSolver().solve(new File( + ""D:/code/codejam/resources/dancing-input.txt""), new File( + ""D:/code/codejam/resources/dancing-output.txt"")); + } +} +" +A22504,"import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Scanner; + + +public class B { + + public static void main(String[] args) { + try { + // so eclipse can read file from system in + System.setIn(new FileInputStream(new File(""large.in""))); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + Scanner scanner = new Scanner(System.in); + long T = scanner.nextLong(); + scanner.nextLine(); + for (int i = 0; i < T; i++) { + long N = scanner.nextLong(); + long S = scanner.nextLong(); + long p = scanner.nextLong(); + long y = 0; + for (int j = 0; j < N; j++) { + long score = scanner.nextLong(); + double mean = (double)score / 3; + if (mean <= (double)p - 2) { + continue; + } else if (mean >= (double)p ) { + y++; + continue; + } + int result = test(score, p - 1); + if (result == 0) { + y++; + } else if (result == 1 && S > 0) { + y++; + S--; + } + } + System.out.printf(""Case #%d: %d%n"", i + 1, y); + } + } + + private static int test(long score, long q) { + int result = -1; + long from = q - 1; + if (from < 0) { + from = 0; + } + long to = q + 1; + if (to > 10) { + to = 10; + } + for (long a = from; a <= to; a++) { + for (long b = from; b <= to; b++) { + for (long c = from; c <= to; c++) { + if (a + b + c == score) { + if ((a == q + 1) || (b == q + 1 )|| (c == q + 1)) { + if (Math.abs(a - b) == 2 || Math.abs(a - c) == 2 || Math.abs(b - c) == 2) { + result = 1; + } else { + return 0; + } + } + + } + } + } + } + return result; + + } + +} +" +A20117,"import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; + +/** + * Date: 14/4/12 + * Time: 10:43 AM + */ +public class ProblemB { + public static void main(String[] args) throws IOException { + ArrayList al = GoogleFileStream.getInput(); + ArrayList ret = new ArrayList(); + + for( String i : al ) + ret.add( solution( i ) ); + + GoogleFileStream.setOutput(ret); + } + /* + HashMap help = new HashMap() + { + { // no surprise - surprise. + put( 30, [10,false] ); // 10, 10, 10 + put( 29, [10,false] ); // 10, 10, 9 + put( 28, [10,false] ); // 10, 9, 9 + put( 27, [9,10] ); // 9, 9, 9 - 10, 9, 8 + put( 26, [9,9] ); // 9, 9, 8 - 10, 8, 8 + put( 25, [9,9] ); // 9, 8, 8 - + put( 24, [8,9]) // 8, 8, 8 - 9, 8, 7 + put( 23, [8,9]) // 8, 8, 7 - 9, 7, 7 + put( 22, [8,9]) // 8, 7, 7 - + put( 21, [8,9]) // 7, 7, 7 - 8, 7, 6 + put( 20, [8,9]) // 7, 7, 6 - 8, 6, 6 + put( 19, [8,9]) // 7, 6, 6 - + put( 18, [8,9]) // 6, 6, 6 - 7, 6, 5 + put( 17, [8,9]) // 6, 6, 5 - 7, 5, 5 + put( 16, [8,9]) // 6, 5, 5 - + put( 15, [8,9]) // 5, 5, 5 - 6, 5, 4 + put( 14, [8,9]) // 5, 5, 4 - 6, 4, 4 + put( 13, [8,9]) // 5, 4, 4 - + put( 12, [8,9]) // 4, 4, 4 - 5, 4, 3 + put( 11, [8,9]) // 4, 4, 3 - 5, 3, 3 + put( 10, [8,9]) // 4, 3, 3 - + put( 9, [8,9]) // 3, 3, 3 - 4, 3, 2 + put( 8, [8,9]) // 3, 3, 2 - 4, 2, 2 + put( 7, [8,9]) // 3, 2, 2 - + put( 6, [8,9]) // 2, 2, 2 - 3, 2, 1 + put( 5, [8,9]) // 2, 2, 1 - 3, 1, 1 + put( 4, [8,9]) // 2, 1, 1 - + put( 3, [8,9]) // 1, 1, 1 - 2, 1, 0 + put( 2, [8,9]) // 1, 1, 0 - 2, 0, 0 + put( 1, [8,9]) // 1, 0, 0 - + put( 0, [8,9]) // 0, 0, 0 - + + + + } + }; + */ + static int minScore( int score, boolean surprise ) { + int minScore = (score + 2) / 3; + if( score > 1 && score < 28 && surprise && score % 3 != 1 ) + minScore++; + return minScore; + } + + + private static String solution(String i) { + ArrayList input = new ArrayList(Arrays.asList(i.split("" ""))); + //int numOfGooglers = Integer.valueOf( input.get(0) ); + int numOfSurprisingTriplets = Integer.valueOf( input.get(1) ); + int minScore = Integer.parseInt( input.get(2) ); + ArrayList scores = new ArrayList(); + for( String s : input.subList(3, input.size()) ) + scores.add( Integer.valueOf(s) ); + + Collections.sort(scores); + + ArrayList ret = new ArrayList(); + for( int score : scores ) + ret.add(minScore(score, false)); + + for( int ix = 0; ix < ret.size(); ix++ ) + if( ret.get(ix).equals( minScore - 1 ) + && ret.get(ix) != minScore(scores.get(ix), true) + && numOfSurprisingTriplets > 0 + ) + { + numOfSurprisingTriplets--; + ret.set(ix, ret.get(ix)+1); + } + + int count = 0; + for( int sc : ret ) + if( sc >= minScore ) + count++; + + return String.valueOf(count); + } +} +" +A20622,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package codejam2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * + * @author Albatross + */ +public class Main { + + + public static void main(String[] args) throws FileNotFoundException, IOException { + + String final_output=""""; + + try{ + FileReader input = new FileReader(""Input.txt""); + BufferedReader bufRead = new BufferedReader(input); + String line; + line = bufRead.readLine(); + int testCases = Integer.parseInt(line); + + + for (int i=0; i=Limit) + LimitPass++; + else if (remPts!=0 && minNum+1>=Limit) + LimitPass++; + else if (Surprising!=0) + { + if(remPts==2 && minNum+2>=Limit){ + LimitPass++; + Surprising--; + } + else if(remPts==0 && minNum+1>=Limit && minNum!=0){ + LimitPass++; + Surprising--; + } + } + } + final_output = final_output+""Case #""+(i+1)+"": ""+LimitPass+""\n""; + + } + bufRead.close(); + } + finally{ + + } + + FileWriter output_file = new FileWriter(""Output.txt""); + BufferedWriter bufWrite = new BufferedWriter(output_file); + try{ + + bufWrite.write(final_output); + } + finally{ + bufWrite.close(); + } + + } + +} +" +A20518,"package compete; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.Scanner; + +public class Dance { + + private static void print(String sth) { + System.out.println(sth); + } + + private static int best(int S, int P, int [] totals) { + int ret=0; + for (int i = 0;i=P*3-2 && P*3-2>0) { + ret++; + } else if (P*3-4>0 && t>=P*3-4 && S>0) { + S--; + ret++; + } + } + return ret; + } + + public static void main(String args[]) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""input.txt"")); + + int num = Integer.parseInt(in.readLine()); + + for (int i=0;i probableSurprising = new ArrayList(); + + //30„Å®29„Å®28は例外 + for(int j=0;j(){ + public int compare(Integer t1, Integer t2) { + return t2 - t1; + } + }); + for(int j=0;j= p){ + ans++; + } + + } + System.out.println(""Case #""+(i+1)+"": ""+ ans); + out.printf(""Case #%d: %s\n"", i+1, ans); + } + out.flush(); + } +} +" +A20967,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package javaapplication1; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +/** + * + * @author kutub + */ +public class dwg { + + public boolean valid(int score1,int score2,int score3,int total) + { + if(score1>=0 && score2>=0 && score3>=0 && score1+score2+score3==total) + { + return true; + } + else + return false; + } + public boolean same(int s1,int s2,int s3) + { + if(s1==s2 && s2==s3) + { + return true; + } + else + return false; + } + public boolean surprising(int score1,int score2,int score3) + { + if(Math.abs(score1-score2)==2 || Math.abs(score2-score3)==2 || Math.abs(score3-score1)==2) + { + return true; + } + else + return false; + } + public int possibilities(int [] total,int b,int sur) + { + int best=0,sc=0,score1=0,score2=0,score3=0; + for(int i=0;i=b || score2>=b || score3>=b) + { + best++; + } + else + { + if(sc=b || score2>=b || score3>=b) + { + best++; + } + else + { + sc--; + } + if(surprising(score1, score2, score3)) + { + sc++; + } + } + } + } + + } + + else + { + score1=Math.round(total[i]/3); + score2=Math.round(total[i]/3)+1; + score3=Math.round(total[i]/3)+1; + if(valid(score1, score2, score3, total[i])) + { + if(score1>=b || score2>=b || score3>=b) + { + best++; + } + else + { + if(sc=b || score2>=b || score3>=b) + { + best++; + } + else + { + sc--; + } + if(surprising(score1, score2, score3)) + { + sc++; + } + } + } + } + } + + } + } + else + { + score1=Math.round(total[i]/3); + score2=Math.round(total[i]/3); + score3=Math.round(total[i]/3); + + if(valid(score1, score2, score3, total[i])) + { + if(score1>=b || score2>=b || score3>=b) + { + best++; + } + else + { + if(sc=b || score2>=b || score3>=b) + { + best++; + } + else + { + sc--; + } + if(surprising(score1, score2, score3)) + { + sc++; + } + } + } + } + } + } + } + + return best; + + } + + + public static void main(String args[]) throws FileNotFoundException + { + File f=new File(""C:/Users/kutub/Documents/NetBeansProjects/JavaApplication1/src/javaapplication1/input1.txt""); + Scanner s=new Scanner(f); + int n=0,noofg=0,sur=0,b=0,best=0,sc=0; + int score[]; + while(s.hasNext()) + { + n=s.nextInt(); + for(int j=1;j<=n;j++) + { + s.nextLine(); + noofg=s.nextInt(); + score=new int[noofg]; + sur=s.nextInt(); + b=s.nextInt(); + for(int i=0;i= minScore) + answer++; + else if(avgValue > (minScore -1)) + answer++; + else if(usedCrazy < numCrazy && curScore>= minScore && curScore > (3*minScore-5)){ + answer++; + usedCrazy++; + } + } + System.out.println(answer); + } + } +} +" +A21007,"package fixjava; + +import java.util.Iterator; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingQueue; + +public class ParallelWorkQueue implements Iterable> { + + public interface CallableFactory { + public Callable newInstance(I input); + } + + private ExecutorService threadPool; + private LinkedBlockingQueue> workQueue; + private Future poisonPill = null; + + public ParallelWorkQueue(final int numThreads, final Iterable inputs, final CallableFactory callableFactory) { + threadPool = Executors.newFixedThreadPool(numThreads); + + // Keep a max of (100x the number of threads) items in the work queue at a time + workQueue = new LinkedBlockingQueue<>(numThreads * 100); + + // Create work-producer thread + new Thread() { + public void run() { + try { + for (final I input : inputs) + workQueue.put(threadPool.submit(callableFactory.newInstance(input))); + + // poisonPill was null until now, and null can never be put in the queue, so + // the barrier can't be triggered. Now set poisonPill to another value that it + // can only attain once, a NOP work unit. + workQueue.put(poisonPill = threadPool.submit(new Callable() { + @Override + public O call() throws Exception { + return null; + } + })); + + // Shut down threads after last callable invoked + threadPool.shutdown(); + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }; + }.start(); + + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + Future next = null; + boolean nextConsumed = true; + + @Override + public boolean hasNext() { + if (nextConsumed) { + try { + next = workQueue.take(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + nextConsumed = false; + } + // Check for poison pill + if (next == poisonPill) { + try { + // Get result of poison pill Future so thread exits + next.get(); + } catch (Exception e) { + throw new RuntimeException(e); + } + return false; // at end + } else { + return true; + } + } + + @Override + public Future next() { + if (nextConsumed) + throw new RuntimeException(""Can't call next() twice without calling hasNext()""); + nextConsumed = true; + return next; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + /** + * Return an Iterable that iterates from 0 to n-1 inclusive. Can be + * passed into the ""inputs"" parameter of ParallelWorkQueue. + */ + public static Iterable makeIntRangeIterable(final int n) { + return new Iterable() { + private final int max = n; + + @Override + public Iterator iterator() { + return new Iterator() { + int num = 0; + + @Override + public boolean hasNext() { + return num < max; + } + + @Override + public Integer next() { + return num++; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + }; + } +} + +" +A21224,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + + + +public class DanceScore { + + + String[] result = new String[9000]; + int testCases = 0; + + public static void main(String[] args)throws Exception{ + DanceScore bp = new DanceScore(); + InputVectorSequenceDance iv = InputVectorSequenceDance.readFileToCreateInputVector(true); + + bp.testCases = Integer.parseInt(iv.inp[0][0]); + + for(int n = 0 ; n < bp.testCases; n++){ + int dancer = Integer.parseInt(iv.inp[n+1][0]); + int surprise = Integer.parseInt(iv.inp[n+1][1]); + int cutoff = Integer.parseInt(iv.inp[n+1][2]); + int solution = 0; + + for(int i = 0; i < dancer; i++){ + int total = Integer.parseInt(iv.inp[n+1][3+i]); + if(total == 0){ + if(cutoff == 0)solution++; + continue; + } + int base = total /3 ; + int offset = total %3; + if(offset == 0){ + if(base >= cutoff) solution++; + else if (base+1 >= cutoff && surprise > 0){ solution++; surprise--;} + }else if(offset == 1){ + if(base >= cutoff) solution++; + else if(base+1 >= cutoff)solution++; + }else if(offset == 2){ + if(base >= cutoff) solution++; + else if(base+1 >= cutoff)solution++; + else if(base+2 >= cutoff && surprise > 0){ solution++; surprise--;} + } + + } + + bp.result[n] = ""Case #""+(n+1)+"":""+"" ""+solution; + } + + bp.outputFile(); + } + + + + + public void outputFile() throws IOException{ + FileWriter fos = new FileWriter (""C:/workspace/googleCJ/google/input/b.txt""); + BufferedWriter bw = new BufferedWriter(fos); + for(int i =0; i< testCases; i++){ + bw.write(result[i]); + bw.write(""\r\n""); + } + bw.close(); + + } + +} + +class InputVectorSequenceDance{ + private static int DATA_LENGTH = 9000; + public int lines = -1; + public String[][] inp = new String[DATA_LENGTH][]; + String[] result = new String[DATA_LENGTH]; + + private InputVectorSequenceDance(){ + + } + + public static InputVectorSequenceDance readFileToCreateInputVector(boolean splitLineBySpace) throws IOException{ + + BufferedReader br = new BufferedReader(new FileReader (""C:/workspace/googleCJ/google/input/a.txt"")); + String str = null; + InputVectorSequenceDance iv = new InputVectorSequenceDance(); + + while ((str = br.readLine()) != null) { + iv.lines++; + iv.inp[iv.lines] = process(str, splitLineBySpace); + } + + return iv; + } + + private static String[] process(String str, boolean splitLineBySpace) { + String[] ret = null; + if(splitLineBySpace){ + ret = str.split(""\\ ""); + }else{ + ret = new String[]{str}; + } + return ret; + } + + +} +" +A20838,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + + + +public class BDancingWithTheGooglers { + + static int dance(int n, int s, int p, int[] tot) { + int count = 0; + int countSurprise = 0; + int min = p + 2*Math.max(0, p - 1); + int minSurprise = p + 2*Math.max(0, p - 2); + for(int i = 0; i < n; ++i) { + if(tot[i] >= min) { + ++count; + continue; + } + if(tot[i] >= minSurprise && countSurprise < s) { + ++count; + ++countSurprise; + } + } + + return count; + } + + public static void main(String[] args) throws NumberFormatException, IOException { + String filename = ""B-large.in""; + BufferedReader r = new BufferedReader(new FileReader(filename)); + int t = Integer.parseInt(r.readLine()); + PrintWriter p = new PrintWriter(""b.out""); + for(int i = 0; i < t; ++i) { + String[] test = r.readLine().split("" ""); + int n = Integer.parseInt(test[0]); + int s = Integer.parseInt(test[1]); + int pp = Integer.parseInt(test[2]); + int[] tot = new int[n]; + for(int a = 0; a < n; ++a) { + tot[a] = Integer.parseInt(test[3 + a]); + } + int j = i + 1; + p.println(""Case #"" + j + "": "" + dance(n, s, pp, tot)); + + } + p.flush(); + p.close(); + } + +} +" +A20729,"import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class QuestionB { + + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""output.txt"")); + + int t = sc.nextInt(); // number of test cases + + for (int i = 0; i < t; i++) { + pw.print(""Case #"" + (i + 1) + "": ""); + System.out.print(""Case #"" + (i + 1) + "": ""); + int n = sc.nextInt(); // number of Googlers + int s = sc.nextInt(); // number of surprising scores + int p = sc.nextInt(); // min score for best result + + int count = 0; + for (int j = 0; j < n; j++) { + int target = sc.nextInt(); + if (target < p) + continue; + int temp = target / 3; + if (temp + temp + temp == target && temp >= p) { + count++; + continue; + } + if (temp + temp + (temp - 1) == target && temp >= p) { + count++; + continue; + } + if (temp + temp + (temp + 1) == target && temp + 1 >= p) { + count++; + continue; + } + if (temp + (temp - 1) + (temp - 1) == target && temp >= p) { + count++; + continue; + } + if (temp + (temp + 1) + (temp + 1) == target && temp + 1 >= p) { + count++; + continue; + } + if (s > 0) { + if (temp + (temp + 1) + (temp + 2) == target + && temp + 1 >= p) { + count++; + s--; + continue; + } + if (temp + (temp - 1) + (temp - 2) == target && temp >= p) { + count++; + s--; + continue; + } + if (temp + temp + (temp + 2) == target && temp + 2 >= p) { + count++; + s--; + continue; + } + if (temp + temp + (temp - 2) == target && temp >= p) { + count++; + s--; + continue; + } + if (temp + (temp + 2) + (temp + 2) == target + && temp + 2 >= p) { + count++; + s--; + continue; + } + if (temp + (temp - 2) + (temp - 2) == target && temp >= p) { + count++; + s--; + continue; + } + if (temp + (temp - 1) + (temp + 1) == target + && temp + 1 >= p) { + count++; + s--; + continue; + } + } + } + pw.print(count + ""\n""); + System.out.println(count); + } + pw.flush(); + pw.close(); + sc.close(); + } + +} +" +A20956,"import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Scanner; +import java.util.UUID; + + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws Exception { + DancingWithTheGooglers speakingInTougues = new DancingWithTheGooglers(); + // file name + String fileName = ""dancing_with_the_googlers""; + + // file variable + File inputFile = new File(fileName + "".in""); + File outputFile = new File(fileName + "".out""); + Scanner scanner = new Scanner(inputFile); + FileWriter writer = new FileWriter(outputFile); + + + // problem variable + int totalCase; + + // get total case + totalCase = Integer.parseInt(scanner.nextLine()); + //System.out.println(""Total case:""+totalCase); + //totalCase = 2; + //HashMap< String, String> dictionaryMap = speakingInTougues.constructDataDictionary(); + + for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) { + + String lineDetail = scanner.nextLine(); + String[] inputArray = lineDetail.split("" ""); + int playerAmount = Integer.parseInt( inputArray[0] ); + int surprisingCaseAmount = Integer.parseInt( inputArray[1] ); + int bestResultNo = Integer.parseInt( inputArray[2] ); + + int[] playerScores = new int[playerAmount]; + int idx = 0; + for(int pAmount = 3; pAmount<(3+playerAmount); pAmount++){ + playerScores[idx] = Integer.parseInt(inputArray[pAmount]); + idx++; + } + int maximumPossible = speakingInTougues.classfiedGoogler(playerScores, surprisingCaseAmount, bestResultNo); + String output = ""Case #"" + caseIndex + "": "" + maximumPossible; + System.out.println(output); + + writer.write(output + ""\n""); + } + + scanner.close(); + writer.close(); + } + + private int classfiedGoogler(int[] playerScores, int suprisingResultAmount, int threshold){ + int maximumPossible = 0; + int totalScore = 0; + int playerAmount = playerScores.length; + int [][] playerTableScore = new int[playerAmount*2][4]; + + int startVal = 0; + int maxNormal, maxSurprise = 0; + int minNormal = 0; + int minSurprise = 0; + List normalPassList = new ArrayList(); + List normalNoSpecialPass = new ArrayList(); + + //System.out.println(""Player Score:""+playerScores.length); + for(int i=0; i= threshold ) + { + if( minNormal >= 0){ + normalPassList.add(i); + } + }else if( maxSurprise >= threshold && maxNormal < threshold){ + if( minSurprise >= 0){ + normalNoSpecialPass.add(i); + } + } + + } + + + if(suprisingResultAmount > 0) + { + if( suprisingResultAmount >= normalNoSpecialPass.size()) + { + maximumPossible += normalNoSpecialPass.size(); + }else{ + maximumPossible += suprisingResultAmount; + } + } + maximumPossible += normalPassList.size(); + + return maximumPossible; + + } + + +} +" +A22643,"public class main { + + + /** + * @param args + */ + public static void main(String[] args) { + + // TODO Auto-generated method stub + + //Texter.writeFile(); + + + + Texter.setupReader(); + Logic.solve(); + + } + +} +" +A21507,"package dancingwiththegooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + + +public class Input { + static String path = ""B-small-attempt0.in""; + + public String getPath() { + return path; + } + public Input(String path){ + this.path = path; + } + public static void main(String[] str) { + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(path); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + // Read File Line By Line + int lineNumber = 0; + String strTestCase = """"; + List lstpattern = null; + Writer output = null; + + File file = new File(""out.txt""); + output = new BufferedWriter(new FileWriter(file)); + while ((strLine = br.readLine()) != null) { + // Print the content on the console + lineNumber++; + if(lineNumber == 1){continue;} + + output.write(""Case #"" +(lineNumber-1)+ "": "" + setValues(strLine) + ""\n""); + } + output.close(); + // Close the input stream + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + } + private static int setValues(String strLine) { + int numberofPlayers = 0; + int bestScore = 0; + int surpriseScores = 0; + List scores = new ArrayList(); + String[] arr = strLine.split("" ""); + for(int i = 0; i < arr.length; i++){ + switch (i) { + case 0: + numberofPlayers = Integer.parseInt(arr[i]); + break; + case 1: + surpriseScores = Integer.parseInt(arr[i]); + break; + case 2: + bestScore = Integer.parseInt(arr[i]); + break; + default: + scores.add(Integer.parseInt(arr[i])); + break; + } + } + TestCase tc = new TestCase(numberofPlayers, surpriseScores, bestScore, scores); + return tc.execute(); + } + +} +" +A20373,"package sholay; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * GoogleDancers + */ +public class GoogleDancers { + + public static String INPUT_FILE_NAME = ""B-large.in""; + public static String OUTPUT_FILE_NAME = ""B-large.out""; + + class Player implements Comparable { + + int totalScore; + int x; + int y; + int z; + int thresholdScore; + boolean isSurprise; + boolean isMax; + + /** + * @param totalScore + * @param thresholdScore + * @param x + * @param y + * @param z + */ + Player(int totalScore, int thresholdScore, int x, int y, int z) { + this.totalScore = totalScore; + this.thresholdScore = thresholdScore; + this.x = x; + this.y = y; + this.z = z; + isSurprise = (Math.abs(x - y) >= 2d || Math.abs(y - z) >= 2d || Math + .abs(x - z) >= 2d); + isMax = (x >= thresholdScore) || (y >= thresholdScore) + || (z >= thresholdScore); + } + + @Override + public int compareTo(Player arg0) { + return (isMax && !isSurprise) ? 1 + : ((isMax && isSurprise) ? 0 : -1); + } + } + + // + Map> map = new HashMap>(); + + /** + * Read the input file, decode the input and write the output file + * + * @throws IOException + */ + public void solve() throws IOException { + BufferedReader in = null; + PrintWriter out = null; + try { + in = new BufferedReader(new FileReader(getFile(INPUT_FILE_NAME))); + out = new PrintWriter(new FileWriter(OUTPUT_FILE_NAME)); + String line = null; + int lineNum = 0; + int numTestCase = 0; + int count = 0; + while ((line = in.readLine()) != null) { + if (lineNum >= 0) { + if (lineNum == 0) { + numTestCase = Integer.parseInt(line); + } else { + count++; + if (count <= numTestCase) { + int solution = getMaxBestResult(line); + out.write(""Case #"" + count + "": "" + solution); + if (count != numTestCase) { + out.write(""\n""); + } + } else { + break; + } + } + } + lineNum++; + } + + } catch (Exception ex) { + System.out.println(""Program failed :"" + ex.getMessage()); + } finally { + in.close(); + out.close(); + } + } + + /** + * @param line + * @return + */ + private int getMaxBestResult(String line) { + map.clear(); + String[] lineArray = line.split("" ""); + int totalPlayers = Integer.parseInt(lineArray[0]); + if (totalPlayers > 0) { + int surprise = Integer.parseInt(lineArray[1]); + int threshold = Integer.parseInt(lineArray[2]); + for (int i = 0; i < totalPlayers; i++) { + List players = getPossiblePlayers(surprise, threshold, + Integer.parseInt(lineArray[3 + i])); + map.put(i, players); + } + return findMaxBest(surprise, map); + } + return 0; + } + + /** + * @param surprise + * @param map + * @return + */ + private int findMaxBest(int surprise, Map> map) { + int maxBest = 0; + Set players = map.keySet(); + for (Integer player : players) { + List possibility = map.get(player); + Player p = getPlayer(surprise, possibility); + if (p != null) { + if (p.isMax) { + maxBest++; + } + if (p.isSurprise) { + surprise--; + } + } + } + return maxBest; + } + + /** + * @param surprise + * @param possibility + * @return + */ + private Player getPlayer(int surprise, List possibility) { + Player pp = null; + Collections.sort(possibility,Collections.reverseOrder()); + for (Player p : possibility) { + if (p.isMax && !p.isSurprise) { + pp = p; + break; + } + } + if (pp == null) { + for (Player p : possibility) { + if (p.isMax && p.isSurprise && surprise > 0) { + pp = p; + break; + } + } + } + if (pp == null) { + for (Player p : possibility) { + if (!p.isSurprise && surprise <= 0) { + pp = p; + break; + } + } + } + if (pp == null) { + for (Player p : possibility) { + if (!p.isSurprise) { + pp = p; + break; + } + } + } + return pp; + } + + /** + * @param surprise + * @param threshold + * @param i + * @return + */ + private List getPossiblePlayers(int surprise, int threshold, + int totalScore) { + List players = new ArrayList(); + // + if ((totalScore) % 3 == 0) { + int div = (totalScore) / 3; + if(div>=0) { + players.add(new Player(totalScore, threshold, div, div, div)); + } + } + // + if ((totalScore - 1) % 3 == 0) { + int div = (totalScore - 1) / 3; + if(div>=0){ + players.add(new Player(totalScore, threshold, div, div, div + 1)); + } + } + // + if ((totalScore - 2) % 3 == 0) { + int div = (totalScore - 2) / 3; + if(div>=0) { + players.add(new Player(totalScore, threshold, div, div + 1, div + 1)); + players.add(new Player(totalScore, threshold, div, div, div + 2)); + } + } + // + if ((totalScore - 3) % 3 == 0) { + int div = (totalScore - 3) / 3; + if(div>=0) { + players.add(new Player(totalScore, threshold, div, div + 1, div + 2)); + } + } + // + if ((totalScore - 4) % 3 == 0) { + int div = (totalScore - 4) / 3; + if(div>=0) { + players.add(new Player(totalScore, threshold, div, div + 2, div + 2)); + } + } + return players; + } + + /** + * @param fileName + * @return + */ + public static File getFile(String fileName) { + return new File(fileName); + } + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + GoogleDancers googleDancers = new GoogleDancers(); + googleDancers.solve(); + } + +} +" +A20154,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + + +public class DancingWithGooglers { + + public static void main(String[] args) { + PrintStream theOut=null; + try { + FileOutputStream o = new FileOutputStream(""./output.txt"", false); + theOut = new PrintStream(o); + } + catch (Exception e) { + e.printStackTrace(); + return; + } + + + Scanner sc=null; + try { + //sc = new Scanner(new File(""./A-small.in"")); + sc = new Scanner(new File(""/home/duck/Downloads/B-large.in"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + int NbGooglers; + int max; + int surprising; + int nbCases = sc.nextInt(); + + mainloop: for(int curCase=1; curCase <= nbCases ;++curCase) { + sc.nextLine(); + NbGooglers = sc.nextInt(); + surprising = sc.nextInt(); + max = sc.nextInt(); + int res=0; + for (int i = 0; i < NbGooglers; i++) { + int tot = sc.nextInt(); + if(tot%3 == 0) { + if(tot/3 >= max) {res++;continue;} + if(tot/3+1 >= max && tot >= 3 && surprising >0) {res++;surprising--;continue;} + } + else if (tot%3 == 1) { + if(tot/3+1>= max) res++; + } + else if (tot%3 == 2) { + if(tot/3+1 >= max) {res++;continue;} + if(tot/3+2 >= max && surprising >0) {res++;surprising--;continue;} + } + } + + + /*******************************************************************/ + theOut.format(""Case #%d: %d\n"",curCase,res); + System.out.format(""Case #%d: %d\n"",curCase,res); + + + + + + } + + } +} +" +A20172,"import java.util.*; +import java.io.*; + +public class B +{ + public static int test (int i, int target) + { + int n = i/3; + + if (i == 0) + { + if (target == 0) return 1; + return 0; + } + if (i == 1) + { + if (target <= 1) return 1; + return 0; + } + + if (i == 2) + { + if (target <= 1) return 1; + if (target <= 2) return 2; + return 0; + } + + + if (n >= (target - (i%3 == 0 ? 0 : 1))) + return 1; + + if (n >= (target - (i%3 == 2 ? 2 : 1))) + return 2; + + return 0; + } + + public static void main(String... args) throws Exception + { + BufferedReader in = new BufferedReader (new FileReader( ""B-large.in"" )); + + String line; + in.readLine(); + int casenum = 1; + + String[] nums; + while ( (line = in.readLine()) != null) + { + nums = line.split("" ""); + + int target = Integer.valueOf(nums[2]); + int surprising = Integer.valueOf(nums[1]); + + int a = 0, b = 0; + + for (int i = 3; i < nums.length; i++) + { + //System.out.println( ""DEBUG: "" + nums[i] + "" -> "" + test(Integer.valueOf(nums[i]),target)); + switch (test(Integer.valueOf(nums[i]),target)) + { + case 0: break; + case 1: a++; break; + case 2: b++; break; + } + } + int result = a + Math.min(b,surprising); + System.out.println(""Case #"" + casenum + "": "" + result); + casenum++; + } + } +}" +A22104,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancewithgoogle; + +import java.util.*; +import java.io.*; + + +/** + * + * @author Aaron + */ +public class DanceWithGoogle { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + + //only 3x+2, 3x can be suprise + try + { + + File file = new File (""input.txt""); + + PrintWriter pw = new PrintWriter (new FileWriter (""output.txt"")); + + if (file.exists ()) + { + FileReader f_rd = new FileReader (file); + LineNumberReader l_rd = new LineNumberReader(f_rd); + String input_s; + + + + input_s = l_rd.readLine(); + int num_case; + + if (input_s!= null) + { + num_case = Integer.parseInt (input_s); + } else + { + throw new IllegalArgumentException(""Invalid Input File""); + } + + + for (int i = 0; i< num_case;i++) + { + //for each test case + input_s = l_rd.readLine(); + String[] values = input_s.split("" ""); + int num_goolge; + int num_s; + int num_p; + int result = 0; + + num_goolge = Integer.parseInt(values[0]); + num_s = Integer.parseInt(values[1]); + num_p = Integer.parseInt(values[2]); + + for ( int j = 0; j < num_goolge; j++) + { + int total = Integer.parseInt(values[3+j]); + + int tmp = total%3; + if (tmp == 0 ) + { + //3x, max without using suprise is X + if ( total/3 >= num_p) + result++; + else + { + if (num_s>0) + { + //special case for 0 + + if (total/3 > 0) + { + if (total/3 + 1 >= num_p) + { + num_s--; + result++; + } + } + } + } + } + else + { + if ( tmp == 1) + { + if ( total/3 + 1 >= num_p) + result++; + } + if (tmp == 2) + { + //3x, max without using suprise is X + if ( total/3 + 1 >= num_p) + result++; + else + { + if (num_s>0) + { + if (total/3 + 2 >= num_p) + { + num_s--; + result++; + } + } + } + } + } + } + pw.println (""Case #""+ (i+1)+"": "" + result); + } + pw.close(); + + l_rd.close (); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + + } +} +" +A22352,"package codejam.qual_2012; + +import java.io.File; +import java.io.PrintStream; +import java.util.Scanner; + +public class MainB { + + public static void main(String[] args) throws Exception { + + String f = ""/home/floris/dev/java/Test/src/codejam/qual_2012/B-large.in""; + Scanner sc = new Scanner(new File(f)); + System.setOut(new PrintStream(new File(f+"".out""))); + int T = sc.nextInt(); + for (int i=1; T-- > 0; i++) { + int numberOfGooglers = sc.nextInt(); + int numberOfSurprises = sc.nextInt(); + int p = sc.nextInt(); + int[] values = new int[numberOfGooglers]; + for (int j = 0; j < numberOfGooglers; j++) { + values[j] = sc.nextInt(); + } + + System.out.printf(""Case #%d: %d%n"", i, solve(numberOfGooglers, numberOfSurprises, p, values)); + } + } + + private static int solve(int numberOfGooglers, int numberOfSurprises, int p, int[] values) { + int result = 0; + for (int v : values) { + int d = v % 3; + if (v == 0) { + if (p==0) result++; + } else if (v == 1) { + if (p<=1) result++; + } else if (d == 0) { + if (v/3 >= p) result++; + else if (numberOfSurprises>0 && (v/3+1)>=p) {result++; numberOfSurprises--;} + } else if (d==1) { + if (v/3+1 >= p) result++; + } else if (d==2) { + if (v/3+1 >= p) result++; + else if (numberOfSurprises>0 && (v/3+2)>=p) {result++; numberOfSurprises--;} + } + } + return result; + } +} +" +A21125,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancinggooglers; + +import java.io.*; + +/** + * + * @author Oscar + */ +public class DancingGooglers { + + public static String resolver(String[] parametros) { + int num = Integer.parseInt(parametros[0]); + int especial = Integer.parseInt(parametros[1]); + int objetivo = Integer.parseInt(parametros[2]); + if(objetivo == 0) + return Integer.toString(num); + int min_1 = objetivo * 3 - 2; + int min_2 = objetivo * 3 - 4; + if(objetivo == 1) + min_2 = 1; + int encontrados = 0; + for(int i = 0; i < num; i++) { + int actual = Integer.parseInt(parametros[3 + i]); + if(actual >= min_1) { + encontrados++; + continue; + } + if(actual >= min_2 && especial > 0) { + especial--; + encontrados++; + } + } + return Integer.toString(encontrados); + } + public static void main(String[] args) throws Exception { + System.out.println(""?""); + BufferedReader lector = new BufferedReader(new InputStreamReader(System.in)); + String tipo = lector.readLine().trim(); + BufferedReader entrada = new BufferedReader(new InputStreamReader(new FileInputStream(tipo + "".in""))); + BufferedWriter salida = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tipo + "".out""))); + int casos = Integer.parseInt(entrada.readLine()); + int contador = 1; + while(casos > 0) { + String[] parametros = entrada.readLine().split("" ""); + salida.write(""Case #"" + contador + "": "" + resolver(parametros) + ""\n""); + contador++; + casos--; + } + salida.close(); + System.out.println(""Fin""); + } +} +" +A21052,"import java.util.*; +import java.io.*; + +public class B { + + public static void main(String[] args) throws IOException { + + Scanner in = new Scanner(new File(""B-large.in"")); + FileWriter fw = new FileWriter(""B-large.out""); + int T = in.nextInt(); + + for (int cases = 1; cases <= T; cases++){ + + // read parameters for this case + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + + // read the data to an array point + int[] point = new int[N]; + fw.write(""Case #"" + cases + "": ""); + for (int i = 0; i < N; i++){ + point[i] = in.nextInt(); + } + + // quicksort the array point + QuickSort result = new QuickSort(point); + result.sort(); + + /* this is used to test + for (int i = 0; i < N; i++){ + fw.write("" "" + point[i]); + } + */ + + // this part is to get the number for this case + + int number = N - 1; + for (int i = N - 1; i >= 0 && point[i] >= 3 * P - 2; i--){ + number = i - 1; + } + // fw.write(""\nP is "" + P +"" Number is "" + number + "" ""); + + int total = N - 1 - number; + + // this part is to inclusice the S + for (int j = 0; j < S && j <= number && point[number - j] >= 3 * P - 4 && point[number - j] >= 2; j++) { + total = N - 1 - number + j +1; + } + fw.write(total + ""\n""); + + } + fw.flush(); + fw.close(); + } +} + +// this is the quicksork +class QuickSort { + private int[] a; + + public QuickSort(int[] anArray){ + a = anArray; + } + + public void sort(){ + sort(0, a.length - 1); + } + + public void sort(int low, int high){ + if (low >= high) return; + int p = partition(low, high); + sort(low, p); + sort(p + 1, high); + } + + private int partition(int low, int high){ + // First element + int pivot = a[low]; + int i = low - 1; + int j = high + 1; + while (i < j) { + i++; while (a[i] < pivot) i++; + j--; while (a[j] > pivot) j--; + if (i < j) swap(i, j); + } + return j; + } + + /** + Swaps two entries of the array. + @param i the first position to swap + @param j the second position to swap + */ + private void swap(int i, int j){ + int temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } +} + " +A20329,"import java.io.*; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class B implements Runnable { + private static BufferedReader reader; + private static StreamTokenizer st; + private static PrintWriter writer; + + public static void main(String[] args) { + new Thread(new B()).start(); + } + + @Override + public void run() { + try { + solve(); + } catch (IOException e) {} + } + + private void solve() throws IOException { + reader = new BufferedReader(new FileReader(""b.in"")); + st = new StreamTokenizer(reader); + writer = new PrintWriter(new FileWriter(""b.out"")); + + int n = nextInt(); + for (int i = 1; i <= n; i++) { + int temp = countAns(); + writer.println(""Case #"" + i + "": "" + temp); + } + + reader.close(); + writer.close(); + } + + static String nextToken() throws IOException { + st.nextToken(); + return st.sval; + } + + static int nextInt() throws NumberFormatException, IOException { + st.nextToken(); + return (int)st.nval; + } + + private static int countAns() throws IOException{ + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + //writer.print(String.valueOf(n) + "" "" + String.valueOf(s) + "" "" + String.valueOf(p) + "" ""); + + ArrayList num = new ArrayList(n); + int nonSurprisingNum = 0; + for (int i = 0; i < n; i++) { + int temp = nextInt(); + //writer.print(String.valueOf(temp) + "" ""); + num.add(temp); + } + + if (p == 0) return n; + + int nonSurprisingFrame = p + 2 * (p - 1); + for (int i = 0; i < num.size(); i++) { + int curNum = num.get(i); + if (curNum >= nonSurprisingFrame) { + nonSurprisingNum++; + num.remove(i); + i--; + } + } + if (s == 0) return nonSurprisingNum; + + int surprisingFrame = Math.max(0, p + 2 * (p - 2)); + int len = num.size(); + int cnt = 0; + while (s > 0 && cnt < len) { + int curNum = num.get(cnt); + if (curNum > 0 && curNum >= surprisingFrame) { + s--; + nonSurprisingNum++; + } + cnt++; + } + + return nonSurprisingNum; + } + +}" +A20205,"package com.code.jam; + +import java.io.File; +import java.io.PrintStream; +import java.util.Scanner; + +public class BDancingWithGooglers { + public static void main(String[] args) throws Exception { + Scanner in = new Scanner (new File(""C:/codeJam/ficheros2012/BDancingWithGooglers-practice.in"")); + PrintStream ps = new PrintStream(""C:/codeJam/ficheros2012/BDancingWithGooglers-practice.out""); + int T = new Integer (in.nextLine()); + for (int nCase = 1; nCase < T + 1; nCase++) { + Scanner inLine = new Scanner(in.nextLine()); + int numberGooglers = inLine.nextInt(); + int surprisingScore = inLine.nextInt(); + int p = inLine.nextInt(); + int maxGooglersWithScoreX = 0; + for (int i = 0; i < numberGooglers; i++) { + int scoreGoogler = inLine.nextInt(); + int desviationScore = scoreGoogler % 3; + int maxScore = (scoreGoogler - desviationScore) / 3; + + if (desviationScore > 0){ + maxScore++; + } + + if (maxScore >= p){ + maxGooglersWithScoreX++; + } + else{ + if (scoreGoogler >= p + && surprisingScore > 0 + && maxScore + 1 >= p){ + maxGooglersWithScoreX++; + surprisingScore--; + } + } + } + System.out.format(""Case #%d: %d\n"", nCase, maxGooglersWithScoreX); + ps.format(""Case #%d: %d\n"", nCase, maxGooglersWithScoreX); + } + ps.flush(); + ps.close(); + } +} +" +A22342,"import java.util.*; +import java.io.*; + +public class DancingGooglers { + + public static void main(String[] args){ + Scanner in = new Scanner(System.in); + int count = in.nextInt(); + //in.nextLine(); + for(int i=0;ip-1){ + //System.out.println(""case 1""); + max++; + } + else if(score/3 == p-1 && s!=0){ + if(!(score==0 && p==1)) + { + s--; + max++; + //System.out.println(""case 2""); + } + } + else if(avg>p-2 && avg > resultMap; + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length == 1) { + String fileName = args[0]; + ProblemTwo problemOne = new ProblemTwo(); + try { + problemOne.solveFile(fileName); + } catch (FileNotFoundException fnf) { + System.out.println(""File not found!""); + System.out.println(fnf.getMessage()); + } catch (IOException e) { + System.out.println(""Could not read file!""); + } + } else { + System.out.println(""Need 1 argument!""); + } + } + + private void solveFile(String fileName) throws IOException { + fillResultMap(); + StringBuilder output = new StringBuilder(); + File file = new File(fileName); + FileReader fileReader = new FileReader(file); + BufferedReader reader = new BufferedReader(fileReader); + String numberOfCasesString = reader.readLine(); + int numberOfCases = Integer.parseInt(numberOfCasesString); + for (int i = 1; i <= numberOfCases; i++) { + output.append(""Case #"" + i + "": ""); + output.append(solveLine(reader.readLine())); + output.append(""\r\n""); + } + //output.append(results.size()); + FileWriter writer = new FileWriter(fileName.replace("".in"", "".out"")); + writer.write(output.toString()); + writer.close(); + } + + private String solveLine(String lineToBeSolved) { + int result = 0; + String[] parts = lineToBeSolved.split("" ""); + int numberOfCandidates = Integer.parseInt(parts[0]); + int surprisingScores = Integer.parseInt(parts[1]); + int scoredAtLeast = Integer.parseInt(parts[2]); + Map findMap = resultMap.get(scoredAtLeast); + for (int i = 3; i < numberOfCandidates + 3; i++) { + if (findMap.get(Integer.parseInt(parts[i])) == Result.POSSIBLE) { + result++; + } else if (surprisingScores > 0 && findMap.get(Integer.parseInt(parts[i])) == Result.POSSIBLE_SURPRISING) { + result++; + surprisingScores--; + } + } + return """" + result; + } + + private void fillResultMap() { + this.resultMap = new HashMap<>(); + for (int i = 0; i <= 10; i++) { + Map scoreResults = new HashMap<>(); + for (int j = 0; j <=30;j++) { + scoreResults.put(j, calculateResult(j, i)); + } + resultMap.put(i, scoreResults); + } + } + + private Result calculateResult(int googlerScore, int scoredAtLeast) { + Result res = Result.NOT_POSSIBLE; + int scoredAtLeastMin1 = scoredAtLeast - 1 >= 0? scoredAtLeast - 1 : 0; + int scoredAtLeastMin2 = scoredAtLeast - 2 >= 0? scoredAtLeast - 2 : scoredAtLeastMin1; + if (googlerScore >= scoredAtLeast + scoredAtLeastMin1 + scoredAtLeastMin1) { + res = Result.POSSIBLE; + } else if (googlerScore >= scoredAtLeast + scoredAtLeastMin2 + scoredAtLeastMin2) { + res = Result.POSSIBLE_SURPRISING; + } + return res; + } + +} + + +" +A20715,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.ArrayList; + +public class Dancing { + /** + * @param args + */ + public static void main(String[] args) { + new Dancing(); + } + + public Dancing () + { + solve(); + } + + /** + * Solves Problem A. Speaking in Tongues + */ + private void solve() { + try { + File f = new File(""./in.txt""); + File output = new File(""./p.dat""); + + if (output.exists()) + output.delete(); + + output.createNewFile(); + + PrintWriter pw = new PrintWriter(output); + FileReader fr = new FileReader(f); + BufferedReader br = new BufferedReader(fr); + + String linea = br.readLine(); + linea = br.readLine(); + + ArrayList ps = new ArrayList(); + ArrayList ss = new ArrayList(); + + ArrayList> ts = new ArrayList>(); + + while (linea != null) { + String [] instancia = linea.split("" ""); + int n = Integer.parseInt(instancia[0]); + int s = Integer.parseInt(instancia[1]); + int p = Integer.parseInt(instancia[2]); + ArrayList temp = new ArrayList(); + + ps.add(p); + ss.add(s); + + for(int i=3;i<3+n;i++) + { + int t = Integer.parseInt(instancia[i]); + temp.add(t); + } + ts.add(temp); + + linea = br.readLine(); + + } + + br.close(); + fr.close(); + pw.println(""maxscore:[""); + for(int i=0;i scores = ts.get(i); + for(int j=0;j ""); + String s = in.next(); + return new File(s); + } + + public static void decodeAndWrite (File f) + { + Scanner inf = null; + PrintWriter outf = null; + + try + { + inf = new Scanner(f); + outf = new PrintWriter(new File(""dancing_results.txt"")); + } + catch (FileNotFoundException e) + { + System.err.println(""That is not a valid filename. Please re-run the program with a valid filename""); + System.exit(1); + } + + int T = inf.nextInt(), N = 0, S = 0, p = 0, ti = 0, count = 0, scount = 0; + + for (int i = 1; i <= T; i++) + { + scount = count = 0; + N = inf.nextInt(); + S = inf.nextInt(); + p = inf.nextInt(); + for (int j = 0; j < N; j++) + { + ti = inf.nextInt(); + if (ti >= (3 * p) - 2) + count++; + else if ((3 * p) - 4 >= 0 && ti >= (3 * p) - 4 && scount < S) + scount++; + } + count += scount; + System.out.println(""Case #"" + i + "": "" + count); + outf.println(""Case #"" + i + "": "" + count); + } + + inf.close(); + outf.close(); + } +} + +" +A21037,"import java.util.Scanner; + + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + new B(); + } + + int[] notSurprising; + int[] surprising; + + public B() + { + notSurprising = new int[31]; + surprising = new int[31]; + + for(int i = 2; i <= 30; ++i) + { + notSurprising[i] = i / 3 + (i % 3 == 0 ? 0 : 1); + surprising[i] = i / 3 + (i % 3 == 2 ? 2 : 1); + } + + Scanner sc = new Scanner(System.in); + + int testCases = sc.nextInt(); + + for(int testCase = 1; testCase <= testCases; ++testCase) + { + int N = sc.nextInt(); + int S = sc.nextInt(); + + int p = sc.nextInt(); + + int result = 0; + + for(int googler = 0; googler < N; ++googler) + { + int score = sc.nextInt(); + + if(notSurprising[score] >= p) + { + result++; + } + else if(S > 0 && surprising[score] >= p) + { + result++; + S--; + } + } + + System.out.printf(""Case #%d: %d\n"", testCase, result); + } + } +} +" +A20226,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; + + +public class Dancing +{ + public int specials = 0; + + public int p = 0; + + public static void main(String[] args) throws NumberFormatException, IOException + { + BufferedReader stdin = new BufferedReader + (new InputStreamReader(System.in)); + int n = Integer.parseInt(stdin.readLine()); + int j = 0; + + while(j=dancing.p) + return 1; + return 0; + } + if(t % 3 == 0) + { + k = t/3; + if(k>= dancing.p) + return 1; + if(dancing.specials>0) + { + if(k+1>=dancing.p) + { + dancing.specials--; + return 1; + } + } + } + if( (t-2) % 3 == 0) + { + k =(t-2)/3; + if(k+1>= dancing.p) + { + return 1; + } + if(dancing.specials>0) + { + if(k+2>=dancing.p) + { + dancing.specials--; + return 1; + } + } + } + } + return 0; + } +} +" +A22753," +//package b; + + +import java.io.*; +import java.util.*; +public class Main { + static int[] good = {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; + static int[] bad = {0,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,10,10}; + public static void main(String[] args) throws IOException{ + BufferedReader in = new BufferedReader(new FileReader(""B.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B.out""))); + int T = Integer.parseInt(in.readLine()); + for(int C = 1; C <= T; C++) doit(C, in, out); + in.close(); + out.close(); + System.exit(0); + } + + private static void doit(int C, BufferedReader in, PrintWriter out) throws IOException{ + StringTokenizer tok = new StringTokenizer(in.readLine()); + int N = Integer.parseInt(tok.nextToken()); + int surprise = Integer.parseInt(tok.nextToken()); + int P = Integer.parseInt(tok.nextToken()); + + int[] num = new int[N]; + for(int i = 0; i < N; i++) num[i] = Integer.parseInt(tok.nextToken()); + + //SOLUTION + Arrays.sort(num); + int ans = 0; + int countSurprise = 0; + + for(int i = 0; i < N; i++){ + if(num[i] >= 2 && num[i] < 28 && good[num[i]] != bad[num[i]] && countSurprise < surprise){ + if(bad[num[i]] >= P) { + ans++; + countSurprise++; + } + } + else if(good[num[i]] >= P) ans++; + } + + out.println(""Case #"" + C + "": "" + ans); + } +} +" +A21423,"package duyonggang; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +public class DancingWithGooglers { + + public static int analyze(String line) + { + // parse + String[] strs = line.split("" ""); + + int count = Integer.parseInt(strs[0]); + int surprisingNum = Integer.parseInt(strs[1]); + int p = Integer.parseInt(strs[2]); + int[] data = new int[count]; + + // analyze + int commonCounter = 0; + int surprisingCounter = 0; + for(int i = 0; i < count; i++) + { + data[i] = Integer.parseInt(strs[3 + i]); + + if((data[i] > 1 && data[i] >= (3 * p - 2)) || (data[i] == 0 && p == 0) || (data[i] == 1 && p <= 1)) + commonCounter++; + else if(data[i] > 1 && data[i] >= (3 * p -4)) + surprisingCounter++; + } + return commonCounter + + (surprisingCounter > surprisingNum ? surprisingNum : surprisingCounter); + } + + public static void main(String[] args) throws Exception + { + File input = new File(""b.txt""); + FileReader fr = new FileReader(input); + BufferedReader br = new BufferedReader(fr); + String line = null; + line = br.readLine(); + int count = Integer.parseInt(line); + for(int i = 0; i < count; i++) + { + line = br.readLine(); + System.out.println(""Case #"" + (i + 1) + "": "" + DancingWithGooglers.analyze(line)); + } + } +} +" +A22318,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + private int maxNonSurprise(int v) { + switch (v % 3) { + case 0: return v / 3; + case 1: + case 2: return v / 3 + 1; + default: throw new AssertionError(); + } + } + + private int maxSurprise(int v) { + if (v <= 2) { + return v; + } + switch (v % 3) { + case 0: + case 1: return v / 3 + 1; + case 2: return v / 3 + 2; + default: throw new AssertionError(); + } + } + + public void run(Scanner in, PrintWriter out, int nCase) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int alreadyP = 0; + int potentialP = 0; + for (int i = 0; i < n; ++i) { + int v = in.nextInt(); + if (maxNonSurprise(v) >= p) { + ++alreadyP; + } else { + if (maxSurprise(v) >= p) { + ++potentialP; + } + } + } + int ans = alreadyP + Math.min(s, potentialP); + out.printf(""Case #%d: %d%n"", nCase, ans); + } + + public static void main(String[] args) throws FileNotFoundException { + String filename = B.class.getSimpleName().toLowerCase(); + + Scanner in = new Scanner(new File(filename + "".in"")); + PrintWriter out = new PrintWriter(filename + "".out""); + + int nCases = in.nextInt(); + + for (int i = 1; i <= nCases; ++i) { + new B().run(in, out, i); + } + + out.close(); + in.close(); + } +} +" +A22336,"package at.neiti.codejam2012; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + BufferedReader r = new BufferedReader(new FileReader(""B-large.in"")); + int n = Integer.parseInt(r.readLine()); + + StringBuilder output = new StringBuilder(); + for(int i=0; i p not surprising + int bestNotSurprising = total/3 + (total%3 != 0 ? 1 : 0); + if(bestNotSurprising >= p) { + googlersGreaterP++; + continue; + } + + //See if Googler points are > p surprising + if(surprising > 0) { + int add = 0; + if(total%3 == 0) { + add = 1; + } else if(total%3 == 2) { + add = 2; + } + int bestSurprising = total == 0 ? 0 : total/3 + add; + if(bestSurprising >= p) { + googlersGreaterP++; + surprising--; + } + } + } + + line += googlersGreaterP + ""\n""; + output.append(line); + } + + r.close(); + + FileWriter fw = new FileWriter(""output_dancing.txt""); + fw.write(output.toString()); + fw.flush(); + fw.close(); + } + +} + +" +A21172,"package codejam2012; + +import java.io.File; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static int testGoal(int value, int goal) { + int modResult = value % 3; + int divResult = value / 3; + /* + * x%3=0:(NS)x/3,(S)x/3+1;x%3=1:(NS)x/3+1,(S)x/3+1;x%3=2:(NS)x/3+1,(S)x/3 + * +2; + */ + int nonSurpriseMax = (modResult == 0) ? divResult : (divResult + 1); + int surpriseMax = (modResult <= 1) ? (divResult + 1) : (divResult + 2); + surpriseMax = Math.min(10, surpriseMax); + // some special checking + if (value <= 1) { + // no surprise + surpriseMax = 0; + } + int goalResult = 0; + if (nonSurpriseMax >= goal) + goalResult++; + if (surpriseMax >= goal) + goalResult++; + System.out.println(value + "" : "" + goalResult); + return goalResult; + } + + public static int eval(int supprise, int goal, int[] scores) { + System.out.println(""=== G:"" + goal + "" S:"" + supprise + "" - "" + + Arrays.toString(scores)); + int[] goalTesting = new int[3]; + for (int score : scores) { + goalTesting[testGoal(score, goal)]++; + } + System.out.println(""--- "" + Arrays.toString(goalTesting) + "" => "" + + (goalTesting[2] + Math.min(supprise, goalTesting[1]))); + return goalTesting[2] + Math.min(supprise, goalTesting[1]); + } + + public static void main(String[] args) throws Exception { + PrintWriter output = new PrintWriter(""output2.txt""); + Scanner scanner = new Scanner(new File(""input2.txt"")); + try { + int input_T = scanner.nextInt(); + for (int i = 0; i < input_T; i++) { + int input_N = scanner.nextInt(); + int input_S = scanner.nextInt(); + int input_p = scanner.nextInt(); + int[] scores = new int[input_N]; + for (int j = 0; j < input_N; j++) { + scores[j] = scanner.nextInt(); + } + output.printf(""Case #%d: %d\n"", i + 1, + eval(input_S, input_p, scores)); + } + } finally { + output.close(); + scanner.close(); + } + } + +} +" +A21391,"package de.hg.codejam.tasks.dance.help; + +public abstract class Converter { + + public static String[] convert(int[] input) { + String[] output = new String[input.length]; + + for (int i = 0; i < input.length; i++) + output[i] = String.valueOf(input[i]); + + return output; + } + +} +" +A22399,"import java.util.*; +public class Dance { + public static void main (String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for(int t = 1; t <= T; t++) { + int num = 0, ptp = 0; + int n = sc.nextInt(), S = sc.nextInt(), p = sc.nextInt(); + for(int i = 0; i < n; i++) { + int score = sc.nextInt(); + int k = score / 3, r = score % 3; + if(r == 1) {if(k + 1 >= p) num++;} + else if(r == 2) {if(k + 1 >= p) num++; else if(k == p - 2) ptp++;} + else {if(k >= p) num++; else if(k == p - 1 && k != 0) ptp++;} + } + System.out.println(""Case #"" + t + "": "" + (Math.min(ptp, S) + num)); + } + } +}" +A21937,"package jp.funnything.competition.util; + +public enum Direction { + UP , DOWN , LEFT , RIGHT; + + public int dx() { + switch ( this ) { + case UP: + case DOWN: + return 0; + case LEFT: + return -1; + case RIGHT: + return 1; + default: + throw new RuntimeException( ""assert"" ); + } + } + + public int dy() { + switch ( this ) { + case UP: + return -1; + case DOWN: + return 1; + case LEFT: + case RIGHT: + return 0; + default: + throw new RuntimeException( ""assert"" ); + } + } + + public Direction reverese() { + switch ( this ) { + case UP: + return DOWN; + case DOWN: + return UP; + case LEFT: + return RIGHT; + case RIGHT: + return LEFT; + default: + throw new RuntimeException( ""assert"" ); + } + } + + public Direction turnLeft() { + switch ( this ) { + case UP: + return LEFT; + case DOWN: + return RIGHT; + case LEFT: + return DOWN; + case RIGHT: + return UP; + default: + throw new RuntimeException( ""assert"" ); + } + } + + public Direction turnRight() { + switch ( this ) { + case UP: + return RIGHT; + case DOWN: + return LEFT; + case LEFT: + return UP; + case RIGHT: + return DOWN; + default: + throw new RuntimeException( ""assert"" ); + } + } +} +" +A23010,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; + +public class GoogleTriplet { + public static void main(String[] args) { + runTestCase(); + } + + public static void runTestCase() { + String fileName = ""B-large.in"";// input file + String outFileName = ""outputFile.txt"";// output file + + try { + FileInputStream fStream = new FileInputStream(fileName); + FileOutputStream fOutStream = new FileOutputStream(outFileName); + + BufferedReader bf = new BufferedReader(new InputStreamReader( + fStream)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( + fOutStream)); + int i = 0; + int testSize = Integer.parseInt(bf.readLine()); + while (i < testSize) { + String in = bf.readLine(); + bw.write(findTriplets(in, ++i)); + bw.newLine(); + } + // close the two files. + bf.close(); + bw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String findTriplets(String inputData, int testCase) { + StringBuffer temp = new StringBuffer(); + temp.append(""Case #"" + testCase + "": ""); + + String[] split = inputData.split("" ""); + int noOfGooglers = Integer.parseInt(split[0]); + int surprise = Integer.parseInt(split[1]); + int p = Integer.parseInt(split[2]); + + List scores = new ArrayList(); + + for (int i = 3; i < 3 + noOfGooglers; i++) { + int score = Integer.parseInt(split[i]); + if (score > 3 * p - 5) { + if (score >= 3 * p - 4 && score < 3 * p - 2 && surprise > 0) { + if (3 * p - 4 > 0) { + scores.add(score); + surprise--; + } + } else if (score >= 3 * p - 2 || p == 0) { + scores.add(score); + } + } + } + temp.append(scores.size()); + return temp.toString(); + } +} +" +A22844,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package question2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +/** + * + * @author karim + */ +public class Question2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + + BufferedWriter out = new BufferedWriter(new FileWriter(""output.out"")); + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + int numOfcases = Integer.parseInt(in.readLine()); + for (int caseNum = 1; caseNum <= numOfcases; caseNum++) { + String input = in.readLine(); + Scanner s = new Scanner(input); + int googlers = s.nextInt(); + int surp = s.nextInt(); + int p = s.nextInt(); + int minCountedTriplet = 3*p -2; + int minCountedTripletWithSur = 3*p -4; + int output =0; + while(s.hasNextInt()){ + int temp = s.nextInt(); + if(temp >= minCountedTriplet) + output++; + else{ + if(surp>0 && temp >= minCountedTripletWithSur && minCountedTripletWithSur>=0){ + output++; + surp--; + } + } + + } + out.write(""Case #"" + caseNum + "": "" + output); + out.newLine(); + } + out.flush(); + out.close(); + in.close(); + + // TODO code application logic here + } +} +" +A22478,"import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + + +public class DancingGooglers { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for (int i = 1; i <= T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + List scores = new ArrayList(); + for (int j = 0; j < N; j++) + scores.add(in.nextInt()); + System.out.println(""Case #"" + i + "": "" + result(S, p, scores)); + } + } + + private static int result(int S, int p, List scores) { + Integer[] v = scores.toArray(new Integer[0]); + Arrays.sort(v); + int res = 0; + int nosup = p + 2*(Math.max(p-1, 0)); + int sup = p + 2*(Math.max(p-2, 0)); + for (int i = v.length-1; i >= 0; i--) + if (v[i] >= nosup) + res++; + else if (v[i] >= sup && S > 0) { + res++; + S--; + } + else + return res; + return res; + } + +} +" +A22327,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class Dancing_Googlers { + public static void main(String args[]) throws Exception + { + FileWriter ofstream = new FileWriter(""outp.out""); + BufferedWriter out = new BufferedWriter(ofstream); + FileInputStream fstream = new FileInputStream(""inp.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + long n,sur,p,ng,rem; + int i,ans=0; + int countn=1; + String strLine; + long[] li = new long[250]; + String[] ls = new String[250]; + strLine = br.readLine(); + n = Long.parseLong(strLine); + while ((strLine = br.readLine()) != null) { + ans=0; + ls = strLine.split("" ""); + for (i=0;i=p) //Finalizing stage 1 + { + //System.out.println (""Hello thier "" + (li[i]/3)); + ++ans; + continue; + } + //Without Surprise + rem = li[i]-(2*p); + if(((rem)+1) == p || ((rem)-1) == p || ((rem)+2) == p || ((rem)-2) == p) + { + ++ans; + continue; + } + //With SUrprise + rem = (li[i]-p)/2; + if(sur>0) + { + if((rem==p) || ((rem+2)==p) || ((rem-2)==p)) + { + --sur; + ++ans; + } + } + } + System.out.println (ans); + out.write(""Case #"" +countn + "": "" +ans + ""\n""); + ++countn; + } + in.close(); + out.close(); + } +} +" +A22383," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * + * @author Rashmika + */ +public class Main { + + public static void main(String[] args) { + try { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + int numLines = 0, i=0; + String str = """"; + String[] testRounds = new String[1]; + while ((str = in.readLine()) != null && str.length() != 0) { + if(numLines!=0){ + testRounds[i++] = str; + }else{ + numLines = Integer.parseInt(str); + testRounds = new String[numLines]; + } + } + + for(int j=0; j=P) ){ + //System.out.println(""Counted ""+i); + winnerCount++; + continue; + }else if( (S>0) && ((n1+1)>=P) ){ + //System.out.println(""Counted ""+i); + winnerCount++; + S--; + continue; + } + }else if(total%3==1){ + n1 = total/3 + 1; + //System.out.println(i+"":""+n1+"" ""+total); + if( (n1>=P) ){ + //System.out.println(""Counted ""+i); + winnerCount++; + continue; + } + }else if(total%3==2){ + n1 = total/3 + 1; + //System.out.println(i+"":""+n1+"" ""+total); + if( (n1>=P) ){ + //System.out.println(""Counted simile""+i); + winnerCount++; + continue; + }else if( (S>0) && ((n1+1)>=P) ){ + //System.out.println(""Counted ""+i); + winnerCount++; + S--; + continue; + } + } + + } + return winnerCount; + + } + +} +" +A21634,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.math.BigInteger; +import java.util.*; +/* + * Problem A. Speaking in Tongues + */ +public class B { + static BufferedReader _in = new BufferedReader(new InputStreamReader(System.in)); + static String _string; + static StringTokenizer _stok; + static String nextLine() throws IOException { + _string = _in.readLine(); + _stok = new StringTokenizer(_string); + return _string;} + static String nextWord() {return _stok.nextToken();} + static int nextInt() {return Integer.parseInt(nextWord());} // 2.1 x 10^9, + static long nextLong() {return Long.parseLong(nextWord());} // 9.2 x 10^18, + static double nextDouble() {return Double.parseDouble(nextWord());} + static BigInteger nextBig() {return new BigInteger(nextWord());} + static void Dprintln(Object s) {if(debug) System.out.println(s);} + static void Dprintln() {if(debug) System.out.println();} + static void Dprint(Object s) {if(debug) System.out.print(s);} + static void Dprintf(String s, Object... args) {if(debug) System.out.printf(s, args);} + static void print(Object s) {System.out.print(s);} + static void println(Object s) {System.out.println(s);} + static void println() {System.out.println();} + static void printf(String s, Object... args) {System.out.printf(s, args);} + + static boolean debug = true; + + + static void solve(double T, double S, int p) { + double avg = T/S; + int a = (int)Math.floor(avg), b = (int)Math.ceil(avg); + + } + + static int best(int x, boolean surp) { + int v = x/3; + int r = x%3; + if (r==0) { + return v + (surp && v>0 ?1:0); + } + else if (r==1) { + return v+1; + } else if (r==2) { + return v+1+ (surp?1:0); + } + System.err.println(""never reach here""); + return -1; + } + + public static void main(String[] args) throws Exception { + + nextLine(); + int Cases = nextInt(); + for (int Case=0; Case= p) c++; + else if (s > 0 && best(sc, true) >= p) { + c++; s--; + } + } + + System.out.println(""Case #"" + (Case+1) + "": "" + (c)); + + } // end for each case + + } // end main + + static long gcd(long a, long b) { + if (b > a) return gcd(b,a); + if (b == 0) return a; + return gcd(b, a % b); + } + +} +" +A21156,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class IOGoogleCodeJam{ + public static ArrayList fileInput(String fileName){ + File file = null; + FileReader fr = null; + BufferedReader br = null; + ArrayList inputs= new ArrayList(); + int lines; + try { + // Apertura del fichero y creacion de BufferedReader para poder + // hacer una lectura comoda (disponer del metodo readLine()). + file= new File (fileName); + fr = new FileReader (file); + br = new BufferedReader(fr); + // Lectura del fichero + while(br.ready()){ + inputs.add(br.readLine()); + } + }catch(Exception e){ + e.printStackTrace(); + }finally{ + // En el finally cerramos el fichero, para asegurarnos + // que se cierra tanto si todo va bien como si salta + // una excepcion. + try{ + if( null != fr ){ + fr.close(); + } + }catch (Exception e2){ + e2.printStackTrace(); + } + } + return inputs; + } + + public static void resultsOutput(ArrayList args, int argsPerLine){ + int numArg=0; + int maxNumber= args.size()/argsPerLine; + for(int caseNumber=1;caseNumber<=maxNumber;caseNumber++){ + System.out.print(""Case #""+caseNumber+"": ""); + for(int i=1;i<=argsPerLine;i++){ + System.out.print(args.get(numArg)+"" ""); + numArg++; + } + System.out.println(); + } + } +} + +" +A21794,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Dance implements Runnable { + public void run(){ + try { + Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new File(""b.out"")); + int testNum = in.nextInt(); + for (int test = 1; test <= testNum; test++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] a = new int[n]; + for(int i = 0; i < n; i++) { + a[i] = in.nextInt(); + } + int r = 0; + int k = 0; + for(int i = 0; i < n; i++) { + if (a[i] % 3 == 0) { + if (a[i] / 3 >= p) { + r++; + } else if (a[i] / 3 == p - 1 && a[i] > 0) { + k++; + } + } + if (a[i] % 3 == 1) { + if (a[i] / 3 >= p - 1) r++; + } + if (a[i] % 3 == 2) { + if (a[i] / 3 >= p - 1) r++; else + if (a[i] / 3 == p - 2) k++; + } + } + int res = r + Math.min(k, s); + out.println(""Case #"" + test + "": "" + res); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new Dance().run(); + } +} +" +A21286,"package codejam; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +/** + * ´ÓÎı¾¶ÁÈ¡ÊäÈë + * @author Administrator + * + */ +public class InOutTool extends ArrayList { + private String inPath ; + private String outPath; + public String outText(String path){ + this.outPath = path; + return outText(); + } + public String outText(){ + StringBuffer sb = new StringBuffer(); + PrintWriter out = null; + try { + out = new PrintWriter(new File(outPath).getAbsoluteFile()); + for(String s:this){ + out.println(s); + sb.append(s);sb.append(""\n""); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally{ + if(null!=out){ + out.close(); + } + } + return sb.toString(); + } + public String readText(String inPath){ + StringBuffer sb = new StringBuffer(); + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(new File(inPath).getAbsoluteFile())); + String s; + while((s = in.readLine()) != null){ + s = s.trim(); + add(s);//ÿһÐÐ×÷ΪArrayListµÄÒ»¸öÔªËØ + sb.append(s);sb.append(""\n""); + } + }catch (FileNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally{ + if(null!=in){ + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return sb.toString(); + } + public InOutTool(String inPath,String outPath){ + this.inPath = inPath;this.outPath = outPath; + readText(inPath); + if((size()!=0)&&get(0).equals("""")) remove(0); + } +} +" +A21242,"package com.jagsaund.codejam.qualifcation; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +public class DancingWithGooglers { + private List> _sets; + private int _numOfSurprisingTriplets; + private int _minResult; + + public DancingWithGooglers() { + _sets = new ArrayList>(); + } + + public String run(String line) { + int[] googlers = null; + int numOfGooglers; + + int pos = 0; + + StringTokenizer tokenizer = new StringTokenizer(line); + + while (tokenizer.hasMoreElements()) { + int v = Integer.parseInt(tokenizer.nextToken()); + if (pos == 0) { + numOfGooglers = v; + googlers = new int[numOfGooglers]; + } else if (pos == 1) { + _numOfSurprisingTriplets = v; + } else if (pos == 2) { + _minResult = v; + } else { + googlers[pos-3] = v; + } + + pos++; + } + + int count = 0; + + for (int number : googlers) { + getIntegerSet(number); + + if (_sets.size() > 0) { + if (_sets.size() == 1) { + List set = _sets.get(0); + + int low = Integer.MAX_VALUE; + int high = Integer.MIN_VALUE; + + for (int n : set) { + if (n < low) low = n; + if (n > high) high = n; + } + + if ((high - low) == 2 && _numOfSurprisingTriplets > 0) { + _numOfSurprisingTriplets--; + count++; + } else if ((high - low) < 2) { + count++; + } + + } else { + count++; + } + } + + +// if (number == 0 && _minResult == 0) count++; + + _sets.clear(); + } + + return count + """"; + } + + private void getIntegerSet(int x) { + getIntegerSet(x, x, new ArrayList()); + } + + private void getIntegerSet(int x, int max, List prefix) { + if (x == 0) { + if (prefix.size() <= 3) { + if (prefix.size() == 2) { + prefix.add(0); + } + + if (prefix.size() == 1) { + prefix.add(0); + prefix.add(0); + } + + if (prefix.size() == 0) { + prefix.add(0); + prefix.add(0); + prefix.add(0); + } + + int low = Integer.MAX_VALUE; + int high = Integer.MIN_VALUE; + + for (int n : prefix) { + if (n < low) low = n; + if (n > high) high = n; + } + + if (high >= _minResult && (high - low) <= 2 && high <= 10) { + _sets.add(prefix); + } + } + + return; + } + + for (int i=Math.min(x, max); i>=1; i--) { + List tmp = new ArrayList(prefix); + tmp.add(i); + getIntegerSet(x-i, i, tmp); + } + } +} +" +A22742,"import java.lang.*; +import java.util.*; +class dancer{ +int count,s,p; +int doneS; +int can; +void Counts(int i1){ + int thrice=3*p; + if(i1>=thrice){count++; + can++;} + else{int diff=(thrice-i1); + if(diff>4){can++;} + else if((diff==1)||(diff==2)){ + if(p==1){count++; + } + if(p>=2){count++; + can++;} + } + else{ + if(p>=2){count++; + doneS++; + } + } + } + + }} +//=========================== +class p1{ +public static void main(String args[]){ +Scanner sc=new Scanner(System.in); +int n=sc.nextInt(); +for(int i=0;id1.s){ + sub=d1.doneS-d1.s; + } +else{sub=0; + } +d1.count=d1.count-sub;; + +System.out.println(""Case #""+(i+1)+"": ""+d1.count);} +}} " +A21942,"package jp.funnything.competition.util; + +import java.util.Arrays; +import java.util.Iterator; + +/** + * Do NOT change the element in iteration + */ +public class Permutation implements Iterable< int[] > , Iterator< int[] > { + public static int[] fromNumber( long value , final int n ) { + final int[] data = new int[ n ]; + + for ( int index = 0 ; index < n ; index++ ) { + data[ index ] = index; + } + + for ( int index = 1 ; index < n ; index++ ) { + final int pos = ( int ) ( value % ( index + 1 ) ); + + value /= index + 1; + + final int swap = data[ index ]; + data[ index ] = data[ pos ]; + data[ pos ] = swap; + } + + return data; + } + + public static long toNumber( final int[] perm ) { + final int[] data = Arrays.copyOf( perm , perm.length ); + + long c = 0; + + for ( int index = data.length - 1 ; index > 0 ; index-- ) { + int pos = 0; + for ( int index_ = 1 ; index_ <= index ; index_++ ) { + if ( data[ index_ ] > data[ pos ] ) { + pos = index_; + } + } + + final int t = data[ index ]; + data[ index ] = data[ pos ]; + data[ pos ] = t; + + c = c * ( index + 1 ) + pos; + } + + return c; + } + + private final int _n; + private final int[] _data; + private final int[] _count; + int _k; + + public Permutation( final int n ) { + _n = n; + + _data = new int[ n ]; + for ( int index = 0 ; index < n ; index++ ) { + _data[ index ] = index; + } + + _count = new int[ n + 1 ]; + for ( int index = 1 ; index <= n ; index++ ) { + _count[ index ] = index; + } + + _k = 1; + } + + @Override + public boolean hasNext() { + return _k < _n; + } + + @Override + public Iterator< int[] > iterator() { + return this; + } + + @Override + public int[] next() { + final int i = _k % 2 != 0 ? _count[ _k ] : 0; + + final int t = _data[ _k ]; + _data[ _k ] = _data[ i ]; + _data[ i ] = t; + + for ( _k = 1 ; _count[ _k ] == 0 ; _k++ ) { + _count[ _k ] = _k; + } + _count[ _k ]--; + + return _data; + } + + @Override + public void remove() { + } +} +" +A22972,"package org.weiwei.googlejam; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: ding + * Date: 12-4-14 + * Time: 上午11:37 + * To change this template use File | Settings | File Templates. + */ +public class Dancing { + List scores; + int surp; + int p; + + public Dancing(List scores, int surp, int p){ + this.scores = scores; + this.surp = surp; + this.p = p; + } + + public static Dancing loadFromString(String input){ + String[] elems = input.trim().split("" ""); + int surp = Integer.parseInt(elems[1].trim()); + int p = Integer.parseInt(elems[2].trim()); + int total = Integer.parseInt(elems[0].trim()); + List scores = new ArrayList(); + for (int i =0; i < total; i++){ + scores.add(Integer.parseInt(elems[3+i].trim())); + } + return new Dancing(scores, surp, p); + } + + public int getNumber(){ + int number = 0; + Collections.sort(scores, Collections.reverseOrder()); + for(int score : scores){ + if(score >= 3*p -2 ){ + number++; + } + else if(surp > 0){ + if(score >=3*p-4 && p >= 2) { + number++; + surp--; + } + else { + break; + } + } else + break; + } + return number; + } +} +" +A20606,"package br.com.app; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + private static Scanner scan = new Scanner(System.in); + private static String[] entrada; + private static int[] possiveisValoresExtra; + private static int pontuacao, totEntradas, totSituacoes, totCompetidores, valorMinimo, totPossiveisValoresExtra, totValores, resto, resultado, totSituacoesMontadas, totCasos; + private static StringBuilder temp = new StringBuilder(); + private static StringBuilder saida = new StringBuilder(); + private static File arquivoEntrada = new File(""/home/emanuel/input.txt""); + private static File arquivoSaida = new File(""/home/emanuel/output.txt""); + private static BufferedReader leitura; + private static FileOutputStream fos; + private static String linha; + + public static void main(String[] args) { + try { + leitura = new BufferedReader(new FileReader(arquivoEntrada)); + linha = leitura.readLine(); + totEntradas = Integer.parseInt(linha); + totCasos = 1; + for (int i = 0; i < totEntradas; i++) { + linha = leitura.readLine(); + entrada = linha.split("" ""); + totCompetidores = Integer.parseInt(entrada[0]); + totSituacoes = Integer.parseInt(entrada[1]); + valorMinimo = Integer.parseInt(entrada[2]); + totPossiveisValoresExtra = 0; + totValores = 0; + possiveisValoresExtra = new int[totCompetidores]; + for (int j = 3; j < entrada.length; j++) { + pontuacao = Integer.parseInt(entrada[j]); + if (pontuacao == 0) { + if (valorMinimo == 0) { + totValores++; + } + continue; + } + resto = pontuacao % 3; + resultado = (pontuacao / 3); + switch (resto) { + case 2: + if ((resultado + 1) >= valorMinimo) { + totValores++; + break; + } + possiveisValoresExtra[totPossiveisValoresExtra++] = pontuacao; + break; + case 1: + if ((resultado + 1) >= valorMinimo) { + totValores++; + } + break; + default: + if (resultado >= valorMinimo) { + totValores++; + } else { + possiveisValoresExtra[totPossiveisValoresExtra++] = pontuacao; + } + break; + } + } + totSituacoesMontadas = 0; + for (int j = 0; j < totPossiveisValoresExtra && totSituacoesMontadas < totSituacoes; j++) { + pontuacao = possiveisValoresExtra[j]; + resto = pontuacao % 3; + resultado = (pontuacao / 3); + if (resto == 2) { + if ((resultado + 2) >= valorMinimo) { + totSituacoesMontadas++; + totValores++; + } + } else { + if ((resultado + 1) >= valorMinimo) { + totSituacoesMontadas++; + totValores++; + } + } + } + saida.append(""Case #"").append(totCasos++).append("": "").append(totValores).append(""\n""); + } + fos = new FileOutputStream(arquivoSaida); + fos.write(saida.toString().getBytes()); + fos.close(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } +} +" +A22099,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class DancingGooglers{ + + private static final int NUMBEROFJUDGES = 3; + + public static void main(String[] args) throws IOException { + + BufferedReader br = null; + try { + + + br = new BufferedReader(new FileReader(""B-large.in"")); + PrintStream out = new PrintStream(new File(""B-Large.out"")); + + int testcases = Integer.parseInt(br.readLine()); + + for (int casenr = 1; casenr <= testcases; casenr++) { + + String line = br.readLine(); + Scanner scanner= new Scanner(line); + + int numOfGoogler = scanner.nextInt(); + int numOfSurprising = scanner.nextInt(); + int bestResult = scanner.nextInt(); + ArrayList totalPoints =new ArrayList (); + + for (int i=0;i (bestResult-1) ){ + numberOfBestGoogler++; + } + else { + if ((Math.max((bestResult-2),0)*(NUMBEROFJUDGES-1) <= (totalPoints.get(i)-bestResult) ) && (numOfSurprising>0)) { + numOfSurprising--; + numberOfBestGoogler++; + } + } + + } + + + System.out.printf(""Case #%d: %d\n"", casenr, numberOfBestGoogler); + out.printf(""Case #%d: %s\n"", casenr, numberOfBestGoogler); + + } + + } catch(FileNotFoundException fe) { + fe.printStackTrace(); + } catch(IOException ie) { + ie.printStackTrace(); + } finally { + try { + if(br != null) { + br.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + +} + + +" +A20316,"package codejam.dancing_with_the_googlers; + +import java.io.IOException; +import java.util.ArrayList; + +import codejam.filestuff.FileStuff; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + FileStuff fs = new FileStuff(""B-large.in"",""B-large.out"",""dancing_with_the_googlers""); + ArrayList input = new ArrayList(); + input = fs.ReadFromFile(); + + ArrayList output = new ArrayList(); + + int xCase = Integer.valueOf(input.get(0)); + int xPointer = 1; + + for (int i=1;i<=xCase;i++) + { + String strOut = ""Case #"" + String.valueOf(i) + "":""; + String strLine = input.get(xPointer); + xPointer++; + String[] arrLine = strLine.split("" ""); + int xN = Integer.valueOf(arrLine[0]); + int xS = Integer.valueOf(arrLine[1]); + int xp = Integer.valueOf(arrLine[2]); + int xRes = 0; + for (int a=0;a= xp) + { + xRes++; + } else + { + if (xS > 0) + { + if (xSub < 2) xDiv++; + if (xDiv >= xp) + { + xRes++; + xS--; + } + } + } + } else + { + if (xp == 0) xRes++; + } + } + strOut += "" "" + String.valueOf(xRes); + output.add(strOut); + } + fs.WriteToFile(output); + System.out.print(""Done!!!""); + } + +} +" +A22981,"package dancingwiththegooglers.codejam; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) throws IOException{ + FileWriter fw = new FileWriter(""./output.txt""); + //Scanner in = new Scanner(new File(""/home/lotrf3/Downloads/A-small-practice.in"")); + Scanner in = new Scanner(new File(""/home/lotrf3/Downloads/B-large.in"")); + int cases = Integer.parseInt(in.nextLine()); + for (int i=0; i= p * 3 - 2) { + res++; + } else if (t[j] >= p * 3 - 4 && p * 3 - 4 > 0) { + puwede++; + } + } + res += Math.min(puwede, S); + w.write(""Case #"" + (i + 1) + "": "" + res + ""\n""); + } + w.flush(); + w.close(); + } + +} +" +A22408,"package qualificationRound; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Q2Dancing { + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + Scanner sc = new Scanner(new File(""qualificationRound/B-large.in"")); + PrintWriter out = new PrintWriter(new File(""qualificationRound/out.txt"")); + + int T = sc.nextInt(); + sc.nextLine(); + + for (int tc = 1; tc <= T; tc++) { + out.print(""Case #""+tc+"": ""); + + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int lowerBound = Math.max(p,3*p-2); + int lowerSurprise = Math.max(p,3*p-4); + int count = 0; + for (int i=0; i= lowerBound) + count++; + else if (t >= lowerSurprise && S > 0) { + count++; + S--; + } + } + + out.println(count); + out.flush(); + } + out.close(); + } + +}" +A20347,"import java.io.*; +import java.util.*; +import java.math.*; +import java.awt.geom.*; + +import static java.lang.Math.*; + +public class Solution implements Runnable { + + int sum1 []; // diff < 2 + int sum2 []; // diff == 2 + + public void solve () throws Exception { + int tt = nextInt(); + + sum1 = new int [31]; + sum2 = new int [31]; + + for (int num1 = 0; num1 <= 10; num1++) + for (int num2 = num1; num2 <= 10; num2++) + for (int num3 = num2; num3 <= 10; num3++) { + int sum = num1 + num2 + num3; + int diff = num3 - num1; + if (diff < 2) { + sum1 [sum] = max (sum1 [sum], num3); + } else if (diff == 2) { + sum2 [sum] = max (sum2 [sum], num3); + } + } + + for (int test = 1; test <= tt; test++) { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + + int d [][] = new int [n + 1][s + 1]; + boolean can [][] = new boolean [n + 1][s + 1]; + can [0][0] = true; + + for (int i = 0; i < n; i++) { + int sum = nextInt(); + int add1 = 0, add2 = 0; + + int p1 = sum1[sum]; if (p1 >= p) add1 = 1; + int p2 = sum2[sum]; if (p2 >= p) add2 = 1; + + for (int j = 0; j <= s; j++) { + if (can[i][j]) { + + d[i + 1][j] = max (d[i + 1][j], d[i][j] + add1); + can[i + 1][j] = true; + + if (j < s) { + d[i + 1][j + 1] = max (d[i + 1][j + 1], d[i][j] + add2); + can [i + 1][j + 1] = true; + } + + } + } + } + + out.println(""Case #""+test+"": ""+d[n][s]); + + } + } + + final String fname = """"; + long stime = 0; + + BufferedReader in; + PrintWriter out; + StringTokenizer st; + + private String nextToken () throws Exception { + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(in.readLine()); + } + return st.nextToken(); + } + + private int nextInt () throws Exception { + return Integer.parseInt(nextToken()); + } + + private long nextLong () throws Exception { + return Long.parseLong(nextToken()); + } + + private double nextDouble () throws Exception { + return Double.parseDouble(nextToken()); + } + + @Override + public void run() { + try { + in = new BufferedReader(new FileReader(""input.txt"")); + out = new PrintWriter(new FileWriter(""output.txt"")); + solve (); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + out.close(); + } + } + + public static void main(String[] args) { + new Thread(null, new Solution(), """", 1<<26).start(); + } + +}" +A21155,"import java.util.ArrayList; + +public class DancingWG{ + public static void main(String[] args){ + ArrayList inputs = IOGoogleCodeJam.fileInput(args[0]); + ArrayList outputs= new ArrayList(); + int lines=Integer.parseInt(inputs.get(0)); + for(int i=1;i<=lines;i++){ + outputs.add(processData(inputs.get(i))); + } + IOGoogleCodeJam.resultsOutput(outputs,1); + } + + public static String processData(String s){ + String aux[] = s.split("" ""); + int N = Integer.parseInt(aux[0]); + int S = Integer.parseInt(aux[1]); + int p = Integer.parseInt(aux[2]); + int c = 0; //count googlers + for(int i=3;i=p){ + c++; + }else if(y>0){//if 0 reach here, it doesn't count + y=(x+3)/3; + if(y<=10 && y>=p && S>0){ + c++; + S--; + } + } + break; + case 1: y=(x+2)/3; + if(y>=p){ + c++;//I dont care if there's a surprise here + } + break; + case 2: y=(x+1)/3; + if(y>=p){ + c++; + }else{ + y=(x+4)/3; + if(y<=10 && y>=p && S>0){ + c++; + S--; + } + } + break; + } + } + return String.valueOf(c); + } +} +" +A20027,"package WQ; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Problem_B { + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + String filename = ""B-large (1).in""; + Scanner s = new Scanner(new FileReader(filename)); + PrintWriter out = new PrintWriter(""out.txt""); + int num = s.nextInt(); + for (int CASE = 1; CASE <= num; CASE++) { + int n = s.nextInt(); + int sr = s.nextInt(); + int p = s.nextInt(); + int[] compet = new int[n]; + for (int i = 0; i < n; i++) { + compet[i] = s.nextInt(); + } + int count = 0; + for (int i = 0; i < compet.length; i++) { + int divide = compet[i] / 3; + int rem = compet[i] % 3; + if (divide >= p) + count++; + else { + if (rem == 0 && sr > 0 && divide > 0 && divide + 1 >= p) { + count++; + sr--; + } else if (rem == 1 && divide + 1 >= p) { + count++; + } else if (rem == 2) { + if (divide + 1 >= p) + count++; + else if (sr > 0 && divide + 2 >= p) { + count++; + sr--; + } + } + } + } + out.println(""Case #"" + CASE + "": "" + count); + } + out.close(); + } +} +" +A20429,"import java.util.Scanner; + +public class Dancing { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); + int[] array = new int[n]; + for (int i = 0; i < n; i++) { + int k = scan.nextInt(); + int[] arrayInt = new int[k]; + int s = scan.nextInt(); + int p = scan.nextInt(); + for (int j = 0; j < k; j++) + arrayInt[j] = scan.nextInt(); + int a = 0; + for (int j = 0; j < k; j++) { + int div = arrayInt[j] / 3; + int rem = arrayInt[j] - div * 3; + if (rem == 0) { + if (div >= p) + a++; + else if (div == p - 1 && s >= 1 && div - 1 >= 0) { + a++; + s--; + } + } else if (rem == 1) { + if (div >= p - 1) + a++; + } else { + if (div >= p - 1) + a++; + else if (div == p - 2 && s >= 1) { + a++; + s--; + } + } + } + array[i] = a; + } + for (int i = 1; i <= n; i++) + System.out.println(""Case #"" + i + "": "" + array[i - 1]); + } +} +" +A20395,"import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.Scanner; + + +public class EjercicioA { + public static boolean prueba = false; + public static void main(String args[]){ + + try { + FileOutputStream fos = new FileOutputStream(new File(""solucion.txt"")); + OutputStream os = System.out; + if (!prueba) + os = fos; + Scanner s = new Scanner(new File(""problema.txt"")); + int a = s.nextInt(); + for(int i = 0; i < a; i++){ + int cantP = s.nextInt(); + int sorpresa = s.nextInt(); + int puntos = s.nextInt(); + int total = 0; + int minP = 0; + + int maxSin = puntos + ((puntos -1) > 0 ? (puntos -1) : 0)*2; + int maxSorp = puntos + ((puntos -2) > 0 ? (puntos -2) : 0)*2; + for (int j = 0; j< cantP; j++){ + int totP = s.nextInt(); + if (totP < puntos) + continue; + if (totP >= maxSin) + total++; + else if (sorpresa > 0 && totP >= maxSorp){ + sorpresa --; + total++; + } + + } + + os.write((""Case #"" + (i + 1) + "": "" + (total) + ""\n"").getBytes()); + + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +} +" +A21611,"import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + + +public class Counter { + + private int T; + private Lock lock; + private ICounterZeroEvent e; + + + public Counter(int T, ICounterZeroEvent e) + { + this.T = T; + this.e = e; + lock = new ReentrantLock(); + } + + public void increase() { + lock.lock(); + T--; + if (T==0) + e.fireEvent(); + lock.unlock(); + System.out.println(T); + + } + +} +" +A21840,"package com.sam.googlecodejam.dance; + +import com.sam.googlecodejam.helper.InputReader; + +public class DanceScore { + + int iBestScore; + int iSuprize; + + int iMean; + + int iSetCount = 0; + + class TripletScore { + public int judge1; + public int judge2; + public int judge3; + + public void setValue(int j1, int j2, int j3) { + judge1 = j1; + judge2 = j2; + judge3 = j3; + } + + public int sum() { + //System.out.println(judge1 + judge2 + judge3); + return judge1 + judge2 + judge3; + } + + public boolean containsGreater(int value) { + //System.out.println(judge1 >= value || judge2 >= value || judge3 >= value); + if(judge1 >=0 && judge2 >=0 && judge3 >=0) + { + return judge1 >= value || judge2 >= value || judge3 >= value; + } + return false; + } + } + + /* + * e.g. If score is 13,14,15, 15 - avg = 15/3 + (15%3==0)= 5 (3,5,5), + * (4,4,5) (4,5,5) (5,5,5) (4,6,5) If score is 22,23,24 22 - avg = 22/3 + * +(22%3==0) = 8 (6,8,8), (7,7,8) (7,8,8) (8,8,8), (7,8,9) + */ + TripletScore possibleValues[] = new TripletScore[6]; + + public void generateTripletFromScore(int score) { + int mean = score / 3 + (score % 3 == 0 ? 0 : 1); + iMean = mean; + for(int i=0;i<6;i++) + { + possibleValues[i] = new TripletScore(); + } + // Non Suprizing + possibleValues[0].setValue(mean - 1, mean - 1, mean); + possibleValues[1].setValue(mean - 1, mean, mean); + possibleValues[2].setValue(mean, mean, mean); + // Suprizing + possibleValues[3].setValue(mean - 2, mean, mean); + possibleValues[4].setValue(mean - 1, mean + 1, mean); + possibleValues[5].setValue(mean - 1, mean - 1, mean + 1); + + } + + public void isScore(int score) { + // check if any combination yeilds a result that would be greater than + // the better score + // We first check if a non-suprizing one works and only then use up a + // suprizing! + for (int i = 0; i < 3; i++) { + if (possibleValues[i].sum() == score) { + if (possibleValues[i].containsGreater(iBestScore)) { + iSetCount++; + return; + } + } + } + if (iSuprize != 0) { + for (int i = 3; i < 6; i++) { + if (possibleValues[i].sum() == score) { + if (possibleValues[i].containsGreater(iBestScore)) { + iSetCount++; + iSuprize--; + return; + } + } + } + } + } + + public static void main(String[] args) { + + InputReader reader = new InputReader(""c://input.in""); + reader.readNextLine(); // read the line number off - we don't need it + + String lineRead = null; + int i = 1; + while ((lineRead = reader.readNextLine()) != null) { + DanceScore score = new DanceScore(); + System.out.print(""Case #"" + i + "": ""); + i++; + String values[] = lineRead.split("" ""); + + score.iSuprize = Integer.parseInt(values[1]); + score.iBestScore = Integer.parseInt(values[2]); + + for (int LoopCount = 3; LoopCount <= Integer.parseInt(values[0])+2; LoopCount++) { + score.generateTripletFromScore(Integer + .parseInt(values[LoopCount])); + score.isScore(Integer + .parseInt(values[LoopCount])); + } + System.out.println(score.iSetCount); + } + } + +} +" +A21280,"/** + * KSpokas: GCJ 2012 Qualification Round Problem B + */ + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + + +public class qualProblemB { + private final static int EXPECTED_ARG_COUNT = 1; + private static Map lookup = new HashMap(); + private static Map surprisingLookup = new HashMap(); + + public static void main(String[] args) { + if (args.length != EXPECTED_ARG_COUNT) { + System.err.println(""Error: expecting "" + EXPECTED_ARG_COUNT); + return; + } + buildLookups(); + + String fileName = args[0]; + try { + FileInputStream fstream = new FileInputStream(fileName); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + BufferedWriter out = new BufferedWriter(new FileWriter(fileName + "".out"")); + + Integer testCaseCount = Integer.parseInt(br.readLine()); + + for (int i = 0; i < testCaseCount; i++) { + String strLine = br.readLine(); + + StringBuilder sb = new StringBuilder(""Case #""); + sb.append(i + 1).append("": ""); + sb.append(calculate(strLine)); + out.write(sb.toString()); + out.newLine(); + } + in.close(); + out.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } + + private static int calculate(String input) { + int maxValue = 0; + + String[] values = input.split("" ""); + Integer dancerCount = Integer.parseInt(values[0]); + Integer surprisingCount = Integer.parseInt(values[1]); + Integer targetScore = Integer.parseInt(values[2]); + + for (int i = 3; i < dancerCount + 3; i++) { + Integer dancerTotal = Integer.parseInt(values[i]); + + if (dancerTotal >= lookup.get(targetScore)) { + maxValue++; + } else if (surprisingCount > 0 && dancerTotal >= surprisingLookup.get(targetScore)) { + maxValue++; + surprisingCount--; + } + } + return maxValue; + } + + private static void buildLookups() { + for (int i = 0; i <= 10; i++) { + lookup.put(i, getPossibleScores(i)); + surprisingLookup.put(i, getPossibleSurprisingScores(i)); + } + } + + private static Integer getPossibleScores(Integer i) { + Set scoreSet = new HashSet(); + + if (i == 0) { + scoreSet.add(0); + } else { + scoreSet.addAll(getScores(i - 1, i)); + scoreSet.addAll(getScores(i, i + 1)); + scoreSet.add(3 * i); + } + return Collections.min(scoreSet); + } + + private static Integer getPossibleSurprisingScores(Integer i) { + Set scoreSet = new HashSet(); + + if (i == 0) { + scoreSet.add(0); + } else { + scoreSet.addAll(getScores(i - 2, i)); + scoreSet.addAll(getScores(i, i + 2)); + + if ((i - 2) >= 0) { + scoreSet.add((i - 2) + (i - 1) + i); + } + + if (i - 1 >= 0 && i + 1 <= 10) { + scoreSet.add((i - 1) + i + (i + 1)); + } + + if (i + 2 <= 10) { + scoreSet.add(i + (i + 1) + (i + 2)); + } + } + + return Collections.min(scoreSet); + } + + private static Set getScores(Integer min, Integer max) { + Set scores = new HashSet(); + + if (min >= 0 && max <= 10) { + scores.add((2 * min) + max); + } + return scores; + } + +} +" +A20887,"import java.io.IOException; +import java.util.InputMismatchException; +import java.io.OutputStream; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.io.FileInputStream; +import java.io.Writer; +import java.math.BigInteger; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream; + try { + inputStream = new FileInputStream(""B-large.in""); + } catch (IOException e) { + throw new RuntimeException(e); + } + OutputStream outputStream; + try { + outputStream = new FileOutputStream(""dancinggooglers.out""); + } catch (IOException e) { + throw new RuntimeException(e); + } + StreamInputReader in = new StreamInputReader(inputStream); + OutputWriter out = new OutputWriter(outputStream); + DancingGooglers solver = new DancingGooglers(); + int testCount = Integer.parseInt(in.next()); + for (int i = 1; i <= testCount; i++) + solver.solve(i, in, out); + out.close(); + } +} + +class DancingGooglers { + public void solve(int testNumber, StreamInputReader in, OutputWriter out) { + out.print(""Case #"" + testNumber + "": ""); + + int n = in.readInt(), s = in.readInt(), p = in.readInt(); + int res = 0; + for(int i = 0; i < n; ++i) { + int t = in.readInt(); + if (t >= 3 * Math.max(0, p-1) + 1 || t >= 3 * p || t >= Math.max(0, 3 * p - 1)) { + ++res; + } + else if (s > 0 && t >= 3 * Math.max(0, p-2) + 2) { + --s; + ++res; + } + } + + out.printLine(res); + } +} + +class StreamInputReader extends InputReader { + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + + public StreamInputReader(InputStream stream) { + this.stream = stream; + } + + public int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + } + +class OutputWriter { + private final PrintWriter writer; + + public OutputWriter(OutputStream outputStream) { + writer = new PrintWriter(outputStream); + } + + public OutputWriter(Writer writer) { + this.writer = new PrintWriter(writer); + } + + public void print(Object...objects) { + for (int i = 0; i < objects.length; i++) { + if (i != 0) + writer.print(' '); + writer.print(objects[i]); + } + } + + public void printLine(Object...objects) { + print(objects); + writer.println(); + } + + public void close() { + writer.close(); + } +} + +abstract class InputReader { + + public abstract int read(); + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + public String next() { + return readString(); + } + + protected boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + } + +" +A20475,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.io.LineReader; + + +public class DancingWithGooglers { + + public static void main(String[] args) throws NumberFormatException, IOException { + LineReader lineReader = new LineReader(new FileReader(args[0])); + FileWriter out = new FileWriter(args[0] + ""-out.txt""); + + int t = Integer.parseInt(lineReader.readLine()); + for (int counter = 1; counter <= t; counter++) { + String[] nums = lineReader.readLine().split("" ""); + int surprisingTriplets = Integer.parseInt(nums[1]); + int bestResultMin = Integer.parseInt(nums[2]); + List totals = Lists.newArrayList(); + for (int i = 3; i < nums.length; i++) { + totals.add(Integer.parseInt(nums[i])); + } + + int result = compute(surprisingTriplets, bestResultMin, totals); + out.write(String.format(""Case #%d: %d\n"", counter, result)); + } + out.close(); + } + + private static int compute(int surprisingTriplets, int bestResultMin, List totals) { + // surpr = 1, bestMin = 5 | 15 13 11 + // 5, 3, 3 = 11 - surpr. min + // 5, 4, 4 = 13 - norm. min + + int surprMin = bestResultMin + 2 * Math.max(bestResultMin - 2, 0); + int normMin = bestResultMin + 2 * Math.max(bestResultMin - 1, 0); + + int count = 0; + for (int t : totals) { + if (t >= normMin) { + count++; + } else if (t >= surprMin && surprisingTriplets > 0) { + count++; + surprisingTriplets--; + } + } + + return count; + } + + +} +" +A20449,"package codejam.suraj.quals2012.googledancers; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import javax.swing.event.TreeExpansionEvent; + +import codejam.suraj.quals2012.CodeJamSkeleton; +import codejam.suraj.quals2012.googlerese.Googlerese; + +public class GoogleDancers extends CodeJamSkeleton { + + @Override + protected void handleTestCase(int testCaseNumber) throws IOException { + // TODO Auto-generated method stub + + String line = readLine(); + String[] lineSplits = line.split(""\\s+""); + + int numberOfG = Integer.parseInt(lineSplits[0]); + int surprises = Integer.parseInt(lineSplits[1]); + int p = Integer.parseInt(lineSplits[2]); + List scores = new ArrayList(lineSplits.length - 3); + for (int i = 3; i < numberOfG + 3; ++i){ + scores.add(Integer.parseInt(lineSplits[i])); + } + + Iterator iter = scores.iterator(); + int requiredSurprises = 0; + + int bestAndRequired = 0; + int numBestResults = 0; + System.out.println(""Test Case "" + testCaseNumber); + System.out.println(line); + while(iter.hasNext()){ + int score = iter.next(); + int max = score/3; + if(score > 0 && score%3 != 0) + max = max + 1; + + if(p == max){ + ++numBestResults; + } + else if(p > max){ + if(score == 2 || score > 2 && score%3 == 0 || + score > 2 && score%3 == 2){ + int possibleMax = max + 1; + if(possibleMax == p){ + ++requiredSurprises; + } + + } + + } + else if (p < max){ + int min = 0; + if(score <= 2){ + min = 0; + if(p == min){ + ++numBestResults; + } + + } + else{ + if(score%3 == 0){ + min = max - 1; + if(min == p){ + ++requiredSurprises; + ++numBestResults; + ++bestAndRequired; + } + else{ + ++numBestResults; + } + } + else if (score%3 == 1 || score%3 == 2){ + min = max - 1; + if(min == p){ + ++numBestResults; + } + else if (min - 1 == p){ + ++requiredSurprises; + ++numBestResults; + ++bestAndRequired; + } + else{ + ++numBestResults; + } + } + } + } + else if (p == max){ + ++numBestResults; + } + } + + int result = numBestResults + Math.min(requiredSurprises - bestAndRequired, surprises); + + + addOutput(testCaseNumber, """"+result); + + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + CodeJamSkeleton testCase = new GoogleDancers(); + testCase.handleAllTestCases(args[0], args[1]); + } + +} +" +A21402,"package it.simone.google.code.jam2012; + +public class Dancer implements GoogleCodeExercise { + + int surprise = 0; + int googlers = 0; + int p = 0; + + @Override + public String execute(String line) { + + int result = 0; + + String[] data = line.split("" ""); + googlers = Integer.parseInt(data[0]); + surprise = Integer.parseInt(data[1]); + p = Integer.parseInt(data[2]); + + for (int i = 3; i < data.length; i++) { + + int total = Integer.parseInt(data[i]); + result += analize(total); + } +// if (surprise >= 1) +// System.out.println(""WARNING""); + return """" + result; + } + + @Override + public void initialize() { + + } + + private int analize(int total) { + int avg = total / 3; + int rem = total % 3; + int maxVote = avg; + + + if (avg >= p) { + maxVote = avg; + } else if (rem == 1) { + maxVote = avg + 1; + } else if (rem == 2) { + if ((avg + 1) >= p) + maxVote = avg + 1; + else if (surprise > 0) { + if ((avg + 2) >= p) { + maxVote = avg + 2; + surprise--; + } else + maxVote = avg + 1; + } + } else if (rem == 0 && avg!=0) { + if ((avg + 1) >= p && surprise > 0) { + maxVote = avg + 1; + surprise--; + } + } + + if (maxVote >= p) + return 1; + else + return 0; + } + +} +" +A20441,"import java.util.*; + +public class B { + static Vector> num = new Vector>(); + + static void fill() { + for(int i = 0; i < 33; ++i) { + num.add(new TreeSet()); + } + + for(int i = 0; i <= 10; ++i) { + for(int j = i; j <= i+2; ++j) { + for(int k = j; k <= i+2; ++k) { + if(k <= 10) { + int sum = i+j+k; + int diff1 = k-i, diff2 = j-i; +// if(sum == 13) { +// System.out.println(i + "" "" + j + "" "" + k); +// } + if(diff1 == 2) { + if(diff2 < 2) { + num.get(3*k+2).add(sum); +// if(sum == 13) { +// System.out.println(""Strict""); +// } + } + else { + num.get(3*k+1).add(sum); +// if(sum == 13) { +// System.out.println(""Non""); +// } + } + } + else { + num.get(3*k).add(sum); +// if(sum == 13) { +// System.out.println(""Binhthuong""); +// } + } + } + } + } + } + } + + static int[] check(int score, int p) { + int r[] = new int[3]; + + int size = num.size(); + for(int i = 0; i < size; ++i) { + Set temp = num.get(i); + if(temp.contains(score)) { + if(i/3 >= p) { + r[0] = 1; + if(i%3 == 2 && r[2] >= 0) { + r[2] = 1; + } + else { + r[2] = -1; + } + } + if(i%3 != 0) { + r[1] = 1; + } + } + } + + if(r[2] < 0) { + r[2] = 0; + } +// System.out.println(""check "" + score + "" "" + Arrays.toString(r)); + return r; + } + + public static void main(String args[]) { + fill(); + + Scanner input = new Scanner(System.in); + int test = input.nextInt(); + for(int i = 1; i <= test; ++i) { + int N = input.nextInt(), S = input.nextInt(), p = input.nextInt(); + int t[] = new int[N]; + for(int j = 0; j < N; ++j) { + t[j] = input.nextInt(); + } + int result = 0; + //int high[] = new int[N], strict[] = new int[N], nons[] = new int[N]; + int high = 0, strict = 0, nons = 0; + for(int j = 0; j < N; ++j) { + int temp[] = check(t[j], p); + high += temp[0]; + nons += temp[1]; + strict += temp[2]; + } +// System.out.println(N + "" "" + S + "" "" + p); +// System.out.println(high + "" "" + nons + "" "" + strict); + if(nons < S) { + result = 0; + } + else { + if(strict > S) { + result = high + S -strict; + } + else { + result = high; + } + } + + System.out.println(""Case #"" + i + "": "" + result); + } + } +} +" +A22129,"import java.io.*; +import java.util.*; + +class ProblemB +{ + public static void main(String[] args) + { + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""input.txt""); + BufferedWriter out = new BufferedWriter(new FileWriter(""output.txt"")); + + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + int[][] judge = new int[3][1]; + int googler = 0, surprise = 0, p = 0; + int count = 0; + + String strLine, outputLine; + + int line = 0; + + int control = 0; + + //to get rid of the first line + br.readLine(); + + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + + line++; + + outputLine = ""Case #""+line+"": ""; + //outputLine = """"; + + String tempString = """"; + control = 0; + count = 0; + + for (int i = 0; i < strLine.length(); ++i) + { + if (strLine.charAt(i) == ' ' || i == strLine.length()-1) + { + if (i == strLine.length()-1) + { + tempString += """"+strLine.charAt(i); + } + switch (control) + { + case 0 : + googler = Integer.parseInt(tempString); + judge = new int[3][googler]; + break; + case 1 : + surprise = Integer.parseInt(tempString); + break; + case 2 : + p = Integer.parseInt(tempString); + break; + default : + int score = Integer.parseInt(tempString); + judge[0][control-3] = score/3; + judge[1][control-3] = score/3; + judge[2][control-3] = score/3; + if (score%3 == 1) + { + judge[2][control-3]++; + } + else if (score%3 == 2) + { + judge[1][control-3]++; + judge[2][control-3]++; + } + break; + } + control++; + tempString = """"; + continue; + } + tempString += """"+strLine.charAt(i); + } + + System.out.println(googler+"" ""+surprise+"" ""+p); + for (int i = 0; i < googler; ++i) + { + System.out.print(judge[0][i]+"" ""); + System.out.print(judge[1][i]+"" ""); + System.out.print(judge[2][i]+"" ""); + + System.out.println(); + } + + for (int i = 0; i < googler; ++i) + { + if (judge[2][i] == p-1 && judge[2][i] == judge[1][i] && judge[0][i] > 0 && judge[1][i] > 0 && surprise > 0) + { + judge[2][i]++; + judge[1][i]--; + surprise--; + } + } + + + for (int i = 0; i < googler; ++i) + { + if (judge[0][i] >= p || judge[2][i] >= p) + { + count++; + } + } + + outputLine += """"+count; + + out.write(outputLine); + out.newLine(); + System.out.println(outputLine); + System.out.println(); + } + //Close the input stream + in.close(); + out.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A22032,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Scanner; +import java.util.StringTokenizer; + + +public class Recycle { + + public Recycle() + { + readFile(""Files/recycle.in""); + } + public void readFile(String file) + { + try{ + FileInputStream fstream = new FileInputStream(file); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = """"; + br.readLine(); + int count = 1; + while ((strLine = br.readLine()) != null) + { + System.out.print(""Case #"" + (count++) + "": ""); + Scanner scanner = new Scanner(strLine); + int numSurprising = 0; + int p = 0; + scanner.nextInt(); + int numMax = 0; + numSurprising = scanner.nextInt(); + p = scanner.nextInt(); + while(scanner.hasNextInt()) + { + int current = scanner.nextInt(); + if(current == 0 && p != 0) + continue; + else if(current == 0 && p == 0) + numMax++; + else if(current >= (3*p-2)) + { + numMax++; + } + else if(numSurprising > 0 && ((3*p-2) - current) <= 2) + { + numSurprising--; + numMax++; + } + } + + + System.out.print(numMax); + System.out.println(); + } + }catch(Exception e){} + } + public static void main(String [] args) + { + Recycle r = new Recycle(); + } +} +" +A22257,"package taskb; + +import java.io.FileNotFoundException; +import java.util.*; +import java.io.File; +import java.io.PrintWriter; + +public class TaskB { + + private void solve(Scanner in, PrintWriter out, int caseNum){ + int res = 0; + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int []usual = new int[N]; + int []surprise = new int[N]; + + for(int i = 0;i=p){ + res++; + } else{ + if(sLeft < 1) + continue; + if(surprise[i]>=p){ + res++; + sLeft--; + } + } + + } + + + out.format(""Case #%d: %s\n"", caseNum, res); + } + + public TaskB(){ + + try{ + Scanner in = new Scanner(new File(""B-large.in"")); + int T = in.nextInt(); + PrintWriter out = new PrintWriter(""Blarge.out""); + for(int i = 0;i=p && x<=30 && smallx>=0) + { + n.notSurp = true; + next = false; + } + } + + } + // NOT 2: 3x+1 + if(next) + { + scratch = n.num; + scratch -= 1; + if(scratch%3==0) + { + int x = (scratch/3)+1; + int smallx = (scratch/3); + if(x>=p && x<=30 && smallx>=0) + { + n.notSurp = true; + next = false; + } + } + } + //NOT 1: 3x + if(next) + { + scratch = n.num; + if(scratch%3==0) + { + int x = (scratch/3); + int smallx = (scratch/3); + if(x>=p && x<=30 && smallx>=0) + { + n.notSurp = true; + } + } + } + next = true; + ///////////////////////////// + // SURP 3: 3x+4 + if(next) + { + scratch = n.num; + scratch -= 4; + if(scratch%3==0) + { + int x = (scratch/3)+2; + int smallx = (scratch/3); + if(x>=p && x<=30 && smallx>=0) + { + n.surp = true; + next = false; + } + } + } + // SURP 2: 3x+3 + if(next) + { + scratch = n.num; + scratch -= 3; + if(scratch%3==0) + { + int x = (scratch/3)+2; + int smallx = (scratch/3); + if(x>=p && x<=30 && smallx>=0) + { + n.surp = true; + next = false; + } + } + } + + // SURP 1: 3x+2 + if(next) + { + scratch = n.num; + scratch -= 2; + if(scratch%3==0) + { + int x = (scratch/3)+2; + int smallx = (scratch/3); + if(x>=p && x<=30 && smallx>=0) + { + n.surp = true; + next = false; + } + } + } + + numberList[cnt] = n; + cnt++; + } + + int dummyS = surpCount; + for (int i = 0; i 0) + { + dummyS--; + result++; + } + else if(numberList[i].notSurp==true && numberList[i].surp==false) + { + result++; + } + else if(numberList[i].notSurp==true && numberList[i].surp==true) + { + result++; + } + } + int asd = t+1; + w.println(""Case #"" + asd + "": "" + result); + } + + w.close(); + + } + + +} +" +A21217,"import java.util.Scanner; + +public class B { + public static void main(String args[]) { + new B(); + } + + public B() { + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); + for(int t=1; t<=T; t++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int y = 0; + for(int n=0; n 0) S--; + else continue; + } + + if(d >= -2) y++; + } + System.out.printf(""Case #%d: %d\n"", t, y); + } + } +}" +A21490,"import java.util.Scanner; + +public class Dancing { + + public static int isPossible(int p, int t){ + + // -1 -> not possible + // 0 -> possible + // 1 -> possible but surprising + + int a = (t-p)/2; + int b = t-p-a; + + if((t/3)>=p){ + return 0; + } + if(a<0 || b<0){ + return -1; + } + if(Math.abs(p-a)<=2 && Math.abs(p-b)<=2 && Math.abs(p-b)<=2) { + if(Math.abs(p-a)==2 || Math.abs(p-b)==2 || Math.abs(p-b)==2){ + return 1; + } + return 0; + } + return -1; + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int i = 0; i < T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int t[] = new int[N]; + int count=0; + + for(int j=0; j=3*p-2) + res++; + else if(s>0&&(x>=3*p-4)&&((x>0)||p==0)){ + res++;s--; + } + } + System.out.println(""Case #"" + i + "":""+ "" "" + res); + } + } + +} +" +A21459,"import static java.lang.Math.*; +import static java.math.BigInteger.*; +import static java.util.Arrays.*; +import static java.util.Collections.*; +import java.math.*; +import java.util.*; +import java.io.*; + +import static java.lang.Math.*; +public class DancingWiththeGooglers { + public static void main (String [] args) throws IOException { + String[]filename=""test A-small A-large B-small B-large C-small C-large D-small D-large"".split("" ""); + ////////////////// 0 1 2 3 4 5 6 7 8 + String fn=filename[4]; + f = new BufferedReader(new FileReader(fn+"".in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fn+"".out""))); + + nl(); + int t = ip(tk()); + for (int i = 0; i < t; i++) { + nl(); + int n = ip(tk()),s=ip(tk()),p=ip(tk()); + int res=0; + int sp=0; + for (int j = 0; j < n; j++) { + int data=ip(tk()); + int ans=data/3,rest=data%3; + if(ans>=p)res++; + else if(ans==p-1&&rest>0){res++;} + else if(ans==p-1&&rest==0&&sp=0){res++;sp++;} + else if(ans==p-2&&rest==2&&sp { + public int compareTo(Comp other) {// myself first asc + if (len == other.len) + return str.compareTo(other.str);// myself first asc + return other.len - len;// other first desc + } + + int len; + String str; + public Comp(int len, String str) { + super(); + this.len = len; + this.str = str; + } + } +} +" +A22579,"import java.io.*; +import java.util.StringTokenizer; + +public class q2 +{ + public static int spl,threshold,players,output; + public static void main(String []args) throws IOException + { + + PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(""output.txt""))); + BufferedReader br=new BufferedReader(new FileReader(""input.txt"")); + + int arr[]=new int[107]; + int limit=Integer.parseInt(br.readLine()); + String x1; + String word=""""; + for(int li=1;li<=limit;li++) + { + x1=br.readLine(); + int j=0; + StringTokenizer st =new StringTokenizer(x1); + while (st.hasMoreElements()) { + + String token = st.nextElement().toString(); + arr[j]=Integer.parseInt(token); + j++; + } + + spl=arr[1]; + threshold=arr[2]; + players=arr[0]; + output=find(arr); + pw.println(""Case #""+li+"": ""+output); + arr=new int[107]; + } + pw.close(); + } + + public static int find(int arr[]) + { + int a=0,b=0,c=0; + int op=0; + for(int i=3;i<(players+3);i++) + { + int num=arr[i]; + int num2=num; + boolean check=true; + a=num/3; + b=a; + c=a; + int diff=num2-(a*3); + + if(diff==0) + { if(a>=threshold||b>=threshold||c>=threshold) + op++; + else + { + if(spl>0) + { + if((a-1)>0) + { + if((a-1)>=threshold||b>=threshold||(c+1)>=threshold) + { + op++; + spl--; + } + } + } + } + + } + + if(diff==1) + { if((a+1)>=threshold||b>=threshold||c>=threshold) + { op++; + } + + else + { + if(spl>0) + { + if((a+1)>=threshold||(b-1)>=threshold||(c+1)>=threshold) + { + op++; + spl--; + } + + } + } + + } + if(diff==2) + { + if((a+1)>=threshold||(b+1)>=threshold||c>=threshold){ + op++; + } + else + { if(spl>0) + { + if((a+2)>=threshold||b>=threshold||c>=threshold) + { + op++; + spl--; + } + } + } + + } + } + + return op; + } +}" +A20011,"import static java.lang.Math.*; +import static java.lang.System.currentTimeMillis; +import static java.lang.System.exit; +import static java.lang.System.arraycopy; +import static java.util.Arrays.sort; +import static java.util.Arrays.binarySearch; +import static java.util.Arrays.fill; +import java.util.*; +import java.io.*; + +public class Main { + + public static void main(String[] args) throws IOException { + new Main().run(); + } + + BufferedReader in; + PrintWriter out; + StringTokenizer st = new StringTokenizer(""""); + + private void run() throws IOException { + in = new BufferedReader(new FileReader(""input.txt"")); + out = new PrintWriter(""output.txt""); + + int T = nextInt(); + for (int t = 0; t < T; t++) { + out.print(""Case #"" + (t + 1) + "": ""); + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] a = new int[n]; + for (int i = 0; i < n; i++) + a[i] = nextInt(); + int ans = 0; + for (int i = 0; i < n; i++) { + if (a[i] == 0) { + if (p == 0) + ans++; + continue; + } + if (a[i] % 3 == 0) { + if (a[i] / 3 >= p) { + ans++; + continue; + } + if (a[i] / 3 + 1 >= p && s > 0) { + ans++; + s--; + } + } + if (a[i] % 3 == 1) + if (a[i] / 3 + 1 >= p) { + ans++; + } + if (a[i] % 3 == 2) { + if (a[i] / 3 + 1 >= p) { + ans++; + continue; + } + if (a[i] / 3 + 2 >= p && s > 0) { + ans++; + s--; + } + } + } + out.println(ans); + } + + in.close(); + out.close(); + } + + void chk(boolean b) { + if (b) + return; + System.out.println(new Error().getStackTrace()[1]); + exit(999); + } + void deb(String fmt, Object... args) { + System.out.printf(Locale.US, fmt + ""%n"", args); + } + String nextToken() throws IOException { + while (!st.hasMoreTokens()) + st = new StringTokenizer(in.readLine()); + return st.nextToken(); + } + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + String nextLine() throws IOException { + st = new StringTokenizer(""""); + return in.readLine(); + } + boolean EOF() throws IOException { + while (!st.hasMoreTokens()) { + String s = in.readLine(); + if (s == null) + return true; + st = new StringTokenizer(s); + } + return false; + } +} +" +A21165,"package qualification; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; + +public class B { + static int surprise=0; + static int[] findMin(int[] a) + { + for(int i=0;ia[j]) + { + int t=a[i]; + a[i]=a[j]; + a[j]=t; + } + + return a; + + } + + static boolean checkTriplet(int a, int b, int c, int maxScore) + { + if(Math.abs(a-b)>2 || Math.abs(a-c)>2 || Math.abs(b-c)>2) + return false; + if(Math.abs(a-b)==2 || Math.abs(a-c)==2 || Math.abs(b-c)==2) + if((a>=maxScore || b>=maxScore || c>=maxScore) && surprise>0) + { + surprise--; + return true; + } + else return false; + if(a>=maxScore || b>=maxScore || c>=maxScore) + return true; + return false; + + + } + public static void main(String args[]) throws FileNotFoundException + { + Scanner sin=new Scanner(new File(""C:\\Users\\DELL\\Desktop\\CodeJam\\B-small-attempt1.in"")); + PrintStream ps=new PrintStream(new File(""C:\\Users\\DELL\\Desktop\\CodeJam\\BOut.out"")); + int cases=sin.nextInt(); + for(int i=1;i<=cases;i++) + { + int num=sin.nextInt(); + surprise=sin.nextInt(); + int maxScore=sin.nextInt(); + int count=0; + int[] scores=new int[num]; + for(int j=0;jscores[j]) + continue; + int div=scores[j]/3; + int rem=scores[j]-div; + if(rem= goal) + madeIt = true; + + int surpriseNumber = bestResult-4; + if (lastNumber >= surpriseNumber) + surprise = true; + + p(""madeIt "" + madeIt); + p(""surprise "" + surprise); + } + + public boolean surprise() + { + return surprise; + } + + public boolean madeIt() + { + return madeIt; + } + + + public static int maxNumber(int[] scores, int numSurprises, int goal) + { + int madeItCount = 0; + int surpriseCount = 0; + for (int score : scores) + { + DanceScore danceScore = new DanceScore(score); + danceScore.process(goal); + if (danceScore.madeIt()) + madeItCount++; + else if (danceScore.surprise()) + surpriseCount++; + } + + if (surpriseCount > numSurprises) + madeItCount += numSurprises; + else madeItCount += surpriseCount; + + return madeItCount; + } + + public static void main (String [] args) + { + try + { + InputStreamReader converter = new InputStreamReader(System.in); + BufferedReader in = new BufferedReader(converter); + + Integer numCases = Integer.valueOf(in.readLine()); + + for (int i = 0; i < numCases; i ++) + { + String input = in.readLine(); + String[] values = input.split("" ""); + int numPeople = Integer.valueOf(values[0]); + int numSurprises = Integer.valueOf(values[1]); + int goal = Integer.valueOf(values[2]); + int[] scores = new int[numPeople]; + for (int j = 0; j < numPeople ; j++) + { + scores[j] = Integer.valueOf(values[3+j]); + } + int maxNumber = maxNumber(scores, numSurprises, goal); + System.out.println(""Case #"" + (i+1) + "": "" + maxNumber); + } + } catch (Exception e) + { + throw new RuntimeException (e); + } + } +}" +A21309,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +/* Jin Hao Chong + * Google Code Jam 2012 Qualification Round Question 2 + * In this program, I used the Java standard library of java.io; + */ +public class Googlers { + public static void main(String args[]){ + BufferedReader in = null; + BufferedWriter out = null; + + try{ + //input and output + in = new BufferedReader(new FileReader(""B-large.in"")); + out = new BufferedWriter(new FileWriter(""Output.txt"")); + + int totalround, round, total; + String read, output; + String[] split; + int[] numbers; + + //get rounds + read = in.readLine(); + round = Integer.parseInt(read); + totalround = round; + + //Calculation + while(round > 0){ + output = ""Case #"" + (totalround - round + 1) + "": ""; + read = in.readLine(); + split = read.split("" ""); + numbers = new int[split.length]; + + for(int i = 0; i < split.length; i++){ + numbers[i] = Integer.parseInt(split[i]); + } + + int noSurpriseScore = (numbers[2] * 3) - 2; + int surpriseScore = noSurpriseScore - 2; + + if(surpriseScore < 0){ + surpriseScore = 0; + } + + if(noSurpriseScore < 1){ + total = numbers[0]; + } + else{ + + int noSurprise = 0; + int surprise = 0; + + for(int i = 3; i < numbers.length; i++){ + if(numbers[i] >= numbers[2]){ + if(numbers[i] >= noSurpriseScore) + noSurprise++; + else if(numbers[i] >= surpriseScore) + surprise++; + } + } + + if(surprise > numbers[1]) + surprise = numbers[1]; + + total = noSurprise + surprise; + + if(total > numbers[0]) + total = numbers[0]; + } + + output += total; + + //write output to file + out.write(output); + if(round != 1) out.newLine(); + round--; + } + in.close(); + out.close(); + }catch(Exception e){ + System.err.print(e); + } + } +} +" +A21258,"import java.util.Scanner; +import java.lang.Math; + +class q2{ + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + Score s = new Score(); + + int size = new Integer(sc.nextLine()); + + int j = 1; + + while(sc.hasNextLine() && size > 0){ + String str = sc.nextLine(); + String[] tok = str.split("" ""); + int nGooglers = new Integer(tok[0]); + int sTrips = new Integer(tok[1]); + int pScore = new Integer(tok[2]); + int[] tPoints = new int[nGooglers]; + + for(int i=3; i= p) + ++moreThanp; + else if(s>0 && (r == 0 || r == 2) && t[i]>1){ + ++ave; + if(ave >= p){ + ++moreThanp; + --s; + } + } + } + + return moreThanp; + } +} + + +" +A20064,"package com.gmail.bubby4j.cj2012.qual2; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Main { + public static void main(String[] args) { + //Begin-------------------------------------------------------------------------- + Scanner scanner = null; + String inputfile = ""C:\\Users\\James\\CodeJam2012\\B-large.in""; + String outputfile = ""C:\\Users\\James\\CodeJam2012\\large.out""; + BufferedWriter out = null; + Integer numcases = 0; + try { + out = new BufferedWriter(new FileWriter(outputfile)); + } catch (IOException e1) { + e1.printStackTrace(); + } + try { + scanner = new Scanner(new FileInputStream(inputfile)); + } catch (FileNotFoundException e) { + System.out.println(""File not found!""); + System.exit(1); + } + Integer thisCase = 1; + Boolean gotCase = false; + while(scanner.hasNext()){ + String line = scanner.nextLine(); + if(isInteger(line) && !gotCase){ + numcases = Integer.parseInt(line); + gotCase = true; + }else{ + System.out.println(""Case #""+thisCase); + if(thisCase < numcases){ + appendOut(""Case #"" + thisCase + "": ""+score(line)+""\n"", out); + }else{ + appendOut(""Case #"" + thisCase + "": ""+score(line), out); + } + thisCase++; + } + } + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println(""Complete!""); + //End---------------------------------------------------------------------------- + } + + + + private static String score(String line) { + String[] parts = line.split("" ""); + Integer ngooglers = Integer.parseInt(parts[0]); + Integer suprising = Integer.parseInt(parts[1]); + Integer bestresult = Integer.parseInt(parts[2]); + ArrayList scores = new ArrayList(); + for (int i = 0; i < ngooglers; i++){ + scores.add(Integer.parseInt(parts[i+3])); + } + //End parsing line + Integer maxnumbers = 0; + for (Integer score: scores) { + Integer[] thisguess = new Integer[]{0,0,0}; + Integer baseNumber = intDivision(score, 3); + thisguess[0] = baseNumber; + thisguess[1] = baseNumber; + thisguess[2] = baseNumber; + Integer addingTo = 0; + while(addArray(thisguess) < score){ + thisguess[addingTo]++; + addingTo++; + } + thisguess = reverseArray(thisguess); + + + String sup = """"; + //After all applying + if(bestScore(thisguess) >= bestresult){ + maxnumbers++; + }else if(suprising > 0 && canSuprise(thisguess)){ + //Isn't at or past the top, try to make suprising + Integer[] suprised = suprise(thisguess); + if(bestScore(suprised) >= bestresult){ + maxnumbers++; + suprising--; + thisguess = suprised; + sup = "" (*)""; + } + } + System.out.println(thisguess[0] + "" "" + thisguess[1] + "" "" + thisguess[2] + sup); + } + // return maximum number of Googlers who could have had a best result of + // greater than or equal to bestresult + return Integer.toString(maxnumbers); + } + + public static boolean canSuprise(Integer[] scores){ + if((scores[2] == scores[1] && scores[0]+1 == scores[1]) || (scores[0] == scores[1] && scores[2] - 1 == scores[1]) || (scores[0] == scores[1] && scores[1] == scores[2] && scores[0] != 0)){ + return true; + } + return false; + } + + public static Integer[] suprise(Integer[] in){ + Integer[] in2 = in.clone(); + if(in[2] == in2[1] && in2[0]+1 == in2[1]){ + in2[2]++; + in2[1]--; + return in2; + }else if(in2[0] == in2[1] && in2[2] - 1 == in2[1]){ + in2[1]++; + in2[0]--; + return in2; + }else if(in2[0] == in2[1] && in2[1] == in2[2] && in2[0] != 0){ + in2[0]--; + in2[2]++; + return in2; + } + return null; + } + + public static Integer bestScore(Integer[] thisguess){ + Integer currentBest = 0; + for (Integer score: thisguess) { + if(score > currentBest){ + currentBest = score; + } + } + return currentBest; + } + public static Integer addArray(Integer[] list){ + Integer tally = 0; + for (Integer score: list) { + tally += score; + } + return tally; + } + public static Integer[] reverseArray(Integer[] list){ + for(int i = 0; i < list.length / 2; i++){ + int temp = list[i]; + list[i] = list[list.length - i - 1]; + list[list.length - i - 1] = temp; + } + return list; + } + + public static Integer intDivision(Integer i1, Integer i2){ + //Rounds down integer division + return (int) Math.floor(i1/i2); + } + + public static boolean isInteger(String i){ + try{ + Integer.parseInt(i); + return true; + }catch(Exception e){ + return false; + } + + } + public static void appendOut(String str, BufferedWriter out){ + try { + out.append(str); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} +" +A22514,"import java.util.*; + +public class dancing_googlers { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + int T = scanner.nextInt(); + int[] answers = new int[T]; + + for (int c = 0; c < T; c++) { + + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + answers[c] = 0; + + for (int i = 0; i < N; i++) { + int t = scanner.nextInt(); + if (t >= (p + (p - 1) + (p - 1))) { + answers[c]++; + } + else if ((t >= (p + (p - 1) + (p - 1)) - 2) && (S > 0) && (t > 1) && (t < 29)) { + answers[c]++; + S--; + } + } + } + for (int c = 0; c < T; c++) { + int j = c+1; + System.out.println(""Case #""+j+"": ""+answers[c]); + } + } +} +" +A21049,"package problemB; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +public class DancingWithTheGooglers { + final static String DIRECTORY = ""ioFile""; + + final static String FNAME = ""B-large""; + + public BufferedReader in; + + public PrintWriter out; + + void open() throws IOException { + in = new BufferedReader( new FileReader( new File( DIRECTORY + ""/"" + FNAME + "".in"" ) ) ); + out = new PrintWriter( new File( DIRECTORY + ""/"" + FNAME + "".out"" ) ); + } + + void close() throws IOException { + out.close(); + } + + void run() throws IOException { + String nac = in.readLine(); + for (int i=0; i list = new ArrayList(); + for ( int j = 3; j < sa.length; j++) { + list.add(Integer.parseInt(sa[j])); + } + for ( int j =0; j=0; j++) { + int num = list.get(j); + if ( num % 3 == 0) { + if ( num/3 >= p) + count ++; + else if (num > 0 && s>0 && num/3+1 >=p) { + s--; + count++; + } + } + else if ( num % 3 == 1 && num/3 +1 >=p ) { + count ++; + } + else if ( num % 3 == 2 ) { + if ( num/3 +1 >= p) + count ++; + else if (s>0 && num/3 + 2 >=p ) { + s--; + count ++; + } + } +// if ( (num/3 ) >= p) +// count ++; +// else if (num > 0 && s>0 && (num/3 + 2) >=p ) { +// s--; +// count++; +// } + } + out.println(""Case #"" + (i+1) + "": "" + count); + } + } + + int count(String sNumber, char ch){ + int count=0; + for(int i=0;i T getSolver() { + return (T)solver; + } + + private String autoCompleteResourceName(String resource) { + if (resource.indexOf("":"") != -1) { + return resource; + } + return ""classpath:"" + + solver.getClass().getPackage().getName().replace('.', '/') + + ""/"" + resource; + } + +} +" +A22875,"package com.google.codejam.googlers; + +import java.io.FileReader; +import java.io.IOException; +import java.io.LineNumberReader; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + + +/** + * Class to read input file and prepare list of test cases. + * @author Sushant Deshpande + */ +public class InputReader { + /** + * Method for preparing List of Test Cases. + * @param inputFilePath String + * @return List + */ + public static List prepareTestCases(final String inputFilePath) { + final List testCases = new LinkedList(); + LineNumberReader lineReader = null; + try { + lineReader = new LineNumberReader(new FileReader(inputFilePath)); + final String line = lineReader.readLine(); + final int noOfTCs = Integer.parseInt(line); + for(int i = 0; i < noOfTCs; i++) { + final String [] inputLine = lineReader.readLine().split("" ""); + final int noOfGooglers = Integer.parseInt(inputLine[0]); + final int surprisingTriplets = Integer.parseInt(inputLine[1]); + final int bestScore = Integer.parseInt(inputLine[2]); + final String [] scoreArray = Arrays.copyOfRange(inputLine, 3, inputLine.length); + final int [] scores = populateScores(scoreArray); + TestCase testCase = new TestCase(i + 1, noOfGooglers, surprisingTriplets, bestScore, scores); + testCases.add(testCase); + } + } catch(IOException ie) { + System.out.println(""Problem occured while reading input file. "" + ie.getMessage()); + } finally { + if(lineReader != null) { + try { + lineReader.close(); + } catch(IOException ie) { + System.out.println(""Some problem occured while closing input file reader "" + ie.getMessage() ); + } + } + } + return testCases; + } + + /** + * Method to populate score integer array from scores read from the input file. + * @param scoreArray String[] scoreArray + * @return int [] integer array containing scores. + */ + private static int [] populateScores(String[] scoreArray) { + final int [] scores = new int[scoreArray.length]; + for(int i = 0; i < scoreArray.length; i++) { + scores[i] = Integer.parseInt(scoreArray[i]); + } + return scores; + } +}" +A22807,"import java.io.* ; +import java.text.DecimalFormat; +import java.util.*; +import static java.lang.Math.* ; +import static java.util.Arrays.* ; + +public class B { + + public static void main(String[] args) throws FileNotFoundException { + + in = new Scanner(new InputStreamReader(new FileInputStream(""b_in.txt""))); + out = new PrintStream(new BufferedOutputStream(new FileOutputStream(""b_out.txt""))); + + int n = in.nextInt() ; in.nextLine() ; + int t = 1 ; + while( n-- > 0) + new B().solveProblem(t++); + + out.close(); + } + + static Scanner in = new Scanner(new InputStreamReader(System.in)); + static PrintStream out = new PrintStream(new BufferedOutputStream(System.out)); + + + //static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + + public void solveProblem(int nr) { + out.print(""Case #"" + nr + "": "" ) ; + + int N = in.nextInt() ; + int S = in.nextInt() ; + int p = in.nextInt() ; + + int[] v = new int[N] ; + for( int i = 0 ; i < N ; i++ ) + v[i] = in.nextInt() ; + + int[] min_ns = new int[31] ; + int[] min_s = new int[31] ; + fill( min_s, -1 ); + + for( int i = 0 ; i <= 10 ; i++ ) + for( int j = i ; j <= i + 2 && j <= 10 ; j++ ) + for( int k = j ; k <= i + 2 && k <= 10 ; k++ ){ + min_s[i+j+k] = max(min_s[i+j+k],k ) ; + } + for( int i = 0 ; i <= 10 ; i++ ) + for( int j = i ; j <= i + 1 && j <= 10 ; j++ ) + for( int k = j ; k <= i + 1 && k <= 10 ; k++ ){ + min_ns[i+j+k] = max(min_ns[i+j+k],k ) ; + } + int t1 = 0 ; + int t2 = 0 ; + + for( int a : v ){ + + if( min_ns[a] >= p ) + t1++ ; + else if( min_s[a] >= p ) + t2++ ; + + } + + out.println(t1+min(t2,S)) ; + System.err.println(""Case #"" + nr + "" solved"") ; + } + + +}" +A20418,"import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +public class BSmall { + public static void get() { + try { + File inputFile = new File(""B-large.in""); + inputFile.createNewFile(); + Scanner scan = new Scanner(inputFile); + int t = Integer.parseInt(scan.nextLine()); + File out = new File(""out.txt""); + FileWriter fw = new FileWriter(out); + for (int i = 0; i < t - 1; i++) { + fw.append(""Case #"" + (i + 1) + "": ""); + int counter = 0; + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + + for (int j = 0; j < n; j++) { + int g1 = scan.nextInt(); + if (g1 == 0 && p > 0) { + continue; + } + + if (p > 0) { + int key = g1 / p; + + if (key >= 3) { + counter++; + } else { + if (key == 2) { + int talet = p + (g1 % p); + int v = talet / 2; + if (p - v == 1) { + counter++; + } else { + if (p - v == 2 && s > 0) { + counter++; + s--; + } + } + } else { + int x = g1 - p; + x = x / 2; + if (p - x == 1) { + counter++; + } else { + if (p - x == 2 && s > 0) { + s--; + counter++; + } + + } + } + + } + } else { + counter++; + } + + } + fw.append("""" + counter + ""\n""); + } + + fw.append(""Case #"" + (t) + "": ""); + int counter = 0; + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + + for (int j = 0; j < n; j++) { + int g1 = scan.nextInt(); + if (p > 0) { + int key = g1 / p; + + if (key >= 3) { + counter++; + } else { + if (key == 2) { + int talet = p + g1 % p; + int v = talet / 2; + if (p - v == 1) { + counter++; + } else { + if (p - v == 2 && s > 0) { + counter++; + s--; + } + } + } + + } + } else { + counter++; + } + } + fw.append("""" + counter); + fw.close(); + + } catch (Exception e) { + + } + } + + public static void main(String[] args) { + get(); + } + +} +" +A20035,"import java.io.*; +/** + * Write a description of class Main here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Main +{ + private static int count = 1; + + public static void main() + { + try{ + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + PrintWriter out = new PrintWriter(new FileWriter(""B_large_result.txt"")); + String a = br.readLine(); + String strLine = null; + while ((strLine = br.readLine()) != null) + { + //System.out.println(""Case #""+(count)+"": ""+count(strLine)); + out.println(""Case #""+(count++)+"": ""+count(strLine)); + } + in.close(); + out.close(); + }catch (Exception e){e.printStackTrace();} + } + + //private int n = 1; + + public static int count(String input) + { + int yes = 0; + int maybe = 0; + int del = 0; + int num = Integer.parseInt(input.substring(del,input.indexOf("" "", del))); + del = input.indexOf("" "", del)+1; + int surprising = Integer.parseInt(input.substring(del,input.indexOf("" "", del))); + del = input.indexOf("" "", del)+1; + int bestMark = Integer.parseInt(input.substring(del,input.indexOf("" "", del))); + del = input.indexOf("" "", del)+1; + int limit1 = bestMark*3-2; + + //System.out.println(""riadok ""+(n++)+"" : "" + input); + for (int i = 0; i < num; i++) + { + int value = 0; + if (i = bestMark) + if(value >= limit1) + yes++; + else if (value >= limit1-2) + maybe++; + + del = input.indexOf("" "", del)+1; + } + return yes + Math.min(maybe, surprising); + } +}" +A20477,"package dance; + +import java.util.*; + +public class dance { + public static void main(String[] args){ + Scanner input = new Scanner(System.in); + int T = input.nextInt(); + for(int l=0;l=p){ + //System.out.println(""max for ""+t[i]+"" is ""+max[i]); + ans++; + } + else if(flag && p-max[i] == 1 && s>0){ + if(!(t[i]%3==0 && t[i]/3==0)){ + ans++; + s--; + } + } + } + System.out.println(""Case #""+(l+1)+"": ""+ans); + } + } + +} +" +A21896,"import java.io.*; +import java.util.*; + +public class DancingWithTheGooglers{ + public static void main(String[] args) throws Exception{ + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); + + int n = Integer.parseInt(in.readLine()); + + for(int i = 0; i < n; ++i){ + StringTokenizer st = new StringTokenizer(in.readLine()); + int T = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] normal = new int[T]; + int[] surprising = new int[T]; + for(int j = 0; j < T; ++j){ + int sum = Integer.parseInt(st.nextToken()); + if(sum%3 == 2){ + normal[j] = sum/3+1; + if(sum/3+2 <= 10) + surprising[j] = sum/3+2; + else + surprising[j] = sum/3+1; + }else if(sum%3 == 1){ + normal[j] = sum/3+1; + surprising[j] = sum/3+1; + }else{ + normal[j] = sum/3; + if(sum/3 - 1 >= 0 && sum/3+1 <= 10) + surprising[j] = sum/3+1; + else + surprising[j] = sum/3; + } + } + int ans = 0; + for(int j = 0; j < T; ++j){ + if(S > 0 && normal[j] < p && surprising[j] >= p){ + --S; + ++ans; + }else if(normal[j] >= p){ + ++ans; + } + } + out.println(""Case #""+(i+1)+"": ""+ans); + } + out.close(); + } +} + + " +A21073,"package jam; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class CodeJam2012Q2 { + public static void main(String [] args){ + final String FILE_NAME=""B-large.in""; + StringTokenizer st; + + //IOUsage Variables + String lineIn=""""; + int numCases=0; + + //Index Variables + + //Contest Vars + int numGooglers = 0; + int numSurprising = 0; + int atLeastResult = 0; + int[] googlerScores; + + int numGP = 0; + + try + { + BufferedReader br = new BufferedReader(new FileReader(FILE_NAME)); + lineIn = br.readLine(); + numCases = Integer.parseInt(lineIn); + for(int i=0; i0) + { + numGP++; + numSurprising--; + } + } + } + else + { + if((googlerScores[j] % 3) == 0) + { + if((googlerScores[j]/3) - atLeastResult > -1 ) + { + numGP++; + } + else if((((googlerScores[j]/3) - atLeastResult) == -1) && numSurprising>0) + { + numGP++; + numSurprising--; + } + } + else if((googlerScores[j] % 3) == 1) + { + if (((googlerScores[j]/3)+1) - atLeastResult >= 0) + { + numGP++; + } + } + else if((googlerScores[j] % 3) == 2) + { + if((googlerScores[j]/3) - atLeastResult + 1 > -1 ) + { + numGP++; + } + else if((((googlerScores[j]/3) - atLeastResult + 1) == -1) && numSurprising>0) + { + numGP++; + numSurprising--; + } + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+numGP); + + numGP=0; + } + } + catch(IOException ioe) + { + ioe.printStackTrace(); + } + + + } +} +" +A23050,"package codejam; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class Dancing { + Scanner in; + PrintWriter out; + int N; + int P, S; + + public void solve() throws IOException { + int tn = in.nextInt(); + in.nextLine(); + for (int test = 1; test <= tn; test++) { + String line = in.nextLine(); + String[] numbers = line.split("" ""); + N = Integer.parseInt(numbers[0]); + S = Integer.parseInt(numbers[1]); + P = Integer.parseInt(numbers[2]); + int[] x = new int[N]; + for (int i = 0; i < N; i++) { + x[i] = Integer.parseInt(numbers[3 + i]); + } + out.println(""Case #"" + test + "": "" + calculate(x)); + } + } + + boolean[] moreThanP = new boolean[N]; + boolean[] isSurprising = new boolean[N]; + boolean[] isSurprisingAndMoreThanP = new boolean[N]; + boolean[] seen = new boolean[N]; + + private int calculate(int[] x) { + moreThanP = new boolean[N]; + isSurprising = new boolean[N]; + isSurprisingAndMoreThanP = new boolean[N]; + seen = new boolean[N]; + int res = 0; + Arrays.sort(x); + //ArrayUtils.reverse(x); + for (int i = 0; i < x.length; i++) { + generate(x, i); + } + + int i = 0; + int s = S; + while (i < N && s > 0) { + if (isSurprisingAndMoreThanP[i]) { + s--; + res++; + seen[i] = true; + } + i++; + } + i = 0; + while (i < N && s > 0) { + if (!seen[i] && isSurprising[i]) { + s--; + seen[i] = true; + } + i++; + } + + i = 0; + while (i < N) { + if (!seen[i] && moreThanP[i]) { + res++; + seen[i] = true; + } + i++; + } + + return res; + } + + private void generate(int[] x, int index) { + for (int a = 10; a >= 0; a--) + for (int b = 10; b >= 0; b--) + for (int c = 10; c >= 0; c--) { + if (a + b + c == x[index] && isValid(a, b,c)) { + if (getMax(a,b,c) >= P) { + if (isSurprising(a, b, c)) { + isSurprisingAndMoreThanP[index] = true; + } else { + moreThanP[index] = true; + } + } + else if (isSurprising(a, b, c)) { + isSurprising[index] = true; + } + } + } + } + + + private boolean isValid(int a, int b, int c) { + return Math.abs(a - b) <= 2 && Math.abs(b - c) <= 2 && Math.abs(c - a) <= 2; + } + + private boolean isSurprising(int a, int b, int c) { + return Math.abs(a - b) == 2 || Math.abs(b - c) == 2 || Math.abs(c - a) == 2; + } + + private int getMax(int a, int b, int c) { + return Math.max(Math.max(a, b),c ); + } + + + public void run() { + try { + in = new Scanner(Googlerese.class.getResourceAsStream(""/resources/B-large.in"")); + out = new PrintWriter(new File(""/tmp/ProblemB.out"")); + + solve(); + + in.close(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] arg) { + new Dancing().run(); + } + + +} +" +A20497,"import static java.util.Arrays.sort; + +import java.io.*; +import java.util.*; + +public class ProblemB { + public static void main(String[] args) throws Throwable { + Scanner in = new Scanner(new File(""b.in"")); + PrintWriter out = new PrintWriter(""b.out""); + int testCount = Integer.parseInt(in.nextLine().trim()); + for (int i = 0; i < testCount; i++) { + out.print(""Case #"" + (i + 1) + "": ""); + solve(in, out); + } + out.close(); + } + + static void solve(Scanner in, PrintWriter out) { + int n = in.nextInt(); + int m = in.nextInt(); + int p = in.nextInt(); + int[] a = new int[n]; + for (int i = 0; i < n; i++) { + a[i] = in.nextInt(); + } + sort(a); + int ans = 0; + for (int i = n - 1; i >= 0; i--) { + int z = (a[i] + 2) / 3; + if (z >= p) { + ++ans; + continue; + } + if (p >= 2 && z == p - 1 && a[i] % 3 != 1 && m > 0) { + --m; + ++ans; + } else { + break; + } + } + out.println(ans); + } +} +" +A22074,"package hk.polyu.cslhu.codejam; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import hk.polyu.cslhu.codejam.lib.FileStream; +import hk.polyu.cslhu.codejam.lib.ResultCollector; +import hk.polyu.cslhu.codejam.solution.Solution; +import hk.polyu.cslhu.codejam.solution.impl.StoreCredit; +import hk.polyu.cslhu.codejam.solution.impl.qualificationround.DancingWithTheGooglers; +import hk.polyu.cslhu.codejam.solution.impl.qualificationround.SpeakingInTongues; +import hk.polyu.cslhu.codejam.thread.JamThreadManager; + +/** + * Hello world! + * + */ +public class App +{ + public static Logger logger = Logger.getLogger(App.class); + + public List> getTestCaseList(String filePath) { + List> testCaseList = new ArrayList>(); + List content = FileStream.read(filePath); + logger.info(""The amount of lines: "" + content.size()); + logger.info(""The amount of test cases: "" + content.get(0)); + + for (int i = 1; i < content.size(); i++) + testCaseList.add(content.subList(i, i + 1)); + + return testCaseList; + } + + public static void main( String[] args ) + { + String filePath = ""C:\\Users\\Allen HU\\Dropbox\\Misc\\B-large.in""; + String resultFile = filePath + "".result""; + String resultPattern = ""Case #"" + ResultCollector.IndexPartInRow + "": "" + ResultCollector.ResultPartInRow + ""\n""; + boolean allowMultiThreads = true; + + List> testCaseList = new App().getTestCaseList(filePath); + + Solution solution = new DancingWithTheGooglers(); + + JamThreadManager jtm = new JamThreadManager(solution, testCaseList, resultFile, resultPattern, allowMultiThreads); + try { + jtm.runThreads(); + } catch (CloneNotSupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} +" +A21408,"import java.io.*; + +public class Dancing { + + public static void main (String[] args) throws IOException { + BufferedReader input = new BufferedReader(new FileReader (args[0])); + FileWriter output = new FileWriter(""dancingOutput.txt""); + int numTests = Integer.parseInt(input.readLine()); + for (int test = 1; test <= numTests; test++) { + output.write(""Case #"" + test + "": ""); + String testCase = input.readLine(); + String[] split = testCase.split("" ""); + int[] nums = new int[split.length - 3]; + int numGooglers = Integer.parseInt(split[0]); + int surprising = Integer.parseInt(split[1]); + int maxScore = Integer.parseInt(split[2]); + int firstScore = maxScore + Math.max(maxScore-1, 0)*2; + int secondScore = maxScore + Math.max(maxScore-2, 0)*2; + for (int i = 3; i < split.length; i++) { + nums[i-3] = Integer.parseInt(split[i]); + } + int sum = 0; + for (int i = 0; i < nums.length; i++) { + if (nums[i] >= firstScore) { + sum++; + } else if (surprising > 0 && nums[i] >= secondScore) { + sum++; + surprising--; + } + } + output.write(sum + ""\n""); + } + output.flush(); + } + +} +" +A20401,"package qualification.taskA; + +import java.util.HashMap; +import java.util.Map; + +import Parser.MyReader; +import Parser.MyWriter; + +public class Main { + public static void main(String[] args) { + MyReader myReader = new MyReader( + ""/Users/shami13/Downloads/A-small-attempt0.in""); + MyWriter myWriter = new MyWriter(""/Users/shami13/Downloads/A-small-attempt0.out""); + + Map dictionary = createDictionary(); + + int taskLength = Integer.parseInt(myReader.read()); + + + for (int i = 1; i <= taskLength; i++) { + String taskString = myReader.read(); + Task task = new Task(dictionary); + String result = task.execute(taskString); + myWriter.writeString(""Case #"" + i + "": "" + result); + System.out.println(""Case #"" + i + "": "" + result); + } + myWriter.close(); + } + + private static Map createDictionary() { + Map result = new HashMap(); + result.put('q', 'z'); + result.put('z', 'q'); + + + String[] originals = { ""ejp mysljylc kd kxveddknmc re jsicpdrysi"", + ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"", + ""de kr kd eoya kw aej tysr re ujdr lkgc jv"" }; + + String[] results = { ""our language is impossible to understand"", + ""there are twenty six factorial possibilities"", + ""so it is okay if you want to just give up"" }; + + for(int i = 0; i < originals.length; i++){ + for(int p = 0; p < originals[i].length(); p++){ + if (!result.containsKey(originals[i].charAt(p))){ + result.put(originals[i].charAt(p), results[i].charAt(p)); + } + } + } + + return result; + } +} +" +A20160,"import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +/** + * @author: Ahmad Medhat Othman + * @codeJame: AMedOs + * @topCoder: AMedOs + * @email :amedhat.cs@gmail.com + * */ +public class B { + + + public static void main(String[] args) throws Exception { + // Input file + //A-small.in + //A-large.in + String in = ""B-large.in""; + + FileInputStream fin = new FileInputStream(in); + Scanner scn = new Scanner(fin); + + // Output file + String out = ""B.out""; + FileOutputStream fout = new FileOutputStream (out); + PrintStream ps = new PrintStream(fout); + + int T=0; + T = scn.nextInt(); + + int t,i,k=0; + int n,s,p,num,rem,res=0; + for (t=1 ; t<= T ; t++) { + res=0; + n = scn.nextInt(); + s = scn.nextInt(); + p = scn.nextInt(); + for (i=0;i=p){ + res++; + } else{ + if (rem == 0){ + if (num+1 >= p && s>0 && num>0){ + res++; + s--; + } + } + if (rem == 1){ + if (num+1 >= p){ + res++; + } + } + if (rem == 2){ + if (num+1 >=p){ + res++; + } else if (num+2 >= p && s>0){ + res++; + s--; + } + } + } + } + ps.println(""Case #"" + t + "": "" + res); + } + + fout.close(); + fin.close(); + System.out.println(""Done:.......""); + System.exit(0); + } +} +" +A22954,"import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + + +public class b { + public static void main(String[] args){ + new b().go(); + } + + private void go() { + Scanner in=new Scanner(System.in); + int numc=in.nextInt(); + for(int cnum=1;cnum<=numc;cnum++){ + int n=in.nextInt(),s=in.nextInt(),p=in.nextInt(); + ArrayLista=new ArrayList(); + for(int i=0;i=p&&i>=p)count++; + else if(s>0&&(i+4)/3>=p&&i>=p){ + count++; + s--; + } + } + System.out.printf(""Case #%d: %d\n"", cnum,count); + } + } + +}" +A21547,"package com.jp.common; + +public interface Puzzle { + + public String[] solve(String[] dataSet ); + +} +" +A20107,"package org.alaoui.googledance; + +import java.io.IOException; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest extends TestCase { + /** + * Create the test case + * + * @param testName + * name of the test case + */ + public AppTest(String testName) { + super(testName); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(AppTest.class); + } + + /** + * Rigourous Test :-) + * + * @throws IOException + */ + public void testApp() { + + } +} +" +A20169,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class GoogleDancers { + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String s = br.readLine(); + int numberOfTestCases = Integer.parseInt(s); + + StringBuffer output = new StringBuffer(); + for (int i = 1; i <= numberOfTestCases; i++) { + String testCase = br.readLine().trim(); + String[] inputparams = testCase.split("" ""); + + long N, S, p; + long totalPoints[] = new long[110]; + + N = Long.parseLong(inputparams[0]); + S = Long.parseLong(inputparams[1]); + p = Long.parseLong(inputparams[2]); + + for (int j = 3; j <= N + 2; j++) { + totalPoints[j - 3] = Long.parseLong(inputparams[j]); + } + + String outputString = solveTestCase(N, S, p, totalPoints); + + if (i != 1) { + output.append(""\n""); + } + + output.append(""Case #"" + i + "": ""); + output.append(outputString); + } + + System.out.println(output); + } + + private static String solveTestCase(long N, long S, long p, long[] totalPoints) { + long maxNoOfBest = 0; + long possibleSuprises = 0; + + for (int i = 0; i < N; i++) { + int totalPnts = (int) totalPoints[i]; + int oneScore = totalPnts / 3; + int mod = totalPnts % 3; + + if (mod >= 1) { + if (oneScore >= p || (oneScore + 1) >= p) { + maxNoOfBest++; + } else if (oneScore + mod >= p) { + possibleSuprises++; + } + } else { + if (oneScore >= p) { + maxNoOfBest++; + } else if (oneScore > 0 && oneScore + 1 >= p) { + possibleSuprises++; + } + } + } + + if (possibleSuprises < S) { + maxNoOfBest = maxNoOfBest + possibleSuprises; + } else { + maxNoOfBest = maxNoOfBest + S; + } + + return String.valueOf(maxNoOfBest); + } +} +" +A21505,"package j2012qualifier; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class B { + public static String inputDirectory=""src/j2012qualifier/""; + public static String inputFile=""B.in""; + public static String outputFile=""B.out""; + public static PrintWriter output; + public static void main(String[] args) throws FileNotFoundException{ + Scanner s=new Scanner(new File(inputDirectory + inputFile)); + output=new PrintWriter(new File(inputDirectory + outputFile)); + int cases = s.nextInt(); + for(int Case=1;Case<=cases;Case++){ + s.nextLine(); + int googlers = s.nextInt(); + int maxSupriseScores = s.nextInt(); + int targetScore = s.nextInt(); + int normalScores = 0; + int surpriseScores = 0; + for(int i=0;i< googlers; i++) { + int score = s.nextInt(); + if (targetScore > score) { + continue; + } + int otherScore = (score - targetScore) / 2; + if (otherScore >= targetScore - 1) { + normalScores++; + } else if(otherScore >= targetScore - 2) { + surpriseScores++; + } + } + int answer = normalScores + Math.min(surpriseScores, maxSupriseScores); + out(""Case #""+Case+"": ""+answer); + } + output.flush(); + } + + public static void out(String s){ + output.println(s); + //System.out.println(s); + } +}" +A20844,"package Test1; + + +import java.io.BufferedReader; +import java.io.InputStreamReader; + + + + +public class Test1 { + + static String[] orig = {""ejp mysljylc kd kxveddknmc re jsicpdrysi"", ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"",""de kr kd eoya kw aej tysr re ujdr lkgc jv""}; + static String[] target = {""our language is impossible to understand"",""there are twenty six factorial possibilities"",""so it is okay if you want to just give up""}; + static int[] map = new int[26]; + static int[] hash = new int[26]; + public static void main(String[] args) { + + int n,s,p,T; + int[] t = new int[31]; + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) ; + try { + + String str = in.readLine(); + int result,vaildp,tempmax; + n = Integer.parseInt(str.trim()); + for (int i = 1; i <= n; i++) { + str = in.readLine(); + String[] temp = str.split("" ""); + T = Integer.parseInt(temp[0]); + s = Integer.parseInt(temp[1]); + p = Integer.parseInt(temp[2]); + result = 0; + vaildp = 0; + for (int j=3; j= p) result++; + else { + tempmax = numtemp / 3; + if (numtemp % 3 == 1) tempmax = tempmax +1; + else if (numtemp % 3 == 2) tempmax = tempmax +2; + else if (tempmax > 0) tempmax = tempmax + 1; + if (tempmax >= p) vaildp++; + } + //System.out.println(""num=""+numtemp+"";max=""+max+"";vild=""+vaildp); + } + if (vaildp > s) vaildp = s; + result = result + vaildp; + if (result > T) result = T; + System.out.println(""Case #""+i+"": ""+result); + //System.out.println(""""); + } + } catch (Exception e) { + + } + } +} + +" +A20055,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package google.code.jam.dancing.with.the.googlers; + +import java.util.ArrayList; + +/** + * + * @author Lucas + */ +public class BestResultFinder { + + public ArrayList findBestResult(ArrayList list) { + + ArrayList result = new ArrayList(); + ArrayList current; + int total; + int surprising; + int min; + int value; + + for (int n = 0; n < list.size(); n++) { + + current = list.get(n); + total = 0; + surprising = current.get(1); + min = current.get(2); + + for (int m = 0; m < current.get(0); m++) { + + value = current.get(3 + m) / 3; + + switch (current.get(3 + m) % 3) { + + // (n, n, n) -> Regular + // (n - 1, n , n + 1) -> Surprising + + case 0: { + + if (value >= min) { + total++; + } else if ((surprising > 0) && (value > 0) && (value + 1 >= min)) { + total++; + surprising--; + } + break; + } + + // (n, n, n + 1) -> Regular + // (n - 1, n + 1, n + 1) -> Surprising + + case 1: { + if ((value >= min) || (value + 1 >= min)) { + total++; + } else if ((surprising > 0) && (value + 1 >= min)) { + total++; + surprising--; + } + break; + } + + // (n, n + 1, n + 1) -> Regular + // (n, n, n + 2) -> Surprising + + case 2: { + if ((value >= min) || (value + 1 >= min)) { + total++; + } else if ((surprising > 0) && (value + 2 >= min)) { + total++; + surprising--; + } + break; + } + } + } + result.add(total); + } + return result; + } +} +" +A22974,"import static java.lang.System.in; +import static java.lang.System.out; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Dancing { + + + public static void main(String[] args) throws IOException { + Scanner asdf = new Scanner(in); + Scanner file = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + int t = file.nextInt(); + + for(int r=1; r<=t; r++){ + run(r, file, out, asdf); + } + + out.close(); + } + + public static void run(int r, Scanner file, PrintWriter out, Scanner asdf){ + + int n = file.nextInt(); + int s = file.nextInt(); + int p = file.nextInt(); + int count = 0; + int[] ds = new int[n]; + //int sc[] = new int[3]; + + for(int a=0; a=goal) + count++; + else if(s>0 && i>=2 && (i+2)>=goal){ + count++; + s--; + } + + } + + //System.out.println(count); + //System.out.println(); + + out.println(""Case #""+r+"": ""+count); + } + + /*public static void run(int r, Scanner file, PrintWriter out, Scanner asdf){ + + int n = file.nextInt(); //3 # googlers + int s = file.nextInt(); //3 # surprises + int p = file.nextInt(); //10 score search + int count = 0; + + int[] ds = new int[n]; + for(int a=0; a10){ + sc[1] += sc[2]-10; + sc[2] = 10; + } + if(sc[2]

=p){ + if(s>0 && (sc[2]-sc[1]==2 || sc[2]-sc[0]==2)){ + s--; + count++; + } + else if(sc[2]-sc[1]<2 && sc[2]-sc[1]<2) + count++; + } + else if(s>0 && sc[2]-sc[1]<=1 && sc[2]-sc[0]<=1 && (sc[0]!=0 && sc[1]!=0 && sc[2]!=0)){ + sc[2]++; + if(sc[2]==p){ + s--; + count++; + } + } + //if(sc[0]==-1 && p!=0) + //count--; + + System.out.println(sc[0]+"" ""+sc[1]+"" ""+sc[2]+"" ""+s+"" ""+count); + } + System.out.println(r+"" ""+n+"" ""+p); + System.out.println(); + //out.println(""Case #""+r+"": ""+count); + }*/ + +} + + + + + + + +/*for(int i:ds){ +sc[0] = i/3; +sc[1] = i/3; +sc[2] = i-sc[0]-sc[1]; + +if(sc[2]>10){ + sc[1] += sc[2]-10; + sc[2] = 10; +} + +if(sc[2]>=p){ + if(sc[2]-sc[1]<=1) + count++; + else if(s>0){ + s--; + count++; + } + break; +} +}*/" +A21856,"package codejam2012qual; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.util.Arrays; + +import util.InputReader; + +public class DancingGooglers implements Runnable { + + private InputReader in; + private PrintWriter out; + private static String delimiter = "" ""; + + public static void main(String[] args) { + new Thread(new DancingGooglers()).start(); + } + + public DancingGooglers() { + try { + BufferedReader buffer = new BufferedReader(new FileReader(""d:\\B-large.in"")); + in = new InputReader(buffer); + + System.setOut(new PrintStream(new FileOutputStream(""d:\\output.txt""))); + out = new PrintWriter(System.out); + + } catch (FileNotFoundException e) { + throw new RuntimeException(); + } + } + + @Override + public void run() { + + int numTests = in.readInt(); + + for (int testNumber = 0; testNumber < numTests; testNumber++) { + + out.print(""Case #"" + (testNumber + 1) + "": ""); + + String line = in.readString(); + String[] strVector = line.split(delimiter); + + int numbers = Integer.parseInt(strVector[0]); + if (numbers == 0) { + out.println(0); + continue; + } + + int surTriplets = Integer.parseInt(strVector[1]); + int target = Integer.parseInt(strVector[2]); + + int[] scores = new int[numbers]; + for(int i=0; i=0 && surTriplets>=0 ; i--) { + //out.print(scores[i]/3.0+""\t""); + + if((scores[i] - target) >= 2*(target-1) && (scores[i] - target)>=0) + counter++; + else if(surTriplets > 0) { + if((scores[i] - target) >= 2*(target-2) && (scores[i] - target)>=0) { + counter++; + surTriplets--; + } + } + else + break; + } + out.println(counter); + } + out.close(); + } + +} +" +A22801,"public class P { + + public static void main(String[] arg) { + + //greedyPossibleTuple(new int[] {29,20,8,18, 18,21},8,2); + //greedyPossibleTuple(new int[] {8,0}, 1,1); + //greedyPossibleTuple(new int[] {23, 22, 21, 20, 29}, 8, 0); + //System.out.println(parseLine(""6 2 8 29 20 8 18 18 21"")); + + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + try { + String line; + java.util.ArrayList lines = new java.util.ArrayList(); + while((line = in.readLine())!=null) { + lines.add(line); + } + + for(int i=1;i=least) { + scount++; + marker[i]=true; + //System.out.println(""S:""+data[i]+"",""+m); + } + } + + int count = scount; + for(int i=0;i= least) { + //System.out.println(""A:""+data[i]); + if(marker[i]) { + scount--; + } else { + marker[i] = true; + count++; + } + } + } + + if(scount > maxsup) { + count -= (scount - maxsup ); + } + //System.out.println(count + "","" +scount + "","" + maxsup); + + //System.out.println(""....""); + + return count; + } + + public static int computeTuple(int a, boolean s) { + int min = (int)Math.floor((double)a/3); + + int g = s?2:1; + int[] mines = {min, min, min}; + + int i=0; + int j=1; + + if(mines[0]+mines[1]+mines[2] == a && gg) i=0; + } + j++; + } + + //System.out.println(mines[0]); + return mines[0]; + } +} +" +A22633,"package com.evolve.codejam2012.qualification; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Dancing { + + private static final String TEST_FILE = ""B-large.in""; + private PrintWriter pw = null; + private BufferedReader br = null; + + Dancing(boolean skip) throws IOException { + + + String outFile = TEST_FILE.replace("".in"", "".out""); + System.out.println(outFile); + this.pw = new PrintWriter(new FileWriter(outFile)); + if (skip) + return; + + File file = new File(TEST_FILE); + if (file.exists()) { + br = new BufferedReader(new java.io.FileReader(TEST_FILE)); + } else { + br = new BufferedReader(new InputStreamReader(System.in), 1 << 16); + } + } + + void doit() throws NumberFormatException, IOException { + int testsNumber = Integer.parseInt(br.readLine()); + + System.out.println(testsNumber); + + for (int i = 1; i <= testsNumber; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + + int N = Integer.parseInt( st.nextToken() ); // number of googlers 1 <= N <= 3. + int S = Integer.parseInt( st.nextToken() ); // number of surprising triplets of scores 0 <= S <= N. + int p = Integer.parseInt( st.nextToken() ); // minimal result 0 <= p <= 10. + + int[] scores = new int[N]; + for (int j = 0; j < N; j++) { + scores[j] = Integer.parseInt( st.nextToken() ); // 0 <= ti <= 30. + } + + // non surprising + boolean[] nonsurpising = new boolean[N]; + int counter = 0; + for (int score : scores) { + //nonsurpising[counter] = false; + + if (score % 3 == 0) { + int a = score / 3; + if (a >= p) { + nonsurpising[counter] = true; + } + } + if (score >= 1 && (score-1) % 3 == 0) { + int a = (score-1) / 3 + 1; + if (a >= p) { + nonsurpising[counter] = true; + } + } + if (score >= 2 && (score-2) % 3 == 0) { + int a = (score-2) / 3 + 1; + if (a >= p) { + nonsurpising[counter] = true; + } + } + counter++; + } + + // surprising + boolean[] surpising = new boolean[N]; + if (S > 0) { // tylko gdy sa jakies + // zakladamy ze kazdy jest surprising + + counter = 0; + for (int score : scores) { + //surpising[counter] = false; + + if (score >= 3 && (score-3) % 3 == 0) { + int a = (score-3) / 3 + 2; + if (a >= p) { + surpising[counter] = true; + } + } + + if (score >= 2 && (score-2) % 3 == 0) { + int a = (score-2) / 3 + 2; + if (a >= p) { + surpising[counter] = true; + } + } + + if (score >= 4 && (score-4) % 3 == 0) { + int a = (score-4) / 3 + 2; + if (a >= p) { + surpising[counter] = true; + } + } + + counter++; + } + } + + System.out.println(""nonsurprising: "" + Arrays.toString(nonsurpising)); + System.out.println(""surprising: "" + Arrays.toString(surpising)); + + int max = 0; + for (int k = 0; k < N; k++) { + if (nonsurpising[k]) { + max++; + } else if (S > 0 && surpising[k]) { + max++; + S--; + } + } + + pw.println(""Case #"" + i + "": "" + max); + } + pw.flush(); + pw.close(); + } + + public static void main(String[] args) throws NumberFormatException, IOException { + new Dancing(false).doit(); + + } + +} +" +A21055,"package main; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.StringTokenizer; + +public class QualificationB { + + public static void main(String[] args) throws IOException { + String sampleIn = ""input/b_sample.in""; + String sampleOut = ""output/b_sample.out""; + + String smallIn = ""input/B-small-attempt0.in""; + String smallOut = ""output/B-small-attempt0.out""; + + String largeIn = ""input/B-large.in""; + String largeOut = ""output/B-large.out""; + + + String inFile = largeIn; + String outFile = largeOut; + + FileWriter fstream = new FileWriter(outFile); + BufferedWriter out = new BufferedWriter(fstream); + + int ncase = 0; + for(TestCase tc : loadCodeLines(inFile)) { + int withoutSurprises = 0; + int withSurprises = 0; + for (int s : tc.scores) { + if (canMakeWithoutSurprise(tc.p, s)) { + withoutSurprises++; + } else if (canMakeWithSurprise(tc.p, s)) { + withSurprises++; + } + } + ncase++; + System.out.println(""Case #"" + ncase + "": "" + (withoutSurprises + Math.min(tc.s, withSurprises))); + out.write(""Case #"" + ncase + "": "" + (withoutSurprises + Math.min(tc.s, withSurprises)) + ""\n""); + + //System.out.println(""n="" + tc.n + "" s="" + tc.s + "" p="" + tc.p + "" scores="" + tc.scores.toArray()); + } + out.close(); + } + + private static boolean canMakeWithoutSurprise(int p, int score) { + int rem = score - p; + if (rem < 0) return false; + int lower = rem / 2; + return lower >= Math.max(p-1, 0); + } + + public static boolean canMakeWithSurprise(int p, int score) { + int rem = score - p; + if (rem < 0) return false; + int lower = rem / 2; + return lower >= Math.max(p-2, 0); + } + + public static List loadCodeLines(String filename){ + List cases = new LinkedList(); + try{ + BufferedReader reader = new BufferedReader(new FileReader(filename)); + String tString = reader.readLine(); + int t = Integer.parseInt(tString); + for(int i=0; i scores = new LinkedList(); + while(tokenizer.hasMoreTokens()) { + int score = Integer.parseInt(tokenizer.nextToken("" \n"")); + scores.add(score); + } + cases.add(new TestCase(n,s,p,scores)); + } + } catch(Exception e){ + e.printStackTrace(); + throw new RuntimeException(""can't load "" + filename + ""!""); + } + return cases; + } + + private static class TestCase { + public int n, s, p; + public List scores; + public TestCase(int n, int s, int p, List scores) { + this.n = n; + this.s = s; + this.p = p; + this.scores = scores; + } + } + +} +" +A20708,"package test; +import java.io.*; + +public class Test { + + static public void magic(String tmp, int Result [],int index ){ + int N=0,S=0,P=0,size; + char Carr []= new char[300]; + size=tmp.length(); + tmp.getChars(0, size, Carr, 0); + + int i=0,j=0,spc=0; + String bom; + while (spc<3){ + + if(Carr[j]!=' '){ + j++; + }else{ + bom=tmp.substring(i, j); + if(spc==0) + N=Integer.parseInt(bom); + if(spc==1) + S=Integer.parseInt(bom); + if(spc==2) + P=Integer.parseInt(bom); + spc++; + j++; + i=j; + } + } + + int counter=N; + int bomnum,nosur,sur,ans=0; + nosur=((P-1)*2)+P; + sur=((P-2)*2)+P; + if(sur<0) + sur=1; + while (counter>0){ + if(Carr[j]!=' '&&j=nosur){ + ans++; + }else if(bomnum>=sur && S>0){ + ans++; + S--; + } + j++; + i=j; + counter--; + } + } + + Result[index]=ans; + + } + + public static void main(String[] args) { + + //////// + int index=0,T,casenum=1,j; + String tmp; + + int Result[]=new int [101]; + + //////// + + BufferedReader reader; + reader = new BufferedReader(new InputStreamReader(System.in)); + try { + tmp = reader.readLine(); + T=Integer.parseInt(tmp); + + j=T; + while(j!=0){ + tmp = reader.readLine(); + magic (tmp,Result,index); + + index++; + j--; + } + + j=T; + while(j!=0){ + System.out.println(""Case #""+casenum+"": ""+Result[casenum-1]); + casenum++; + j--; + } + + + } catch (IOException e) { + e.printStackTrace(); + } + } +}" +A21070,"package com.googlecode.codejam.model; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; + +public class JamResolver { + + private final JamCaseResolverFactory jamCaseResolverFactory; + + private final File input; + + private final File output; + + public JamResolver(JamCaseResolverFactory jamCaseResolverFactory, String parentDirectory, String fileName) { + this.jamCaseResolverFactory = jamCaseResolverFactory; + if(!new File(parentDirectory).exists()) + parentDirectory = Constants.PARENT_DIRECTORY + parentDirectory; + this.input = new File(parentDirectory, fileName); + this.output = new File(parentDirectory, fileName.replaceFirst(""\\.in$"", "".out"")); + } + + public void resolve() throws Exception { + System.out.println(""Started computation, resolver: "" + jamCaseResolverFactory.getClass().getPackage().getName()); + System.out.println(""Input\tFile: "" + input.getAbsolutePath()); + System.out.println(""Output\tFile: "" + output.getAbsolutePath()); + final ExecutorService executor = Executors.newFixedThreadPool(1); + try { + final Iterator lineIterator = FileUtils.lineIterator(input, ""UTF-8""); + final int caseNumber = Integer.parseInt(lineIterator.next()); + final List> solutions = new ArrayList>(caseNumber); + for (int i = 1; i <= caseNumber; i++) { + solutions.add(executor.submit(jamCaseResolverFactory.newJamCaseResolver(i, lineIterator))); + } + final BufferedWriter solutionFile = new BufferedWriter(new OutputStreamWriter(FileUtils.openOutputStream(output))); + int count = 1; + try { + for (Future future : solutions) { + solutionFile.append(""Case #"").append(String.valueOf(count++)).append("": ""); + solutionFile.append(future.get()); + solutionFile.newLine(); + } + } finally { + IOUtils.closeQuietly(solutionFile); + } + } finally { + executor.shutdown(); + } + System.out.println(""Ended computation""); + } + +} +" +A22466,"import com.sun.org.apache.bcel.internal.generic.AALOAD; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class RecycledNum extends JamProblem { + public static void main(String[] args) throws IOException { + RecycledNum p = new RecycledNum(); + p.go(); + } + + @Override + String solveCase(JamCase jamCase) { + RecNCase ca = (RecNCase) jamCase; + int res = 0; + for (int n = ca.A; n < ca.B; n++) { + String m = """"; + //print(""n ""+n); + Set bag = new HashSet<>(); + int length = intLength(n); + for (int t = 1; t < length; t++) { + int pow = (int) Math.pow(10, t); + int pow2 = (int) Math.pow(10,length-t); + int f = (n / pow); + int s = n - (pow * f); + int cand = f + (pow2 * s); + //print(""m "" + cand); + if (cand < ca.A || cand > ca.B || cand <= n) { + continue; + } + if (bag.contains(cand)) { + continue; + } + if (intLength(cand) != intLength(n)) { + continue; + } + res++; + bag.add(cand); + //print(""""+ n+ "" "" + cand); + } + } + return """" + res; + } + + private void print(String m) { + System.out.println(m); + } + + private int intLength(int n) { + return Integer.toString(n).length(); + } + + @Override + JamCase parseCase(List file, int line) { + RecNCase ca = new RecNCase(); + ca.lineCount = 1; + String s = file.get(line); + int[] ints = JamUtil.parseIntList(s, 2); + ca.A = ints[0]; + ca.B = ints[1]; + return ca; + } +} + +class RecNCase extends JamCase { + int A, B; +} +" +A21190,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam.lib; + +public interface InputConverter { + + boolean readLine(String data); + T generateObject(); + +} +" +A21919,"import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Scanner; +import java.util.Set; +import java.util.HashSet; + +public class CodeJamB { + + public static int[][] matrix; + public static boolean[][] had; + public static boolean[][] down; + public static char[][] result; + public static int height; + public static int width; + + public static void readLoop(File dataInput) throws Exception{ + Scanner scan = new Scanner(dataInput); + + int caseNumber = 0; + int cases = 0; + + if (scan.hasNext()){ + cases = scan.nextInt(); + } + + while (scan.hasNext()) { + caseNumber++; + int result = 0; + int googlers = scan.nextInt(); + int surprising = scan.nextInt(); + int leastP = scan.nextInt(); + int minS = leastP*3-4; + if (minS<2) + minS=2; + int min = leastP*3-2; + for (int i = 0; i < googlers; i++){ + int score = scan.nextInt(); + if (score>=min){ + result++; + } else if (surprising>0 && score>=minS){ + surprising--; + result++; + } + } + printAnswer(caseNumber, """"+result); + } + scan.close(); + } + + public static void main (String args[]) { + // check arguments and grab input files + if (args.length==1) { + // check if the filenames in the arguments exist + File dataInput = new File(args[0]); + if (dataInput.exists()) { + try { + readLoop(dataInput); + } catch (Exception e) { + println(""An error occurred""); + println(e.toString()); + } + } else { + println(""File does not exist""); + } + } else { + println(""Incorrect number of arguments""); + } + } + + public static void printAnswer(int caseNumber, String answer){ + System.out.println(""Case #""+caseNumber+"": ""+answer); + } + + public static void println(String out){ + System.out.println(out); + } +} +" +A21366,"package com.dennis.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class DancingGoogle { + + /** + * @param args + */ + + public static void main(String[] args) throws IOException{ + + + BufferedReader fin = new BufferedReader(new FileReader(""dancing.in"")); + PrintWriter fout = new PrintWriter(new BufferedWriter(new FileWriter(""dancing.out""))); + + StringTokenizer stringy; + + int times = Integer.parseInt(fin.readLine()); + + + for(int x= 0 ; x=limit) count++; + } + + fout.println(""Case #"" + (x+1) + "": "" + count); + + } + + + + + + fout.close(); + System.exit(0); + + } + +} +" +A22299,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.Arrays; +public class B { + public static void main(String[] args) throws IOException { + BufferedReader input = + new BufferedReader(new InputStreamReader(System.in)); + int a = Integer.parseInt(input.readLine()); + for (int i = 1; i <= a; i++) { + String[] b = input.readLine().split("" ""); + int s = Integer.parseInt(b[1]); + int p = Integer.parseInt(b[2]); + int[] gs = new int[Integer.parseInt(b[0])]; + for (int j = 0; j < gs.length; j++) { + gs[j] = Integer.parseInt(b[j+3]); + } + Arrays.sort(gs); + int hasil = 0; + for (int j = gs.length - 1; j >= 0; j--) { + if (gs[j]/3 >= p) { + hasil++; + //System.out.println(""1 "" + gs[j]); + } + else { + if (gs[j] % 3 == 2) { + if (gs[j]/3 + 1 >= p) { + hasil++; + //System.out.println(""2 "" + gs[j]); + } + else if (gs[j]/3 + 2 >= p && s > 0) { + s--; + hasil++; + //System.out.println(""3 "" + gs[j]); + } + } + else if (gs[j] % 3 == 1) { + if (gs[j]/3 + 1 >= p) { + hasil++; + //System.out.println(""4 "" + gs[j]); + } + } + else { + if (gs[j]/3 + 1 >= p && s > 0 && gs[j]/3 > 1) { + s--; + hasil++; + //System.out.println(""5 "" + gs[j]); + } + } + } + } + System.out.println(""Case #"" + i + "": "" + hasil); + } + } +} +" +A21047,"package DancingWithTheGooglers; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.Collections; +import java.util.Scanner; +import java.util.ArrayList; + +public class DancingWithTheGooglers { + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new FileInputStream(""input.txt"")); + PrintWriter out = new PrintWriter(new FileOutputStream(""output.txt"")); + + int lines = in.nextInt(); + in.nextLine(); + int counter = 0; + + for (;counter scores = new ArrayList(); + for (int i = 0; i=p) + finalCount++; + else if (s>0) { + s--; + finalCount++; + } + } + out.write(finalCount + ""\n""); + } + + in.close(); + out.close(); + } +} +" +A22038,"import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Scanner; + +public class Run3 { + class ll { + public lln f; + public lln l; + } + + class lln { + public Object v; + public lln n; + } + + private static Scanner sc; + + public static int gi() { + return Integer.parseInt(sc.next()); + } + + public static String gn() { + return sc.next(); + } + + public static void main(String[] args) throws IOException { + System.setIn(new FileInputStream(""B-large.in"")); + System.setOut(new PrintStream(""output.txt"")); + + sc = new Scanner(System.in); + + int T = gi(); + + for (int z = 0; z < T; z++) { + + int N = gi(); + int S = gi(); + int P = gi(); + + int[] ti = new int[N]; + for(int i = 0; i < N; i++) { + ti[i] = gi(); + } + + int c = 0; + int[][] sc = new int[N][3]; + //System.out.println(""z: "" + z); + //System.out.println(""N: "" + N); + //System.out.println(""S: "" + S); + //ystem.out.println(""P: "" + P); + //System.out.println(/*N + "" "" + */S + "" "" + P /*+ ' ' + z + "" ""*/); + + int temp = 0; + for(int i = 0; i < N; i++) { + temp = ti[i]; + for(int j = 2; j >= 0; j--) { + sc[i][j] = temp/(j+1); + temp -= temp/(j+1); + } + Arrays.sort(sc[i]); + //System.out.println(ti[i] + ""\t"" + sc[i][0] + "","" + sc[i][1] + "","" + sc[i][2] + ""\t"" + (sc[i][0] + sc[i][1] + sc[i][2])); + } + + int c2 = 0; + boolean incc2; + + for (int i = 0; i < N; i++) { + incc2 = false; + if(c2 < S) { + if(sc[i][2] < P && sc[i][2] + 1 == P) { + /*if(sc[i][2] - sc[i][0] == 1 && sc[i][2] - sc[i][1] == 0) { + sc[i][2] += 1; + sc[i][1] -= 1; + incc2 = true; + } + else */ + if(sc[i][0] > 0 && sc[i][2] - sc[i][0] == 0) { + sc[i][2] += 1; + sc[i][0] -= 1; + incc2 = true; + } + else if(sc[i][1] > 0 && sc[i][2] - sc[i][0] == 1 && sc[i][2] - sc[i][1] == 0) { + sc[i][2] += 1; + sc[i][1] -= 1; + incc2 = true; + } + } + if(incc2) { + c2++; + } + } + if(sc[i][2] >= P) { + c++; + } + } + + System.out.format(""Case #%d: %d\r\n"", z + 1, c); + } + } + +} +" +A21551," +import java.io.*; + +public class Main { + + static final String FILE = ""B-large""; + static final String INPUT = FILE + "".in""; + static final String OUTPUT = FILE + "".out""; + // + static final int[] NOT_SURPRISING = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10}; + static final int[] SURPRISING = {0, 0, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 0, 0}; + + public static void main(String[] args) throws FileNotFoundException, IOException { + int T, N, S, p, x, y; + int[] t; + + PrintWriter pw; + try (BufferedReader br = new BufferedReader(new FileReader(INPUT))) { + pw = new PrintWriter(OUTPUT); + + T = Integer.parseInt(br.readLine()); + for (x = 1; x <= T; x++) { + y = 0; + + // + String temp[] = br.readLine().split("" ""); + N = Integer.parseInt(temp[0]); + S = Integer.parseInt(temp[1]); + p = Integer.parseInt(temp[2]); + + t = new int[N]; + for (int i = 0; i < N; i++) { + t[i] = Integer.parseInt(temp[3 + i]); + } + + // + for (int i = 0; i < N; i++) { + if (NOT_SURPRISING[t[i]] >= p) { + y++; + } else if (S > 0 && SURPRISING[t[i]] >= p) { + y++; + S--; + } + } + + System.out.println(""Case #"" + x + "": "" + y); + pw.println(""Case #"" + x + "": "" + y); + } + } + pw.close(); + } +} +" +A20666,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Scanner; + + +public class googler +{ + + int cases; + int googlers; + int surprises; + int goal; + int[] points; + + /** + * @param args + */ + public static void main(String[] args) + { + googler gag = new googler(); + + } + + public googler() + { + parseInput(); + } + + //read in each case line by line. + public void parseInput() + { + try + { + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + FileWriter fwstream = new FileWriter(""Googlers.out""); + BufferedWriter out = new BufferedWriter(fwstream); + + + cases = Integer.parseInt(br.readLine()); + + for (int i = 0; i < cases; i++) + { + solveCase(br.readLine(), i, out); + } + + out.close(); + + } + catch (Exception e) + {//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + //parses variables for this case. + public void solveCase(String caseArgs, int caseNum, BufferedWriter file) throws IOException + { + int y = 0; //the number of scores in this case above goal + Scanner sc = new Scanner(caseArgs); + googlers = sc.nextInt(); + surprises = sc.nextInt(); + goal = sc.nextInt(); + points = new int[googlers]; + int bestScore; + // building the arrray of scores + for (int i = 0; i < points.length; i++) + points[i] = sc.nextInt(); + + + //System.out.println(""N:"" + googlers + "" S:"" + surprises + "" P:"" + goal + "" "" + Arrays.toString(points)); + for (int i = 0; i < points.length; i++) + { + + if (unsurprising(points[i])) + { + y++; //chalk one up + + } + else if (surprises > 0 && surprising(points[i])) + { + y++; + surprises--; + } + } + + file.write(""Case #"" + (caseNum+1) + "": "" + y + '\n'); + //System.out.println("" Case #"" + (caseNum+1) + "": "" + y); + } + + + //returns best score if unsurprising + public boolean unsurprising(int total) + { + //System.out.println(goal); + int min = goal*3; + min = min - 2; + if (min <= 0) + min = goal; + //System.out.println(""min: "" + min + "" total: "" + total); + return (total >= min); + } + + public boolean surprising(int total) + { + int min = goal*3; + min = min - 4; + if (min <= 0) + min = goal; + //System.out.println(""Smin: "" + min + "" Stotal: "" + total); + return (total >= min); + } + + + + +} +" +A22483,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlecodequalificationround; + +import java.util.Scanner; + +/** + * + * @author LeongYan + */ +public class DancingWithGooglers { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + sc.nextLine(); + int[] out = new int[t]; + for (int i = 0; i < t; i++) { + out[i] = 0; + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] scores = new int[n]; + for (int j = 0; j < n; j++) { + scores[j] = sc.nextInt(); + } + for (int j = 0; j < n; j++) { + if(scores[j] > ((p * 3) - 3)){ + out[i]++; + } + else if(scores[j] >= ((p * 3) - 4) && scores[j] <= ((p * 3) - 3) && s > 0){ + if(scores[j] == 0){ + + } + else{ + out[i]++; + s--; + } + } + } + } + for (int i = 0; i < t; i++) { + System.out.println(""Case #"" + (i + 1) + "": "" + out[i]); + } + } +} +" +A22823,"package mgg.utils; + +public class Pair { + + public int first; + public int second; + + public Pair(int first, int second){ + this.first = first; + this.second = second; + } + + @Override + public String toString() { + return ""("" + first + "", "" + second + "") ""; + } + +} +" +A20215,"package com.google.code; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.Reader; + +/** + * @author Wellington Tadeu dos Santos [wellsantos@wellsantos.com] + */ +public class ProblemB { + + boolean endOfLine; + Reader reader; + Appendable writer; + + public ProblemB(Reader in, Appendable out) throws Exception { + this.reader = in; + this.writer = out; + } + + public static void main(String[] args) throws Exception { + long time = System.nanoTime(); + String in = ""./src/com/google/code/B-large.in""; + String out = in.substring(0, in.length() - 3) + "".out""; + FileReader reader = new FileReader(in); + FileWriter writer = new FileWriter(out); + new ProblemB(reader, writer).run(); + writer.flush(); + writer.close(); + reader.close(); + System.out.println((System.nanoTime() - time) / 1000000.0); + } + + private int readInt() throws Exception { + int val = 0; + int chr; + while ((chr = this.reader.read()) >= '0' && chr <= '9') { + val = val * 10 + (chr - '0'); + } + switch (chr) { + case '\r': + chr = this.reader.read(); + case '\n': + case -1: + this.endOfLine = true; + break; + default: + this.endOfLine = false; + } + return val; + } + + private void run() throws Exception { + int testCases = this.readInt(); + for (int caseIndex = 1; caseIndex <= testCases; caseIndex++) { + int n = this.readInt(); + int s = this.readInt(); + int p = this.readInt(); + int scored = 0; + int surprisingPossibility = 0; + for (int i = 0, c = n; i < c; i++) { + int ti = this.readInt(); + int dif = (ti % 3); + int low = ti / 3; + switch (dif) { + case 0: + if (low >= p){ + scored++; + } else if (low + 1 >=p && low > 0){ + surprisingPossibility++; + } + break; + + case 1: + if (low + 1>= p){ + scored++; + } + break; + case 2: + if (low + 1>= p){ + scored++; + } else if (low + 2 >=p){ + surprisingPossibility++; + } + break; + } + } + if (surprisingPossibility > s) { + surprisingPossibility = s; + } + scored += surprisingPossibility; + this.writer.append(""Case #"" + caseIndex + "": "" + scored + ""\n""); + } + } + +}" +A21785,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +/** + * + * @author Mahmoud + */ +public class CodeJam2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + try { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""output.txt"")); + + int n, s, p; + + String inStrLine = in.readLine(); + if (inStrLine == null) { + System.out.println(""wrong format""); + return; + } + int num = Integer.parseInt(inStrLine); + for (int i = 0; i < num; i++) { + writer.write(""Case #"" + (i + 1) + "": ""); + inStrLine = in.readLine(); + if (inStrLine == null) { + System.out.println(""wrong format""); + return; + } + + String[] params = inStrLine.split("" ""); + n = Integer.parseInt(params[0]); + s = Integer.parseInt(params[1]); + p = Integer.parseInt(params[2]); + + + int t,max, result = 0; + for (int j = 0; j < n; j++) { + t = Integer.parseInt(params[j + 3]); + + max = t==0?0:((t - 1) / 3) + 1; + if (max >= p) { + result++; + } else if (s != 0) { + max = t==0?0:((t - 2) / 3) + 2; + if (max >= p) { + result++; + s--; + } + } + } + + writer.write(String.valueOf(result)); + if (i != num - 1) { + writer.write('\n'); + } + } + + writer.flush(); + + } catch (Exception e) { + System.err.println(""cant open file""); + } + } +} +" +A20388,"package codejam; +import java.io.*; +public class FileRead { + String fileName; + FileReader fr; + BufferedReader br; + FileRead(String fileName) + { + this.fileName=fileName; + File f=new File(""K:\\CodeJam\\Input\\""+fileName);//Create a file object + + FileReader fr; + try { + fr = new FileReader(f); + br=new BufferedReader(fr); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + //function to read next line. + public String readNextLine(){ + String text=null; + try { + text=br.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + + return text; + } + public int readNextInt(){ + int n = 0; + try{ + n=Integer.parseInt(br.readLine().trim()); + }catch(Exception e){ + System.out.println(""Invalid integer""); + } + return n; + } + public int [] readNextIntArray(){ + int []n=null; + try{ + String []numarray=br.readLine().split("" ""); + n=new int[numarray.length]; + for(int i=0;i= enoughPoints) { + maximumNumberOfGooglers++; + } + else if (enoughPointsForSurprise > 0 && sum >= enoughPointsForSurprise && numberOfSurprisesLeft > 0) { + numberOfSurprisesLeft--; + maximumNumberOfGooglers++; + } + } + + } + + public String toString() + { + return maximumNumberOfGooglers.toString(); + } + +} +" +A20026,"package problemB; + +import java.io.IOException; +import java.util.LinkedList; + +import utils.InputReader; + +public class SolverB { + + public static void main(String[] args) throws IOException { + LinkedList input = InputReader.read(""C:/Users/Danielle/Desktop/B-large.in""); + int num = Integer.parseInt(input.removeFirst()); + int i = 1; + for (String string : input) { + if (i > num) { + System.err.println(i+"">""+num); + break; + } + String[] split = string.split("" ""); + int dancers = Integer.parseInt(split[0]); + int supplies = Integer.parseInt(split[1]); + int targetScore = Integer.parseInt(split[2]); + + boolean hasSupplies = supplies>0; + + int couldBeAbove = 0; + + for (int k = 3; k < dancers+3; k++){ + int total = Integer.parseInt(split[k]); + if (total == 0 && targetScore > 0) continue; + if (total > 27){ + if (targetScore < 11) couldBeAbove++; + continue; + } + int avg = total/3; + int lacking = targetScore-avg; + if (lacking < 1) couldBeAbove++; + else if (lacking > 2) continue; + else { + int rest = total%3; + if (rest == 1){ + if (lacking == 1) couldBeAbove++; + } else if (hasSupplies){ + switch(rest){ + case 2: + switch (lacking) { + case 1: + couldBeAbove++; + break; + case 2: + couldBeAbove++; + hasSupplies = (--supplies)>0; + break; + } + break; + case 0: + if (lacking == 1){ + couldBeAbove++; + hasSupplies = (--supplies)>0; + } + break; + } + } else { + if (rest == 2 && lacking == 1) couldBeAbove++; + } + } + } + System.out.println(""Case #""+(i++)+"": ""+couldBeAbove); + } + } +} +" +A21881,"import java.util.Scanner; + + +public class Scoring { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int numLines = sc.nextInt(); + int lineCount = 1; + + while (numLines > 0) { + int numGoogler = sc.nextInt(); + int numSurprisingScores = sc.nextInt(); + int scoreThreshold = sc.nextInt(); + int result = 0; +// System.out.println(numGoogler +"" ""+ numSurprisingScores +"" ""+ scoreThreshold); + while (numGoogler > 0) { + int totalScore = sc.nextInt(); +// System.out.println(totalScore); + boolean passed = processScore(scoreThreshold, totalScore); + + if (passed) { + result++; +// System.out.println(""here!!!""); + } else if (!passed && numSurprisingScores > 0) { + int maxPossibleScore = calculateMaxScore(totalScore); + if (maxPossibleScore >= scoreThreshold) { + result++; + numSurprisingScores--; +// System.out.println(""here!""); + } +// System.out.println(""here!!""); + } + numGoogler--; + } + System.out.println(""Case #"" + lineCount + "": "" + result); + lineCount++; + numLines--; + } + } + + private static int calculateMaxScore(int totalScore) { + int avg = totalScore/3; + int mod = totalScore%3; + int max = 0; + if (totalScore != 0) { + if (mod <= 1) { + max = avg+1; + } else if (mod == 2) { + max = avg+2; + } + } + return max; + } + + public static boolean processScore(int scoreThreshold, int totalScore) { + int avg = totalScore/3; + int mod = totalScore%3; +// System.out.println(avg+"" ""+mod); + + if (mod > 0) { + if (avg+1 >= scoreThreshold) { + return true; + } + } else if (mod == 0) { + if (avg >= scoreThreshold) { + return true; + } + } + return false; + } + +} +" +A22732," +import java.util.Scanner; + +public class CodeJam12B { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for (int zz = 1; zz <= T; zz++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int[] t = new int[N]; + int out = 0; + + for (int i = 0; i < N; i++) { + t[i] = in.nextInt(); + t[i] = t[i] - p; + if (t[i] >= 0) { + if (t[i] >= 2 * (p - 1)) { + out++; + } else if (t[i] >= 2 * (p - 2) && S > 0) { + S--; + out++; + } + } + } + System.out.format(""Case #%d: %d\n"", zz, out); + } + } +} +" +A22243,"package DancingGooglers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * + * @author Nikhil + */ +public class b { + + public static void main(String[] args) throws FileNotFoundException, IOException { + File fInput = new File(args[0]); + String tmp; + if (fInput.exists() && fInput.isFile()) { + BufferedReader br = new BufferedReader(new FileReader(fInput)); + int iTestCases = Integer.parseInt(br.readLine()); + int iCase = 1; + while (null != (tmp = br.readLine())) { + Danscore d = new Danscore(tmp); + d.solve(); + System.out.println(""Case #"" + iCase + "": "" + d); + iCase++; + } + br.close(); + } + } +} + +class Danscore { + + private int iBestScoreDancers; + private int iDancers; + private int iSurprises; + private int iBestScore; + private List scores; + + Danscore(String tmp) { + String[] inp = tmp.split("" ""); + iDancers = Integer.parseInt(inp[0]); + iSurprises = Integer.parseInt(inp[1]); + iBestScore = Integer.parseInt(inp[2]); + scores = new ArrayList(); + for (int i = 3; i < inp.length; i++) { + scores.add(Integer.parseInt(inp[i])); + } + Collections.sort(scores, Collections.reverseOrder()); + } + + void solve() { + iBestScoreDancers = 0; + // Minimum score required to qualify as best score + has Surprises + int iMinimumReq = iBestScore + (iBestScore - 2) + (iBestScore - 2); + // Make sure minimum required score is positive + iMinimumReq = iMinimumReq<0? 0:iMinimumReq; + // Normal scores required if Suprises are exausted + int iNormalScore = iBestScore + (iBestScore - 1) + (iBestScore - 1); + iNormalScore = iNormalScore<0? 0:iNormalScore; + + Iterator itr = scores.iterator(); + while (itr.hasNext()) { + int iscore = itr.next(); + if (iscore < iBestScore) continue; + if (iscore >= iNormalScore) { + iBestScoreDancers++; + continue; + } + if (iSurprises > 0 && iscore >= iMinimumReq) { + iBestScoreDancers++; + iSurprises--; + } + } + } + + @Override + public String toString() { + return String.valueOf(iBestScoreDancers); + } +} +" +A20686,"import java.util.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.text.DecimalFormat; + +/** + * + * + */ +public class B { + + + public static void main(String[] args) { + try { + + Scanner scanner = (new Scanner(new File(""c:/input.txt""))); + int N = scanner.nextInt(); + + FileOutputStream out = new FileOutputStream(""c:/output.txt""); + PrintWriter wr = new PrintWriter(out); + + scanner.nextLine(); + + for (int i = 0; i < N; i++) { + doCase(i+1, scanner, wr); + } + + + wr.close(); + out.close(); + } catch (Exception e) { + System.out.println(""Error: "" + e.getMessage()); + e.printStackTrace(); + } + } + + private static void doCase(int caseNum, Scanner scanner, PrintWriter wr) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + int notSurp = 3 * p - 2; + int surp = 3 * p - 4; + if (p == 1) { + surp = 1; + } + int cnt = 0; + for (int i = 0; i < N; i++) { + int res = scanner.nextInt(); + if (res >= notSurp) { + cnt++; + } else if (res >= surp) { + if (S > 0) { + S--; + cnt++; + } + } + } + wr.println(""Case #"" + caseNum + "": "" + cnt); + } + + private static String formatNumber(int result, String format) { + DecimalFormat f = new DecimalFormat(format); + return f.format(result); + } +}" +A22749," +import java.util.Scanner; + +public class BDancingWithGooglers { + public static void main(String[] ags) { + //System.setIn(new FileInputStream(""src/com/afarok/google/codejam2012/qualificationround/B-large.in"")); + //System.setOut(new PrintStream(new File(""src/com/afarok/google/codejam2012/qualificationround/B-large.out""))); + Scanner stdIn = new Scanner(System.in); + int t = stdIn.nextInt(); + for(int tCase=1;tCase<=t;++tCase) { + int n = stdIn.nextInt(); + int ns = stdIn.nextInt(); + int p = stdIn.nextInt(); + + int y =0; + for(int i=0;i=p) { + ++ y; + continue; + } + + if(p-d>2) continue; + + if(p-d==1) { + if(r>0) { + ++y; + continue; + } else { + if(ns>0) { + ++y; + --ns; + continue; + } + } + } else { + if(ns>0 && r==2) { + ++y; + --ns; + continue; + } + } + + + } + System.out.println(""Case #""+tCase+"": ""+y); + } + } +} +" +A21476,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +public class main { + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""out.txt"")); + Pattern pat = Pattern.compile("" ""); + String firstLine = (br.readLine()); + Integer numLines = new Integer(firstLine); + Integer i; + + for(i=1;i<=numLines;i++){ + Integer res=0; + bw.write(""Case #""+i+"": ""); + String line = (br.readLine()).trim(); + String [] st= pat.split(line); + List scores = Lists.newArrayList(); + for(Integer j=3;j scores){ + Integer res=0; + for(Integer e:scores){ + Double aver= new Double(e)/3; + Boolean r=false; + if(aver>=p){ + res++; + }else{ + Integer max=0; + if(aver!=0.0){ + if(aver>=(Math.floor(aver)+0.25)){ + max= (int) (Math.floor(aver)+1); + if(max>=p){ + res++; + r=true; + } + } + if(numS!=0&&!r){ + if(aver>=(Math.floor(aver)+0.50)){ + max= (int) (Math.floor(aver)+2); + }else{ + max= (int) (Math.floor(aver)+1); + } + if(max>=p){ + res++; + numS--; + } + } + + + } } + } + + return res; + } +}" +A20043,"package Qual2012; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + + +public class Qual2012B { + + public static void main(String args[]){ + +// String filePath = ""X:\\GCJ\\2012B-small-attempt0.in""; + String filePath = ""X:\\GCJ\\2012B-large-attempt0.in""; + FileInputStream fis = null; + BufferedReader readFile = null; + String line; + + try { + fis = new FileInputStream(filePath); + readFile = new BufferedReader(new InputStreamReader(fis, ""ISO-8859-1"")); + line = readFile.readLine(); + int T = Integer.parseInt(line); + for (int i = 1; i <= T; i++) { + line = readFile.readLine(); + System.out.println(""Case #"" + i + "": "" + solve(line) ); + } + } + catch(Exception e) { + e.printStackTrace(); + }finally{ + try { + fis.close(); + readFile.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private static int solve (String line) { + + String[] temp = line.split("" ""); + + int n = Integer.parseInt(temp[0]); + int s = Integer.parseInt(temp[1]); + int p = Integer.parseInt(temp[2]); + int[] t = new int[n]; + + int ret = 0; + + for (int i = 0; i < n; i++) + t[i] = Integer.parseInt(temp[i + 3]); + + for (int i = 0; i < n; i++) { + int remainder = t[i] % 3; + int max = (t[i] + 2) / 3; + + if (max >= p) { + ret++; + continue; + } else if (remainder != 1 && t[i] > 0 && max + 1 >= p && s > 0) { + ret++; + s--; + } + } + + return ret; + + } +} +" +A20701,"import java.io.*; + +public class G2 { + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(""d:\\B-large.in"")); + int n = Integer.parseInt(in.readLine()); + int cnt; + int surprize; + int min; + int[] points; + BufferedWriter out = new BufferedWriter(new FileWriter(""d:\\g2Largeo.txt"")); + for (int i = 1; i <= n; i++) { + String[] s = in.readLine().split("" ""); + cnt = Integer.parseInt(s[0]); + surprize = Integer.parseInt(s[1]); + min = Integer.parseInt(s[2]); + points = new int[cnt]; + for (int j = 0; j < cnt; j++) { + points[j] = Integer.parseInt(s[3 + j]); + } + int answer = solve(cnt, surprize, min, points); + System.err.println(""Case #"" + i + "": "" + answer); + out.write(""Case #"" + i + "": "" + answer); + out.newLine(); + } + out.close(); + } + + private static int solve(int cnt, int surprize, int min, int[] points) { + int anywayTotal = 0; + int surprizingTotal = 0; + + int anywayMax = 0; + int surprizingMax = 0; + + for (int point : points) { + int whole = (point) / 3; + int part = point % 3; + if (point > 0 && part == 0) { + whole--; + part = 3; + } + anywayMax = surprizingMax = whole; + + switch (part) { + case 1: + anywayMax++; + break; + case 2: + case 3: + anywayMax++; + surprizingMax+=2; + break; + } + if (anywayMax >= min) + anywayTotal++; + else if (surprizingMax >= min) + surprizingTotal++; + + } + return anywayTotal + Math.min(surprize, surprizingTotal); + } +} +" +A22861,"package google.codejam2012.qualification; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + + static public void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 64 << 10); + int testsNumber = Integer.parseInt(br.readLine().trim()); + for (int test = 1; test <= testsNumber; test++) { + StringTokenizer tokenizer = new StringTokenizer(br.readLine()); + int contestantsCount = Integer.parseInt(tokenizer.nextToken()); + int surprisesCount = Integer.parseInt(tokenizer.nextToken()); + int threshold = Integer.parseInt(tokenizer.nextToken()); + int result = 0; + for (int i = 0; i < contestantsCount; i++) { + int score = Integer.parseInt(tokenizer.nextToken()); + // - (score + 2) / 3 + // - (score + 4) / 3 + if (2 <= score & score <= 28) { + int best = (score + 2) / 3; + int bestSurprise = (score + 4) / 3; + if (best >= threshold) { + result++; + } + else if (bestSurprise >= threshold & surprisesCount > 0) { + result++; + surprisesCount--; + } + } + else if ((score + 2) / 3 >= threshold) { + result++; + } + } + System.out.println(""Case #"" + test + "": "" + result); + } + } + catch (Exception e) { + System.err.println(""Error:"" + e.getMessage()); + } + } +} +" +A20358,"import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; + + +public class BQ { + public static void main(String[] args) { + BufferedReader reader = null; + BufferedWriter writer = null; + int T = 0, k, j, N, S, p, i, ti, tis, mod, G = 0; + String line = null, caseSolution; + try { + reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); + writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(args[1]))); + T = Integer.parseInt(reader.readLine()); + for (k = 1; k <= T; k++) { + line = reader.readLine(); + N = Integer.parseInt(line.substring(0, j = line.indexOf((int)' ', 0))); + S = Integer.parseInt(line.substring(++j, j = line.indexOf((int)' ', j))); + p = Integer.parseInt(line.substring(++j, j = line.indexOf((int)' ', j))); + for (i = 0; i < N; i++) { + if (i != N - 1) { + ti = Integer.parseInt(line.substring(++j, j = line.indexOf((int)' ', j))); + } + else { + ti = Integer.parseInt(line.substring(++j)); + } + tis = ti/3; + mod = ti%3; + if (tis >= p || (tis + 1 >= p && mod > 0)) { + G++; + } + else { + if (((tis + 1 >= p && mod == 0 && tis > 0) || (tis + 2 >= p && mod == 2)) && S > 0) { + G++; + S--; + } + } + } + writer.write(""Case #"" + k + "": "" + G + ""\n""); + G = 0; + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + try { + if (reader != null) { + reader.close(); + } + if (writer != null) { + writer.close(); + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + } +}" +A20387,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.HashSet; +import java.util.Scanner; + + +public class Dancing { + + public static void main(String[] args) throws IOException{ + FileInputStream fstream = new FileInputStream(""B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String inputCnt = br.readLine(); + FileOutputStream outFile = new FileOutputStream(""output.txt""); + DataOutputStream out = new DataOutputStream(outFile); + BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(out)); + + int cnt = Integer.parseInt(inputCnt); + for(int line=1;line<=cnt;line++){ + + String inputString = br.readLine(); + Scanner sc = new Scanner(inputString); + String outputString = ""Case #""+line+"": ""; + int numTotal = sc.nextInt(); + int numSuprise = sc.nextInt(); + int p = sc.nextInt(); + int expectNoSuprise = p*3-2; + int expectWithSuprise = p*3-4; + if(expectWithSuprise<1) + expectWithSuprise =1; + int sumNoSuprise = 0; + int potential = 0; + for(int i= 1; i <= numTotal; i++){ + int score = sc.nextInt(); + if(score >= expectNoSuprise){ + sumNoSuprise++; + } + else if(score >= expectWithSuprise){ + potential ++; + } + } + int realPotential = Math.min(numSuprise, potential); + int result = sumNoSuprise+realPotential; + outputString+=result+""""; + wr.write(outputString); + wr.newLine(); + wr.flush(); + + } + wr.close(); + out.close(); + br.close(); + in.close(); + fstream.close(); + outFile.close(); + } +} +" +A21124,"import java.util.Scanner; + +public class Googlers { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int cases = sc.nextInt(); + for (int x = 0; x < cases; x++) { + sc.nextLine(); + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int posibles = 0; + for (int i = 0; i < n; i++) { + int ti = sc.nextInt(); + if (ti < p) + continue; + //if (ti == 3 * p || ti == 3 * p - 1 || ti == 3 * p - 2) + if (ti >= 3 * p - 2) + posibles++; + else if (s > 0 && (ti >= 3 * p - 4)) { + posibles++; + s--; + } + } + System.out.println(""Case #"" + (x+1) + "": "" + posibles); + } + } +} +" +A21570,"package me.mevrad.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class SolutionB { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + readFile(""B-large.in""); + processData(); + writeFile(); + } + + public static void readFile(String filename) { + try { + BufferedReader in = new BufferedReader(new FileReader(filename)); + String line; + while ((line = in.readLine()) != null) { + // System.out.println(line); + processLine(line); + } + in.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static int counter = 0; + static ArrayList data = new ArrayList(); + static ArrayList finalText = new ArrayList(); + public static void processLine(String line) { + if (counter == 0) { + counter++; + return; + } + String[] splited = line.split("" ""); + DataTemplate dt = new DataTemplate(); + int c = 0; + for (String s : splited) { + if (c == 0) + dt.numberOfGooglers = Integer.parseInt(s); + else if (c == 1) + dt.surprisingScores = Integer.parseInt(s); + else if (c == 2) + dt.p = Integer.parseInt(s); + else { + dt.scores.add(Integer.parseInt(s)); + } + c++; + System.out.println(s); + } + data.add(dt); + counter++; + System.out.println(""Next line""); + } + + public static void processData() { + counter = 0; + System.out.println(""processData data size:""+ data.size()); + for (DataTemplate dt : data) { + counter++; + int c = 0; + for (int i = 0; i < dt.scores.size(); i++) { + boolean visited = false; + int temp = dt.scores.get(i) / 3; + if(dt.p> dt.scores.get(i)) + continue; + if(temp < 0 && Math.ceil(temp) >= dt.p){ + c++; + continue; + } + if(temp >= dt.p){ + c++; + continue; + } + int temp1 = (dt.scores.get(i)-dt.p)/2; + if(dt.p-temp1<2){ + c++; + continue; + } + if((dt.p - temp1 == 2) && dt.surprisingScores >0){ + dt.surprisingScores--; + c++; + continue; + } + //System.out.println(""temp: "" + temp); +// if(temp < 0 && Math.ceil(temp) >= dt.p){ +// c++; +// dt.scores.remove(i); +// i--; +// visited = true; +// } +// if (temp >= dt.p && !visited) { +// c++; +// dt.scores.remove(i); +// i--; +// visited = true; +// } +// else if(temp >= 1 && temp%1>0 && Math.floor(temp)+1 >= dt.p && !visited){ +// c++; +// //System.out.println(""temp1: "" + Math.ceil(temp)+1); +// dt.scores.remove(i); +// i--; +// visited = true; +// } +// else if (dt.surprisingScores > 0 && !visited && temp > 0.5 && (temp%1 > 0.5 || temp%1 == 0)) { +// temp += 2; +// //System.out.println(""temp2: "" + temp); +// if (temp >= dt.p) { +// c++; +// dt.scores.remove(i); +// i--; +// dt.surprisingScores--; +// } +// } + } + System.out.println(counter+ "": Score: "" + c); + String s = """"; + s += ""Case #""+counter+"": ""+c; + finalText.add(s); + } + + } + + public static void writeFile(){ + try { + FileWriter fstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + for(String s : finalText){ + out.write(s); + out.write(""\n""); + } + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +} +" +A20528,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + + +public class Dance { + + static int getMaxGooglers(int N,int S, int p, int[] t) { + int count=0; + int surpriseCount=0; + + int avg=p*3; + for(int i=0;i=p) { + if(t[i]>=avg-2) + + count++; + + else if(surpriseCount=avg-4) { + count++; + surpriseCount++; + } + } + } + } + return count; + } + +} +" +A21745,"package googlers; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class Main { + + public static int calcWIS(int n){ + if(n - 2 < 0) + return 0; + return ((n - 2) / 3) + 2; + } + + public static int calcWOS(int n){ + if(n - 1 < 0) + return 0; + return ((n - 1) / 3) + 1; + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + //String fileName = args[0]; + String fileName = ""googlers/B-large.in""; + Scanner sC = null; + try { + sC = new Scanner(new File(fileName)); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + int T = sC.nextInt(); + int N, S, p; + int[] tab, wiS, woS; + for(int i = 0; i < T; i++){ + N = sC.nextInt(); + S = sC.nextInt(); + p = sC.nextInt(); + tab = new int[N]; + wiS = new int[N]; + woS = new int[N]; + + for(int j = 0; j < N; j++){ + tab[j] = sC.nextInt(); + wiS[j] = calcWIS(tab[j]); + woS[j] = calcWOS(tab[j]); + //System.out.println(tab[j] + "" "" + wiS[j] + "" "" + woS[j]); + } + + int count = 0; + + for(int j = 0; j < N; j++){ + if(woS[j] >= p){ + count++; + } + if(woS[j] < p && wiS[j] >= p && S > 0){ + count++; + S--; + } + } + + System.out.println(""Case #"" + (i + 1) + "": "" + count); + + } + + } + +} +" +A22132,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithGooglers { + + public static void main(String[] args) throws Exception{ + char problem = 'B'; + boolean smallCase = false; + boolean practice = false; + BufferedReader br = new BufferedReader(new FileReader(problem + ""-"" + (smallCase ? ""small"" : ""large"") + (practice ? ""-practice"" : """") + "".in"")); + PrintWriter out = new PrintWriter(new FileWriter(problem + ""-"" + (smallCase ? ""small"" : ""large"") + (practice ? ""-practice"" : """") + "".out"")); + int t = Integer.parseInt(br.readLine()); + for(int i = 1; i <= t; i++) { + out.println(""Case #"" + i + "": "" + solve(br.readLine())); + } + out.close(); + System.exit(0); + } + + public static int solve(String in) { + Scanner sc = new Scanner(in); + int numPeople = sc.nextInt(); + int numSurprize = sc.nextInt(); + int target = sc.nextInt(); + int output = 0; + for(; numPeople > 0; numPeople--) { + int cur = sc.nextInt(); + if(cur >= target * 3 - 2) output ++; + else if(target != 1 && numSurprize > 0 && cur >= target * 3 - 4) { + output ++; + numSurprize --; + } + } + return output; + } + +} +" +A21094,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package problem.b; +import java.util.Scanner; +import java.io.*; + +/** + * + * @author Jason + */ +public class ProblemB { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + Scanner input = new Scanner(System.in); + System.out.println(""Enter name of input file: ""); + File inputFile = new File(input.next()); + File outputFile = new File(""output.txt""); + Scanner file = null; + PrintWriter output = null; + while(file == null) + { + try{ + file = new Scanner(inputFile); + output = new PrintWriter(outputFile); + } + catch(Exception E){ + System.out.println(""invalid file""); + } + } + int cases = file.nextInt(); + file.nextLine(); + for(int i = 0; i < cases;) + { + int numGooglers = file.nextInt(); + int numSurprises = file.nextInt(); + int bestResult = file.nextInt(); + int numHighScores = 0; + for(int j = 0; j < numGooglers;j++) + { + int tempScore = file.nextInt(); + if (tempScore >= (bestResult*3)-2) + numHighScores++; + else if (tempScore >= (bestResult*3)-4 && numSurprises > 0 && tempScore > 0) + { + numHighScores++; + numSurprises--; + } + } + output.println(""Case #"" + ++i + "": "" + numHighScores); + } + output.close(); + } +} +" +A21513,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +public class Googlers { + public static void main(String args[]) { + try { + File file = new File(""input.txt""); + FileReader filereader = new FileReader(file); + BufferedReader br = new BufferedReader(filereader); + + File out = new File(""output.txt""); + FileWriter filewriter = new FileWriter(out); + BufferedWriter bw = new BufferedWriter(filewriter); + PrintWriter pw = new PrintWriter(bw); + + String str = br.readLine(); + int line = Integer.valueOf(str); + for (int i = 0; i < line; i++) { + int x = i + 1; + pw.print(""Case #"" + x + "": ""); + str = br.readLine(); + int ans = solve(str); + pw.println(ans); + } + pw.close(); + bw.close(); + + } catch (IOException ie) { + ie.printStackTrace(); + } + } + + private static int solve(String s) { + int count = 0; + String[] elems = s.split("" ""); + int N = Integer.valueOf(elems[0]); + int S = Integer.valueOf(elems[1]); + int p = Integer.valueOf(elems[2]); + + for (int i = 3; i < N + 3; i++) { + int score = Integer.valueOf(elems[i]); + int q = score / 3; + int mod = score % 3; + if (q >= p) { + count++; + } else if ((mod == 0 && q + 1 >= p) && (S > 0 && score >= q + 1)) { + count++; + S--; + } else if ((mod == 1 && q + 1 >= p) && (score >= q + 1)) { + count++; + } else if ((mod == 2 && q + 1 >= p) && (score >= q + 1)) { + count++; + } else if ((mod == 2 && q + 2 >= p) && (S > 0 && score >= q + 2)) { + count++; + S--; + } + } + return count; + + } +} +" +A21590,"import java.util.Scanner; + +public class ProblemB { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int tt = 1; tt <= t; tt++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int v[] = new int[n]; + for (int i = 0; i < n; i++) { + v[i] = sc.nextInt(); + } + int c = 0; + int vx[][] = new int[n][3]; + for (int i = 0; i < n; i++) { + int x[] = new int[3]; + x[0] = x[1] = x[2] = v[i] / 3; + if (v[i] != x[0] + x[1] + x[2]) { + x[2]++; + } + if (v[i] != x[0] + x[1] + x[2]) { + x[1]++; + } + vx[i] = x; + } + for (int i = 0; i < n; i++) { + if (vx[i][0] >= p || vx[i][1] >= p || vx[i][2] >= p) { + c++; + } else { + if (v[i] >= 2 && v[i] <= 28 && s != 0) { + if (vx[i][1] == vx[i][2]) { + vx[i][1]--; + vx[i][2]++; + if (vx[i][0] >= p || vx[i][1] >= p || vx[i][2] >= p && (vx[i][0] >= 0 && vx[i][1] >= 0 && vx[i][2] >= 0)) { + c++; + s--; + } + } else if (vx[i][0] == vx[i][1]) { + vx[i][0]--; + vx[i][1]++; + if (vx[i][0] >= p || vx[i][1] >= p || vx[i][2] >= p && (vx[i][0] >= 0 && vx[i][1] >= 0 && vx[i][2] >= 0)) { + c++; + s--; + } + } + } + } +// System.out.println(p + "" "" + c + "" "" + v[i] + "" "" + vx[i][0] + "" "" + vx[i][1] + "" "" + vx[i][2]); + } + System.out.println(""Case #"" + tt + "": "" + c); + } + } + +} +//WA" +A20184,"package com.webcumo.tasks.b; + +/** + * @author Cumo + */ +public class Worker { + + public static String translateFromGooglereseToEnglish(String googlersString) { + int count; + int surprises; + int p; + String[] items = googlersString.split("" ""); + count = Integer.parseInt(items[0]); + surprises = Integer.parseInt(items[1]); + p = Integer.parseInt(items[2]); + + int pReal = p * 3 - 2; + int pPossible = p * 3 - 4; + + int result = 0; + + for (int i = 3 ; i < count + 3 ; i++) { + int num = Integer.parseInt(items[i]); + if (num >= pReal) + result ++; + else if (num >= pPossible && surprises > 0 && num >= p) { + result ++; + surprises --; + } + } + + return """" + result; + } + +} +" +A20507,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class B { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + File in = new File(""b.in""); + File out = new File(""b.out""); + + BufferedWriter bw = new BufferedWriter(new FileWriter(out)); + Scanner sc = new Scanner(in); + + int T = Integer.parseInt(sc.nextLine()); + + + for(int i=0;i= p){ + count++; + }else if((m/3+1)>=p){ + count++; + surp++; + } + + }else if(m%3==1){ + + if((m/3 + 1)>=p){ + count++; + } + + }else{ + + if((m/3+1)>=p){ + count++; + }else if((m/3+2)>=p){ + count++; + surp++; + } + } + } + + count = surp<=S ?count:count-(surp-S); + + + bw.write(""Case #""+(i+1)+"": ""+count+""\n""); + + + } + bw.close(); + } + +} +" +A21060,"import java.util.*; +import java.io.*; + +public class Test { + + public void doMain() throws Exception{ + Scanner input = new Scanner(new FileReader(""./iothings/B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""./iothings/output.txt"")); + int n = input.nextInt(); + for(int i = 0 ; i < n ; i++){ + int N = input.nextInt(); + int S = input.nextInt(); + int P = input.nextInt(); + int[] person = new int[N]; + for(int j = 0 ; j < N ; j++){ + person[j] = input.nextInt(); + } + pw.println(""Case #""+(i+1)+"": ""+num(N,S,P,person)); + } + input.close(); + pw.flush(); + pw.close(); + } + + public static int num(int N,int S,int P,int[] person){ + Arrays.sort(person); + int mone = 0; + //int mtwo = 0; + int oks = 0; + int preoks = 0; + for(int i = 0 ; i < person.length ; i++){ + if(person[i]/3 == 0){ + if(P == 2){ + if(person[i] == 2)mone++; + }else if(P == 1){ + if(person[i] >= 1){ + preoks++; + } + }else if(P == 0){ + preoks++; + } + }else if(person[i]/3 >= P || (person[i]/3 >= P-1 && person[i] % 3 == 1) || (person[i]/3 >= P-1 && person[i] % 3 == 2)){ + oks = person.length-i; + break; + }else if(person[i]/3 >= P-1){ + mone++; + }else if(person[i]/3 >= P-2 && person[i] % 3 == 2){ + mone++; + } + } + oks += preoks; + if(S <= mone){ + oks += S; + }else{ + oks += mone; + } + return oks; + } + + public static void main(String[] args) throws Exception{ + (new Test()).doMain(); + } + + +} +" +A22230,"package teardrop.jam2012.qr.dancing; + +import java.io.*; + +public class SetSolver { + private final Reader reader; + private final Writer writer; + + public SetSolver(Reader reader, Writer writer) { + this.reader = reader; + this.writer = writer; + } + + public void solve() throws IOException { + try (BufferedReader bufferedReader = new BufferedReader(reader)) { + CaseSolver caseSolver = new CaseSolver(bufferedReader, writer); + int caseCount = Integer.valueOf(bufferedReader.readLine()); + for (int i = 1; i <= caseCount; ++i) { + writer.write(String.format(""Case #%d: "", i)); + caseSolver.solve(); + writer.write('\n'); + } + } + } +} +" +A21491,"import java.io.*; +import java.util.*; + +public class B { + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + + Scanner sc = new Scanner(br.readLine()); + int T = sc.nextInt(); + int caseNumber = 1; + + + + for(int i=0; i ta = new ArrayList(); + //ArrayList tb = new ArrayList(); + + + for(int j=0; j0){ + if(tr/3 >= p){ + count++; + }else if((tr + 2)/3 >= p){ + count++; + //countCanBeS++; + }else if(tr/30){ + if((tr+3)/3 >= p){ + count++; + S--; + }else if((tr+4)/3 >= p){ + //System.out.println(""Hello"" + count); + count++; + S--; + } + } + } + + }else if(tr==0 && p==0){ + count++; + } + + } + + + System.out.println(""Case #""+ caseNumber +"": ""+count); + caseNumber++; + + } + + + } +}" +A22511,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.StringTokenizer; + + +public class DancingGogglers { + static class Data{ + int n,surprise,max; + int score [][]; + + int getNumberofNonMax(){ + int max = 0; + for(int i = 0 ; i < score.length; i++){ + if(score[i][1] ==0 && score[i][0] >=2) + max++; + } + return max; + } + int getNumberOfMax(){ + int max = 0; + for(int i = 0 ; i < score.length; i++){ + if(score[i][1] ==1) + max++; + } + return max; + } + int getNumberofMaxWithOnlySurprise(){ + int max = 0; + for(int i = 0 ; i < score.length; i++){ + if(score[i][2] ==1) + max++; + } + return max; + } + int getSolution (){ + int initMax = getNumberOfMax(); + if(getNumberofMaxWithOnlySurprise() > surprise){ + return (initMax - (getNumberofMaxWithOnlySurprise() - surprise )); + } + if(getNumberofNonMax() >= surprise){ + return getNumberOfMax(); + } + return initMax; + } + } + + public static void main(String[] args) { + Data[] data = getData(); + for(int i = 0 ; i < data.length; i++){ + int index = i+1; +// System.out.print(""Case #"" + index + "": "" + data[i].n + "" ""+ data[i].surprise + "" "" + data[i].max + "" ""); +// for(int score[] : data[i].score){ +// System.out.print(score[0] + "" ""); +// } + System.out.println(""Case #"" + index + "": "" + data[i].getSolution()); + } + + + } + + private static Data[] getData() { + try { + String[] input = getInput(""B-large.in""); + Data [] data = new Data[input.length]; + + for(int i = 0 ; i < input.length; i++){ + Data d = new Data(); + StringTokenizer token = new StringTokenizer(input[i], "" ""); + d.n = Integer.parseInt((String) token.nextElement()); + d.surprise = Integer.parseInt((String) token.nextElement()); + d.max = Integer.parseInt((String) token.nextElement()); + d.score = new int[d.n][1+1+1]; + for(int j = 0 ; j < d.n; j++){ + d.score[j][0] = Integer.parseInt((String) token.nextElement()); + if(d.score[j][0] < d.max) continue; + if((d.score[j][0] == 0 && d.max == 0)|| (d.score[j][0] >= (3*d.max -4) && (d.score[j][0]!=0)) ){ + d.score[j][1] = 1; + if((d.score[j][0] == 3*d.max-4) || + (d.score[j][0] == 3*d.max-3)){ + d.score[j][2] =1; + } + } + } + data[i] = d; + } + return data; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } + + static String[] getInput(String fileName) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + try { + String message = reader.readLine(); + int numberOfTestCases = Integer.parseInt(message); + String[] input = new String[numberOfTestCases]; + for (int i = 0; i < numberOfTestCases; i++) { + message = reader.readLine(); + input[i] = message; + } + return input; + } finally { + reader.close(); + } + } +} +" +A20072,"import java.io.*; +import java.util.*; + +/** + * @author Chris Dziemborowicz + * @version 2012.0414 + */ +public class DancingWithTheGooglers +{ + public static void main(String[] args) + throws Exception + { + // Get input files + File dir = new File(""/Users/Chris/Documents/UniSVN/code-jam/dancing-with-the-googlers/data""); + File[] inputFiles = dir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) + { + return name.endsWith("".in""); + } + }); + + // Learn score mappings + learn(); + + // Process each input file + for (File inputFile : inputFiles) { + System.out.printf(""Processing \""%s\""...\n"", inputFile.getName()); + + String outputPath = inputFile.getPath().replaceAll(""\\.in$"", "".out""); + BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath)); + + Scanner scanner = new Scanner(inputFile); + System.out.printf(""Number of test cases: %s\n"", scanner.nextLine()); + + int count = 0; + while (scanner.hasNext()) { + String line = scanner.nextLine(); + String output = String.format(""Case #%d: %d\n"", ++count, process(line)); + + System.out.print(output); + writer.write(output); + } + + writer.close(); + System.out.println(""Done.\n""); + } + + // Compare to reference files (if any) + for (File inputFile : inputFiles) { + System.out.printf(""Verifying \""%s\""...\n"", inputFile.getName()); + + String referencePath = inputFile.getPath().replaceAll(""\\.in$"", "".ref""); + String outputPath = inputFile.getPath().replaceAll(""\\.in$"", "".out""); + + File referenceFile = new File(referencePath); + if (referenceFile.exists()) { + InputStream referenceStream = new FileInputStream(referencePath); + InputStream outputStream = new FileInputStream(outputPath); + + boolean matched = true; + int referenceRead, outputRead; + do { + byte[] referenceBuffer = new byte[4096]; + byte[] outputBuffer = new byte[4096]; + + referenceRead = referenceStream.read(referenceBuffer); + outputRead = outputStream.read(outputBuffer); + + matched = referenceRead == outputRead + && Arrays.equals(referenceBuffer, outputBuffer); + } while (matched && referenceRead != -1); + + if (matched) { + System.out.println(""Verified.\n""); + } else { + System.out.println(""*** NOT VERIFIED ***\n""); + } + } else { + System.out.println(""No reference file found.\n""); + } + } + } + + + private static int[] highestOrdinary = new int[31]; + private static int[] highestSurprising = new int[31]; + + + public static void learn() + { + Arrays.fill(highestOrdinary, -1); + Arrays.fill(highestSurprising, -1); + + for (int i = 0; i <= 10; i++) { + for (int j = i; j <= i + 2 && j <= 10; j++) { + for (int k = j; k <= i + 2 && k <= 10; k++) { + int score = i + j + k; + if (k == i + 2) { + if (k > highestSurprising[score]) { + highestSurprising[score] = k; + } + } else { + if (k > highestOrdinary[score]) { + highestOrdinary[score] = k; + } + } + } + } + } + } + + + public static int process(String line) + { + // Parse input + Scanner scanner = new Scanner(line); + int num = scanner.nextInt(); + int numSurprising = scanner.nextInt(); + int p = scanner.nextInt(); + int[] scores = new int[num]; + for (int i = 0; i < num; i++) { + scores[i] = scanner.nextInt(); + } + + // Find surprising scores + int count = 0; + for (int score : scores) { + if (highestOrdinary[score] >= p) { + count++; + } else if (numSurprising > 0 && highestSurprising[score] >= p) { + numSurprising--; + count++; + } + } + return count; + } +}" +A21334," +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; +import javax.imageio.IIOException; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + +/** + * + * @author abood + */ +public class proba { + public static void main(String[] args) throws IIOException, FileNotFoundException, IOException{ + //String alpha=""abcdefghojklmnopqrstuvwxyzabcdefghojklmnopqrstuvwxyz""; + BufferedReader br =new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out =new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + int loop=Integer.parseInt(br.readLine()); + StringTokenizer st; + for (int i = 1; i <= loop; i++) { + int res=0; + st=new StringTokenizer(br.readLine()); + int n=Integer.parseInt(st.nextToken()); + int s=Integer.parseInt(st.nextToken()); + int p=Integer.parseInt(st.nextToken()); + for (int j = 0; j < n; j++) { + int x=Integer.parseInt(st.nextToken()); + + + if(x=p-1)res++; + else if(x==p-2){ + if(s>0){res++;s--;} + } + } + //System.out.println(""Case #""+i+"": ""+res); + out.println(""Case #""+i+"": ""+res); + } + out.close(); + System.exit(0); + } + +} +" +A20270," +import java.io.File; +import java.util.Arrays; +import java.util.Scanner; + +public class DancingWiththeGooglers { + + public static void main(String[] args) throws Exception { + + File inp = new File(""B-large.in""); + Scanner sc = new Scanner(inp); + + int T = sc.nextInt(); + + + int result, n, s, p; + + for (int i = 0; i < T; i++) { + + n = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + + int[] q = new int[n]; + + for (int lop = 0; lop < n; lop++) { + q[lop] = sc.nextInt(); + } + + + result = dowork(n, s, p, q); + + System.out.println(""Case #"" + (i + 1) + "": "" + result); + + + + } + + + + + } + + private static int dowork(int n, int s, int p, int[] q) { + int r = 0; + + Arrays.sort(q); + + int minSumWithoutSur = p * 3 - 2; + int minSumWithSur = p * 3 - 4; + + minSumWithSur = (minSumWithSur >= 0)? minSumWithSur : 0 ; + + + for (int i = q.length - 1; i >= 0; i--) { + if (q[i] >= minSumWithoutSur) { + r++; + } else if ((q[i] >= minSumWithSur) && (q[i] != 0) && (s > 0)) { + r++; + s--; + } + } + + + return r; + } +} +" +A20014,"package com.codejam.solution; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +public class GoogleDance { + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader reader=new BufferedReader(new FileReader(new File(System.getProperty(""user.home"")+File.separator+""Desktop""+File.separator+""input.txt""))); + PrintWriter output=new PrintWriter(new File(System.getProperty(""user.home"")+File.separator+""Desktop""+File.separator+""output.txt"")); + int cases=Integer.parseInt(reader.readLine()); + for(int i=0;i0){ + if(totals[track]%3==2){ + if((totals[track]/3)+2>=p){ + qualified++; + found++; + } + }else if(totals[track]%3==0){ + if((totals[track]/3)+1>=p){ + qualified++; + found++; + } + }else{ + if(totals[track]/3+1>=p){ + qualified++; + } + } + } + else{ + if(p==0){ + qualified++; + }else{ + if(totals[track]%3==1){ + if(totals[track]/3+1>=p){ + qualified++; + } + } + } + } + track++; + } + while(track0){ + if(totals[track]%3>=1){ + if(totals[track]/3+1>=p){ + qualified++; + track++; + break; + } + }else{ + if(totals[track]/3>=p){ + qualified++; + track++; + break; + } + } + }else{ + if(p==0){ + qualified++; + track++; + break; + } + } + track++; + } + if(track { + + private static final int MAX_PARAM_COUNT = 10; + + private IntArrayLine paramConverter; + private InputConverter converter; + + private Object[] input; + private int lineNumber; + + public DynamicMultiLineConverter(InputConverter lineConverter) { + this(lineConverter, 0); + } + + public DynamicMultiLineConverter(InputConverter lineConverter, int paramCount) { + this.converter = lineConverter; + if (paramCount > 0) { + paramConverter = new IntArrayLine(paramCount); + } else { + paramConverter = new IntArrayLine(new int[MAX_PARAM_COUNT]); + } + } + + @Override + public boolean readLine(String data) { + if (lineNumber == 0) { + paramConverter.readLine(data); + int[] params = paramConverter.generateObject(); + int count = getCount(params); + input = new Object[count + 1]; + input[lineNumber++] = params; + } else { + if (!converter.readLine(data)) { + input[lineNumber++] = converter.generateObject(); + } + } + + if (lineNumber >= input.length){ + lineNumber = 0; + } + return lineNumber == 0; + } + + @Override + public Object[] generateObject() { + return input; + } + + /** + * default implementation, just uses first parameter value + */ + protected int getCount(int[] parameters) { + return parameters[0]; + } + +} +" +A20346,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.LinkedList; + + +public class DancingWiththeGooglers +{ + int maxWiner =0; + LinkedList x = new LinkedList(); + ArrayList answer = new ArrayList(); + + public DancingWiththeGooglers() + { + + } + + public void solve(int[] given) + { + int maxNumberOfSur = given[1]; + for(int i=3;i= given[2]) + { + maxWiner++; + } + else if(rest ==1) + { + if(min+rest>=given[2]) + { + maxWiner++; + } + } + else if(rest ==2) + { + x.add(min); + } + } + int use = 1; + if(maxNumberOfSur!=0) + { + for(int i=0;i=given[2] && use<=maxNumberOfSur) + { + maxWiner++; + use++; + } + } + } + else + { + for(int i=0;i=given[2]) + { + maxWiner++; + } + } + } + answer.add(maxWiner); + x=new LinkedList(); + maxWiner=0; + } + + + public void write() + { + try{ + // Create file + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + int m=0; + for(int i=0;i= p || (max[t[i]] >=p && S-- > 0 )) + { + c++; + } + } + + return c + """"; + } + + public static void main(String[] args) throws Exception + { + DEBUG = false; + main(DancingWithTheGooglers.class); + } +} +" +A21367,"import java.util.Scanner; + +public class B { + public static void main(String args[]){ + Scanner scanner = new Scanner(System.in); + int testCount = scanner.nextInt(); + for (int test = 1; test <= testCount; test++){ + int numGooglers = scanner.nextInt(); + int numSurprise = scanner.nextInt(); + int cutScore = scanner.nextInt(); + int qtdePass = 0; + for (int pointsCount = 0; pointsCount=cutScore) { + qtdePass+=1; + continue; + } + + if(testMinor0){ + if(testMinor+1 >= cutScore){ + qtdePass+=1; + testDist-=1; + continue; + } else{ + if(testMinor+2>=cutScore && testDist>=2 && numSurprise>0) { + qtdePass+=1; + numSurprise-=1; + testDist-=1; + continue; + } + } + } + + if(testMinor= cutScore && numSurprise>0){ + qtdePass+=1; + numSurprise-=1; + continue; + } + } + + } + + System.out.println(""Case #"" + (test) + "": ""+qtdePass); + } + } +} +" +A20979,"package fixjava; + +import java.util.ArrayList; + +/** + * An ArrayList that allows values to be set at positions greater than or equal to size(), which causes the end of the list to be padded with an + * identity element before the value is set + */ +public class ArrayListAutoPadded extends ArrayList { + + private T identity; + + public ArrayListAutoPadded(T identity) { + super(); + this.identity = identity; + } + + public ArrayListAutoPadded(T identity, int initialCapacity) { + super(initialCapacity); + this.identity = identity; + } + + /** + * Set the value at the given location to the specified value, padding the list to the desired length if necessary. Returns the old value at the + * location, if there was one, otherwise the identity value that was passed in the constructor. + */ + public T set(int index, T element) { + if (size() > index) { + return super.set(index, element); + } else { + while (size() < index) + add(identity); + add(element); + return identity; + } + }; + + /** + * Combine the value at the given location with the new value, by calling labmda.apply(oldValue, newValue). The identity value that was passed in + * the constructor is used if the index >= size(). Returns the *old* value that was stored at the index before combining, or identity if there was + * no old value. + */ + public T combineAndSet(int index, Lambda2 combineFunc, T newValue) { + T oldValue; + if (size() > index) { + oldValue = get(index); + } else { + while (size() <= index) + add(identity); + oldValue = identity; + } + return super.set(index, combineFunc.apply(oldValue, newValue)); + } + + private static final long serialVersionUID = 1L; +} +" +A21483,"package br.com.codejam.qualification; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithGooglers { + public static void main(String[] args) throws IOException { + String file = ""B-small-attempt3""; + Scanner sc = new Scanner(new FileReader(file + "".in"")); + PrintWriter pw = new PrintWriter(new FileWriter(file + "".out"")); + int T = new Integer(sc.nextLine()); + + for (int i = 1; i <= T; i++) { + int result = 0; + pw.print(""Case #"" + i + "": ""); + String line = sc.nextLine(); + String[] numbers = line.split("" ""); + int N = new Integer(numbers[0]); + int S = new Integer(numbers[1]); + int P = new Integer(numbers[2]); + for (int j = 0; j < N; j++) { + int div = new Integer(numbers[j + 3]); + if(div == 0 && P == 0) + result++; + if (div != 0) { + div = div / 3; + if (div >= P) { + result++; + } else { + if ((P - div) == 1) { + if ((new Integer(numbers[j + 3]) % 3) >= 1) { + result++; + } else if ((new Integer(numbers[j+3]) % 3) == 0 && S > 0) { + result++; + S--; + } + } else if ((P - div) == 2) { + if ((new Integer(numbers[j + 3]) % 3) == 2 && S > 0) { + result++; + S--; + } + } + } + } + } + pw.println(result); + } + pw.flush(); + pw.close(); + sc.close(); + } + +} +" +A21164,"import java.util.*; + +public class Dancing { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(), N, S, p, total; + int[] scores; + String output = """"; + + for (int i = 0; i < T; i++) { + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + + scores = new int[N]; + for (int j = 0; j < N; j++) + scores[j] = in.nextInt(); + Arrays.sort(scores); + + total = 0; + for (int j = N-1; j >= 0; j--) { + if (p == 0) + total++; + else if (scores[j] == 0) + continue; + else if (scores[j]/3 >= p || (scores[j]/3 == p - 1 && scores[j]%3 > 0)) + total++; + else if (S > 0 && (scores[j]/3 == p - 1 || (scores[j]/3 == p - 2 && scores[j]%3 == 2))) { + S--; + total++; + } + } + if (p > 10) + total = 0; + output += ""Case #"" + (i+1) + "": "" + total + ""\n""; + } + System.out.print(output); + } +} +" +A23071,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +class Test{ + int output; + char[] mapping; + String line; + int S; + int P; + int[] Ti; + + public Test(String line){ + Scanner lineReader = new Scanner(line); + int N = lineReader.nextInt(); + S = lineReader.nextInt(); + P = lineReader.nextInt(); + Ti = new int[N]; + for (int i = 0; i < N; i++){ + Ti[i] = lineReader.nextInt(); + } + } + + public int getOutput(){ + return output; + } + + public void solve(){ + for (int x: Ti){ + if(P == 0){ + output++; + } + else if((x >= P*3 -2 && x > 0)){ + output++; + } + else if(x >= P*3 -4 && S > 0 && x > 0 && P > 1){ + output++; + S--; + } + } + } + + public char translate(char c){ + if (c == ' '){ + return c; + } + boolean changeCase = false; + if(c != Character.toLowerCase(c)){ + c = Character.toLowerCase(c); + changeCase = true; + } + char toReturn = mapping[Character.valueOf(c) - Character.valueOf('a')]; + if(changeCase){ + toReturn = Character.toUpperCase(toReturn); + } + return toReturn; + } + +} + +public class ProblemB { + + public static void main(String[] args) throws IOException{ + File inputFile = new File(""input.txt""); + Scanner scan = new Scanner(inputFile); + int loopCount = scan.nextInt(); + scan.nextLine(); + FileWriter outputFile = new FileWriter(""output.txt""); + for(int i = 1; i <= loopCount; i++){ + Test start = new Test(scan.nextLine()); + start.solve(); + outputFile.write(""Case #""+i+"": "" + start.getOutput()); + if(i < loopCount){ + outputFile.write(""\r\n""); + } + } + outputFile.close(); + } +} +" +A20111,"import java.util.*; + +class Main +{ + public static void main(String[] arg) + { + Scanner in = new Scanner(System.in); + + int trials = in.nextInt(); + + int tt = 0; + while(tt < trials) + { + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + + int ret = 0; + for(int i=0; i= P) + { + ++ret; + } else if(S > 0 && score == P-1 && val % 3 != 1 && val > 0) + { + --S; + ++ret; + } + } + + System.out.println(""Case #"" + ++tt + "": "" + ret); + } + } +}" +A22292,"import java.util.*; +import java.io.*; +public class Googlers { + public static void main(String[] args)throws IOException { + Scanner sc = new Scanner(new File(""input2.txt"")); + int loop = sc.nextInt(); + int num; + int s = 0; + int p; + int n; + int count = 0; + int check; + + ArrayList array = new ArrayList(); + for (int i = 0 ; i < loop ; i++) { + num = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + for (int j=0 ; j= n) + count++; + else { + if(s>0){ + check = (p+(p-2)*2); + if(in >= check && check >0){ + count++; + s--; + } + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+count); + count = 0; + array.clear(); + } + + } +}" +A21646,"package codejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class ProblemB +{ + public static void main(String[] args) throws FileNotFoundException + { + Scanner sc = new Scanner(new File(""B-large.in"")); + sc.nextLine(); // input size + int cases = 0; + while(sc.hasNext()) + { + String line = sc.nextLine(); + String[] vals = line.split("" ""); + int googlerCount = Integer.parseInt(vals[0]); + int maxSupriseCount = Integer.parseInt(vals[1]); + int limit = Integer.parseInt(vals[2]); + int[] scores = new int[vals.length - 3]; + for(int i = 0; i < vals.length - 3; i++) + { + scores[i] = Integer.parseInt(vals[i+3]); + } + + int output = 0; + int supriseCount = 0; + for(int score : scores) + { + if (score == 0 && limit > 0) { + continue; + } + double avg = score / 3d; + if (avg >= limit) + { + output++; + } + else if (limit - avg < 1) { + output++; + } + else if (limit - avg < 1.5) { + if (supriseCount < maxSupriseCount) { + supriseCount++; + output++; + } + } + } + System.out.println(""Case #"" + ++cases + "": "" + output); + + } + } +} +" +A22583,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class B { + + + public static void main(String[]args)throws Exception { + File f = new File(args[0]); + File out = new File(f.getParentFile(), f.getName()+"".out""); + BufferedWriter w = new BufferedWriter(new FileWriter(out)); + Scanner s = new Scanner(f); + int T = s.nextInt(); + s.nextLine(); + for (int t=1;t<=T;t++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] totals = new int[N]; + for (int x=0; x= min) { + num++; + } else if (totals[x] < floor) { + continue; + } else if (s > 0) { + s--; + num++; + } + } + return String.valueOf(num); + } + + static void println(BufferedWriter w, String s) throws IOException { + System.out.println(s); + w.write(s+""\n""); + } +} +" +A20601,"import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import com.google.common.base.Charsets; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; +import com.google.common.io.Files; + +public class Main { + + static String[] ins = new String[] { + ""yeqz"", + ""ejp mysljylc kd kxveddknmc re jsicpdrysi"", + ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"", + ""de kr kd eoya kw aej tysr re ujdr lkgc jv"" + }; + + static String[] outs = new String[] { + ""aozq"", + ""our language is impossible to understand"", + ""there are twenty six factorial possibilities"", + ""so it is okay if you want to just give up"" + }; + + public static void main(String[] args) throws IOException { + +// File f = new File(""B-small-attempt0.in""); +// File f = new File(""B-small-attempt2.in""); + File f = new File(""B-large.in""); +// File f = new File(""A-large-practice.in""); +// File f = new File(""example.in""); +// File f = new File(""test.in""); + List lines = Files.readLines(f, Charsets.UTF_8); + + int cases = Integer.valueOf(lines.get(0)); + int c = 0; + while (c < cases) { + c++; + String[] tokens = lines.get(c).split("" ""); + int n = Integer.valueOf(tokens[0]); + int s = Integer.valueOf(tokens[1]); + int p = Integer.valueOf(tokens[2]); +// System.out.println(lines.get(c)); +// System.out.printf(""%d %d\n"", s, p); + + int[] g = new int[n]; + int result = 0; + for (int i = 0; i < n; i++) { + int score = Integer.valueOf(tokens[3 + i]); + int mod = mod(score, 3); + int a = 0; + int b = 0; + switch (score) { + case 0: a = 0; b = 0; break; + case 1: a = 1; b = 0; break; + case 2: a = 1; b = 2; + break; + default: + switch (score % 3) { + case 0: a = mod + 0; b = mod + 1; break; + case 1: a = mod + 1; b = mod + 1; break; + case 2: a = mod + 1; b = mod + 2; break; + } + } + if (a > 10) a = 10; + if (b > 10) b = 10; +// System.out.printf(""%d (%d, %d) "", score, a, b); + if (a >= p) { + result++; + continue; + } + if (s > 0 && b >= p) { + result++; + --s; + } + } + +// System.out.println(); + System.out.println(""Case #"" + c + "": "" + result); + + } + } + + static int mod(int a, int b) { + return ((a - (a % b)) / b); + } +}" +A21308,"import java.util.*; + +public class Dance +{ + public static void main(String args[]) + { + Scanner input = new Scanner(System.in); + int numCase; + numCase = input.nextInt(); + for(int n=0; n0) + { + bestIfS[i] = (int)((double)scores[i]/3+1.5); + bestIfNS[i] = (int)((double)scores[i]/3+0.7); // Rounding + } else { + bestIfS[i] = 0; + bestIfNS[i] = 0; + } + + /* + *System.out.printf(""S:%d !:%d N:%d\n"",scores[i] + * bestIfS[i], + * bestIfNS[i]); + */ + } + + for(int i=0; i=min) { maxAboveMin++; } + else if (surprising>0 && bestIfS[i]>=min) + { + maxAboveMin++; + surprising--; + } + } + + System.out.printf(""Case #%d: %d\n"",n+1,maxAboveMin); + + } + } +} +" +A20470,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; + +public class GCIFileWriter { + + public GCIFileWriter (File file) throws IOException { + mBufferedWriter = new BufferedWriter(new FileWriter(file)); + mFile = file; + } + + public void writeResult(GCIResult res) throws IOException + { + Iterator it = res.iterator(); + while(it.hasNext()) + { + mBufferedWriter.write(it.next() + ""\n""); + mBufferedWriter.flush(); + } + } + + public void reset() throws IOException + { + mBufferedWriter.close(); + mBufferedWriter = new BufferedWriter(new FileWriter(mFile)); + } + + public void close() throws IOException + { + mBufferedWriter.flush(); + mBufferedWriter.close(); + } + + private BufferedWriter mBufferedWriter; + private File mFile; + +} +" +A23041," +import java.io.*; +import java.text.*; +import java.math.*; +import java.util.*; + +public class J12QB implements Runnable { + Scanner in; + PrintWriter out; + static String taskname = "".\\src\\B-large""; + int test, testn, i, j, k; + int N,S,p; + + public static void main(String[] args) { + new Thread(new J12QB()).start(); + } + + public void solve() throws Exception { + testn = in.nextInt(); + + for (test = 0; test < testn; test++) { + int A=0,B=0,C=0,n; //A:must be surprise to be a candidate B: must not surprise C:candidate + out.print(""Case #"" + (test + 1) + "": ""); + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + for (int i = 0; i < N; i++) { + n=in.nextInt(); + if (n==0) + C+=(p==0)?1:0; + else if (n>=3*p-4){ + C++; + if (n==3*p-3 || n==3*p-4) + A++; + } + } + if(A>S) + C-=(A-S); + + out.print(C+""\n""); + } + } + + @Override + public void run() { + try { + in = new Scanner(new File(taskname + "".in"")); + out = new PrintWriter(taskname+"".out""); + //out = new PrintWriter(System.out, true); + // in = new BufferedReader( new InputStreamReader(System.in)); + // out = new BufferedWriter( new OutputStreamWriter(System.out)); + solve(); + out.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A21274,"import java.util.*; + +class Dancer{ + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + int testcase, numdancer, surprise, limit, counter, score; + testcase = sc.nextInt(); + for(int i=1;i<=testcase;i++){ + counter = 0; + System.out.print(""Case #""+i+"": ""); + numdancer = sc.nextInt(); + surprise = sc.nextInt(); + limit = sc.nextInt(); + for(int j=0;j0){ + counter++; + surprise--; + } + } + else{ + switch(score%3){ + case 0:{ + if(score/3 >= limit) + counter++; + else if(surprise>0 && (score/3) + 1 >= limit){ + counter++; + surprise--; + } + + break; + } + case 1:{ + if((score/3)+1 >=limit) + counter++; + break; + } + case 2:{ + if((score/3)+1>=limit) + counter++; + else if(surprise>0 && (score/3)+2>=limit){ + counter++; + surprise--; + } + break; + } + } + } + } + System.out.println(counter); + } + } +}" +A20968,"package midnighter.googlejam.y2012; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class QualificationB +{ + static final String inFileName = ""inputs/B-large.in""; + static final String outFileName = ""outputs/B-large.out""; + + + Scanner in; + PrintWriter out; + + public int oneCase() + { + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + int[] scores = new int[N]; + int res = 0; + + for (int i = 0; i < N; i++) + { + int s = scores[i] = in.nextInt(); + int max1 = (s % 3 == 0) ? s / 3 : s / 3 + 1; + int max2 = (s % 3 == 2) ? s / 3 + 2 : s / 3 + 1; + + if (s == 0) + max1 = max2 = 0; + if (s == 1) + max1 = max2 = 1; + + if (max1 >= P || (max2 >= P && --S >= 0)) + res++; + } + + return res; + } + + public void run() throws Exception + { + in = new Scanner(new FileReader(inFileName)); + out = new PrintWriter(new FileWriter(outFileName)); + + int nCases = in.nextInt(); + in.nextLine(); + for (int c = 1; c <= nCases; c++) + out.println(""Case #"" + c + "": "" + oneCase()); + + out.flush(); + out.close(); + in.close(); + } + + public static void main(String[] args) throws Exception + { + new QualificationB().run(); + } +} +" +A21892,"import java.util.*; +import java.io.*; + +public class Main { + + final static String FNAME = ""A-small-practice""; + + public BufferedReader in; + + public PrintWriter out; + + static char[][] map = new char[2][26]; + + + void open() throws IOException { + in = new BufferedReader( new FileReader( new File( FNAME + "".in"" ) ) ); + out = new PrintWriter( new File( FNAME + "".out"" ) ); + } + + void close() throws IOException { + out.close(); + } + + void run() throws IOException { + + + String str = in.readLine(); + String[] input; + int n,s,p, noSmin, Smin,count; + int num = new Integer( str ); + for(int i = 0; i=2){ + Smin= p+2*(p-1); + noSmin= p+2*(p-2); + + }else if(p==1){ + Smin=p+2*(p-1); + noSmin=p+2*(p-1); + }else{ + Smin=0; + noSmin=0; + } + + + for(int j = 3; j<3+n;j++) + { + int no = new Integer(input[j]); + if (no >= noSmin) + { + + if (no >= Smin) + { + count++; + } + + if(no < Smin && s>0) + { + + count++; + s--; + } + } + + } + + out.println( ""Case #"" + (i+1) + "": "" + count ); + + + } + + + } + + public static void main( String[] args ) throws IOException { + new Thread() { + + public void run() { + try { + Main solution = new Main(); + solution.open(); + solution.run(); + solution.close(); + } catch ( Exception e ) { + throw new RuntimeException( e ); + } + } + }.start(); + } +}" +A22109,"package com.lily.acm.googleCodeJam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; + +public class DancingWiththeGooglers +{ + public static final int[] SUM_P = + { 0, 1, 2, 2,2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, + 9, 10, 10, 10, 10, 10 }; + public static final int[] SUM = + { 0, 1,1,1,2,2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, + 8, 9, 9, 9, 10, 10, 10}; + + + + static int getPropertMaxPerson(String[] input) + { + int count = 0; + int s = Integer.valueOf(input[1]); + int p = Integer.valueOf(input[2]); + Arrays.sort(input, 3, input.length); + for (int i = input.length - 1; i >=3 ; i--) { + int sum = Integer.valueOf(input[i]); + if (s > 0) { + if (SUM[sum] >= p) { + count++; + } + else if (SUM_P[sum] >= p) { + count++; + s--; + } + } + else { + if (SUM[sum] >= p) { + count++; + } + } + } + return count; + } + + public static void readInput(String fileName){ + BufferedReader is= null; + FileOutputStream os =null; + int count=1; + try + { + is = new BufferedReader(new FileReader(fileName)); + os = new FileOutputStream(new File(""c://output2.txt"")); + String input=""""; + + if(is.readLine()==null) return ; + while((input= is.readLine())!=null){ + os.write((""Case #""+count+++"": ""+getPropertMaxPerson(input.split("" ""))+""\r\n"").getBytes()); + os.flush(); + } + + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + }finally{ + try + { + is.close(); + os.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + public static void main(String[] args) + { + readInput(""c://B-large.in""); + } + +} +" +A22556,"package com.theblind.problem; + +import java.util.ArrayList; +import java.util.Scanner; + +import com.theblind.utility.FileUtility; + +public class DancingWiththeGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner in = new Scanner(System.in); + String inputFileName = in.next(); + String inputData = FileUtility.readFromFile(inputFileName); + + DancingWiththeGooglers problem = new DancingWiththeGooglers(); + String content = problem.solve(inputData); + + FileUtility.writeToFile(""output.txt"", content); + } + + private String solve(String inputData) { + // TODO Auto-generated method stub + Scanner in = new Scanner(inputData); + StringBuilder sb = new StringBuilder(); + + int testCases = in.nextInt(); + for (int i = 1; i <= testCases; ++i) { + sb.append(""Case #"" + i + "": ""); + + int googlers = in.nextInt(); + int surprisingCase = in.nextInt(); + int target = in.nextInt(); + ArrayList scores = new ArrayList(); + for (int j = 0; j < googlers; ++j) { + scores.add(in.nextInt()); + } + + int accepted = 0; + int acceptLine = Math.max(target, target * 3 - 2); + int limited = 0; + int limitLine = Math.max(target, target * 3 - 4); + for (Integer score : scores) { + if (score >= acceptLine) { + ++accepted; + } + else if (score >= limitLine) { + ++limited; + } + } + + int result = accepted + Math.min(surprisingCase, limited); + sb.append(result); + sb.append(""\n""); + } + return sb.toString(); + } + +} +" +A21397,"package edu.gcj.solutions; + +import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +public class DancingGooglers { + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + Scanner inf = new Scanner(new File(""C:\\Users\\Coltin\\Downloads\\B-large.in"")); + + int T = inf.nextInt(); + System.out.println(T); + + for (int t = 0; t < T; t++) { + int N = inf.nextInt(); // Number of googlers + int S = inf.nextInt(); // Number of surprisingly triplets + int p = inf.nextInt(); // Max score we want to find in a triplet + + int results = 0; + for (int n = 0; n < N; n++) { // We can calculate googlers scores independently, so 1 at a time + int googlerScore = inf.nextInt(); + //System.out.print(""Googler Score: "" + googlerScore + "" p="" + p); + if (p == 0) { + results++; + continue; + } else if (googlerScore == 0) { + continue; + } else if (Maximize(googlerScore) >= p) { + //System.out.println("" Maximized""); + results++; + } else if ((S > 0) && (MaximizeSurprising(googlerScore) >= p)) { + //System.out.println("" MaximizedSURPRISE""); + S -= 1; + results++; + } else { + //System.out.println("" NONE""); + } + } + System.out.println(""Case #"" + (t+1) + "": "" + results); + } + } + + private static int MaximizeSurprising(int googlerScore) { + int perJudge = googlerScore/3; + int pointsRemaining = googlerScore - (perJudge*3); + if (pointsRemaining == 2) { + return perJudge+2; + } + return perJudge+1; + } + + private static int Maximize(int googlerScore) { + int perJudge = googlerScore/3; + int pointsRemaining = googlerScore - (perJudge*3); + if (pointsRemaining == 0) { + return perJudge; + } + return perJudge+1; + } +} +" +A22676,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Formatter; +import java.util.Scanner; + + +public class G2 { + private static Scanner inp; + private static Formatter out; + private static int T = 0; + private static int g = 0; + private static int s = 0; + private static int p = 0; + private static int cnt = 0; + private static int tmp = 0; + + public static void main(String[] args) { + try { + inp = new Scanner(new File(""test.txt"")); + } catch (FileNotFoundException e) { + System.out.println(""File not found!""); + } + try { + out = new Formatter(""out.txt""); + } catch (FileNotFoundException e) { + System.out.println(""File not found!""); + } + T = inp.nextInt(); + inp.nextLine(); + for(int i = 0; i < T; i++) { + out.format(""Case #%d: "", i+1); + cnt = 0; + g = inp.nextInt(); + s = inp.nextInt(); + p = inp.nextInt(); + for(int j = 0; j < g; j++) { + tmp = inp.nextInt(); + if(tmp >= p*3-2) { + cnt++; + } else if(tmp >= p*3-4 && s > 0 && tmp > 0){ + cnt++; + s--; + } + } + out.format(""%d\r\n"", cnt); + } + inp.close(); + out.close(); + } +} +" +A21160,"package com.google.codejam; + +public class DancingGoogler { + public int solve(String str){ + String[] arr = str.split("" ""); + int n = Integer.valueOf(arr[0]); + int s = Integer.valueOf(arr[1]); + int p = Integer.valueOf(arr[2]); + int[] c = new int[n]; + for (int i = 0; i < c.length; i++) { + c[i] = Integer.valueOf(arr[3+i]); + } + int res = 0; + for (int i = 0; i < c.length; i++) { + if(p == 0){ + res++; + }else if(p == 1){ + if(c[i] > 0) res++; + }else{ + if(c[i] >= 3*p - 2) res++; + else if(c[i] >= 3*p - 4 && s > 0){ + res++; s--; + } + } + } + return res; + } +} +" +A20703,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class GoogleJamQ2 { + + static int[] triplets = new int[100]; + static int number_googlers = 0; + static int number_surprising = 0; + static int least_number = 0; + + + + /** + * @param args + * @throws IOException + */ + private static void get_numbers(String toCalculate) + { + char[] number_to_convert = new char[4]; + int number_got = 0; + int number_triplets = 0; + int number_length = 0; + int str_length = toCalculate.length(); + for(int k = 0; k < str_length; k++) + { + number_to_convert[0] = toCalculate.charAt(k); + number_length ++; + if(k + 1 < str_length) + { + number_to_convert[1] = toCalculate.charAt(k+1); + k++; + if(number_to_convert[1] != ' ') + { + number_length ++; + if(k + 1 < str_length) + { + number_to_convert[2] = toCalculate.charAt(k+1); + k++; + if(number_to_convert[2] != ' ') + { + number_length ++; + k++; + } + } + + } + } + + switch(number_got) + { + case 0: + number_googlers = new Integer(new String(number_to_convert,0,number_length)); + number_got ++; + break; + case 1: + number_surprising = Integer.parseInt(new String(number_to_convert,0,number_length)); + number_got ++; + break; + case 2: + least_number = Integer.parseInt(new String(number_to_convert,0,number_length)); + number_got ++; + break; + default: + triplets[number_triplets] = Integer.parseInt(new String(number_to_convert,0,number_length)); + number_got ++; + number_triplets ++; + break; + } + number_length = 0; + } + } + + private static boolean canGreater(int total, int least) + { + int single = total / 3; + int remainer = total % 3; + if (single >= least) + { + return true; + } + else + { + + switch(remainer) + { + case 0: + if(number_surprising > 0) + { + if(single == 0) + { + //System.out.println(single+"", ""+single+"", ""+single); + return false; + } + else if((single + 1) >= least) + { + //System.out.println((single-1)+"", ""+single+"", ""+(single+1)); + number_surprising --; + return true; + } + else + { + return false; + } + } + else + { + //System.out.println(single+"", ""+single+"", ""+single); + return false; + } + + case 1: + if((single + 1) >= least) + { + return true; + } + else + return false; + + case 2: + if((single + 1) >= least) + { + return true; + } + else + { + if((number_surprising > 0)) + { + if((single + 2) >= least) + { + number_surprising --; + return true; + } + } + else + { + return false; + } + + } + } + } + return false; + } + + + public static void main(String[] args) throws IOException { + //System.out.println(""Begin cacluating""); + FileInputStream fstream = new FileInputStream(""rec/input.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + strLine = br.readLine(); + int x = Integer.parseInt(strLine); + + int output_result = 0; + + for(int i = 0; i < x; i++) + { + strLine = br.readLine(); + get_numbers(strLine); + //System.out.println(""googlers: ""+number_googlers+"" surprising: ""+number_surprising+"" least: ""+least_number); + + for(int k = 0; k < number_googlers; k++) + { + //System.out.println((k+1)+"": ""+triplets[k]); + if(canGreater(triplets[k], least_number)) + { + output_result ++; + } + } + System.out.println(""Case #""+(i+1)+"": ""+output_result); + output_result = 0; + } + + + } + +} + +" +A22847,"import java.io.*; +import java.util.*; + +public class DancingWithGooglers { + + void solve() throws Exception { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = nextInt(); + } + + if (p == 0) { + out.println(n); + return; + } + + int cutOff1 = p + 2 * (p - 1); + int cutOff2 = p + 2 * Math.max(0, p - 2); + int count1 = 0, count2 = 0; + for (int i = 0; i < n; i++) { + if (t[i] >= cutOff1) { + count1++; + } else if (t[i] >= cutOff2) { + count2++; + } + } + int ans = count1 + Math.min(count2, s); + out.println(ans); + } + + void run() { + try { + in = new BufferedReader(new FileReader(""input.txt"")); + out = new PrintWriter(""output.txt""); + int tests = nextInt(); + for (int i = 0; i < tests; i++) { + out.print(""Case #"" + (i + 1) + "": ""); + solve(); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + BufferedReader in; + StringTokenizer st; + PrintWriter out; + final String filename = new String(""DancingWithGooglers"").toLowerCase(); + + String nextToken() throws Exception { + while (st == null || !st.hasMoreTokens()) + st = new StringTokenizer(in.readLine()); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + public static void main(String[] args) { + new DancingWithGooglers().run(); + } + +} +" +A23054,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +public class DancingGooglers { + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + DancingGooglers test = new DancingGooglers(); + test.botInit(""B-large.in"", ""B-large.txt""); + //test.ropeInit(""Rope-small.in"", ""Rope-small.txt""); + } + + public void botInit(String inputFile, String outputFile){ + + BufferedReader input; + List result = new Vector(); + + try { + + input = new BufferedReader(new FileReader(inputFile)); + + int cases = Integer.parseInt(input.readLine()); + + for (int i = 0; i < cases; i++){ + + result.add(caseSolver(input)); + } + + printResult(result, outputFile); + + } catch (FileNotFoundException fnte) { + + System.out.println(""File "" + inputFile + "" not found""); + + } catch (IOException ioe) { + + System.out.println(""Error reading file""); + } + } + + public int caseSolver(BufferedReader input) throws IOException{ + + String line = input.readLine(); + String data[] = line.split("" ""); + int googlers = Integer.parseInt(data [0]); + int surprises = Integer.parseInt(data[1]); + int score = Integer.parseInt(data[2]); + int result = 0; + + int surpriseScore1 = (score - 1) * 3; + int surpriseScore2 = ((score - 1) * 3) - 1; + //Set chick data positions + for (int i = 3; i < data.length; i++){ + + int currentScore = Integer.parseInt(data[i]); + + if (currentScore == 0 && score > 0){ + + continue; + } + + if (currentScore > surpriseScore1){ + + result++; + + } else if ((currentScore == surpriseScore1 || currentScore == surpriseScore2) && surprises > 0){ + + result++; + surprises--; + } + } + + return result; + } + + + public void printResult(List results, String outputFile) throws IOException{ + PrintWriter printer = new PrintWriter(new File(outputFile)); + + for (int i = 0; i < results.size(); i++){ + + int state = results.get(i); + + printer.println(""Case #"" + (i + 1) + "": "" + state); + printer.flush(); + } + } +} +" +A22354,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + + +public class QR2 { + private String[][] in; + private int numCases; + private String[] out; + + public QR2() { + String inFilename = ""B-large.in""; + readFile(inFilename); + numCases = new Integer(in[0][0]); + out = new String[numCases]; + calculateResult(); + String outFilename = ""B-large.out""; + writeOut(outFilename); + } + + public void calculateResult() { + int arp = 1; + for(int c = 0; c < numCases; c++) { + int N = new Integer(in[arp][0]); + int S = new Integer(in[arp][1]); + int p = new Integer(in[arp][2]); + int[] t = new int[N]; + for(int i = 0; i < N; i++) { + t[i] = new Integer(in[arp][3+i]); + } + + int nsupo = 0; + int supo = 0; + + for(int ct : t) { + if(((ct+2)/3) >= p) { + nsupo++; + } else if((ct > 0) && (((ct+4)/3) >= p)) { + supo++; + } + } + + if(supo >= S) { + out[c] = (new Integer(nsupo + S)).toString(); + } else { + out[c] = (new Integer(nsupo + supo)).toString(); + } + + arp++; + } + } + + public void readFile(String filename) { + try { + BufferedReader br = new BufferedReader(new FileReader(filename)); + String cl; + ArrayList inal = new ArrayList(); + while((cl = br.readLine()) != null) { + String[] cle = cl.split(""\\s""); + inal.add(cle); + } + in = inal.toArray(new String[0][]); + br.close(); + } catch(Exception e) { + System.err.println(e); + } + } + + public void writeOut(String filename) { + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); + for(int i = 0; i < out.length; i++) { + int caseNum = i + 1; + String caseTxt = ""Case #"" + caseNum + "": ""; + if(i > 0) { + bw.newLine(); + } + bw.write(caseTxt); + bw.write(out[i]); + } + bw.close(); + } catch(Exception e) { + System.err.println(e); + } + } + + public void printInArray() { + for(int i = 0; i < in.length; i++) { + for(int j = 0; j < in[i].length; j++) { + System.out.print(in[i][j]); + System.out.print("" ""); + } + System.out.print(""\n""); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + new QR2(); + } + +} +" +A21131,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package Happy; +import java.io.*; +import java.math.*; +import java.lang.*; +import java.util.*; +import java.util.Arrays.*; +import java.io.BufferedReader; +//import java.io.IOException; +//import java.io.InputStreamReader; +//import java.io.PrintWriter; +//import java.util.StringTokenizer; + +/** + * + * @author ipoqi + */ +public class Happy { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + new Happy().haha(); + } + + public void haha() { + BufferedReader in = null; + BufferedWriter out = null; + try{ + in = new BufferedReader(new FileReader(""B-large.in"")); + out = new BufferedWriter(new FileWriter(""B-large.out"")); + int T = Integer.parseInt(in.readLine()); + System.out.println(""T=""+T); + + for(int i=0;i= p){ + ans++; + } else { + if(S>0 && base>=1){ + if((base+1) >= p){ + S--; + ans++; + } + } + } + } else if(rest == 1){ + if((base+1) >= p){ + ans++; + } + } else {//rest == 2 + if((base+1)>=p){ + ans++; + } else { + if(S>0){ + if((base+2)>=p){ + S--; + ans++; + } + } + } + } + + } + + + out.write(""Case #""+(i+1)+"": ""+ans+""\n""); + System.out.print(""Case #""+(i+1)+"": ""+ans+""\n""); + } + in.close(); + out.close(); + }catch(Exception e){ + e.printStackTrace(); + try{ + in.close(); + out.close(); + }catch(Exception e1){ + e1.printStackTrace(); + } + } + System.out.print(""YES!\n""); + } + +} +" +A20413,"package MyAllgoritmicLib; + +public class NOD { + public static int gcd (int a, int b) + { + if (b == 0) + return a; + else + return gcd (b, a % b); + } + + public static long gcd (long a, long b) + { + if (b == 0) + return a; + else + return gcd (b, a % b); + } + + public static double gcd (double a, double b) + { + if (b == 0) + return a; + else + return gcd (b, a % b); + } +} +" +A22222,"import java.io.BufferedReader; +import java.io.FileReader; +import java.util.StringTokenizer; + + +public class B { + + void main2(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(args[0])); + String line = br.readLine(); + int count = Integer.parseInt(line); + for (int i = 0; i < count; i++) { + line = br.readLine(); + + // 3 1 5 15 13 11 + StringTokenizer st = new StringTokenizer(line, "" "", false); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + + int[] t = new int[n]; + for (int j = 0; j < n; j++) { + t[j] = Integer.parseInt(st.nextToken()); + } + + System.out.println(""Case #"" + (i + 1) + "": "" + max(n, s, p, t)); + } + br.close(); + } + + + private int max(int n, int s, int p, int[] t) { + int max = 0; + + for (int i = 0; i < n; i++) { + + int r = t[i] % 3; + int k = t[i] / 3; + int b = 0; + int bs = 0; + switch (r) { + case 0: + b = k; + bs = t[i] == 0 ? 0 : k + 1; + break; + case 1: + b = k + 1; + bs = t[i] == 1 ? -1 : k + 1; + break; + case 2: + b = k + 1; + bs = k + 2; + } + + if (b >= p) { + max++; + } else if (bs >= p && s > 0) { + max++; + s--; + } + + } + return max; + } + + + + public static void main(String[] args) throws Exception { + new B().main2(args); + } +} +" +A20905," +import java.io.BufferedReader; +import java.util.*; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class program { + + /** + * @param args + * + * Reads the input file for test cases. + */ + //main method for Problem A. +/* + public static void main(String[] args) { + // TODO Auto-generated method stub + File inFile = new File(""/home/kolive/Programming/GoogleCodeJam_2012/in""); + + + try { + BufferedReader myReader = new BufferedReader(new FileReader(inFile)); + String tmp = """"; + int i = 1; + tmp = myReader.readLine(); + while( (tmp = myReader.readLine()) != null) + { + + System.out.print(""\nCase #"" + i + "": "" + ProblemA.translateString(tmp)); + i++; + } + + + } catch (IOException e) { + System.out.println(""Exception Caught: "" + e); + } + } +*/ + + public static void main(String[] args) { + // TODO Auto-generated method stub + File inFile = new File(""/home/kolive/Programming/GoogleCodeJam_2012/in""); + + + try { + BufferedReader myReader = new BufferedReader(new FileReader(inFile)); + String tmp = """"; + int i = 1; + tmp = myReader.readLine(); + while( (tmp = myReader.readLine()) != null) + { + String arguments[] = tmp.split("" ""); + + + System.out.print(""\nCase #"" + i + "": "" + GenerateMaxP(Integer.parseInt(arguments[2]), + Arrays.copyOfRange(arguments, 3, arguments.length), + Integer.parseInt(arguments[1]))); + i++; + } + + + } catch (IOException e) { + System.out.println(""Exception Caught: "" + e); + } + } + + public static int GenerateMaxP(int p, String[] totalScores, int numSuprising) { + boolean containsP[] = new boolean[totalScores.length]; + int totalScoresI[] = new int[totalScores.length]; + + for(int i = 0; i < totalScores.length;i++) + { + totalScoresI[i] = Integer.parseInt(totalScores[i]); + } + for(int i = 0; i < totalScores.length; i++) + { + int[] tmp = ProblemB.generateTriplet(totalScoresI[i]); + int[] dupe = Arrays.copyOf(tmp, tmp.length); + + if (tmp[0] < p) + { + containsP[i] = false; + while(tmp[0] < p && numSuprising > 0) + { + //see if the surprising config has p + + + + //decrease the next biggest and increase tmp[0], if there's something to borrow from + if(tmp[1] > tmp[2] && tmp[2] > 0) + { + tmp[1]--; + //start by increasing tmp[0] + tmp[0] ++; + } + else if (tmp[2] > 0) + { + tmp[2]--; + //start by increasing tmp[0] + tmp[0] ++; + }else + { + //System.out.println( dupe[0] + "","" + dupe[1] + "","" + dupe[2]); + break; + } + + //confirm that it's not yet suprising + if((tmp[0] - tmp[1]) >= 2 || (tmp[0] - tmp[2]) >= 2) + { + //if now suprising, and max is included. Accept this result, decrease suprising count + if(tmp[0] >= p && (tmp[0] - tmp[1]) <= 2 && (tmp[0] - tmp[2]) <= 2) + { + containsP[i] = true; + numSuprising--; + + //System.out.println( tmp[0] + "","" + tmp[1] + "","" + tmp[2] + ""*""); + break; + } + else + { + containsP[i] = false; + + + //System.out.println( dupe[0] + "","" + dupe[1] + "","" + dupe[2]); + break; + } + + }else if(tmp[0] >= p) + { + //if not yet suprising, but we've gotten a p, set contains p to true, move on. + containsP[i] = true; + + //System.out.println( tmp[0] + "","" + tmp[1] + "","" + tmp[2]); + break; + } + + } + }else + { + containsP[i] = true; + + //System.out.println( dupe[0] + "","" + dupe[1] + "","" + dupe[2]); + } + + + + } + int count = 0; + for(int i = 0; i < containsP.length; i++) + { + if(containsP[i]) + count++; + } + + return(count); + } + +} +" +A21863,"import java.util.Scanner; + +public class cj1 { + public static void main(String[] args){ + Scanner s = new Scanner(System.in); + int T = s.nextInt(); + for (int i = 1; i<=T; i++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int nc=0; + int nawt=0; + int nbwt=0; + int naw=0; + int nbw=0; + int delta=0; + for (int j = 1; j<=N; j++) { + int ti = s.nextInt(); + if (ti==0) { + if(ti==p) { + nbw++; + nbwt++; + } + continue; + } + if((ti-1)%3==0) { + if ((ti+2)/3>=p) nc++; + } + if(ti%3==0){ + if(ti/3>=p) { + nbw++; + nbwt++; + } + else if((ti+3)/3>=p) nbw++; + } + if((ti+1)%3==0) { + if ((ti+1)/3>=p) { + naw++; + nawt++; + } + else if ((ti+4)/3>=p) naw++; + } + } + if(S<=(naw+nbw-nawt-nbwt)) delta=S; + else delta=naw+nbw-nawt-nbwt; + int max = nc + nawt + nbwt + delta; + System.out.println(""Case #"" + i + "": ""+ max); + } + } +} +" +A22220,"/** + * Program : Test for google code jam + * Author : jenogg + * Since : 2012.04.14 + */ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + + +public class Subject0102 { + + /** Mapping map */ + private Map mapper; + + /** + * Construct + */ + public Subject0102() { + init(); + } + + /** + * Initialize. + */ + private void init() { + /* + Input + 3 + ejp mysljylc kd kxveddknmc re jsicpdrysi + rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd + de kr kd eoya kw aej tysr re ujdr lkgc jv + + Output + Case #1: our language is impossible to understand + Case #2: there are twenty six factorial possibilities + Case #3: so it is okay if you want to just give up + */ + String input = "" abcdefghijklmnopqrstuvwxyz""; + String output = "" yhesocvxduiglbkrztnwjpfmaq""; + mapper = new HashMap(); + for (int letter=0; letter < input.length(); letter++) { + mapper.put(input.substring(letter,letter+1), output.substring(letter,letter+1)); + } + } + + /** + * Test + */ + public void test() { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String systemIn; + int sentenceSize = 0; + String[] sentence = new String[]{}; + try { + //println(""Input""); + systemIn = nvl(in.readLine()); + sentenceSize = getSentenceSize(systemIn); + if (sentenceSize > 0) { + sentence = new String[sentenceSize]; + for (int index = 0; index < sentenceSize; index++) { + systemIn = in.readLine(); + sentence[index] = nvl(systemIn); + } + //println(""\n-------------------------------------------\n""); + in.close(); + + //println(""Output""); + for (int index = 0; index < sentenceSize; index++) { + print(""Case #"" + (index+1) + "": ""); + printSentence(sentence[index]); + } + } + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Gets size of sentences + * @param sentenceSize Sentence size + * @return Size of sentences + * @throws Exception + */ + private int getSentenceSize(String sentenceSize) throws Exception { + return Integer.parseInt(nvl(sentenceSize, ""0"")); + } + + /** + * Print mapping sentence + * @param sentence Source sentence + */ + private void printSentence(String sentence) { + int success = 0; + + String[] data = sentence.split("" ""); + int dancers = Integer.parseInt(data[0]); + int suprise = Integer.parseInt(data[1]); + int cutline = Integer.parseInt(data[2]); + + if (cutline == 0) { + success = dancers; + } else { + for (int index=0; index < dancers; index++) { + int totalPoint = Integer.parseInt(data[3+index]); + if (totalPoint == 0) { + continue; + } + int basePoint = totalPoint / 3; + int rest = totalPoint % 3; + int canPoint = basePoint; + + if (rest != 0) { + canPoint++; + } + if (canPoint >= cutline) { + success++; + continue; + } + + if (suprise > 0) { + if (rest != 1) { + canPoint++; + if (canPoint >= cutline) { + success++; + suprise--; + continue; + } + } + } + } + } + println(success); + } + + /** + * Replace null to empty string + * @param string Input value of string + * @return If input string is null then empty string, otherwise trimmed input string + */ + private String nvl(String string) { + return nvl(string, """"); + } + + /** + * Replace null to replace string + * @param string Input value of string + * @param replace Replace value of string + * @return If input string is null then empty string, otherwise trimmed input string + */ + private String nvl(String string, String replace) { + return string == null ? """" : string.trim(); + } + + /** + * Print out + * @param obj Value of object + */ + private void print(Object obj) { + System.out.print(obj); + } + + /** + * Print line out + */ + private void println() { + println(""""); + } + + /** + * Print line out + * @param obj Value of object + */ + private void println(Object obj) { + System.out.println(obj); + } + + /** + * main + * @param args Arguments + */ + public static void main(String[] args) { + Subject0102 subject = new Subject0102(); + subject.test(); + } +} +" +A21580,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.common; + +/** + * + * @author jim + */ +public abstract class AbstractProcessor implements Processor { + + public Output process(Input input) { + int lines = Integer.parseInt(input.getHeader()[0]); + String[] data = input.getData(); + if (lines != data.length) + throw new IllegalArgumentException(""There are a different number "" + + ""of data lines to the number specified in the header""); + String[] out = new String[lines]; + for (int i = 0; i < lines; i++) { + out[i] = processLine(data[i]); + } + return new Output(out); + } +} +" +A21512,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class Dance { + + public static void main(String[] args) { + BufferedReader reader = null; + BufferedWriter writer = null; + try { + + if (args.length == 0) { + System.out.println(""Usage Dance ""); + System.exit(0); + } + + File inputFile = new File(args[0]); + + if (!inputFile.exists()) + System.out.println(String.format(""File {0} not found in the current directory"", args[0])); + + + + FileReader fileReader = new FileReader(inputFile.getAbsolutePath()); + reader = new BufferedReader(fileReader); + FileWriter fileWriter = new FileWriter(""Output.txt""); + writer = new BufferedWriter(fileWriter); + String line = reader.readLine(); + int numberOfTestCases = Integer.parseInt(line); + for (int i = 0; i < numberOfTestCases; i++) { + line = reader.readLine(); + String[] tokens = line.split("" ""); + int N = Integer.parseInt(tokens[0]); + int S = Integer.parseInt(tokens[1]); + int P = Integer.parseInt(tokens[2]); + int[] totalScores = new int[N]; + for (int j = 3; j < tokens.length; j++) { + totalScores[j - 3] = Integer.parseInt(tokens[j]); + } + writer.write(""Case #"" + (i + 1) + "": "" + maxWithScoreGreaterThanP(P,S,totalScores)); + writer.newLine(); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (reader!=null) { + reader.close(); + } + if (writer!=null) { + writer.close(); + } + } catch(Exception e) {} + } + } + + private static int maxWithScoreGreaterThanP(int p, int s, int[] totalScores) { + int count = 0; + int remainingSurprises = s; + for (int i = 0; i < totalScores.length; i++) { + boolean found = false; + int required = totalScores[i]; + for (int x=p; x<=10 && !found;x++) { + for (int y = x; y >= x - 2 && y>= 0 && !found;y--) { + for (int z = x; z >= y && z >=0 ;z--) { + if (x + y + z == required ) { + int min = Math.min(y, z); + if (min == x - 2 && remainingSurprises > 0){ + found = true; + count++; + remainingSurprises--; + break; + } else if (min > x-2) { + found = true; + count++; + break; + } + } + } + } + } + } + return count; + } + + + + +} +" +A22475,"import java.util.Scanner; + +/** + * + * @author Yasura + */ +public class B { + + public static void main(String[] args) { + Scanner scanInt= new Scanner(System.in); + int noOfCases = scanInt.nextInt(); + int N,S,p,t,max; + for(int i=0;ip-1){ + max++; + } + else if((t/3==p-1)&&S!=0&&t>2){ + max++; + S--; + } + } + else if(t%3==1 && (t+2)/3>p-1){ + max++; + } + else if (t%3==2){ + if((t+1)/3>p-1){ + max++; + } + else if ((t+1)/3==p-1&&S!=0){ + max++; + S--; + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+max); + } + } +} +" +A20739,"import java.io.*; +import java.util.*; +import java.util.regex.*; + +import static java.lang.Math.*; + +public class B { + + public class Tripple { + Integer t1, t2, t3; + + public Tripple() { + } + + @Override + public String toString() { + return ""("" + t1 + "", "" + t2 + "", "" + t3 + "")""; + } + } + + public static void main(String[] args) throws Exception { + B b = new B(); + b.run(args); + } + + public void run(String[] args) throws Exception { + + Scanner in = (args.length > 0) ? new Scanner(new File(args[0])) : new Scanner(System.in); + int T = in.nextInt(); + for(int zz = 1; zz <= T;zz++){ + System.err.format(""#%d\n"", zz); + System.out.format(""Case #%d: "", zz); + + int N = in.nextInt(); + int S = in.nextInt(); + int s = S; + int p = in.nextInt(); + + int tps[] = new int[N]; + int count = 0; + for (int n = 0; n < N; n++) { + tps[n] = in.nextInt(); + Tripple tripple = new Tripple(); + int tp = tps[n]; + s = tripple(tp, p, s, tripple); + if (s >= 0 && tripple.t1 != null && tripple.t1 >= p) { + count++; + } + System.err.println(tp + ""_"" + p + "" : "" + tripple + "" ... "" + s + "" c: "" + count); + } + + System.out.format(""%d\n"", count); + } + } + + private int tripple(int tp, int p0, int s, Tripple t) { + if (s < 0 || tp < p0) { + t.t1 = null; + return s; + } + + int p = p0; + boolean possible1 = false; + while(!possible1) { + possible1 = true; + + int r = tp; + t.t1 = p; + r -= p; + + int p2 = p; + + boolean possible = false; + int run = 0; + while(!possible) { + run++; + t.t2 = p2; + int r2 = r - p2; + t.t3 = r2; + if (t.t2 + 1 >= p && t.t3 + 1 >= p) { + possible = true; + } else if (t.t2 + 2 >= p && t.t3 + 2 >= p && run > 1) { + + if (s <= 0) { + p--; + possible1 = false; + } else { + s--; + } + possible = true; + + } else if (p2 < 1) { + t.t1 = null; + return s; + } else { + p2--; + } + } + + if (t.t3 > p) { + p++; + possible1 = false; + } + + } + return s; + } +} +" +A22229,"package teardrop.jam2012.qr.dancing; + +import java.io.*; + +public class Launcher { + public static void main(String[] args) { + if (args.length < 2) { + System.err.println(""Enter input and output filenames""); + System.exit(1); + } + + try ( + Reader reader = new InputStreamReader(new FileInputStream(args[0]), ""UTF-8""); + Writer writer = new OutputStreamWriter(new FileOutputStream(args[1]), ""UTF-8"")) { + SetSolver solver = new SetSolver(reader, writer); + solver.solve(); + } catch (UnsupportedEncodingException e) { + System.err.println(""Unsupported encoding: ""+ e.getMessage()); + } catch (FileNotFoundException e) { + System.err.println(""Unable to open file: "" + e.getMessage()); + } catch (IOException e) { + System.err.println(""IO error: "" + e.getMessage()); + } + } +} +" +A22251," +import java.util.*; + +public class QualB12 { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + + for (int i = 1; i <= T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int g = 0; + + for (int j = 1; j <= N; j++) { + int a = in.nextInt(); + if (a/3 >= p) ++g; + else if (a/3 >= p-2) { + if (a/3 == p-1) { + if (a%3 == 2) { + ++g; + } + else if (a%3 == 1) { + ++g; + } + else if (a%3 == 0) { + if (S > 0 && a/3 > 0) { + ++g; + --S; + } + } + } + else if (a/3 == p-2) { + if (a%3 == 2) { + if (S > 0){ + ++g; + --S; + } + } + } + else { + System.out.println(""a is "" + a + "" and p is "" + p); + assert false; + } + } + } + System.out.println(""Case #"" + i + "": "" + g); + + } + } + + /* Self-Made Test Cases + + 4 + 3 0 5 0 0 0 + 3 1 6 14 13 12 + 2 0 10 30 30 + 4 1 5 13 12 11 11 + + Case #1: 0 + Case #2: 1 + Case #3: 2 + Case #4: 2 + + */ +} + +" +A21594," +public class kickClass { + + public static void main(String[] args){ + //testGraph.run(); + //testCollection.run(); + solutionRunner t1 = new solutionRunner(); + } +} +" +A22344," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author Chung Lee + */ +public class DanceGoogler { + + public static void Main(String[] args) throws FileNotFoundException { + + Scanner scanner = new Scanner(new File(args[0])); + PrintWriter writer = new PrintWriter(args[1]); + + int noCase = scanner.nextInt(); + + for (int i = 0; i < noCase; i++) { + int noGooglers = scanner.nextInt(); + int noSurprice = scanner.nextInt(); + int P = scanner.nextInt(); + + List totalScore = new ArrayList(); + List noSurpriceBest = new ArrayList(); + for (int j = 0; j < noGooglers; j++) { + int total = scanner.nextInt(); + totalScore.add(total); + noSurpriceBest.add((int) Math.ceil(total / 3.)); + } + + int noAtLeastP = 0; + + for (int j = 0; j < totalScore.size(); j++) { + if (noSurpriceBest.get(j) >= P) { + noAtLeastP++; + } else if ((totalScore.get(j) % 3 == 0 || totalScore.get(j) % 3 == 2) + && totalScore.get(j) != 0 + && totalScore.get(j) <= 27 + && noSurpriceBest.get(j) == P - 1 + && noSurprice > 0) { + noSurprice--; + noAtLeastP++; + } + } + + System.out.print(String.format(""Case #%d: %d"", i + 1, noAtLeastP)); + writer.print(String.format(""Case #%d: %d"", i + 1, noAtLeastP)); + + if (i != noCase - 1) { + System.out.println(); + writer.println(); + } + + } + + writer.close(); + } +} +" +A20665,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.HashSet; +import java.util.Set; + + +public class Dancing { + + + public static void main(String [] args) throws NumberFormatException, IOException + { + BufferedReader in = new BufferedReader(new StringReader(args[0])); + int rows = Integer.parseInt(in.readLine()); + for ( int i = 1; i <= rows; i++) + { + String line = in.readLine(); + String[] vals = line.split("" ""); + int googlers = Integer.parseInt(vals[0]); + int surprising = Integer.parseInt(vals[1]); + int score = Integer.parseInt(vals[2]); + int [] googlerScores = new int[googlers]; + + for ( int j = 0; j < googlerScores.length; j++) + { + googlerScores[j]=Integer.parseInt(vals[3+j]); + } + + //System.out.println(""Surprising: "" + surprising); + int maxCount = 0; + + int normalCount = 0; + int suprisingCount = 0; + Set normals = new HashSet(); + for ( int k = 0; k < googlers; k++ ) + { + if ( getBestRegularScore(googlerScores[k])>=score ) + { + normalCount++; + normals.add(k); + } + } + + for ( int k = 0; k < googlers; k++ ) + { + if ( !normals.contains(k) + && getBestSurprisingScore(googlerScores[k])>=score ) + { + suprisingCount++; + } + if ( suprisingCount == surprising ) + { + break; + } + } + +// for ( int j = 0; j < Math.pow(2, googlers); j++) +// { +// if ( instanceCount(j) == surprising ) +// { +// //System.out.println(""Case: "" + Integer.toBinaryString(j)); +// int count = 0; +// for ( int k = 0; k < googlers; k++ ) +// { +// int pow = (int) Math.pow(2,k); +// boolean normal = (pow & j) == 0; +// //System.out.println(k+"": ""+ normal); +// if ( normal && getBestRegularScore(googlerScores[k])>=score ) +// { +// count++; +// } +// else if ( !normal && getBestSurprisingScore(googlerScores[k])>=score ) +// { +// count++; +// } +// } +// if ( count >= maxCount ) +// { +// maxCount = count; +// } +// +// } +// } + + System.out.println(""Case #""+i+"": "" + (normalCount+suprisingCount)); + } + } + + public static int instanceCount(int number) + { + int count = 0; + for ( char c : Integer.toString(number, 2).toCharArray() ) + { + if ( c == '1' ) + { + count++; + } + } + return count; + } + + public static int getBestRegularScore(int totalScore) + { + int bestScore = totalScore/3; + if ( totalScore%3>0) + { + bestScore++; + } + return bestScore>10?10:bestScore; + } + + public static int getBestSurprisingScore(int totalScore) + { + if ( totalScore == 0 ) + { + return 0; + } + int ret = (totalScore+4)/3; + return ret>10?10:ret; + } +} +" +A22506,"package q2; + +import java.util.Scanner; + +public class DWG { + + /** + * @param args + */ + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int _t = 0; _t < t; _t++) { + + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int floor, sfloor; + if (p == 0){ + floor = 0; + } else { + floor = p+(2*(p-1)); + } + if (p == 1){ + sfloor = 1; + } else { + sfloor = p+(2*(p-2)); + } + + int y = 0; + for (int _n=0; _n= floor) { + y++; + } else if (ti >= sfloor && s > 0 && sfloor >= 0) { + y++; + s--; + } + } + + + System.out.printf(""Case #%d: %d\n"",_t+1,y); + } + } + +} +" +A23028,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +class DancingWithTheGooglers { + + public static void main(String[] args) throws FileNotFoundException { + + File input = new File(""/home/michael/sandbox/codejam2012/B-large.in.txt""); + File output = new File(""/home/michael/sandbox/codejam2012/B-large.out.txt""); + PrintWriter fout = new PrintWriter(output); + Scanner s = new Scanner(input); + int tests = s.nextInt(); + for( int t = 0; t < tests; t++ ) { + int dancers = s.nextInt(); + int surprises = s.nextInt(); + int threshold = s.nextInt(); + int definites = 0; + int potential_surprises = 0; + for( int d = 0; d < dancers; d++ ) { + int score = s.nextInt(); + int[] analysis = new int[2]; + process(score,analysis); + if( analysis[0] >= threshold ) { + if( analysis[0] == threshold && analysis[1] == 1 ) { + potential_surprises++; + } else { + definites++; + } + } + } + fout.println( ""Case #"" + (t+1) + "": "" + + (definites + Math.min(surprises,potential_surprises)) ); + } + fout.close(); + } + + //analysis[0] is the highest achievable individual score given + //the total score; analysis[1] is 1 if that score would be + //surprising and 0 otherwise + private static void process(int score, int[] analysis) { + analysis[1] = 0; + int avg_score = score / 3; + if( score < 2 ) { // special cases, since -1 is not a legal score + analysis[0] = score; + } else if( score > 28 ) { // also special cases; 11 is also illegal + analysis[0] = 10; + } else if( score % 3 == 0 ) { + analysis[0] = avg_score + 1; + analysis[1] = 1; + } else if( score % 3 == 1 ) { + analysis[0] = avg_score + 1; + // not surprising + } else if( score % 3 == 2 ) { + analysis[0] = avg_score + 2; + analysis[1] = 1; + } + } +} +" +A22555,"import java.util.Scanner; + +public class dance +{ +public static void main(String args[]) +{ +Scanner sc = new Scanner(System.in); +int n = sc.nextInt(); +int test = 1, i, j; +int[] arr = new int[100]; +int[] arr1 = new int[100]; +while (test <= n ) { + int N_G = sc.nextInt(); + int N_S = sc.nextInt(); + int query = sc.nextInt(); + int count = 0; + int surprize_count = 0; + for(i = 0 ; i < N_G ; i++) + arr[i] = sc.nextInt(); + int total = 0; + int temp = query-1; + int temp1 = query-2; + for(i = 0 ; i < N_G ; i++){ + if(arr[i]/3 >= query || (arr[i]/3 == query-1 && arr[i]%3 > 0)) + total++; + else if(N_S > 0 && ((arr[i]/3 == temp1 && arr[i]%3 == 2) || (arr[i]/3 == temp && temp != 0))){ + N_S--; + total++; + } + } + arr1[test-1] = total; + test++; + } +for(i = 1 ; i <= n ; i++) + System.out.println(""Case #"" +i+"": ""+arr1[i-1]); +} +} +" +A21354,"package common; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.LinkedList; +import java.util.Queue; + +public class FileTranslatorBasis { + + private int numOfCase; + private File file; + Queue dataList = new LinkedList(); + + + + public static FileTranslatorBasis getInstance(String fname){ + if(fname ==null){ + throw new IllegalArgumentException(); + } + return new FileTranslatorBasis(new File(fname)); + } + + private FileTranslatorBasis(File file) { + this.file = file; + read(); + } + + private void read(){ + try{ + FileReader fr = new FileReader(this.file); + BufferedReader br = new BufferedReader(fr); + + String line; + while((line = br.readLine())!=null){ + dataList.add(line); + } + }catch(IOException e){ + e.printStackTrace(); + } + numOfCase = Integer.parseInt(dataList.poll()); + } + + public int getNumOfCase(){ + return numOfCase; + } + + public int getIntData(){ + return Integer.parseInt(dataList.poll()); + } + + public int[] getIntDataArray(){ + String[] tmp = getStrDataArray(); + int[] data = new int[tmp.length]; + int i = 0; + for(String t: tmp){ + data[i++] = Integer.parseInt(t); + } + return data; + } + + + public long getLongData(){ + return Long.parseLong(dataList.poll()); + } + + public long[] getLongDataArray(){ + String[] tmp = getStrDataArray(); + long[] data = new long[tmp.length]; + int i = 0; + for(String t: tmp){ + data[i++] = Long.parseLong(t); + } + return data; + } + public String getStrData(){ + return dataList.poll(); + } + + public String[] getStrDataArray(){ + return dataList.poll().split("" ""); + } + + + +} +" +A22328,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class Bsmall { + + private static int[] triplet(int total, boolean special) { + int[] scores = {0, 0, 0}; + + for (int i = 10; i != -1; --i) { + + for (int j = i; j != -1; --j) { + + // Si no hay mas especiales + if ((special) ? i - j > 2 : i - j > 1) + break; + + for (int k = j; k != -1; --k) { + + // Si no hay mas especiales + if ((special) ? j - k > 2 || i - k > 2: j - k > 1 || i - k > 1) + break; + + if (i + j + k == total) { + scores[0] = i; + scores[1] = j; + scores[2] = k; + + return scores; + } + } + } + } + + return scores; + } + + public static void main(String[] args) { + BufferedReader br = null; + + try { + br = new BufferedReader(new FileReader(args[0])); + + int t = Integer.parseInt(br.readLine()); + + for (int i = 0; i != t; ++i) { + System.out.print(""Case #"" + (i+1) + "": ""); + + String[] tokens = br.readLine().split("" ""); + + int n = Integer.parseInt(tokens[0]); // Num jugadores + int s = Integer.parseInt(tokens[1]); // Num especiales + int p = Integer.parseInt(tokens[2]); // Score a buscar + int count = 0; + + for (int g = 0; g != n; ++g) { + int total = Integer.parseInt(tokens[g + 3]); + + if (triplet(total, false)[0] >= p) { + ++count; + } else if (s > 0 && triplet(total, true)[0] >= p) { + ++count; + --s; + } + + } + + System.out.println(count); + } + + } catch (IOException e) { + System.out.println(""Error :(""); + } finally { + + try { + if (br != null) br.close(); + } catch (IOException ex) { + System.out.println(""Error :(""); + } + } + } +}" +A21403,"package it.simone.google.code.jam2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class GoogleCodeJamManager { + + public static void main(String[] args) { +// GoogleCodeExercise tm = new Translator(); +// GoogleCodeJamManager.execute(""inputFile_Translator.in"",""outputFile_Translator.out"",tm); + GoogleCodeExercise dancer = new Dancer(); + GoogleCodeJamManager.execute(""inputFile_Dancer.in"",""outputFile_Dancer.out"",dancer); + } + + public static void execute(String inputFile,String outputFile,GoogleCodeExercise exercise) { + + BufferedReader br = null; + BufferedWriter bw=null; + int testNumber=0; + + try { + exercise.initialize(); + br = new BufferedReader(new FileReader(inputFile)); + bw=new BufferedWriter(new FileWriter(outputFile)); + String line = br.readLine(); + testNumber=Integer.parseInt(line); + line=br.readLine(); + int testCounter=1; + while (line != null) { + System.out.println(""Test"" +testCounter +""/""+testNumber+ ""\t Line="" + line); + String translatedLine=exercise.execute(line); + bw.write(""Case #""+testCounter+"": ""+translatedLine+""\n""); + line=br.readLine(); + testCounter++; + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally { + + try { + if (br != null) + br.close(); + if(bw!=null) + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + +} +" +A20221,"package codejam2; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Date; +import java.util.Scanner; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +public abstract class CodejamRunner { + public static final int NUM_WORKERS = 4; + public static final int TIMEOUT_MINUTES = 10; + + // Default behavior is to get number of test cases that follow + public int preparse(Scanner s) { + String line = s.nextLine(); + return new Scanner(line).nextInt(); + } + + public abstract CodejamCase parseCase(Scanner s); + + public void run(String[] args) { + Date start = new Date(); + // Set up worker threads + ExecutorService es = Executors.newFixedThreadPool(args.length > 0 ? NUM_WORKERS : 1); + + // Read in file one test at a time and put in work queue + try { + Scanner s = new Scanner(new FileInputStream(args.length > 0 ? args[0] : ""sample"")); + PrintStream o = args.length > 0 ? + new PrintStream(new FileOutputStream(args[0]+ "".output"")) : + System.out; + + int numTests = preparse(s); + + final CodejamCase[] tests = new CodejamCase[numTests]; + + for (int i = 0; i < numTests; i++) { + final int id = i; + tests[id] = parseCase(s); + es.execute(new Runnable() { + @Override + public void run() { + tests[id].compute(); + System.err.print(id + "" ""); + } + }); + } + + // Wait until work queue is empty + try { + es.shutdown(); + if (!es.awaitTermination(TIMEOUT_MINUTES, TimeUnit.MINUTES)) { + System.err.println(""Timeout! "" + es.shutdownNow().size() + "" tests incomplete.""); + } + } catch (InterruptedException e) { + System.err.println(""Interrupted!""); + e.printStackTrace(); + } + + // Output results + for (int i = 0; i < numTests; i++) { + o.println(""Case #"" + (i+1) + "": "" + tests[i].getOutput()); + } + + } catch (IOException e) { + System.err.println(""IO error!""); + e.printStackTrace(); + } + + System.err.println(""\nExecution time: "" + (new Date().getTime() - start.getTime()) + ""(ms)""); + System.exit(0); + } + + public static String padInt(int num, int len) { + String s = ""00000000000"" + String.valueOf(num); + return s.substring(s.length()-4); + } +} +" +A20102,"import java.util.*; + +public class Problem2 { + public Problem2(){ + Scanner scan = new Scanner(System.in); + int inputs = scan.nextInt(); + for(int i=1; i<=inputs; i++){ + int googlers = scan.nextInt(); + int sur = scan.nextInt(); + int bResult = scan.nextInt(); + int num = 0; + int[] results = new int[googlers]; + for(int j=0; j=bS || score[i][2]>=bS || score[i][3]>=bS){ + score[i][0]=1; + } + } + int x = 0; + List z = new ArrayList(); + for(int i=0; i= bS-1 && f1 && score[a][4]==1){ + f++; + } + } + x = x-f; + return g-x; + } + + public static void main(String[] args){ + new Problem2(); + } +} +" +A20245,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlejam2012qrb; + +import java.io.*; +/** + * + * @author Vincent + */ +public class GoogleJam2012QRB { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try{ + //Prepare the reader + BufferedReader in = new BufferedReader( new FileReader(""inputFile.txt"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""outputFile.txt"")); + + //Get the amount of cases to be solved + String str = in.readLine(); + int caseCount = Integer.parseInt(str); + + //For each test case + for(int i = 0; i < caseCount; i++){ + //Get the line of the problem + str = in.readLine(); + + String[] problemData = str.split("" ""); + int googlerCount = Integer.parseInt(problemData[0]); + int suprCount = Integer.parseInt(problemData[1]); + int targetResult = Integer.parseInt(problemData[2]); + + int autoPassScore = targetResult * 3 - 2; + int surpPassScore = autoPassScore - 2; + + if(surpPassScore < 1) surpPassScore = 1; + + int autoCountPass = 0; + int surpCountPass = 0; + int totalCountPass; + + for(int j = 0; j < googlerCount; j++){ + int currentScore = Integer.parseInt(problemData[j+3]); + if(currentScore >= autoPassScore) autoCountPass++; + else if(currentScore >= surpPassScore) surpCountPass++; + } + + totalCountPass = autoCountPass; + if(suprCount <= surpCountPass) totalCountPass += suprCount; + else totalCountPass += surpCountPass; + + out.write(""Case #"" + (i+1) + "": ""); + out.write("""" + totalCountPass); + + out.newLine(); + System.out.println(); + } + in.close(); + out.close(); + } + catch (Exception e){ + System.out.println(""Read Failed""); + } + } +} +" +A21114,"import java.io.*; +import java.util.*; + +public class ProblemB { + + private static final int[] bestSurprise = new int[31]; + private static final int[] bestBoring = new int[31]; + + private static void seed() { + Arrays.fill(bestSurprise, -1); + Arrays.fill(bestBoring, -1); + for (int i = 0; i <= 10; i++) { + for (int j = Math.max(0, i - 2); (j <= i + 2) && (j <= 10); j++) { + for (int k = Math.max(0, i - 2); (k <= i + 2) && (k <= 10); k++) { + if (Math.abs(k - i) > 2 || Math.abs(k - j) > 2 || Math.abs(i - j) > 2) { + continue; + } + int total = i + j + k; + int max = Math.max(i, Math.max(j, k)); + if (Math.abs(k - i) == 2 || Math.abs(k - j) == 2 || Math.abs(i - j) == 2) { + bestSurprise[total] = Math.max(bestSurprise[total], max); + } else { + bestBoring[total] = Math.max(bestBoring[total], max); + } + } + } + } + } + + + public static int solve(int[] scores, int S, int P) { + int[][] history = new int[scores.length + 1][S + 1]; + for (int[] cases : history) { + Arrays.fill(cases, -1); + } + return solve(scores, 0, S, P, history); + } + + private static int solve(int[] scores, int index, int S, int P, int[][] history) { + if (index >= scores.length) { + if (S > 0) { + return -1; + } else { + return 0; + } + } else if ((S < 0) || (S > scores.length - index)) { + return -1; + } else if (history[index][S] != -1) { + return history[index][S]; + } + int best = -1; + if (S > 0 && bestSurprise[scores[index]] != -1) { + int surpriseAttempt = solve(scores, index + 1, S - 1, P, history); + if (surpriseAttempt != -1) { + best = Math.max(best, surpriseAttempt + (bestSurprise[scores[index]] >= P ? 1 : 0)); + } + } + if (bestBoring[scores[index]] != -1) { + int boringAttempt = solve(scores, index + 1, S, P, history); + if (boringAttempt != -1) { + best = Math.max(best, boringAttempt + (bestBoring[scores[index]] >= P ? 1 : 0)); + } + } + history[index][S] = best; + return best; + } + + public static void main(String[] args) throws Exception { + seed(); + Scanner input = new Scanner(System.in); + int T = Integer.parseInt(input.nextLine().trim()); + for (int i = 0; i < T; i++) { + String[] tokens = input.nextLine().split("" ""); + int N = Integer.parseInt(tokens[0].trim()); + int S = Integer.parseInt(tokens[1].trim()); + int P = Integer.parseInt(tokens[2].trim()); + int[] scores = new int[N]; + for (int j = 0; j < N; j++) { + scores[j] = Integer.parseInt(tokens[3 + j].trim()); + } + System.out.println(""Case #"" + (i+1) + "": "" + solve(scores, S, P)); + } + } +}" +A20961,"import java.io.*; +import java.util.StringTokenizer; + +/** + * User: Grant + * Date: 14/04/12 + * Time: 22:51 + */ +public class ProblemB { + public static void main(String[] args) throws IOException { + + // Prepare output file + File outputFile = new File(""E:\\Programming\\Java\\CodeJam\\resources\\problemBOutput.txt""); + if(outputFile.exists()) { + outputFile.delete(); + } + + FileWriter fileWriter = new FileWriter(outputFile); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + + // Read input file + File inputFile = new File(""E:\\Programming\\Java\\CodeJam\\resources\\TestInput.txt""); + FileReader fileReader = new FileReader(inputFile); + BufferedReader bufferedReader = new BufferedReader(fileReader); + + Integer testCases = Integer.parseInt(bufferedReader.readLine().trim()); + for(int i = 0; i < testCases; i++) { + StringTokenizer st = new StringTokenizer(bufferedReader.readLine().trim(), "" ""); + int googlerCount = Integer.parseInt(st.nextToken().trim()); + int totalSurpriseCount = Integer.parseInt(st.nextToken().trim()); + int bestResult = Integer.parseInt(st.nextToken().trim()); + + int outputNum = 0; + + int surprisesUsed = 0; + start: for(int j = 0; j < googlerCount; j++) { + int total = Integer.parseInt(st.nextToken().trim()); + boolean surpriseAvailable = false; + for(int x = 0; x <= 10; x++) { + for(int y = 0; y <= 10; y++) { + for(int z = 0; z <= 10; z++) { + if(x + y + z == total + && (x >= bestResult + || y >= bestResult + || z >= bestResult)) { + if(Math.abs(x-y) <= 1 && Math.abs(y-z) <= 1 && Math.abs(x-z) <= 1) { + outputNum++; + continue start; + } + if(!surpriseAvailable + && surprisesUsed < totalSurpriseCount + && Math.abs(x-y) <= 2 && Math.abs(y-z) <= 2 && Math.abs(x-z) <= 2) { + surpriseAvailable = true; + } + } + } + } + } + if(surpriseAvailable) { + surprisesUsed++; + outputNum++; + } + } + + bufferedWriter.write(""Case #"" + (i+1) + "": "" + outputNum + ""\n""); + } + + bufferedReader.close(); + fileReader.close(); + + // Write output file + bufferedWriter.flush(); + fileWriter.flush(); + bufferedWriter.close(); + fileWriter.close(); + } +} + + + + + + + + + + + + + + + + + + +" +A21964,"import java.util.Scanner; + +public class Q2 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int ncases = Integer.parseInt(in.nextLine()); + for(int q = 1; q <= ncases; q++) { + System.out.print(""Case #"" + q + "": ""); + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int total = 0; + for(int i = 0; i < n; i++) { + int t = in.nextInt(); + int noSurprise = (int) Math.ceil((double) t / 3); + if(noSurprise >= p) { + total++; + continue; + } + if(s > 0 && (t != 0) && (t < 28) && (t % 3 == 0 || t % 3 == 2)) { + if(noSurprise + 1 >= p) { + total++; + s--; + continue; + } + } + } + System.out.println(total); + } + } +} +" +A21970,"package com.renoux.gael.codejam.utils; + + + +/** + * Pour tests unitaires + * + * @author renouxg + */ +public final class StringUtils { + + public static String multiply(String text, int nb) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < nb; i++) { + builder.append(text); + } + return builder.toString(); + } + + +} +" +A21780,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + public static void main(String args[]){ + try { + Scanner scanner = new Scanner(new File(""B-large.in"")); + int noOfCase = scanner.nextInt(); + scanner.nextLine(); +// System.out.println(noOfCase); + String [] cases = new String [noOfCase]; + int counter=0; + while(scanner.hasNextLine()){ + cases[counter] = scanner.nextLine(); +// System.out.println(cases[counter]); + counter++; + } + + for(int i =0 ;i 0) { + if (extraScore == 0) { + if (superisingCounter < noOfSuprise) { + if (diff == 1) { + leastScoreCounter++; + superisingCounter++; + } + } + if (diff < 1) { + leastScoreCounter++; + } else { + + } + + } else if (extraScore == 1) { + + if (diff <= 1) { + leastScoreCounter++; + } else { + + } + + } else { + // extraScore ==2 + if (superisingCounter < noOfSuprise) { + if (diff == 2) { + leastScoreCounter++; + superisingCounter++; + } + } + + if (diff <= 1) { + leastScoreCounter++; + } + } + } else if (scoreOfPeople[i] == 0) { + if(diff ==0 ){ + leastScoreCounter++; + } + } + } + + +// System.out.println(); + + return leastScoreCounter; + } +} +" +A22916,"import java.util.Scanner; + +class Main{ + + public static void main(String[] args){ + Scanner S= new Scanner(System.in); + int T= S.nextInt(),i,j; //Variables de Control + int n,s,p,val; //Variables del Problema + int score,aux; + for(i=0;i=p){ + val++; + }else if((score%3==2 || score%3==0) && score>1 && score<29 && s>0 && (aux+1)==p){ + val++; + s--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + val); + } + } + +}" +A20244,"import java.util.*; + +public class B { + + public static void main(String[] args) { + new B(); + } + + public B() { + Scanner scan = new Scanner(System.in); + int NCASES = scan.nextInt(); + for (int ZZ = 1; ZZ <= NCASES; ZZ++) { + System.out.print(""Case #""+ZZ+"": ""); + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int count = 0; + for (int i = 0; i < N; i++) { + int t = scan.nextInt(); + if (t < p) continue; + if (t > (p-1)*3) { + count++; + } else if (t >= p*3-4 && S > 0) { + count++; + S--; + } + } + System.out.println(count); + } + } + +} +" +A21615,"import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + + +public class QuestionA extends Question{ + + private static Map translationMap; + private static boolean isInit; + private StringBuilder sb; + + public QuestionA(Result result, Counter counter) + { + super(result, counter); + if (!isInit) { + init(); + isInit=true; + } + } + + private void init() { + translationMap = new HashMap(); + String text = ""zyeq""+""ejp mysljylc kd kxveddknmc re jsicpdrysi""+""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd""+""de kr kd eoya kw aej tysr re ujdr lkgc jv""; + String translation = ""qaoz""+""our language is impossible to understand""+""there are twenty six factorial possibilities""+""so it is okay if you want to just give up""; + for (int i = 0; i < text.length(); i++) { + if (!translationMap.containsKey(text.charAt(i))) + translationMap.put(text.charAt(i), translation.charAt(i)); + } + } + + @Override + public void readInput(Scanner scanner) { + sb = new StringBuilder(); + sb.append(scanner.nextLine()); + } + + @Override + public String solution() { + for (int i = 0; i < sb.length(); i++) { + sb.setCharAt(i, translationMap.get(sb.charAt(i))); + } + return sb.toString(); + } + + +} +" +A20972,"package org.marcus905.gcj2012; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static void main(String[] args){ + try { + + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(""/home/marcus905/Desktop/in""))); + + Scanner sc = new Scanner(bis); + PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(new File(""/home/marcus905/Desktop/out"")))); + int len = Integer.parseInt(sc.next().trim()); + sc.nextLine(); + int[] results = new int[len]; + + for(int i = 0; i < len; i++){ + + int googlers = 0, surprisingscoresets = 0, thresholdgrade = 0, currentgoogler = 0; + int[] scores = new int[3]; + googlers = sc.nextInt(); + surprisingscoresets = sc.nextInt(); + thresholdgrade = sc.nextInt(); + + for(int j = 0; j < googlers; j++){ + currentgoogler = sc.nextInt(); + if ((currentgoogler/3==thresholdgrade-2 && surprisingscoresets > 0 + && currentgoogler % 3 == 2) || + (currentgoogler/3==thresholdgrade-1 && surprisingscoresets > 0 + && currentgoogler % 3 == 0) + && (currentgoogler > 1 && currentgoogler < 29)){ + surprisingscoresets--; + /* + int averagegrade = currentgoogler/3; + for(int k = 0; k<3; k++) + scores[k]=averagegrade; + currentgoogler-=3*averagegrade; + switch(currentgoogler){ + case 2:scores[0]+=2; currentgoogler=0; break; + case 1:scores[1]+=1; currentgoogler=0; + case 0:scores[2]+=1; scores[0]-=1; currentgoogler=0; + } + */ + results[i]++; + } + else if (currentgoogler/3==thresholdgrade-1 && currentgoogler % 3 > 0 + || currentgoogler/3>=thresholdgrade){ + results[i]++; + } + + } + + + + + + } + + int k = 1; + for(int j: results){ + pw.print(""Case #""+k+"": ""+j+""\n""); + k++; + } + pw.close(); + + } + catch(Exception e){ + e.printStackTrace(); + } + } + +} +" +A22188,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; + +public class ProblemB { + + private static final String OUT = ""C:/workspaces/tc/CodeJam/src/B.out""; + private static final String IN = ""D:/downloads/B-large.in""; + + public static boolean canHaveScoreWithoutSurprise(int score, int requiredScore) { + if (requiredScore == 0) { + return true; + } + return Math.max(0, requiredScore - 1) * 3 + 1 <= score; + } + + public static boolean canHaveScoreWithSurprise(int score, int requiredScore) { + return Math.max(0, requiredScore - 2) * 3 + 2 <= score; + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(IN)); + BufferedWriter bw = new BufferedWriter(new FileWriter(OUT)); + int T = Integer.parseInt(br.readLine()); + for (int i = 0; i < T; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = Integer.parseInt(st.nextToken()); + } + int withoutSurpriseTotal = 0; + int withSurpriseTotal = 0; + for (int score : t) { + if (canHaveScoreWithoutSurprise(score, p)) { + withoutSurpriseTotal++; + } else { + if (canHaveScoreWithSurprise(score, p)) { + withSurpriseTotal++; + } + } + } + int res = withoutSurpriseTotal + Math.min(withSurpriseTotal, S); + bw.write(""Case #"" + (i + 1) + "": "" + res + ""\n""); + } + bw.close(); + } + +} +" +A20684,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class problem2 +{ + void main() + { + solve(); + } + + void solve() + { + try + { + FileInputStream fstream = new FileInputStream(""pr2_input.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter fout = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fout); + + int iCases = Integer.parseInt(br.readLine()); + for (int iStep = 0; iStep < iCases; iStep++) + { + String strLine = br.readLine(); + String[] numbers = strLine.split("" ""); + + int N = Integer.valueOf(numbers[0]).intValue(); + int S = Integer.valueOf(numbers[1]).intValue(); + int P = Integer.valueOf(numbers[2]).intValue(); + + List notes = new ArrayList(); + for (int jStep = 0; jStep < N; jStep++) + { + notes.add(Integer.valueOf(numbers[jStep + 3]).intValue()); + } + + //< Calcculate notes + int iNormalMinNote = P * 3 - 2; + int iSurpriseMinNote = P * 3 - 4; + + Collections.sort(notes); + + int iGooglers = 0; + for (int jStep = 0; jStep < notes.size(); jStep++) + { + if (S > 0) + { + if (notes.get(jStep) >= iSurpriseMinNote) + { + if (notes.get(jStep) >= 2) + { + S--; + iGooglers++; + } + } + } + else + { + if (notes.get(jStep) >= iNormalMinNote) + { + iGooglers++; + } + } + } + + if (iStep != (iCases - 1)) + { + out.write(String.format(""Case #%d: %d\n"", iStep + 1, iGooglers)); + } + else + { + out.write(String.format(""Case #%d: %d"", iStep + 1, iGooglers)); + } + } + + out.close(); + } + catch (Exception e) + { + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A20078,"package qual2012.B; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class MainDefault2 { + + //private static String inputFileName = ""sample.in""; + //private static String inputFileName = ""B-small-attempt1.in""; + private static String inputFileName = ""B-large.in""; + //private static String outputFileName = ""sample.out""; + //private static String outputFileName = ""B-small-1.out""; + private static String outputFileName = ""B-large.out""; + + private static int nbrOfTests; + private static String inputFolder = ""input/""; + private static String outputFolder = ""output/""; + + /** + * @param args + */ + public static void main(String[] args) { + + MainDefault2 mainDefault = new MainDefault2(); + + MyTestCase[] input = mainDefault.readInputCodeJam(inputFileName); + StringBuffer output = mainDefault.createOutput(input); + printToFile(output, outputFileName); + } + + public MainDefault2() { + // TODO if anything should be prepared for all testcases + } + + public MyTestCase[] readInputCodeJam(String fileName) { + MyTestCase[] testCases = null; + File file = new File(inputFolder + fileName); + try { + Scanner scanner = new Scanner(file); + + nbrOfTests = Integer.valueOf(scanner.nextLine()); + testCases = new MyTestCase[nbrOfTests]; + + for (int i = 0; i < nbrOfTests; i++) { + // TODO line(s) / testcase + String tmp = scanner.nextLine(); + + String[] testCaseInput = tmp.split("" ""); + MyTestCase obj = new MyTestCase(testCaseInput); + + testCases[i] = obj; + } + + scanner.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return testCases; + } + + public StringBuffer createOutput(MyTestCase[] myTestCases) { + StringBuffer buffer = new StringBuffer(); + int count = 1; + for (int i = 0; i < nbrOfTests; i++) { + buffer.append(""Case #"" + count++ + "": ""); + + MyTestCase myTestCase = myTestCases[i]; + buffer.append(myTestCase.getAnswer()); + + buffer.append(""\n""); + } + return buffer; + } + + public static void printToFile(StringBuffer output, String fileName) { + try { + FileWriter fstream = new FileWriter(outputFolder + fileName); + BufferedWriter out = new BufferedWriter(fstream); + out.write(output.toString()); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + class MyTestCase { + private String answer; + private int nbrOfGooglers; + private int nbrOfSuprises; + private int bestResult; + private int[] totalPoints; + + public MyTestCase(String[] input) { + nbrOfGooglers = Integer.valueOf(input[0]); + nbrOfSuprises = Integer.valueOf(input[1]); + bestResult = Integer.valueOf(input[2]); + + totalPoints = new int[nbrOfGooglers]; + for (int i = 0; i < nbrOfGooglers; i++) { + totalPoints[i] = Integer.valueOf(input[3 + i]); + } + if(bestResult == 0) { + answer = String.valueOf(nbrOfGooglers); + } else if(bestResult == 1) { + int atLeastCount = 0; + for(int oneTot : totalPoints) { + if(oneTot != 0) { + atLeastCount++; + } + } + answer = String.valueOf(atLeastCount); + } else { + solve(); + } + } + + private void solve() { + //System.out.println(""nbrOf: "" + nbrOfGooglers + "", suprises: "" + nbrOfSuprises + "", bestResult: "" + bestResult); + int count = 0; + for(int oneTot : totalPoints) { + //System.out.println(""oneTot: "" + oneTot); + int limitNbr = 3*bestResult; + int inclNbr = limitNbr - 2; + int supNbr = limitNbr - 4; + if(oneTot >= inclNbr) { + count++; + } else if (oneTot >= supNbr) { + if(nbrOfSuprises > 0) { + nbrOfSuprises--; + count++; + } + } + } + answer = String.valueOf(count); + } + + private void solve2() { + int count = 0; + for (int tot : totalPoints) { + int avgNbr = tot / 3; + //System.out.println(""tot: "" + tot + "" avg: "" + avgNbr + "" bestResult: "" + bestResult); + if (avgNbr == 0) { + if(bestResult <= tot) { + //System.out.println(""small""); + count++; + } + } else if (avgNbr >= bestResult) { + count++; + //System.out.println(count); + } else if (avgNbr + 1 >= bestResult) { + int oneExtra = tot % 3; + if (oneExtra > 0) { + count++; + //System.out.println(""one: "" + count); + } else { + if (nbrOfSuprises > 0) { + nbrOfSuprises--; + count++; + //System.out.println(""two: "" + count); + } + } + } else if (avgNbr + 2 >= bestResult) { + int twoExtra = tot % 3; + if (twoExtra == 2 && nbrOfSuprises > 0) { + nbrOfSuprises--; + count++; + //System.out.println(""three: "" + count); + } + } + } + System.out.println(""finish: "" + count); + System.out.println(""nbrOfSuprises left: "" + nbrOfSuprises); + answer = String.valueOf(count); + } + + public String getAnswer() { + return answer; + } + } +} +" +A20804,"package be.mokarea.gcj.common; + +public abstract class TestCase { + private final int caseNumber; + + protected TestCase(int caseNumber) { + this.caseNumber = caseNumber; + } + + public int getCaseNumber() { + return caseNumber; + } +} +" +A21511,"import java.io.*; +import java.util.*; + +public class ProbB { + public static void main(String[] args) throws FileNotFoundException, IOException { + ProbB p = new ProbB(); + p.solveAll(); + } + int tests = 0; + Scanner in; + BufferedWriter out; + public ProbB() throws FileNotFoundException, IOException { + out = new BufferedWriter(new FileWriter(""b.out"")); + in = new Scanner(new File(""b.in"")); + tests = in.nextInt(); + in.nextLine(); + //System.out.println(tests); + } + + public void solveAll() throws IOException { + for(int i = 0; i < tests; i++) { + solve(i+1); + } + out.close(); + in.close(); + } + public void solve(int casenr) throws IOException { + int n, s, p, gar = 0, may = 0; + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + for(int i = 0; i < n; i++) { + int tot = in.nextInt(); + int tmay = 3*p-4; + int tgar = 3*p-2; + if(tmay < 0) + tmay = p; + if(tot >= tgar) { + gar++; + } else if(tot >= tmay) { + may++; + } + } + out.write(""Case #""+casenr+"": ""); + out.write(new Integer(gar+Math.min(s, may)).toString()); + out.write('\n'); + } +}" +A22242,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class B { + public static void main(String[] args) throws Exception { + Scanner scanner = new Scanner(new File(""b.in"")); + int T = scanner.nextInt(); + PrintWriter out = new PrintWriter(new File(""b.out"")); + for (int I=0; I0?1:0); + int s2 = t - s1 - s3; + if (s3 >= p) + res++; + else if (s3+1 == p && s>0) { + if (s3==s2 && s2>0) { + res++; + s--; + } + } + } + out.println(res); + } + out.close(); + } +} +" +A21914,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +class Case1 extends Question{ + public Case1(String in, String out) { + super(in, out); + } + class Unit{ + int c; + int i; + ArrayList items; + ArrayList items_old; + public Unit(int c,int i,ArrayList items){ + this.c=c; + this.i=i; + this.items=items; + items_old=new ArrayList(); + items_old.addAll(items); + } + public String solve(){ + int st=0; + int ed=items.size()-1; + Collections.sort(items); + while(true){ + int small=items.get(st); + int large=items.get(ed); + int sum=small+large; + if(sum>c) ed--; + else if(sum rr=new ArrayList(); + for(int k=0;k units=new ArrayList(); + ArrayList rst=new ArrayList(); + int n=pInt(0); + int i=1; + while(i arr=splitInt(i++,"" ""); + units.add(new Unit(c,i,arr)); + } + for(int j=0;j rate=new HashMap(); + Map change=new HashMap(); + public Case2(String in, String out) { + super(in, out); + } + public void solve(){ + ArrayList graph=new ArrayList(); + ArrayList rst=new ArrayList(); + change.put('a','y'); + change.put('b','h'); + change.put('c','e'); + change.put('d','s'); + change.put('e','o'); + change.put('f','c'); + change.put('g','v'); + change.put('h','x'); + change.put('i','d'); + change.put('j','u'); + change.put('k','i'); + change.put('l','g'); + change.put('m','l'); + change.put('n','b'); + change.put('o','k'); + change.put('p','r'); + change.put('q','z'); + change.put('r','t'); + change.put('s','n'); + change.put('t','w'); + change.put('u','j'); + change.put('v','p'); + change.put('w','f'); + change.put('x','m'); + change.put('y','a'); + change.put('z','q'); + int count=0; + for(String s:data){ + String n=""""; + for(int i=0;i word_map=new HashMap(); + for(String s:data){ + ArrayList words=splitString(s,"" ""); + for(String w:words){ + if(word_map.containsKey(w)){ + word_map.put(w,word_map.get(w)+1); + }else{ + word_map.put(w,1); + } + } + } + Set key_word=word_map.keySet(); + for(String w:key_word){ + if(word_map.get(w)>2){ + if(w.length()<=2) + System.out.println(w+"":""+word_map.get(w)); + } + } + for(String w:key_word){ + if(word_map.get(w)>2){ + if(w.length()==3) + System.out.println(w+"":""+word_map.get(w)); + } + } + for(String w:key_word){ + if(word_map.get(w)>2){ + if(w.length()==4) + System.out.println(w+"":""+word_map.get(w)); + } + } + + Set keys=rate.keySet(); + for(char key='a';key<='z';key++){ + System.out.println(key+"":""+rate.get(key)); + } + try { + write(file_out,rst); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} + +class Dancer extends Question{ + + public Dancer(String in, String out) { + super(in, out); + // TODO Auto-generated constructor stub + } + public void solve(){ + try { + data=read(file_in); + } catch (IOException e) { + e.printStackTrace(); + } + int cases=pInt(0); + data.remove(0); + ArrayList rst=new ArrayList(); + int count=1; + for(String s:data){ + ArrayList arr=splitInt(s,"" ""); + int num=arr.remove(0); + int sp=arr.remove(0); + int cut=arr.remove(0); + int cut_normal=cut*3-2; + int cut_sp=cut==1?1:cut*3-4; + int besters=0; + for(int i:arr){ + if(i>=cut_normal) + besters++; + else if(i>=cut_sp){ + if(sp>0){ + besters++; + sp--; + } + } + + } + String add=""Case #""+count+"": ""+besters; + rst.add(add); + count++; + } + try { + write(file_out,rst); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + +} + + +class Question{ + String file_in; + String file_out; + ArrayList data; + + public Question(String in,String out){ + file_in=in; + file_out=out; + try { + data=read(file_in); + } catch (IOException e) { + e.printStackTrace(); + } + + } + public void solve(){} + public int pInt(int index){ + return Integer.parseInt(data.get(index)); + } + public int pInt(String s){ + return Integer.parseInt(s); + } + public ArrayList splitString(String s,String sep){ + ArrayList arr=new ArrayList(); + String[] ss=s.split(sep); + for(int i=0;i splitInt(String s,String sep){ + ArrayList arr=new ArrayList(); + String[] ss=s.split(sep); + for(int i=0;i splitString(int index,String sep){ + return splitString(data.get(index), sep); + } + public ArrayList splitInt(int index,String sep){ + return splitInt(data.get(index), sep); + } + public ArrayList read(String filename) + throws IOException{ + ArrayList arr=new ArrayList(); + BufferedReader br=null; + br=new BufferedReader(new FileReader(filename)); + String l=null; + while((l=br.readLine())!=null){ + arr.add(l); + } + br.close(); + return arr; + } + public void write(String filename,ArrayList data) + throws IOException{ + PrintWriter pw=new PrintWriter(filename); + for(String s:data){ + pw.println(s); + } + pw.close(); + } + +} + +public class Test { + public static void main(String[] args){ + + Question a=new Dancer(""B-large.in"",""rst.txt""); + a.solve(); + + } + + +} +" +A20404,"package qualification.taskB; + +public class Task { + + private int T; + private int S; + private int P; + private int[] googlers; + + public Task(int t, int s, int p, int[] googlers) { + super(); + T = t; + S = s; + P = p; + this.googlers = googlers; + } + + public String execute() { + int result = 0; + for (int googler : googlers) { + int mod = googler % 3; + int div = (googler - mod) / 3; + if (googler != 0) { + if (div >= P) { + result++; + } else if ((P - div) == 1 && mod >= 1) { + result++; + } else if ((P - div) == 2 && mod == 2 && S > 0) { + S--; + result++; + } else if ((P - div) == 1 && mod == 0 && S > 0) { + S--; + result++; + } + } else { + if(P == 0){ + result++; + } + } + } + return result + """"; + } + +} +" +A20786,"import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * Problem B. Dancing With the Googlers + */ + +/** + * @author zdenda + * + */ +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + + Scanner in = new Scanner(System.in); + + int t = in.nextInt(); + in.nextLine(); + + for (int i = 1; i <= t; i++) { + + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + List ti = new ArrayList(); + for (int j = 0; j < n; j++) { + ti.add(in.nextInt()); + } + //in.nextLine(); + + int result = compute(s, p, ti); + + System.out.println(""Case #""+ i + "": "" + result); + + } + + } + + /** + * computes the maximum number of Googlers that could have had a best result of at least p + * + * @param s - the number of surprising triplets of scores + * @param p + * @param ti - the total points of the Googlers + * @return the maximum number of Googlers that could have had a best result of at least p + */ + public static int compute(int s, int p, List ti) { + + // limit for not surprising + int nsLimit = p + 2 * (Math.max(0, (p-1))); + // limit for surprising + int sLimit = p + 2 * (Math.max(0, (p-2))); + + // not surprising counter + int nsCount = 0; + // surprising counter + int sCount = 0; + + for (Integer score : ti) { + if(score >= nsLimit) { + ++nsCount; // if it's over not surprising limit + } else if (score >= sLimit) { + ++sCount; // if it's at over surprising limit, but under not surprising limit + } + } + + // max number of surprising scores is S, so we take the smaller number + sCount = Math.min(s, sCount); + + return nsCount + sCount; + + } + +} +" +A23072,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashSet; + +public class ProblemB { + + static ArrayList triples = new ArrayList(); + static int p = 0; + static int s = 0; + static int count = 0; + + public static void main(String args[]) { + ReadInFile(); + } + + private static int parseLine(String str) { + + count = p = s = 0; + triples.clear(); + + String[] tokens = str.split(""\\s+""); + + int N = Integer.parseInt(tokens[0]); + s = Integer.parseInt(tokens[1]); + p = Integer.parseInt(tokens[2]); + + ArrayList scores = new ArrayList(); + for (int i = 0; i < N; i++) + scores.add(Integer.parseInt(tokens[i + 3])); + + GenerateTriples(scores, s, p); + + UpdateTriples(); + + return count; + } + + private static void UpdateTriples() { + for (int[] triple : triples) { + int maxScore = Math.max(Math.max(triple[0], triple[1]), triple[2]); + if (maxScore >= p) + count++; + else if (maxScore == p - 1 && s > 0 && triple[0] > 0 + && triple[1] > 0 && triple[2] > 0) { + count++; + s--; + } + } + } + + private static void GenerateTriples(ArrayList scores, int s, int p) { + for (int score : scores) { + int d = score / 3; + int[] triple = new int[3]; + triple[0] = triple[1] = triple[2] = d; + + if (score % 3 == 1) + triple[0]++; + if (score % 3 == 2) + triple[0] = triple[1] = d + 1; + + triples.add(triple); + } + } + + private static void ReadInFile() { + try { + + FileWriter ofstream = new FileWriter(""c:/cygwin/out.txt""); + BufferedWriter out = new BufferedWriter(ofstream); + + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""c:/cygwin/B-small-attempt0.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + // Read File Line By Line + int i = 0; + strLine = br.readLine(); + while ((strLine = br.readLine()) != null) { + // Print the content on the console + System.out.println(strLine); + System.out.println(""Case #"" + (++i) + "": "" + parseLine(strLine) + + ""\n""); + out.write(""Case #"" + (i) + "": "" + parseLine(strLine) + ""\n""); + } + // Close the input stream + in.close(); + out.close(); + + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A22747,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing.with.the.googlers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author B4dT0bi + */ +public class DancingWithTheGooglers +{ + + public static String [] input; + public static String wholeOutput=""""; + public static void readInput(String inputFile) + { + BufferedReader br = null; + try + { + br = new BufferedReader(new FileReader(inputFile)); + String serializedSettings = """"; + String line = null; + while ((line = br.readLine()) != null) + serializedSettings += line + ""\n""; + input=serializedSettings.split(""\n""); + br.close(); + } catch (Exception ex) + { + Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); + } finally + { + try + { + br.close(); + } catch (IOException ex) + { + Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + public static void writeOutput(String inputFile) + { + try + { + BufferedWriter out = new BufferedWriter(new FileWriter(inputFile+"".out"")); + out.write(wholeOutput); + out.close(); + } catch (IOException e) + { + e.printStackTrace(); + } + + } + public static void main(String[] args) + { + readInput(args[0]); + + wholeOutput=""""; + for(int i=1;i0) + { + if(win(googlerPoints[n], bestResult, true)) + { + anzBest++; + surResult--; + } + } + } + } + wholeOutput+=""Case #""+i+"": ""+anzBest+""\n""; + } + writeOutput(args[0]); + + } + static HashMapresults=new HashMap(); + public static boolean win(int result,int best,boolean surprise) + { + if(!results.containsKey(result)) + { + results.put(result, getResults(result)); + } + ArrayListtmp=results.get(result); + for(int i=0;itmp2=tmp.get(i); + int max=tmp2.get(0); + int sur=tmp2.get(1); + if(sur==0) + { + if(max>=best)return true; + } + } + if(surprise) + for(int i=0;itmp2=tmp.get(i); + int max=tmp2.get(0); + int sur=tmp2.get(1); + if(sur==1) + { + if(max>=best)return true; + } + } + return false; + } + private static ArrayList getResults(int res) + { + ArrayListtmp=new ArrayList(); + HashSetmySet=new HashSet(); + for(int a=0;a<11;a++) + { + for(int b=0;b<11;b++) + { + for(int c=0;c<11;c++) + { + if(a+b+c==res) + { + int min=a; + if(bmax)max=b; + if(c>max)max=c; + if(max-min<=2) + { + ArrayListtmp2=new ArrayList(); + tmp2.add(max); + if(max-min==2) + { + tmp2.add(1); + } + else + { + tmp2.add(0); + } + if(!mySet.contains(""""+max+"";""+tmp2.get(1))) + { + mySet.add(""""+max+"";""+tmp2.get(1)); + tmp.add(tmp2); + } + } + } + } + } + } + return tmp; + } +} + +" +A22604,"import java.io.*; + +public class qua1 { + public static int[] factorize(int i) { + int[] re = new int[3]; + if(i==0) + for(int ind=0; ind<3; ind++) { + re[ind] = 0; + } + else { + int temp = i / 3; + temp++; + for(int ind=0; ind<3; ind++) { + re[ind] = temp; + } + int diff = temp * 3 - i; + for(int ind=0; ind=info[2]) + sign = 1; + } + for(int ind=0;ind<3;ind++) { + if(sign==0 && t[ind]==info[2]-1 && iter!=0 && t[ind]!=0 && diff2!=2) { + sign = 1; + iter--; + } + } + //System.out.println(sign); + if(sign==1) + res++; + } + int line = i+1; + System.out.println(""Case #"" + line + "": "" + res); + } + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + } +} +" +A22043,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + static Scanner sc; + public static void main(String a[]) throws FileNotFoundException + { + int n,i,res; + sc= new Scanner(new FileInputStream(""d:\\test\\a.in"")); + PrintStream out=new PrintStream(new FileOutputStream(""d:\\test\\a.out"")); + + n=sc.nextInt(); + for(i=1;i<=n;i++) + { + res=process(); + out.println(""Case #""+i+"": ""+res); + + } + } + static int process() + { + int n,s,p,i,val,res=0,limit=0,sLimit=1; + n=sc.nextInt(); + s=sc.nextInt(); + p=sc.nextInt(); + //if(p==0) return n; + if(p>0) limit = p+p-1+p-1; + if(p>1) sLimit = p+p-2+p-2; + if(limit<0) limit=0; + if(sLimit<0) sLimit=0; + for(i=0;i=limit) res++; + else if(val>=sLimit&&s>0) + { + s--; + res++; + } + } + if(p==0) return n; + return res; + } +} +" +A21961,"import java.util.Scanner; + +public class Dance +{ + public static void main(String[] args) + { + Scanner jin=new Scanner(System.in); + int numtries=jin.nextInt(); + + jin.nextLine(); + for(int line=0; line=0) System.out.print(totals.length-impossible); + else System.out.print(totals.length+surprises-impossible); + System.out.println(); + } + } + + private static int surprising(int totalPoints, int bestScore) + { + if(bestScore>totalPoints) return -1; //impossible ... I can't score that well! + + double remaining=(totalPoints-bestScore)/2.0; + + if(remaining==bestScore) return 1; //unsurprising + else if(remainingbestScore*/ return 1; //unsurprising //(int)(remaining+0.5)-bestScore>1; //round up + } +} +" +A20075,"package qualification; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Comparator; + + +public class B { + + private static final char[] CASE = ""Case #"".toCharArray(); + + public static void main(String[] args) throws Throwable { +// in = System.in; +// out = System.out; +// in = new FileInputStream(""in/B.in""); + in = new FileInputStream(""in/B-large.in""); + out = new PrintStream(new FileOutputStream(""out/B.out"")); + + int T = readInt(); + + int[] t = new int[128]; + for (int test = 1; test <= T; test++) { + int N = readInt();// number of googlers + int S = readInt();// number of surprising triplets + int p = readInt();// minimal result + for (int i = 0; i < N; i++) { + t[i] = readInt(); + } + // TODO need to test it with 10's and 0's +// Arrays.sort(t, 0, N); + int result = 0; + //for (int i = N-1; i >= 0; i--) { + for (int i = 0; i < N; i++) { + int v = t[i]; +// int aThird = v/3; +// if (aThird >= p) { +// result++; +// } else if (aThird*3 < v && aThird+1 == p) {// for example: 5 6 6 or 5 5 6 +// result++; +// } else if (S > 0 && aThird*3 == v && aThird*3 == (p-1)*3 && p > 1) {// 6 7 8 'anomally' +// result++; +// S--; +// } else if (S > 0 && v == (p*3)-4 && p > 1) {// 6 6 8 'anomally' +// result++; +// S--; +// } else { +// break;// no more will do +// } + if (v >= (p*3) - 2) { + result++; + } else if (S>0 && v >= 2 && v >= (p*3)-4) { + result++; + S--; + } + } + + writeOut(CASE); + writeOutNumber(test); + writeOut(':'); + writeOut(' '); + writeOutNumber(result); + writeOutLn(); + } + + flush(); + + } + + static InputStream in; + static PrintStream out; + + static byte[] buffer = new byte[8192]; + static int pos; + static int max; + + static final int maxOut = 8192; + static byte[] output = new byte[maxOut]; + static int posOut = 0; + + static char[] tmpcharr = new char[128]; + + static int pow2(int v) { + return v * v; + } + + static boolean reachedEndOfLine() throws Throwable { + while (true) { + int data = read(); + if (data == -1) + return true; + if (data == '\r' || data == '\n') { + return true; + } + if (data == ' ') { + continue; + } + pos--; + return false; + } + } + + // COMPARISION FUNCTIONS + + static boolean isValidChar(int v) { + // nao verifica o 'DELETE' (127) + return (v & 0xE0) != 0; + } + + static boolean isNum(int v) { + return v >= '0' && v <= '9'; + } + + static boolean isLowercase(int cur) { + return cur >= 'a' && cur <= 'z'; + } + + static boolean isUppercase(int cur) { + return cur >= 'A' && cur <= 'Z'; + } + + // is a letter (alphabetic) + static boolean isAlpha(int cur) { + return isLowercase(cur) || isUppercase(cur); + } + + // is alphanumeric (letters and numbers) + static boolean isAlphaNum(int cur) { + return isAlpha(cur) || isNum(cur); + } + + static boolean isMinus(int cur) { + return cur == '-'; + } + + static boolean isPlus(int cur) { + return cur == '+'; + } + + // INPUT FUNCTIONS + + static void goToBeginOfNextWord() throws Throwable { + int cur; + // se for -1 já sai do método + while ((cur = read()) != -1) { + // se for um char válido então deixa o ponteiro nele + if (cur > 32) { + pos--; + return; + } + } + } + + // return the length of the string read + static String readWord() throws Throwable { + int len = 0; + int cur; + // descarta os espacos em branco primeiro + while ((cur = read()) < 33) { + if (cur == -1) return """"; + } + + tmpcharr[len++] = (char) cur; + while ((cur = (char) read()) > 32) { + tmpcharr[len++] = (char) cur; + } + + return new String(tmpcharr, 0, len); + } + + static void discardWord() throws Throwable { + int cur; + // descarta os espacos em branco primeiro + while ((cur = read()) < 33) { + if (cur == -1) + return; + } + // descarta os valores 'validos' + while ((cur = read()) > 32) + ; + } + + static int readInt() throws Throwable { + int cur; + while (!isNum(cur = read()) && !isMinus(cur)) + if (cur == -1) + return -1; + int v = 0; + boolean minus = false; + if (isMinus(cur)) { + minus = true; + cur = read(); + } + while (isNum(cur)) { + v *= 10; + v += (cur - '0'); + cur = read(); + } + return minus ? -v : v; + } + + static char readChar() throws Throwable { + int cur; + for (;;) { + cur = read(); + if (cur == -1) + return 0; + if (cur == '\r' || cur == '\n' || cur == ' ') + continue; + + return (char) cur; + } + } + + static long readLong() throws Throwable { + int cur; + while (!isNum(cur = read()) && !isMinus(cur)) + if (cur == -1) + return -1; + long v = 0; + boolean minus = false; + if (isMinus(cur)) { + minus = true; + cur = read(); + } + while (isNum(cur)) { + v *= 10; + v += (cur - '0'); + cur = read(); + } + return minus ? -v : v; + } + + static boolean hasInput() throws Throwable { + while (true) { + int data = read(); + if (data == -1) + return false; + if ((data & 0xE0) != 0) { + pos--; + return true; + } + } + } + + static int read() throws Throwable { + if (pos >= max) { + max = in.read(buffer); + if (max < 0) + return -1; + pos = 0; + } + return buffer[pos++] & 0xff; + } + + // OUTPUT FUNCTIONS + + // escreve um char + + static void writeOut(char c) { + if (posOut >= maxOut) { + writeOutToStream(); + } + output[posOut++] = (byte) c; + } + + // escreve a quebra de linha + static void writeOutLn() { + writeOut('\n'); + } + + // escreve um char[] + static void writeOut(char[] cs) { + writeOut(cs, 0, cs.length); + } + + // escreve uma cadeia de caracteres + static void writeOut(char[] chars, int offset, int length) { + final int end = offset + length; + for (int i = offset; i < end; i++) { + writeOut(chars[i]); + } + } + + static void writeOutNumber(int value) { + int len = 0; + int pos = tmpcharr.length; + if (value == 0) { + writeOut('0'); + return; + } + boolean negative = value < 0; + if (negative) + value = -value; + while (value > 0) { + tmpcharr[--pos] = (char) ((value % 10) + '0'); + len++; + value /= 10; + } + if (negative) + writeOut('-'); + writeOut(tmpcharr, pos, len); + } + + static void writeOutNumberAsBin(int num) { + int len = 0; + int pos = tmpcharr.length; + if (num == 0) { + writeOut('0'); + return; + } + while (num > 0) { + tmpcharr[--pos] = ((num & 1) == 1) ? '1' : '0'; + len++; + num >>>= 1; + } + writeOut(tmpcharr, pos, len); + } + + static void flush() { + writeOutToStream(); + out.flush(); + } + + // PRIVATE methods must be used only by the utility methods + + private static void writeOutToStream() { + out.write(output, 0, posOut); + posOut = 0; + } + +}" +A21534,"import java.io.*; +import java.util.LinkedList; +class firstgame21 +{ + BufferedReader br; + PrintWriter pw; + + String input; + int totalpass; + + public firstgame21() + { + try + { + br = new BufferedReader(new FileReader(""B-large.in"")); + pw = new PrintWriter(new BufferedWriter(new FileWriter(""output1.txt""))); + + + input = br.readLine(); + int count = Integer.parseInt(input); + + for (int x=1; x<= count; x++) + { + totalpass = 0; + input = br.readLine(); + String data[] = input.split("" ""); + int people = Integer.parseInt(data[0]); + int extra = Integer.parseInt(data[1]); + int min = Integer.parseInt(data[2]); + + for (int y = 0; y< people ; y++ ) + { + int p = Integer.parseInt(data[3+y]); + int max; + if (p%3==0) + { + max = p/3; + //System.out.println(""max1:""+max); + if (max >= min) + { + totalpass++; + } + else if (max + 1 == min) + { + if (max == 0) + { + } + else if (extra > 0) + { + totalpass++; + extra-- ; + } + } + } + else if (p%3==1) + { + max = (p/3) + 1; + //System.out.println(""max2:""+max); + if (max >= min) + { + totalpass++; + } + } + else if (p%3==2) + { + max = (p/3) + 1; + //System.out.println(""max3:""+max); + if (max >= min) + { + totalpass++; + } + else if (max+1 == min) + { + if (extra > 0) + { + totalpass++; + extra-- ; + } + } + } + } + + System.out.println(""Case #""+x+"": ""+totalpass); + pw.println(""Case #""+x+"": ""+totalpass); + } + // after end read + pw.close(); + } + catch (IOException e) + { + System.out.println(e); + } + } + public static void main(String[] args) + { + new firstgame21(); + } +} +" +A21558,"package qualification; + +import java.io.*; + +public class Bsmall { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""./src/qualification/B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""./src/qualification/B-large.out"")); + int[][] inputs = new int[100][103]; + int casenumber = 0; + String input = null; + int total = 0; + while((input=br.readLine()) != null) + { + if(casenumber==0) + { + total = Integer.parseInt(input); + }else{ + String[] array = input.split("" ""); + // N + inputs[casenumber-1][0] = Integer.parseInt(array[0]); + // S + inputs[casenumber-1][1] = Integer.parseInt(array[1]); + // p + inputs[casenumber-1][2] = Integer.parseInt(array[2]); + // N integers ti. + for(int i=3;i=p) + { + count++; + }else if(sum%3==2) + { + if(triplets[0]==(p-2) && (s-used>0)) + { + triplets[0]+=2; + used++; + count++; + }else{ + triplets[0]++; + triplets[1]++; + if(triplets[0]>=p) + { + count++; + } + + } + }else if(sum%3==1) + { + triplets[0]++; + if(triplets[0]>=p) + { + count++; + } + }else if(sum%3==0) + { + if(s-used>0 && triplets[0]==p-1) + { + triplets[0]++; + triplets[2]--; + used++; + count++; + } + } + } + i++; + } + return count; + } +} +" +A21736,"package qualification_2012; + +import java.io.PrintWriter; +import java.util.Scanner; + +public class PB { + static Scanner sc = new Scanner(System.in); + static PrintWriter pw = new PrintWriter(System.out); + + public static void main(String[] args) { + int t = sc.nextInt(); + for (int i = 1; i <= t; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[][] d1 = new int[n + 1][s + 1]; + int[][] d2 = new int[n + 1][s + 1]; + + for (int j = 1; j <= n; j++) { + int x = sc.nextInt(); + + for (int k = 0; k <= Math.min(s, j); k++) { + if (k != 0) + d1[j][k] = Math.max(d1[j - 1][k - 1], d2[j - 1][k - 1]) + + (check(x, p, true) ? 1 : 0); + if (k < j) + d2[j][k] = Math.max(d2[j - 1][k], d1[j - 1][k]) + + (check(x, p, false) ? 1 : 0); + } + } + pw.println(""Case #"" + i + "": "" + Math.max(d1[n][s], d2[n][s])); + } + pw.flush(); + } + + static boolean check(int a, int p, boolean surprised) { + + if (surprised) { + switch (a % 3) { + case 0: + return (a > 0 && a < 28 && ((a + 3) / 3) >= p); + case 1: + return (a > 1 && a < 29 && ((a + 2) / 3) >= p); + case 2: + return (a < 27 && ((a + 4) / 3) >= p); + } + } else { + switch (a % 3) { + case 0: + return (a / 3) >= p; + case 1: + return ((a + 2) / 3) >= p; + case 2: + return ((a + 1) / 3) >= p; + } + } + return false; + } +} +" +A21193,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + + +public class Dance { + +public static int[][] JudgedScores(int a){ + + int div=a/3; + int[][] Demo=new int[1][3]; + + + if(a==0) { Demo[0][0]=0; Demo[0][1]=0; Demo[0][2]=0; + + } + else {Demo[0][0]=div; Demo[0][1]=div; Demo[0][2]=div; + + if(Demo[0][0]+Demo[0][1]+Demo[0][2]==a){} else {Demo[0][0]=Demo[0][0]+1;} + if(Demo[0][0]+Demo[0][1]+Demo[0][2]==a){} else {Demo[0][1]=Demo[0][1]+1;} + } + + + return Demo; +} + +public static int[][] SurpriseCheck(int a,int b,int[][] c){ + + int surprisesAllowed=a; + int bestNo=b; + int [][] googlerScores=c; + + if(surprisesAllowed==0 || bestNo==0 || bestNo==1) return googlerScores; + else{ + int surprisesDone=0; + + for(int i=0;i=bestNo) {flag=1;} + else if(Demo[0][1]>=bestNo) {flag=1;} + else if(Demo[0][2]>=bestNo) {flag=1;} + + else if(flag==0){ + + Demo[0][0]=Demo[0][0]+1; Demo[0][1]=Demo[0][1]-1; + if(Demo[0][0]-Demo[0][1]>2 || Demo[0][0]-Demo[0][1]<-2 || Demo[0][0]-Demo[0][2]>2 || Demo[0][0]-Demo[0][2]<-2){ + + Demo[0][0]=Demo[0][0]-1; Demo[0][1]=Demo[0][1]+1; + } + else{ + + if(Demo[0][0]==bestNo) + {flag=1;} + + else {Demo[0][0]=Demo[0][0]-1; Demo[0][1]=Demo[0][1]+1; } + + } + + if(flag==0){ + + Demo[0][0]=Demo[0][0]+1; Demo[0][1]=Demo[0][2]-1; + if(Demo[0][0]-Demo[0][1]>2 || Demo[0][0]-Demo[0][1]<-2 || Demo[0][0]-Demo[0][2]>2 || Demo[0][0]-Demo[0][2]<-2){ + + Demo[0][0]=Demo[0][0]-1; Demo[0][2]=Demo[0][2]+1; + } + else{ + + if(Demo[0][0]==bestNo) + flag=1; + + else {Demo[0][0]=Demo[0][0]-1; Demo[0][2]=Demo[0][2]+1;} + + } + } + + + if(flag==0){ + + Demo[0][0]=Demo[0][0]+2; Demo[0][1]=Demo[0][1]-1; Demo[0][2]=Demo[0][2]-1; + if(Demo[0][0]-Demo[0][1]>2 || Demo[0][0]-Demo[0][1]<-2 || Demo[0][0]-Demo[0][2]>2 || Demo[0][0]-Demo[0][2]<-2){ + + Demo[0][0]=Demo[0][0]-2;Demo[0][1]=Demo[0][1]+1; Demo[0][2]=Demo[0][2]+1; + } + else{ + + if(Demo[0][0]==bestNo) + flag=1; + + else{ Demo[0][0]=Demo[0][0]-2; Demo[0][1]=Demo[0][1]+1; Demo[0][2]=Demo[0][2]+1;} + + } + } + + +if(flag==0){ + + Demo[0][1]=Demo[0][1]+1; Demo[0][0]=Demo[0][0]-1; + if(Demo[0][1]-Demo[0][0]>2 || Demo[0][1]-Demo[0][0]<-2 || Demo[0][1]-Demo[0][2]>2 || Demo[0][1]-Demo[0][2]<-2){ + + Demo[0][1]=Demo[0][1]-1;Demo[0][0]=Demo[0][0]+1; + } + else{ + + if(Demo[0][1]==bestNo) + flag=1; + + else {Demo[0][1]=Demo[0][1]-1;Demo[0][0]=Demo[0][0]+1;} + + } + } + +if(flag==0){ + + Demo[0][1]=Demo[0][1]+1; Demo[0][2]=Demo[0][2]-1; + if(Demo[0][1]-Demo[0][0]>2 || Demo[0][1]-Demo[0][0]<-2 || Demo[0][1]-Demo[0][2]>2 || Demo[0][1]-Demo[0][2]<-2){ + + Demo[0][1]=Demo[0][1]-1;Demo[0][2]=Demo[0][2]+1; + } + else{ + + if(Demo[0][1]==bestNo) + flag=1; + + else {Demo[0][1]=Demo[0][1]-1;Demo[0][2]=Demo[0][2]+1;} + + } + } + +if(flag==0){ + + Demo[0][1]=Demo[0][1]+2; Demo[0][0]=Demo[0][0]-1;Demo[0][2]=Demo[0][2]-1; + if(Demo[0][1]-Demo[0][0]>2 || Demo[0][1]-Demo[0][0]<-2 || Demo[0][1]-Demo[0][2]>2 || Demo[0][1]-Demo[0][2]<-2){ + + Demo[0][1]=Demo[0][1]-2; Demo[0][0]=Demo[0][0]+1;Demo[0][2]=Demo[0][2]+1; + } + else{ + + if(Demo[0][1]==bestNo) + flag=1; + + else {Demo[0][1]=Demo[0][1]-2;Demo[0][0]=Demo[0][0]+1;Demo[0][2]=Demo[0][2]+1;} + + } + } +if(flag==0){ + + Demo[0][2]=Demo[0][2]+1; Demo[0][0]=Demo[0][0]-1; + if(Demo[0][2]-Demo[0][0]>2 || Demo[0][2]-Demo[0][0]<-2 || Demo[0][1]-Demo[0][2]>2 || Demo[0][1]-Demo[0][2]<-2){ + + Demo[0][2]=Demo[0][2]-1;Demo[0][0]=Demo[0][0]+1; + } + else{ + + if(Demo[0][2]==bestNo) + flag=1; + + else {Demo[0][2]=Demo[0][2]-1;Demo[0][0]=Demo[0][0]+1;} + + } + } + +if(flag==0){ + + Demo[0][2]=Demo[0][2]+1; Demo[0][1]=Demo[0][1]-1; + if(Demo[0][2]-Demo[0][0]>2 || Demo[0][2]-Demo[0][0]<-2 || Demo[0][1]-Demo[0][2]>2 || Demo[0][1]-Demo[0][2]<-2){ + + Demo[0][2]=Demo[0][2]-1;Demo[0][1]=Demo[0][1]+1; + } + else{ + + if(Demo[0][2]==bestNo) + flag=1; + + else {Demo[0][2]=Demo[0][2]-1;Demo[0][1]=Demo[0][1]+1;} + + } + } + +if(flag==0){ + + Demo[0][2]=Demo[0][2]+1;Demo[0][0]=Demo[0][0]-1;Demo[0][1]=Demo[0][1]-1; + if(Demo[0][2]-Demo[0][0]>2 || Demo[0][2]-Demo[0][0]<-2 || Demo[0][1]-Demo[0][2]>2 || Demo[0][1]-Demo[0][2]<-2){ + + Demo[0][2]=Demo[0][2]-1;Demo[0][0]=Demo[0][0]+1;Demo[0][1]=Demo[0][1]+1; + } + else{ + + if(Demo[0][2]==bestNo) + flag=1; + + else {Demo[0][2]=Demo[0][2]-1;Demo[0][0]=Demo[0][0]+1;Demo[0][1]=Demo[0][1]+1;} + + } + } + + +if(flag==1) surprisesDone=surprisesDone+1; + + } + + googlerScores[i][0]=Demo[0][0]; + googlerScores[i][1]=Demo[0][1]; + googlerScores[i][2]=Demo[0][2]; + + if(surprisesDone==surprisesAllowed){return googlerScores;} + } + + + + } + + return googlerScores; +} + + +public static int checkResult(){ + + return 0; + +} + public static void main(String args[]) throws Exception{ + BufferedReader reader = new BufferedReader(new FileReader(new File(""C:/Users/Faisal/Downloads/B-large.in""))); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""B-large.in""))); + String line = reader.readLine(); + int k = Integer.parseInt(line); + int count=1; + for(int i = 0 ; i < k ; i ++){ + line = reader.readLine(); + + String[] newLine=line.split("" ""); + + + + + System.out.println(count); + count++; + int noOfGooglers=Integer.parseInt(newLine[0]); System.out.println(""noOfGooglers ""+noOfGooglers); + int surprises=Integer.parseInt(newLine[1]); + int bestNo=Integer.parseInt(newLine[2]); + int[] totalScores=new int[noOfGooglers]; + + for(int j=3,n=0;j=bestNo || googlerScores[h][0]>=bestNo || googlerScores[h][0]>=bestNo ){ + + result++; + + } + } + + + + int Case=i+1; + writer.write(""Case #"" + Case + "": ""); + writer.write(Integer.toString(result)); + if(Case==k){} else{writer.write(""\n""); } + + + } + reader.close(); + writer.close(); + } + +} + +" +A22100,"import java.util.*; +import java.io.*; + +public class Main { + + char []a; + BufferedReader in; + StringTokenizer str = null; + PrintWriter out; + + private String next() throws Exception{ + if (str == null || !str.hasMoreElements()) + str = new StringTokenizer(in.readLine()); + return str.nextToken(); + } + + private int nextInt() throws Exception{ + return Integer.parseInt(next()); + } + + public void run() throws Exception{ + in = new BufferedReader(new FileReader(""in.txt"")); + out = new PrintWriter(new File(""out.txt"")); + int t = nextInt(); + for(int i=1;i<=t;i++){ + solve(i); + } + out.close(); + } + + private void solve(int x) throws Exception{ + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int ret = 0; + int a[] = new int[n]; + for(int i=0;i= p){ + ret++; + }else{ + if (k > 0 && k + 1 >= p && s > 0){ + ret++; + s--; + } + } + }else if (r == 1){ + if (k + 1 >= p){ + ret++; + } + }else{ + if (k + 1 >= p){ + ret++; + }else{ + if (k + 2 >= p && s > 0){ + ret++; + s--; + } + } + } + } + out.println(""Case #"" + x + "": "" + ret); + } + + public static void main(String[] args) throws Exception{ + new Main().run(); + } +} +" +A20772,"package qualification.Dancing; + +import java.io.*; + +public class IO { + + /** + * Reads a line of text from the input. + * + * @return The text entered. @comp Best and worst case are O(U) where U is + * the complexity of BufferedReader.readLine method for the input. + */ + public static String readln() { + InputStreamReader input = new InputStreamReader(System.in); + BufferedReader keyboard = new BufferedReader(input); + + try { + return keyboard.readLine(); + } catch (IOException e) { + println(""Unexpected exception while reading input.""); + } + return null; + } + + /** + * Terminates the current line by writing the line separator string. The + * line separator string is defined by the system property line.separator, + * and is not necessarily a single newline character ('\n'). + * + * @pre none @post none @complexity Best and worst case are the same. Time + * complexity is U where U is the complexity for System.out.println() + * method. + */ + public static void println() { + System.out.println(); + } + + /** + * Prints a string. If the argument is null then the string ""null"" is + * printed. Otherwise, the string's characters are converted into bytes + * according to the platform's default character encoding, and these bytes + * are written in exactly the manner of the write(int) method. + * + * @param s The string to print. @complexity Best and worst case are the + * same. Time complexity is U where U is the complexity for + * System.out.print(String) method. @pre none @post none + */ + public static void print(String s) { + System.out.print(s); + } + + /** + * Prints a String and then terminate the line. This method behaves as + * though it invokes print(String) and then println(). + * + * @param s The string to print. @complexity Best and worst case are the + * same. Time complexity is U where U is the complexity for + * System.out.print(String) method. @pre none @post none + */ + public static void println(String s) { + print(s); + println(); + } + + public static int readInt() { + try { + int val = Integer.parseInt(readln()); + + return val; + } catch (NumberFormatException ex) { + println(""Not an integer.""); + } + + return -1; + } +}" +A20384,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class DancingWithThegooglers { + + + private static Map pointMap = new HashMap(); + public static void main(String[] args) { + + pointMap.put(0, new Points(0, 0)); + pointMap.put(1, new Points(1, 1)); + pointMap.put(2, new Points(4, 2)); + pointMap.put(3, new Points(7, 5)); + pointMap.put(4, new Points(10, 8)); + pointMap.put(5, new Points(13, 11)); + pointMap.put(6, new Points(16, 14)); + pointMap.put(7, new Points( 19, 17)); + pointMap.put(8, new Points( 22, 20)); + pointMap.put(9, new Points( 25, 23)); + pointMap.put(10, new Points( 28, 26)); + try { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String str = """"; + + // Testcases + str = in.readLine(); + int cases = Integer.valueOf(str); + List output = new ArrayList(); + + for(int i = 1; i <= cases; i++){ + + str = in.readLine(); + + String[] numbers = str.split("" ""); + + int googlers = Integer.valueOf(numbers[0]); + int surprising = Integer.valueOf(numbers[1]); + int points = Integer.valueOf(numbers[2]); + + Integer[] results = new Integer[googlers]; + + + for(int j = 3; j < 3 + googlers; j++){ + results[j - 3] = Integer.valueOf(numbers[j]); + } + + // sort the shit out of it + Arrays.sort(results, Collections.reverseOrder()); + + + output.add(""Case #"" + i+ "": "" + calculate(googlers, surprising, points, results)); + } + + for(String outputLine : output){ + System.out.println(outputLine); + } + + } catch (IOException e) { + } + + } + + private static String calculate(int googlers, int surprising, int points, + Integer[] results) { + String res = googlers + "" : "" + surprising + "" : "" + points + "" anz: "" + results.length + "" first: "" + results[0] + "" last: "" + results[results.length - 1]; + + Points p = pointMap.get(points); + int result = 0; + int surleft = surprising; + for(int i = 0; i < results.length; i++){ + if(results[i] >= p.minPoints){ + result++; + continue; + } + if(results[i] >= p.surPoints && surleft > 0) { + result++; + surleft--; + continue; + } + break; + } + return String.valueOf(result); + } + +} +" +A22123,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package practice; + +import java.util.Scanner; + +/** + * + * @author Kristanto + */ +public class Practice { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int test = s.nextInt(); + int[] result = new int[test]; + for (int x=0; x= limit){ + result[x] = result[x]+1; + } else if (points%3 >= 1){ + if ((points/3)+1 == limit){ + result[x] = result[x]+1; + } + else { + if (surprising != 0){ + if ((points/3) + 2 == limit){ + result[x] = result[x]+1; + surprising--; + } + } + } + } else{ + if (surprising != 0){ + if ((points/3) + 1 == limit && points != 0){ + result[x] = result[x] + 1; + surprising--; + } + } + } + + } + } + + for (int x=0; x= 0; i--) { + int total = t[i]; + int score = getMaxScore(total); + if (surprisingCount < s && canBeSurprising(total)) { + int surprisingScore = getMaxSurprisingScore(total); + if (score < p && surprisingScore >= p) { + surprisingCount++; + score = surprisingScore; + } + } + if (score >= p) { + result++; + } + } + return result; + } + + private static boolean canBeSurprising(int total) { + return (total >= 2) && (total <= 28); + } + + private static int getMaxScore(int total) { + return (total + 2) / 3; + } + + private static int getMaxSurprisingScore(int total) { + return (total + 4) / 3; + } +} +" +A20410,"package MyAllgoritmicLib; + +public class BinnomNeutona { + + public static int C(int k, int n){ + return factorial(n)/(factorial(k)*factorial(n-k)); + } + + public static int factorial(int n){ + int result = 1; + for(int i = n; i > 1; i--){ + result *= i; + } + return result; + } +} +" +A21112,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingWithTheGooglers { + public static void main(String[] args) throws IOException { + printMaxPossibleHighScorers(new BufferedReader(new FileReader(""B-large.in"")), new BufferedWriter(new FileWriter(""out.txt""))); + } + + public static void printMaxPossibleHighScorers(BufferedReader in, BufferedWriter out) throws IOException { + String line = in.readLine(); // we don't need to read num test cases + int caseNum = 1; + + while ((line = in.readLine()) != null && line.length() != 0 ) { + String result = ""Case #"" + caseNum + "": ""; + + String[] lineDetails = line.split("" ""); + int n = Integer.parseInt(lineDetails[0]); // googlers + int s = Integer.parseInt(lineDetails[1]); // surprises + int p = Integer.parseInt(lineDetails[2]); // high score + int[] googlers = new int[lineDetails.length-3]; + + for (int j = 3; j < lineDetails.length; j++) { + googlers[j-3] = Integer.parseInt(lineDetails[j]); + } + + int maxPossibleHighScorers = 0; + int possibleHighScorers = 0; + int surprisesLeft = s; + for (int j = 0; j < n; j++) { + int score = googlers[j]; + int base = score / 3; + int offset = score % 3; + int maxScore = -1; + if (base > 0) { + maxScore = (offset == 0 ? base : base + 1); + if ((p - maxScore == 1) && offset != 1 && surprisesLeft > 0) { + maxScore++; + surprisesLeft--; + } + } else { + maxScore = (score == 0 ? 0 : 1); + if ((p - maxScore == 1) && offset == 2 && surprisesLeft > 0) { + maxScore++; + surprisesLeft--; + } + } + + if (maxScore >= p) { + possibleHighScorers++; + } + } + if (possibleHighScorers > maxPossibleHighScorers) { + maxPossibleHighScorers = possibleHighScorers; + } + result += maxPossibleHighScorers; + + out.write(result); + out.newLine(); + caseNum++; + } + in.close(); + out.close(); + } +} +" +A21701,"import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + + String inputName = ""B-large""; + + FileReader fr = new FileReader(inputName+"".in""); + Scanner sc = new Scanner(fr); + + FileWriter fstream = new FileWriter(inputName+"".out""); + BufferedWriter out = new BufferedWriter(fstream); + + int T = sc.nextInt(); + for(int i = 0; i < T; i++){ + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int t[] = new int[N]; + for(int j = 0; j < N; j++){ + t[j] = sc.nextInt(); + } + int ans = 0; + //System.out.println(N + "" "" + S + "" "" + p); + for(int j = 0; j < N; j++){ + int leftover = t[j] - p; + //System.out.println(leftover + "" "" + leftover/2); + if(leftover < 0){ + continue; + } + if(leftover/2 >= p-1){ + ans++; + } + else if(S > 0 && leftover/2 >= p-2){ + ans++; + S--; + } + } + + out.write(""Case #"" + (i+1) + "": "" + ans); + out.newLine(); + System.out.println(""Case #"" + (i+1) + "": "" + ans); + } + + fr.close(); + out.close(); + } +} +" +A21676,"package test.com; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Stack; + +public class Qual2012B { + + + public static void main(String[] args) throws Exception { + FileInputStream fos = new FileInputStream(""c:/sanker/workspace/input2/B-large.in""); + BufferedReader buf = new BufferedReader(new InputStreamReader(fos)); + String str = """"; + int S, P, numT, N; + + str = buf.readLine(); + numT = Integer.parseInt(str); + for(int i=0; i= P) { + count++; + }else { + int d1 = num - P; + int d2 = (P * 2) - 2; + if(d1 >= d2) + count++; + else { + int d3 = (P * 2) - 4; + if(d1 >= d3 && surpriseCnt+1 <= S) { + count++; surpriseCnt++; + } + } + } + + } + System.out.println(""Case #""+(i+1)+"": ""+count); + + } + + } + + + +} +" +A21214,"import java.util.Scanner; + + +public class Solution { + + public static void main(String[] args) + { + Scanner s = new Scanner(System.in); + int size = s.nextInt(); + for (int count = 1; count <= size; count++){ + int dancerNum = s.nextInt(); + int surpNum = s.nextInt(); + int score = s.nextInt(); + int[] dancerScore = new int[dancerNum]; + char[] marks = new char[dancerNum]; + for (int i = 0; i < dancerNum; i++){ + dancerScore[i] = s.nextInt(); + } + + int highB = score * 3 - 2; + int lowB = (score - 1) * 3 - 1; + int output = 0; + int sup = surpNum; + int markIdx = 0; + if (score < 2) + { + for (Integer i : dancerScore){ + if (i >= score) + { + marks[markIdx] = '+'; + output++; + }else{ + marks[markIdx] = '-'; + } + markIdx++; + } + + } + else + { + for (Integer i : dancerScore){ + if (i >= highB){ + output++; + marks[markIdx] = '+'; + }else if (i< highB && i >= lowB && sup > 0){ + //if (){ + output++; + sup--; + marks[markIdx] = '*'; +// }else{ +// +// marks[markIdx] = '-'; +// } + } + else{ + marks[markIdx] = '-'; + } + markIdx++; + } + } +// System.out.print(""Case #""+count+"": "" + dancerNum + "" "" + surpNum + "" ""+ score + "" ""); +// for (Integer i: dancerScore) +// { +// System.out.print(i+"" ""); +// } + System.out.println(""Case #""+count+"": ""+output); +// for (Character mark: marks) +// { +// System.out.print(mark+"" ""); +// } +// System.out.println(); + } + + } + +} +" +A20073,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class Dancing { + + public static int findmax(int N, int S, int p, ArrayList googlers){ + int legit = 0; + int surprise = 0; + for(int g : googlers){ + if ( g >= (3*p) - 2){ + legit++; + } + else if(g > 0 && g >= (3*p) - 4){ + surprise++; + } + } + return legit + Math.min(S, surprise); + }//Dancing.findmax() + + + public static void main(String[] args) throws IOException{ + + String inputFile = args[0]; + String outputFile = args[1]; + File file = new File(inputFile); + BufferedReader reader = new BufferedReader(new FileReader(file)); + BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile)); + + int numCases = Integer.parseInt(reader.readLine()); + + for (int i = 1; i <= numCases; i++){ + int caseNumber = i; + String[] arguments = reader.readLine().split("" ""); + int N = Integer.parseInt(arguments[0]); + int S = Integer.parseInt(arguments[1]); + int p = Integer.parseInt(arguments[2]); + ArrayList googlers = new ArrayList(); + for(int j = 0; j < N; j++){ + googlers.add(Integer.parseInt(arguments[j+3])); + } + + writer.write(""Case #"" + caseNumber + "": "" + Dancing.findmax(N,S,p,googlers)); + writer.newLine(); + } + reader.close(); + writer.close(); + }//Dancing.main() +}//Dancing +" +A22995,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package IO; + +import java.util.ArrayList; + +/** + * + * @author dannocz + */ +public class Input { + + private int noTestCases; + private ArrayList testCases; + //private ArrayList resultCases; + + public int getNoTestCases() { + return noTestCases; + } + + public void setNoTestCases(int noTestCases) { + this.noTestCases = noTestCases; + } + + public Input(int noTestCases, ArrayList cases) { + this.noTestCases = noTestCases; + this.testCases= new ArrayList(); + for (String case1 : cases) { + testCases.add(new TestCase(case1)); + } + + // this.resultCases= new ArrayList<>(); + } + +// public ArrayList getResultCases() { +// return resultCases; +// } +// +// public void setResultCases(ArrayList resultCases) { +// this.resultCases = resultCases; +// } +// +// public void addResultCase(String result) { +// this.resultCases.add(result); +// } + + + public void printResultCases(){ + for (int i = 0; i < testCases.size(); i++) { + String result=testCases.get(i).result()+""""; + FileManagerGUI.log.append(""Case #""+(i+1)+"": ""+result+""\n""); + System.out.println(""Case #""+(i+1)+"": ""+result); + } + } + + +} +" +A21130,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + + public static void main(String[] args) { + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + int count = 0; + try { + count = Integer.parseInt(input.readLine()); + } catch (Exception e) { + System.out.println(e.toString()); + System.exit(1); + } + DataModel[] dm = new DataModel[count]; + for(int i = 1; i<=count; i++) { + try { + dm[i-1] = new DataModel(input.readLine(),i); + dm[i-1].run(); + } catch (IOException e) { + System.out.println(e.toString()); + System.exit(1); + } + } + for(int i = 1; i<=count;i++) { + while(!dm[i-1].isDone()) {} + dm[i-1].getOutput(); + } + } +} +" +A21148,"import java.util.Scanner; + +public class b { + public static void main(String[] args){ + + Scanner in = new Scanner(System.in); + int numOfLines = new Integer(in.nextLine()); + for (int i= 1; i<=numOfLines; i++){ + String [] lineValues = in.nextLine().split("" ""); + int numberOfPlayers = new Integer(lineValues[0]); + int numberOfSupers = new Integer(lineValues[1]); + int bestResul = new Integer(lineValues[2]); + int bestResulMin1 = bestResul-1>0 ? bestResul-1 : 0; + int bestResulMin2 = bestResul-2>0 ? bestResul-2 : 0; + int res = 0; + //System.out.println(""number of players: ""+numberOfPlayers); + for (int j =3; j= bestResul+2*(bestResulMin1)) + { + res++; + continue; + }else if (numberOfSupers>0) + { + if (puntuations>= bestResul+2*(bestResulMin2)) + { + res++; + numberOfSupers--; + continue; + } + } + } + System.out.format(""Case #%d: %d\n"", i, res); + } + return; + } +}" +A21239,"import java.util.*; +import java.lang.*; +import java.math.*; +import java.io.*; + +import static java.lang.Math.*; +import static java.util.Arrays.*; +import static java.util.Collections.*; + +public class B{ + Scanner sc=new Scanner(System.in); + + int INF=1<<28; + double EPS=1e-9; + + int caze, T; + int n, s, p; + int[] ts; + + void run(){ + T=sc.nextInt(); + for(caze=1; caze<=T; caze++){ + n=sc.nextInt(); + s=sc.nextInt(); + p=sc.nextInt(); + ts=new int[n]; + for(int i=0; i=3){ + max2=t/3+1; + }else{ + max2=t/3; + } + }else if(t%3==1){ + max1=max2=t/3+1; + }else{ + max1=t/3+1; + max2=t/3+2; + } + max2=min(max2, 10); + if(max1=p){ + count2++; + }else{ + count3++; + } + // debug(t, max1, max2, p); + } + int ans=count3+min(count2, s); + answer(ans+""""); + } + + void answer(String s){ + println(""Case #""+caze+"": ""+s); + } + + void println(String s){ + System.out.println(s); + } + + void print(String s){ + System.out.print(s); + } + + void debug(Object... os){ + System.err.println(deepToString(os)); + } + + public static void main(String[] args){ + try{ + System.setIn(new FileInputStream(""dat/B-large.in"")); + System.setOut(new PrintStream(new FileOutputStream( + ""dat/B-large.out""))); + }catch(Exception e){} + new B().run(); + System.out.flush(); + System.out.close(); + } +} +" +A21421,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.StringTokenizer; + +public class Dancing { + + static int N, S, p; + static int[] t; + + public static void main(String[] args) throws Exception { + BufferedReader reader = new BufferedReader(new FileReader(""dancing.in"")); + int tc = Integer.parseInt(reader.readLine()); + String line; + StringTokenizer st; + for (int c = 1; c <= tc; c++) { + line = reader.readLine(); + st = new StringTokenizer(line); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + t = new int[N]; + for (int i = 0; i < N; i++) { + t[i] = Integer.parseInt(st.nextToken()); + } + System.out.println(""Case #""+c+"": ""+solve()); + } + } + + static int solve(){ + boolean[] puedeSolo = new boolean[N]; + for (int i = 0; i < N; i++) { + int k = t[i]/3; + if (t[i]%3==0 && k>=p) puedeSolo[i]=true; + if (t[i]%3!=0 && k+1>=p) puedeSolo[i]=true; + } + + boolean[] puedeSorpresa= new boolean[N]; + for (int i = 0; i < N; i++) { + int k = t[i]/3; + if (t[i]%3==2 && k+2>=p) puedeSorpresa[i]=true; + if (t[i]>=2 && t[i]%3<2 && k+1>=p) puedeSorpresa[i]=true; + } + + int cps = 0; + for (int i = 0; i < N; i++) { + if (puedeSolo[i]) cps++; + } + + int cpsor = 0; + for (int i = 0; i < N; i++) { + if (!puedeSolo[i] && puedeSorpresa[i]) cpsor++; + } + + return Math.min(cps+cpsor, cps + S); + } + +} +" +A21692,"import java.util.*; +public class b { +public static void main(String[] args) +{ + Scanner input = new Scanner(System.in); + int t = input.nextInt(); + for(int T = 1; T <= t; T++) + { + System.out.print(""Case #"" + T + "": ""); + int n = input.nextInt(); + int s = input.nextInt(); + int p = input.nextInt(); + int[] data = new int[n]; + for(int i =0; i= 0; at--) + { + if(data[at] >= p + 2*Math.max(0,p -1)) + count++; + else if(data[at] >= p + 2*Math.max(0,p -2) && s > 0) + { + count++; + s--; + } + } + System.out.println(count); + } +} +} +" +A21458," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.*; + +import static java.lang.Math.*; +import static java.util.Arrays.*; + +public class B { + + int INF = 1 << 28; + + void run() { + Scanner sc; + FileOutputStream fw; + try { + sc = new Scanner(new File(""B.in"")); + fw = new FileOutputStream(new File(""B.out"")); + PrintWriter pw = new PrintWriter(fw); +// sc.useDelimiter(""\\n""); + int n = sc.nextInt(); + for(int i=1;i<=n;i++) { + int t = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] total = new int[t]; + for(int j=0;j= p ) cnt++; + else if( s > 0 ){ + if( score[j][2] == score[j][1] && score[j][2] + 1 >= p && + total[j] != 0 && score[j][2] != 10) { + s--; + cnt++; + } + } + } + pw.println(""Case #"" + i + "": "" + cnt); + } + pw.close(); + fw.close(); + } catch (FileNotFoundException e) { + // TODO 自動生成された catch ブロック + e.printStackTrace(); + } catch (IOException e) { + // TODO 自動生成された catch ブロック + e.printStackTrace(); + } + } + + public static void main(String[] args) { + new B().run(); + } + + void debug(Object... os) { + System.err.println(Arrays.deepToString(os)); + } +} +" +A23068,"package com.google.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Date; + +public class DancingGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + + String input = null; + String outputFileLocation = ""C:\\google-code-jam\\output\\B-large-output.txt""; + // String outputFileLocation = + // ""C:\\google-code-jam\\output\\B-small-output.txt""; + String inputFileLocation = ""C:\\google-code-jam\\input\\B-large-practice.in""; + // String inputFileLocation = + // ""C:\\google-code-jam\\input\\B-small-practice.in""; + File outputFile = new File(outputFileLocation); + + BufferedWriter outputWriter = null; + DataInputStream in = null; + int caseNum = 1; + int count = 0; + String appCount = """"; + + try { + outputWriter = new BufferedWriter(new FileWriter(outputFile)); + + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(inputFileLocation); + + // Get the object of DataInputStream + in = new DataInputStream(fstream); + + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = null; + + int numtestCases = 1; + + int numofGooglers = 0; + int numberofSurprisingTriplet = 0; + int optimalValue = 0; + + numtestCases = new Integer(br.readLine()).intValue(); + + // Read File Line By Line + for (int i = 1; i <= numtestCases; i++) { + + // get credit from file + input = br.readLine(); + + // System.out.println(""## "" + i + "" "" + input); + + String[] a = input.split(""\\s""); + // System.out.println(""a = "" + a); + + numofGooglers = Integer.parseInt(a[0]); + numberofSurprisingTriplet = Integer.parseInt(a[1]); + optimalValue = Integer.parseInt(a[2]); + + // System.out.println(""numofGooglers = "" + numofGooglers); + // System.out.println(""numberofSurprisingTriplet = "" + // + numberofSurprisingTriplet); + // System.out.println(""optimal value = "" + optimalValue); + + int answer = 0; + int usedNumofSurprisingTroplets = 0; + for (int j = 3; j < numofGooglers + 3; j++) { + int totalScore = Integer.parseInt(a[j]); + + int quotient = totalScore / 3; + int remainder = totalScore % 3; + + // System.out.println(""Quotient = "" + quotient); + // System.out.println(""remainder = "" + remainder); + // System.out.println(""optimal value = "" + optimalValue); + + if (quotient >= optimalValue) { + answer++; + + } else if (quotient == 0 && remainder > 0) { + if (remainder >= optimalValue && optimalValue <= 1) { + answer++; + } + + } else if (quotient > 0 && quotient < optimalValue + && remainder > 0) { + + if (quotient + 1 == optimalValue) { + answer++; + } else if (quotient + 2 == optimalValue) { + if (numberofSurprisingTriplet > 0 + && usedNumofSurprisingTroplets <= numberofSurprisingTriplet) { + usedNumofSurprisingTroplets++; + numberofSurprisingTriplet--; + + // System.out.println(""111 used "" + // + usedNumofSurprisingTroplets); + // System.out + // .println(""111 numberofSurprisingTriplet "" + // + numberofSurprisingTriplet); + + answer++; + } + } + + } else if (quotient > 0 && quotient < optimalValue + && remainder == 0) { + // System.out.println(""22222 quotient "" + quotient); + if (quotient + 1 == optimalValue) { + /* + * System.out.println(""222 numberofSurprisingTriplet "" + * + numberofSurprisingTriplet); + */ + if (numberofSurprisingTriplet > 0 + && usedNumofSurprisingTroplets <= numberofSurprisingTriplet) { + usedNumofSurprisingTroplets++; + numberofSurprisingTriplet--; + /* + * System.out.println(""222 used "" + + * usedNumofSurprisingTroplets); + */ + answer++; + } + } + } + + // outputWriter.write(""Case #"" + i + "": "" + arrSoln[0] + "" "" + // + arrSoln[1]); + + // outputWriter.newLine(); + + }// inner for loop + + // System.out.println(""used "" + usedNumofSurprisingTroplets); + // System.out.println(""Case #"" + i + "": "" + answer); + outputWriter.write(""Case #"" + i + "": "" + answer); + outputWriter.newLine(); + + }// test case for loop + + // Close the input stream + in.close(); + + // Close the output stream + outputWriter.close(); + + System.out.println(""Done""); + } catch (IOException e) // Catch exception if any + { + System.err.println(""IO Error: "" + e.getMessage()); + } catch (Exception e) // Catch exception if any + { + System.err.println(""Error: "" + e.getMessage()); + } + + } + +} +" +A22226,"import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + + +public class Dancing { + + public static void main(String[] args) throws IOException { + File file = new File(""c:\\java\\DancingResults.txt""); + File inFile = new File(""c:\\java\\B-large.in""); + file.createNewFile(); + PrintStream out = new PrintStream(file); + Scanner scanIn = new Scanner(inFile); + + int T = 0; + int n = 0; + int p = 0; + int score = 0; + + int s = 0; + int total = 0; + + T = scanIn.nextInt();//number of cases + + for(int i = 0; i < T; i++, total = 0){ + n = scanIn.nextInt();//Number of dancers in case + s = scanIn.nextInt();//number of surprising scores + p = scanIn.nextInt();//score to be obtained + for(int j = 0; j < n; j++){ + score = scanIn.nextInt(); + + if(p == 0){ + total++; + continue; + } + + if(score >= minPossible1(p)){ + total++; + } + else if(score >= minPossible2(p) && s>0){ + total++; + s--; + } + + }//End of n loop + + out.println(""Case #""+(i+1)+"": ""+total); + + }//End of Case-loop + } + + public static int minPossible1(int pt){ + if((pt*3)-2 <= 0) return 1; + + return (pt*3)-2; + } + + public static int minPossible2(int pt){ + if((pt*3)-4 <= 0) return 1; + + return (pt*3)-4; + } + +} +" +A20932,"package org.tritree_tritree; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Scanner; + +public class ProblemBLarge { + + public static void main(String[] args) throws IOException { + File source = new File(""B-large.in""); + Scanner scan = new Scanner(source); + + int t = scan.nextInt(); + scan.nextLine(); + List resultList = new ArrayList(); + for (int i = 1; i < t + 1; i++) { + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int[] pointArray = new int[n]; + for (int j = 0; j < n; j++) { + pointArray[j] = scan.nextInt(); + } + String result = ""Case #"" + i + "": "" + resolve(s, p, pointArray); + resultList.add(result); + } + + SimpleDateFormat dateFormat = new SimpleDateFormat(""yyyy-MM-dd_hhmmss""); + File resultFile = new File(""B-large-"" + dateFormat.format(new Date()) + "".out""); + FileOutputStream fileOutputStream = new FileOutputStream(resultFile); + + for (String result: resultList) { + result = result + ""\n""; + fileOutputStream.write(result.getBytes()); + } + fileOutputStream.flush(); + fileOutputStream.close(); + } + + private static int resolve(int s, int p, int[] pointArray) { + int cnt = 0; + int remainScnt = s; + for (int i = 0; i < pointArray.length; i++) { + int target = pointArray[i]; + if (p*3 -2 <= target) { + cnt++; + } else if (target == 0) { + continue; + } else if (0 < remainScnt) { + if (p*3 -4 <= target) { + cnt++; + remainScnt--; + } + } + } + return cnt; + } + +} +" +A20247,"import java.util.Scanner; + +/** + * Google Code Jam 2012 + * + * @author 7henick + */ +public class ProblemB { + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + sc.nextLine(); + + for (int i = 0; i < T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + int result = 0; + + for (int j = 0; j < N; j++) { + int g = sc.nextInt(); + + int min = g / 3; + int best = g - min * 2; + + if (best - min == 0) { + if (best >= p) { + result++; + } else { + if (best + 1 >= p && min - 1 >= 0 && S > 0) { + result++; + S--; + } + } + } else if (best - min == 1) { + if (best >= p) { + result++; + } + } else if (best - min == 2) { + + if (best - 1 >= p) { + result++; + } else { + if (best >= p && S > 0) { + result++; + S--; + } + } + } else { + throw new Exception(); + } + } + + System.out.println(""Case #"" + (i + 1) + "": "" + result); + sc.nextLine(); + } + } +} +" +A22200,"import java.io.*; +import java.util.*; +public class dancing { + private void go() throws Exception{ + File infile = new File(""B-large.in""); + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); + int num_of_cases = Integer.parseInt(br.readLine()); + for(int i=1;i<=num_of_cases;i++){ + String cur_str = br.readLine(); + StringTokenizer stk = new StringTokenizer(cur_str); + int num_of_emp = Integer.parseInt(stk.nextToken()); + int num_of_surprise = Integer.parseInt(stk.nextToken()); + int req_num = Integer.parseInt(stk.nextToken()); + int surprise_not_needed = req_num*3 - 2; + int surprise_needed = Math.max(req_num*3 -2 -2,1); + int satisifed = 0; + int scores[] = new int[num_of_emp]; + for(int k=0;k= surprise_not_needed){ + satisifed++; + continue; + } + else{ + if(scores[k] >= surprise_needed && num_of_surprise>0){ + satisifed++; + num_of_surprise--; + continue; + } + else continue; + } + } + System.out.println(""Case #""+i+"": ""+satisifed); + } + } + public static void main(String[] args){ + try { + new dancing().go(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} +" +A22542,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; + + +public class B { + + /** + * @param args + */ + + public static String rest(ArrayList list) + { + + String n = list.get(0); + list.remove(0); + return n; + }; + + public static void main(String[] args) { + // TODO Auto-generated method stub + + String line; + ArrayList liste = new ArrayList(); + + + BufferedReader buffer = null; + try { + buffer=new BufferedReader(new FileReader(new File(args[0]))); + + for(int i=0; (line = buffer.readLine())!=null; i++){ + liste.add(line); + } + } + catch(IOException e){ + System.out.println(""IO-Fehler!""); + } + + + int anzahl = Integer.parseInt(rest(liste)); + + + + // fuer jeden Fall methode aufrufen + for ( int i = 0 ; i < anzahl; i++ ){ + methode(i+1, liste); + } + } + + // spezifische code fŸr alle aufgaben + public static void methode(int nummer, ArrayList liste) + { + // buffer und input machen + // input ist ein stringarray mit meiner ersten Zeile + // String[] input = rest(liste); + StringBuffer ergebnisbuffer = new StringBuffer(); + + String[] input = rest(liste).split("" ""); + ArrayList arraylist = new ArrayList(); + + + for (int i=0; i < input.length; i++){ + int n = Integer.parseInt(input[i]); + arraylist.add(n); + } + + int googler = arraylist.get(0); + + + int surprises = arraylist.get(1); + + + int p = arraylist.get(2); + + + ArrayList ergebnisse = new ArrayList(5); + + arraylist.subList(3, arraylist.size()); + + for (int i=3; i < arraylist.size() ; i++){ + ergebnisse.add(arraylist.get(i)); + } + + int sum = 0; + int newsurprises = surprises; + + + for (int i=0; i < ergebnisse.size();i++){ + if(ergebnisse.get(i) == 0) + { + ergebnisse.remove(i); + } + } + + Collections.sort(ergebnisse); + Collections.reverse(ergebnisse); + + + + for (int i=0; i < ergebnisse.size();i++){ + if ((ergebnisse.get(i) >= 0) && (ergebnisse.get(i)<= 30)){ + if(ergebnisse.get(i) >= ((3*p)-2)){ + sum=sum+1; + } + if((ergebnisse.get(i) == ((3*p)-4)) && (newsurprises >0)){ + sum=sum+1; + newsurprises=newsurprises-1; + } + if((ergebnisse.get(i) == ((3*p)-3)) && (newsurprises >0)){ + sum=sum+1; + newsurprises=newsurprises-1; + } + } + } + + if (p == 0){ + sum = googler; + } + + System.out.println(""Case #"" + nummer + "": "" + sum); + } +}" +A22549,"import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +import Triple.Triple; + +public class Dancing +{ + + /*@formatter:off*/ + /** + * Problem B. Dancing With the Googlers + * Problem: + * + * You're watching a show where Googlers (employees of Google) dance, and + * then each dancer is given a triplet of scores by three judges. Each + * triplet of scores consists of three integer scores from 0 to 10 + * inclusive. The judges have very similar standards, so it's surprising if + * a triplet of scores contains two scores that are 2 apart. No triplet of + * scores contains scores that are more than 2 apart. + * + * For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and + * (6, 8, 8) are surprising. (7, 6, 9) will never happen. + * + * The total points for a Googler is the sum of the three scores in that + * Googler's triplet of scores. The best result for a Googler is the maximum + * of the three scores in that Googler's triplet of scores. Given the total + * points for each Googler, as well as the number of surprising triplets of + * scores, what is the maximum number of Googlers that could have had a best + * result of at least p? + * + * For example, suppose there were 6 Googlers, and they had the following + * total points: 29, 20, 8, 18, 18, 21. You remember that there were 2 + * surprising triplets of scores, and you want to know how many Googlers + * could have gotten a best result of 8 or better. + * + * With those total points, and knowing that two of the triplets were + * surprising, the triplets of scores could have been: + * + * 10 9 10 + * 6 6 8 (*) + * 2 3 3 + * 6 6 6 + * 6 6 6 + * 6 7 8 (*) + * The cases marked with a (*) are the surprising cases. This gives us 3 Googlers who got at least one + * score of 8 or better. There's no series of triplets of scores that would + * give us a higher number than 3, so the answer is 3. Input + * + * The first line of the input gives the number of test cases, T. T test + * cases follow. Each test case consists of a single line containing + * integers separated by single spaces. The first integer will be N, the + * number of Googlers, and the second integer will be S, the number of + * surprising triplets of scores. The third integer will be p, as described + * above. Next will be N integers ti: the total points of the Googlers. + * + * Output + * + * For each test case, output one line containing ""Case #x: y"", where x is + * the case number (starting from 1) and y is the maximum number of Googlers + * who could have had a best result of greater than or equal to p. + * + * Limits + * + * 1 <= T <= 100. + * 0 <= S <= N. + * 0 <= p <= 10. + * 0 <= ti <= 30. + * At least S of the ti values will be between 2 and 28, inclusive. + * Small dataset + * 1 <= N <= 3. + * Large dataset + * 1 <= N <= 100. + * Sample + * Input + * 4 + * 3 1 5 15 13 11 + * 3 0 8 23 22 21 + * 2 1 1 8 0 + * 6 2 8 29 20 8 18 18 21 + * + * Output + * Case #1: 3 + * Case #2: 2 + * Case #3: 1 + * Case #4: 3 + */ + /*@formatter:on*/ + + private static String CASE = ""Case #""; + + public static void main(String[] args) + { + Scanner in = null; + PrintWriter out = null; + int T = 0; // number of test cases + int N = 0; // number of contestants in current test case + int S = 0; // number of surprising triplets in current test case + int p = 0; // individual judge's score threshold for current test case + + if (args.length < 2) + { + System.out.println(""Syntax: java Dancing \""infile\"" \""outfile\""""); + System.exit(1); + } + + // Opening infile + try + { + in = new Scanner(new File(args[0])); + } catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + + // Opening outfile + try + { + out = new PrintWriter(new FileWriter(args[1])); + } catch (Exception e1) + { + e1.printStackTrace(); + System.exit(1); + } + + try + { + T = in.nextInt(); + //System.out.println(T); + + for (int i = 0; i < T; i++) + { + int k = 0; + int higher = 0; + Triple t = null; + + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + //System.out.println(""N="" + N + "", S="" + S + "", p="" + p); + for (int j = 0; j < N; j++) + { + k = in.nextInt(); + t = new Triple(k); + //System.out.print(k + "": ""); + if (t.isHigher(p)) + { + //System.out.print(t + ""[!] ""); + higher += 1; + } else if ((t.couldBeHigher(p)) && (S > 0)) + { + //System.out.print(t + ""->""); + t.Unusify(); + S -= 1; + //System.out.print(t + ""[*] ""); + higher += 1; + } else + { + //System.out.print(t + "" ""); + } + } + //System.out.println(""; Total = "" + higher); + out.println(CASE + (i + 1) + "": "" + higher); + System.out.println(CASE + (i + 1) + "": "" + higher); + } + out.close(); + } catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + +} +" +A22238,"import java.util.*; +import java.io.*; +public class GoogleB { + + public static int doit(int s, int p, ArrayList arr){ + int count =0 ; + for (int i = 0; i < arr.size(); i++){ + if ((p-1>=0 && arr.get(i) >= 2*(p-1) + p) || (arr.get(i) >= 3*p)){ + count++; + arr.remove(i); + i--; + } + else if ((p-2 >= 0 && arr.get(i) >= 2*(p-2) + p && s > 0)){ + arr.remove(i); + s--; + i--; + count++; + } + } + return count; + } + + public static void main(String[] args) throws Exception{ + Scanner scan = new Scanner(new File(""B-small.txt"")); + int lines = scan.nextInt(); + for (int i = 0; i < lines; i++){ + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + ArrayList arr = new ArrayList(); + for (int j = 0; j < n; j++){ + arr.add(scan.nextInt()); + } + System.out.println(""Case #"" + (i+1) + "": "" + doit(s, p, arr)); + } + } +} +" +A21689," + +package sabriel; + + + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +import java.util.StringTokenizer; + +/** + * + * @author sabriel + */ +public class DanceIt { + + + public static void main(String[] args) { + try { + FileInputStream fstream = + new FileInputStream(""C:\\Users\\sabriel\\Documents\\NetBeansProjects\\Sabriel\\p2\\input.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + BufferedWriter out1 = new BufferedWriter( + new FileWriter( + ""C:\\Users\\sabriel\\Documents\\NetBeansProjects\\Sabriel\\p2\\out.out"", + true)); + String times = br.readLine(); + int n = Integer.valueOf(times); + + System.out.println(""number of test cases : "" + n); + + // will be used vars + + int currentCase = 0; + int G; + int S ; + int P; + int fav; + int s = 0; + + // processor starts + + while ((strLine = br.readLine()) != null) { + + ++currentCase; + + + StringTokenizer st=new StringTokenizer(strLine,"" ""); + G=Integer.valueOf(st.nextToken()); + int scores[]=new int[G]; + S=Integer.valueOf(st.nextToken()); + P=Integer.valueOf(st.nextToken()); + int tmp=0; + + System.out.println(""\n""+G+"" ""+P+"" ""+P); + + while(st.hasMoreTokens()){ + + scores[tmp]=Integer.valueOf(st.nextToken()); + System.out.print(scores[tmp]+"" ""); + ++tmp; + + } + + + // logic + fav=0; + s=0; + + + for (int i=0;i= 3 * best - 2 && 3*best - 2>=0) { + count1++; + } else if (score >= 3 * best - 4 && 3*best-4>=0) { + count2++; + } + } + + if (count2 <= numSurp) { + System.out.println(""Case #""+counter+"": ""+ (int)(count1 +count2)); + } + else{ + System.out.println(""Case #""+counter+"": ""+ (int)(count1+numSurp)); + } + + } + + } + } + +} +" +A21076,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.HashMap; +import java.util.Map; + +public class B { + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(""b.in""))); + PrintStream out = new PrintStream(new FileOutputStream(""b.out"")); + long count = readInt(in); + for (int i = 0; i < count; i++) { + String[] data = in.readLine().split("" ""); + int n = Integer.parseInt(data[0]); + int s = Integer.parseInt(data[1]); + int p = Integer.parseInt(data[2]); + int goodLimit = 3 * p - 2; + if (p == 0) { + goodLimit = 0; + } + int sLimit = 3 * p - 4; + if (p == 1) { + sLimit = 1; + } + System.out.println(goodLimit + "" "" + sLimit); + int good = 0; + int sur = 0; + for (int j = 0; j < n; j++) { + int v = Integer.parseInt(data[3 + j]); + if (v >= goodLimit) { + good++; + } else if (v >= sLimit) { + sur++; + } + } + + System.out.println(good + "" "" + sur); + out.println(""Case #"" + (i + 1) + "": "" + (good + Math.min(s, sur))); + } + out.flush(); + out.close(); + + } + + private static long readInt(BufferedReader in) { + try { + return Long.parseLong(in.readLine()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static void loadCode(String s1, String t1, Map m) { + for (int i = 0; i < s1.length(); i++) { + m.put(s1.charAt(i), t1.charAt(i)); + } + } +} +" +A21404,"package it.simone.google.code.jam2012; + +public interface GoogleCodeExercise { + + public String execute(String line); + public void initialize(); +} +" +A21944,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +public class qualb{ + + public static void main(String[] args){ + qualb.solve(); + } + + private static void solve(){ + String fileName = ""B-large.in""; + String outputFileName = fileName; + if(outputFileName.contains(""."")){ + outputFileName = outputFileName.substring(0,outputFileName.indexOf(""."")); + } + outputFileName = outputFileName+"".out""; + File file = new File(fileName); + + try { + FileWriter fstream = new FileWriter(outputFileName,true); + BufferedWriter out = new BufferedWriter(fstream); + BufferedReader reader = new BufferedReader(new FileReader(file)); + + //Number of cases + String text = reader.readLine(); + int NoCases = Integer.parseInt(text); + + for(int caseNo=0;caseNo=minScoreUnSupprising){ + NoGooglersUnSupprising++; + } else if(GooglerScore>=minScoreSupprising){ + NoGooglersSupprising++; + } + } + + if(NoGooglersSupprising>NoSupprising) NoGooglersSupprising = NoSupprising; + System.out.println(""Case #""+(caseNo+1)+"": ""+(NoGooglersUnSupprising+NoGooglersSupprising)); + out.write(""Case #""+(caseNo+1)+"": ""+(NoGooglersUnSupprising+NoGooglersSupprising)); + out.newLine(); + } + out.close(); + } catch (Exception e) { + System.out.println(e); + } + } +}" +A21989,"import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.FileInputStream; +import java.util.Arrays; +import java.util.Scanner; + + +public class B { + + public static int gao(int s, int p , int[] ss) { + int p1 = p + Math.max(0,p-1) * 2; + int p2 = p + Math.max(0,p-2) * 2; + + Arrays.sort(ss); + int ret = 0; + for (int i = ss.length - 1; i >=0; --i) { + int n = ss[i]; + if (n >= p1) { + ret ++; + } else if (n >= p2 && s > 0) { + ret ++; + s--; + } + } + + + return ret; + + + } + + public static void main(String[] args) throws Exception { + + + //InputStream in = System.in; + InputStream in = new FileInputStream(""c:\\B-large.in""); + + Scanner scanner = new Scanner(in); + //BufferedReader r = new BufferedReader(new InputStreamReader(in)); + /* + for (;;) { + String l = r.readLine(); + if (l == null) { + break; + } + } + */ + + int n; + n = scanner.nextInt(); + for (int i = 1; i <= n; ++i) { + int m = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int[] ss = new int[m]; + for (int j = 0; j < m; ++j) { + ss[j] = scanner.nextInt(); + } + System.out.println(""Case #"" + i + "": "" + gao(s, p, ss)); + } + + + + } + +} +" +A21266,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class Tools +{ + + public static ArrayList getInput(String filename) throws IOException + { + BufferedReader br = new BufferedReader(new FileReader(filename)); + + ArrayList output = new ArrayList(); + + String line; + while ((line = br.readLine()) != null) + output.add(line.split("" "")); + + br.close(); + return output; + } + + public static ArrayList getInputSingle(String filename) throws IOException + { + BufferedReader br = new BufferedReader(new FileReader(filename)); + + ArrayList output = new ArrayList(); + + String line; + while ((line = br.readLine()) != null) + output.add(line); + + br.close(); + return output; + } + + public static void saveOutput(String filename, ArrayList output) throws IOException + { + BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); + + for(int i=0; i output) throws IOException + { + BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); + + for(int i=0; i= score1 - 1 && score2 <= score1 + 1 && + score3 >= score1 - 1 && score3 <= score1 + 1 && + score2 >= score3 - 1 && score2 <= score3 + 1){ + return true; + } + } + } + } + return false; + } + + private boolean canSolveWithSurprisingScore(int totalscore) { + if(surprising <= 0) + return false; + boolean suprisingScoreFound = false; + for(int score1 = p; score1 <= 10; score1++){ + for(int score2 = score1-2; score2 <= score1+2; score2++){ + for(int score3 = score1-2; score3 <= score1+2; score3++){ + if(score1+score2+score3 != totalscore) + continue; + if(score2 >= score1 - 2 && score2 <= score1 + 2 && + score3 >= score1 - 2 && score3 <= score1 + 2 && + score2 >= score3 - 2 && score2 <= score3 + 2){ + return true; + } + + } + } + } + return false; + } + + + + public String toString(){ + String toReturn = String.format(""Googlers: %1$d \nSuprising: %2$d \np: %3$d \nscores: ["", + googlers, + surprising, + p, + totals); + for(int score : totals) + toReturn += """" + score + "" ""; + toReturn = toReturn.substring(0, toReturn.length() - 1); + return toReturn += ""]""; + } + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int T = Integer.parseInt(scan.nextLine()); + int i = 0; + while(scan.hasNextLine()){ + String line = scan.nextLine(); + i++; + QualB sol = new QualB(line); + System.out.println(""Case #"" + i + "": "" + sol.maxnr); + } + } + +} +" +A22709,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2012.qr; + +import codejam.common.CodeHelper; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Chen Ling + */ +public class ProblemB { + + private static String SMALL_IN_FILE_NAME = ""/codejam2012/qr/B-small.in""; + private static String LARGE_IN_FILE_NAME = ""/codejam2012/qr/B-large.in""; + private static String SMALL_OUT_FILE_NAME = ""/codejam2012/qr/B-small.out""; + private static String LARGE_OUT_FILE_NAME = ""/codejam2012/qr/B-large.out""; + + public static void main(String[] args) { +// List smallLines = CodeHelper.loadInputLines(SMALL_IN_FILE_NAME); +// List smallOutputs = new ArrayList(); +// for (int i = 1; i < smallLines.size(); i++) { +// String line = smallLines.get(i); +// List numbers = new ArrayList(); +// String[] numberArray = line.split("" ""); +// for (String number : numberArray) { +// numbers.add(number); +// } +// smallOutputs.add(""Case #"" + i + "": "" + solve(numbers)); +// } +// CodeHelper.writeOutputs(SMALL_OUT_FILE_NAME, smallOutputs); +// + List largeLines = CodeHelper.loadInputLines(LARGE_IN_FILE_NAME); + List largeOutputs = new ArrayList(); + for (int i = 1; i < largeLines.size(); i++) { + String line = largeLines.get(i); + List numbers = new ArrayList(); + String[] numberArray = line.split("" ""); + for (String number : numberArray) { + numbers.add(number); + } + largeOutputs.add(""Case #"" + i + "": "" + solve(numbers)); + } + CodeHelper.writeOutputs(LARGE_OUT_FILE_NAME, largeOutputs); + } + + public static int solve(List numbers) { + int result = 0; + int s = Integer.parseInt(numbers.get(1)); + int p = Integer.parseInt(numbers.get(2)); + List triplets = new ArrayList(); + for (int i = 3; i < numbers.size(); i++) { + int t = Integer.parseInt(numbers.get(i)); + int n = t / 3; + int a = t % 3; + Triplet triplet = null; + if (a == 0) { + triplet = new Triplet(n, n, n); + } else if (a == 1) { + triplet = new Triplet(n, n, n + 1); + } else { + triplet = new Triplet(n, n + 1, n + 1); + } + triplets.add(triplet); + } + Collections.sort(triplets); + int index = 0; + for (Triplet triplet : triplets) { + if (index == s) { + break; + } + if (triplet.getThird() >= p) { + continue; + } + if ((triplet.getThird() - triplet.getFirst()) == 0) { + if (triplet.getFirst() == 0) { + continue; + } + triplet.setFirst(triplet.getFirst() - 1); + triplet.setThird(triplet.getThird() + 1); + index++; + } else if ((triplet.getThird() - triplet.getSecond()) == 1) { + if (triplet.getSecond() == 0) { + continue; + } + triplet.setFirst(triplet.getFirst() - 1); + triplet.setSecond(triplet.getSecond() + 1); + index++; + } else if ((triplet.getThird() - triplet.getFirst()) == 1) { + triplet.setSecond(triplet.getSecond() - 1); + triplet.setThird(triplet.getThird() + 1); + index++; + } + } + Collections.sort(triplets); + for (Triplet triplet : triplets) { + if (triplet.getThird() >= p) { + result++; + } else { + break; + } + } + return result; + } + + private static class Triplet implements Comparable { + + private int first; + private int second; + private int third; + + public Triplet(int first, int second, int third) { + this.first = first; + this.second = second; + this.third = third; + } + + public int getFirst() { + return first; + } + + public void setFirst(int first) { + this.first = first; + } + + public int getSecond() { + return second; + } + + public void setSecond(int second) { + this.second = second; + } + + public int getThird() { + return third; + } + + public void setThird(int third) { + this.third = third; + } + + @Override + public int compareTo(Triplet o) { + return o.getThird() - this.getThird(); + } + } +} +" +A22532,"import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class googler { + + /** + * @param args + */ + static Scanner kb ; + public static void main(String[] args) throws FileNotFoundException { + // TODO Auto-generated method stub +PrintWriter out = new PrintWriter(""answergoogler.txt""); + kb = new Scanner(System.in); + int testcase = kb.nextInt(); + for(int i=0;i=minimum){ + answer++; + continue; + }else if(left==0&&Math.abs(divided-minimum)==1&&surprise!=0){ + answer++; + surprise--; + continue; + }else if(divided+left>=minimum){ + int first = minimum; + + left = left- (first-divided); + int divided2 = (total-first)/2; + if(first-divided==2){ + if(surprise>0){ + answer++; + surprise--; + + } + }else{ + + answer++; + } + + } + + } + //System.out.println(question+"" and answer is ""+ answer); + return answer; + // + } + +} +" +A21757,"package main; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class DancingWithTheGooglers { + + public static void main(String... args) throws NumberFormatException, IOException { + BufferedReader buffer = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); + + int qtd = Integer.parseInt(buffer.readLine()); + + List saida = new ArrayList(); + for (int i = 1; i <= qtd; i++) { + saida.add(""Case #"" + i + "": "" + qtdMelhoresResultados(buffer.readLine())); + } + + buffer.close(); + + escrevaNoArquivoASaida(""output.txt"", saida); + } + + private static void escrevaNoArquivoASaida(String nomeArquivo, List saida) throws IOException { + BufferedWriter br = new BufferedWriter(new FileWriter(new File(nomeArquivo))); + + for (String string : saida) { + br.write(string + ""\n""); + } + + br.close(); + + } + + public static int qtdMelhoresResultados(String entrada) { + String[] argumentos = entrada.split("" ""); + + int qtdGooglers = Integer.valueOf(argumentos[0]); + int notasSurpresas = Integer.valueOf(argumentos[1]); + int notaCorte = Integer.valueOf(argumentos[2]); + + int qtdMelhoresResultados = 0; + int surpresasUtilizados = 0; + for (int i = 0; i < qtdGooglers; i++) { + int notaGoogler = Integer.valueOf(argumentos[3+i]); + + int mediaNota = notaGoogler / 3; + + int nota1 = mediaNota; + int nota2 = mediaNota; + int nota3 = mediaNota; + + if (nota1 + nota2 + nota3 != notaGoogler) { + nota3++; + } + + if (nota1 + nota2 + nota3 != notaGoogler) { + nota2++; + } + + if (nota1 + nota2 + nota3 != notaGoogler) { + throw new RuntimeException(""Something went terribly wrong: "" + entrada ); + } + + if (nota1 >= notaCorte || nota2 >= notaCorte || nota3 >= notaCorte) { + qtdMelhoresResultados++; + continue; + } + + if (surpresasUtilizados == notasSurpresas) { + continue; + } + + if (nota2 > 0 && (nota3+1) - (nota2 - 1) <= 2) { + nota2--; + nota3++; + + if (nota1 >= notaCorte || nota2 >= notaCorte || nota3 >= notaCorte) { + qtdMelhoresResultados++; + surpresasUtilizados++; + } + } + } + + return qtdMelhoresResultados; + } + + +} +" +A21538,"package com.cuteants.problems.codejam.y2012.qualification; + +import java.io.*; +import java.util.InputMismatchException; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws Exception { + InputReader sc = new StreamInputReader(new FileInputStream(""C:\\Users\\aurel\\Downloads\\B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedOutputStream(new FileOutputStream(""C:\\Users\\aurel\\Downloads\\B_large_out.txt""), 10000), false); + + int tests = sc.nextInt(); + for (int i = 1; i <= tests; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int sum = 0; + for (int j = 0; j < n; j++) { + int t = sc.nextInt(); + int a = t / 3; + switch (t % 3) { + case 0: + if (a >= p) { + // a + a + a + sum++; + } else if (s > 0 && a + 1 >= p && a >= 1 && a <= 9) { + // (a - 1) + a + (a + 1) + sum++; + s--; + } + break; + case 1: + if (a + 1 >= p) { + // a + a + (a + 1) + sum++; + } + break; + case 2: + if (a + 1 >= p) { + // a + (a + 1) + (a + 1) + sum++; + } else if (s > 0 && a + 2 >= p && a <= 8) { + // a + a + (a + 2) + sum++; + s--; + } + break; + } + } + out.println(""Case #"" + i + "": "" + sum); + } + out.close(); + } + + abstract static class InputReader { + + public abstract int read(); + + public int nextInt() { + int c = read(); + while (isSpaceChar(c)) { + c = read(); + } + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') { + throw new InputMismatchException(); + } + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public long readLong() { + int c = read(); + while (isSpaceChar(c)) { + c = read(); + } + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + long res = 0; + do { + if (c < '0' || c > '9') { + throw new InputMismatchException(); + } + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) { + c = read(); + } + StringBuilder res = new StringBuilder(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + public boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + } + + static class StreamInputReader extends InputReader { + + private InputStream stream; + private byte[] buf = new byte[2048]; + private int curChar, numChars; + + public StreamInputReader(InputStream stream) { + this.stream = stream; + } + + @Override + public int read() { + if (numChars == -1) { + throw new InputMismatchException(); + } + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) { + return -1; + } + } + return buf[curChar++]; + } + } + +} +" +A20788,"import java.util.Scanner; + + +public class B { + + public static void main(String[] argv){ + Scanner in = new Scanner (System.in); + int T=in.nextInt(); + + for(int i=0; i0 & ind0 & ind=p ){ + Rep++; + NS[ind]=-1; + Surp--; + } + ind++; + + } + + for(int k=0; k=p) + Rep++; + } + + + System.out.println(""Case #""+(i+1)+"": ""+Rep); + //System.out.println(); + } + + } + + public static void prT(int[] t){ + System.out.println(); + for(int x:t) + System.out.print(x+"" ""); + } + +} +" +A22644,"import java.util.ArrayList; + + + + +public class Logic { + + + + + public static void solve() { + + //First input line + //Texter.readLine(); + + int noOfCases = Integer.valueOf(Texter.readLine()); + + + + + //Texter.writeText(""Output""); + + + for (int i = 1; i <= noOfCases; i++) { + + int caseNo = i; + + String nextLine = Texter.readLine(); + + if (nextLine == null) { + + nextLine = Texter.readLine(); + System.out.println(""HHH""); + } + System.out.println(""HHHsda""); + + ArrayList numbers = Texter.parseNumberList(nextLine); + //ArrayList numbers = (ArrayList) numbersOrig.clone(); + + ArrayList triplets = new ArrayList(); + + + int noOfGooglers = numbers.get(0); + int surprises = numbers.get(1); + int minBest = numbers.get(2); + + numbers.remove(0); + numbers.remove(0); + numbers.remove(0); + + for (int q = 0; q < noOfGooglers; q++) { + + int curScore = numbers.get(q); + + triplets.add(crunch(curScore)); + + + } + + + int[] surpriseIndexes = new int[surprises]; + + + //Count how many above min + + int answer = 0; + + for (int z = 0; z < numbers.size(); z++) { + + if (triplets.get(z)[0] >= minBest) { + + answer++; + + } + + + } + + + + //Loop number of surprises + + ArrayList triedOnes = new ArrayList(); + + for (int t = 0; t < surprises; t++) { + + Integer[] reCrunched = null; + + //while (reCrunched == null) { + for (int y = 0; y < triplets.size(); y++) { + + + int curMin = -1; + + int surpriseIndex = -1; + + //Find the highest one that is below min + //Start there + + for (int r = 0; r < triplets.size(); r++) { + + if (triedOnes.contains(r)) { + continue; + } + + + int highestNum = triplets.get(r)[0]; + + if (highestNum < minBest && highestNum > curMin) { + + curMin = highestNum; + //surpriseIndexes[t] = r; + surpriseIndex = r; + + } + + } + + //Remove so don't find again + //triplets.remove(surpriseIndex); + + if (surpriseIndex == -1) { + + break; + + } + + triedOnes.add(surpriseIndex); + + //See if it can be made a surprise one + + // + y to account for the number that have been removed + reCrunched = surpriseCrunch(numbers.get(surpriseIndex)); + + + + + if (reCrunched != null) { + + reCrunched = getHighest(reCrunched[0], reCrunched[1], reCrunched[2]); + + } + //If still too low set to null so will continue looping + + if (reCrunched != null) { + + if (reCrunched[0] < minBest) { + + reCrunched = null; + + } + } + + + if (reCrunched != null) { + + if (reCrunched[0] >= minBest) { + + answer++; + break; + + } + } + + } + + + + + } + + + + + Texter.writeText(""Case #"" + caseNo + "": "" + answer); + + + //int no = 15; + + //triplets.add(crunch(no)); + + + + + } + + + + + } + + + + static Integer[] crunch(int score) { + + + + /*for (int i = 10; i >= 0; i--) { + for (int q = 10; q >= 0; q--) { + for (int w = 10; w >= 0; w--) {*/ + + + int i = 10; + int q = 10; + int w = 10; + + + while (true) { + + + if (i + q + w == score) { + + return getHighest(i, q, w); + + } + + w--; + + if (i + q + w == score) { + + return getHighest(i, q, w); + + } + + q--; + + if (i + q + w == score) { + + return getHighest(i, q, w); + + } + + i--; + + + } + + + + + /*} + } + }*/ + + + + + } + + + + static Integer[] surpriseCrunch(int score) { + + + + for (int i = 10; i >= 0; i--) { + for (int q = 10; q >= 0; q--) { + for (int w = 10; w >= 0; w--) { + + + if (i + q + w == score) { + + if (checkSurprise(i, q, w)) { + + return new Integer[] { i, q, w }; + } + } + } + } + } + + return null; + + + + + } + + + + static boolean checkSurprise(int i, int q, int w) { + + if (i >= 0 && q >= 0 && w >= 0) { + + //Check if a diff of 2 + + if (i - q == 2 || i - w == 2 || q - i == 2 || q - w == 2 || w - i == 2 || w - q == 2) { + + //No greater than 2 diff + + if (i - q <= 2 && i - w <= 2 && q - i <= 2 && q - w <= 2 && w - i <= 2 && w - q <= 2) { + + return true; + + } + } + } + + return false; + + + + + } + + + + static Integer[] getHighest(int i, int q, int w) { + + if (i >= q && i >= w) { + + return new Integer[] { i, q, w }; + + } + + + if (q >= i && q >= w) { + + return new Integer[] { q, i, w }; + + } + + if (w >= i && w >= q) { + + return new Integer[] { w, i, q }; + + } + + + return null; + + + + + } + + + + +} +" +A22778,"package google.solver; + +import google.loader.ChallengeLoader; +import google.loader.ChallengeReader; + +import java.io.FileInputStream; +import java.util.Properties; + +public class Solver implements ChallengeConstants{ + + private ChallengeReader reader; + private String inputFileName; + private String result; + private final String path; + + public Solver(String aPath) { + this.path = aPath; + init(); + solve(); + writeResult(); + } + + private void solve() { + ChallengeLoader loader = new ChallengeLoader(reader); + loader.load(inputFileName); + result = loader.getResult(); + } + + private void init() { + try{ + String propFileName = path+DELIMITER+CHALLENGE_DEFINITION; + Properties properties = new Properties(); + properties.load(new FileInputStream(propFileName)); + inputFileName = path+DELIMITER+(String)properties.get(""fileName""); + String readerClassName = (String)properties.get(""readerClassName""); + reader = (ChallengeReader) Class.forName(readerClassName).newInstance(); + } + catch(Exception e){ + throw new RuntimeException(e); + } + } + + public String getResult(){ + return result; + } + + + public void writeResult(){ + String result = getResult(); + write(result); + } + + + private void write(String text) { + ProblemPackageCreator.write(getResultFileName(), text); + } + + private String getResultFileName() { + return inputFileName+"".result""; + } + + public static void main(String[] args) { + String problem = CHALLENGE_NAME; + String path = BASE_DIR+DELIMITER+problem; + Solver solver = new Solver(path); + String result = solver.getResult(); + System.out.println(result); + } +} +" +A20403,"package qualification.taskC; + +import Parser.MyReader; +import Parser.MyWriter; + +public class Main { + private final static int n = 20000001; + + public static void main(String[] args) { + MyReader myReader = new MyReader( + ""/Users/shami13/Downloads/C-small-attempt0.in""); + MyWriter myWriter = new MyWriter( + ""/Users/shami13/Downloads/C-small-attempt0.out""); + + boolean[][] table = new boolean[n][n]; + + for (int i = 1; i < n; i++) { + for (int p = 1; p < n; p++) { + table[i][p] = isRecycled(i, p); + } + } + + int taskLength = Integer.parseInt(myReader.read()); + for (int i = 1; i <= taskLength; i++) { + String[] taskString = myReader.read().split("" ""); + Task task = new Task(Integer.parseInt(taskString[0]), + Integer.parseInt(taskString[1]), table); + String result = task.execute(); + myWriter.writeString(""Case #"" + i + "": "" + result); + System.out.println(""Case #"" + i + "": "" + result); + } + myWriter.close(); + } + + public static boolean isRecycled(int a, int b) { + if (a != b) { + + String bString = """" + b; + + for (int i = 0; i < bString.length(); i++) { + int temp = b % 10; + b /= 10; + for(int p = 1; p < bString.length(); p ++){ + temp *= 10; + } + b += temp; + if (a == b) { + return true; + } + } + } + return false; + } +} +" +A21819,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancinggooglers; + +import java.io.*; + +/** + * + * @author Ruben + */ +public class DancingGooglers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + if (args.length >= 2) { + new dance(args[0], args[1]); + } + } catch (Exception e) { + System.out.println(""error!\n"" + e); + } + } + + private static class dance { + + public dance(String input, String output) throws Exception { + execute(input, output); + } + + private void execute(String input, String output) throws Exception { + File inputfile = new File(input); + File outputfile = new File(output); + FileReader fr = new FileReader(inputfile); + BufferedReader reader = new BufferedReader(fr); + FileWriter fw = new FileWriter(outputfile); + BufferedWriter bw = new BufferedWriter(fw); + int lines = Integer.parseInt(reader.readLine()); + for (int i = 0; i < lines; i++) { + bw.write(""Case #"" + (i + 1) + "": "" + calculate(reader.readLine())); + bw.newLine(); + } + bw.close(); + fw.close(); + fr.close(); + } + + private String calculate(String line) { + String[] split = line.split("" ""); + int[] scores = new int[split.length - 3]; + for (int i = 0; i < scores.length; i++) { + scores[i] = Integer.parseInt(split[i + 3]); + } + return calculate(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), scores); + } + + private String calculate(int n, int s, int p, int[] scores) { + int max = 0, remaining_surprises = s; + insertion_sort(scores);//just to be sure it is sorted + for (int i = 0; i < scores.length; i++) { + if (scores[i] >= 2) { + if ((scores[i] + 2) / 3 >= p) { + max++; + } else if (remaining_surprises > 0 && (scores[i] + 4) / 3 >= p) { + max++; + remaining_surprises--; + } + } else if (scores[i] == 1) { + if(p<=1) + max++; + } else { //score = 0 + if(p==0) + max++; + } + } + return """" + max; + } + + private static void insertion_sort(int array[]) { + for (int i = 1; i < array.length; i++) { + int j = i; + int B = array[i]; + while ((j > 0) && (array[j - 1] > B)) { + array[j] = array[j - 1]; + j--; + } + array[j] = B; + } + } + } +} +" +A23073,"import java.io.*; +import java.util.Scanner; + + +public class SurprisingDancers { + public static void main(String[] args) { + BufferedReader br; + BufferedWriter bw; + int count; + try + { + br = new BufferedReader(new FileReader(args[0])); + bw = new BufferedWriter(new FileWriter(new File(""output.txt""))); + count = new Integer(br.readLine()); + for(int i = 1; i <= count; i++) + { + try + { + bw.write(""Case #"" + i + "": ""); + Scanner intReader = new Scanner(br.readLine()); + int numGooglers = intReader.nextInt(); + int numSurprises = intReader.nextInt(); + int p = intReader.nextInt(); + int ans = 0; + for(int j = 1; j <= numGooglers; j++) + { + int score = intReader.nextInt(); + if((score/3) >= p) + { + ans++; + } + else + { + if(score % 3 == 0 && score > 0) + { + if((score/3 + 1) >= p) + { + if(numSurprises > 0) + { + numSurprises--; + ans++; + } + } + } + if(score % 3 == 1) + { + if((score/3 + 1) >= p) + { + ans++; + } + } + if(score % 3 == 2) + { + if((score/3 + 1) >= p) + { + ans++; + } + else if((score/3 + 2) >= p) + { + if(numSurprises > 0) + { + numSurprises--; + ans++; + } + } + } + } + } + String stringAns = """" + ans; + bw.write(stringAns); + bw.newLine(); + } + catch(IOException e) + { + System.out.println(""Error reading line.""); + } + } + br.close(); + bw.close(); + } + catch(FileNotFoundException e) + { + System.out.println(""File not found.""); + } + catch(IOException e) + { + System.out.println(""Error reading first line or creating output.""); + } + } + +} +" +A20526,"package CodeJam; + +import java.io.*; +import java.util.*; + +public class B_2012 { + + public static void main(String[] args) throws IOException { + + + Scanner in = new Scanner(System.in); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""test3.out""))); + + int NS[] = {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; + int S[] = {-1,-1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,-1,-1}; + + int cases= in.nextInt(); + + for(int c=0;c G = new ArrayList(); + + for(int i=0;i0 && S[G.get(i)]>=b) { + s--; + G.remove(i); + C++; + i--; + } + } + for(int i=0;i0 && NS[G.get(i)]=b ) C++; + + out.println(""Case #""+(c+1)+"": ""+C); + + } + out.close(); + System.exit(0); + } +} +" +A21599,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Scanner; + + +public class SpeakingInTongues { + + + /** + * The first line of the input gives the number of test cases, T. + * T test cases follow. + * Each test case consists of a single line containing integers separated by single spaces. + * The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. + * The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + // Reading the input file + Scanner in = new Scanner(new File(""B-large.in"")); + // writting the input file + FileOutputStream fos = new FileOutputStream(""B-large.out""); + PrintStream out = new PrintStream(fos); + //Close the output stream + int testCase=Integer.parseInt(in.nextLine()); + for(int i=0;i scores= new ArrayList(); + int BestResults=0; + int Surprising=0; + for(int j=0;j= atLeastP)) { + BestResults++; + } else { + if (((((temp / 3) + 1) >= atLeastP) && ((temp / 3) >= 1)) + && (Surprising < NoOfSurprisingResults)) { + BestResults++; + Surprising++; + + } + System.out.println(""Case 0""+""itr:""+i+"" surprising:""+temp); + } + + break; + case 1: + if ((temp / 3) + 1 >= atLeastP) { + BestResults++; + continue; + } + + break; + case 2: + if ((temp / 3) + 1 >= atLeastP) { + BestResults++; + } else { + if (((temp / 3) + 2 >= atLeastP) + && (Surprising < NoOfSurprisingResults)) { + BestResults++; + Surprising++; + } + System.out.println(""Case 2""+""itr:""+i+"" surprising:""+temp); + } + break; + default: + System.out.println(""Error""); + } + + }// Internal for + out.println(BestResults); + // System.out.println(BestResults); + System.out.println(Surprising); + BestResults = 0; + }// for + in.close(); + out.close(); + fos.close(); + + } +} +" +A22988,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class B { + static Scanner s; + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + // TODO Auto-generated method stub + s = new Scanner(new File(""a.txt"")); + int T = s.nextInt(); + for(int a=1;a<=T;a++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int res = 0; + for (int i=0;i= 3) res++; + else if ((v+2)/p>=3) { + res++; + } + else if (S!=0 && (v+4)/p>=3) { + res++; S--; + } + } + if (s.hasNext()) s.nextLine(); + System.out.println(""Case #""+a+"": ""+res); + } + s.close(); + } + +} +" +A20823,"package codeJam2011; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + try { + BufferedReader input = new BufferedReader (new InputStreamReader(new FileInputStream(""./bin/codeJam2011/B-large.in""))); + BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""./bin/B.out""))); + + int cases = Integer.parseInt(input.readLine()); + for ( int i =0; i < cases ;i++) + { + int bestCounter =0; + String [] line = input.readLine().split("" ""); + int su = Integer.parseInt(line[1]); + int best = Integer.parseInt(line[2]); + + + for(int n =3; n= 3*best-2) + { + bestCounter++; + } + else if(3*best-4>0 & score >= 3*best-4 & su >0 ) + { + bestCounter++; + su --; + } + + } + output.write(""Case #""+(i+1)+"": ""+bestCounter+""\n""); + System.out.println(""Case #""+(i+1)+"": ""+bestCounter); + + } + output.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} +" +A23060,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +public class CodeJam { + + public ReadWriteTextFile rw = new ReadWriteTextFile(); + public Triplet[] array = new Triplet[31]; + + + public void init() + { + for(int i=0;i<31;i++) + { + array[i] = new Triplet(); + } + + array[0].normal = 0;array[0].surprising = 0; + array[1].normal = 1;array[1].surprising = 1; + array[2].normal = 1;array[2].surprising = 2; + array[3].normal = 1;array[3].surprising = 2; + array[4].normal = 2;array[4].surprising = 2; + array[5].normal = 2;array[5].surprising = 3; + array[6].normal = 2;array[6].surprising = 3; + array[7].normal = 3;array[7].surprising = 3; + array[8].normal = 3;array[8].surprising = 4; + array[9].normal = 3;array[9].surprising = 4; + array[10].normal = 4;array[10].surprising = 4; + array[11].normal = 4;array[11].surprising = 5; + array[12].normal = 4;array[12].surprising = 5; + array[13].normal = 5;array[13].surprising = 5; + array[14].normal = 5;array[14].surprising = 6; + array[15].normal = 5;array[15].surprising = 6; + array[16].normal = 6;array[16].surprising = 6; + array[17].normal = 6;array[17].surprising = 7; + array[18].normal = 6;array[18].surprising = 7; + array[19].normal = 7;array[19].surprising = 7; + array[20].normal = 7;array[20].surprising = 8; + array[21].normal = 7;array[21].surprising = 8; + array[22].normal = 8;array[22].surprising = 8; + array[23].normal = 8;array[23].surprising = 9; + array[24].normal = 8;array[24].surprising = 9; + array[25].normal = 9;array[25].surprising = 9; + array[26].normal = 9;array[26].surprising = 10; + array[27].normal = 9;array[27].surprising = 10; + array[28].normal = 10;array[28].surprising = 10; + array[29].normal = 10;array[29].surprising = 10; + array[30].normal = 10;array[30].surprising = 10; + + + + } + public static void main(String[] args) { + CodeJam codeJam = new CodeJam(); + + codeJam.init(); + + int sampleSize = codeJam.rw.readIntLine(); + + + for (int i = 0; i < sampleSize; i++) { + + int count=0; + int N = codeJam.rw.readInt(); + int score; + int S = codeJam.rw.readInt(); + int p = codeJam.rw.readInt(); + for(int k=0;k= p) + { + count++; + } + else if(codeJam.array[score].surprising >= p && S>0) + { + count++; + S--; + } + + + + + } + + + codeJam.rw.writeNextLine(count); + } + codeJam.rw.close(); + } +} +" +A21138,"package com.gzroger.codejam2012; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class QB { + public static void main(String[] args) { + try { + BufferedReader reader = new BufferedReader(new FileReader(args[0])); + int nCases = Integer.parseInt( reader.readLine() ); + for (int iCases=0; iCases K[i] ) { + System.out.println(""problem!""); + } + + if ( (maxIfNotS+maxIfNotS-1+maxIfNotS-1) > K[i] ) { + System.out.println(""problem!""); + } + + if (maxIfNotS>=p) + cPos++; + else if (maxIfS>=p && S>0) { + cPos++; + S--; + } + } + return cPos; + } +} +" +A22941,"import java.io.*; +import java.util.*; + +class Triplet +{ + public static void main (String [] args) throws IOException + { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + + StringTokenizer st = new StringTokenizer(in.readLine()); + int numCases = Integer.parseInt(st.nextToken()); + + for (int i = 0; i < numCases; i++) + { + out.print(""Case #"" + (i+1) + "": ""); + + st = new StringTokenizer(in.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int numSurprisings = Integer.parseInt(st.nextToken()); + int P = Integer.parseInt(st.nextToken()); + + int min = 0; + int minNoSurprising = 0; + + if (P > 1) + { + min = 3*P - 4; + minNoSurprising = 3*P - 2; + } + else if (P == 1) + { + min = 1; + minNoSurprising = 1; + } + else + { + min = 0; + minNoSurprising = 0; + } + + int[] totalPoint = new int[n]; + + for (int j = 0; j < n; j++) + { + totalPoint[j] = Integer.parseInt(st.nextToken()); + } + + int maxCandidateWithNoSurprisings = 0; + int maxCandidateWithSurprisings = 0; + + for (int j = 0; j < n; j++) + { + if (totalPoint[j] >= minNoSurprising) + { + maxCandidateWithNoSurprisings++; + } + else if (totalPoint[j] >= min) + { + maxCandidateWithSurprisings++; + } + } + + if (maxCandidateWithSurprisings <= numSurprisings) + { + out.print((maxCandidateWithNoSurprisings + maxCandidateWithSurprisings)); + } + else + { + out.print((maxCandidateWithNoSurprisings + numSurprisings)); + } + + out.println(); + } + + out.close(); + } +}" +A22548,"import java.io.IOException; +import java.util.Arrays; +import java.util.InputMismatchException; +import java.util.ArrayList; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Writer; +import java.math.BigInteger; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + * @author lwc626 + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream = System.in; + OutputStream outputStream = System.out; + MyInputReader in = new MyInputReader(inputStream); + MyOutputWriter out = new MyOutputWriter(outputStream); + B_Dancing_With_the_Googlers solver = new B_Dancing_With_the_Googlers(); + solver.solve(1, in, out); + out.close(); + } +} + +class B_Dancing_With_the_Googlers { + public void solve(int testNumber, MyInputReader in, MyOutputWriter out) { + int test = in.nextInt() ; + for (int tc = 0; tc < test; tc++) { + int n = in.nextInt() ; + int s = in.nextInt() ; + int p = in.nextInt() ; + int[] A = new int[ n ]; + ArrayList> ap = new ArrayList>(); + + for( int i = 0 ; i < n ; i ++ ){ + A[i] = in.nextInt() ; + if( A[i] % 3 == 0 ){ + ap.add( Pair.makePair( A[i] / 3 , A[i] >= 3 ? A[i] / 3 + 1 : -1 )); + } + else if( A[i] % 3 == 1 ){ + ap.add( Pair.makePair( (A[i] + 2)/ 3 , A[i] >= 4 ? (A[i]+2) / 3 : -1 ) ); + }else{ + ap.add( Pair.makePair( (A[i] + 1)/ 3 , A[i] >= 2 ? (A[i] + 4)/3 : -1 ) ); + } + } + //out.printLine( ap.toString()); + int [][] dp = new int[ n+1 ][ s+1 ]; + for( int[] o : dp ) Arrays.fill( o , -1 ); + dp[0][0] = 0 ; + for( int i = 0 ; i < n ; i ++ ){ + for( int j = 0 ; j <= s ; j ++ ) if( dp[i][j] != -1 ){ + update( dp , i+1 , j , dp[i][j] + (ap.get(i).first >= p ? 1 : 0) ); + if(j+1<=s && ap.get(i).second != -1) + update( dp , i+1 , j+1 , dp[i][j] + (ap.get(i).second >= p ? 1 : 0 ) ); + } + } + //for( int[] o : dp ) IOUtils.printIntArrays( out, o ); + out.printLine( ""Case #"" + (tc+1) +"": ""+ dp[n][s] ); + } + } + + private void update(int[][] dp, int i, int j, int v) { + if( dp[i][j] == -1 || dp[i][j] < v ) dp[i][j] = v ; + } +} + +class MyInputReader { + + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + + public MyInputReader(InputStream stream) { + this.stream = stream; + } + + public int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + public int nextInt(){ + return readInt() ; + } + + public static boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + } + +class MyOutputWriter { + private final PrintWriter writer; + + public MyOutputWriter(OutputStream outputStream) { + writer = new PrintWriter(outputStream); + } + + public MyOutputWriter(Writer writer) { + this.writer = new PrintWriter(writer); + } + + public void print(Object...objects) { + for (int i = 0; i < objects.length; i++) { + if (i != 0) + writer.print(' '); + writer.print(objects[i]); + } + } + + public void printLine(Object...objects) { + print(objects); + writer.println(); + } + + public void close() { + writer.close(); + } + +} + +class Pair implements Comparable> { + public final U first; + public final V second; + + public static Pair makePair(U first, V second) { + return new Pair(first, second); + } + + private Pair(U first, V second) { + this.first = first; + this.second = second; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Pair pair = (Pair) o; + + return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null); + + } + + public int hashCode() { + int result = first != null ? first.hashCode() : 0; + result = 31 * result + (second != null ? second.hashCode() : 0); + return result; + } + + public String toString() { + return ""("" + first + "","" + second + "")""; + } + + public int compareTo(Pair o) { + int value = ((Comparable)first).compareTo(o.first); + if (value != 0) + return value; + return ((Comparable)second).compareTo(o.second); + } +} + +" +A22309,"package com.paupicas.year2012.codejam.qr; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Arrays; +import java.util.Collections; + +public class B { + + public static void main(String[] args) throws Exception { + String filename = ""B-large""; + BufferedReader inputFile = new BufferedReader(new FileReader(filename + "".in"")); + FileWriter outputFile = new FileWriter(filename + "".out""); + + int casesNumber = Integer.valueOf(inputFile.readLine()); + for (int cn = 1; cn <= casesNumber; cn++) { + String result = ""Case #"" + cn + "": ""; + + String inputLine = inputFile.readLine(); + String[] textNums = inputLine.split("" ""); + int n = Integer.valueOf(textNums[0]); + int s = Integer.valueOf(textNums[1]); + int p = Integer.valueOf(textNums[2]); + Integer[] scores = new Integer[n]; + + for (int i = 3; i < textNums.length; i++) { + int v = Integer.valueOf(textNums[i]); + scores[i - 3] = v; + } + + Arrays.sort(scores, Collections.reverseOrder()); + + int count = 0; + for (int i = 0; i < scores.length; i++) { + Integer c = scores[i] / 3; + Integer m = scores[i] % 3; + + if (m > 0) { + c++; + } + + if (c >= p) { + count++; + } else if (s > 0) { + if ((m == 0 || m == 2) && c + 1 >= p && c + 1 <= scores[i]) { + count++; + s--; + } + } + } + + result = result + count; // + "" ("" + inputLine + "")""; + + System.out.println(result); + outputFile.write(result); + if (cn < casesNumber) { + outputFile.write(""\n""); + } + } + + inputFile.close(); + outputFile.close(); + } + +} +" +A20278,"package Problem2; + +import java.util.ArrayList; +import java.util.HashMap; + +public class Main { + + public static void main(String[] args){ + + ArrayList ArS = new ArrayList(); + ArS = FileReader.Parsefile(""input.txt""); + int[] ArS2 = DancingGooglers.Count_List(ArS); + FileReader.writeconfig(""output.txt"", ArS2); + + } + + + +} +" +A21382,"package com.google.codejam; + +import java.io.File; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Scanner; + +import org.apache.commons.lang.ArrayUtils; + +// Libraries used: http://commons.apache.org/lang/, http://commons.apache.org/collections/ +public class B { + + private static boolean debugAllowed = true; + private static Scanner scanner; + private static int numberOfCases; + private static int N; + private static int[] t; + private static long S; + private static long p; + + private static void parseCase(int caseNumber) { + debug(""Case #"" + caseNumber); + + N = scanner.nextInt(); + debug("" N: "" + N); + S = scanner.nextLong(); + debug("" S: "" + S); + p = scanner.nextLong(); + debug("" p: "" + p); + + t = new int[N]; + for (int i = 0; i < N; i++) { + t[i] = scanner.nextInt(); + } + debug("" t: "" + Arrays.asList(ArrayUtils.toObject(t))); + } + + private static String solveCase() { + int solution = 0; + for (int i = 0; i < N; i++) { + int base = (t[i] - 1) / 3; + int remainder = (t[i] - 1) % 3 + 1; + debug("" t[i]: "" + t[i] + ""\t base: "" + base + ""\t remainder: "" + remainder); + if (base * 3 + remainder != t[i]) { + throw new RuntimeException(); + } + + if (remainder == 0) { + if (base >= p) { + solution++; + } + debug("" "" + base + "", "" + base + "", "" + base + "" (a)""); + } else if (remainder == 1) { + if (base + 1 >= p) { + solution++; + } + debug("" "" + base + "", "" + base + "", "" + (base + 1) + "" (b)""); + } else { + if (base + 1 >= p) { + solution++; + if (remainder == 2) { + debug("" "" + base + "", "" + (base + 1) + "", "" + (base + 1) + "" (c2)""); + } else { + debug("" "" + (base + 1) + "", "" + (base + 1) + "", "" + (base + 1) + "" (c3)""); + } + } else { + if (base + 2 >= p & S > 0) { + solution++; + S--; + if (remainder == 2) { + debug("" "" + base + "", "" + base + "", "" + (base + 2) + "" (d2)""); + } else { + debug("" "" + base + "", "" + (base + 1) + "", "" + (base + 2) + "" (d2)""); + } + } else { + if (remainder == 2) { + debug("" "" + base + "", "" + (base + 1) + "", "" + (base + 1) + "" (e2)""); + } else { + debug("" "" + (base + 1) + "", "" + (base + 1) + "", "" + (base + 1) + "" (e3)""); + } + } + } + } + } + + return String.valueOf(solution); + } + + public static void main(String[] args) throws Exception { + File inputFile = new File(args[0]); + String outputFileName = inputFile.getParent() + File.separator + inputFile.getName().replace("".in"", "".out""); + PrintStream out = new PrintStream(outputFileName); + + scanner = new Scanner(inputFile); + numberOfCases = Integer.valueOf(scanner.nextLine()); + debug(numberOfCases + "" cases""); + + long startTime = System.currentTimeMillis(); + for (int caseNumber = 1; caseNumber <= numberOfCases; caseNumber++) { + parseCase(caseNumber); + + String solution = solveCase(); + + String resultString = ""Case #"" + caseNumber + "": "" + solution; + out.println(resultString); + debug(""Solution for "" + resultString); + + debug(""""); + } + long time = System.currentTimeMillis() - startTime; + debug(""Time: "" + time + "" ms ("" + time / numberOfCases + "" ms / case)""); + + out.close(); + } + + private static void debug(String text) { + if (debugAllowed) { + System.out.println(text); + } + } +} +" +A22082,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancingwiththegooglers; + +import java.io.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.StringTokenizer; + +/** + * + * @author Кирилл и Папа + */ +public class DancingWithTheGooglers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""input.in""))); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""output.txt""))); + int numOfTestCases = Integer.parseInt(br.readLine()); + for (int testCaseI = 0; testCaseI < numOfTestCases; testCaseI++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = Integer.parseInt(st.nextToken()); + } + int res = 0; + int availableSurp = s; + for (int i = 0; i < t.length; i++) { + int bestRes = (t[i] + 2) / 3; + if ((bestRes < p) && (availableSurp > 0) && (t[i] >= 2)) { + int r = (t[i] + 4) / 3; + if (r >= p) { + bestRes = r; + availableSurp--; + } + } + res += ((bestRes >= p) ? 1 : 0); + } + bw.write(""Case #"" + (testCaseI + 1) + "": "" + res); + bw.newLine(); + } + br.close(); + bw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} +" +A22869,"package gcj2012Q; + +import java.io.*; +import java.util.*; + +public class B { + public static void main(String[] args) { + new B().run(new Scanner(System.in)); + } + + void run(Scanner sc) { + int n = sc.nextInt(); + for(int i = 1; n-- > 0; i++) + solve(sc, i); + } + + void solve(Scanner sc, int case_num) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int count = 0, surprising = 0; + for(int i = 0; i < n; i++) { + int t = sc.nextInt(); + if(t < p) continue; + if(t / 3 >= p || (t / 3 == p - 1 && t % 3 > 0)) count++; + else if(t / 3 == p - 1 && t % 3 == 0) surprising++; + else if(t / 3 == p - 2 && t % 3 == 2) surprising++; + } +// System.out.println(count+"" ""+surprising); + int res = count + Math.min(surprising, s); + + System.out.printf(""Case #%d: %d\n"", case_num, res); + } +} +" +A21232,"package problem_b; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class ProblemB { + + public static void main(String[] args) { + try { + processFile(""/Users/ibogomolov/Desktop/B-large.in"", ""/Users/ibogomolov/Desktop/out.txt""); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + + private static int process(int n, int s, int p, int[] total) { + int res = 0; + for (int i = 0; i < n; i++) { + int div = total[i]/3; + int mod = total[i]%3; + if (div >= p || (div + 1 >= p && mod >= 1)) { + res++; + } else if ((div + 2 >= p && mod == 2 && s > 0) || (div + 1 >= p && div >= 1 && mod == 0 && s > 0)) { + res++; + s--; + } + } + return res; + } + + public static void processFile(String in, String out) throws IOException { + Scanner scanner = new Scanner(new File(in)); + BufferedWriter writer = new BufferedWriter(new FileWriter(out)); + int cases = scanner.nextInt(); + for (int i = 1; i < cases+1; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int[] array = new int[n]; + for (int j = 0; j < n; j++) { + array[j] = scanner.nextInt(); + } + writer.write(""Case #"" + i + "": "" + process(n, s, p, array) + ""\n""); + } + + scanner.close(); + writer.close(); + } +} +" +A23035,"import java.util.Scanner; + +public class DancingGooglers { + public static void main( String args[] ) { + new DancingGooglers(); + } + + public DancingGooglers() { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + + for( int j=0; j chars = getDifDigits(); + int base = chars.size() > 1 ? chars.size() : 2; + replaceDigits(chars, base); + numOfSeconds = getNumberInBase10(base); + return this; + } + + private long getNumberInBase10(int originalBase) { + long num = 0, lenght = currentLine.length(); + for (int i = 0; i < lenght; i++) { + num += getIntByChar(currentLine.charAt(i)) + * Math.pow(originalBase, lenght - (i + 1)); + } + return num; + } + + private int getIntByChar(char charAt) { + if (charAt <= 58) { + return charAt - 48; + } + return charAt - 96 + 9; + } + + private void replaceDigits(ArrayList chars, int base) { + replace(chars.remove(0), getNumberChar(1)); + if (chars.size() == 0) { + return; + } + replace(chars.remove(0), getNumberChar(0)); + + int tmp = 2; + for (char aaa : chars) { + replace(aaa, getNumberChar(tmp)); + tmp++; + } + } + + private String replace(char a, char b) { + String temp = null; + int index = -1; + do { + index = originalLine.indexOf(a, index + 1); + if (index > -1) { + currentLine.setCharAt(index, b); + } + } while (index > -1); + + return temp; + } + + private char getNumberChar(int number) { + if (number < 10) { + return (char) (number + 48); + } + return (char) (97 + number - 10); + } + + private ArrayList getDifDigits() { + ArrayList tmp = new ArrayList(); + char tempChar; + for (int i = 0; i < originalLine.length(); i++) { + tempChar = originalLine.charAt(i); + if (!tmp.contains(tempChar)) { + tmp.add(originalLine.charAt(i)); + } + } + return tmp; + } + +} +" +A20920,"package at.jaki.codejam.qr2012.B; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + private static final String TEMPLATE = ""Case #%d: %d""; + + private static final String IN = ""B-small-attempt0.in""; + private static final String OUT = ""B-small-attempt0.out""; + + private static Scanner sc; + private static PrintWriter pw; + + public static void main(String[] args) throws FileNotFoundException { + sc = new Scanner(new File(IN)); + pw = new PrintWriter(new File(OUT)); + int tests = sc.nextInt(); + for (int i = 1; i <= tests; i++) { + resolve(i); + } + pw.flush(); + pw.close(); + } + + private static void resolve(int TT) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] scores = new int[n]; + for (int i = 0; i < n; i++) { + scores[i] = sc.nextInt(); + } + + int total = 0; + for (int i = 0; i < n; i++) { + int q = scores[i] / 3; + int r = scores[i] % 3; + + int best; + if (r == 0) { + best = q; + } else { + best = q + 1; + } + if (best >= p) { + total++; + continue; + } + + if (best == p - 1) { + if (s > 0 && r != 1 && scores[i] != 0) { + total++; + s--; + continue; + } + } + } + pw.println(String.format(TEMPLATE, TT, total)); + System.out.println(total); + + } +} + +// 4---> 2 1 1 +// 4*--> 2 2 0 + +// 5---> 2 2 1 +// 5*--> 3 1 1 + +// 6---> 2 2 2 +// 6*--> 3 2 1 + +// 7---> 3 2 2 +// 7*--> 3 3 1 " +A21259,"import java.util.ArrayList; +import java.util.Collections; + +public class Solver { + int S; + int p; + ArrayList scores; + + Solver(int S, int p, ArrayList scores) { + this.S = S; + this.p = p; + this.scores = scores; + } + + static int getMaxScoreNoSuprise(int n) { + int base = n / 3 - 1; + if (base < 0) + base = 0; + + int max = 0; + for (int i = base; i <= base + 3; i++) + for (int j = base; j < base + 3; j++) + for (int k = base; k < base + 3; k++) { + if (Math.abs(i - j) <= 1 && Math.abs(i - k) <= 1 + && Math.abs(j - k) <= 1 && (i + j + k) == n) { + max = Math.max(max, Math.max(i, Math.max(j, k))); + } + + } + return max; + + } + + static int getMaxScoreWithSuprise(int n) { + int base = n / 3 - 1; + if (base < 0) + base = 0; + + int max = 0; + for (int i = base; i <= base + 4; i++) + for (int j = base; j < base + 3; j++) + for (int k = base; k < base + 3; k++) { + if (Math.abs(i - j) <= 2 && Math.abs(i - k) <= 2 + && Math.abs(j - k) <= 2 && (i + j + k) == n) { + max = Math.max(max, Math.max(i, Math.max(j, k))); + } + + } + return max; + } + + int solve() { + + Collections.sort(scores); + +// for(int score : scores) + // System.out.println(getMaxScoreNoSuprise(score) + "" "" + getMaxScoreWithSuprise(score)); + + int surprises =0 ; + for(int i=0;i= p && getMaxScoreNoSuprise(scores.get(i))

=p ) + pScores++; + } + + return surprises + pScores; + } + +} +" +A21110,"package codjamdoce; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +public class DancingGooglers { + + private final File file; + private int ncases; + private DanceContest[] contests; + private int[] result; + + public DancingGooglers(File file) { + this.file = file; + } + + public void init() throws Exception { + int numberOfParticipantsIndex = 0; + int numberOfSurprisingScoresIndex = 1; + int minScoreIndex = 2; + BufferedReader reader = new BufferedReader(new FileReader(file)); + try { + String line; + int lineNumber = 0; + + int contestsCount = 0; + while ((line = reader.readLine()) != null) { + if (lineNumber == 0) { + ncases = Integer.valueOf(line.trim()); + contests = new DanceContest[ncases]; + result = new int[ncases]; + } else { + StringTokenizer tokenizer = new StringTokenizer(line.trim(), "" ""); + + int index = 0; + Googler[] participants = null; + int surprisingScores = 0; + int minScore = 0; + + int participantsCount = 0; + while (tokenizer.hasMoreElements()) { + String next = tokenizer.nextToken(); + if (index == numberOfParticipantsIndex) { + participants = new Googler[Integer.valueOf(next)]; + } else if (index == numberOfSurprisingScoresIndex) { + surprisingScores = Integer.valueOf(next); + } else if (index == minScoreIndex) { + minScore = Integer.valueOf(next); + } else { + Googler googler = new Googler(Integer.valueOf(next), minScore); + participants[participantsCount] = googler; + participantsCount++; + } + index++; + } + + if (participants != null && surprisingScores >= 0 && minScore >= 0) { + contests[contestsCount] = new DanceContest(participants, surprisingScores); + contestsCount++; + } + } + lineNumber++; + } + + } finally { + reader.close(); + } + } + + public void processContests() { + int count = 0; + for (DanceContest contest : contests) { + result[count] = contest.getBestResultParticipants(); + count++; + } + } + + public void printResult() throws IOException { + int count = 0; + File outfile = new File(""out""); + if (outfile.exists()) + outfile.delete(); + outfile.createNewFile(); + FileOutputStream out = new FileOutputStream(outfile); + try { + for (int r : result) { + if (count == ncases - 1) { + out.write(MessageFormat.format(""Case #{0}: {1}"", (count + 1), r).getBytes()); + } else { + out.write(MessageFormat.format(""Case #{0}: {1}\n"", (count + 1), r).getBytes()); + } + count++; + } + } finally { + out.close(); + } + } + + private static class DanceContest { + + private final Googler[] participants; + private final int surprisingScores; + + public DanceContest(Googler[] participants, int surprisingScores) { + this.participants = participants; + this.surprisingScores = surprisingScores; + } + + private int getBestResultParticipants() { + int surprisingScoresLeft = surprisingScores; + int result = 0; + + for (Googler participant : participants) { + participant.getBestScoreTable(surprisingScoresLeft > 0); + + boolean haveSurprisingScore = participant.haveSurprisingScore(); + if (participant.hasBestResult(participant.getTableScore())) { + if (!haveSurprisingScore) { + result++; + } else if (haveSurprisingScore && surprisingScoresLeft > 0) { + result++; + } + } + + if (haveSurprisingScore) { + surprisingScoresLeft--; + } + + } + return result; + } + + } + + private static class Googler { + + enum ScoreType { + LESSER, GREATER, EQUAL + } + + private final int score; + private final int MAX_SCORE = 30; + private List tableScore; + private final int minScore; + + public Googler(int score, int minScore) { + this.score = score; + this.minScore = minScore; + } + + public void getBestScoreTable(boolean canBeSurprising) { + tableScore = new ArrayList(); + + if (this.score == 0) { + tableScore.add(0); + tableScore.add(0); + tableScore.add(0); + return; + } + + this.tableScore = calculateTable((getScore() * 10) / MAX_SCORE); + + if (!isValidTable(this.tableScore) || !hasBestResult(this.tableScore)) { + int retry = 4; + while (retry > 0) { + if (retryTable(canBeSurprising, retry) && isValidTable(this.tableScore)) { + break; + } + retry--; + } + } + + if (!isValidTable(this.tableScore)) { + Integer[] array = this.tableScore.toArray(new Integer [tableScore.size()]); + this.tableScore = new ArrayList(); + this.tableScore.add(array[0]); + this.tableScore.add(array[1] - 1); + this.tableScore.add(array[2] + 1); + } + + if (!isValidTable(this.tableScore)) { + System.out.println(); + } + + return; + } + + public boolean retryTable(boolean canBeSurprising, int retry) { + int average = (getScore() * 10) / MAX_SCORE; + if (retry == 6 && average > 2 && canBeSurprising) { + List table = calculateTable(average - 2); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + table = calculateTable(average - 2); + Integer second = table.remove(1); + Integer third = table.remove(1); + second -=1; + third +=1; + table.add(second); + table.add(third); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + if (retry == 6 && average > 1) { + List table = calculateTable(average - 1); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + + if (retry == 5 && average > 2 && canBeSurprising) { + List table = calculateTable(average - 2); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + if (retry == 5 && average > 1) { + List table = calculateTable(average - 1); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + + if (retry == 4 && canBeSurprising) { + List table = calculateTable(average + 2); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + table = calculateTable(average + 2); + Integer second = table.remove(1); + Integer third = table.remove(1); + second -=1; + third +=1; + table.add(second); + table.add(third); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + if (retry == 4 && average > 1) { + List table = calculateTable(average + 1); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + + if (retry == 3 && canBeSurprising) { + List table = calculateTable(average + 2); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + table = calculateTable(average + 2); + Integer second = table.remove(1); + Integer third = table.remove(1); + second -=1; + third -=1; + table.add(second); + table.add(third); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + if (retry == 3 && average > 1) { + List table = calculateTable(average + 1); + if (hasBestResult(table) && isValidTable(table)) { + this.tableScore = table; + return true; + } + } + return false; + } + + public List calculateTable(int average) { + List table = new ArrayList(); + if (average * 3 == getScore()) { + table.add(average); + table.add(average); + table.add(average); + } else { + ScoreType scoreType = firstScoreType(average); + if (scoreType != null) { + if (scoreType != null && scoreType == ScoreType.LESSER) { + processLesser(average, table); + } else if (scoreType == ScoreType.GREATER) { + processGreater(average, table); + } else { + processEqual(average, table); + } + } else { + scoreType = secondScoreType(average); + if (scoreType != null) { + if (scoreType == ScoreType.LESSER) { + processLesser(average, table); + } else if (scoreType == ScoreType.GREATER) { + processGreater(average, table); + } else { + processEqual(average, table); + } + } + } + } + + return table; + } + + private void processEqual(int average, List table) { + table.add(average); + table.add(average + 1); + table.add((getScore() - ((average + average)))); + } + + private boolean hasBestResult(List tableScore) { + for (int score : tableScore) { + if (score >= this.minScore) { + return true; + } + } + return false; + } + + public void processGreater(int average, List table) { + table.add(average); + table.add(average + 1); + table.add((getScore() - ((average + 1) + average))); + } + + public void processLesser(int average, List table) { + table.add(average); + table.add(average - 1); + table.add((getScore() - ((average - 1) + average))); + } + + public ScoreType secondScoreType(int average) { + int number = getScore() - ((average - 1) + average); + boolean result = number - average <= 2; + boolean lesser = result; + + number = getScore() - ((average + 1) + average); + result = number - average <= 2; + boolean greater = result; + + if (lesser) { + return ScoreType.LESSER; + } else if (greater) { + return ScoreType.GREATER; + } else { + number = getScore() - ((average) + average); + result = number - average <= 2; + if (result) { + return ScoreType.EQUAL; + } + return null; + } + } + + public ScoreType firstScoreType(int average) { + int number = getScore() - ((average - 1) + average); + number = number - average; + boolean lesser = number == 1 || number == 0; + + number = getScore() - ((average + 1) + average); + number = number - average; + boolean greater = number == 1 || number == 0; + + if (lesser) { + return ScoreType.LESSER; + } else if (greater) { + return ScoreType.GREATER; + } else { + number = getScore() - ((average) + average); + boolean result = (number - average) == 0 || (number - average) == 1; + if (result) { + return ScoreType.EQUAL; + } + return null; + } + } + + public int getScore() { + return this.score; + } + + public List getTableScore() { + return this.tableScore; + } + + public boolean haveSurprisingScore() { + boolean result = false; + outer: for (int s : tableScore) { + for (int cs : tableScore) { + if ((cs - s) == 2) { + result = true; + break outer; + } + if ((cs - s) > 2) { + System.out.println(); + } + } + } + return result; + } + + private boolean isValidTable(List table) { + boolean valid = true; + int calculatedScore = 0; + for (int s : table) { + calculatedScore += s; + } + + if (calculatedScore != score) { + return false; + } + + outer: for (int s : table) { + for (int cs : table) { + if ((cs - s) > 2) { + valid = false; + break outer; + } + } + } + return valid; + } + + } + + public static void main(String[] args) throws Exception { + if (args.length < 1) { + System.out.println(""Provide absolute path of input file""); + } + File file = new File(args[0]); + if (file.isFile()) { + DancingGooglers dancingGooglers = new DancingGooglers(file); + dancingGooglers.init(); + dancingGooglers.processContests(); + dancingGooglers.printResult(); + } + } +} +" +A22288,"package qual; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class B { + public static void main(String[] args) throws Exception{ + String in_file = ""q/b/l_in.txt""; + String out_file = in_file.replace(""_in.txt"", ""_out.txt""); + BufferedReader in = new BufferedReader(new FileReader(in_file)); + BufferedWriter out = new BufferedWriter(new FileWriter(out_file)); + + int t = Integer.parseInt(in.readLine()); + for (int i = 1; i <= t; i++){ + String[] tmp = in.readLine().split("" ""); + int n = Integer.parseInt(tmp[0]); + int s = Integer.parseInt(tmp[1]); + int p = Integer.parseInt(tmp[2]); + int[] res = new int[n]; + for (int j = 0; j < n; j++){ + res[j] = Integer.parseInt(tmp[j + 3]); + } + + int min = p > 0 ? p + (p-1) * 2 : p; + int sup_min = p > 1 ? p + (p-2) * 2 : p; + int count = 0; + for (int j = 0; j < n; j++){ + int cres = res[j]; + if (cres >= min) { + count++; + } else if (s > 0 && cres >= sup_min) { + count++; + s--; + } + } + out.write(""Case #"" + i + "": "" + count + ""\n""); + } + + in.close(); + out.close(); + } +} +" +A22917," +import java.io.*; +import java.util.*; + +public class Dancing { + public enum Category {containsHighNotSupprising, containsHighOnlyIfSupprising, doesNotContainHigh}; + + public class Score { + + public Score(int p, int score) { + this.score = score; + this.category = getCategoryFor(p, score); + } + + private Category getCategoryFor(int p, int score) { + if (score >= 29) { + return Category.containsHighNotSupprising; + } else if (score == 1) { + if (p == 0 || p == 1) { + return Category.containsHighNotSupprising; + } + return Category.doesNotContainHigh; + } else if (score == 0) { + if (p == 0) { + return Category.containsHighNotSupprising; + } + return Category.doesNotContainHigh; + } else if (score >= (3*p)-2) { + return Category.containsHighNotSupprising; + } else if (score >= (3*p)-4) { + return Category.containsHighOnlyIfSupprising; + } + return Category.doesNotContainHigh; + } + + public int score; + public Category category; + } + + public class TestCase { + int p; + int s; + List scores = new ArrayList(); + + public TestCase(String line) { + Scanner scan = new Scanner(line); + int numScores = scan.nextInt(); + s = scan.nextInt(); + p = scan.nextInt(); + for(int i = 0; i < numScores; i++) { + int score = scan.nextInt(); + scores.add(new Score(p,score)); + } + } + + public int getResult() { + int countContainsHighNotSurprising = 0; + int countContainsHighOnlyIfSurprising = 0; + for(Score score : scores) { + if(score.category==Category.containsHighNotSupprising) countContainsHighNotSurprising++; + else if(score.category==Category.containsHighOnlyIfSupprising) countContainsHighOnlyIfSurprising++; + } + return countContainsHighNotSurprising + Math.min(s,countContainsHighOnlyIfSurprising); + } + } + + + + public static final PrintStream out = System.out; + public static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + public int numCases; + + public void doCase(int caseNumber) throws Exception { + String line = in.readLine(); + TestCase testCase = new TestCase(line); + out.println(testCase.getResult()); + } + + public void run() throws Exception { + numCases = Integer.parseInt(in.readLine().trim()); + for (int i = 1; i <= numCases; i++) { + out.print(""Case #"" + i + "": ""); + doCase(i); + } + } + + public static void main(String[] args) throws Exception { + new Dancing().run(); + } + +} +" +A20631,"import java.io.*; +public class DancingWithTheGooglers +{ + public static void main(String [] args) throws Exception + { + BufferedReader br = new BufferedReader(new FileReader(""BBI.txt"")); + + String write = """"; + int i = Integer.parseInt(br.readLine()); + + for(int j = 1; j <= i; j++) + { + String ra = br.readLine(); + int c = 0; + + Integer [] ir = c(ra.split("" "")); + int S = ir[1]; + for(int k = 0; k < ir[0]; k++) + { + boolean flag = false; + int score = ir[k + 3]; + int [] triplet = new int[3]; + + for(int l = 0; l < 3; l++) + if(score >= 0) + { + triplet [l] = score / (3 - l); + score = score - triplet[l]; + if(triplet[l] >= ir[2]) + { + c = c + 1; + flag = true; + break; + } + + } + + if(S > 0) + { + for(int m = 1; m < 3; m++) + { + if(!flag && triplet[m-1] > 0) + if(triplet[m] == triplet[m - 1]) + { + triplet[m] = triplet[m] + 1; + triplet[m-1] = triplet[m-1] - 1; + if(triplet[m] >= ir[2]) + { + c = c + 1; + S = S - 1; + } + break; + } + } + + } + + } + + String newLine = ""\n""; + if(j == i) + newLine = """"; + write = write + ""Case #"" + j + "": "" + c + newLine; + //System.out.println(""Case #"" + j + "": "" + c); + } + + BufferedWriter bw = new BufferedWriter(new FileWriter(""BBO.txt"")); + bw.write(write); + bw.flush(); + bw.close(); + System.out.println(write); + } + + static Integer [] c(String [] args) + { + Integer [] array = new Integer[args.length]; + for(int i = 0; i < args.length; i++) + { + array [i] = Integer.parseInt(args[i]); + } + return array; + } + +}" +A23011,"import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.File; +import java.io.PrintStream; +import java.util.Scanner; +import java.util.Arrays; +import java.util.ArrayList; + +public class Dancers{ + public static ArrayList scores; + + public static void main(String arg[]){ + System.out.print(""Enter the file path of the input file : ""); + String path = new Scanner(System.in).nextLine(); + String ANS ="""", output="""", test; + int diff; + + try{ + Scanner read = new Scanner(new File(path)); + int testCases = Integer.parseInt(read.nextLine()); + int cn=0; String tongue; + while(cn++ to exit...""); + (new Scanner(System.in)).nextLine(); + System.exit(1); + } + } + + public static void writeToFile(String file, String text){ + PrintStream out = null; + try { + out = new PrintStream(new FileOutputStream(file)); + out.print(text); + } + catch(Exception e){} + finally { + if (out != null) out.close(); + } + } + + public static int solve(String test){ + String temp[] = test.split("" ""); + ArrayList tempList = new ArrayList(); + Triplet[] scores; + int dancerNo, surpriseNo, bestResult; + + dancerNo = Integer.parseInt(temp[0]); + surpriseNo = Integer.parseInt(temp[1]); + bestResult = Integer.parseInt(temp[2]); + int counter = 0; + + while(counter < dancerNo){ + tempList.add(new Triplet(temp[3+counter])); + counter++; + } + + scores = tempList.toArray(new Triplet[tempList.size()]); + + + Arrays.sort(scores); + + scores = doTheSurprises(scores,surpriseNo, bestResult); + + System.out.println(Arrays.toString(scores)); + + return count(scores, bestResult); + } + + public static Triplet[] doTheSurprises(Triplet sc[], int surprise, int max){ + Triplet temp; + int sNo=0; + for(int i=sc.length-1; i>=0; i--){ + if(sNo==surprise){ + break; + } + + if(sc[i].scores[2]=max){ + temp++; + } + } + return temp;} +} + +class Triplet implements Comparable{ + public int scores[] = new int[3]; + public Triplet(int x, int y, int z){ + scores[0]=x; + scores[1]=y; + scores[2]=z; + } + + public Triplet(String x){setThrees(Integer.parseInt(x));} + + public Triplet(int x){setThrees(x);} + + public void setThrees(int numb){ + this.scores[0] =numb/3; + this.scores[1] = (numb-scores[0])/2; + this.scores[2] = numb - scores[0] - scores[1]; + } + + public int compareTo(Triplet x){ + if(scores[2]x.scores[2]){ + return 1; + } + else{ + return 0; + } + + } + + public boolean doSurprise(){ + int s1 = scores[1], s2 = scores[2]; + + if(s1 == s2){ + s1--; s2++; + if(s1>=0 && s2<=10){ + scores[1] = s1; + scores[2] = s2; + return true; + } + } + return false; + } + + public String toString(){ + return Arrays.toString(scores); + } +} +" +A20132,"import java.util.Scanner; +public class Dancing { + private static boolean isValidScore(int score) { + return score >=0 && score <= 10; + } + private static boolean canReach (int tot, int p, boolean canSurprise) { + int n = tot / 3; + int a,b,c; + a = n; + b = n; + c = tot - a - b; + int max = -1; + if (a==c) { + //a-1, a, a+1 + if (isValidScore(a-1) && isValidScore(a) && isValidScore(a+1) && canSurprise) { + max = a+1; + } + //a, a, a + else if (isValidScore(a)) max = a; + } + if (a+1 == c) { + //a, a, a+1 + if (isValidScore(a) && isValidScore(a+1)) max = a+1; + } + if (a+2 == c) { + //a, a, a+2 + if (isValidScore(a) && isValidScore(a+2) && canSurprise) max = a+2; + //a, a+1, a+1 + else if (isValidScore(a) && isValidScore(a+1)) max = a+1; + } + return max >= p; + } + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for (int i=0; i < T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int numCanReach = 0; + for (int j=0; j < N; j++) { + int tot = in.nextInt(); + if (canReach(tot, p, false)) numCanReach++; + else if (canReach(tot,p, true) && S != 0) { + numCanReach++; + S--; + } + } + System.out.println(""Case #""+(i+1)+"": ""+numCanReach); + } + } +} +" +A22058,"import java.io.*; +import java.util.*; + +public class BDancingGooglers { + public static void main(String[] args) throws IOException { + // parsing file + Scanner scanner = new Scanner(new File(""B-large.in"")); + int cases = Integer.parseInt(scanner.nextLine()); + int[][] lineArray = new int[cases][]; + int index = 0; + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + String[] split = line.split(""\\s""); + lineArray[index] = new int[split.length]; + for (int i = 0; i < split.length; i++) { + lineArray[index][i] = Integer.parseInt(split[i]); + } + + // printing parsed information + for (int i = 0; i < split.length; i++) { +// System.out.print(lineArray[index][i] + "" ""); + } +// System.out.println(); + // + + index++; // DON'T DELETE + } + + // doing computation by case + FileWriter fw = new FileWriter(""outputb.txt""); + for (int i = 0; i < lineArray.length; i++) { + int count = 0; + // int googlers = lineArray[i][0]; + int surprises = lineArray[i][1]; + int p = lineArray[i][2]; +// System.out.println(""p is "" + p + "", surprises is "" + surprises); + int base1 = Math.max(3 * p - 2, 0); + int base2 = Math.max(3 * p - 4, 0); + for (int j = 3; j < lineArray[i].length; j++) { + if (p == 0) { + count++; + } + else if (lineArray[i][j] == 0) { + + } + else if (base1 <= lineArray[i][j]) { + count++; +// System.out.println(""\tscore "" + lineArray[i][j] + "", count "" + count); + } else if (base2 <= lineArray[i][j] && surprises != 0) { + count++; + surprises--; +// System.out.println(""\t2score "" + lineArray[i][j] + "", count "" + count + "", surprises left "" + surprises); + } else { +// System.out.println(""\t3score "" + lineArray[i][j]); + } + } + fw.write(""Case #"" + (i + 1) + "": "" + count + ""\n""); +// System.out.println(""Case #"" + (i + 1) + "": "" + count); +// System.out.println(); + } + fw.close(); + } + +} +" +A22890,"package y2012; + +import java.io.*; +import java.util.Arrays; + +public class Glob { + + /** + * Fetch the entire contents of a text file, and return it in a String. + * This style of implementation does not throw Exceptions to the caller. + * + * @param aFile is a file which already exists and can be read. + */ + static public void IOwork() { + //...checks on aFile are elided + try { + //use buffering, reading one line at a time + //FileReader always assumes default encoding is OK! + BufferedReader input = new BufferedReader(new FileReader(new File(""F:\\file.in""))); + Writer output = new BufferedWriter(new FileWriter(new File(""F:\\file.out""))); + try { + String line = null; //not declared within while loop + /* + * readLine is a bit quirky : + * it returns the content of a line MINUS the newline. + * it returns null only for the END of the stream. + * it returns an empty String if two newlines appear in a row. + */ + line = input.readLine(); + int NoOfCases = Integer.parseInt(line); + for (int i = 0; i < NoOfCases; i++) { + line = input.readLine(); + String[] v1 = line.split("" ""); + int t = Integer.parseInt(v1[0]); + int s = Integer.parseInt(v1[1]); + int p = Integer.parseInt(v1[2]); + int answer = 0; + System.out.println(t); + System.out.println(s); + System.out.println(p); + for (int j = 3; j < v1.length; j++) { + int temp = Integer.parseInt(v1[j]); + if (temp > 0) { + switch (temp%3) { + case 0 : { + if (temp/3 >= p) answer++; + else if (temp/3+1 == p && s > 0) { + answer++; + s--; + } + break; + } + case 1 : { + if (temp/3+1 >= p) answer++; + break; + } + case 2 : { + if (temp/3+1 >= p) answer++; + else if (temp/3+2 == p && s > 0) { + answer++; + s--; + } + break; + } + } + } + else if (p == 0) answer++; + } + output.write(""Case #""+(i+1)+"": ""+answer+""\n""); + } + } + finally { + input.close(); + output.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + } + + private static int rope(int[][] lines) { + int ans = 0; + for (int i = 0; i < lines.length-1; i++){ + for (int j = i+1; j < lines.length; j++) { + if ((lines[i][0] > lines[j][0] && lines[i][1] < lines[j][1])||(lines[i][0] < lines[j][0] && lines[i][1] > lines[j][1])) + ans++; + } + } + return ans; + } + + public static void main (String[] aArguments) throws IOException { + IOwork(); + } +}" +A20913,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + + +public class ProblemB { + public static void main(String[] args) throws IOException{ + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String result =""""; + int num = Integer.parseInt(br.readLine()); + for (int i = 0; i < num; i++) { + result += ""Case #""+(i+1)+"": ""; + String input[] = br.readLine().split("" ""); + int numGooglers = Integer.parseInt(input[0]); + int numSurprising = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + int greaterThanP = 0; + int surprisingGreaterThanP = 0; + for (int j = 0; j < numGooglers; j++) { + int googler = Integer.parseInt(input[j + 3]); + if (googler >= p + 2*(p-1)) + greaterThanP++; + else if(googler >= p + 2*(p-2) && googler >= p) + surprisingGreaterThanP++; + } + result += (greaterThanP+(int)Math.min(numSurprising, surprisingGreaterThanP)); + if (i != num - 1) + result += ""\n""; + } + PrintWriter out = new PrintWriter(new BufferedWriter( + new FileWriter(new File(""out.txt"")))); + out.print(result); + out.flush(); + out.close(); + System.out.print(result); + } + +} +" +A21150,"import java.util.*; +import java.io.*; +public class Dancer +{ + public static void main(String[] args) + { + Scanner in = new Scanner(new BufferedInputStream(System.in)); + int T = in.nextInt(); + for(int i = 0; i < T; i++) + { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int minTotal = p*3-4; + int minTotalnoS = p*3-2; + if(p <= 1) + { + minTotal = p; + minTotalnoS = p; + } + int surprises = 0; + int dancers = 0; + //int[] scores = new int[N]; + for(int j = 0; j < N; j++) + { + // scores[j] = in.nextInt(); + int score = in.nextInt(); + if(score >= minTotal) { + dancers++; + if(score < minTotalnoS) + surprises++; + } + } + if(S < surprises) + dancers -= (surprises - S); + System.out.printf(""Case #%d: %d\n"",i+1,dancers); + } + } +}" +A22656,"import java.io.*; +import java.util.*; +public class tr +{ + public static void main(String args[])throws FileNotFoundException,IOException + { + RandomAccessFile in=new RandomAccessFile(""B-large.in"",""r""); + FileOutputStream out= new FileOutputStream(""out.txt""); + int o=Integer.parseInt(in.readLine()); + int j=0; + int res[]=new int[o]; + String str[]=new String[o+1]; + while((str[j]=in.readLine())!=null) + { + String []cas=str[j].split("" ""); + int no=Integer.parseInt(cas[0]); + int sur=Integer.parseInt(cas[1]); + int min=Integer.parseInt(cas[2]); + int da[]=new int[no]; + int mark[]=new int[no]; + int [][]trip=new int[no][3]; + int cursur=0; + String map; + String []mchar=new String[3]; + for(int i=0;i=min) + { + res[j]++; + break; + } + } + } + if(cursurda[j]) + { + temp=da[i]; + da[i]=da[j]; + da[j]=temp; + } + } + } + return da; + } + + static boolean check(int d,int min) + { + String map; + String []mchar=new String[3]; + map=sursplit(d); + mchar=map.split("" ""); + int a=Integer.parseInt(mchar[0]); + int b=Integer.parseInt(mchar[1]); + int c=Integer.parseInt(mchar[2]); + if(a>=min||b>=min||c>=min)return true; + return false; + } + + static String normalsplit(int da) + { + switch(da) + { + case 0:return 0+"" ""+0+"" ""+0; + case 1:return 1+"" ""+0+"" ""+0; + case 2:return 1+"" ""+1+"" ""+0; + case 3:return 1+"" ""+1+"" ""+1; + case 4:return 2+"" ""+1+"" ""+1; + case 5:return 2+"" ""+2+"" ""+1; + case 6:return 2+"" ""+2+"" ""+2; + case 7:return 2+"" ""+2+"" ""+3; + case 8:return 2+"" ""+3+"" ""+3; + case 9:return 3+"" ""+3+"" ""+3; + case 10:return 3+"" ""+3+"" ""+4; + case 11:return 3+"" ""+4+"" ""+4; + case 12:return 4+"" ""+4+"" ""+4; + case 13:return 4+"" ""+4+"" ""+5; + case 14:return 4+"" ""+5+"" ""+5; + case 15:return 5+"" ""+5+"" ""+5; + case 16:return 5+"" ""+5+"" ""+6; + case 17:return 5+"" ""+6+"" ""+6; + case 18:return 6+"" ""+6+"" ""+6; + case 19:return 6+"" ""+6+"" ""+7; + case 20:return 6+"" ""+7+"" ""+7; + case 21:return 7+"" ""+7+"" ""+7; + case 22:return 7+"" ""+7+"" ""+8; + case 23:return 7+"" ""+8+"" ""+8; + case 24:return 8+"" ""+8+"" ""+8; + case 25:return 8+"" ""+8+"" ""+9; + case 26:return 8+"" ""+9+"" ""+9; + case 27:return 9+"" ""+9+"" ""+9; + case 28:return 9+"" ""+9+"" ""+10; + case 29:return 9+"" ""+10+"" ""+10; + case 30:return 10+"" ""+10+"" ""+10; + } + return """"; + } + + static String sursplit(int da) + { + switch(da) + { + case 2:return 2+"" ""+0+"" ""+0; + case 3:return 2+"" ""+1+"" ""+0; + case 4:return 2+"" ""+2+"" ""+0; + case 5:return 2+"" ""+2+"" ""+1; + case 6:return 1+"" ""+2+"" ""+3; + case 7:return 1+"" ""+3+"" ""+3; + case 8:return 2+"" ""+2+"" ""+4; + case 9:return 3+"" ""+2+"" ""+4; + case 10:return 2+"" ""+4+"" ""+4; + case 11:return 3+"" ""+3+"" ""+5; + case 12:return 4+"" ""+3+"" ""+5; + case 13:return 3+"" ""+5+"" ""+5; + case 14:return 4+"" ""+4+"" ""+6; + case 15:return 5+"" ""+4+"" ""+6; + case 16:return 4+"" ""+6+"" ""+6; + case 17:return 5+"" ""+5+"" ""+7; + case 18:return 6+"" ""+5+"" ""+7; + case 19:return 5+"" ""+7+"" ""+7; + case 20:return 6+"" ""+6+"" ""+8; + case 21:return 7+"" ""+6+"" ""+8; + case 22:return 6+"" ""+8+"" ""+8; + case 23:return 7+"" ""+7+"" ""+9; + case 24:return 8+"" ""+7+"" ""+9; + case 25:return 7+"" ""+9+"" ""+9; + case 26:return 8+"" ""+8+"" ""+10; + case 27:return 9+"" ""+8+"" ""+10; + case 28:return 8+"" ""+10+"" ""+10; + } + return """"; + } +}" +A21973,"package com.renoux.gael.codejam.utils; + + + + +/** + * Pour tests unitaires + * + * @author renouxg + */ +public final class ArrayUtils { + + public static int[] parseInts(String[] strings) { + int[] res = new int[strings.length]; + int i = 0; + for (String s : strings) { + res[i++] = Integer.parseInt(s); + } + + return res; + } + + public static long[] parseLongs(String[] strings) { + long[] res = new long[strings.length]; + int i = 0; + for (String s : strings) { + res[i++] = Long.parseLong(s); + } + + return res; + } +} +" +A20832,"package dancing; +import java.io.*; + +public class DancingG { + private int N; + private String[] InputStringArray; + private String[] OutputStringArray; + + public static void main(String[] args) { + try{ + DancingG dg = new DancingG(); + if (dg.GetDataFromInputFile()) + if (dg.ProcestestData()) + dg.WriteDatatoOutputFile(); + else + System.out.println(""Error while writing to outputfile""); + else + System.out.println(""Error while getting the input data""); + }catch(IOException ex){ + System.out.println(""IO Error""); + } + } + private boolean GetDataFromInputFile() throws IOException{ + int casecount=0; + FileInputStream in = new FileInputStream(""E:\\Study\\Google Code jam\\2012\\DancingG"" + + ""\\Input\\A-small-attempt0.in""); + DataInputStream di = new DataInputStream(in); + BufferedReader br = new BufferedReader(new InputStreamReader(di)); + String line; + if ((line = br.readLine())!= null) { + casecount = Integer.parseInt(line); + InputStringArray = new String[casecount]; + OutputStringArray = new String[casecount]; + } + for (int i=0; i=normallimit) + count++; + else + if (Integer.parseInt(parameters[i])>=surprisinglimit) + surprisinglimtcount++; + + } + if (surprisinglimtcount>S) surprisinglimtcount=S; + count = count + surprisinglimtcount; + return String.valueOf(count); + } +} +" +A21343,"package dancingwiththegooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingWithTheGooglers { + + + public static void main(String[] args) throws IOException { + + + BufferedReader br=new BufferedReader(new FileReader(new File(""./dancingwiththegooglers/b-large.in""))); + BufferedWriter bw=new BufferedWriter(new FileWriter(new File(""./dancingwiththegooglers/large.out""))); + + int numberOfCase=Integer.parseInt(br.readLine()); + + StringBuilder out=new StringBuilder(); + + for(int i=1;i<=numberOfCase;i++){ + int count=0; + out.append(""Case #""+i+"": ""); + + String[]input=br.readLine().split("" ""); + + int surprising=Integer.parseInt(input[1]); + int goal=Integer.parseInt(input[2]); + int googlers=Integer.parseInt(input[0]); + for(int j=3;j<3+googlers;j++){ + + int result=check(Integer.parseInt(input[j]),goal,surprising); + if(result==0){ + count++; + surprising--; + } + if(result==1) + count++; + + + + } + + + + out.append(count); + if(i=goal+(goal-2)+(goal-2)) + return 0; + else + return -1; + } + else + return 1; + + } + +} +" +A20890,"package codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +public abstract class Task { + + private String inputFileName; + private BufferedReader in; + private PrintWriter out; + + public Task(String[] args) { + inputFileName = args[0]; + } + + public void execute() throws IOException { + File f = new File(inputFileName); + in = new BufferedReader(new FileReader(f)); + + catchInputData(); + + in.close(); + + processInputData(); + + f = new File(inputFileName.substring(0, inputFileName.length() - 2) + ""out""); + f.createNewFile(); + out = new PrintWriter(new BufferedWriter(new FileWriter(f))); + + generateOutputFile(); + + out.flush(); + out.close(); + } + + protected abstract void generateOutputFile() throws IOException; + + protected abstract void processInputData(); + + protected abstract void catchInputData() throws IOException; + + protected String readLine() throws IOException { + return in.readLine(); + } + + protected void writeLine(String line) throws IOException { + out.println(line); + } + +} +" +A20212,"package dancingwithgooglers; + +import java.util.Scanner; + +public class Main { + + static enum Mark { + IMPOSSIBLE, SURPRISING, REGULAR; + } + + static class Googler { + + private int total = 0; + + public Googler(int total) + { + this.total = total; + } + + public Mark canGetMark(int mark) + { + if(mark > 10 || mark < 0) return Mark.IMPOSSIBLE; + + if(canGetMark(mark+1) == Mark.REGULAR) return Mark.REGULAR; + + if(mark + mark + mark == total) return Mark.REGULAR; + if(mark > 0) if(mark + mark + mark - 1 == total) return Mark.REGULAR; + if(mark > 0) if(mark + mark - 1 + mark - 1 == total) return Mark.REGULAR; + if(mark < 10) if(mark + mark + mark + 1 == total) return Mark.REGULAR; + if(mark < 10) if(mark + mark + 1 + mark + 1 == total) return Mark.REGULAR; + + if(canGetMark(mark+1) == Mark.SURPRISING) return Mark.SURPRISING; + + if(mark < 9) if(mark + mark + 1 + mark + 2 == total) return Mark.SURPRISING; + if(mark < 9) if(mark + mark + 2 + mark + 2 == total) return Mark.SURPRISING; + if(mark > 1) if(mark + mark - 1 + mark - 2 == total) return Mark.SURPRISING; + if(mark > 1) if(mark + mark - 2 + mark - 2 == total) return Mark.SURPRISING; + + return Mark.IMPOSSIBLE; + } + + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + + for(int testCase = 1; testCase <= T; testCase++) + { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int result = 0; + for(int i = 0; i < N; i++) + { + Googler googler = new Googler(sc.nextInt()); + Mark mark = googler.canGetMark(p); + if(mark == Mark.REGULAR) + { + result++; + } + else if(mark == Mark.SURPRISING && S > 0) + { + result++; + S--; + } + } + System.out.println(""Case #""+testCase+"": ""+result); + } + } + +} +" +A20819,"import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Collections; +import java.util.Scanner; +import java.util.Vector; + + +public class pbB { + public static void main(String[] args) throws FileNotFoundException { + Scanner sc = new Scanner(new FileReader(""test.in"")); + PrintWriter out= new PrintWriter(""bigout.out""); + + int k=sc.nextInt(), n,s,p,rep,sup,inf; Vector scores; + for(int i=1;i<=k;i++){ + scores= new Vector(); + n= sc.nextInt();s=sc.nextInt();p=sc.nextInt(); + for(int h= 0;h=0;h--){ + if(scores.elementAt(h)>=sup) rep++; + else if (scores.elementAt(h)>=inf && s>0){ + rep++;s--; + } + else break; + } + out.print(""Case #""+i+"": ""+rep); + if (i!=k) out.println(); + } + out.close(); +} +} +" +A21485,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try{ + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + + + + strLine = br.readLine(); + int T = Integer.valueOf(strLine); + // System.out.println(T); + int N[] = new int[T]; + int S[] = new int[T]; + int p[] = new int[T]; + + int t[][] = new int[T][100]; + + int j = 0; + + while ((strLine = br.readLine()) != null) { +// N[j]=Integer.valueOf(strLine); + // strLine = br.readLine(); + String[] ss = strLine.split("" ""); + + // System.out.println(N[j]+ ""-""); + N[j] = Integer.valueOf(ss[0]); + S[j] = Integer.valueOf(ss[1]); + p[j] = Integer.valueOf(ss[2]); + + for (int i = 0; i < N[j]; i++) { + t[j][i] = Integer.valueOf(ss[i+3]); + // System.out.println(a[j][i]); + } + + j++; + + } + + + + + + + for (int k=0; k= p[k]) count++; + } + else{ + if (rounded >= p[k]) count++; + else if ((rounded+1 >= p[k]) && (t[k][i]>0)) possible ++; + } + + + + + + if (possible < S[k]) { + res = count + possible; + } + else { + res = count + S[k]; + } + + } + + + + + System.out.print(""Case #""); + System.out.print(k+1); + System.out.print("": ""); + System.out.print(res); + + + System.out.println(); + + + } + + + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + + } + +} +" +A21464,"package codejam.dancing; + +import codejam.is.TestAbstract; + +import java.util.StringTokenizer; + +/** + * Created with IntelliJ IDEA. + * User: ofer + * Date: 4/14/12 + * Time: 4:48 AM + * To change this template use File | Settings | File Templates. + */ +public class DancingTest extends TestAbstract { + + + @Override + public void run(String s) { + StringTokenizer tokenizer = new StringTokenizer(s); + int numOfGooglers = Integer.parseInt(tokenizer.nextToken()); + int numOfSurprises = Integer.parseInt(tokenizer.nextToken()); + int bestResult = Integer.parseInt(tokenizer.nextToken()); + + int result = 0; + for (int i = 0; i < numOfGooglers; i++) { + int score = Integer.parseInt(tokenizer.nextToken()); + if (score >= bestResult + 2*Math.max(bestResult-1, 0)) { + result++; + } else if (score >= (bestResult + 2*Math.max(bestResult-2, 0)) && numOfSurprises > 0) { + result++; + numOfSurprises--; + } + } + + output.append(result); + } +} +" +A21864," +package prg2; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +/** + * @author Brijesh Mistry + * + */ +public class GooglerDance { + + + + public static void main(String[] args) { + + try{ + FileInputStream fstream = new FileInputStream(""b1.in""); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String fileline; + + //Read File Line By Line + int j =0 ; + String strTestcases ; + int iTestcases = 0; + + //Read no of testcases + if(((strTestcases = br.readLine()) != null)){ + System.out.println(""Test cases:""+strTestcases); + iTestcases = Integer.parseInt(strTestcases); + } + //int noofGoogler = 0; + //int noOfSurprises = 0; + //int noOfSurprisesRemaining = 0; + //int limitScore = 0; + //int minscore = 0; + //int totalWinner = 0; + for(int k=1;k<=iTestcases;k++){ + //for(int k=1;k<=3;k++){ + int noofGoogler = 0; + int noOfSurprises = 0; + int noOfSurprisesRemaining = 0; + int limitScore = 0; + int minscore = 0; + int totalWinner = 0; + if((fileline = br.readLine()) != null){ + //System.out.println (""line #""+(k)+"" ""+fileline); + StringTokenizer st = new StringTokenizer(fileline, "" ""); + noofGoogler = Integer.parseInt(st.nextToken()); + noOfSurprises = Integer.parseInt(st.nextToken()); + limitScore = Integer.parseInt(st.nextToken()); + //System.out.println(k+""Parameters fetched:""+noofGoogler+"" : ""+noOfSurprises+ "" : ""+limitScore); + + //Logic that gives the no of players + //store Max scores into ArrayList + ArrayList maxScores = new ArrayList(); + ArrayList secondscore =new ArrayList(); + for(int i=0;i=minscore && score >= limitScore){ + totalWinner +=1; + }else{ + //System.out.println(""adding score: case :""+k+"":""+score); + secondscore.add(score); + } + } + + noOfSurprisesRemaining = noOfSurprises; + if(noOfSurprisesRemaining>0){ + minscore = (limitScore-2)*2+limitScore; + //System.out.println(""min score""+minscore); + + for(int score:secondscore){ + if(score>=minscore && noOfSurprisesRemaining>0 && score >= limitScore){ + //ystem.out.println(""for Surprises score: case :""+k+"":"" +score); + totalWinner +=1; + noOfSurprisesRemaining --; + } + } + } + + + + System.out.println(""Case #""+k+"": ""+totalWinner); + + } + } + + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + e.printStackTrace(); + } + + } + +} +" +A20705,"import java.io.*; +import java.util.*; + + +public class Blank { + public static int cases = 0; + + public static void main(String args[]) { + File input = new File(""Input.txt""); + File output = new File(""Output.txt""); + saveGame(output, convertString(loadGame(input))); + } + + public static String[] loadGame(File input){ + Scanner in; + try { + in = new Scanner(input); + String[] output = new String[30]; + cases = in.nextInt(); + in.nextLine(); + for(int i = 0; i < cases; i++){ + output[i] = in.nextLine().toLowerCase(); + } + in.close(); + return output; + } + catch (StringIndexOutOfBoundsException e) { + } + catch (FileNotFoundException e) { + } + catch (NoSuchElementException e) { + } + catch (NullPointerException e) { } + return null; + } + + public static void saveGame(File name, String[] output){ + PrintWriter out; + try { + out = new PrintWriter(name); + for(int i = 1; i <= cases; i++){ + out.println(""Case #"" + i + "": "" + output[(i-1)]); + } + out.close(); + } + catch (FileNotFoundException e) { + + } + catch (NullPointerException e) { + + } + } + + public static String[] convertString(String[] output){ + String[] returnString = new String[30]; + for(int i = 0; i < cases; i++){ + returnString[i] = Character.toString(convert(output[i].charAt(0))); + for(int j = 1; j < output[i].length(); j++){ + returnString[i] += convert(output[i].charAt(j)); + } + } + return returnString; + } + + public static char convert(char letter){ + char returnLetter; + switch (letter) { + case 'a': returnLetter = 'y'; + break; + case 'b': returnLetter = 'h'; + break; + case 'c': returnLetter = 'e'; + break; + case 'd': returnLetter = 's'; + break; + case 'e': returnLetter = 'o'; + break; + case 'f': returnLetter = 'c'; + break; + case 'g': returnLetter = 'v'; + break; + case 'h': returnLetter = 'x'; + break; + case 'i': returnLetter = 'd'; + break; + case 'j': returnLetter = 'u'; + break; + case 'k': returnLetter = 'i'; + break; + case 'l': returnLetter = 'g'; + break; + case 'm': returnLetter = 'l'; + break; + case 'n': returnLetter = 'b'; + break; + case 'o': returnLetter = 'k'; + break; + case 'p': returnLetter = 'r'; + break; + case 'q': returnLetter = 'z'; + break; + case 'r': returnLetter = 't'; + break; + case 's': returnLetter = 'n'; + break; + case 't': returnLetter = 'w'; + break; + case 'u': returnLetter = 'j'; + break; + case 'v': returnLetter = 'p'; + break; + case 'w': returnLetter = 'f'; + break; + case 'x': returnLetter = 'm'; + break; + case 'y': returnLetter = 'a'; + break; + case 'z': returnLetter = 'q'; + break; + default: returnLetter = ' '; + break; + } + return returnLetter; + } + +} +" +A22770,"package com.menzus.gcj._2012.qualification.b; + +import com.menzus.gcj.common.OutputEntry; + +public class BOutputEntry implements OutputEntry { + + private int maximumGooglersNumber; + + public void setMaximumGooglersNumber(int maximumGooglersNumber) { + this.maximumGooglersNumber = maximumGooglersNumber; + } + + @Override + public String formatOutput() { + return Integer.toString(maximumGooglersNumber); + } +} +" +A21581,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.common; + +import java.util.ArrayList; + +/** + * + * @author jim + */ +public class Input { + + private final String[] header; + private final String[] data; + + public Input(ArrayList lines, int header) { + int size = lines.size(); + this.header = new String[header]; + this.data = new String[size - header]; + for (int i = 0; i < size; i++) { + String line = lines.get(i); + if (i < header) + this.header[i] = line; + else + this.data[i - header] = line; + } + } + + public String[] getHeader() { + return header; + } + + public String[] getData() { + return data; + } + +} +" +A20891,"package codejam.qualification; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import codejam.Task; + +public class B extends Task { + + private int t; + private String[][] testCases; + private String[] resultset; + + public B(String[] args) { + super(args); + } + + public static void main(String[] args) throws IOException { + Task taskB = new B(args); + taskB.execute(); + } + + protected void catchInputData() throws IOException { + t = Integer.parseInt(readLine()); + testCases = new String[t][]; + + // iterates over cases + for (int c = 0; c < t; c++) { + testCases[c] = readLine().split("" ""); + } + } + + protected void processInputData() { + resultset = new String[t]; + + // iterates over cases + for (int c = 0; c < t; c++) { + String[] testCase = testCases[c]; + + int n = Integer.valueOf(testCase[0]); + int s = Integer.valueOf(testCase[1]); + int p = Integer.valueOf(testCase[2]); + int y = 0; + + for (int i = 3; i < 3 + n; i++) { + int t = Integer.valueOf(testCase[i]); + if (Math.ceil((float) t / 3) >= p) { + y++; + } else if (s > 0 && t > 1 && (Math.round((float) t / 3) + 1) >= p) { + y++; + s--; + } + } + + resultset[c] = """"+y; + } + } + + protected void generateOutputFile() throws IOException { + // iterates over cases + for (int c = 0; c < t; c++) { + writeLine(""Case #"" + (c + 1) + "": "" + resultset[c]); + } + } + +} +" +A22662,"import java.util.Scanner; + + +public class BS { + + public static void main(String args[]) { + Scanner in = new Scanner(System.in); + + int count = in.nextInt(); + for (int i = 1; i <= count ; i++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int p_count = 0; + int s_count = 0; + for (int j = 0; j < n; j++) { + int current = in.nextInt(); + int rest = current - p; + if (rest < 0) { + continue; + } + int restOf2p = rest - (p * 2); + if (restOf2p >= -2) { + p_count++; + continue; + } + if (restOf2p >= -4) { + s_count++; + } + } + if (s_count > s) { + s_count = s; + } + System.out.format(""Case #%d: %d\n"",i,p_count + s_count); + } + } + +} + +" +A22374,"/* + * Main.java + * + * Created on 14.04.2012, 10:03:46 + * + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package codejam12; + +import qualification.CodeJamQuali; + +/** + * + * @author Besitzer + */ +public class Main { + + /** + * @param args the command line arguments + */ + /*public static void main(String[] args) { + char[] C = new char[26]; + CodeJamQuali CJQ =new CodeJamQuali(); + CJQ.fillDict(""our language is impossible to understand"",""ejp mysljylc kd kxveddknmc re jsicpdrysi"",C); + CJQ.fillDict(""there are twenty six factorial possibilities"",""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"",C); + CJQ.fillDict(""so it is okay if you want to just give up"",""de kr kd eoya kw aej tysr re ujdr lkgc jv"",C); + C['z'-'a']='q'; + C['q'-'a']='z'; + System.out.println(""abcdefghijklmnopqrstuvwxyz""); + System.out.println(C); + for(int i =0;i<26;i++)if(C[i]=='z')System.out.println(""found""); + + }*/ + + public static void main(String[] args) { + + CodeJamQuali CJQ =new CodeJamQuali(); + //CJQ.go(""src/qualification/A-small-attempt0.in"", 1); + CJQ.go(""src/qualification/B-large.in"", 2); + + } + +} +" +A21149,"import java.io.*; +import java.util.*; +import java.math.*; +public class Solution { + static int miracles=-1; + static int tresh=1000; + public static void main(String args[]) throws Exception { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for(int t = 0; t < T; t++) { + int N=sc.nextInt(); + miracles=sc.nextInt(); + tresh=sc.nextInt(); + int count=0; + for(int i=0;i=tresh; + case 1: + return ((v/3)+1)>=tresh; + case 2: + return ((v+1)/3)>=tresh; + } + return false; + } + public static boolean isAboveThresMiracle(int v) { + if(miracles<=0) + return false; + switch(v%3) { + case 0: + if(v>0&&(v/3)+1>=tresh) { + miracles--; + return true; + } + break; + case 2: + if(((v+1)/3)+1>=tresh) { + miracles--; + return true; + } + break; + } + return false; + } +} +" +A22752,"package Qualification; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; + +public class B { + public static void main(String[] args) throws IOException{ + BufferedReader in = new BufferedReader(new FileReader(new File(""C:\\Users\\braidon\\Desktop\\CodeJam\\B-large.in""))); + FileWriter out = new FileWriter(new File(""C:\\Users\\braidon\\Desktop\\CodeJam\\B-large.out"")); + //BufferedReader in = new BufferedReader(new FileReader(new File(""C:\\Users\\braidon\\Desktop\\CodeJam\\B-small.in""))); + //FileWriter out = new FileWriter(new File(""C:\\Users\\braidon\\Desktop\\CodeJam\\B-small.out"")); + + int N = new Integer(in.readLine()); + + for(int c = 1; c <= N; c++){ + int resp = 0; + String[] sin = in.readLine().split("" ""); + int n = Integer.parseInt(sin[0]); + int s = Integer.parseInt(sin[1]); + int p = Integer.parseInt(sin[2]); + int[] t = new int[n]; + int[] m = new int[n]; + for(int c1 = 3; c1 <= sin.length-1; c1++){ + t[c1-3] = Integer.parseInt(sin[c1]); + } + Arrays.sort(t); + for(int c1 = 3; c1 <= sin.length-1; c1++){ + int ti = t[c1-3]; + m[c1-3] = 0; + if(ti != 0){ + if(s > 0){ + int a1 = ti/3; + int a2 = 0; + if(a1 + 2 <= 10){ + a2 = a1 + 2; + }else{ + a2 = 10; + a1 = 8; + } + if((a1+a2+a1 == ti)|| + (a1+a2+a2 == ti)|| + (a1+a2+a2-1 == ti)){ + m[c1-3] = a2; + if(a2 < p){ + m[c1-3] = 0; + }else{ + s -= 1; + } + } + if(m[c1-3] == 0){ + a1 -= 1; + a2 = a1 + 2; + if((a1+a2+a1 == ti)|| + (a1+a2+a2 == ti)|| + (a1+a2+a2-1 == ti)){ + m[c1-3] = a2; + if(a2 < p){ + m[c1-3] = 0; + }else{ + s -= 1; + } + } + } + } + if(m[c1-3] == 0){ + int a1 = ti/3; + if(ti%3 == 0){ + m[c1-3] = a1; + } + else{ + m[c1-3] = a1+1; + } + } + } + if(m[c1-3] >= p){ + resp += 1; + } + } + out.write(""Case #"" + c + "": "" + resp + ""\n""); + } + out.flush(); + out.close(); + } + static void inverter(int[] b){ + int left = 0; + int right = b.length-1; + + while (left < right) { + int temp = b[left]; + b[left] = b[right]; + b[right] = temp; + + left++; + right--; + } + } +} +" +A21661,"package com.google.code; + +import java.io.IOException; + +public class B extends GCJ { + + protected B() throws IOException { + super(); + } + + @Override + protected void code(int count) throws IOException { + readLine(); + int N = getIntInput(0); + int S = getIntInput(1); + int p = getIntInput(2); + + int limitForOrdinary = p + (p - 1 < 0 ? p : p - 1) * 2; + int result = 0; + for (int i = 0; i < N; i++) { + int googler = getIntInput(3 + i); + if (googler>= limitForOrdinary) { + result ++; + continue; + } + if (S>0) + if (googler>1 && googler+2 >=limitForOrdinary) { + S--; + result++; + continue; + } + } + writeln(result); + } + public static void main(String[] args) throws NumberFormatException, + IOException { + new B().run(); +} +} +" +A22066,"package hk.polyu.cslhu.codejam.solution.impl.qualificationround; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import hk.polyu.cslhu.codejam.solution.Solution; + +import org.apache.log4j.Logger; + +public class SpeakingInTongues extends Solution { + private Map codeMap; + private String oriText; + + private void setCodeMap() { + this.codeMap = new HashMap(); + codeMap.put(""y"", ""a""); + codeMap.put(""e"", ""o""); + codeMap.put(""q"", ""z""); + codeMap.put(""z"", ""q""); + + List oriTextList = new ArrayList(); + oriTextList.add(""ejp mysljylc kd kxveddknmc re jsicpdrysi""); + oriTextList.add(""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd""); + oriTextList.add(""de kr kd eoya kw aej tysr re ujdr lkgc jv""); + + List encodedTextList = new ArrayList(); + encodedTextList.add(""our language is impossible to understand""); + encodedTextList.add(""there are twenty six factorial possibilities""); + encodedTextList.add(""so it is okay if you want to just give up""); + + for (int i = 0; i < oriTextList.size(); i++) { + String oriText = oriTextList.get(i); + String encodedText = encodedTextList.get(i); + + for (int j = 0; j < oriText.length(); j++) { + String ori = oriText.substring(j, j + 1); + String encoded = encodedText.substring(j, j + 1); + + if (ori.equals("" "")) + continue; + + if (! codeMap.containsKey(ori)) + codeMap.put(ori, encoded); + else if (! codeMap.get(ori).equals(encoded)) + logger.error(""Found duplicate encoded string for input "" + ori); + } + } + + logger.info(""The size of code map is "" + this.codeMap.size()); + } + + @Override + public void setProblem(List problemDesc) { + // TODO Auto-generated method stub + this.oriText = problemDesc.get(0); + } + + @Override + public void solve() { + // TODO Auto-generated method stub + this.setCodeMap(); + + this.result = """"; + + for (int i = 0; i < this.oriText.length(); i++) { + String ori = this.oriText.substring(i, i + 1); + + if (ori.equals("" "")) + this.result += ori; + else if (this.codeMap.containsKey(ori)) + this.result += this.codeMap.get(ori); + else + logger.error(""Failure to find the encoded string for "" + ori); + } + } +} +" +A21219,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class B { + + public static void main(String[] args) throws Exception { + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(in.readLine()); + for (int m = 0; m < n; m++) { + String[] parts = in.readLine().split("" ""); + int googlers = Integer.parseInt(parts[0]); + int s = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + + int[] scores = new int[googlers]; + for (int i = 0; i < googlers; i++) { + scores[i] = Integer.parseInt(parts[i + 3]); + } + + Arrays.sort(scores); + + int winners = 0; + + for (int score : scores) { + int j1 = score / 3 + 1; + int[] judge = { j1, j1, j1 }; + int sum = j1 * 3; + for (int i = 0; sum > score; i++) { + judge[i % 3]--; + sum--; + } + if (judge[2] >= p) { + winners++; + continue; + } + if (judge[2] == p - 1 && s > 0) { + if (judge[0] == judge[2] && judge[0] != 0) { + winners++; + s--; + continue; + } + if (judge[1] == judge[2] && judge[1] != 0) { + winners++; + s--; + continue; + } + } + } + + System.out.println(""Case #"" + (m + 1) + "": "" + winners); + } + + } +}" +A20187,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + + +public class Main { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(args[0])); + br.readLine(); + int c = 1; + for(String s = br.readLine(); s != null ;s = br.readLine()){ + int[] vals = strToInt(s.split("" "")); + int special = 0; + int possible = 0; + float score = vals[2]; + for(int i = 3; i < vals.length; i++){ + if(isSpecial(score, vals[i])){ + special++; + }else if(canBeSpecial(score, vals[i])){ + possible ++; + } + } + + System.out.println(""Case #"" + c + "": "" + (special + Math.min(possible, vals[1]))); + c++; + } + + + } + + private static boolean isPossible(float s, float num){ + return((num) >= s); + } + + + private static boolean isSpecial(float s, float num){ + return(isPossible(s, num) && (num/3+1) > s); + } + + private static boolean canBeSpecial(float s, float num){ + return(isPossible(s, num) && (num/3+2) > s + 0.5); + } + + private static int[] strToInt(String[] s){ + int[] ret = new int[s.length]; + for(int i = 0; i < s.length; i++){ + ret[i] = Integer.parseInt(s[i]); + } + return ret; + } + + +} +" +A21955,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + + +public class main { + + /** + * @param args + */ + public static void main(String[] args) { + try { + System.setOut(new PrintStream(new File(""B-large.out""))); + + Scanner sc = new Scanner(new File(""B-large.in"")); + + int T = sc.nextInt(); + sc.nextLine(); + + for (int tc = 1; tc<=T; tc++) { + int y = 0, y2 = 0; + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + for (int i = 0; i=p || (t/3==p-1 && t%3>0)) { + y++; + } else if((t/3==p-1 && t%3==0) || (t/3==p-2 && t%3==2)) { + if(S>0 && t>=2 && t<=28) { + y++; + S--; + } + } + } + + + + System.out.format(""Case #%d: %d%n"", tc, y); + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + +} +" +A22961,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class Solver { + + public static void main(String[] args) { + try { + FileInputStream fIS = new FileInputStream(args[0]); + BufferedReader r = new BufferedReader(new InputStreamReader(fIS)); + + int t = Integer.parseInt(r.readLine()); + for (int i=0;i= okMin) + ++ok; + } + + int suprisings = 0; + int sMin = notNegative(p-2)+notNegative(p-2)+p; + for (int i=0;i= sMin) + ++suprisings; + } + + if (suprisings > s) + suprisings = s; + + return ok + suprisings; + } + + private static int notNegative(int i) { + return (i < 0) ? 0 : i; + } +} +" +A21959,"package util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class MyUtil { + + + public static BufferedReader getReader(String filename){ + try { + return new BufferedReader(new FileReader(""data/"" + filename)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + return null; + } + + public static BufferedWriter getWriter(String filename){ + try { + return new BufferedWriter(new FileWriter(""output/"" + filename + "".out.txt"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } +} +" +A21550,"import java.io.*; +import java.util.*; + +public class Googlers { + + public static int surprise = 0; + public static int beatTarget = 0; + + public static boolean bestScore(int totalScore, int targetScore) { + + int bestNoSurprise = (int) Math.ceil(totalScore/3.0); + + // If this googler beat the target score + if(bestNoSurprise>=targetScore) { + beatTarget += 1; + return true; + } + + // These are scores that can be a surprise, if there is surprise left + else if(totalScore%3!=1&&totalScore>1&&totalScore<29&&surprise>0) { + + // Test if surprising the score would help + if(bestNoSurprise=targetScore) { + + surprise-=1; + beatTarget += 1; + return true; + + } + + } + + // These are scores that had no hope + return true; + + + } + + public static void main(String[] args) { + + Scanner input = null; + PrintWriter output = null; + + try { + output = new PrintWriter(new FileWriter(""output.txt"")); + input = new Scanner(new File(""input.txt"")); + } catch (FileNotFoundException h) { + System.out.println(""File not found 1""); + System.exit(0); + } catch (IOException e) { + System.out.println(""File not found 2""); + System.exit(0); + } + + int count = Integer.parseInt(input.nextLine()); + + + for(int i=0;i 0 ? 1 : 0) >= p) { + count++; + } + else if (q + (r > 0 ? r : q > 0 ? 1 : 0) >= p && s > 0) { + s--; + count++; + } + } + System.out.println(count); + } + } +} + +/* + * 3 ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym + * veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv + * + * Case #1: our language is impossible to understand Case #2: there are twenty + * six factorial possibilities Case #3: so it is okay if you want to just give + * up + */ +" +A22430," + +import java.util.Scanner; + +/** + * + * @author krishna + */ +public class Dance { + + public static void main(String [] args) + { + Program(); + } + public static void Program() + { + Scanner inp=new Scanner(System.in); + String patt[]; + int count; + String line; + // System.out.println(""Test Case ""); + + int test=Integer.parseInt(inp.nextLine()); + int num=1; + int S,N,P; + int judge1,judge2,judge3,rem; + int Score[]=new int[100]; + while(num<=test) + { + // System.out.println(""pattern ""); + + line=inp.nextLine(); + patt=line.split("" ""); + + N=Integer.parseInt(patt[0]); + S=Integer.parseInt(patt[1]); + P=Integer.parseInt(patt[2]); + count=0; + for(int i=0;i= P) + count++; + else if( S > 0 && (judge1 + 1)>=P ) + { + judge1++; + judge2--; + count++; + S--; + } + // System.out.println(judge1+"" ""+judge2+"" ""+ judge3); + } + else if(rem==1) + { + judge1++; + if(judge1 >= P) + { + count++; + } + + // System.out.println(judge1+"" ""+judge2+"" ""+ judge3); + + } + else if(rem==2) + { + judge1++; + judge2++; + if( (judge1 )>=P) + { + count++; + } + else if( S!=0 && ((judge1)+1)>=P) + { + S--; + judge1++; + judge2--; + count++; + } + + // System.out.println(judge1+"" ""+judge2+"" ""+ judge3); + } + } + System.out.println(""Case #""+num+"": ""+count); + num++; + } + } +} +" +A20396,"import java.io.*; +import java.util.*; + +class GoogleDance +{ + public static void main(String[] args) + { + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + Scanner sc=new Scanner(new InputStreamReader(System.in)); + int t=sc.nextInt(); + String ans[]=new String[t]; + for(int i=0;i=p) + { + b++; + continue; + } + else if((quo+1)==p) + { + if(s>0) + { + if((quo-1)>0) + { + s--; + b++; + continue; + } + } + } + } + else if(rem==1) + { + if((quo+1)>=p) + { + b++; + continue; + } + } + else if(rem==2) + { + if((quo+1)>=p) + { + b++; + continue; + } + else if((quo+2)>=p) + { + if(s>0) + { + s--; + b++; + continue; + } + } + } + } + ans[i]=""Case #""+(i+1)+"": ""+b; + } + for(int i=0;i= p) + cnt++; + else if (A[i] >= p && p - (A[i] - p) / 2 == 2 && sur > 0) { + sur--; + cnt++; + } + System.out.println(""Case #"" + m + "": "" + cnt); + } + } +} +" +A20204,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; +import java.util.*; +import java.io.*; +public class DancingWithGooglers { + public static void main(String[] args) throws Exception + { + Scanner input = new Scanner(new File(""C:\\temp\\B-large.in"")); + int A = input.nextInt(); + for (int c = 1; c <= A; c++) + { + int N = input.nextInt(); + int S = input.nextInt(); + int p = input.nextInt(); + double[] t = new double[N]; + for (int n = 0; n < N; n++) + { + t[n] = input.nextInt(); + } + int a = 0; + for (int i = 0; i < t.length; i++) + { + for (int j = p; j <= 10; j++) + { + if (p == 0 && t[i] == 0) + { + a++; + break; + } + else if (j >= p && j*3-t[i] <= 2 && t[i] > j) + { + a++; + break; + } + else if (j >= p && j*3-t[i] <=4 && t[i] > j && S>0) + { + S--; + a++; + break; + } + } + } + System.out.println(""Case #"" + c + "": "" + a); + } + + } +} +" +A22460,"import com.sun.org.apache.bcel.internal.generic.NEW; + +import java.io.IOException; +import java.util.List; + +public class WaterSheds extends JamProblem { + + public static void main(String[] args) throws IOException { + WaterSheds p = new WaterSheds(); + p.go(); + } + + Character[][] res; + WSCase cs; + char curr; + + @Override + String solveCase(JamCase jamCase) { + cs = (WSCase) jamCase; + curr = 'a'; + res = new Character[cs.h][cs.w]; + for (int y = 0; y < cs.h; y++) { + for (int x = 0; x < cs.w; x++) { + res[y][x] = ' '; + } + } + for (int y = 0; y < cs.h; y++) { + for (int x = 0; x < cs.w; x++) { + res[y][x] = update(y, x); + } + } + return ""\n"" + JamUtil.printTable(res); //To change body of implemented methods use File | Settings | File Templates. + } + + private char update(int y, int x) { + if (res[y][x] != ' ') { + return res[y][x]; + } + int min = cs.table[y][x]; + int dir = -1; + if (y > 0) { + int curr = cs.table[y - 1][x]; + if (curr < min) { + min = curr; + dir = 0; + } + } + if (x > 0) { + int curr = cs.table[y][x - 1]; + if (curr < min) { + min = curr; + dir = 1; + } + } + if (x < cs.w - 1) { + int curr = cs.table[y][x + 1]; + if (curr < min) { + min = curr; + dir = 2; + } + } + if (y < cs.h - 1) { + int curr = cs.table[y + 1][x]; + if (curr < min) { + min = curr; + dir = 3; + } + } + if (dir == -1) { + return res[y][x] = curr++; + } else { + switch (dir) { + case 0: + return res[y][x] = update(y - 1, x); + case 1: + return res[y][x] = update(y, x - 1); + case 2: + return res[y][x] = update(y, x + 1); + case 3: + return res[y][x] = update(y + 1, x); + default: + throw new RuntimeException(); + } + } + } + + @Override + JamCase parseCase(List file, int line) { + int i = line; + String firstLine = file.get(i++); + int[] pair = JamUtil.parseIntList(firstLine, 2); + WSCase cas = new WSCase(); + cas.h = pair[0]; + cas.w = pair[1]; + cas.lineCount = cas.h + 1; + cas.table = new int[cas.h][]; + for (int ih = 0; ih < cas.h; ih++) { + cas.table[ih] = JamUtil.parseIntList(file.get(i++), cas.w); + } + return cas; + } +} + +class WSCase extends JamCase { + int w, h; + int[][] table; +} +" +A21673,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class Ex2 { + + + public static void main(String[] args) throws IOException{ + String dir = System.getProperty(""user.dir""); + String lineOfText; + int T = 0; + BufferedReader input = new BufferedReader(new FileReader(dir + ""\\B-large.in"")); + BufferedWriter output = new BufferedWriter(new FileWriter(dir + ""\\B-large.out"")); + try { + + lineOfText = input.readLine(); + T = Integer.parseInt(lineOfText); + + int N=0; + lineOfText = input.readLine(); + while (lineOfText!=null) { + N++; + StringBuilder newString = new StringBuilder(); + + Pattern p = Pattern.compile(""-?\\d+""); + Matcher m = p.matcher(lineOfText); + m.find(); + int googlers = Integer.parseInt(m.group()); + m.find(); + int surprises = Integer.parseInt(m.group()); + m.find(); + int limit = Integer.parseInt(m.group()); + ArrayList points = new ArrayList(); + for(int i=0;i=2){ + for(int i=0;i=(limit+limit-1+limit-1)){ + result++; + } else if(surprises>0 && points.get(i)==(limit+limit-1+limit-2)){ + surprises--; + result++; + } else if(surprises>0 && points.get(i)==(limit+limit-2+limit-2)){ + surprises--; + result++; + } + } + } else if(limit==1){ + for(int i=0;i=(limit)){ + result++; + } + } + } else if(limit==0){ + result = googlers; + } + lineOfText = input.readLine(); + + newString.append(""Case #""+N+"": ""+result); + output.write(newString.toString()); + output.newLine(); + } + + + + + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + input.close(); + output.close(); + } + + } + +} +" +A21401,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + + +public class problem { + + public static void main(String[] args) throws IOException{ + final String filein = ""C:\\Users\\BYTE\\Downloads\\b-small-attempt0.in""; + //final String filein = ""C:\\Users\\byte\\Downloads\\NewFolder\\C-small-attempt6.txt""; + BufferedReader in = new BufferedReader(new FileReader(filein)); + + + int tests=Integer.parseInt(in.readLine()); + + int n=0,s=0,p=0,num=0; + + for(int i=0;i=p ) + num++; + else if((q+1)>=p && !((q+1)>10)) + { + num++; + sur++; + } + + } + + else if(r==1) + { + if((q+1)>=p && !((q+1)>10)) + num++; + + } + + else if(r==2) + { + if(q>=p ) + num++; + else if((q+1)>=p && !((q+1)>10)) + num++; + + else if((q+2)>=p && !((q+2)>10)) + { + num++; + sur++; + } + + } + + } + int temp =0; + + if(num<=s) temp=num; + else + temp = num-(sur-s); + + System.out.println(""Case #""+(i+1)+"": ""+temp); + num=0; + + } + } + +} +" +A20340,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2012; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * + * @author acer + */ +public class B { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + // TODO code application logic here + FileInputStream input = new FileInputStream(""input.txt""); + DataInputStream in = new DataInputStream(input); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileOutputStream output = new FileOutputStream(""output.txt""); + + int T = Integer.parseInt(br.readLine()); + + for (int i = 0; i < T; i++) { + String[] temp = br.readLine().split("" ""); + int N = Integer.parseInt(temp[0]); + int S = Integer.parseInt(temp[1]); + int P = Integer.parseInt(temp[2]); + int[] points = new int[N]; + int count = 0, scount = 0; + + for (int j = 0; j < N; j++) { + points[j] = Integer.parseInt(temp[j + 3]); + int avg = points[j] / 3; + if (points[j] % 3 == 0) { + if (avg >= P) { + count++; + } else if ((avg + 1) == P && avg != 0 && avg != 10) { + scount++; + } + } else if (points[j] % 3 == 1) { + if ((avg+1) >= P) { + count++; + } + } else if (points[j] % 3 == 2) { + if ((avg + 1) >= P) { + count++; + } else if ((avg + 2) == P && avg != 9) { + scount++; + } + } + } + if (S >= scount) { + output.write((""Case #"" + (i + 1) + "": "" + (count + scount) + ""\n"").getBytes()); + } else { + output.write((""Case #"" + (i + 1) + "": "" + (count + S) + ""\n"").getBytes()); + } + } + } +} +" +A21842,"/** + * @author Saifuddin Merchant + * + */ +package com.sam.googlecodejam.helper; + +public class StringHelper { +} +" +A21256,"import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class ProblemB { + + private void solve() { + Scanner in = new Scanner(new BufferedInputStream(System.in)); + PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); + + int T = in.nextInt(); + for (int i = 1; i <= T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int r = 0; + for (; N > 0; N--) { + int k = in.nextInt(); + if (k + 2 >= 3 * p && k >= p) { + r++; + } else if (k + 4 >= 3 * p && k >= p && S > 0) { + r++; + S--; + } + } + out.println(""Case #"" + i + "": "" + r); + } + + + out.flush(); + out.close(); + } + + public static void main(String[] args) throws IOException { + ProblemB solver = new ProblemB(); + solver.solve(); + } +} +" +A20192,"import java.util.*; +import static java.lang.Math.*; + +public class BB { + public static void main(String[] args){ + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int zz = 1; zz <= T;zz++){ + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int res = 0; + for(int i = 0; i < N;i++){ + + int t = in.nextInt(); + if(p==0){ + res++; continue; + } + if(t>=p && t>=(p*3-2)){ + res++; + } + else if(S>0 && t>=p && (t>=(p*3-4))){ + S--; + res++; + } + + } + System.out.format(""Case #%d: %d\n"", zz, res); + } + } +} +" +A21039,"package package02; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + private static void checkInputFile(String filePath) throws IOException{ + BufferedReader br=new BufferedReader(new FileReader(new File(filePath))); + PrintWriter output=new PrintWriter(filePath.concat("".out"")); + + String str=new String(); + int row=0; + + while((str=br.readLine())!=null){ + if(row!=0){ + int as=checkOneline(str); + output.println(""Case #""+row+"": ""+as); + } + row=row+1; + } + output.close(); + br.close(); + } + + private static int checkOneline(String str) { + int as=0; + int s=0; + int p=0; + int tst1=0; + int tst2=0; + + //将一行数字的字符串转为整型List; + List iLst=new ArrayList(); + int j=0; + for(int i=0;ip-3){ + tst1=tst1+1; + } + if((iLst.get(i)p-5)&&(iLst.get(i)!=0)){ + tst2=tst2+1; + } + } + //如果tst2比意外分多çš��话,就等于意外数 + if(tst2>s){ + tst2=s; + } + + as=tst1+tst2; + return as; + } + + public static void main(String args[]) throws IOException{ + Scanner scanner=new Scanner(System.in); + String inputFilePath=scanner.nextLine(); + checkInputFile(inputFilePath); + } +} +" +A22341,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.HashMap; +import java.util.Scanner; + + +public class P2 { + static Scanner sc; + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + sc = new Scanner(System.in); + + try { + sc = new Scanner(new FileInputStream(""B.in"")); + System.setOut(new PrintStream(new FileOutputStream(""B.out.txt""))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + new P2().run(); + + System.out.flush(); + } + + + public void run(){ + int T = sc.nextInt(); + + for(int t=1; t<=T;t++){ + + int R = 0; + + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + + for(int n = 0; n < N ; n++){ + int i = sc.nextInt(); + int r = i - p*2; + if(r>=0) + if(r>=p-2){ + R++; + }else if(r>=p-4 && S>0){ + S--; + R++; + } + } + + System.out.printf(""Case #%d: %d%n"", t, R); + + } + + } + +} +" +A21686,"package util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author bohmd + */ +public abstract class BaseResolver { + + private final String file; + private BufferedReader reader; + private BufferedWriter writer; + int lineNum = 0; + int caseNum = 0; + + public BaseResolver(String file) { + this.file = file; + } + + public void resolve() throws Exception { + reader = new BufferedReader(new FileReader(input())); + writer = new BufferedWriter(new FileWriter(output())); + while (reader.ready()) { + executeLine(reader.readLine()); + lineNum++; + } + reader.close(); + writer.close(); + } + + private String input() { + return file + "".in""; + } + + private String output() { + return file + "".out""; + } + + protected abstract void executeLine(String line) throws Exception; + + protected void write(String result) throws Exception { + writer.write(""Case #"" + (++caseNum) + "":"" + result); + writer.newLine(); + } + + public int getLineNum() { + return lineNum; + } +} +" +A20596,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class main { + + public static void main(String[] args) { + // inputファイルを読み込み + BufferedReader bufferReader = null; + String str = """"; + try { + bufferReader = new BufferedReader(new InputStreamReader( + new FileInputStream(""/Users/yago/Documents/in.txt""), + ""UTF-8"")); + // 一行ずつ読み込み + int probs = 0; + while ((str = bufferReader.readLine()) != null) { + if (str.length() > 3) { + probs++; + calc(str, probs); + } + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } finally { + try { + if (bufferReader != null) { + bufferReader.close(); + } + } catch (Exception e) { + } + } + } + + private static void calc(String str, int probNum) { + Integer n, s, p, Ti, ansCnt = 0; + String[] strAry = str.split("" ""); + n = Integer.valueOf(strAry[0]); + s = Integer.valueOf(strAry[1]); + p = Integer.valueOf(strAry[2]); + + for (int i = 0; i < n; i++) {// 各ダンサーについて + Ti = Integer.valueOf(strAry[3 + i]); + if (Ti >= 3 * p - 2) {// p + (p - 1) * 2 + ansCnt++; +// System.out.println(""A"" + "" "" + strAry[3 + i]); + } else if (s != 0 && Ti >= 3 * p - 4 && Ti > 0) {// p + (p - 2) * 2 + ansCnt++; + s--; +// System.out.println(""B"" + "" "" + strAry[3 + i]); + } + } + + System.out.println(""Case #"" + probNum + "": "" + ansCnt); + } +}" +A22185,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.lang.Math; +import java.util.Arrays; + +public class DancingWithTheGooglers { + public static int testSize = 0; + + public static int[] convertString2Nums(int n, String str) { + int[] result = new int[n]; + + int begIndex = 0; + int endIndex = 0; + + for(int i = 0; i < n - 1; i++) { + endIndex = str.indexOf(' ', begIndex); + result[i] = Integer.parseInt(str.substring(begIndex, endIndex)); + begIndex = endIndex + 1; + } + result[n - 1] = Integer.parseInt(str.substring(begIndex, str.length())); + return result; + } + + public static boolean isPossibleScore(int score, int P) { + if(0 == P) return true; + if(score < P) return false; + int remain = (score - P) >> 1; + if(P - remain > 1) + return false; + return true; + } + + public static boolean isSurprisePossible(int score, int P) { + if(0 == P) return true; + if(score < P) return false; + int remain = (score - P) >> 1; + if(P - remain > 2) + return false; + return true; + } + + public static int maxDancers(String input) { + int result = 0; + String[] params = input.split("" ""); + int N = Integer.parseInt(params[0]); + int S = Integer.parseInt(params[1]); + int P = Integer.parseInt(params[2]); + + int[] a = new int[N]; + int numOfSurprise = 0; + + for(int i = 0; i < N; i++) { + a[i] = Integer.parseInt(params[i + 3]); + } + + Arrays.sort(a); + for(int i = N - 1; i >= 0 ; i--) { + if(isPossibleScore(a[i], P)) { + result++; + } else { + if(numOfSurprise < S && isSurprisePossible(a[i], P)) { + result++; + numOfSurprise++; + } + } + } + /* + + int i = 0; + while(a[i] < P ) { + i++; + if(i >= N) + break; + } + + if(i == N) + return 0; + + int j = 0; + for(j = 0; j < S && j + i < N; j++) { + result ++; + } + + if(j + i < N) { + for(int k = j + i; k < N; k++) { + if(isPossibleScore(a[k], P)) + result++; + } + } + */ + return result; + } + + public static void Output(String inPath, String outPath) { + try { + FileInputStream fstream = new FileInputStream(inPath); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + File of = new File(outPath); + of.delete(); + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(outPath), true)); + + String line = br.readLine(); + + int[] parameters = convertString2Nums(1, line); + int numOfTest = parameters[0]; + + String str = new String(); + for(int i = 0; i < numOfTest; i ++) { + line = br.readLine(); + str = new String(""Case #"" + (i+1) + "": "" + maxDancers(line)); + System.out.println(str); + bw.write(str); + bw.newLine(); + } + + in.close(); + bw.close(); + } catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + //public static + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + String inFile = new String(); + String outFile = new String(); + testSize = 2; + switch(testSize) { + case 0: + inFile = new String(""./B-test.in""); + outFile = new String(""./B-test.out""); + break; + + case 1: + inFile = new String(""./B-small-attempt1.in""); + outFile = new String(""./B-small-attempt1.out""); + break; + + case 2: + inFile = new String(""./B-large.in""); + outFile = new String(""./B-large.out""); + break; + default: + break; + } + Output(inFile, outFile); + } + + +} +" +A20432,"package qr; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws FileNotFoundException { + Scanner scanner = new Scanner(new File(""B-large.in"")); + int tcn = scanner.nextInt(); + int tc = 1; + while (tc <= tcn) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + // int[] base = new int[n]; + int y = 0; + + for (int i = 0; i < n; i++) { + int t = scanner.nextInt(); + int base = t / 3; + int mmm = t % 3; + if (mmm != 0) { + base++; + } + + if (base >= p) { + if (mmm == 0 && t >= 0) + y++; + if (mmm == 1 && t >= 1) + y++; + if (mmm == 2 && t >= 2) + y++; + } else if (s > 0) { + if (base + 1 == p) { + if (mmm == 0 && t >= 3) { + y++; + s--; + } +// if (mmm == 1 && t >= 4) { +// y+=0; +// s--; +// } + if (mmm == 2 && t >= 2) { + y++; + s--; + } + + } + } + } + System.out.printf(""Case #%d: %d\n"", tc, y); + + // base >= p -> ok + // base -1 -> can be ok + + tc++; + } + + } +} +" +A20593,"import java.util.ArrayList; +import java.util.Scanner; + + +public class GooglerDancer { + + private int caseNumber; + private int numberOfGooglers; + private int numberOfSuprisingTriplets; + private int minimumBestScoreP; + private ArrayList list; + + + public GooglerDancer(int caseNumber,String data) { + + this.caseNumber=caseNumber; + Scanner s=new Scanner(data); + this.numberOfGooglers=s.nextInt(); + this.numberOfSuprisingTriplets=s.nextInt(); + this.minimumBestScoreP=s.nextInt(); + list=new ArrayList(); + while(s.hasNextInt()){ + list.add(s.nextInt()); + } + } + + + public void process() { + int count =0; + + if(numberOfGooglers>0){ + ///// + if(minimumBestScoreP>0){ + for(int i=0;i0) + { + if((Integer)(list.get(i)/minimumBestScoreP)>=3){ + count++; + } + else{ + if((Integer)(minimumBestScoreP-(list.get(i)-minimumBestScoreP)/2)==1){ + count++; + } + else{ + if((Integer)(minimumBestScoreP-(list.get(i)-minimumBestScoreP)/2)==2 && numberOfSuprisingTriplets>0){ + count++; + numberOfSuprisingTriplets--; + } + } + } + } + } + //////////// + }else{ + count=numberOfGooglers; + } + } + System.out.println(""Case #""+caseNumber+"": ""+count); + + } + +} +" +A20931,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class TestB { + private final static String DAT_PATH = ""/Users/ttsurumi/Downloads/""; + +// private final static String dat = ""A-sample-practice.in""; +// private final static String dat = ""A-small-practice.in""; + private final static String dat = ""B-large.in""; + + public static String datPath = DAT_PATH + dat; + public static String ansPath = DAT_PATH + dat + "".ans""; + /** + * @param args + */ + public static void main(String[] args) { + try{ + BufferedReader br = new BufferedReader(new FileReader(datPath)); + BufferedWriter bw = new BufferedWriter(new FileWriter(ansPath)); + String[] movCounts = br.readLine().split("" ""); + String tmp_str; + int count = 1; + while((tmp_str = br.readLine()) != null){ + String[] row = tmp_str.split("" ""); + long N = Long.parseLong(row[0]); + long s = Long.parseLong(row[1]); + long p = Long.parseLong(row[2]); + int ans = 0; +// p(""N="" + N + "", s=""+s+"", p=""+p); + for(int i = 0; i < N; i++){ + long elm = Long.parseLong(row[i + 3]); + if(check(elm, p)){ + // p(""c""+i); + ans++; + }else if(0 < s && scheck(elm, p)){ + // p(""s""+i); + ans++; + s--; + } + } +// p(""ans""+ans); + bw.write(""Case #"" + count + "": "" + ans ); + bw.newLine(); + count++; + } + bw.flush(); + }catch(IOException e){ + System.err.println(e); + } + } + private static boolean check(long elm, long max){ + if(max <= elm / 3)return true; + if(elm % 3 == 0)return false; + if(max <= elm / 3 + 1)return true; + return false; + } + private static boolean scheck(long elm, long max){ + if(elm % 3 == 0){ + if(elm != 0 && max <= elm / 3 + 1){ + return true; + } + }else if(elm %3 == 2){ + if(max <= elm / 3 + 2)return true; + } + return false; + } + private static void p(String s){ + System.out.println(s); + } +} + +" +A23090,"import java.util.Scanner; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner readStuff = new Scanner(System.in); + + int numCases, numGooglers, numSurprises, numTarget; + int scores, results = 0; + + numCases = readStuff.nextInt(); + + for (int i = 0; i< numCases; i++) { + numGooglers = readStuff.nextInt(); + numSurprises = readStuff.nextInt(); + numTarget = readStuff.nextInt(); + + for (int j=0; j= (3*numTarget - 2) && scores > 0) { + results++; + } + else if (scores >= (3*numTarget-4) && scores > 0 && numSurprises > 0) { + results++; + numSurprises--; + } + if (scores == 0 && numTarget == 0) { + results++; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + results); + results = 0; + } + } + +} +" +A20364,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Scanner; + + +public class Googlers { +public static void main(String[] args) throws Exception { + String file=""B-large.in""; + String oFile=""B-large.out""; + BufferedReader br = new BufferedReader(new FileReader(file)); + BufferedWriter bw = new BufferedWriter(new FileWriter(oFile)); + int cases = Integer.parseInt(br.readLine()); + for(int i=1; i<=cases; i++) + { + bw.write(""Case #""+i+"": ""); + String line = br.readLine(); + String[] lineElems = line.split("" ""); + int N= Integer.parseInt(lineElems[0]);//Googlers + int S= Integer.parseInt(lineElems[1]);//Surprising Scores + int p= Integer.parseInt(lineElems[2]);//P score + //here come the points + int surprises=0; + int goodlers=0; + int lim = 3*(p-2)+1; + for(int j=3; j< N+3; j++) + { + int score_i = Integer.parseInt(lineElems[j]); + + if(score_i>lim+2) + { + goodlers++; + } + if(score_i<= lim+2 && score_i>lim && score_i>1) + { + surprises++; + } + } + goodlers+=Math.min(S, surprises); + bw.write(""""+goodlers); + bw.newLine(); + } + br.close(); + bw.close(); +} +} +" +A22366,"package round0; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Dance { + BufferedReader _in; + PrintWriter _out; + + int _numTestCases; + Input[] _inputs; + + public Dance(BufferedReader in) throws Exception { + this._in = in; + this._out = new PrintWriter(""answers.out""); + } + + public void calculate() throws Exception { + this._inputs = readInputs(); + + for(int i=0; i < _inputs.length; i++) { + processInput(_inputs[i], i+1); + } + _out.flush(); + _out.close(); + } + + + private void processInput(Input input, int caseIndex) { + int maxGP = 0; + int surprisesAvailable = input.S; + for(int i=0; i < input.N; i++) { + int mp = input.tpts[i]/3; + int modulo = input.tpts[i]%3; + switch(modulo) { + case 0: + if(mp >= input.p) { + maxGP++; + } else if(mp+1 >= input.p && mp > 0 && surprisesAvailable > 0) { + maxGP++; + surprisesAvailable--; + } + break; + case 1: + if(mp+1 >= input.p) { + maxGP++; + } + break; + case 2: + if(mp+1 >= input.p) { + maxGP++; + } else if(mp+2 >= input.p && surprisesAvailable > 0) { + maxGP++; + surprisesAvailable--; + } + break; + default: + //not needed + } + + } + + _out.println(""Case #"" + caseIndex +"": "" + maxGP); + } + + private Input[] readInputs() throws Exception { + + Scanner scanner = new Scanner(_in); + _numTestCases = scanner.nextInt(); + Input[] inputs = new Input[_numTestCases]; + for(int i=0; i < _numTestCases; i++) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int [] tpts = new int[N]; + for(int j=0; j < N; j++) + tpts[j] = scanner.nextInt(); + inputs[i] = new Input(N, S, p, tpts); + } + return inputs; + } + + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(args[0])); + new Dance(in).calculate(); + } + + + private class Input { + int N; + int S; + int p; + int[] tpts; + + public Input(int N, int S, int p, int[] tpts) { + this.N = N; + this.S = S; + this.p = p; + this.tpts = tpts; + } + } +} +" +A20294,"package qualification; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class Dancing { + + public static void main(String[] s){ + doIt(); + } + + private static void doIt() { + Scanner s=null; + try {s = new Scanner(new File(""B-large.in""));} + catch (FileNotFoundException e) {e.printStackTrace();} + + PrintWriter out=null; + try {out = new PrintWriter(new FileWriter(""a.out""));} + catch (IOException e) {e.printStackTrace();} + + int cases=s.nextInt(); + + for(int idx=0;idx=targetScore) valid++; + else if(current%3!=0 && current/3+1>=targetScore) valid++; + + else if(surprising>0 && current/3+1==targetScore && current>1){ + surprising--; + valid++; + } + else if(surprising>0 && current%3==2 && current/3+2==targetScore){ + surprising--; + valid++; + } + + } + + int index=idx+1; + out.println + (""Case #""+index+"": ""+valid); + } + + + out.close(); + } +} +" +A21345,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Dancing { + private int numDancers; + private int surprising; + private int minMax; + private int[] scores; + + private int result; + + /** + * Constructor + * + * @param N + * @param S + * @param p + */ + public Dancing(int N, int S, int p, int[] data) { + numDancers = N; + surprising = S; + minMax = p; + scores = data; + result = 0; + } + + /** + * @param args + */ + public static void main(String[] args) { + try { + // Input I/O handler + File input = new File(args[0]); + Scanner sc = new Scanner(input); + int cases = Integer.parseInt(sc.nextLine()); + + // Output I/O handler + FileWriter output = new FileWriter(args[1], true); + PrintWriter pw = new PrintWriter(output); + + // Process all the cases + for (int i = 1; i <= cases; i++) { + // Get the data + String[] line = sc.nextLine().split("" ""); + int N = Integer.parseInt(line[0]); + int S = Integer.parseInt(line[1]); + int p = Integer.parseInt(line[2]); + ; + int[] scores = new int[line.length - 3]; + for (int k = 0; k < scores.length; k++) { + scores[k] = Integer.parseInt(line[k + 3]); + } + + // Solve each test case + Dancing solver = new Dancing(N, S, p, scores); + solver.solve(); + pw.println(""Case #"" + i + "": "" + solver.getResult()); + pw.flush(); + } + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * Returns the number of maximum number of Googlers who could have had a + * best result of greater than or equal to p. + * @return result + */ + public int getResult() { + return result; + } + + /** + * Perform the algorithm. + */ + private void solve() { + int currentSurp = 0; + int guarantee = minMax + Math.max(0, (minMax - 1)) + + Math.max(0, (minMax - 1)); + int minScore = minMax + Math.max(0, (minMax - 2)) + + Math.max(0, (minMax - 2)); + for (int i = 0; i < scores.length; i++) { + if (scores[i] >= guarantee) { + result++; + } else if (scores[i] >= minScore) { + if (currentSurp < surprising) { + result++; + currentSurp++; + } + } + } + } +} +" +A22719,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + */ + +/** + * @author Shweta + * + */ +public class DancingGoogler { + + /** + * @param list + * @param minimumScore + * @param numberOfSurprisingResults + */ + private List list; + private int numberOfSurprisingResults, minimumScore; + private int maxNumberOfGooglersForBestResult; + + public DancingGoogler(List list, int numberOfSurprisingResults, + int minimumScore) { + this.list = list; + Collections.sort(this.list); + this.numberOfSurprisingResults = numberOfSurprisingResults; + this.minimumScore = minimumScore; + putScores(this.list); + calculateAnswer(); + } + + /** + * + */ + private void calculateAnswer() { + for (Googler googler : this.list) { + boolean minScoreGiven = false; + for (int i = 0; i < 3; i++) { + int score = googler.getScores()[i]; + if (score >= minimumScore) { + minScoreGiven = true; + break; + } + } + if (minScoreGiven) { + maxNumberOfGooglersForBestResult++; + } else if (numberOfSurprisingResults > 0) { + if (googler.getMaxScore() > 0) { + googler.getScores()[1] = googler.getScores()[1] - 1; + googler.getScores()[2] = googler.getScores()[2] + 1; + + if (googler.getScores()[2] >= minimumScore) { + maxNumberOfGooglersForBestResult++; + numberOfSurprisingResults--; + } + } + } + } + } + + /** + * @param list2 + */ + private void putScores(List googlers) { + for (Googler googler : googlers) { + int maxScore = googler.getMaxScore(); + int[] scores = new int[3]; + int base = maxScore / 3; + scores[0] = base; + scores[1] = base; + scores[2] = base; + + if (maxScore % 3 == 1) { + scores[1] = base + 1; + } else if (maxScore % 3 == 2) { + scores[1] = base + 1; + scores[2] = base + 1; + } + + googler.setScores(scores); + } + } + + /** + * @return + */ + public int answer() { + return maxNumberOfGooglersForBestResult; + } + + public static void main(String args[]) throws Exception { + BufferedReader bufferedReader = new BufferedReader( + new FileReader( + new File( + ""C:\\Documents and Settings\\Kamlesh\\Desktop\\codejam\\B-large.in""))); + int numberOfTest = Integer.valueOf(bufferedReader.readLine()); + for (int i = 1; i <= numberOfTest; i++) { + String line = bufferedReader.readLine(); + String tokens[] = line.split(""\\ ""); + int n = Integer.valueOf(tokens[0]); + int surprizingTriplets = Integer.valueOf(tokens[1]); + int minimumScore = Integer.valueOf(tokens[2]); + List list = new ArrayList(); + for (int j = 1; j <= n; j++) { + int maxScore = Integer.valueOf(tokens[2 + j]); + Googler googler = new Googler(maxScore); + list.add(googler); + } + DancingGoogler dc = new DancingGoogler(list, surprizingTriplets, + minimumScore); + + System.out.println(""Case #"" + i + "": "" + dc.answer()); + + } + } + +} +" +A20386,"import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + + +public class B { + public static void main(String ... args) throws Exception{ + Scanner in = new Scanner(new File(""B-large.in"")); + PrintStream out = new PrintStream(new File(""B-large.out"")); + + int[] max1 = new int[31]; + int[] max2 = new int[31]; + max1[0] = 0; + max2[0] = 0; + + max1[1] = 1; + max2[1] = 1; + + max1[2] = 1; + max2[2] = 2; + + max1[3] = 1; + max2[3] = 2; + + max1[4] = 2; + max2[4] = 2; + + max1[5] = 2; + max2[5] = 3; + + max1[6] = 2; + max2[6] = 3; + + max1[7] = 3; + max2[7] = 3; + + max1[8] = 3; + max2[8] = 4; + + max1[9] = 3; + max2[9] = 4; + + max1[10] = 4; + max2[10] = 4; + + max1[11] = 4; + max2[11] = 5; + + max1[12] = 4; + max2[12] = 5; + + max1[13] = 5; + max2[13] = 5; + + max1[14] = 5; + max2[14] = 6; + + max1[15] = 5; + max2[15] = 6; + + max1[16] = 6; + max2[16] = 6; + + max1[17] = 6; + max2[17] = 7; + + max1[18] = 6; + max2[18] = 7; + + max1[19] = 7; + max2[19] = 7; + + max1[20] = 7; + max2[20] = 8; + + max1[21] = 7; + max2[21] = 8; + + max1[22] = 8; + max2[22] = 8; + + max1[23] = 8; + max2[23] = 9; + + max1[24] = 8; + max2[24] = 9; + + max1[25] = 9; + max2[25] = 9; + + max1[26] = 9; + max2[26] = 10; + + max1[27] = 9; + max2[27] = 10; + + max1[28] = 10; + max2[28] = 10; + + max1[29] = 10; + max2[29] = 10; + + max1[30] = 10; + max2[30] = 10; + + int T = in.nextInt(); + in.nextLine(); + + for(int t=0;t=p?1:0; + cnt2+= max2[num]>=p?1:0; + } + cnt1 += Math.min(cnt2-cnt1, S); + out.println(""Case #"" + (t+1) + "": "" + cnt1); + } + + + } +} +" +A20645," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Scanner; +import java.util.Arrays; + +/** + * + * @author CuteCoke + */ +public class B { + //final String TASK_NAME = ""B-small-attempt2""; + final String TASK_NAME = ""B-large""; + //final String TASK_NAME = ""sample""; + final String IN_FILE = TASK_NAME+"".in""; + final String OUT_FILE = TASK_NAME+"".out""; + + public int solve(int N, int S, int p, int[] t){ + int res = 0; + + for(int i=0; i=(p*3-2)){ + res++; + }else if (t[i]>=2 && t[i]>=(p*3-4) && S>0){ + res++; + S--; + } + } + return res; + } + + public void doMain() throws Exception{ + try{ + + Scanner sc1 = null; + BufferedReader br = new BufferedReader(new FileReader(IN_FILE)); + BufferedWriter bw = new BufferedWriter(new FileWriter(OUT_FILE)); + + int T = Integer.parseInt(br.readLine()); + + for (int a=0; a=pMinNoSurprised) + googlers++; + else if(score[i]>=pMinSurprised) + nbSurprised++; + } + if(nbSurprised>S) + googlers+=S; + else + googlers+=nbSurprised; + int z = zz+1; + answers[zz]=""Case #""+z+"": ""+googlers+""\n""; + + } + + + + + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + + try + { + PrintWriter pw = new PrintWriter(out); + for(int i=0;i= p) { + result++; + } + if (Googlers[i].best == (p-1) && Googlers[i].remainder != 1 && Googlers[i].total != 0 && Googlers[i].total != 29 && Googlers[i].total != 30) { + count++; + } + } + + if (count >= S) { + result += S; + } + else { + result += count; + } + + return result; + } +} + +class Googler { + int total; + int remainder; + int best; + + public Googler(int total) { + this.total = total; + this.remainder = total % 3; + int n = total / 3; + switch (remainder) { + case 0: best = n; break; // This is an intermediate value. + case 1: best = n + 1; break; + case 2: best = n + 1; break; // So is this. + } + } +} +" +A21082,"package com.google.cj12; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +class Dancing { + + public static void main(String[] args) throws IOException { + BufferedReader f = new BufferedReader(new FileReader(""resources/B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter( + ""resources/B-large.out""))); + new Dancing().solve(f, out); + out.close(); + } + + private void solve(BufferedReader f, PrintWriter out) throws IOException { + int T = read(f); + for (int i=0; i= p) { + count++; + continue; + } + + if (S == 0 || t<2 || t%3==1) continue; + + max = t%3==0? base+1 : base+2; + if (max >= p) { + count++; + S--; + } + } + + out.println(""Case #"" + (i+1) + "": "" + count); + } + } + + public int read(BufferedReader f) throws IOException { + return Integer.parseInt(f.readLine()); + } +} +" +A20642,"import java.util.*; +import java.io.*; +import java.lang.*; + +class DancingGooglers { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = Integer.parseInt(sc.nextLine()); + + for (int i=0; i g = new ArrayList(); + for (int j=0; j 10) continue; + if (Math.abs(a-b) > 2 || Math.abs(b-c) > 2 || Math.abs(a-c) > 2) continue; + if (Math.abs(a-b) == 2 || Math.abs(b-c) == 2 || Math.abs(a-c) == 2) { + // surprising + bestSurprising = Math.max(bestSurprising, Math.max(a, Math.max(b, c))); + } else { + // no + bestNonSurprising = Math.max(bestNonSurprising, Math.max(a, Math.max(b, c))); + } + } + } + g.add(new Googler(bestNonSurprising, bestSurprising)); + } + + Collections.sort(g); + //for (int k=0; k= p) { taken[k] = true; count++; } + } + int countsurprise = 0; + for (int k=0; k= p) { taken[k] = true; count++; countsurprise++; } + } + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } +} + +class Googler implements Comparable { + int bns = 0, bs = 0; // Best Non, Best Surprising + Googler(int a, int b) { bns = a; bs = b; } + + public int compareTo(Googler g) { + if (this.bs != g.bs) return g.bs - this.bs; + return this.bns - g.bns; + } +} + + + +" +A22790,"package google.loader; + +import java.util.List; + +public interface ChallengeReader { + + + List createChallenges(String[] lines); + +} +" +A22711," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Dancing +{ + + static int n; + static int[] score; + + static int solve( int surp, int p ) + { + int notPossible = 0; + int cutOff = 3*p - 4; + int surCutOff = 3*p-2; + + + Arrays.sort( score ); + + if( p == 0 ) + return n; + + if( p==1 ) // only score of zero is invalid + { + for( int i=0; i 0 ) + { + surp--; + continue; + } + + else + { + notPossible++; + } + } + + else if( score[ i ] >= surCutOff ) + { + break; + } + + + + else + break; + + } + + + return n-notPossible; + + } + + public static void main( String[] args ) throws IOException + { + FileWriter fr= new FileWriter(""/home/gowri/Desktop/out.txt""); + BufferedWriter out = new BufferedWriter( fr ); + BufferedReader br = new BufferedReader( new InputStreamReader( System.in )); + int T = Integer.parseInt( br.readLine() ); + String s; + StringTokenizer tok; + + for( int i=0; i= p ){ + abovep++; + }else { + if(sur > 0){ + maxpos = maxp(sc[i], true); + //wasSurpr = wasS(sc[i]); + if(maxpos >= p){ + abovep++; + sur--; + } + } + } + // System.out.println(sc[i]+"" max ""+maxpos); + // System.out.println("" abovep ""+abovep+"" sur ""+sur); + + } + return abovep; + } + + public static void main(String args[]){ + + Scanner s = new Scanner(System.in); + int T = s.nextInt(); + + for(int i = 1; i<=T; i++){ + int n = s.nextInt(); + int sur = s.nextInt(); + int p = s.nextInt(); + int sc[] = new int[n]; + for(int j = 0; j= p){ + count++; + continue; + } + + if (uses < S){ + if (a[2] == a[1] && a[1] !=0) + if (a[2]+1 >= p){ + count++; + uses++; + } + + } + + } + + pw.println(""Case #""+(i+1)+"": ""+count); + } + + + + pw.flush();; + pw.close(); + + + } +} +" +A21853,"import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.Writer; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + private String mInputFileName; + private String mOutputFileName; + + private int N; + private int S; + private int P; + private int[] mScores; + + public DancingWithTheGooglers(String inputFileName, String outputFileName) { + mInputFileName = inputFileName; + mOutputFileName = outputFileName; + } + + public void solve() { + long start = System.currentTimeMillis(); + Scanner scanner = null; + try { + scanner = new Scanner(new FileReader(mInputFileName)); + Writer output = new BufferedWriter(new FileWriter(mOutputFileName)); + int cases = scanner.nextInt(); + for (int i = 1; i <= cases; i++) { + N = scanner.nextInt(); + S = scanner.nextInt(); + P = scanner.nextInt(); + mScores = new int[N]; + for (int j = 0; j < N; j++) { + mScores[j] = scanner.nextInt(); + } + System.out.println(""CASE: "" + i + "" / "" + cases); + if (i > 1) output.write(""\n""); + output.write(""Case #"" + i + "": ""); + output.write(getAnswer()); + } + output.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (scanner != null) scanner.close(); + } + System.out.println(""TIME: "" + (System.currentTimeMillis() - start)); + } + + private String getAnswer() { + int res = 0; + for (int j = 0; j < N; j++) { + int score = mScores[j]; + int q = score / 3; + int r = score % 3; + int noSup = q; + int sup = q; + if (score > 0) { + switch (r) { + case 0: + sup++; + break; + case 1: + noSup++; + sup++; + break; + case 2: + noSup++; + sup += 2; + break; + } + } + + if (noSup >= P) { + res++; + } else if (S > 0 && sup >= P) { + res++; + S--; + } + } + //System.out.println(res); + return """" + res; + } + + public static void main(String[] args) { + String fileName = ""test""; + String extension = "".txt""; + String outputSuffix = ""_output""; + new DancingWithTheGooglers(fileName + extension, + fileName + outputSuffix + extension).solve(); + } + +} +" +A22070,"package hk.polyu.cslhu.codejam.lib; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; + +public class ResultCollector { + public static Logger logger = Logger.getLogger(ResultCollector.class); + public static String IndexPartInRow = ""%i""; + public static String ResultPartInRow = ""%r""; + + private Map> resultMap; + private String resultFile, resultPattern; + private int amountOfTestCases, numOfProcessedTestCases; + + /** + * Constructs a instance of result collector + * + * @param amountOfTestCases int The amount of test cases + * @param resultFile String The location of result file + */ + public ResultCollector(int amountOfTestCases, String resultFile, String resultPattern) { + this.resultMap = new HashMap> (); + this.resultFile = resultFile; + this.resultPattern = resultPattern; + this.amountOfTestCases = amountOfTestCases; + this.numOfProcessedTestCases = 0; + } + + /** + * update the result stored in the object + * + * @param partIndex int The part index of result + * @param partOfResult List The part of result + */ + public synchronized void updateResult(int partIndex, List partOfResult) { + // add the part of result + if (this.resultMap.containsKey(partIndex)) { + logger.error(""Failure to add the part of result with part index "" + partIndex); + } else { + this.resultMap.put(partIndex, partOfResult); + this.numOfProcessedTestCases += partOfResult.size(); + + logger.info(""The #"" + partIndex + "" is completed!""); + } + + // trigger the save method when all test cases are processed + if (this.numOfProcessedTestCases == this.amountOfTestCases) + this.save(); + else if (this.numOfProcessedTestCases > this.amountOfTestCases) + logger.error( + ""The number of processed test cases is more than the amount of test cases ("" + + this.numOfProcessedTestCases + "" > "" + + this.amountOfTestCases + "")""); + } + + /** + * Save the result in the given file + * + * @param filePath String The location of file to be saved + */ + private void save() { + // constructs the content + String content = this.constructTheContent(); + FileStream.save(this.resultFile, content); + + logger.info(""The result of all test cases is saved with the path "" + this.resultFile); + } + + /** + * Construct the content to be saved + * + * @return String The content of file + */ + private String constructTheContent() { + // TODO Auto-generated method stub + String content = """"; + int rowIndex = 1; + + // sort the key of result map + List keySet = new LinkedList(this.resultMap.keySet()); + Collections.sort(keySet); + + + for (Integer key : keySet) { + List resultList = this.resultMap.get(key); + + for (String result : resultList) { + String rowContent = this.resultPattern.replaceAll(IndexPartInRow, String.valueOf(rowIndex)).replaceAll(ResultPartInRow, result); + content += rowContent; + rowIndex++; + } + } + + return content; + } +} +" +A21614,"import java.util.Scanner; + +public abstract class Question extends Thread{ + + protected Result result; + protected Counter counter; + + public Question(Result result, Counter counter) + { + super(); + this.result = result; + this.counter = counter; + } + + public abstract void readInput(Scanner scanner); + + public void solveTestCase(){ + setResult(solution()); + } + + public abstract String solution(); + + public String getResult() { + return result.output; + } + + public void setResult(String output) { + this.result.output = output; + } + + public void run() { + solveTestCase(); + //System.out.println(result); + counter.increase(); + } +} +" +A21499,"package com.wenod.googlerese.main; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +public class GooglereseConverter { + + public static void main(String arg[]) throws NumberFormatException, + IOException { + + FileInputStream inputreader = new FileInputStream(""B-large.in""); + + DataInputStream in = new DataInputStream(inputreader); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + String strLine; + + int input = Integer.parseInt(br.readLine()); + + for (int k = 0; k < input; k++) { + strLine = br.readLine(); + String[] values = strLine.split("" ""); + + int numberOfGooglers = Integer.parseInt(values[0]); + + int numberOfSurprisingTriplets = Integer.parseInt(values[1]); + int numberOfSurprized = 0; + int resultLimit = Integer.parseInt(values[2]); + + System.out.print(numberOfGooglers + "" "" + + numberOfSurprisingTriplets + "" "" + resultLimit + "" --> ""); + + int numberOfBestResult = 0; + PrintWriter output = new PrintWriter(new BufferedWriter( + new FileWriter(""output.txt"", true))); + output.write(""Case #"" + (k + 1) + "": ""); + for (int i = 0; i < numberOfGooglers; i++) { + int val = Integer.parseInt(values[i + 3]); + System.out.print(val + "" ""); + + int testingValue = ((resultLimit * 2) - (val - resultLimit)); + if (val >= ((testingValue * 3) - 4)) { + if (testingValue == 4 || testingValue == 3) { + if (numberOfSurprized < numberOfSurprisingTriplets) { + numberOfSurprized++; + numberOfBestResult++; + } + } else if (testingValue < 3) { + numberOfBestResult++; + } + } + + } + System.out.println("" --> "" + numberOfBestResult); + output.write(Integer.toString(numberOfBestResult)); + output.println(); + output.close(); + } + + in.close(); + + } +} +" +A22578,"import java.io.IOException; +import java.util.Scanner; + +public class DancingWithTheGooglers { + public static void main(String[] args) throws IOException { + Scanner scan = new Scanner(System.in); + int T = scan.nextInt(); + + int counter = 1; + while (T-- > 0) { + int returned = 0; + int N = scan.nextInt(); + int surp = scan.nextInt(); + int theMax = scan.nextInt(); + double[] array = new double[N]; + for (int i = 0; i < array.length; i++) { + array[i] = scan.nextDouble(); + } + for (int i = 0; i < array.length; i++) { + if (Math.ceil((double) array[i] / 3) >= theMax) { + returned++; + } else if (array[i] >= theMax) { + double temp = array[i] - theMax; + double first = theMax; + double second = Math.ceil((double) temp / 2); + double third = temp - second; + + double diff1 = Math.abs(first - second); + double diff2 = Math.abs(second - third); + double diff3 = Math.abs(first - third); + + if (diff1 <= 2 && diff2 <= 2 && diff3 <= 2) { + if (diff1 == 2 || diff2 == 2 || diff3 == 2) { + if (surp > 0 + && (first >= theMax || second >= theMax || third >= theMax)) { + surp--; + returned++; + } + } + } + } + } + System.out.println(""Case #"" + counter++ + "": "" + returned); + } + } +}" +A21684,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +public class B implements CodeJamCaseSolver { + + int n, s, p; + int[] t; + + @Override + public void input(Scanner in) { + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + t = new int[n]; + for(int i=0;i 0) + allowed = v/3+1; + else + allowed = notallowed; + } else if(v%3 == 1) { + notallowed = v/3+1; + allowed = v/3+1; + } else { + notallowed = v/3+1; + if(v/3+1 > 0) + allowed = v/3+2; + else + allowed = notallowed; + } + if(notallowed >= p) { + count++; + } else if(allowed >= p && remains > 0) { + count++; + remains--; + } + } + return count + """"; + } + + public static void main(String[] args) throws Exception { + CodeJamSolver.launch(8, ""B-example.in"", new CodeJamCaseSolverFactory() { + @Override + public CodeJamCaseSolver createSolver() { + return new B(); + } + }); + } + +} +interface CodeJamCaseSolver { + void input(Scanner in); + String solve(); +} +interface CodeJamCaseSolverFactory { + CodeJamCaseSolver createSolver(); +} +class CodeJamSolver { + + public static void launch(int threadNumber, String inputFileNameOnDesktop, CodeJamCaseSolverFactory factory, Integer... caseNumbers) throws Exception { + if(!inputFileNameOnDesktop.endsWith("".in"")) + throw new RuntimeException(""input filename should ends with '.in'""); + String outputFileNameOnDesktop = inputFileNameOnDesktop.substring(0, inputFileNameOnDesktop.length()-3) + "".out""; + String desktopDir = System.getProperty(""user.home"") + ""/Desktop""; + String inputFile = desktopDir + ""/"" + inputFileNameOnDesktop; + String outputFile = desktopDir + ""/"" + outputFileNameOnDesktop; + launch(inputFile, outputFile, threadNumber, factory, caseNumbers); + } + + private static void launch(String inputFilePath, String outputFilePath, final int threadNumber, final CodeJamCaseSolverFactory factory, Integer... caseIndices) throws Exception { + final Object lock = new Object(); + final long startTime = System.currentTimeMillis(); + final Scanner in = new Scanner(new File(inputFilePath)); + final int casen = in.nextInt(); + final int[] nextIndex = {0}; + final String[] results = new String[casen]; + final Set caseIndexToSolve = createCaseIndicesToSolve(casen, caseIndices); + ExecutorService executor = Executors.newFixedThreadPool(threadNumber); + for(int i=0;i createCaseIndicesToSolve(int casen, Integer... caseIndices) { + final Set set = new TreeSet(); + if(caseIndices.length == 0) { + for(int i=1;i<=casen;i++) + set.add(i); + } else { + for(int v : caseIndices) { + if(v < 1 || v > casen) + throw new RuntimeException(""invalid index : "" + v); + set.add(v); + } + } + return set; + } + + private static void printLine() { + for(int i=0;i<100;i++) + System.out.print(""-""); + System.out.println(); + } + + private static int countNotNull(final String[] results) { + int solved = 0; + for(String s : results) + if(s != null) + solved++; + return solved; + } + + private static void outputProgess(long startTime, int solved, int caseNumberToSolve) { + long duration = System.currentTimeMillis() - startTime; + long estimation = (long)Math.round((double)duration * caseNumberToSolve / solved / 1000); + System.out.printf(""%.03fs : %d/%d solved (estimated : %dm %ds)\n"", (double)duration / 1000, solved, caseNumberToSolve, estimation / 60, estimation % 60); + } + + private static void outputResult(final String[] results, String outputFilePath) throws FileNotFoundException { + PrintStream ps = new PrintStream(outputFilePath); + for(int i=0;i=val1){ + count++; + } + } + //System.out.println(num); + return count; + } + else{ + int count=0; + int val1 = 3*p-2; + int val2 = 3*p-4; + for(int i=0; i=val1){ + count++; + } + else if(scores[i]=val2){ + if(num>0){ + count++; + num--; + } + } + } + return count; + } + + } + +} +" +A21778,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package javaapplication6; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author ucho + */ +public class JavaApplication6 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + PrintWriter writer = new PrintWriter(new FileWriter(""output"")); + Scanner scanner = new Scanner(new FileReader(""input"")); + int tests = scanner.nextInt(); + scanner.nextLine(); + for(int t=0;t= passingScore) { + if ((score + 2) / 3 >= passingScore) { + ok++; + } else { + if ((score + 4) / 3 >= passingScore) { + conditionalOk++; + } + } + } + } + String msg = ""Case #""+(t+1)+"": ""+(ok+Math.min(conditionalOk, sup)); + System.out.println(msg); + writer.println(msg); + scanner.nextLine(); + } + writer.close(); + } +} +" +A23046,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + + +public class ProblemB { + public static void main(String[] args) throws NumberFormatException, IOException{ + + BufferedReader reader=new BufferedReader(new FileReader(new File(args[0]))); + + int numTestCases=Integer.parseInt(reader.readLine()); + + String[] split; + + for (int testCase=0; testCase28) + b=-1; + else + b=(curr+4)/3; + + if (a>=p) + res++; + else if (s>0&&b>=p){ + res++; + s--; + } + } + + System.out.println(""Case #""+(testCase+1)+"": ""+res); + } + } +} +" +A22535,"package commons; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +public class FileUtilities { + + public static void writeFile(List strings, File file) + throws IOException { + + file.createNewFile(); + FileWriter writer = new FileWriter(file); + + for (int i = 1; i <= strings.size(); i++) { + writer.write(""Case #""); + writer.write(i + "": ""); + writer.write(strings.get(i-1)); + writer.write(""\n""); + } + + writer.close(); + } + + public static List readFile(File file) throws IOException { + + BufferedReader reader = new BufferedReader(new FileReader(file)); + + String input = reader.readLine(); + List result = new LinkedList(); + + while (!(input == null)) { + result.add(input); + input = reader.readLine(); + } + + reader.close(); + + return result; + } +} +" +A21980,"import java.util.*; + +class B{ + public static void main(String... arg){ + Scanner sc = new Scanner(System.in); + + int cases = sc.nextInt(); + + for(int caseNo = 1; caseNo <= cases; caseNo++ ){ + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + int[] t = new int[N]; + int n = 0; + for(int i = 0; i < N; i++) + t[i] = sc.nextInt(); + if(p == 0) + System.out.println(""Case #"" + caseNo + "": "" + N); + else{ + for(int i = 0; i < N; i++){ + int tmp = ((int)(t[i]/3)); + if(t[i] == 0) tmp = 0; + else{ + if(t[i] % 3 != 0) tmp = tmp + 1; + } + if(tmp >= p) n++; + } + if (S == 0) + System.out.println(""Case #"" + caseNo + "": "" + n); + else{ + Arrays.sort(t); + for(int i = N-n-1; i >= 0 && S > 0; i--){ + int tmp = ((int)(t[i]/3)); + if(t[i] == 0) tmp = 0; + else{ + int rem = t[i] % 3; + if(rem == 2 && t[i] <= 28) tmp = tmp + 2; + else if(rem == 0 && t[i] <= 29) tmp = tmp + 1; + else continue; + } + if(tmp >= p) { n++; S--; } + } + System.out.println(""Case #"" + caseNo + "": "" + n); + } + } + } + } +}" +A20969,"import java.awt.image.BufferStrategy; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Scanner; + + +public class DancingGooglers { + public static void main(String[] args) { + File file = new File(""C:\\Users\\aadi\\Desktop\\DancingGooglers\\B-small-attempt0.in""); + try{ + FileWriter fstream = new FileWriter(""C:\\Users\\aadi\\Desktop\\DancingGooglers\\out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + Scanner scanner = new Scanner(file); + int numOfCases = Integer.parseInt(scanner.nextLine()); + for(int i =0 ;i< numOfCases ; i++){ + int sCount= 0; + int non_sCount = 0; + String line = scanner.nextLine(); + Scanner scanner2 = new Scanner(line); + scanner2.useDelimiter("" ""); + int n = scanner2.nextInt(); + int s = scanner2.nextInt(); + int p = scanner2.nextInt(); + while(scanner2.hasNext()){ + int tot = scanner2.nextInt(); + if(tot>=Math.max((p*3-2), 0)){ + non_sCount++; + }else if(tot>=(p + Math.max((p-2),0) + Math.max((p-2),0)) ){ + sCount++; + } + } + out.write(""Case #""+(i+1)+"": ""); + if(sCount0){return (p+1);}else{return p;}}}} + + public static int solution(int x, int[] p,int s){ + int sur=s; int ans=0; + for(int k=0;k=x){ans++;} + else{ + if(sur>0){if(surprise(p[k])>=x){ + ans++;sur--;}else{}}else{}} + } + return ans;} + public static void main(String[] args) throws IOException{ + Scanner c = new Scanner(System.in); + int times=c.nextInt(); + for(int p=0;p cases = new ArrayList(); + int makesit = 0; + int needsSurp = 0; + + public DancingWithTheGooglers() { + + + + + + + try { + // Setup in/out + System.setIn(new FileInputStream(""C:\\GCJ\\B-large.in"")); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new FileWriter(""C:\\GCJ\\B-large.out"")); + bw.flush(); + + + + int untill = Integer.parseInt(br.readLine()); + + for (int t = 1; t <= untill; t++) { + + String[] ins = br.readLine().split("" ""); + int n = Integer.parseInt(ins[0]); // number of googlers + int s = Integer.parseInt(ins[1]); // number of surpirsing trips + int p = Integer.parseInt(ins[2]); // min points + int[] ti = new int[n]; + for (int i = 3; i < n + 3; i++) { + ti[i - 3] = Integer.parseInt(ins[i]); + } + for (int m = 0; m < ti.length; m++) { + doMath(ti[m], p); + } + + int ans = makesit; + if (s < needsSurp) { + ans += s; + } else { + ans += needsSurp; + } + + + String out = ""Case #"" + t + "": "" + ans; + + cases.add(out); + makesit = 0; + needsSurp = 0; + + } + + for (String s : cases) { + System.out.println(s); + bw.write(s); + bw.flush(); + bw.newLine(); + } + + } catch (IOException ex) { + System.out.println(""SOMETHING WENT WRONG""); + } + } + + public void doMath(int number, int p) { + int start = 10; + boolean done = false; + while (true) { + if (start + start + start == number) { + if (start >= p) { + makesit++; + done = true; + break; + } + break; + } + if (start + start + start - 1 == number) { + if (start >= p) { + makesit++; + done = true; + break; + } + break; + } + if (start + start - 1 + start - 1 == number) { + if (start >= p) { + makesit++; + done = true; + break; + } + break; + } + start--; + } + if (!done) { + start = 10; + while (true) { + if (start == 1) { + break; + } + if (start + (start - 1) + (start - 2) == number) { + if (start >= p) { + needsSurp++; + break; + } + break; + } + if (start + (start - 2) + (start - 2) == number) { + if (start >= p) { + needsSurp++; + break; + } + break; + } + start--; + + } + } + + } + + public static void main(String[] args) { + new DancingWithTheGooglers(); + + } +} +" +A21033,"package dancing; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class Dance +{ + + public static void main(String[] args) throws Exception + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int count = Integer.parseInt(br.readLine()); + + for(int i = 0;i < count;i++) + { + String[] info = br.readLine().split("" ""); + int n = Integer.parseInt(info[0]); + int s = Integer.parseInt(info[1]); + int p = Integer.parseInt(info[2]); + + int[] scores = new int[n]; + for(int j = 0;j < n;j++) + scores[j] = Integer.parseInt(info[3 + j]); + + int maxCount = 0; + + int minS = p + 2 * (p - 2); + int minN = p + 2 * (p - 1); + + //System.out.println(minS + "" "" + minN); + + for(int score : scores) + { + if(score == 0 && p != 0) + continue; + + if(score >= minN) + { + maxCount++; + continue; + } + + if(score >= minS && s > 0) + { + maxCount++; + s--; + continue; + } + } + + System.out.println(""Case #"" + (i + 1) + "": "" + maxCount); + } + } + +} +" +A22865,"import java.io.File; +import java.util.*; + + +public class Googlers { + public static void main(String[] args) throws Throwable{ + Scanner scan = new Scanner(new File(""in_b"")); + scan.nextLine(); + + int l = 1; + while(scan.hasNextLine()){ + String[] line = scan.nextLine().split("" ""); + int surprise = Integer.valueOf(line[1]); + int p = Integer.valueOf(line[2]); + int min = (p * 3) - 2; + int sup = min - 2; + + int ok = 0; + for(int i = 3; i < line.length ; i++){ + int score = Integer.valueOf(line[i]); + if(p == 1){ + if(score == 0){ + continue; + } + } + if(score >= min){ + ok++; + continue; + } + if(score >= sup){ + if(surprise > 0){ + ok++; + surprise--; + } + } + + } + System.out.println(""Case #"" + l + "": "" + ok); + l++; + } + } +} +" +A21429,"package run; +import java.io.*; + +public class Main +{ + public static void main(String args[]) throws IOException + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String s = br.readLine(); + int n = Integer.parseInt(s); + for(int i = 1;i<=n;i++) + { + s = br.readLine(); + String []s_arr = s.split("" ""); + + int n_googler = Integer.parseInt(s_arr[0]); + int n_surprise = Integer.parseInt(s_arr[1]); + int threshold = Integer.parseInt(s_arr[2]); + int number = 0; + for(int j = 0;j=1) + number++; + } + + else if(threshold*3-2<=score) + { + number++; + } + + else if(threshold*3-4<=score&&n_surprise>0) + { + number++; + n_surprise--; + } + else + continue; + } + + System.out.println(""Case #"" + i + "": "" + number); + } + } +} +" +A21516," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.Integer; +import java.util.ArrayList; + +class jam1a { + public static void main(String[] args) { + BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in)); + try { + String s = bufferRead.readLine(); + int testCases=Integer.parseInt(s); + ArrayList sars = new ArrayList(); + for(int i=0; i< testCases; i++){ + s = bufferRead.readLine(); + sars.add(s); + } + System.out.println(""\n""); + + for(int j=0; j nums = new ArrayList(); + for(int i=3; i numbers){ + if(p==0) return numbers.size(); + int ret=0; + for (int i=0; i0 ) continue; + float avg=(float)tempNum/3; + float tempRem=tempNum-p; + boolean okNoSuprise=false; + if(tempRem%2==0){ + int tempVal=(int) (tempRem/2); + if((tempVal+1)>=p) { + okNoSuprise=true; + } + }else{ + int tempForDiv=(int) (tempRem-1); + int val1=(int) (tempForDiv/2); + if((val1+1)>=p){ + okNoSuprise=true; + } + } + if((avg)>=p) ret++; + else if(okNoSuprise) ret++; + else if( surprises > 0){ + if(tempRem%2==0){ + int tempVal=(int) (tempRem/2); + if((tempVal+2)>=p) { + ret++; + surprises--; + } + }else{ + int tempForDiv=(int) (tempRem-1); + int val1=(int) (tempForDiv/2); + int val2=val1+1; + if((val1+2)>=p){ + ret++; + surprises--; + } + } + } + } + return ret; + } + +}" +A22873,"package codejam20120413; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.*; + +public class B { + + void run()throws IOException{ + BufferedReader bf = new BufferedReader(new FileReader(""B.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""B.out"")); + + int cases = Integer.parseInt(bf.readLine()); + for (int i=0; ip*3-3) + count++; + else + if ((p*3-3 > 0) && (score==p*3-3 || score==p*3-4) && S-->0) + count++; + + } + + pw.write(""Case #""+ (i+1) + "": ""+ count + ""\n""); + } + pw.close(); + } + + public static void main(String[] args)throws IOException { + new B().run(); + } + + +} +" +A20448,"package codejam.suraj.quals2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public abstract class CodeJamSkeleton { + // To Read Input file + private BufferedReader fileReader = null; + private BufferedWriter fileWriter = null; + private StringBuffer output = null; + + public CodeJamSkeleton() + { + this.output = new StringBuffer(); + } + + public CodeJamSkeleton(String inputFilename, String outputFilename) + throws IOException { + super(); + try{ + fileReader = + new BufferedReader(new FileReader(inputFilename)); + } + catch(IOException e) + { + System.err.println(""Could not read from file.""); + e.printStackTrace(); + throw e; + } + try{ + fileWriter = new BufferedWriter( + new FileWriter(outputFilename)); + }catch(IOException e) + { + System.err.println(""Error opening output file.""); + System.err.println(""Output = "" + output.toString()); + throw e; + } + + this.output = new StringBuffer(); + } + + + /* + * This method return next non empty line until it encounters + * the end of file + */ + protected String readLine() throws IOException + { + String line = null; + do{ + line = fileReader.readLine(); + if(line != null) + { + if(line.trim().equals("""")) + continue; + else + return line; + } + }while(line != null); + return line; + } + + + protected void addOutput(int testCaseNumber, String outputText) + { + output.append(""Case #"" + testCaseNumber + "": "" + outputText + ""\n""); + } + + protected void writeOutput() throws IOException + { + try{ + System.out.println(output); + fileWriter.write(output.toString()); + fileWriter.flush(); + }catch(IOException e) + { + System.err.println(""Error writing in output file.""); + System.err.println(""Output = "" + output.toString()); + throw e; + } + + try{ + + fileWriter.close(); + }catch(IOException e) + { + System.err.println(""Error closing output file.""); + System.err.println(""Output = "" + output.toString()); + throw e; + + } + } + + protected abstract void handleTestCase(int testCaseNumber) + throws IOException; + + protected void iterateTestCase() throws IOException + { + String currentLineRead = readLine(); + int numCases = Integer.parseInt(currentLineRead.trim()); + + for(int i = 0; i < numCases; i++) + { + handleTestCase(i+1); + } + + } + + public void handleAllTestCases(String inputFilename, String outputFilename) + + { + try{ + fileReader = + new BufferedReader(new FileReader(inputFilename)); + } + catch(IOException e) + { + System.err.println(""Could not read from file.""); + e.printStackTrace(); + System.exit(1); + } + try{ + fileWriter = new BufferedWriter( + new FileWriter(outputFilename)); + }catch(IOException e) + { + System.err.println(""Error opening output file.""); + System.err.println(""Output = "" + output.toString()); + System.exit(1); + } + try{ + iterateTestCase(); + writeOutput(); + } + catch(IOException e) + { + e.printStackTrace(); + System.exit(1); + } + + + } + + + +} +" +A22368,"import java.io.*; +import java.util.*; + +public class Main { +// static Scanner in; static int next() throws Exception {return in.nextInt();}; + static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;} + static PrintWriter out; + static String NAME = ""b""; + + public static void main(String[] args) throws Exception { +// in = new Scanner(new File(NAME + "".in"")); + out = new PrintWriter(new File(NAME + "".out"")); + in = new StreamTokenizer(new BufferedReader(new FileReader(new File(NAME + "".in"")))); + + int tests = next(); + int inf = 1000000; + + for (int test = 1; test <= tests; test++) { + int n = next(); + int s = next(); + int p = next(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) t[i] = next(); + + int[][] max = new int[n + 1][n + 1]; + for (int[] mm : max) Arrays.fill(mm, -inf); + max[0][0] = 0; + + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + if (t[i] <= (p - 1) * 3) max[i + 1][j] = Math.max(max[i + 1][j], max[i][j]); + if (2 <= t[i] && t[i] <= (p - 1) * 3 - 2) max[i + 1][j + 1] = Math.max(max[i + 1][j + 1], max[i][j]); + if (p + 2*Math.max(p - 2, 0) <= t[i] && t[i] <= 28) max[i + 1][j + 1] = Math.max(max[i + 1][j + 1], max[i][j] + 1); + if (3*p - 2 <= t[i]) max[i + 1][j] = Math.max(max[i + 1][j], max[i][j] + 1); + } + + out.print(""Case #"" + test + "": ""); + out.println(max[n][s]); + + } + + out.close(); + } +}" +A22042,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; + +/** + * + * @author Aymen + */ +public class main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + + int[] v = new int[1000]; + int[] tabMin = new int[100]; + + String outputFile = System.getenv(""USERPROFILE"") + ""\\Documents\\B-large.out""; + String inputFile = System.getenv(""USERPROFILE"") + ""\\Documents\\B-large.in""; + //String outputFile = System.getenv(""USERPROFILE"") + ""\\Documents\\output.txt""; + //String inputFile = System.getenv(""USERPROFILE"") + ""\\Documents\\input.txt""; + + BufferedWriter os = new BufferedWriter(new FileWriter(outputFile)); + DataInputStream is = new DataInputStream(new FileInputStream(inputFile)); + + int T = Integer.valueOf(is.readLine()); + System.out.println(""T "" + T); + for (int i = 0; i < T; i++) { + String list = is.readLine(); + list += "" ""; + int n = Integer.valueOf(list.substring(0, list.indexOf("" ""))); + list = list.substring(list.indexOf("" "") + 1); + int s = Integer.valueOf(list.substring(0, list.indexOf("" ""))); + list = list.substring(list.indexOf("" "") + 1); + int p = Integer.valueOf(list.substring(0, list.indexOf("" ""))); + list = list.substring(list.indexOf("" "") + 1); + int valMin = 3 * p - 4; + if (valMin < 0) s = 0; + int number = 0; + int surp = 0; + + for (int j = 0; j < s; j++) { + tabMin[j] = 0; + } + + for (int j = 0; j < n; j++) { + int val = Integer.valueOf(list.substring(0, list.indexOf("" ""))); + if (val >= valMin){ + if ((val == valMin) || (val == valMin + 1)){ + surp += 1; + if (surp <= s){ + number += 1; + } + }else number += 1; + } + list = list.substring(list.indexOf("" "") + 1); + } + + + + int m = i + 1; + System.out.println(""number "" + number); + os.write(""Case #"" + m + "": "" + number); + os.newLine(); + System.out.println(""""); + } + is.close(); + os.close(); + } +} +" +A20903,"package jam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Map; +import java.util.TreeMap; + +public class Jam2 { + + public static void main(String[] args) throws Exception { + + BufferedReader reader = new BufferedReader(new FileReader(""C:/jam/input.txt"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""C:/jam/output.txt"")); + int nr = new Integer(reader.readLine()); + int[] normal = new int[11]; + int[] sup = new int[11]; + for (int i = 0; i < 11; i++) { + normal[i] = 3 * i - 2; + sup[i] = 3 * i - 4; + } + normal[0] = 0; + sup[0] = 0; + sup[1] = 1; + + for (int i = 0; i < nr; i++) { + String in = reader.readLine(); + String data1[] = in.split("" ""); + Integer data2[] = new Integer[data1.length]; + for (int t = 0; t < data1.length; t++) { + data2[t] = Integer.parseInt(data1[t]); + } + int N = data2[0]; + int S = data2[1]; + int p = data2[2]; + + int mayNormal = 0; + int maySup = 0; + // System.out.println(""normal[p] = "" + normal[p]); + // System.out.println(""sup[p] = "" + sup[p]); + for (int j = 0; j < N; j++) { + int test = data2[3+j]; + // System.out.println(""test = "" + test); + + if(test >= normal[p]){ + mayNormal++; + }else if (test >= sup[p]){ + maySup++; + } + } + // System.out.println(""mayNormal = "" + mayNormal); + // System.out.println(""maySup = "" + maySup); + + int out = mayNormal + Math.min(maySup, S); + System.out.println(""out = "" + out); + writer.write(""Case #""+(i+1)+"": ""+out); + writer.newLine(); + + } + writer.close(); + } +} +" +A22175,"import java.util.Scanner; + + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int nbr_case = scan.nextInt(); + for(int i = 0; i < nbr_case; i++) + { + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int possible_max = 0; + int curr =0; + //int[] vec = new int[N]; + for( int j = 0; j 0) + { + if(curr > (p*3 - 3) && (curr >= p)) + { + possible_max++; + } + else + { + if(curr > (p*3-5) && (curr >= p)) + { + possible_max++; + S--; + } + + } + + } + else + { + + if(curr > (p*3 - 3) && (curr >= p)) + { + possible_max++; + } + + } + + + //vec[j] = scan.nextInt(); + } + //System.out.println(vec.toString()); + System.out.format(""Case #%d: %d\n"", i+1, possible_max); + } + + + } + +} +" +A21161,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class Dancing { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader (""data/input"")); + PrintWriter pw = new PrintWriter(new FileWriter(""data/output"")); + int lines = Integer.parseInt(br.readLine()); + for(int j = 0; j < lines; j++){ + String sol = ""Case #"" + (j+1) + "": ""; + StringTokenizer st = new StringTokenizer(br.readLine()); + int googlers = Integer.parseInt(st.nextToken()); + int surprising = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int googlerOK = 0; + while(st.hasMoreElements()){ + int score = Integer.parseInt(st.nextToken()); + int value = score/3; + int mod = score%3; + if(score == 0){ + if(p==0){ + googlerOK++; + } + }else if(value >= p || (mod > 0 && value+1>=p)){ + googlerOK++; + }else if(mod == 2 && value+2 >= p && surprising > 0){ + surprising--; + googlerOK++; + }else if(mod < 2 && value+1 >= p && surprising > 0){ + surprising--; + googlerOK++; + } + } + pw.println(sol + """"+ googlerOK); + } + pw.close(); + + } + +} +" +A21098,"package fr.diodfr.y2012.qual; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +public class Exo2 { + private Scanner fileScanner; + private Scanner lineScanner; + private int numberOfCase; + + public Exo2(String fileName) { + try { + fileScanner = new Scanner(new BufferedReader(new FileReader(fileName))); + numberOfCase = fileScanner.nextInt(); + nextLine(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public int getNumberOfCase() { + return numberOfCase; + } + + public boolean hasNextLine() { + return fileScanner.hasNextLine(); + } + + public void nextLine() { + String nextLine = fileScanner.nextLine(); +// System.out.println(""Exo2.nextLine():"" + nextLine); + lineScanner = new Scanner(nextLine); + } + + public boolean hasNext() { + return lineScanner.hasNext(); + } + + public String next() { + return lineScanner.next(); + } + + public int nextInt() { + return lineScanner.nextInt(); + } + + public void close() { + if (lineScanner != null) { + lineScanner.close(); + } + fileScanner.close(); + } + + + private void computeCase(String outPutFileName) throws IOException { + BufferedWriter file = new BufferedWriter(new FileWriter(outPutFileName)); + + for (int i = 0; i < numberOfCase; i++) { + nextLine(); + int result = getResult(); + + file.append(""Case #"" + (i + 1) + "": "" + result); + System.out.println(""Case #"" + (i + 1) + "" : "" + result); + file.newLine(); + } + file.close(); + } + + private int getResult() { + int numberCount = nextInt(); + int numberSurprisingTriplet = nextInt(); + int p = nextInt(); + int numbers[] = new int[numberCount]; + + for (int i = 0; i < numberCount; i++) { + numbers[i] = nextInt(); + } + + return dancing(numberCount, numberSurprisingTriplet, p, numbers); + } + + private int dancing(int numberCount, int numberSurprisingTriplet, int p, int[] numbers) { + int result = 0; + int currentSurprising = 0; + int smallSurprising = Math.max(p*3-4, 0); + int smallNumber = Math.max(p*3-2, 0); + + for (int i = 0; i < numbers.length; i++) { + if (numbers[i] <= p && p!=0) { + } else if (numbers[i] >= smallNumber) { + result++; + } else if (numbers[i] >= smallSurprising) { + currentSurprising++; + } + } + + return result + Math.min(numberSurprisingTriplet, currentSurprising); + } + + public static void main(String[] args) { + + Exo2 exo = new Exo2(""/home/didier/Téléchargements/B-small-attempt1.in""); + + try { + exo.computeCase(""/home/didier/Téléchargements/B-small-attempt1.out""); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A22553,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + + +public class DancingWiththeGooglers { + public static void main(String[] args){ + Scanner in; + try { + in = new Scanner(new File(""B-large.in"")); + solve(in); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + public static void solve(Scanner in){ + int caseNum = in.nextInt(); + for(int i =1; i<=caseNum; i++){ + int googlers = in.nextInt(); + int surpising = in.nextInt(); + int p = in.nextInt(); + int ans =0; + ArrayList scores = new ArrayList(); + for(int j =0; j=p*3-2){ + ans++; + } + else{ + int two = p*3-4; + if(score<4){ + two+=(4-score); + } + if(score>=two){ + + if(surpising>0){ + ans++; + surpising--; + } + } + } + + } + System.out.println(""Case #"" +i+"": ""+ans); + + } + } +} +" +A20408,"package MyAllgoritmicLib; + +public class Sort { + public static int partition(int[] m, int a, int b) { + int i = a; + for (int j = a; j <= b; j++) // ïðîñìàòðèâàåì ñ a ïî b + { + if (m[j] >= m[b]) // åñëè ýëåìåíò a[j] íå ïðåâîñõîäèò + // a[b], + { + int t = m[i]; // ìåíÿåì ìåñòàìè a[j] è a[a], a[a+1], a[a+2] è + // òàê äàëåå... + m[i] = m[j]; // òî åñòü ïåðåíîñèì ýëåìåíòû ìåíüøèå a[b] â + // íà÷àëî, + m[j] = t; // à çàòåì è ñàì a[b] «ñâåðõó» + i++; // òàêèì îáðàçîì ïîñëåäíèé îáìåí: a[b] è a[i], ïîñëå ÷åãî + // i++ + } + } + return i - 1; // â èíäåêñå i õðàíèòñÿ <íîâàÿ ïîçèöèÿ ýëåìåíòà a[b]> + 1 + } + + public static void quicksort(int[] m, int a, int b) // a - íà÷àëî ïîäìíîæåñòâà, + // b - + // êîíåö + { // äëÿ ïåðâîãî âûçîâà: a = 0, b = <ýëåìåíòîâ â ìàññèâå> - 1 + if (a >= b) + return; + int c = partition(m, a, b); + quicksort(m, a, c - 1); + quicksort(m, c + 1, b); + } +} +" +A20034,"package com.code; + +import java.io.BufferedReader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class DancingWithGooglers +{ + public static void main(String[] args) + { + ReadWriteInputFile readObj = new ReadWriteInputFile(); + BufferedReader br = null; + Writer outWriter = null; + int caseNo = 0,i=0; + + String strLine=""""; + br = readObj.readInputFile(""B-large.in""); + outWriter = readObj.writeOutputFile(""output.txt""); + if(br!=null || outWriter!=null) + { + try + { + caseNo = Integer.parseInt(br.readLine()); + while ((strLine = br.readLine()) != null) + { + String[] splitStr = strLine.split("" ""); + int N=Integer.parseInt(splitStr[0]),S=Integer.parseInt(splitStr[1]) , p=Integer.parseInt(splitStr[2]); + int validCount=0; + ArrayList totalScores = new ArrayList(); + for (int j = 3; j < splitStr.length; j++) + { + totalScores.add(splitStr[j]); + } + for(int j=0;j=p) + validCount++; + else if((q+1)>=p && S!=0 && q!=0) + { + validCount++;S--; + } + } + if(r==1) + { + if((q+1)>=p) + validCount++; + } + if(r==2) + { + if((q+1)>=p) + validCount++; + else if((q+2)>=p && S!=0) + { + validCount++;S--; + } + } + } + outWriter.write(""Case #""+(++i)+"": ""+validCount+""\n""); + } + + } + catch (Exception e) + { + e.printStackTrace(); + } + readObj.closeObjects(outWriter); + } + } +} + + +/* + + + for(int j=0;j= P) { + greater++; + } else { + if (score % 3 == 0 && score != 0) { + + if ( score / 3 + 1 >= P && S > 0) { + S--; + greater++; + } + } else if (score != 0) { + if ( score / 3 + 1 >= P) { + greater++; + } else if ( score / 3 < P && score / 3 + 2 >= P && S > 0) { + S--; + greater++; + } + } else if (P == 0) { + greater++; + } + } + } + return greater; + } + + public static void main(String[] args) throws Exception { + + Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(""output.out""); + + int[] googler = new int[100]; + int testCases = Integer.parseInt(in.next()); + int count = 0; + while (in.hasNext()) { + count++; + int N = Integer.parseInt(in.next()); + int S = Integer.parseInt(in.next()); + int P = Integer.parseInt(in.next()); + + for (int i = 0; i < N; i++) { + googler[i] = Integer.parseInt(in.next()); + } + int greater = solve(N, S, P, googler); + out.printf(""Case #%d: %d\n"", count, greater); + + } + + out.close(); + in.close(); + } +} +" +A20784,"import java.io.*; +/** + * + * @author ankush + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args)throws IOException { + //System.out.println(Math.floor(Math.log10(11))); + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + int t=Integer.parseInt(br.readLine()); + int ans[]=new int[t]; + for(int i=0;i=0 && Math.abs(a-b)<2 && Math.abs(a-c)<2 && Math.abs(c-b)<2) + { + max=Math.max(a, b); + max=Math.max(max,c); + if(max >= p && pos[j]!=1) + { + count++; + pos[j]=1; + // System.out.println(arr[j]+"" ""+a+"" ""+b+"" ""+c); + a=100;b=100; + break; + } + } + } + } + if(a==11) + { + for(a=p;a<11;a++) + { + for(b=0;b<11;b++) + { + c=(arr[j]-a-b); + if(c>=0 && Math.abs(a-b)<3 && Math.abs(a-c)<3 && Math.abs(c-b)<3) + { + max=Math.max(a, b); + max=Math.max(max,c); + if(max >= p && s>0 && pos[j]!=1) + { + s--; + count++; + pos[j]=1; + // System.out.println(arr[j]+"" ""+a+"" ""+b+"" ""+c+"" ""+s); + a=11;b=11; + break; + } + } + } + } + } + + }/* + if(s>0) + { + for(int j=0;j=0 && Math.abs(a-b)==2 || Math.abs(a-c)==2 || Math.abs(c-b)==2) + { + max=Math.max(a, b); + max=Math.max(max,c); + if(max >= p && pos[j]==1) + { + s--; + // System.out.println(arr[j]+"" ""+a+"" ""+b+"" ""+c); + a=100;b=100; + break; + } + } + } + } + } + } + }*/ + ans[i]=count; + //System.out.println(x+"" ""+ans[i]+"" ""+s); + + } + for(int i=0;i= lowUn) answer++; + else if (points[j] >= lowSu) possible++; + } + + answer += Math.min(possible, s); + System.out.println(""Case #""+i+"": ""+answer); + } + } + + public static int lowestUnsurprising(int p) { + return p + (Math.max(p-1, 0))*2; + } + + public static int lowestSurprising(int p) { + return p + (Math.max(p-2, 0))*2; + } +} +" +A21294,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + + +public class Driver { + + + public static void main(String[] args) { + DeTerminator testBed = new DeTerminator(); + try{ + FileInputStream filestream = new FileInputStream(""test.txt""); + DataInputStream input = new DataInputStream(filestream); + BufferedReader buffer = new BufferedReader(new InputStreamReader(input)); + String currentLine; + int counter = 1; + int j = Integer.parseInt(buffer.readLine()); + for(int i = 0; i < j; i++){ + currentLine = buffer.readLine(); + String delimiter = "" ""; + String[] temp; + temp = currentLine.split(delimiter); + System.out.println(""Case #"" + counter + "": "" + testBed.determine(temp)); + counter++; + } + input.close(); + + } + catch (Exception e){ System.err.println(""Error: "" + e.getMessage()); } + } + +} +" +A21766,"import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithTheGooglers { + private static Scanner scan; + private static PrintWriter writer; + private static File input = new File(""B-large.in""); + private static File output = new File(""B-large.out""); + + public static void main(String[] args) throws Exception { + scan = new Scanner(input); + writer = new PrintWriter(output); + int total = scan.nextInt(); + int n, s, p, sum[]; + for (int t = 1; t <= total; t++) { + n = scan.nextInt();// googler's number + s = scan.nextInt();// surprising + p = scan.nextInt();// min_score + sum = new int[n]; + for (int i = 0; i < sum.length; i++) + sum[i] = scan.nextInt(); + int maximum = 0; + for (int score : sum) { + int part = score / 3; + switch (score % 3) { + case 0: + if (part >= p) { + maximum++; + } else if (s > 0 && part > 0 && part + 1 >= p) { + maximum++; + s--; + } + break; + case 1: + if (part >= p || part + 1 >= p) { + maximum++; + } else if (s > 0 && part + 1 >= p) { + maximum++; + s--; + } + break; + case 2: + if (part + 1 >= p || part >= p) { + maximum++; + } else if (s > 0 && part + 2 >= p) { + maximum++; + s--; + } + break; + } + } + println(String.format(""Case #%d: %d"", t, maximum)); + } + writer.flush(); + } + + public static void println(String p) { + System.out.println(p); + writer.println(p); + } +} +" +A22345,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.Arrays; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + try{ + // Open the file that is the first + // command line parameter + + FileInputStream fstream = new FileInputStream(""B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileOutputStream ostream = new FileOutputStream(""Output.txt""); + DataOutputStream out = new DataOutputStream(ostream); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); + + int count = Integer.parseInt(br.readLine()); + for (int i = 0; i < count; i++) { + String lineString = br.readLine(); + String [] arrayLineString = lineString.split("" ""); + int googlersCount = Integer.parseInt(arrayLineString[0]); + + if (googlersCount > 0 && googlersCount <= 100); + else break; + + int surprisingResultsCount = Integer.parseInt(arrayLineString[1]); + + if (surprisingResultsCount >= 0 && surprisingResultsCount <= googlersCount); + else break; + + int maxNumber = Integer.parseInt(arrayLineString[2]); + + if (maxNumber >= 0 && maxNumber <= 10); + else break; + + int maxSumForSurprisngResults = maxNumber + (maxNumber - 2) * 2; + if (maxSumForSurprisngResults >=2); + else maxSumForSurprisngResults = 2; + + int maxSumForNormalResults = maxNumber + (maxNumber - 1) * 2; + + int scoresArray [] = convertArrayStringToNumbers(arrayLineString, googlersCount); + + Arrays.sort(scoresArray); + int answerCount = 0; + for (int j = (scoresArray.length - 1); j >= 0; j--){ + if (scoresArray[j] >= 0 && scoresArray[j] <= 30); + else break; + + if (scoresArray[j] >= maxSumForNormalResults){ + answerCount++; + } + else if (scoresArray[j] >= maxSumForSurprisngResults){ + if (surprisingResultsCount > 0){ + surprisingResultsCount--; + answerCount++; + } + else break; + } + else break; + } + bw.write(""Case #"" + (i+1) + "": "" + answerCount); + bw.newLine(); + bw.flush(); + + } + //Close the input stream + in.close(); + out.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + private static int [] convertArrayStringToNumbers(String[] arrayLineString, int count) { + // TODO Auto-generated method stub + int array [] = new int[count]; + for (int i = 3; i < arrayLineString.length; i++){ + array[i-3] = Integer.parseInt(arrayLineString[i]); + } + return array; + } + +} +" +A21375,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public class Qualification_B { + + private static final boolean DEBUG = false; + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + + List input = readFile(args[0]); + int testCases = Integer.parseInt(input.get(0)); + String outputFilename = args[0].substring(0, args[0].length() - 2) + ""out""; + + FileOutputStream output = new FileOutputStream(outputFilename); + + try { + for (int i = 1; i <= testCases; i++) { + + String[] oneTest = input.get(i).split("" ""); + int noOfGooglers = Integer.parseInt(oneTest[0]); + int noOfSurprising = Integer.parseInt(oneTest[1]); + int minPoint = Integer.parseInt(oneTest[2]); + + int[] googlerMarks = new int[noOfGooglers]; + for (int j = 0; j < noOfGooglers; j++) { + googlerMarks[j] = Integer.parseInt(oneTest[3 + j]); + } + + if (DEBUG) { + debug(""Test Case: "" + i); + debug(""===============""); + debug(input.get(i)); + } + int result = getResult(noOfGooglers, noOfSurprising, minPoint, googlerMarks); + + outputResult(output, i, String.valueOf(result)); + } + } finally { + + if (output != null) { + output.close(); + } + } + } + + private static int getResult(final int noOfGooglers, + final int noOfSurprising, final int minPoint, + final int[] googlerMarks) { + + int result = 0; + int remainSurprising = noOfSurprising; + Arrays.sort(googlerMarks); + int minValue = 0; + int maxValue = 0; + int modValue = 0; + + for (int i = 0; i < noOfGooglers; i++) { + minValue = googlerMarks[i] / 3; + modValue = (minValue == 0)? googlerMarks[i] : googlerMarks[i] % 3; + if (minValue > 0) { + maxValue = (modValue == 0)? minValue : minValue + 1; + } else { + maxValue = 1; + } + + maxValue = (maxValue > googlerMarks[i])? minValue : maxValue; + + if (DEBUG) { + debug(""No: "" + noOfGooglers); + debug(""Surprise: "" + remainSurprising); + debug(""MinPoint: "" + minPoint); + debug(""Mark: "" + googlerMarks[i]); + debug(""Min: "" + minValue + "" - "" + ""Max: "" + maxValue); + debug(""Mod: "" + modValue); + } + +// if (maxValue >= minPoint) { +// debug(""Meet: "" + googlerMarks[i]); +// result++; +// } else { +// if (remainSurprising > 0 && maxValue < googlerMarks[i]) { + if (modValue > 0) { + if (minValue >= minPoint) { +// debug(""Meet: "" + googlerMarks[i]); + result++; + } else if ((modValue == 1) && (minValue + modValue) == minPoint) { +// debug(""Meet: "" + googlerMarks[i]); + result++; + } else if ((modValue == 2) && (minValue + 1) >= minPoint) { +// debug(""Meet: "" + googlerMarks[i]); + result++; + } else if ((remainSurprising > 0) && (minValue + modValue) >= minPoint) { +// debug(""Meet *: "" + googlerMarks[i]); + remainSurprising--; + result++; + } else { +// debug(""Does not meet""); +// debug(""No: "" + noOfGooglers); +// debug(""Surprise: "" + remainSurprising); +// debug(""Mark: "" + googlerMarks[i]); +// debug(""Min: "" + minValue + "" - "" + ""Max: "" + maxValue); + } + } else { + if (minValue >= minPoint) { +// debug(""Meet: "" + googlerMarks[i]); + result++; + } else if (remainSurprising > 0 && minValue > 0 && (minValue + 1) == minPoint) { +// debug(""Meet *: "" + googlerMarks[i]); + remainSurprising--; + result++; + } else { +// debug(""Does not meet""); +// debug(""No: "" + noOfGooglers); +// debug(""Surprise: "" + remainSurprising); +// debug(""Mark: "" + googlerMarks[i]); +// debug(""Min: "" + minValue + "" - "" + ""Max: "" + maxValue); + } + } +// } +// } + } + + return result; + } + + public static List readFile(String filename) throws IOException { + + List lines = new ArrayList(); + BufferedReader reader = new BufferedReader(new InputStreamReader( + new FileInputStream(filename))); + + try { + String data; + while ((data = reader.readLine()) != null) { + lines.add(data); + } + } finally { + reader.close(); + } + + return lines; + } + + private static void outputResult(FileOutputStream output, int caseNo, String result) throws IOException { + output.write(String.format(""Case #%d: %s\r\n"", caseNo, result).getBytes()); +// debug(String.format(""Case #%d: %s\r\n"", caseNo, result)); + } + + private static void debug(String debug) { + System.out.print(debug + ""\r\n""); + } +} +" +A22276,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + +public class DancingGooglers +{ + String line=""Code Jam""; + static int noOfTCs; + + public static void main(String[] args) + { + //initialize(); + new DancingGooglers().calculate(); + //generateOPFile(); + } + + private void calculate() + { + try + { + BufferedReader br = new BufferedReader(new FileReader(""C:/CodeJam/B-large.in"")); + FileWriter fw = new FileWriter(""C:/CodeJam/B-large-output.txt""); + BufferedWriter bw = new BufferedWriter(fw); + line = br.readLine().trim(); + noOfTCs = Integer.parseInt(line); + int dancers,surprises,maxScore; + for(int testCase=0;testCase=maxScore) + maxDancers++; + else if(rem == 0 && result > 0 && (result+1)>=maxScore && surprises > 0) + { + maxDancers++; + surprises--; + } + } + else + { + if((1+result) >= maxScore) + { + maxDancers++; + } + else + { + if(surprises > 0 && (rem+result) >= maxScore) + { + maxDancers++; + surprises--; + } + } + } + + } + + line = ""Case #""+(testCase+1)+"": ""+maxDancers; + System.out.println(line); + bw.write(line); + bw.newLine(); + } + br.close(); + bw.close(); + System.out.println(""Done !""); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + /*static void generateOPFile() + { + try + { + FileWriter fw = new FileWriter(""C:/CodeJam/output.txt""); + BufferedWriter bw = new BufferedWriter(fw); + for(int i=1;i<=noOfTCs;i++) + { + line = ""Case #""+i+"": ""+1; + bw.write(line); + bw.newLine(); + } + bw.close(); + } + catch(Exception e) + { + e.printStackTrace(); + } + }*/ + + /*static void initialize() + { + try + { + BufferedReader br = new BufferedReader(new FileReader(""C:/CodeJam/C-small.in"")); + line = br.readLine().trim(); + noOfTCs = Integer.parseInt(line); + br.close(); + + } + catch(Exception e) + { + e.printStackTrace(); + } + }*/ +} +" +A20052,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancingwiththegooglers; + +import java.util.*; +import java.io.*; +/** + * Google Code Jam 2012 + * Problem B. Dancing With the Googlers + * @author STEVEN GANTENG + * step.v4n@gmail.com + */ +public class DancingWithTheGooglers { + + public static int cases; + public static String result=""""; + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + try { + FileInputStream fin = new FileInputStream(""B-large-in.txt""); + FileOutputStream fout = new FileOutputStream(""B-large.out""); + Scanner source = new Scanner(fin); + cases = source.nextInt(); + Double t[] = new Double[100]; + int count=0; + int a=1; + for (int j=0;j=p) + { + count++; + } + else if (tmp[k]==0) + { + if (p>0) + { + + } + } + else if ((tmp[k]-p)>-0.7) + { + count++; + } + else if ((tmp[k]-p)>-1.34) + { + if (S==0) + { + + } + else if (S!=0) + { + count++; + S-=1; + } + } + + //System.out.print(tmp[k]+"" ""); + } + System.out.println(); + result += ""Case #""+a+"": ""+count+""\n""; + a++; + fout.write(result.getBytes()); + result=""""; + count=0; + System.out.println(); + + } + } catch (IOException e) + { + + } + //System.out.print(0/3); + } +} +" +A22098,"package org.rudy.cj2012; + +import java.io.*; +import java.util.Scanner; + +/** + * User: rudy + */ +public class Dancing { + public static void main(String[] args) throws FileNotFoundException { + Scanner scanner = new Scanner(new BufferedInputStream(new FileInputStream(""B-large.in""))); + PrintStream out = new PrintStream(new FileOutputStream(""B-large.out"")); + int nTests = scanner.nextInt(); + for (int test = 1; test <= nTests; test++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int [] t = new int[n]; + int potential = 0; + int already = 0; + for (int f = 0; f < n; f++) { + t[f] = scanner.nextInt(); + int minScore = (t[f]+2) / 3; + int maxScore = (t[f]+4) / 3; + if (minScore >= p) { + already++; + continue; + } + if (maxScore >=p && t[f] > 1) + potential++; + } + + out.printf(""Case #%d: %d\n"", test, already + Math.min(potential, s)); + } + out.close(); + } +} +" +A20888,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; + +public class B { + + public static void readFile() throws FileNotFoundException { + File f = new File(""B-large.in""); + Scanner in = new Scanner(f); + PrintWriter out = new PrintWriter(new File(""B-large"")); + + int T, S, p, N; + + T = in.nextInt(); + //System.out.println(T); + + ArrayList L = new ArrayList(); + int found, q, r; + + for (int i = 0; i < T; i++) { + found = 0; + N = in.nextInt(); + //System.out.print(N + "" ""); + S = in.nextInt(); + //System.out.print(S + "" ""); + p = in.nextInt(); + //System.out.println(p); + + int[] totalPoints = new int[N]; + + for (int j = 0; j < N; j++) { + totalPoints[j] = in.nextInt(); + q = totalPoints[j] / 3; + r = totalPoints[j] % 3; + // //System.out.println(q + ""--"" + r); + if (r == 0) + L.add(new int[] { q, q, q }); + else if (r == 1) + L.add(new int[] { q, q, q + 1 }); + else + L.add(new int[] { q, q + 1, q + 1 }); + + int lastIndex = L.size() - 1; + + if (L.get(lastIndex)[0] >= p || L.get(lastIndex)[1] >= p + || L.get(lastIndex)[2] >= p) { + //System.out.println(""1111111111""); + found++; + continue; + } else { + if (L.get(lastIndex)[0] + L.get(lastIndex)[1] + + L.get(lastIndex)[2] < 3 * p - 4) { + //System.out.println(""2222222222""); + continue; + } + if (S > 0 && q > 1) { + //System.out.println(""333333333333""); + L.get(lastIndex)[1]--; + L.get(lastIndex)[2]++; + S--; + found++; + } + } + + } + //System.out.println(""Found : "" + found); + if (i < T - 1) + out.println(""Case #""+ (i + 1) + "": "" + found); + else + out.print(""Case #""+ (i + 1) + "": "" + found); + } + + // //System.out.println(L.get(3)[0]); + + out.close(); + } + + public static void main(String[] args) throws FileNotFoundException { + readFile(); + + } + +} +" +A22159,"/** + * Created by IntelliJ IDEA. + * User: SONY + * Date: 19.02.12 + * Time: 13:12 + * To change this template use File | Settings | File Templates. + */ + +import java.io.*; +import java.util.*; + +import static java.lang.Math.*; + +public class Main extends Thread { + public Main(String inputFileName, String outputFileName) { + try { + this.input = new BufferedReader(new FileReader(inputFileName)); + this.output = new PrintWriter(outputFileName); + this.setPriority(Thread.MAX_PRIORITY); + } catch (Throwable e) { + System.err.println(e.getMessage()); + e.printStackTrace(); + System.exit(666); + } + } + + final int doit2() throws Throwable { + int N = nextInt(), S = nextInt(), p = nextInt(); + int t[] = new int[N]; + for (int i = 0; i < N; ++i) t[i] = nextInt(); + int[][] dp = new int[N + 1][S + 2]; + for (int i = 0; i < N; ++i) { + for (int j = 0; j <= Math.min(S, i); ++j) { + int act = t[i]; + if (act >= 3 * p - 2) { + dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + 1); + } else { + dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j]); + } + if (act >= 2 && act <= 28) { + dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j]); + if (act >= Math.max(p, 3 * p - 4)) { + dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + 1); + } + } + } + } + return dp[N][S]; + } + + final String doit(int ID) throws Throwable { + return String.format(""Case #%d: %d"", ID, doit2()); + } + + + private void solve() throws Throwable { + int testCases = nextInt(); + for (int i = 1; i <= testCases; ++i) { + output.println(doit(i)); + } + } + + public void run() { + try { + solve(); + } catch (Throwable e) { + System.err.println(e.getMessage()); + e.printStackTrace(); + System.exit(666); + } finally { + output.close(); + } + } + + public static void main(String... args) { + new Main(""input.txt"", ""output.txt"").start(); + } + + private int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + private double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + private long nextLong() throws IOException { + return Long.parseLong(next()); + } + + private String next() throws IOException { + while (tokens == null || !tokens.hasMoreTokens()) { + tokens = new StringTokenizer(input.readLine()); + } + return tokens.nextToken(); + } + + private StringTokenizer tokens; + private BufferedReader input; + private PrintWriter output; +} +" +A21363,"import java.util.Scanner; +import java.io.*; + +public class Google3 { + public static void main(String[] args) throws IOException { + Scanner kb = new Scanner(new File(""c:/input.in"")); +// Scanner kb = new Scanner(System.in); + int numCase = kb.nextInt(); + for (int i = 0; i < numCase; i++) { + int numGoogler = kb.nextInt(); + int numSurprising = kb.nextInt(); + int p = kb.nextInt(); + int minSurprising = (p * 3) - 4; + int minOrdinary = (p * 3) - 2; + if (p == 0 || p == 1) { + minSurprising = p; + minOrdinary = p; + } + int count = 0; + int countSurprising = 0; + for (int j = 0; j < numGoogler; j++) { + int point = kb.nextInt(); + if (point < minSurprising); + else if (point >= minOrdinary) { + count++; + } + else if (point >= minSurprising && point <= minOrdinary && countSurprising < numSurprising) { + count++; + countSurprising++; + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + count); + } + } +} + +" +A22850,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class QualificationB { + + public static void main(String[] args) { + File file = new File(""D:/CodeJam/B-large.in""); + StringBuffer contents = new StringBuffer(); + BufferedReader reader = null; + + try { + reader = new BufferedReader(new FileReader(file)); + String text = null; + + int row = 0; + // repeat until all lines is read + while ((text = reader.readLine()) != null) { + //contents.append(text).append(System.getProperty(""line.separator"")); + if(row == 0) + System.out.println(text); + else{ + String[] textArr = text.split("" ""); + int s = Integer.parseInt(textArr[1]); + int p = Integer.parseInt(textArr[2]); + int savePoint = (p*3)-2; + int surprisePoint = savePoint-2; + if(savePoint < p) + savePoint = p; + if(surprisePoint < p) + surprisePoint = p; + int sure = 0; + int notsure = 0; + for(int i=3; i= savePoint) + sure++; + else if(Integer.parseInt(textArr[i]) >= surprisePoint) + notsure++; + } + if(notsure > s) + sure += s; + else + sure += notsure; + + contents.append(""Case #""+row+"": ""+sure). + append(System.getProperty(""line.separator"")); + } + row++; + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + // show file contents here + System.out.println(contents.toString()); + + try{ + // Create file + FileWriter fstream = new FileWriter(""D:/CodeJam/B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + out.write(contents.toString()); + //Close the output stream + out.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A22813,"import java.io.*; +import java.util.*; + +public class b { + + public static void main(String[] args) { + + Scanner fin = new Scanner(System.in); + + int numCases = fin.nextInt(); + + for (int loop=1; loop<=numCases; loop++) { + + int numPeople = fin.nextInt(); + int numSurprise = fin.nextInt(); + int threshold = fin.nextInt(); + + int safe = 0; + int surprise = 0; + int lost = 0; + int either = 0; + + for (int i=0; i= 2) { + + if (next >= 3*threshold - 2) + safe++; + else if (next >= 3*threshold - 4) + surprise++; + else + lost++; + } + else { + if (threshold == 0) + safe++; + else { + if (next >= 1) + safe++; + else + lost++; + } + + } + } + + System.out.println(""Case #""+loop+"": ""+(safe+Math.min(surprise, numSurprise))); + } + } +}" +A21486,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class dancers { + + + + + public static void main(String[] args) throws FileNotFoundException { + + File myFile = new File (""E:/GoogleIn.txt""); + Scanner inFile = new Scanner (myFile); + PrintWriter outputStream = null; + outputStream = new PrintWriter(""E:/GoogleOut.txt""); + + String line = inFile.nextLine(); + System.out.println(""line ""+line); + int cases = Integer.parseInt(line); + System.out.println(""cases ""+cases); + for (int t=0; t < cases; t++){ + + int numdancing = inFile.nextInt(); + System.out.println(""numdancing ""+numdancing); + int outlier = inFile.nextInt(); + System.out.println(""outlier ""+outlier); + int p = inFile.nextInt(); + System.out.println(""p ""+p); + int p3 = p*3; + int cnt =0; + int totalScores[] = new int[numdancing]; + for (int index = 0; index < numdancing; index++){ + totalScores[index] = inFile.nextInt(); + } + for ( int i = 0; i < numdancing; i++){ + if(p ==0){ + cnt++; + continue; + }else if(p ==1){ + if (totalScores[i]>0) + cnt++; + continue; + + } + + if (totalScores[i]>= p3-2){ + cnt++; + } + else if(totalScores[i]>= p3-4){ + if (outlier>0){ + outlier--; + cnt++; + } + } + + } + outputStream.println(""Case #""+(t+1)+"": ""+cnt); + } + outputStream.flush(); + } + +} +" +A21393,"package de.hg.codejam.tasks.io; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public abstract class Reader { + + public static String[] readFile(String path) { + String[] input = null; + + try (BufferedReader reader = new BufferedReader(new FileReader(path))) { + int inputSize = Integer.parseInt(reader.readLine()); + input = new String[inputSize]; + + for (int i = 0; i < inputSize; i++) + input[i] = reader.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + + return input; + } +} +" +A22616,"import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class Parser { + + File instance; + Scanner sc; + + public Parser(String f){ + instance = new File(f); + } + + public List>> parse(int nbLinePerCase) throws FileNotFoundException{ + sc = new Scanner(instance); + int nbCase = sc.nextInt(); + List>> input = new ArrayList>>(nbCase); + String line; + sc.nextLine(); + for(int i = 0; i < nbCase; i++){ + List> ll = new ArrayList>(nbLinePerCase); + for(int j = 0; j < nbLinePerCase; j++){ + List l = new ArrayList(); + line = sc.nextLine(); + Scanner sc2 = new Scanner(line); + while(sc2.hasNext()){ + l.add(sc2.next()); + } + ll.add(l); + } + input.add(ll); + } + + return input; + } +} +" +A20834,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(new File(""./src/B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""./src/output.out"")); + + int T = in.nextInt(); + int s, p, n, v, a; + int[] t; + + for (int zz = 0; zz < T; ++zz) { + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + t = new int[n]; + a = 0; + v = (p - 2 < 0 ? 0 : p - 2); + v *= 2; + v += p; + for (int i = 0; i < n; ++i) { + t[i] = in.nextInt(); + } + Arrays.sort(t); + for (int i = 0; i < n; ++i) { + if (p == 0) { + ++a; + continue; + } + if (p == 1 && t[i] > 0) { + ++a; + continue; + } + if (t[i] < v) + continue; + if ((t[i] == v || t[i] == v + 1) && s > 0) { + --s; + ++a; + } else if (t[i] > v + 1) + ++a; + } + out.write(""Case #"" + (zz + 1) + "": "" + a + (zz + 1 == T ? """" : ""\n"")); + } + + out.close(); + in.close(); + } +}" +A21168,"/** + * + * @author jenny + */ +public class DancingGooglers extends javax.swing.JFrame { + int lineas = 0; + String entrada; + String salida = """"; + + /** + * Creates new form DancingGooglers + */ + public DancingGooglers() { + initComponents(); + } + + public void parsear(){ + int imprimibles = 0; + String[] entradas = entrada.split(""\n""); + lineas = Integer.parseInt(entradas[0]); + if(lineas > entradas.length){ + imprimibles = entradas.length - 1; + }else{ + imprimibles = lineas; + } + for(int i=1;i<=imprimibles;i++){ + int mayores = 0; + int sobres = 0; + salida = salida + ""Case #"" + i + "": ""; + String[] valores = entradas[i].split("" ""); + int numgog = Integer.parseInt(valores[0]); + int triplets = Integer.parseInt(valores[1]); + int mayor = Integer.parseInt(valores[2])*3; + for (int j=3;j 0 & mayor > 0)||(mayor == 0)){ + if(numact >= (mayor-2)){ + mayores = mayores + 1; + }else if(numact >= (mayor-4)){ + sobres = sobres + 1; + } + } + } + if (sobres > triplets){ + mayores = mayores + triplets; + }else{ + mayores = mayores + sobres; + } + salida = salida + mayores + ""\n""; + mayores = 0; + sobres = 0; + } + jTextArea2.setText(salida); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings(""unchecked"") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jLabel1 = new javax.swing.JLabel(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTextArea2 = new javax.swing.JTextArea(); + jLabel2 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + jLabel1.setText(""Input""); + + jTextArea2.setColumns(20); + jTextArea2.setRows(5); + jScrollPane2.setViewportView(jTextArea2); + + jLabel2.setText(""Output""); + + jButton1.setText(""Generar""); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE) + .addComponent(jButton1)) + .addComponent(jLabel1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jLabel2) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap(12, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(jLabel2)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE) + .addComponent(jScrollPane1)) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jButton1) + .addGap(165, 165, 165)))) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + entrada = jTextArea1.getText(); + parsear(); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* + * Set the Nimbus look and feel + */ + // + /* + * If Nimbus (introduced in Java SE 6) is not available, stay with the + * default look and feel. For details see + * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if (""Nimbus"".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(DancingGooglers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(DancingGooglers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(DancingGooglers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DancingGooglers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* + * Create and display the form + */ + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + new DancingGooglers().setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTextArea jTextArea2; + // End of variables declaration//GEN-END:variables +} +" +A21472,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +public class B { + + public static void main(String[] args) { + try { + BufferedReader input = new BufferedReader(new FileReader(""/home/ramzy/Desktop/codejam/B-small.in"")); + PrintWriter output = new PrintWriter(""/home/ramzy/Desktop/codejam/B-large.in""); + String line = input.readLine(); + int T = Integer.valueOf(line); + for(int i = 1; i <= T; i++) { + line = input.readLine(); + String[] values = line.split("" ""); + int N = Integer.valueOf(values[0]); + int S = Integer.valueOf(values[1]); + int p = Integer.valueOf(values[2]); + int[] nums = new int[N]; + for(int j = 0; j < N; j++) { + nums[j] = Integer.valueOf(values[3+j]); + } + Arrays.sort(nums); + int result = 0; + for(int j = N-1; j >= 0; j--) { + if(p == 0) { + result++; + } else if(p == 1) { + if(nums[j] < 1) + break; + else + result++; + }else if(nums[j] > (p-1)*3) { + result++; + } else if(nums[j] > (p-2)*2 + (p-1) && S > 0) { + result++; + S--; + } else if(S < 0) { + break; + } + } + + output.println(""Case #"" + i + "": "" + result); + System.out.println(""Case #"" + i + "": "" + result); + + } + output.close(); + input.close(); + } catch(IOException e) { + System.err.println(e); + } + } + +} +" +A21870,"package cj2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class CJ2012QB { + + public static void main(String[] args) { + BufferedReader bf = null; + BufferedWriter bw = null; + + try { + bf = new BufferedReader(new FileReader(""./src/cj2012/"" + args[0] + "".in"")); + bw = new BufferedWriter(new FileWriter(""./src/cj2012/"" + args[0] + "".out"")); + + int N = Integer.valueOf(bf.readLine()); + + for (int n=0; n < N; n++) { + scores(bf, bw, n); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (bw != null) bw.close(); + if (bf != null) bf.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * https://code.google.com/codejam/contest/1460488/dashboard#s=p1 + */ + private static void scores(BufferedReader bf, BufferedWriter bw, int caseNum) throws NumberFormatException, IOException { + String[] ia = bf.readLine().split("" ""); + + int N = Integer.valueOf(ia[0]); + + int S = Integer.valueOf(ia[1]); + + int P = Integer.valueOf(ia[2]); + + int result = 0; + + int enough = Math.max(((P-1) * 3) + 1, P); + + int surprising = Math.max(enough - 2, P); + + for (int i=0; i < N; i++) { + int score = Integer.valueOf(ia[i+3]); + + if (score >= enough) { + result++; + } else if (score >= surprising && S > 0){ + S--; + result++; + } else { + } + } + + bw.write(""Case #"" + (caseNum+1) + "": "" + result + ""\n""); + } +} +" +A22361,"import java.io.*; + +public class QualB { + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int z = Integer.parseInt(br.readLine()); + int[] u = {0, 0, 3, 6, 9, 12, 15, 18, 21, 24, 27}; + int[] ul = {0, 0, 1, 4, 7, 10, 13, 16, 19, 22, 25}; + + + for(int i=0; i u[p]){ + ctr++; + + }else if(t > ul[p] && ss > 0){ + ss--; + ctr++; + } + } + + System.out.println(""Case #"" + (i+1) + "": "" + ctr); + } + } + } +} +" +A22531,"import java.io.*; + +public class DancingWithGooglers { + + static int caseNumber; + static int totalCases; + + public static void main(String[] args) throws Exception { + + caseNumber = 1; + + File fileIn = new File(""C:\\GCJ\\DancingWithGooglers\\B-large.in""); + FileInputStream fileInputStream = null; + BufferedInputStream inputStream = null; + BufferedReader reader = null; + Writer out; + + String newLine = System.getProperty(""line.separator""); + + String fileOutPath = ""C:\\GCJ\\DancingWithGooglers\\outputLarge.txt""; + File fileOut = new File(fileOutPath); + if (! fileOut.createNewFile()){ + fileOut.delete(); + fileOut.createNewFile(); + } + + out = new OutputStreamWriter(new FileOutputStream(fileOutPath), ""US-ASCII""); + + + StringBuilder builder = new StringBuilder(); + + try { + fileInputStream = new FileInputStream(fileIn); + + // Here BufferedInputStream is added for fast reading. + inputStream = new BufferedInputStream(fileInputStream); + reader = new BufferedReader(new InputStreamReader(inputStream)); + + totalCases = Integer.parseInt(reader.readLine()); + while (caseNumber <= totalCases){ + builder.append(handleTestCase(reader)); + builder.append(newLine); + caseNumber++; + } + + + // dispose all the resources after using them. + fileInputStream.close(); + inputStream.close(); + reader.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + System.out.print(builder.toString()); + out.write(builder.toString()); + out.close(); + } + + public static String handleTestCase(BufferedReader reader) throws IOException{ + String[] splitLine = reader.readLine().split("" ""); + int[] ints = stringArrayToIntArray(splitLine); + int numScores = ints[0]; + int numSurprises = ints[1]; + int goal = ints[2]; + + int surprisesLeft = numSurprises; + int metGoal = 0; + for(int i = 3; i < ints.length; i++){ + //Base cases + if(ints[i] == 0) { + if(goal == 0) + metGoal++; + } + + else if(ints[i] == 1){ + if(goal == 1) + metGoal++; + } + //Handles if the number is divisible by 3 + //If the average is >= the goal, it is trivially meeting the goal + //If you allow for a surprise, the max can grow by 1 + else if(ints[i] % 3 == 0){ + if(ints[i] / 3 >= goal) + metGoal++; + else if ( ints[i] / 3 == goal - 1){ + if(surprisesLeft > 0) { + surprisesLeft--; + metGoal++; + } + } + } + + //The value of the maximum doesn't change even with a surprise with ints[i] % 3 ==1 + //So I don't even evaluate it here and worry about deducting available surprises + else if(ints[i] % 3 == 1){ + if(ints[i] / 3 >= goal-1) + metGoal++; + } + + //Value of the maximum with % 3 == 2 is one above the average by default + //Allowing for a surprise allows for it to be one higher + else if(ints[i] % 3 == 2){ //Unecessary ""if"" statement kept to remind about the last case + if(ints[i] / 3 >= goal-1) + metGoal++; + else if(ints[i] / 3 == goal - 2){ + if(surprisesLeft > 0) { + surprisesLeft--; + metGoal++; + } + } + } + + } + + if(surprisesLeft > 0) + System.out.println(""Surprises were left: ""+surprisesLeft+"" on case ""+caseNumber); + return ""Case #""+caseNumber+"": ""+metGoal; + } + + public static int[] stringArrayToIntArray(String[] input){ + int[] ints = new int[input.length]; + for (int i = 0; i < input.length; i++){ + ints[i] = Integer.parseInt(input[i]); + } + return ints; + } +} +" +A21613,"public class Result { + + public String output; + public int i; + + public Result(int i) { + this.i = i; + } + + @Override + public String toString() { + return ""Case #""+i+"": "" + output; + } + + +} +" +A20668,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.text.MessageFormat; +import java.util.Map; +import java.util.Scanner; + + +public class QualQ2 { + + + private final Scanner inputScanner = new Scanner(System.in); + + private Scanner testCaseScanner; + + private int answer; + + int[] scores; + + int N; + int p; + int S; + /** + * @param args + */ + public static void main(String[] args) { + QualQ2.init(); + QualQ2 speaking = new QualQ2(); + speaking.solve(); + } + + private static void init() { + try { + System.setIn(new FileInputStream(""in.txt"")); + System.setOut(new PrintStream(""out.txt"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + private void solve() { + // Number of test cases + int T = inputScanner.nextInt(); + inputScanner.nextLine(); + for (int i = 1; i <= T; i++) { + initTestCase(); + readTestCase(); + solveTestCase(); + printTestCase(i); + } + } + + + private void initTestCase() { + answer = 0; + } + + private void readTestCase() { + testCaseScanner = new Scanner(inputScanner.nextLine()); + + N = testCaseScanner.nextInt(); + S = testCaseScanner.nextInt(); + p = testCaseScanner.nextInt(); + + scores = new int[N]; + for (int i=0;i= p) { + answer++; + continue; + } + if (high == p-1 && S>0 && high !=0) { + int mod = scores[i] % 3; + if (mod == 0 || mod == 2) { + answer++; + S--; + } + } + } + } + + + private final MessageFormat printFormat = new MessageFormat(""Case #{0}: ""); + + private void printTestCase(int num) { + System.out.print(printFormat.format(new Object[] { num })); + System.out.println(answer); + } +} +" +A22300,"import java.io.*; +import java.util.*; + +public class test2 +{ + + public static void main(String[] args) throws Exception + { + new test2().run(); + } + + PrintWriter out = null; + + boolean isOK(int n, int p, boolean s) + { + int a = n / 3; + if (n % 3 != 0) + a++; + + if (a >= p) + return true; + + if (s) + { + return 3 * p - 4 <= n; + } + + return false; + } + + void run() throws Exception + { + Scanner in = new Scanner(System.in); + out = new PrintWriter(new FileWriter(""codejam.txt"")); + + int T = in.nextInt(); + for (int i = 0; i < T; i++) + { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int[] scores = new int[N]; + for (int j = 0; j < N; j++) + scores[j] = in.nextInt(); + + Arrays.sort(scores); + int total = 0; + for (int j = N - 1; j >= 0; j--) + { + if (isOK(scores[j], p, false)) + total++; + else + { + if (S > 0 && p >= 2) + { + if (isOK(scores[j], p, true)) + { + total++; + S--; + } + else + break; + } + else + break; + } + } + + out.printf(""Case #%d: %d\n"", i + 1, total); + } + out.close(); + } +} +" +A21947,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + if(args.length != 1) { + return; + } + FileInputStream inputStream = new FileInputStream(args[0]); + InputStreamReader istReader = new InputStreamReader(inputStream); + BufferedReader buffReader = new BufferedReader(istReader); + + // T + int T = Integer.valueOf(buffReader.readLine()); + + for(int i = 1; i <= T; i++) { + String[] caseStrs = buffReader.readLine().split("" ""); + int n = Integer.valueOf(caseStrs[0]);// N + int s = Integer.valueOf(caseStrs[1]);// S + int p = Integer.valueOf(caseStrs[2]);// p + int p_possible, p_certain; + switch(p) { + case 0: + case 1: + p_possible = p_certain = p; + break; + default: + p_possible = (p * 3) - 4; + p_certain = (p * 3) - 2; + } + + int y = 0, py = 0; + for(int j = 0; j < n; j++) { + int t = Integer.valueOf(caseStrs[3 + j]); + + if(t >= p_certain) { + y++; + continue; + } + + if(t >= p_possible) { + py++; + continue; + } + } + + if(s > py) { + y += py; + } else { + y += s; + } + + StringBuilder resultBuilder = new StringBuilder(""Case #""); + resultBuilder.append(i); + resultBuilder.append("": ""); + resultBuilder.append(y); + System.out.print(resultBuilder.toString()); + if(i != T) + System.out.println(); + } + } + +} +" +A21466,"import java.util.*; +import java.math.*; + +public class dancingGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + Scanner scan = new Scanner(System.in); + int numStrings = scan.nextInt(); + + for(int i =1; i <= numStrings; i++){ + int numGooglers = scan.nextInt(); + int numSurprises = scan.nextInt(); + int p = scan.nextInt(); + + int[] totalScores; + totalScores = new int[numGooglers]; + + int withoutSurpriseCount, withSurpriseCount; + withoutSurpriseCount = 0 ; + withSurpriseCount = 0; + + for(int j = 1; j <= numGooglers; j++){ + + totalScores[j-1] = scan.nextInt(); + + if(totalScores[j-1] >= p + 2*Math.max(p-1, 0)){ + withoutSurpriseCount = withoutSurpriseCount + 1; + } + else if(totalScores[j-1] >= p + 2*Math.max(p-2,0)){ + withSurpriseCount = withSurpriseCount + 1; + } + } + + //System.out.println(""\n "" + numGooglers + "" "" + numSurprises + "" "" + withoutSurpriseCount + "" "" + withSurpriseCount); + + int temp1 = Math.min(withSurpriseCount, numSurprises); + int temp2 = temp1 + withoutSurpriseCount; + int temp3 = Math.min(numGooglers, temp2); + + System.out.format(""Case #%d: %d\n"", i, temp3); + + } + } + +} +" +A21176,"import java.io.*; +import java.util.*; +import java.math.*; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + + +public class Solution +{ + public static void main(String[] args) throws IOException + { + new Solution().run(); + } + StreamTokenizer in; + Scanner ins; + PrintWriter out; + + int nextInt() throws IOException + { + in.nextToken(); + return (int)in.nval; + } + + + void run() throws IOException + { + + if(System.getProperty(""ONLINE_JUDGE"")!=null) + { + in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); + ins = new Scanner(System.in); + out = new PrintWriter(System.out); + } + else + { + in = new StreamTokenizer(new BufferedReader(new FileReader(""input.txt""))); + ins = new Scanner(new FileReader(""input.txt"")); + out = new PrintWriter(new FileWriter(""output.txt"")); + } + int n = nextInt(); + for(int k =0; k=p || (a+2>=p && p>=1 && a-1>=0)) + answ++; + else + { + if(a+4>=p && p>=2 && t>0 && a-2>=0) + { + answ++; + t--; + } + } + + } + out.print(answ); + out.println(); + } + + out.close(); + } + + interface Ololo + { + public int Calc(); + } + enum Trololo{ZOMBI, Ololosha, kukuru} + class Team implements Comparable + { + public int p,t; + public int compareTo(Object obj) + { + Team a = (Team) obj; + if(p>a.p || p==a.p && t0) { + x=calcifSur(values[i],p); + if(x==1) + surprising--; + } + result+=x; + } + + brout.write(""Case #""+l+"": ""+result+""\n""); + } + brout.close(); + return; + } + public static int calcifpossible(int k,int p) { + int kk=k%3; + int ifnotsurprising=0; + int num1not=0,num2not=0,num3not=0; + switch(kk) { + case 0: + + num1not=k/3; + num2not=k/3; + num3not=k/3; + + break; + case 1: + + num1not=k/3; + num2not=k/3; + num3not=k/3+1; + + + break; + case 2: + + num1not=k/3; + num2not=k/3+1; + num3not=k/3+1; + break; + } + if(num1not>=p) { + ifnotsurprising++; + } + if(num2not>=p) { + ifnotsurprising++; + } + if(num3not>=p) { + ifnotsurprising++; + } + if(ifnotsurprising>0) return 1; + else return 0; + + } + public static int calcifSur(int k,int p) { + int num1s=0; + int num2s=0; + int num3s=0; + int kk=k%3; + int ifsurprising=0; + switch(kk) { + case 0: + if(k==30 || k==0) { + num1s=k/3; + num2s=k/3; + num3s=k/3; + } else { + num1s=k/3-1; + num2s=k/3; + num3s=k/3+1; + + } + + break; + case 1: + if(k==1) { + num1s=k/3; + num2s=k/3; + num3s=k/3+1; + + } else { + num1s=k/3-1; + num2s=k/3+1; + num3s=k/3+1; + + } + + break; + case 2: + num1s=k/3; + num2s=k/3; + num3s=k/3+2; + + break; + } + if(num1s>=p) { + ifsurprising++; + } + if(num2s>=p) { + ifsurprising++; + } + if(num3s>=p) { + ifsurprising++; + } + if(ifsurprising>0) return 1; + else return 0; + } + public static int getAnswer(int[] x,int p,int surprisingleft,int start) { + if(x.length-start=x.length && surprisingleft!=0) { + return Integer.MIN_VALUE; + } + if(start==x.length && surprisingleft==0) { + return 0; + } + boolean flag=false; + if(surprisingleft==0) { + flag=true; + } + int ifsurprising=0; + int ifnotsurprising=0; + int k=x[start]%3; + int num1s=0; + int num2s=0; + int num3s=0; + int num1not=0; + int num2not=0; + int num3not=0; + switch(k) { + case 0: + if(x[start]==30 || x[start]==0) { + num1not=x[start]/3; + num2not=x[start]/3; + num3not=x[start]/3; + num1s=x[start]/3; + num2s=x[start]/3; + num3s=x[start]/3; + } else { + num1s=x[start]/3-1; + num2s=x[start]/3; + num3s=x[start]/3+1; + num1not=x[start]/3; + num2not=x[start]/3; + num3not=x[start]/3; + } + + break; + case 1: + if(x[start]==1) { + num1s=x[start]/3; + num2s=x[start]/3; + num3s=x[start]/3+1; + num1not=x[start]/3; + num2not=x[start]/3; + num3not=x[start]/3+1; + } else { + num1s=x[start]/3-1; + num2s=x[start]/3+1; + num3s=x[start]/3+1; + num1not=x[start]/3; + num2not=x[start]/3; + num3not=x[start]/3+1; + } + + break; + case 2: + num1s=x[start]/3; + num2s=x[start]/3; + num3s=x[start]/3+2; + num1not=x[start]/3; + num2not=x[start]/3+1; + num3not=x[start]/3+1; + break; + } + if(num1s>=p) { + ifsurprising++; + } + if(num2s>=p) { + ifsurprising++; + } + if(num3s>=p) { + ifsurprising++; + } + if(num1not>=p) { + ifnotsurprising++; + } + if(num2not>=p) { + ifnotsurprising++; + } + if(num3not>=p) { + ifnotsurprising++; + } + if(flag) { + if(ifnotsurprising>0) + return getAnswer(x,p,surprisingleft,start+1)+1; + else + return getAnswer(x,p,surprisingleft,start+1); + } + else { + int acc21=0; + int acc22=0; + if(ifsurprising>0) { + acc21=1; + } + if(ifnotsurprising>0) { + acc22=1; + } + + if(getAnswer(x,p,surprisingleft-1,start+1)+acc21> getAnswer(x, p, surprisingleft, start+1)+acc22) + return getAnswer(x,p,surprisingleft-1,start+1)+acc21; + else + return getAnswer(x, p, surprisingleft, start+1)+acc22; + } + + } +} + +" +A20872,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + + +public class qb { + + public static void main(String [] args) + { + String fileName = ""B-large.in""; + + try{ + FileReader fr = new FileReader(fileName); + BufferedReader br = new BufferedReader(fr); + + FileWriter fw = new FileWriter(""output.txt""); + BufferedWriter bw = new BufferedWriter(fw); + + String line=""""; + int count = 0; + while((line=br.readLine())!=null) + { + if(count == 0) + { + count++; + continue; + } + String [] sp = line.split("" ""); + + int [] rule = new int[3]; //rule 3°³¸¦ Áý¾î³ÖÀ½. 1.»ç¶÷¼ö, 2.¼­ÇÁ¶óÀÌ¡ °¹¼ö. 3.¸Æ½ºÁ¡¼ö + for(int i=0; i<3; i++) + rule[i] = Integer.parseInt(sp[i]); + + + int [] player = new int[sp.length-3]; //³ª¸ÓÁö µÚ¿¡ °ªµéÀÌ Ç÷¹À̾î Á¡¼öÀ̹ǷΠ´Æ. + int [] playerScore = new int[player.length*3]; //ÇÑ»ç¶÷´ç ¼¼¸íÀÇ ½É»çÀ§¿ø Æò°¡ Á¡¼ö + for(int i=0; i= rule[2]) + { + nPlayerCanSup++; + } + } + else + { + if((playerScore[i*3]) >= rule[2]) + nPlayerCanSup++; + } + + } + } + } + if(nPlayerCanSup >= rule[1]) + solution = nPlayerOverMax + rule[1]; + else + solution = nPlayerOverMax + nPlayerCanSup; + + if(solution > rule[0]) + solution = rule[0]; + + bw.write(""Case #""+count+"": ""+solution); + bw.write(""\n""); + count++; + } + + bw.close(); + fw.close(); + br.close(); + fr.close(); + + + }catch(Exception EE) + { + EE.printStackTrace(); + } + + + } + +} +" +A20120,"package t2; + +import java.io.*; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class T1 { + BufferedWriter out; + ArrayList list = new ArrayList(); + int i = 1; + + + T1(){ + try { + out = new BufferedWriter(new FileWriter(new File(""output.txt""))); + } catch (IOException ex) {} + start(); + try { + out.close(); + } catch (IOException ex) { + Logger.getLogger(T1.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static void main(String[] args) { + T1 t = new T1(); + } + + private void lerArquivo(String input) { + File f = new File(input); + if(!f.exists()) + { + System.exit(-1); + } + try { + BufferedReader in = new BufferedReader(new FileReader(f)); + String line; + int lineCount = 0; + in.readLine(); + while((line = in.readLine())!=null) + { + list.add(line); + } + } catch (Exception e) {} + } + + private void write(String str){ + str = ""Case #""+i+"": ""+ str + ""\n""; + try { + out.write(str, 0, str.length()); + i++; + } catch (IOException ex) { + Logger.getLogger(T1.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private void start(){ + lerArquivo(""input.txt""); + for(String str: list){ + int counter = 0; + StringTokenizer st = new StringTokenizer(str); + int googlers = Integer.parseInt(st.nextToken()); + int surprising = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + for(int i = 0; i < googlers; i++){ + int score = Integer.parseInt(st.nextToken()); + int base = score / 3; + if(base >=p) + counter++; + else if(base == 0){ + if(score >= p && score == 1){ + counter++; + }else if (score >= p && score == 2 && surprising > 0){ + counter++; + surprising--; + } + }else if(score%3 == 0){ + if(base+1 >= p && surprising > 0){ + surprising--; + counter++; + } + }else if((score % 3) == 1){ + if(base+1 >= p) + counter++; + }else if((score%3) == 2){ + if(base+1 >= p){ + counter++; + }else if(base+2 >= p && surprising > 0){ + counter++; + surprising--; + } + } + } + write(""""+counter); + } + } +} +" +A21913,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintStream; +import java.util.StringTokenizer; + +public class B { + + private B() { + } + + public static void main(final String[] args) throws Exception { + final B a = new B(); + a.solve(); + } + + public void solve() throws Exception { + final BufferedReader in = new BufferedReader(new FileReader(new File(""f.in""))); + System.setOut(new PrintStream(this.getClass().getSimpleName() + "".out"")); + // StringTokenizer st; + final String line = in.readLine(); + final int test = Integer.parseInt(line); + for (int q=1; q <= test;q++) { + final StringTokenizer st = new StringTokenizer(in.readLine()); + + final int N = Integer.parseInt(st.nextToken()); + final int S = Integer.parseInt(st.nextToken()); + final int p = Integer.parseInt(st.nextToken()); + final int[] mas = new int[N]; + for (int i = 0; i < N; i++) { + mas[i] = Integer.parseInt(st.nextToken()); + } + + final int[][] result = new int[N][3]; + for (int i = 0; i < N; i++) { + result[i][0] = (mas[i] + 2) / 3; // Normal + if (mas[i] == 0) { + result[i][1] = 0; + continue; + } + final int div = mas[i] / 3; + final int mod = mas[i] % 3; + if (mod == 0) { + result[i][1] = div + 1; // Suprised + } else if (mod == 1) { + result[i][1] = -1; // Suprised + } else if (mod == 2) { + result[i][1] = div + 2; // Suprised + } + // result[i][0] = (mas[i]+2)/3; //bonus + } + + int res = 0; + int added = 0; + + for (int i = 0; i < N; i++) { + if (result[i][0] >= p) { + res++; + continue; + } + if (result[i][1] >= p) { + added++; + continue; + } + } + + res = res + Math.min(added, S); + System.out.println(""Case #"" + q + "": "" + res); + } + } +} +" +A20546,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.StringTokenizer; + +/** + * + * @author parusnik + */ +public class Codejam { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""input.txt"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""output.txt"")); + + int T = Integer.parseInt(br.readLine()); + StringTokenizer st; + + for (int t = 1; t<=T; t++){ + bw.write(""Case #"" + String.valueOf(t) + "": ""); + st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + + int k = 0; + int d = 0; + + for (int i = 0; i=0){ + a/=2; + if (a==p-2) k++; + else if (a>p-2) d++; + } + } + + d += Math.min(k, s); + bw.write(String.valueOf(d)); + + bw.newLine(); + } + + br.close(); + bw.close(); + } + +} +" +A20633,"package utils; + +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + + +public class Dancing { + + public static void main(String[] args) { + lecture(""/Users/valentinbonneaud/Downloads/B-large.in""); +// lecture(""/Users/valentinbonneaud/Desktop/test.txt""); + } + + public static void lecture(String name){ + + Scanner flux = null; + PrintWriter out; + + try { + flux = new Scanner(new FileInputStream(name)); + out = new PrintWriter(new FileWriter(""/Users/valentinbonneaud/Downloads/B-large-practice out.in"", false)); + } catch (Exception e1) { + e1.printStackTrace(); + return; + } + + int nb = flux.nextInt(); + + for(int i =0;i tab; + + public Scores(int x) + { + tab = new ArrayList(); + tab.add(new Score(x)); + + int[] score = tab.get(0).getVec(); + Score test; + + test=new Score(score[0]+1,score[1],score[2]-1); + if(!test.isIncorrect()) + tab.add(test); + + test=new Score(score[0],score[1]+1,score[2]-1); + if(!test.isIncorrect()) + tab.add(test); + + test=new Score(score[0]-1,score[1],score[2]+1); + if(!test.isIncorrect()) + tab.add(test); + + test=new Score(score[0]-1,score[1]+1,score[2]); + if(!test.isIncorrect()) + tab.add(test); + + test=new Score(score[0]+1,score[1]-1,score[2]); + if(!test.isIncorrect()) + tab.add(test); + + test=new Score(score[0],score[1]-1,score[2]+1); + if(!test.isIncorrect()) + tab.add(test); + } + + public boolean isGreater(int p) + { + boolean trueWithSurprising = false; + for(int i = 0;i0 && trueWithSurprising) + { + s--; + return true; + } + + return false; + } +} + +class Score +{ + int[] vec; + boolean surprising; + + public Score(int x,int y,int z) + { + vec = new int[3]; + vec[0]=x; + vec[1]=y; + vec[2]=z; + } + public Score(int x) + { + vec = new int[3]; + int reste = x; + vec[0] = (int)(Math.floor(reste/3.)); + reste-=vec[0]; + vec[1] = (int)(Math.floor(reste/2.)); + reste-=vec[1]; + vec[2] = reste; + + while(true) + { + if(isIncorrect()){ + + //We looking for the max and the min + System.out.println(""Incorrect ! ""+vec[0]+"" ""+vec[1]+"" ""+vec[2]); + Arrays.sort(vec); + vec[0]+=1; + vec[2]-=1; + continue; + } + else + break; + } + surprising=isSurprising(); + } + + public int[] getVec() { + return vec; + } + + public boolean isGreater(int p) + { + return ((vec[0]>=p)||(vec[1]>=p)||(vec[2]>=p)); + } + + public boolean isSurprising(){ + if(Math.abs(vec[0]-vec[1]) >= 2) + return true; + if(Math.abs(vec[1]-vec[2]) >= 2) + return true; + if(Math.abs(vec[0]-vec[2]) >= 2) + return true; + + return false; + } + + public boolean isIncorrect(){ + if(vec[0]<0 || vec[1]<0 || vec[2]<0) + return true; + + if(Math.abs(vec[0]-vec[1]) >= 3) + return true; + if(Math.abs(vec[1]-vec[2]) >= 3) + return true; + if(Math.abs(vec[0]-vec[2]) >= 3) + return true; + + return false; + } +}" +A21514,"package dancewithgooglers; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Main { + + private static final String OUTPUT_TEMPLATE = ""Case #""; + + + + public static void main(String[] args) { + + if (args.length < 1) { + System.out.println(""feed me a parameter""); + return; + } + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(args[0]); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + // Read File Line By Line + strLine = br.readLine(); + StringBuilder sb = new StringBuilder(); + int case_no = 1; + while ((strLine = br.readLine()) != null) { + String[] raw_data = strLine.split("" ""); + int googlers_number = Integer.parseInt(raw_data[0]); + int surprise_number = Integer.parseInt(raw_data[1]); + int cutoff_point = Integer.parseInt(raw_data[2]); + int[] total_points = new int[googlers_number]; + for(int temp = 0; temp-1;i--){ + + if(total_points[i]>=comfort_cutoff){ + count++; + } + else if(total_points[i]>=special_cutoff){ + if(special_cutoff == -1 && total_points[i]==0) + break; + else if(surprise_number>0){ + count++; + surprise_number--; + } + else + break; + } + } + sb.append(OUTPUT_TEMPLATE).append(case_no++).append("": "").append(count).append(""\n""); + count = 0; + } + // Close the input stream + System.out.println(sb.toString()); + in.close(); + + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + e.printStackTrace(); + } + } + + +} +" +A21925,"package codejam; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Gedion Moyo + */ +public class dance { + + /** + * @param args the command line arguments + */ + + static Scanner in; + static PrintWriter out; + + public static void main(String[] args) { + try { + in = new Scanner(new FileReader(""src/codejam/input.txt"")); + out = new PrintWriter(new FileWriter(""src/codejam/output.txt"")); + solve(); + } catch (Exception ex) { + Logger.getLogger(CodeJam.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static void solve() throws Exception { + + + int caseCount = Integer.valueOf(in.nextLine()); + for (int caseNum = 0; caseNum < caseCount; caseNum++) { + System.out.println(""solving case "" + caseNum); + + out.print(""Case #"" + (caseNum + 1) + "":""); + out.print("" ""); + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] t = getScores(N); + int count = 0; + int suprises = 0; + for (int j=0; j= p){ + if ((t[j]/3 >= p)||((t[j]+2)/3>=p)){ + count++; + }else if (((t[j]+4)/3 >= p) && suprises < S){ + count++; + suprises++; + } + } + } + out.print(count); + out.print(""\n""); + } + out.flush(); + out.close(); + in.close(); + + } + + public static int[] getScores(int N){ + int[] scores = new int[N]; + for (int i =0; i < N;i++){ + scores[i] = in.nextInt(); + } + + return scores; + } +} +" +A21926,"package codeJam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +/** + * http://code.google.com/codejam/contest/1460488/dashboard#s=p1 + * @author Weiwei Cheng + */ +public class DancingWithTheGooglers { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new FileReader(""_input.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""_output.in"")); + + br.readLine(); + + String line = null; + int count = 0; + + while((line=br.readLine())!=null){ + + String[] input = line.split("" ""); + + int numGooglers = Integer.parseInt(input[0]); + int maxNumSuprises = Integer.parseInt(input[1]); + int neededScore = Integer.parseInt(input[2]); + + int[] scores = new int[numGooglers]; + int ans = 0; + int numSuprises = 0; + + for(int i=3; i= neededScore){ + ans++; + } + else if(highscoreWithSup >= neededScore && numSuprises < maxNumSuprises){ + ans++; + numSuprises++; + } + } + else{//score==0 + if(0 >= neededScore){ + ans++; + } + } + } + else if(score % 3 == 1){ + int highscoreWithSup = score / 3 + 1; + int highscoreNoSup = highscoreWithSup; + if(highscoreNoSup >= neededScore){ + ans++; + } + } + else{ + int highscoreWithSup = score / 3 + 2; + int highscoreNoSup = score / 3 + 1; + if(highscoreNoSup >= neededScore){ + ans++; + } + else if(highscoreWithSup >= neededScore && numSuprises < maxNumSuprises){ + ans++; + numSuprises++; + } + } + } + + bw.append(""Case #"" + ++count + "": "" + ans); + + bw.newLine(); + } + + br.close(); + bw.close(); + + } + +} +" +A20188,"import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + + +public class Q2 { + + public static void main (String[] args) + { + Scanner s = new Scanner(System.in); + + int numTests = s.nextInt(); + for (int test = 0; test < numTests; test++) + { + int googlers = s.nextInt(); + int surprises = s.nextInt(); + int threshold = s.nextInt(); + List scores = new ArrayList(googlers); + for (int i = 0; i < googlers; i++) + { + scores.add(s.nextInt()); + } + Collections.sort(scores); + Collections.reverse(scores); + + int numAboveThreshold = 0; + for (int i = 0; i < googlers; i++) + { + int score = scores.get(i); + if (score >= 29) + { + //cannot possibly be surprise (10/10/9) + numAboveThreshold ++; + continue; + } + if (score < threshold) + { + //no way we get there + continue; + } + if (3 * threshold - 2 <= score) + { + //no need to use a surprise + numAboveThreshold ++; + continue; + } + if (3 * threshold - 4 <= score && surprises > 0) + { + numAboveThreshold ++; + surprises --; + continue; + } + } + + System.out.println(""Case #"" + (test+1) + "": "" + numAboveThreshold); + } + } + +} +" +A22902,"package Q2; + +import java.io.BufferedReader; +import java.io.IOException; + +abstract public class Solver { + protected BufferedReader input; + protected final String nl = System.getProperty(""line.separator""); + + abstract public String solve() throws Exception; + + protected String readLine(){ + try { + return input.readLine(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + return null; + } + + protected Long[] splitLineL(String line){ + return splitLineL(line, "" ""); + } + + protected Long[] splitLineL(String line, String delim){ + String[] split = line.split(delim); + Long[] $ = new Long[split.length]; + for(int i=0;i void printArr(T[] arr){ + for(int i=0;i void printArr(T[][] arr){ + for(int i=0;i> debug = new HashMap>(); + + int cases = Integer.parseInt(f.readLine()); + for (int zz = 1; zz <= cases; zz++) { + String x = f.readLine(); + StringTokenizer st = new StringTokenizer(x); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); //At least p for BEST score. + int[] points = new int[n]; + int ans = 0; + + // Assume p = 5 + int magicNum = Math.max((p - 2) + (p - 2) + p,p); // 3 3 5 or 3 4 5 + // magicNum and MagicNum+1 are always be surprising + + // 3 5 5 or 4 4 5 + // magicNum+2 may be surprising or not. + + //p=0 -2 -2 0 + //p=1 -1 -1 1 + //p=2 0 0 2 + //p=3 1 1 3 + //p=4 2 2 4 + + for (int xx = 0; xx < n; xx++) { + points[xx] = Integer.parseInt(st.nextToken()); + + if (p==0 || p==1) { + if (points[xx]>=p) + ans++; + continue; + } + + if (s > 0 && (points[xx] == magicNum || points[xx] == magicNum + 1)) { + s--; + ans++; + } else if (points[xx] >= magicNum + 2) { + ans++; + } + } + out.println(""Case #"" + zz + "": "" + ans); + + } + + out.close(); // close the output file + System.exit(0); // don't omit this! + } + +}" +A20165,"import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class DancingWiththeGooglers { + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(""B-large.in"")); + PrintWriter pw = new PrintWriter(""B-large.out""); + + int tc = sc.nextInt(); + for(int i=1; i<=tc; i++){ + int N = sc.nextInt(); + int S = sc.nextInt(); + int P = sc.nextInt(); + int sum=0; + for(int j=0; j= P){ + sum++; + }else if(maxScore == P-1 && maxScore >0 && (tot%3)!=1){ + if(S>0){ + sum++; + S--; + } + } + } + pw.println(""Case #"" + i + "": "" + sum); + } + + pw.close(); + sc.close(); + } + +} +" +A22261,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.HashMap; + + +public class Main { + + private static String fileDirectory = ""files/""; + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Problem2(fileDirectory + ""B-large.in"",fileDirectory + ""B-large.out""); + } + + public static void Problem2(String inFile, String outFile) + { + try { + BufferedReader br = new BufferedReader(new FileReader(inFile)); + BufferedWriter bw = new BufferedWriter(new FileWriter(outFile)); + + + + + int cases = Integer.parseInt(br.readLine()); + + for (int i = 0; i < cases; i++) + { + if (i > 0) + { + bw.newLine(); + } + + + String line = br.readLine(); + String[] numbers = line.split("" ""); + int N = Integer.parseInt(numbers[0]); + int S = Integer.parseInt(numbers[1]); + int p = Integer.parseInt(numbers[2]); + + int count = 0; + for (int j = 3; j < numbers.length; j++) + { + + int t = Integer.parseInt(numbers[j]); + if (t >= ((p - 1) + (p - 1) + p) && t >= p) + { + count++; + } + else if ((t >= ((p - 2) + (p - 2) + p)) && S > 0 && t >= p) + { + count++; + S = S - 1; + } + System.out.println(S); + } + bw.write(""Case #"" + (i+1) + "": ""); + bw.write(Integer.toString(count)); + } + + + bw.close(); + br.close(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + +} +" +A20984,"package fixjava; + +public class StringUtils { + + /** Repeat the given string the requested number of times. */ + public static String repeat(String str, int numTimes) { + StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes)); + for (int i = 0; i < numTimes; i++) + buf.append(str); + return buf.toString(); + } + + /** + * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is + * greater than numPlaces-1, then the output string will be longer than numPlaces. + */ + public static String padLeft(String str, char padChar, int numPlaces) { + int bufSize = Math.max(numPlaces, str.length() + 1); + StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1)); + buf.append(padChar); + for (int i = 1, mi = bufSize - str.length(); i < mi; i++) + buf.append(padChar); + buf.append(str); + return buf.toString(); + } + + /** + * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is + * greater than numPlaces-1, then the output string will be longer than numPlaces. + */ + public static String padRight(String str, char padChar, int numPlaces) { + int bufSize = Math.max(numPlaces, str.length() + 1); + StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1)); + buf.append(str); + buf.append(padChar); + while (buf.length() < bufSize) + buf.append(padChar); + return buf.toString(); + } + + /** Intern all strings in an array, skipping null elements. */ + public static String[] intern(String[] arr) { + for (int i = 0; i < arr.length; i++) + arr[i] = arr[i].intern(); + return arr; + } + + /** Intern a string, ignoring null */ + public static String intern(String str) { + return str == null ? null : str.intern(); + } + +} +" +A22614,"package gcj2012.Pre; + +import java.util.Scanner; + +public class B { + + static Scanner sc = new Scanner(System.in); + public static void main(String[] a){ + + long numCases = Long.parseLong(sc.nextLine()); + for(long kase = 0 ; kase < numCases ; kase++){ + String[] ss = sc.nextLine().split("" ""); + int n = Integer.parseInt(ss[0]); + int s = Integer.parseInt(ss[1]); + int p = Integer.parseInt(ss[2]); + int[] scores= new int[n]; + for(int i = 0 ; i < n ; i++) + scores[i] = Integer.parseInt(ss[3+i]); + + int ret = 0; + if(p == 0){ + ret = n; + }else if(p == 1){ + for(Integer i : scores){ + if(i > 0){ + ret++; + } + } + }else{ + int canCntSurNotNeed = 0; + int canCntSurNeed = 0; + int canSurOnly = 0; + int canCntOnly = 0; + for(int i = 0 ; i < n ; i++){ + if(scores[i] > 28){ + canCntOnly++; + }else if(scores[i] >= p+p-1+p-1){ + canCntSurNotNeed++; + }else if(scores[i] >= p+p-2+p-2){ + canCntSurNeed++; + }else if(scores[i] >= 2){ + canSurOnly++; + } + } + if(s <= canCntSurNeed){ + ret = canCntOnly + canCntSurNotNeed + s; + }else{ + ret = canCntOnly + canCntSurNotNeed + canCntSurNeed; + } + } + + System.out.println(""Case #"" + (kase+1) + "": "" + ret); + } + } + +} +" +A22426,"package codejam2012.q; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + +public class B +{ + static public void solveOne(int caseNo, Scanner in, PrintStream out) + { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + + int norm = 0; + int surp = 0; + + // array + for( int i=0 ; i=28 ){ + if( 10 >=p ) norm++; + } else + if( score<=1 ){ + if( 0 >=p ) norm++; + } else { + if( score%3==0 ){ + if( score/3 >=p ) norm++; + else if( score/3+1 >=p ) surp++; + } + if( score%3==1 ){ + if( score/3+1 >=p ) norm++; + else if( score/3+1 >=p ) surp++; + } + if( score%3==2 ){ + if( score/3+1 >=p ) norm++; + else if( score/3+2 >=p ) surp++; + } + } + } + in.nextLine(); + + int answer = norm + (s=p){ + mx++; + }else{ + if(t[i]<=28&&t[i]>1&&c>0){ + if(ps+1>=p&&t[i]%3!=1){ + mx++; + c--; + } + } + } + } + return mx+""""; + } +} +public class Caso1{ + public void iniciar(){ + Scanner s=null; + PrintStream ps=null; + try{ + ps=new PrintStream(new FileOutputStream(new File(""output.txt""))); + s=new Scanner(new FileReader(""input.txt"")); + StringBuffer entrada=new StringBuffer(); + while(s.hasNextLine()){ + entrada.append(s.nextLine()+""\n""); + } + s=new Scanner(entrada+""""); + }catch(Exception e){ + e.printStackTrace(); + } + int numeroCasos=s.nextInt(); + Caso[]casos=new Caso[numeroCasos]; + for(int i=0;i=p) + { + System.out.println(""list of best result w/o surprising "" + listOfBestResults[i]); + bestResultCount++; + } + + else if((listOfBestResults[i]/3) + 2>=p && (listOfBestResults[i]/3) + 1>=p) + { + System.out.println(""list of best result w/o surprising "" + listOfBestResults[i]); + bestResultCount++; + } + else if((listOfBestResults[i]/3) + 2>=p && surprising!=0) + { + System.out.println(""list of best result surprising "" + listOfBestResults[i]); + bestResultCount++; + surprising--; + } + } + else if(listOfBestResults[i]%3 == 1 ) + { + if(listOfBestResults[i]/3>=p) + { + System.out.println(""list of best result w/o surprising "" + listOfBestResults[i]); + bestResultCount++; + } + else if((listOfBestResults[i]/3) + 1>=p) + { + System.out.println(""list of best result w/o surprising "" + listOfBestResults[i]); + bestResultCount++; + } + else if((listOfBestResults[i]/3) + 1>=p && surprising!=0) + { + System.out.println(""list of best result surprising "" + listOfBestResults[i]); + bestResultCount++; + surprising--; + } + } + else if( listOfBestResults[i]%3 == 0 ) + { + if(listOfBestResults[i]/3>=p) + { + System.out.println(""list of best result w/o surprising "" + listOfBestResults[i]); + bestResultCount++; + } + + else if((listOfBestResults[i]/3) + 1>=p && surprising!=0) + { + System.out.println(""list of best result surprising "" + listOfBestResults[i]); + bestResultCount++; + surprising--; + } + } + + } + return bestResultCount; + + } + public boolean canItBeBestResult(int x, int p) + { + if(p==0) + { + return true; + } + if( x%3 == 2 && ((x/3)+2) >= p) + { + return true; + } + else if( x%3 == 1 && ((x/3)+1) >= p) + { + return true; + } + else if( x%3 == 0 && ((x/3)+1)>=p && x!=0) + { + return true; + } + + return false; + } +} +" +A22491,"import java.io.IOException; + + +public class DancingGooglers extends FileReaderWriter { + + /*//int[] GOOG = {29, 20, 8, 18, 18, 21}; + int[] GOOG = {23, 22, 21};*/ + + DancingGooglers(String inPath, String outPath) throws IOException { + super(inPath, outPath); + reader(); + + } + + @Override + public void reader() throws IOException { + super.writer(); + strLine = br.readLine(); + nTestCases = Integer.valueOf(strLine); + + int N, S, p; + int nthCase = 0; + + int googlerCount = 0; + + String toWrite = new String(); + + + //While LOOP + while( (strLine = br.readLine()) != null ) { + googlerCount = 0; + ++nthCase; + toWrite = toWrite + ""Case #"" + nthCase + "": ""; + String[] handler = strLine.split("" ""); + + int[] GOOG = new int[handler.length]; + + for(int i=0; i= p) + ++googlerCount; + else { + if(S>0 && base>0 && base+1>=p) { + ++googlerCount; + --S; + } + } + break; + } + + case 1: + { + if(base >= p || base+1 >= p) { + ++googlerCount; + } + else { + if(S > 0 && base + 1 >= p) { + ++googlerCount; + S--; + } + } + break; + } + + case 2: + { + if(base + 1 >= p || base >= p) { + ++googlerCount; + } + else { + if(S > 0 && base + 2 >= p) { + ++googlerCount; + --S; + } + } + break; + } + } + } + toWrite = toWrite + googlerCount + ""\n""; + } + System.out.println(toWrite); + bw.write(toWrite); + bw.close(); + } + +} +" +A22804,"/** + * Copyright Carma Systems, Inc. All rights reserved. + */ +package com.jessehutton.codejam.util; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; + +/** + * @author Jesse Hutton + */ +public abstract class IOHandler { + + protected BufferedReader reader; + protected PrintStream writer; + + public IOHandler(String inputFile) throws FileNotFoundException { + this(new String[] {inputFile}); + } + + public IOHandler(String[] args) throws FileNotFoundException { + reader = new BufferedReader(new FileReader(args[0])); + if (args.length > 1 && args[1] != null) { + writer = new PrintStream(new FileOutputStream(args[1])); + } else { + writer = System.out; + } + } + + public abstract String formatCase(int caseNum, Object result); + + public String line() throws IOException { + return reader.readLine(); + } + + public void recordCase(int caseNum, Object result) { + writer.println(formatCase(caseNum, result)); + } + + public void finish() { + try { + reader.close(); + } catch (IOException e) { + System.err.println(""closing reader failed.""); + e.printStackTrace(); + } + + writer.close(); + } +} +" +A21257," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.HashMap; + +/* + * To change this template, choose Tools | Templates and open the template in + * the editor. + */ +/** + * + * @author Anuj + */ +public class DanceWithGoogle { + + int cases; + String temp[]; + int magic, judges, surp; + int num; + + public DanceWithGoogle() { + cases = 0; + magic = 2; + judges = 3; + surp =0; + } + + public void go() { + try { + int z; + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""out.txt"")); + + cases = Integer.parseInt(br.readLine()); +// System.out.println(""Case : "" + cases); + + for (z = 0; z < cases; z++) { + + int i, j; + temp = br.readLine().split("" ""); + + + int players = Integer.parseInt(temp[0]); + surp = Integer.parseInt(temp[1]); + int thresh = Integer.parseInt(temp[2]); + int count = 0; +// System.out.println(""Case : "" + n); + //m = Integer.parseInt(temp[1]); + //System.out.println(""Case : "" + (z+1) + ""thres : ""+thresh); + + for (i = 0; i < players; i++) { + + int score = Integer.parseInt(temp[i + 3]); + if (check(score, thresh)) { + count++; + } + } + + //System.out.println(""Case #"" + (z + 1) + "": "" + count); + bw.write(""Case #"" + (z + 1) + "": "" + count); + bw.newLine(); + } + + br.close(); + bw.close(); + } catch (java.io.FileNotFoundException e) { + } catch (java.io.IOException e) { + } + } + + private boolean check(int sc, int th) { + + int non = 0; + int sur = 0; + if (sc != 0) { + non = (sc + 2) / 3; + sur = (sc + 4) / 3; + } + if (non >= th) { + return true; + } else if (surp > 0) { + + if (sur >= th) { + //System.out.println(""surp:"" + sur + ""su:"" + surp + "" for sc:"" + sc + ""thres:"" + th); + surp--; + return true; + } + return false; + } else { + return false; + } + } + + public static void main(String[] args) { + DanceWithGoogle codeJam = new DanceWithGoogle(); + codeJam.go(); + } +} +" +A21111,"import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; + +public class BSmall { + private int[] result; + + public BSmall() throws NumberFormatException, IOException { + readFile(); + writeOutFile(); + } + + private int[] getNum(int num, int s) { + int[] result = new int[4]; + int sur = s; + int c = 10; + result[3] = sur; + while (c != 0) { + if (num != 0) { + int i = num / c; + int r = num % c; + if (i == 3) { + if (r == 0) { + result[0] = c; + result[1] = c; + result[2] = c; + result[3] = sur; + break; + } + } + if (i == 2) { + if (c - r == 1) { + result[0] = c; + result[1] = c; + result[2] = r; + result[3] = sur; + break; + } else if (c - r == 2) { + c--; + if (c != 0) { + i = num / c; + r = num % c; + if (i == 3) { + c++; + r = num % c; + result[0] = c; + result[1] = c; + result[2] = r; + // result[3] = sur - 1; + break; + } + } + } + } + + c--; + } else { + break; + } + } + return result; + } + + private boolean containsMax(int max, int[] nums) { + for (int i = 0; i < nums.length - 1; i++) { + if (nums[i] >= max) { + return true; + } + } + return false; + } + + private int getIndex(int Max, int[] nums) { + int index = -1; + for (int i = 0; i < nums.length; i++) { + if (Math.abs(nums[i] - Max) == 1) { + return i; + } + } + return index; + } + + private boolean check(int[] nums, int num) { + boolean flag = true; + int result = 0; + for (int i = 0; i < nums.length - 1; i++) { + result += nums[i]; + boolean f = true; + int index = -1; + for (int j = i; j < nums.length - 1; j++) { + if (!(Math.abs(nums[j] - nums[i]) < 3)) { + return false; + } else { + if ((Math.abs(nums[j] - nums[i]) == 2)) { + if (!f) { + if (index != 0) { + if (nums[index] != nums[j]) { + return false; + } + } + } else { + f = false; + index = j; + } + } + } + } + } + if (result != num) { + return false; + } + return flag; + } + + private int getResult(int S, int Max, int[] numbers) { + int result = 0; + int s = S; + for (int i = 0; i < numbers.length; i++) { + int[] nums = getNum(numbers[i], s); + s = nums[3]; + boolean contain = containsMax(Max, nums); + if (!contain) { + int index = getIndex(Max, nums); + if (index != -1 && s != 0) { + int num = nums[index]; + for (int j = 0; j < nums.length; j++) { + if (index != j) { + if (num == nums[j]) { + nums[index] = num + 1; + nums[j] = nums[j] - 1; + if (nums[j] >= 0) { + boolean flag = check(nums, numbers[i]); + if (flag) { + s--; + result++; + break; + } + } + } + } + } + } + } else { + result++; + } + } + return result; + } + + private void readFile() throws NumberFormatException, IOException { + FileInputStream fis = new FileInputStream(""Input.txt""); + DataInputStream dis = new DataInputStream(fis); + result = new int[Integer.parseInt(dis.readLine())]; + int c = 0; + while (dis.available() > 0) { + String line = dis.readLine(); + String[] numbers = line.split("" ""); + int[] nums = new int[Integer.parseInt(numbers[0])]; + int s = Integer.parseInt(numbers[1]); + int Max = Integer.parseInt(numbers[2]); + for (int i = 3; i < numbers.length; i++) { + nums[i - 3] = Integer.parseInt(numbers[i]); + } + result[c] = getResult(s, Max, nums); + c++; + } + } + + private void writeOutFile() throws IOException { + FileWriter fw = new FileWriter(""Output.txt""); + for (int i = 0; i < result.length; i++) { + if (i < result.length - 1) { + fw.write(""Case #"" + (i + 1) + "": "" + result[i] + ""\n""); + } else { + fw.write(""Case #"" + (i + 1) + "": "" + result[i]); + } + } + fw.close(); + } + + public static void main(String[] args) throws NumberFormatException, + IOException { + BSmall bs = new BSmall(); + + } +} +" +A20056,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package google.code.jam.dancing.with.the.googlers; + +/** + * + * @author Lucas + */ +public class GoogleCodeJamDancingWithTheGooglers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + Utils ut = new Utils(); + BestResultFinder brf = new BestResultFinder(); + + ut.write(brf.findBestResult(ut.parse(""Input/B-large.in"")), ""Output/output""); + + } +} +" +A20266,"package codejam2012.qualification; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + + +public class ProblemB { + + public static void main(String[] args) throws IOException { + String problem = ""ProblemB""; + Scanner in = new Scanner(ClassLoader.getSystemResourceAsStream(String.format(""%s.in"", problem))); + PrintStream out = new PrintStream(String.format(""C:\\workplace\\GoogleCodeJam\\src\\codejam2012\\qualification\\%s.out"", problem)); +// out = System.out; + +// 4 +// 3 1 5 15 13 11 +// 3 0 8 23 22 21 +// 2 1 1 8 0 +// 6 2 8 29 20 8 18 18 21 + int numInputs = in.nextInt(); + in.nextLine(); + for (int i = 0; i < numInputs; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int c = 0; + for (int j = 0; j < N; j++) { + int n = in.nextInt(); + int t; + if (n % 3 == 0) { + t = n / 3; + } else { + t = n / 3 + 1; + } + if (t >= p) { + c++; + continue; + } + if (t + 1 == p && n % 3 != 1 && t != 0 && S > 0) { + c++; + S--; + } + } + out.println(""Case #"" + (i+1) + "": "" + c); +// out.println(map); + } + } +} +" +A22602,"import java.io.*; +import java.util.Scanner; + + +public class DancingGoogler { + + static String outputFile, inputFile; + public static void main(String[] args) throws IOException { + if (args.length != 2) + return; + inputFile = args[0]; + outputFile = args[1]; + + // Create FileReader Object + FileReader inputFileReader = new FileReader(inputFile); + FileWriter outputFileReader = new FileWriter(outputFile); + + // Create Buffered/PrintWriter Objects + BufferedReader inputStream = new BufferedReader(inputFileReader); + PrintWriter outputStream = new PrintWriter(outputFileReader); + + Scanner scanner; + String inLine = null; + int cases = Integer.parseInt(inputStream.readLine().trim()); + + int num, surprising, score; + int[] scores; + for (int i = 1; i < cases + 1; i++) { + inLine = inputStream.readLine().trim(); + scanner = new Scanner(inLine); + num = scanner.nextInt(); + surprising = scanner.nextInt(); + score = scanner.nextInt(); + scores = new int[num]; + for (int j=0; j= totalTarget-2) numBest++; + else if (totalTarget > 3 && scores[i] >= totalTarget-4 ) { + if (surprising>0){ + numBest++; + surprising--; + } + } + } + return numBest; + } + +} +" +A22449,"import sun.reflect.generics.tree.Tree; + +import java.util.ArrayList; +import java.util.List; + +public class MathUtil { + static List convertToBase (int num, int base) { + ArrayList integers = new ArrayList<>(); + if (num == 0) { + integers.add(0); + return integers; + } + + while (num!=0) { + integers.add(num % base); + num /= base; + } + + return integers; + } + + static int sumList(Iterable iterable) { + int sum = 0; + for (Integer integer : iterable) { + sum += integer; + } + return sum; + } + + static int sumSquaredList(Iterable iterable) { + int sum = 0; + for (Integer integer : iterable) { + sum += integer * integer; + } + return sum; + } +} +" +A22425,"package problem1; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; + + + + + +public class Problem1 { + + public static void main(String[] args) throws FileNotFoundException, IOException{ + try { + TextIO.readFile(""L:\\Coodejam\\Input\\Input.txt""); + } + catch (IllegalArgumentException e) { + System.out.println(""Can't open file ""); + System.exit(0); + } + + FileOutputStream fout = new FileOutputStream(""L:\\Coodejam\\Output\\output.txt""); + PrintStream ps=new PrintStream(fout); + + int cases=TextIO.getInt(); + int googlers=0,surprising=0,least=0; + for(int i=0;i0;j++){ + if(biggestNS(score[j])=least)counter++; + + } + + ps.println(""Case #""+(i+1)+"": ""+counter); + } + } + + static int biggestNS(int x){ + if(x==0)return 0; + if(x==1)return 1; + return ((x-1)/3)+1; + } + + static int biggestS(int x){ + if(x==0)return 0; + if(x==1)return 1; + return ((x-2)/3)+2; + } +}" +A20952,"package org.moriraaca.codejam; + +import java.io.File; +import java.io.InputStream; +import java.io.PrintStream; + +public abstract class AbstractSolver { + protected final String RESOURCE_FOLDER = ""src/main/resources/""; + + /* Config */ + protected final String defaultInputFileName; + + protected final OutputDestination outputDestination; + + protected final DebugOutputLevel debugOutputLevel; + + protected final Class dataParserClass; + + protected PrintStream output; + + protected PrintStream getOutput() { + if (output == null) { + try { + switch (outputDestination) { + case STDOUT: + output = System.out; + break; + case FILE: + output = new PrintStream(new File( + defaultInputFileName.replaceAll(""\\.in"", ""\\.out""))); + default: + break; + } + } catch (Exception rethrow) { + throw new Error(""Fatal error on initialization of output"", + rethrow); + } + } + + return output; + } + + public AbstractSolver() { + try { + SolverConfiguration config = getClass().getAnnotation( + SolverConfiguration.class); + debugOutputLevel = config.debugOutputLevel(); + outputDestination = config.outputDestination(); + defaultInputFileName = config.inputFileName(); + dataParserClass = config.parser(); + + } catch (Exception log) { + log.printStackTrace(); + throw new Error(""Fatal error on initialization"", log); + } + } + + public void write(String msg, DebugOutputLevel level) { + if (level.ordinal() <= debugOutputLevel.ordinal()) { + getOutput().print(msg); + } + } + + public final String solve() { + return solve(defaultInputFileName); + } + + @SuppressWarnings(""unchecked"") + public final String solve(String fileName) { + try { + AbstractDataParser dataParser = dataParserClass.getConstructor( + InputStream.class).newInstance( + getClass().getClassLoader().getResourceAsStream(fileName)); + + StringBuilder result = new StringBuilder(); + + for (int i = 0; i < dataParser.getTestCases().length; i++) { + result.append(""Case #"") + .append(i + 1) + .append("": "") + .append(solveTestCase((TC) dataParser.getTestCases()[i])) + .append(""\n""); + } + + return result.toString(); + } catch (Exception e) { + throw new Error(""Fatal error on solve"", e); + } + } + + public final void getSolution() { + write(solve(), DebugOutputLevel.SOLUTION); + } + + protected abstract String solveTestCase(TC testCase); +} +" +A21494,"package cj2012; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Scanner; + +public class b { + + static PrintWriter pw; + static int testOut = 1; + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(new FileReader( + ""C://CODEJAM//2012//B-small-0.in"")); + pw = new PrintWriter(new FileWriter(""C://CODEJAM//2012//B-small-0.out"")); + + int ntest = sc.nextInt(); + + for (int test = 1; test <= ntest; ++test) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + // System.out.print(N+"".""+S+"".""+p+"".""); + + int y = 0; + + for (int i = 1; i <= N; i++) { + int t = sc.nextInt(); + + // System.out.print(t+"",""); + if (t >= p) { + + if (t >= ((3 * p) - 2)) { + y++; + } else if ((t >= ((3 * p) - 4)) && (S > 0)) { + y++; + S--; + } + } + + } + + // System.out.println(); + wc("""" + y); + } + + pw.close(); + sc.close(); + System.out.println(""finished""); + } + + private static void wc(String text) { + String tt = ""Case #"" + testOut++ + "": "" + text; + pw.print(tt); + pw.println(); + System.out.println(tt); + } +} +" +A22655,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +public class DancingGooglers { + + static BufferedWriter out; + private static int countMaxScores = 0; + + public static void main(String[] args) { + System.out.print(""Start\n""); + + // Prepare the writer + try { + FileWriter fstream; + fstream = new FileWriter(""resultfinallarge.txt""); + out = new BufferedWriter(fstream); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // Prepare the reader + try { + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); + + // Read the count of testcases + int testcases = Integer.parseInt(reader.readLine()); + + for (int i = 0; i < testcases; i++) { + countMaxScores = 0; + int countwinners = doYourThing(reader.readLine()); + out.write(""Case #"" + (i + 1) + "": "" + countwinners + ""\n""); + } + + } catch (FileNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // Close the output stream + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private static Integer doYourThing(String readLine) { + // System.out.print(readLine +""\n""); + String parts[] = readLine.split("" ""); + int countgooglers = Integer.parseInt(parts[0]); + int suprising = Integer.parseInt(parts[1]); + int maxscore = Integer.parseInt(parts[2]); + + ArrayList surprisings = new ArrayList(); + surprisings.clear(); + + // First get all the obvious winners + for (int i = 0; i < countgooglers; i++) { + int j = i + 3; + int score = Integer.parseInt(parts[j]); + + if (score >= maxscore) { + if (score >= ((maxscore * 3) - 2)) { + countMaxScores++; + } else if (score <= ((maxscore * 3) - 5)) { + // Finding the obvious loser + System.out.print(""Loser "" + score + ""\n""); + } else { + surprisings.add(score); + } + } + } + if (surprisings.size() >= suprising) { + return countMaxScores + suprising; + } else { + return countMaxScores + surprisings.size(); + } + + } +} +" +A21043,"import java.util.Scanner; + + +public class ProblemB { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int[][] maxs = genmaxs(); + + // check correct maxs + //for(int i = 0; i < maxs.length; i++){ + // System.out.println(i + "": "" + maxs[i][0] + "" "" + maxs[i][1]); + //} + + int T = sc.nextInt(); + + for(int i = 0; i < T; i++){ + int v = processCase(sc, maxs); + + System.out.println(""Case #"" + (i+1) + "": "" + v); + } + } + + public static int processCase(Scanner sc, int[][] maxs){ + int numGooglers = sc.nextInt(); // N + int numSurprising = sc.nextInt(); // S + int maxBest = sc.nextInt(); // p + + int numPure = 0; + int numImpure = 0; + + int[] pts = new int[numGooglers]; + + // find the number of pure vals + for(int i = 0; i < pts.length; i++){ + pts[i] = sc.nextInt(); + + // check to see if purely reached + if(maxs[pts[i]][0] >= maxBest){ + numPure++; + } else if(maxs[pts[i]][1] >= maxBest) { + numImpure++; + } + } + + if(numImpure > numSurprising) numImpure = numSurprising; + + return numPure + numImpure; + } + + public static int[][] genmaxs(){ + int[][] maxs = new int[31][]; + + // set up high maximums + for(int i = 0; i < maxs.length; i++){ + maxs[i] = new int[]{0,0}; + } + + // loop through the triples + for(int i = 0; i < 11; i++){ + for(int j = 0; j < 11; j++){ + for(int k = 0; k < 11; k++){ + int sum = i + j + k; + int max = max(i, j, k); + + // find the max value in each reg and supr triple for a val + if(isReg(i, j, k) && max > maxs[sum][0]){ + maxs[sum][0] = max; + } + if(isSupr(i, j, k) && max > maxs[sum][1]){ + maxs[sum][1] = max; + } + } + } + } + + return maxs; + } + + public static int max(int i, int j, int k){ + return Math.max(i, Math.max(j, k)); + } + + public static boolean isReg(int i, int j, int k){ + return bigDiff(i, j, k, 1); + } + + public static boolean isSupr(int i, int j, int k){ + return bigDiff(i, j, k, 2); + } + + public static boolean bigDiff(int i, int j, int k, int diff){ + return Math.abs(i - j) <= diff && Math.abs(j - k) <= diff && Math.abs(k - i) <= diff; + } + +} +" +A21793,"/** + * Created by IntelliJ IDEA. + * User: ashevenkov + * Date: 14.04.12 + * Time: 11:17 + */ +package codejam.codejam2012; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Arrays; + +/** + * @author ashevenkov + */ +public class QualificationB { + + public static void main(String[] args) throws Exception { + new QualificationB().calculate( + ""/home/ashevenkov/projects/codejam/B-large.in"", + ""/home/ashevenkov/projects/codejam/B-large.out""); + } + + public void calculate(String in, String out) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(in)); + FileWriter fw = new FileWriter(out); + String line = br.readLine(); + int cases = Integer.parseInt(line); + for(int i = 0; i < cases; i++) { + line = br.readLine(); + String[] parts = line.split("" ""); + int N = Integer.parseInt(parts[0]); + int S = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + int[] t = new int[N]; + for(int j = 3; j < parts.length; j++) { + t[j - 3] = Integer.parseInt(parts[j]); + } + String result = dance(S, p, t); + System.out.println(""Case #"" + (i + 1) + "": "" + result); + fw.write(""Case #"" + (i + 1) + "": "" + result); + fw.write(""\n""); + } + fw.flush(); + fw.close(); + } + + private String dance(int s, int p, int[] t) { + int result = 0; + int a1 = p + p - 1 + p - 1; + int a2 = p + p - 2 + p - 2; + if(p == 0) { + return Integer.toString(t.length); + } + if(p == 1) { + a1 = 1; + a2 = 1; + } + Arrays.sort(t); + boolean firstPhase = true; + boolean secondPhase = false; + int leftSurprise = s; + for(int i = t.length - 1; i >= 0; i--) { + int num = t[i]; + if(firstPhase) { + if(num >= a1) { + result++; + } else { + firstPhase = false; + secondPhase = true; + } + } + if(secondPhase) { + if(num >= a2 && leftSurprise > 0) { + result++; + leftSurprise--; + } else { + return Integer.toString(result); + } + } + } + return Integer.toString(result); + } + +} +" +A22373,"/* + * CodeJamTester1A.java + * + * Created on 28.07.2008, 14:20:39 + * + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package qualification; +import java.util.*; +import java.io.*; +import java.math.*; + +/** + * + * @author Besitzer + */ +public class CodeJamQuali { + int testcases; + String dict=""yhesocvxduiglbkrztnwjpfmaq""; + BufferedReader BR; + BigInteger ZERO =BigInteger.ZERO; + BigInteger ONE =BigInteger.ONE; + BigInteger TWO =new BigInteger(""2""); + BigInteger THREE =new BigInteger(""3""); + + public void sort(long[] a){ + for(int i=0;imax){max=a[j];minAt=j;} + } + //System.out.println(""maxAT:""+minAt+"" max: ""+max); + if(minAt>-1){ + long buf =a[i]; + a[i]=a[minAt]; + a[minAt]=buf; + } + } + } + + public void fillDict(String E, String G, char[] C){ + for(int i=0;i1 ? incbound :1; + for(int i =0;i=3*p-2){ + ok++; + }else{ + if(cur>=incbound)incable++; + } + } + S=S0){ + buf= (6*cur-4*prev)%1000; + if(buf<0)buf=(10000+buf)%1000; + prev=cur;cur=buf; + n0--; + // abuse periority of the pairs + if((prev==144)&&(cur==752)&&(n-n0!=4)){ + System.out.println(n-n0-4); + n0=n0%(n-n0-4); + } + } + String S= """"+(cur+999)%1000; + while(S.length()<3)S=""0""+S; + return S; + } + + public void go(String filename,int exerciseNr){ + java.io.File F = new java.io.File(filename); + try{ + BR = new BufferedReader(new FileReader(F)); + BufferedWriter BW= new BufferedWriter(new FileWriter(new File(""output.txt""))); + int cases = Integer.parseInt(BR.readLine()); + for(int i=0;i map = new HashMap(); + for(int i = 0; i < lineArr.length; ++i){ + if(lineArr[i] == ' ') + continue; + System.out.println(""map.put('"" + lineArr[i] + ""','"" + oplinesArr[i] + ""');""); + map.put(lineArr[i], oplinesArr[i]); + } + + + System.out.println(map.keySet().size()); + System.out.println(new TreeSet(map.keySet())); + System.out.println(new TreeSet(map.values())); + + } + +} +" +A20994,"package fixjava; + +/** + * Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method + * in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in + * Java. + */ + +public interface Lambda4 { + public V apply(P param1, Q param2, R param3, S param4); +} +" +A21273,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Dancing_with_the_googlers { + public static int s; + + public static int max(int x, int s, final int sMax, int p) { + int tmp, i = 0, mm = 0, maxx = 0, j = 0, xDIV = 0, min = 1000, k = 0; + xDIV = Math.round(x / 3); + mm = 1; + maxx = xDIV; + for (i = -1 * mm; i <= mm; i++) { + for (j = -1 * mm; ((j <= mm) && (Math.abs(i - j) <= mm)); j++) { + for (k = 0; k <= mm; k++) { + tmp = (xDIV + k) + (xDIV + i) + (xDIV + j); + // System.out.println(""tmp = ""+xDIV+"" + ""+ (xDIV+i)+ + // "" + ""+(xDIV+j)); + if ((x == tmp) && (xDIV + i >= 0) && ((xDIV + j) >= 0) + && ((xDIV + j) <= 10) && ((xDIV + i) <= 10) + && ((xDIV + k) >= 0) && ((xDIV + k) <= 10)) { + if ((xDIV + i) > maxx) { + maxx = xDIV + i; + } + if ((xDIV + i) < min) { + min = xDIV + i; + } + if ((xDIV + j) < min) { + min = xDIV + j; + } + if ((xDIV + j) > maxx) { + maxx = xDIV + j; + } + if ((xDIV + k) < min) { + min = xDIV + j; + } + if ((xDIV + k) > maxx) { + maxx = xDIV + j; + } + + } + } + } + } + if ((maxx < p) && (Dancing_with_the_googlers.s < sMax)) { + mm = 2; + // maxx = xDIV; + for (i = -1 * mm; i <= mm; i++) { + for (j = -1 * mm; (j <= mm) && (Math.abs(i - j) <= mm); j++) { + for (k = -1 * mm; k <= mm; k++) { + tmp = (xDIV + k) + (xDIV + i) + (xDIV + j); + // System.out.println(""tmp = ""+xDIV+"" + ""+ (xDIV+i)+ + // "" + ""+(xDIV+j)); + + if ((x == tmp) && (xDIV + i >= 0) && ((xDIV + j) >= 0) + && ((xDIV + j) <= 10) && ((xDIV + i) <= 10) + && ((xDIV + k) >= 0) && ((xDIV + k) <= 10)) { + if ((xDIV + i) > maxx) { + maxx = xDIV + i; + } + if ((xDIV + i) < min) { + min = xDIV + i; + } + if ((xDIV + j) < min) { + min = xDIV + j; + } + if ((xDIV + j) > maxx) { + maxx = xDIV + j; + } + if ((xDIV + k) < min) { + min = xDIV + j; + } + if ((xDIV + k) > maxx) { + maxx = xDIV + j; + } + } + } + } + } + } + if (maxx - min >= 2) + Dancing_with_the_googlers.s = Dancing_with_the_googlers.s + 1; + return maxx; + } + + public static void main(String[] args) { + String filename = ""/myown/developpement/Google_Code_Jam/Dancing_With_the_Googlers.in""; + StringTokenizer st1; + String ligne = """"; + int T = 0, j = 0, N = 0, S = 0, p = 0, i = 0, s = 0, y = 0; + s = 0; + int[] t; + try { + FileInputStream fStream = new FileInputStream(filename); + BufferedReader in = new BufferedReader(new InputStreamReader( + fStream)); + if (in.ready()) { + ligne = in.readLine(); + T = Integer.parseInt(ligne); + for (j = 0; j < T; j++) { + Dancing_with_the_googlers.s = 0; + y = 0; + ligne = in.readLine(); + st1 = new StringTokenizer(ligne, "" ""); + N = Integer.parseInt(st1.nextToken()); + S = Integer.parseInt(st1.nextToken()); + p = Integer.parseInt(st1.nextToken()); + t = new int[N]; + for (i = 0; i < N; i++) { + t[i] = Integer.parseInt(st1.nextToken()); + + if (max(t[i], s, S, p) >= p) + y++; + // System.out.println(""Ligne: "" + i + "" = "" + t[i] + + // "" = ""+ max(t[i], s, S,p)); + } + System.out.println(""Case #"" + (j + 1) + "": "" + y); + } + } + + } catch (IOException e) { + System.out.println(""File input error""); + } + } +} +" +A21945,"import java.io.*; +import java.util.*; + +public class B +{ + public static void main(String[] args) throws Exception + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int numCases = Integer.parseInt(br.readLine()); + + for(int i = 0; i < numCases; i++) { + solveCase(i+1, br.readLine()); + } + } + + private static void solveCase(int caseNum, String line) { + String[] parts = line.split("" ""); + int numGooglers = Integer.parseInt(parts[0]); + int numSurprising = Integer.parseInt(parts[1]); + int minScore = Integer.parseInt(parts[2]); + + ArrayList scores = new ArrayList(numGooglers); + for(int i = 0 ;i < numGooglers; i++) { + scores.add(Integer.parseInt(parts[i+3])); + } + + //System.out.println(numSurprising +"" surprising""); + //System.out.println(""scores: ""+ scores); + + System.out.println(""Case #""+caseNum+"": ""+solve(minScore, scores, 0, numSurprising, 0)); + } + + private static int solve(int minScore, ArrayList scores, int index, int surprisesRemaining, int result) { + if(index == scores.size()) { + return result; + } + + if(solveWithoutSurprise(minScore, scores.get(index))) { + result++; + } else if(surprisesRemaining > 0 && solveWithSurprise(minScore, scores.get(index))) { + result++; + surprisesRemaining--; + } + + return solve(minScore, scores, index + 1, surprisesRemaining, result); + } + + private static boolean solveWithoutSurprise(int minScore, int totalScore) { + if(minScore ==0) { + return true; + } + if(totalScore == 0) { + return false; + } + + int scoresTo = totalScore - 1; + int each = scoresTo / 3; + if(each + 1 >= minScore) { + return true; + } + return false; + } + + private static boolean solveWithSurprise(int minScore, int totalScore) { + if(totalScore == 0) { + return false; + } + + int scoresTo = totalScore - 2; // if total score was < 2, would have been true from WithoutSurprise + int each = scoresTo / 3; + int remainder = scoresTo % 3; + if(remainder == 0 || remainder == 1) { + if(each + 2 >= minScore) { + return true; + } + return false; + } else { // remainder ==2 + //System.out.println(""totalScore=""+totalScore+"": SHOULD NEVER HAPPEN!!!!!!!!!!!! SHOULD ALWAYS BE ABLE TO SOLVE WIHTOUT SURPIRSE!!!""); + } + return false; + } +}" +A22654,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + + +public class QualifiRound2012B { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try { + BufferedReader br = new BufferedReader(new FileReader(args[0])); + PrintWriter pw = new PrintWriter(args[1]); + String line = br.readLine(); + System.out.println(line); + int T = Integer.valueOf(line.trim()); + for (int i=0; i=p) + good++; + else if(S>0) + { + if(score==0) + { + if(p==0) + good++; + } + else if((score%3 != 2)&&(score/3+1>=p) + ||(score%3 == 2)&&(score/3+2>=p)) + { + good++; + S--; + } + + } + } + + pw.println(""Case #""+(i+1)+"": ""+good); + System.out.println(""Case #""+(i+1)+"": ""+good); + } + pw.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} +" +A21339,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Scanner; +public class Dancers { + + public static void main(String[] args) throws Exception { + PrintWriter out = new PrintWriter(""output.out""); + Scanner in = new Scanner(new File(""B-small-attempt5.in"")); + int testCases = in.nextInt(); + for (int i = 1; i <= testCases; i++){ + int N = in.nextInt(),counter=0; + int S = in.nextInt(); + int P = in.nextInt(); + for(int j = 0 ; j < N ;j++){ + int googler= in.nextInt(); + if(googler%3 == 0){ + if(googler/3 >= P){ + counter++; + } + else if(googler/3 + 1 >= P && S!=0){ + counter++; + S--; + } + } + else if(googler%3==1){ + if(googler/3 + 1 >= P){ + counter++; + } + } + else if(googler%3==2){ + if(googler/3 + 1 >= P){ + counter++; + } + else if(googler/3 + 2 >= P && S!=0){ + counter++; + S--; + } + } + } + out.printf(""Case #%d: %d"",i,counter); + out.printf(""\n""); + } + out.close(); + in.close(); + + } + +}" +A20039,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Main { + + /** + * @param args + * @throws FileNotFoundException + */ + + public static void main(String[] args) throws FileNotFoundException { + // TODO Auto-generated method stub + Scanner reader = new Scanner(new File(""B-large.in"")); + PrintWriter writer = new PrintWriter(new File(""output.txt"")); + int cases = reader.nextInt(); + for (int i=0; i= P) { + X++; + } else if (K < S && base > 0 && (base + 1) >= P) { + K++; + X++; + } + break; + case 1: + if (base >= P || (base + 1) >= P) { + X++; + } else if (K < S && (base + 1) >= P) { + K++; + X++; + } + break; + case 2: + if ((base + 1) >= P || base >= P) { + X++; + } else if (K < S && (base + 2) >= P) { + K++; + X++; + } + break; + } + } + writer.println(""Case #"" + (i+1) + "": "" + X); + } + System.out.println(""done""); + reader.close(); + writer.close(); + } + +} +" +A20937,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class googlers { + + private static String[] casos; + + private static String[] respuestas; + + private static int cantidadPuntajesSorprendentes; + + private static boolean pudoObtenerPuntaje(int puntaje, int total) + { + if(total == 0) + return puntaje == 0; + int umbralNormal = (puntaje-1) * 3 + 1; + int umbralSorprendente = (puntaje-1) * 3 - 1; + if(total >= umbralNormal) + return true; + if(cantidadPuntajesSorprendentes > 0 && total >= umbralSorprendente) + { + cantidadPuntajesSorprendentes --; + return true; + } + return false; + } + + private static int maximaCantidadConMinimoPuntaje(int minimoPuntaje, int[] puntajes) { + int respuesta = 0; + for(int i=0; i=0) + { + answer++; + } + } + } + else + { + if(p==1) + { + for(int iii=3;iii=valid) + { + answer++; + } + } + } + else + { + valid=p*3-4; + for(int j=3;j(valid+1)) + { + answer++; + } + else + { + if(((arr[j]==valid)||(arr[j]==(valid+1)))&&(surprising= max) + return true; + + if(third == max - 2) + if(rem == 2){ + if(surprise > 0){ + surprise --; + return true; + } + return false; + } + else + return false; + + if(third == max - 1) + if(rem > 0) + return true; + else if(surprise > 0 && third > 0){ + surprise --; + return true; + } + + return false; + } + +} +" +A20712,"package dancing; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + +public class Dance { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""out.txt"")); + + int T = Integer.parseInt(br.readLine().trim()); + + for(int t = 1; t<=T; t++){ + String[] s = br.readLine().trim().split("" ""); + int N = Integer.parseInt(s[0]); + int S = Integer.parseInt(s[1]); + int P = Integer.parseInt(s[2]); + int[] ps = new int[N]; + for(int i = 3; i < s.length; i++){ + ps[i-3] = Integer.parseInt(s[i]); + } + List l = new ArrayList(); + int res = 0; + for(int p : ps){ + if(p == 0){ + l.add(new Integer[]{0, 0, 0}); + continue; + } + if(p%3 == 0){ + if(p/3 >= P || p/3<=(P-2) || S<=0){ + l.add(new Integer[]{p/3, p/3, p/3}); + }else{ + l.add(new Integer[]{p/3, p/3-1, p/3+1}); + S--; + } + }else if(p%3 == 1){ + l.add(new Integer[]{p/3, p/3, p/3+1}); + }else{ + if(p/3 == 9){ + l.add(new Integer[]{p/3+1, p/3+1, p/3}); + }else{ + if(p/3 >= P || p/3<(P-2)){ + l.add(new Integer[]{p/3+1, p/3+1, p/3}); + }else{ + if (S<=0){ + l.add(new Integer[]{p/3+1, p/3+1, p/3}); + }else{ + l.add(new Integer[]{p/3, p/3, p/3+2}); + S--; + } + } + } + } + } +// +// for(Integer[] arr: l) System.out.println(Arrays.toString(arr)); +// System.out.println(""""); + + for(Integer[] arr: l){ + if(arr[0]>=P || arr[1]>=P || arr[2]>=P){ + res++; + } + } + bw.write(""Case #""+t+"": ""+res); + bw.newLine(); + } + + br.close(); + bw.close(); + } +} +" +A22559,"package com.piscessera.google.codejam.q02; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; + +public class Q2 { + + private int t; // 0-100 + + private int[] answer; + + public Q2() { + } + + public Q2(int testcase) { + this.t = testcase; + this.answer = new int[this.t]; + } + + public void startProcess(String filename) { + try { + File inFile = new File(""C://"" + filename + "".in""); + + if (inFile.exists()) { + int lineNumber = 0; + int input = 0; + String[] question = null; + InputStream in = new FileInputStream(inFile); + BufferedReader br = new BufferedReader(new InputStreamReader( + in, ""utf-8""), 8); + + StringBuffer sb = new StringBuffer(); + + String line = null; + while ((line = br.readLine()) != null) { + if (lineNumber == 0) { + input = Integer.parseInt(line); + question = new String[input]; + } else if (lineNumber > input) { + continue; + } else { + question[lineNumber - 1] = line; + } + lineNumber++; + } + + this.t = input; + this.answer = new int[this.t]; + int count = 0; + for (String q : question) { + String[] vars = q.split("" ""); + + int[] scores = new int[vars.length - 3]; + for (int i = 0; i < scores.length; i++) { + scores[i] = Integer.parseInt(vars[i + 3]); + } + this.answer[count] = calculate(Integer.parseInt(vars[0]), + Integer.parseInt(vars[1]), + Integer.parseInt(vars[2]), scores); + count++; + } + + // set output + StringBuffer outSb = new StringBuffer(); + int index = 0; + for (int answer : this.answer) { + outSb.append(""Case #"" + (index + 1) + "": "" + answer + ""\n""); + index++; + } + + Writer out = new OutputStreamWriter(new FileOutputStream(""C://"" + + filename + "".out""), ""utf-8""); + out.write(outSb.toString()); + out.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public int calculate(int googlers, int surprising, int minScore, + int[] scores) { + int result = 0; + + int index = 0; + for (int score : scores) { + int base = score / 3; + // int[] realScore = { base, base, base }; + + // find score + switch (score % 3) { + case 0: + // realScore[0] = base - 1; + // realScore[1] = base; + // realScore[2] = base + 1; + + if (base >= minScore) { + result++; + } else { + if (surprising > 0 && base > 0 && (base + 1) >= minScore) { + surprising--; + result++; + } + } + break; + case 1: + // realScore[0] = base - 1; + // realScore[1] = base + 1; + // realScore[2] = base + 1; + + if (base >= minScore || base + 1 >= minScore) { + result++; + } else { + if (surprising > 0 && (base + 1) >= minScore) { + surprising--; + result++; + } + } + + break; + case 2: + // realScore[0] = base; + // realScore[1] = base; + // realScore[2] = base + 2; + + if (base >= minScore || base + 1 >= minScore) { + result++; + } else { + if (surprising > 0 && (base + 2) >= minScore) { + surprising--; + result++; + } + } + break; + } + index++; + } + System.out.println(""Result: "" + result); + + return result; + } + + public static void main(String[] args) { + Q2 obj = new Q2(); + obj.startProcess(""codejam/B-small-attempt4""); + } + +} +" +A21809,"import java.io.*; +import java.util.*; + +public class B { + public static final String INPATH = ""input2.in""; + public static final String OUTPATH = ""output2.out""; + + public static void main (String[] args) throws FileNotFoundException { + Scanner inscan = new Scanner (new File (INPATH)); + PrintStream out = new PrintStream (new File (OUTPATH)); + + int T = inscan.nextInt(); + inscan.nextLine(); + + for (int i=1; i <= T; i++) { + int result = compute (inscan.nextLine()); + out.println(""Case #"" + i + "": "" + result); + } + } + + public static int compute (String line) { + Scanner linescan = new Scanner (line); + int N = linescan.nextInt(); + int S = linescan.nextInt(); + int p = linescan.nextInt(); + + if (p == 0) { + return N; + } + + int count = 0; + for (int i=0; i < N; i++) { + int t = linescan.nextInt(); + + if (t >= 3*p - 2) { + count++; + } else if (3*p - 4 <= t && t <= 3*p - 3 && S > 0 && !(p == 1 && t == 0)) { + count++; + S--; + } + } + + return count; + } + +}" +A21699,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; + + +public class GooglerScores { + + + public static void main(String args[]) throws FileNotFoundException { + + ////////////////////////////////////// + // Begin Code Jam regular code // + ////////////////////////////////////// + + Scanner inFile = new Scanner(new File(""B-large.in"")); + PrintStream outFile = new PrintStream(new File(""B-large-out.txt"")); + + int numCases = inFile.nextInt(); + inFile.nextLine(); // Gets rid of newline char + + ////////////////////////////////////// + // End Code Jam regular code // + ////////////////////////////////////// + + for(int i=1; i<=numCases; i++) { + + int numGooglers = inFile.nextInt(); + int maxNumSurprising = inFile.nextInt(); + int leastValid = inFile.nextInt(); + + int validGooglers = 0; + int validSurprising = 0; + + for(int j=0; j= leastValid) return true; + } + return false; + } + +} +" +A21589,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Formatter; +import java.util.Scanner; + +public final class DancingWithTheGooglers { + + private static String solve(final int N, int S, final int p, int points[]) { + int res = 0; + for (int t:points) { + switch (t%3) { + case 0: + if (t/3>=p) res++; + else if (t >= 3 && t<30 && t>=3 && t/3+1>=p && S>0) { res++; S--; } + break; + case 1: + if (t/3+1>=p) res++; + break; + case 2: + if (t/3+1>=p) res++; + else if (t<29 && t/3+2>=p && S>0) { res++; S--; } + break; + } + } + return """"+res; + } + + public static void main(String[] args) throws FileNotFoundException { + //String filename = ""B-test.in""; + //String filename = ""B-small-attempt0.in""; + String filename = ""B-large.in""; + assert filename.endsWith("".in""); + Scanner in = new Scanner(new File(filename)); + Formatter out = new Formatter(new File(filename.replace("".in"", "".out""))); + + assert in.hasNext(); + int T = in.nextInt(); + in.nextLine(); + for (int t = 0; t < T; t++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int points[] = new int[N]; + for (int i = 0; i < N; i++) + points[i] = in.nextInt(); + + String ans = solve(N, S, p, points); + + String result; + if (t < T - 1) + result = String.format(""Case #%d: %s%n"", t + 1, ans); + else + result = String.format(""Case #%d: %s"", t + 1, ans); + out.format(result); + System.out.format(result); + } + + out.flush(); + out.close(); + } + +} +" +A21702,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class Dancing_With_the_Googlers { + + /** + * @param args + */ + public static void main(String[] args) { + String strFileName = ""B-large""; + String strInputFileName = strFileName + "".in""; + String strOutputFileName = strFileName + "".out""; + int iCaseNumber = 1; + + try { + //////////////////////////////////////////////////////////////// + BufferedReader in = new BufferedReader(new FileReader(strInputFileName)); + BufferedWriter out = new BufferedWriter(new FileWriter(strOutputFileName)); + String inString = """"; + String outString = """"; + + String sTotalNumber = in.readLine(); + + while ((inString = in.readLine()) != null) { + //System.out.println(inString); + + String[] sArray = inString.split("" ""); + int iNumCount = Integer.parseInt(sArray[0]); + int iSurprisingNum = Integer.parseInt(sArray[1]); + int iStandardNum = Integer.parseInt(sArray[2]); + int iResultCount = 0; + + for (int idx = 3; idx < iNumCount + 3; idx++) { + int iTarget = Integer.parseInt(sArray[idx]); + + // ÃÑ ÇÕ¿¡¼­, ±âÁØ°ªÀ» »©°í, ³ª¸ÓÁö¸¦ ±¸ÇÑ´Ù. + // ±× ³ª¸ÓÁö°¡, Â÷ÀÌ°ª + int iRemain = iTarget - iStandardNum; + int iCompare = (iStandardNum - 1) * 2; + int iCompareSecond = (iStandardNum - 2) * 2; + + if (iRemain < 0) { + continue; + } + + if (iRemain >= iCompare) { + iResultCount++; +// System.out.println(String.format(""iTarget:[%d], iRemain:[%d], iCompare[%d], iNumCount:[%d], iSurprisingNum:[%d], iStandardNum:[%d],"" +// ,iTarget,iRemain, iCompare, iNumCount, iSurprisingNum, iStandardNum)); + } + else if (iSurprisingNum > 0 && iRemain >= iCompareSecond) { + iResultCount++; + iSurprisingNum--; +// System.out.println(String.format(""iTarget:[%d], iStandardNum[%d] iRemain:[%d], iCompareSecond[%d], iNumCount:[%d], iSurprisingNum:[%d], iStandardNum:[%d],"" +// ,iTarget,iStandardNum,iRemain, iCompareSecond, iNumCount, iSurprisingNum, iStandardNum)); + } + } + + outString = String.format(""Case #%d: %d\n"", iCaseNumber++, iResultCount); + System.out.print(outString); + out.write(outString); + } + in.close(); + out.close(); + //////////////////////////////////////////////////////////////// + } catch (IOException e) { + System.err.println(""ERROR""); + System.err.println(e); // ¿¡·¯°¡ ÀÖ´Ù¸é ¸Þ½ÃÁö Ãâ·Â + System.exit(1); + } + } +} +" +A20038," +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + + +public class DancingWithGooglers1 extends Thread{ + + //private static int rating[] = {0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; + private static int totalJudge = 3; + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + new DancingWithGooglers1().parseFile(); + + + + } + + public void parseFile() throws Exception + { + File file = null; + FileReader reader = null; + BufferedReader br = null; + + File outFile = null; + PrintWriter prntWriter = null; + try { + file = new File(""B-large.in""); + reader = new FileReader(file); + br = new BufferedReader(reader); + + outFile = new File(""B-large.out""); + prntWriter = new PrintWriter(outFile); + + + String str = """"; + int liTotalCases = 0; + if((str = br.readLine())!=null) + { + liTotalCases = Integer.parseInt(str); + //System.out.println('liTotalCases::: '+liTotalCases); + for(int i=0;i> finalRat = new ArrayList>(); + for(int j=3;j rsSet = isGooglerWithBestResult(Integer.valueOf(strArr[j]), bestResult,totalSurprise); + System.out.println(rsSet); + finalRat.add(rsSet); + + } + System.out.println(""final: ""+finalRat); + + List> orderedSet = new ArrayList>(); + + for(List res:finalRat){ + if(totalMax(res, bestResult)==res.size()) { + noOfGooglerWithBest++; + } + else { + orderedSet.add(res); + } + } + System.out.println(""orderedSet:: ""+orderedSet); + for(List remainingSet:orderedSet){ + for(RatingSet rs:remainingSet){ + if(totalSurprise>0 && rs.isSurprisingCondition() && rs.isHavingBestScore(bestResult)) { + noOfGooglerWithBest++; + totalSurprise--; + break; + } else { + + } + } + } + + System.out.println(""Case #""+ (i+1) + "": ""+ noOfGooglerWithBest); + prntWriter.write(""Case #""+ (i+1) + "": ""+ noOfGooglerWithBest +""\n""); + prntWriter.flush(); + //System.out.println('-------------------End----------------------------------'); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + finally{ + if(reader!=null) + reader.close(); + if(br!=null) + br.close(); + + if(prntWriter!=null) + prntWriter.close(); + } + } + + + private int totalMax(List res,int bestScore){ + int totalBest = 0; + for(RatingSet r:res) { + if(r.isHavingBestScore(bestScore)){ + totalBest++; + } + } + System.out.println(totalBest); + return totalBest; + + } + + public List isGooglerWithBestResult(int totalScore, int bestResult,int totalSurprise) { + System.out.println(""totalScore: ""+totalScore); + + int n = totalScore/totalJudge; + ArrayList set = new ArrayList(); + for(int i=-2;i<=2;i++){ + if(n-i>=0 && n-i<=10) + set.add(n-i); + } + + List rsSet = findPosibleSubSets(set, bestResult, totalScore, totalSurprise); + + + return rsSet; + } + + private List findPosibleSubSets(ArrayList set,int bestResult,int totalScore,int totalSurprise){ + List allSetList = new ArrayList(); + + List rattingSet = getListOfRatingSet(set); + + for(RatingSet rs:rattingSet) { + if(rs.getTotal()==totalScore && rs.isValidRating()){ + allSetList.add(rs); + } + } + + return allSetList; + } + + private List getListOfRatingSet(ArrayList set){ + List rattingSet= new ArrayList(); + + for(int i=0;i=bestScore) { + return true; + } + else if(r2>=bestScore) { + return true; + } + else if(r3>=bestScore) { + return true; + } + else { + return false; + } + } + + public boolean isSurprisingCondition() { + if(maxRating()-minRating()==2){ + return true; + } else { + return false; + } + } + + @Override + public String toString() { + return ""{"" + r1 + "","" + r2 + "","" + r3 + ""}""; + } + + public int minRating(){ + int min = r1; + if(r2max) { + max = r2; + } + if(r3>max){ + max = r3; + } + return max; + } + + public boolean isValidRating(){ + return (maxRating()-minRating()<=2)?true:false; + } +} + +" +A21364,"import java.io.File; +import java.util.Arrays; +import java.util.Scanner; + + +public class ProblemB { + + public static void main(String[] args) throws Exception { + + Scanner leitor = new Scanner(new File(""problemBTest.in"")); + int n = leitor.nextInt(); leitor.nextLine(); + for (int i = 0; i < n; i++) { + int dancers = leitor.nextInt(); + int surp = leitor.nextInt(); + int min = leitor.nextInt(); + int notas[] = new int[dancers]; + for (int j = 0; j < dancers; j++) { + notas[j] = leitor.nextInt(); + } + leitor.nextLine(); + Arrays.sort(notas); + + int resultado = 0; + + int j = 0; + for (j = dancers-1; j >=0; j--) { + if (notas[j] > (3 * (min-1))) { + resultado++; + } else { + break; + } + } + + while (surp > 0 && j >= 0) { + if ((min-2) >= 0) { + if (((notas[j] - min - (min-2)) >= (min-2)) && + ((notas[j] - min - (min-2)) < (min+2)) ) { + resultado++; + surp--; + } + } + j--; + } + System.out.println(""Case #"" + (i+1) + "": "" + resultado); + } + } + +} +" +A21462,"package codejam.is; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +/** + * Created with IntelliJ IDEA. + * User: ofer + * Date: 4/13/12 + * Time: 8:53 PM + * To change this template use File | Settings | File Templates. + */ +public class TestRunner { + + public void runTests(String inputFilePath, String outputFilePath, Class testClass) { + try { + + BufferedReader br = new BufferedReader(new FileReader(inputFilePath)); + int numOfTests = Integer.parseInt(br.readLine()); + + Test[] tests = new Test[numOfTests]; + for (int i = 0; i < numOfTests; i++) { + tests[i] = (Test)testClass.newInstance(); + tests[i].run(br.readLine()); + } + + br.close(); + + BufferedWriter bw = new BufferedWriter(new FileWriter(outputFilePath)); + for (int i = 0; i < numOfTests; i++) { + bw.write(tests[i].getOutput(i+1)); + } + bw.close(); + + + } catch (Exception e) { + System.out.println(""Caught exception: "" + e); + e.printStackTrace(); + } + } + +} +" +A22371,"public class Dancing { + public static int atLeast; + public static Googler[] googlers; + + public static void main(String[] args) { + doProblems(""100\n"" + + ""6 2 8 29 20 8 18 18 21\n"" + + ""70 70 7 20 6 28 3 3 27 25 22 18 24 20 2 17 9 27 27 28 2 8 4 10 26 28 3 9 24 28 8 18 3 23 14 23 16 27 13 23 16 10 8 26 22 21 4 11 13 19 11 15 4 28 26 3 25 24 16 28 20 5 11 18 2 25 14 22 22 28 26 15 10\n"" + + ""54 54 9 20 24 25 26 26 10 23 8 15 23 26 14 4 6 25 22 20 4 6 8 8 23 4 6 9 13 24 12 2 11 19 14 10 27 12 23 17 2 10 11 14 22 8 11 25 8 15 22 14 26 10 6 17 20\n"" + + ""47 0 6 22 9 11 19 19 29 11 0 3 27 27 11 28 5 20 25 22 18 8 20 10 9 29 1 5 15 27 25 19 12 3 11 26 5 26 28 6 15 12 25 20 0 18 21 2 4 29\n"" + + ""90 32 6 6 20 24 24 17 30 18 0 12 18 21 21 13 21 21 11 8 30 21 13 17 29 16 6 25 14 14 24 21 5 7 22 18 7 9 27 17 9 19 22 24 22 28 27 7 9 17 7 10 29 3 24 5 22 18 27 7 29 20 28 5 29 11 20 0 6 8 0 19 6 24 5 14 21 24 7 0 8 25 10 4 30 15 18 17 16 27 15 30 1\n"" + + ""97 6 10 26 1 26 20 19 14 27 16 21 2 10 27 28 3 2 9 28 22 16 28 28 25 4 20 7 5 9 26 0 3 21 17 23 26 29 9 21 18 24 13 10 23 3 15 12 10 20 1 30 2 30 29 28 11 17 29 19 21 2 12 21 24 10 30 13 12 9 30 29 24 12 1 11 9 14 15 29 14 8 3 21 6 9 12 6 12 7 22 19 14 30 22 8 27 16 16 10\n"" + + ""4 0 10 26 9 27 26\n"" + + ""64 8 4 19 18 8 9 1 16 8 5 9 9 4 9 8 8 24 8 8 26 9 8 9 8 9 8 9 9 9 10 8 9 9 21 8 0 9 9 13 24 9 16 2 4 9 8 20 8 9 8 8 19 22 28 8 9 9 8 8 9 26 20 15 12 9 8\n"" + + ""17 3 6 8 14 21 7 17 22 22 9 12 19 22 4 2 16 19 20 7\n"" + + ""55 11 8 5 0 19 28 20 20 30 21 20 14 5 21 20 20 19 5 18 2 20 5 20 20 27 21 5 21 5 11 27 3 28 6 20 21 21 7 21 21 20 20 20 20 18 20 9 20 21 24 20 22 13 21 14 21 23\n"" + + ""67 0 8 11 2 12 8 10 26 2 4 19 28 1 1 27 28 25 5 8 17 15 20 30 12 8 23 29 19 13 15 12 26 1 28 22 5 23 19 13 18 14 24 28 1 22 11 26 16 18 17 17 13 20 11 6 8 12 19 19 8 16 18 12 20 9 21 29 20 29\n"" + + ""87 87 5 8 13 3 28 28 16 22 22 22 11 17 8 14 23 3 6 3 16 17 24 28 24 9 13 12 13 18 17 15 2 3 9 15 18 11 13 10 13 19 8 10 24 8 20 28 5 22 8 12 17 2 19 14 28 20 11 9 18 2 24 28 25 18 19 24 4 26 18 12 25 3 17 16 7 19 4 22 15 16 14 16 19 19 21 20 2 19\n"" + + ""80 0 10 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n"" + + ""96 52 1 28 26 19 11 6 7 0 4 3 24 4 5 16 3 8 18 9 3 13 23 21 14 10 25 13 12 2 16 26 13 17 9 11 0 8 13 23 6 28 2 30 14 29 17 6 15 29 29 3 2 22 5 21 5 10 17 8 28 28 24 10 19 28 14 10 20 29 14 6 9 26 0 1 5 14 19 23 12 24 6 17 18 6 19 3 11 10 16 17 22 0 13 26 19 4 6\n"" + + ""78 45 2 1 21 30 12 11 3 19 26 22 14 28 2 27 28 6 15 19 26 24 17 2 25 12 17 19 14 14 24 19 3 4 26 8 4 3 29 16 22 11 12 9 8 20 29 7 13 27 10 6 3 23 11 11 16 4 15 18 20 18 17 7 9 11 30 1 28 11 28 28 17 24 17 10 23 0 18 16 11\n"" + + ""93 0 2 9 17 6 20 0 19 26 26 18 22 8 2 20 26 6 24 13 11 8 22 0 24 2 12 19 6 6 29 18 14 14 1 8 25 17 23 7 6 1 28 9 12 24 9 27 13 9 15 6 1 13 12 6 25 25 13 18 0 19 25 9 27 24 15 1 26 0 4 28 3 8 2 10 18 6 18 29 23 30 30 22 25 7 20 2 11 10 14 9 1 5 21 2\n"" + + ""35 35 0 15 23 2 11 20 15 4 28 24 18 5 7 4 19 9 18 6 17 2 21 21 18 9 19 20 11 17 17 7 6 24 25 7 4 5\n"" + + ""54 4 4 9 4 3 8 8 18 12 17 25 5 8 19 9 8 8 24 7 8 9 8 29 26 2 8 14 9 9 30 2 4 1 21 8 8 21 28 4 8 5 23 8 27 9 3 8 11 27 8 9 9 9 25 9 2\n"" + + ""81 0 7 21 0 10 4 29 5 27 11 20 19 10 1 21 13 13 12 10 3 26 14 20 16 19 14 16 11 20 8 1 17 27 22 3 29 17 28 1 21 7 26 1 28 28 17 23 0 16 21 24 12 27 0 9 28 3 24 26 17 1 14 17 15 8 30 20 13 19 2 3 4 3 7 7 10 9 22 5 6 25 17 9\n"" + + ""78 2 3 6 27 5 28 27 20 16 9 16 13 5 10 2 26 2 24 27 19 24 23 29 12 1 29 27 6 28 0 28 18 4 30 23 26 28 25 19 15 7 7 24 30 27 2 2 19 0 27 3 7 30 19 8 24 0 19 29 20 24 11 24 30 20 18 27 6 4 10 9 16 25 20 17 28 25 10 17 25\n"" + + ""30 7 9 7 17 10 22 24 24 24 25 24 28 24 19 24 23 12 23 23 12 24 23 6 23 19 24 23 7 24 11 15 5\n"" + + ""2 0 6 15 3\n"" + + ""81 10 3 5 29 6 6 6 20 3 21 16 10 6 11 7 6 6 5 6 6 18 5 6 6 5 6 1 5 21 25 8 6 11 18 17 5 30 6 6 13 6 6 5 6 29 15 5 5 6 14 7 5 28 24 28 30 15 27 0 7 26 5 5 19 21 6 5 15 6 6 5 5 5 17 25 9 6 29 14 21 18 17 27\n"" + + ""69 55 6 10 20 12 8 27 5 11 15 17 30 7 14 6 20 6 27 3 6 15 17 10 8 26 1 3 9 6 27 30 0 16 8 30 19 26 25 25 27 23 20 15 8 11 21 16 24 10 22 23 29 22 0 26 6 3 16 4 11 5 7 4 14 30 0 12 4 29 21 30\n"" + + ""10 0 7 18 11 25 5 20 18 18 18 18 25\n"" + + ""61 60 1 22 22 12 21 13 2 11 6 6 14 12 11 7 16 0 7 26 26 26 28 15 3 20 28 11 5 22 21 15 27 22 13 18 21 21 25 25 8 5 10 5 25 26 13 4 15 20 18 28 18 10 20 5 16 14 7 18 13 14 13 2\n"" + + ""20 0 8 3 29 15 15 19 15 21 9 28 25 7 24 3 3 5 22 26 22 3 16\n"" + + ""62 22 6 11 7 1 15 16 29 8 26 21 4 16 0 7 24 9 8 1 25 10 3 4 30 30 9 4 3 1 30 0 14 16 6 3 1 0 27 4 10 29 22 7 30 1 2 20 9 5 9 10 9 29 8 30 28 8 12 9 22 4 24 24 6\n"" + + ""16 2 9 23 24 24 24 2 17 4 18 5 22 23 23 24 5 24 4\n"" + + ""73 25 4 9 8 8 11 9 14 9 8 30 9 9 10 15 8 25 8 1 8 7 9 11 8 8 24 8 4 9 8 20 8 9 17 27 8 2 27 2 8 9 29 26 8 24 21 7 8 8 9 8 9 8 15 9 18 8 8 22 27 14 1 3 9 15 9 8 30 6 8 12 12 23 26 8\n"" + + ""42 21 10 22 30 14 9 10 6 15 24 24 23 5 0 25 17 28 4 28 3 3 4 19 8 29 8 27 16 23 4 13 17 3 30 18 14 1 15 16 30 3 18 19 19\n"" + + ""33 19 9 0 10 7 24 7 30 27 22 7 9 2 28 0 19 2 9 25 14 4 28 11 13 2 2 20 9 28 22 13 21 30 16 30\n"" + + ""73 31 9 24 28 15 7 8 26 22 11 0 23 28 7 24 23 23 24 24 3 23 23 6 23 24 23 23 23 11 24 23 9 23 23 2 23 15 23 24 23 24 23 29 23 9 23 23 24 23 23 24 24 29 14 8 1 18 18 30 24 23 23 24 24 23 0 23 23 10 24 4 23 24 13 23\n"" + + ""84 67 10 16 30 10 11 8 15 11 24 8 24 30 30 22 5 12 3 26 20 19 12 4 3 11 0 13 25 25 27 7 12 16 7 8 26 27 24 14 24 15 27 16 30 4 19 29 28 13 18 20 9 4 21 21 19 13 30 0 30 1 23 18 17 2 13 10 16 28 16 22 23 0 4 14 16 4 10 17 23 17 29 26 20 28 0\n"" + + ""30 16 8 17 1 18 12 30 21 11 25 28 3 2 4 29 0 11 5 3 7 30 28 8 19 4 0 0 4 13 4 28 14\n"" + + ""1 0 1 27\n"" + + ""81 25 9 24 23 23 4 24 8 13 3 30 8 24 14 26 23 24 25 23 24 24 23 23 17 24 20 10 23 4 23 24 23 19 12 14 10 23 23 24 24 20 15 23 5 30 24 24 23 24 24 30 24 23 18 23 26 7 5 14 24 23 24 24 14 24 10 24 24 23 2 24 23 24 23 16 17 24 20 7 23 23 23 25\n"" + + ""82 36 2 18 28 3 30 3 3 2 2 22 0 18 30 3 3 2 2 2 4 3 3 11 17 23 22 3 3 3 2 2 3 3 3 3 3 2 21 23 3 5 2 3 27 28 7 11 14 3 2 2 2 13 2 3 3 3 3 2 17 2 14 22 3 3 28 2 2 3 3 3 3 2 0 3 24 1 3 3 21 3 25 13 11\n"" + + ""100 90 5 29 4 26 12 11 26 12 29 9 9 4 1 12 10 11 6 24 15 16 19 17 25 13 28 17 2 23 25 14 13 0 23 15 25 27 21 16 4 29 7 11 25 17 24 14 20 2 4 10 17 4 24 9 15 13 17 26 19 1 9 16 21 26 8 24 7 13 26 22 8 28 29 22 4 12 14 4 10 5 17 7 20 27 24 22 18 19 16 22 25 14 9 12 29 28 24 29 7 14 27\n"" + + ""98 1 10 27 25 4 29 24 27 26 27 27 22 26 27 16 27 27 0 26 26 7 9 11 27 26 27 18 10 27 27 27 27 27 26 26 26 16 26 10 2 26 25 26 28 27 27 21 10 14 26 27 5 26 15 26 26 22 17 26 5 8 27 16 14 27 19 27 26 8 26 11 30 10 6 26 26 26 12 28 8 23 26 2 18 26 24 26 28 16 2 30 26 26 20 25 27 26 27 1 30\n"" + + ""1 0 2 3\n"" + + ""81 0 0 27 10 4 17 2 15 17 23 10 24 1 22 6 1 28 15 11 0 17 12 9 13 23 26 9 27 17 5 19 26 20 7 9 30 6 4 7 26 17 28 3 1 25 25 5 9 28 4 11 3 26 14 11 22 16 26 4 9 2 2 24 26 28 7 30 29 10 20 19 1 10 0 18 2 7 3 10 3 24 10 12\n"" + + ""79 58 9 9 6 2 1 6 21 30 15 12 9 14 14 27 29 1 30 9 4 21 23 20 19 9 3 10 23 27 7 15 12 30 26 1 5 8 8 7 11 30 20 12 6 5 28 18 15 30 23 7 24 14 25 24 1 6 2 15 0 6 21 8 21 15 23 15 3 7 17 30 24 19 17 15 3 10 14 16 6 15\n"" + + ""38 8 6 30 5 15 9 15 23 10 15 24 15 17 15 9 15 1 15 15 1 8 15 1 14 14 18 28 14 22 15 15 14 14 10 14 15 28 14 6 14\n"" + + ""57 26 0 5 22 14 23 8 15 29 26 15 29 19 20 4 5 27 4 0 10 26 11 12 25 12 28 8 0 6 30 19 4 16 29 25 4 9 20 18 16 28 7 24 8 12 10 22 5 12 18 30 4 7 25 23 23 28 17 7\n"" + + ""98 6 8 20 21 14 21 21 20 20 22 26 20 21 20 21 20 21 21 16 0 9 18 20 20 17 21 8 20 6 20 26 16 22 21 20 21 2 8 24 15 20 19 20 0 19 20 27 21 21 20 3 20 20 8 20 22 20 20 21 27 21 7 21 28 21 21 19 21 14 20 27 2 2 26 20 20 5 21 28 11 21 20 25 20 20 25 8 23 21 20 6 6 21 30 5 18 23 2 20 21\n"" + + ""62 24 7 18 25 17 17 30 22 17 17 17 17 21 18 2 30 11 1 17 30 0 17 3 9 17 17 17 18 28 28 24 17 17 13 11 18 18 18 17 18 13 2 16 28 18 2 23 13 24 18 18 23 20 17 19 17 20 25 26 17 6 16 17 17\n"" + + ""30 4 8 28 16 18 26 5 30 24 20 15 11 13 23 16 28 26 24 16 21 3 18 1 23 9 12 25 5 18 22 5 20\n"" + + ""67 3 2 3 2 23 3 10 3 3 25 10 14 9 2 30 14 21 3 28 3 3 18 3 2 22 26 14 2 24 2 28 3 2 3 2 17 3 2 3 30 30 25 11 2 2 0 2 1 2 3 8 3 26 2 7 0 2 28 2 2 3 3 13 19 2 2 2 24 2\n"" + + ""56 0 3 10 25 2 11 6 24 12 13 23 21 4 2 25 23 13 10 12 15 7 11 6 2 7 11 11 21 27 0 2 20 21 4 13 21 7 30 4 20 5 16 18 16 4 18 7 16 0 14 20 18 7 7 8 12 30 27\n"" + + ""60 7 3 20 24 10 18 24 26 22 1 26 15 4 3 13 23 26 1 7 21 12 21 30 6 15 9 29 6 22 1 19 6 25 8 9 7 0 26 19 23 0 8 3 24 23 15 6 22 10 23 22 19 0 13 28 26 11 14 21 11 9 29\n"" + + ""49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"" + + ""92 14 7 19 26 0 5 10 7 27 27 25 2 12 26 20 11 5 21 28 28 17 22 1 10 20 8 17 28 21 17 22 8 26 24 4 20 16 19 2 19 30 12 22 11 14 4 0 5 7 28 18 10 20 29 5 30 25 28 21 12 1 24 23 12 13 21 26 5 11 20 30 0 28 2 2 10 2 12 14 12 10 2 26 6 18 16 17 19 22 16 28 20 4 17\n"" + + ""8 8 3 17 20 25 5 9 28 16 10\n"" + + ""54 0 6 14 14 14 14 15 15 28 15 7 15 13 15 12 14 15 11 15 13 29 17 0 15 3 14 14 0 15 24 26 22 14 15 15 25 13 14 15 22 3 15 15 12 14 13 23 14 15 2 8 11 15 9 14 21\n"" + + ""82 27 8 25 4 24 25 20 21 30 21 20 21 20 4 20 20 12 25 28 26 21 20 10 20 20 30 21 2 29 21 20 21 20 28 0 21 20 28 23 20 20 30 29 3 21 23 20 21 21 0 21 17 20 8 22 9 10 6 21 20 20 19 28 25 21 12 21 9 30 20 20 9 20 21 7 21 7 21 25 20 21 4 20 17\n"" + + ""67 6 9 9 17 18 22 11 20 2 2 12 27 4 6 1 24 27 7 0 4 20 26 24 11 15 28 13 22 1 17 11 29 5 12 18 29 9 3 13 18 26 4 13 27 27 13 23 6 27 6 14 14 18 6 5 12 6 22 2 22 30 9 20 17 24 29 15 0 25\n"" + + ""51 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"" + + ""74 0 2 13 16 27 28 19 12 11 4 29 7 12 29 1 10 21 20 11 16 17 14 2 7 5 11 6 7 24 12 6 23 14 2 24 25 5 7 14 4 16 0 15 12 4 21 23 16 0 18 10 4 21 14 17 6 5 10 1 24 19 19 26 17 19 28 18 29 24 20 28 25 5 14 8 6\n"" + + ""32 26 6 1 10 0 2 2 6 13 15 24 18 29 11 8 19 23 4 30 7 18 24 2 9 29 30 19 27 7 21 20 14 18 7\n"" + + ""11 1 6 23 7 12 28 5 16 29 13 14 4 16\n"" + + ""55 26 2 8 11 14 15 15 25 9 19 1 19 17 27 24 29 25 20 25 0 18 9 11 25 24 18 30 7 6 2 1 14 24 28 6 7 10 17 19 2 21 6 20 30 29 29 29 24 17 11 4 7 15 23 19 17 5\n"" + + ""24 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n"" + + ""94 41 7 6 11 26 21 18 1 13 17 3 23 26 10 23 24 19 13 10 24 25 7 18 1 9 8 14 19 18 5 2 3 20 24 11 4 15 22 11 10 16 19 16 16 30 5 19 25 18 22 17 24 2 9 9 26 9 25 22 28 25 14 23 8 27 10 27 27 18 14 28 30 6 27 14 14 11 13 17 1 27 13 5 2 30 15 18 17 17 27 24 18 13 21 5 12\n"" + + ""38 16 8 21 21 21 5 30 8 20 9 23 30 16 7 21 11 20 21 12 20 21 0 21 11 20 9 20 11 20 20 20 20 16 20 22 21 21 29 0 5\n"" + + ""55 55 0 4 19 14 4 19 5 23 28 17 24 6 7 25 20 7 14 20 6 26 9 3 20 26 16 28 9 28 25 10 2 17 8 28 22 17 21 18 5 22 20 16 12 10 23 23 4 2 17 6 18 5 17 10 24 2\n"" + + ""19 7 2 3 1 26 26 7 4 19 14 28 20 21 1 0 14 10 26 16 14 17\n"" + + ""90 26 0 12 7 3 0 19 8 23 4 21 28 28 21 24 2 26 17 1 9 20 30 10 15 19 12 5 22 13 7 10 28 5 29 7 20 20 28 5 4 11 18 10 21 12 0 2 27 28 23 26 17 22 22 8 1 1 20 30 28 24 27 15 9 23 2 3 0 13 16 6 6 24 18 30 1 16 6 12 7 8 7 14 30 10 24 6 4 25 21 11 1\n"" + + ""71 3 5 11 23 12 11 11 3 23 4 12 15 11 29 12 30 11 12 15 12 17 3 21 11 7 10 11 0 26 9 20 11 12 11 12 7 21 25 11 2 27 11 12 12 11 12 11 23 2 12 26 30 11 2 12 11 8 11 11 11 20 12 12 10 12 11 12 11 8 11 5 11 12\n"" + + ""41 0 2 0 28 2 5 20 4 11 27 14 30 1 4 29 30 4 26 24 12 13 22 6 28 30 20 30 6 20 11 30 6 6 8 30 22 20 14 29 7 0 22 19\n"" + + ""52 44 7 3 19 5 28 14 19 23 25 1 0 21 28 13 4 29 15 1 22 25 28 8 1 17 26 21 10 15 5 6 24 3 17 19 14 23 30 18 12 10 26 9 16 28 29 4 20 19 4 17 7 8 28\n"" + + ""78 29 9 23 24 24 23 24 24 29 28 13 16 17 26 5 23 10 6 28 7 0 23 8 24 24 24 24 12 9 14 24 23 16 13 23 20 24 10 24 23 24 23 23 23 25 21 24 23 24 23 20 24 13 10 16 20 9 27 24 23 24 24 23 14 14 23 6 24 23 24 24 17 24 25 24 23 1 0 15 23\n"" + + ""27 0 0 0 19 26 20 28 17 3 7 4 2 0 11 13 8 18 27 22 27 27 25 16 23 29 28 16 24 27\n"" + + ""95 36 0 17 14 1 25 5 15 12 21 28 14 14 0 26 11 28 0 22 21 5 13 18 20 25 19 13 18 13 11 14 2 20 23 1 9 12 1 14 12 4 28 14 3 23 23 23 25 23 3 11 30 25 24 25 15 28 28 26 29 26 24 11 13 18 22 20 29 22 7 30 9 4 28 22 8 17 11 10 27 30 8 28 11 30 18 2 13 14 13 11 2 5 30 16 3 22\n"" + + ""55 1 6 14 14 27 16 14 18 8 15 2 0 14 29 14 15 15 3 28 14 23 14 14 15 8 15 15 23 25 15 1 15 15 23 14 15 14 14 15 15 24 19 15 15 27 24 9 9 14 24 6 13 23 15 5 15 14\n"" + + ""8 5 5 1 14 30 26 10 8 12 25\n"" + + ""96 37 8 16 5 30 0 13 8 21 13 29 21 24 0 23 9 20 23 0 21 8 10 10 15 24 28 23 17 5 17 28 7 7 7 22 17 3 28 8 13 8 14 24 25 20 16 10 12 9 23 11 28 3 8 13 20 14 25 2 13 17 13 4 6 29 26 15 5 17 10 19 30 25 2 6 21 9 12 1 18 4 29 12 7 13 7 30 25 12 29 29 27 3 22 11 29 14 19\n"" + + ""14 12 4 24 9 28 1 14 13 30 17 5 24 26 9 25 15\n"" + + ""11 0 3 6 5 6 6 15 11 30 26 6 6 5\n"" + + ""5 0 4 20 23 8 8 2\n"" + + ""77 25 8 20 21 19 29 21 23 21 30 21 21 8 21 21 20 19 0 21 8 3 20 9 21 13 29 21 20 14 20 20 20 2 21 11 19 29 18 1 21 20 14 22 20 27 23 20 21 20 21 21 20 10 20 20 21 2 23 23 21 19 22 4 20 16 20 20 21 8 21 21 20 24 21 21 24 21 21 6\n"" + + ""80 8 1 26 9 15 12 4 12 27 17 24 30 22 20 18 7 22 16 26 5 3 1 10 0 0 6 25 2 29 12 5 10 22 26 20 7 7 11 9 15 1 16 5 3 19 26 22 18 6 9 26 8 20 23 7 18 3 23 7 25 7 7 4 25 23 11 0 17 3 0 24 4 27 8 10 4 20 4 20 2 3 19\n"" + + ""83 0 5 24 6 6 19 14 21 8 1 18 8 30 16 18 27 5 15 6 27 3 10 15 2 10 11 2 12 1 15 2 29 9 24 8 11 2 20 7 9 23 10 18 23 5 26 8 5 12 30 0 8 6 26 19 5 18 27 7 0 25 25 0 15 4 11 11 18 2 13 17 27 9 28 4 11 9 1 15 4 4 30 25 24 9\n"" + + ""25 22 1 25 28 18 7 11 8 15 23 22 10 17 2 14 20 2 5 4 0 2 21 1 19 7 5 2\n"" + + ""54 54 10 26 27 12 17 3 14 26 10 14 24 10 7 11 10 16 3 10 26 24 12 25 19 17 21 13 4 21 3 5 4 21 3 4 13 3 24 25 27 16 11 15 27 23 9 26 15 27 26 17 18 11 26 8 27\n"" + + ""49 20 1 26 13 9 15 8 3 26 28 27 6 17 2 16 29 0 25 21 24 18 11 2 3 4 29 17 11 29 23 24 7 25 28 5 1 14 19 3 29 28 19 15 5 29 22 29 21 24 23 9\n"" + + ""41 3 8 0 21 20 21 15 21 21 11 21 28 21 20 21 20 5 20 21 21 21 9 20 19 20 21 16 24 21 20 21 20 26 21 27 21 21 7 21 21 20 10 21\n"" + + ""81 81 0 23 22 5 6 27 26 20 19 10 18 20 12 9 25 27 13 16 8 21 12 16 14 22 3 22 5 15 8 16 6 28 16 24 2 22 7 21 5 13 10 5 11 17 24 26 23 7 28 8 13 27 7 5 21 28 17 20 13 3 20 14 6 8 19 14 16 13 5 16 27 7 14 21 17 14 14 28 10 15 25 8\n"" + + ""72 40 8 21 24 20 21 12 21 22 21 21 21 21 20 27 24 20 17 28 3 21 20 21 24 21 19 20 21 21 9 21 6 29 20 3 29 21 16 8 20 20 20 21 28 20 21 21 21 20 1 20 21 21 8 20 21 16 19 25 21 17 12 20 21 9 24 21 21 21 2 20 21 21 21\n"" + + ""46 26 7 12 18 30 30 20 11 24 3 26 8 24 10 22 27 19 12 14 20 5 14 22 6 15 8 10 5 0 30 2 26 10 22 22 20 24 10 20 14 16 4 8 17 24 26 30 17\n"" + + ""99 79 4 28 22 3 26 6 4 23 12 17 0 15 29 11 13 24 9 28 20 5 12 9 4 17 29 22 18 4 9 11 26 24 4 3 29 25 3 26 18 25 18 13 5 16 20 4 13 12 27 17 14 5 16 5 19 0 29 30 26 28 23 9 11 22 17 22 9 3 15 21 9 27 4 1 1 0 15 19 6 15 23 3 16 18 27 6 8 22 10 13 9 11 9 30 0 28 3 5 27 25\n"" + + ""5 1 10 22 2 18 22 5\n"" + + ""63 0 0 0 18 8 8 0 4 19 1 30 6 29 11 5 14 21 16 21 3 18 10 12 17 15 29 3 30 24 15 18 9 9 20 0 12 22 4 28 28 5 17 1 8 20 14 11 10 0 30 13 6 21 7 3 0 9 6 5 14 7 18 4 19 3\n"" + + ""43 20 5 18 12 12 11 3 17 17 11 11 11 12 12 21 13 12 9 12 11 12 12 9 11 11 11 19 11 11 12 18 12 12 11 24 12 11 12 15 5 11 11 12 17 30\n"" + + ""80 30 4 9 8 8 9 8 9 24 8 27 9 24 20 14 9 9 0 11 8 28 3 6 9 13 9 17 8 13 9 8 9 9 8 8 9 8 18 14 8 8 0 5 24 4 6 27 16 21 9 8 9 8 8 9 9 26 16 21 8 20 10 11 8 13 9 8 9 15 15 28 8 24 8 18 6 24 7 1 28 25 3\n"" + + ""38 38 5 15 13 4 16 8 16 23 2 9 16 22 16 23 4 15 15 17 9 28 10 8 10 6 9 6 6 11 28 15 15 28 13 24 15 28 26 19 18\n"" + + ""63 21 6 15 14 5 14 28 15 8 25 16 15 14 19 15 19 21 14 12 6 26 30 14 14 14 15 15 23 15 30 13 12 25 7 29 15 23 14 9 29 24 5 30 15 22 21 28 14 14 15 15 14 5 14 15 7 7 15 15 15 14 4 14 15 15\n"" + + ""88 6 1 25 25 25 27 16 29 6 17 1 8 28 16 18 2 12 6 6 18 6 1 0 22 14 11 6 27 26 18 30 5 15 30 19 14 2 28 7 25 0 23 8 16 17 11 2 19 10 8 3 13 5 23 23 2 13 10 3 1 3 7 7 21 21 20 19 4 18 18 16 1 15 15 23 4 15 5 9 1 24 14 10 13 16 12 3 20 6 9\n"" + + ""83 45 7 13 20 8 27 0 20 28 27 8 0 28 25 30 9 16 24 4 27 30 26 8 4 2 24 23 10 25 29 11 19 6 29 23 0 13 6 21 26 20 6 5 17 30 7 29 25 16 18 9 2 30 16 13 1 10 28 30 11 1 28 23 24 19 27 3 22 19 20 8 22 8 10 21 24 4 11 21 25 28 5 1 28 8\n"" + + ""16 16 7 8 24 4 27 21 13 15 4 7 18 23 17 28 28 17 16\n""); + } + + private static void doProblems(String in) { + String[] problems = in.split(""\n""); + for (int count = 0; count < Integer.valueOf(problems[0]); count++) { + doProblem(problems[count + 1], count + 1); + } + } + + private static void doProblem(String in, int problemNumber) { + String[] array = in.split("" ""); + int numberOfGooglers = Integer.valueOf(array[0]); + int surprisingGooglers = Integer.valueOf(array[1]); + atLeast = Integer.valueOf(array[2]); + int[] googlerTotals = new int[numberOfGooglers]; + for (int count = 0; count < numberOfGooglers; count++) { + googlerTotals[count] = Integer.valueOf(array[count + 3]); + } + googlers = new Googler[numberOfGooglers]; + for (int count = 0; count < numberOfGooglers; count++) { + googlers[count] = new Googler(googlerTotals[count]); + } + int finalOut = 0; + for (int count = 0; count < googlers.length; count++) { + if (googlers[count].canBeTotal) { + + if (!googlers[count].requiresStrange) { + finalOut++; + } else if (surprisingGooglers > 0) { + finalOut++; + surprisingGooglers--; + } + + + } + } + System.out.println(""Case #"" + problemNumber + "": "" + finalOut); + + } + + + static class Googler { + private int total; + private boolean canBeTotal; + private boolean requiresStrange; + private boolean countMe; + + public Googler(int total) { + this.total = total; + canBeAtLeast(); + //System.out.println(total + "" "" + canBeTotal + "" "" + atLeast + "" "" + requiresStrange); + } + + private void canBeAtLeast() { + + if (total % 3 == 0) { + int eachSide = total / 3; + if (eachSide >= atLeast) { + canBeTotal = true; + + } else if (eachSide + 1 >= atLeast) { + canBeTotal = true; + requiresStrange = true; + } + } else if (total % 3 == 1) { + int doubleLong = (int) Math.ceil(total / 3f); + if (doubleLong >= atLeast) { + canBeTotal = true; + } + } else if (total % 3 == 2) { + int doubleLong = (int) Math.ceil(total / 3f); + if (doubleLong >= atLeast) { + canBeTotal = true; + } else if (total - doubleLong * 2 + 2 >= atLeast) { + canBeTotal = true; + requiresStrange = true; + } + } + if (total < 2) { + requiresStrange = false; + if (total < atLeast) { + canBeTotal = false; + } + } + } + + + } + +} +" +A20527,"package practice; + +import java.util.*; + +public class GoogleDance { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + int cases = Integer.parseInt(sc.nextLine()); + for(int i = 0; i scores = new ArrayList(); + for(int j = 3; j=passing){ + result++; + } + }else{ + if(individual>=passing){ + result++; + }else if(surprising>0){ + individual++; + if(individual>=passing){ + result++; + surprising--; + } + } + } + + } + if(score%3==1){ + int individual = score/3+1; + if(individual>=passing){ + result++; + } + } + if(score%3==2){ + int individual = score/3+1; + if(individual>=passing){ + result++; + }else if(surprising>0){ + individual++; + if(individual>=passing){ + result++; + surprising--; + } + } + } + } + System.out.println(""Case #""+caseCounter+"": "" + result); + //Case ends here + } + } +} +" +A20625,"import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Scanner; + +public class GCJ12QRB +{ + private static int n, s, p, count, x, y; + private static String output, newline = System.getProperty(""line.separator""); + + private static void fun(String src) throws IOException + { + output = """"; + Scanner sc = new Scanner(new File(src)); + int i, ntc = sc.nextInt(); + + for(int w=1; w<=ntc; w++) + { + n = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + count = 0; + + for(i=0; i= p) + count++; + else if(s > 0 && y + 1 >= p) { + s--; + count++; + } + } + else if(y == 2) { + y = x / 3; + if(y + 1 >= p) + count++; + else if(s > 0 && y + 2 >= p) { + s--; + count++; + } + } + else { + y = x / 3; + if(y + 1 >= p) + count++; + } + } + + output += ""Case #"" + w + "": "" + count + newline; + } + sc.close(); + } + + public static void main(String[] args) throws IOException + { + fun(""B-large.in""); + OutputStream fo = new FileOutputStream(""B-large.out""); + fo.write(output.getBytes()); + fo.close(); + } +} +" +A22704,"package br.com.luan; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class B { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String line = br.readLine(); + int T = Integer.valueOf(line); + + // Process which number from stdin + for (int i = 0; i < T; i++) { + StringBuilder sb = new StringBuilder(line.length() + 11); + sb.append(""Case #""); + sb.append(i + 1); + sb.append("": ""); + + line = br.readLine(); + String[] split = line.split("" ""); + Integer N = Integer.parseInt(split[0]); + Integer S = Integer.parseInt(split[1]); + Integer p = Integer.parseInt(split[2]); + Integer[] ti = new Integer[N]; + for (int j = 0; j < ti.length; j++) { + ti[j] = Integer.parseInt(split[3 + j]); + } + + int result = doProcess(N, S, p, ti); + + sb.append(result); + + sb.append('\n'); + System.out.print(sb.toString()); + + } + } + + private static int doProcess(Integer n, Integer s, Integer p, Integer[] ti) { + final List sureList = new ArrayList(n); + final List posiList = new ArrayList(n); + + final int impoMax = 3 * p.intValue() - 4; + final int cerMin = 3 * p.intValue() - 2; + + for (int i = 0; i < ti.length; i++) { + Integer in = ti[i]; + int sumScore = in.intValue(); + if (sumScore < impoMax) { + // Impossible to get that score + } else if (sumScore >= cerMin) { + // Sure the dancer get that score + sureList.add(in); + } else if (sumScore > 0) { + // Possibles dancer who can get that score depending the surprising + posiList.add(in); + } + } + + int qualified = methodA(posiList, p, s); + + return sureList.size() + qualified; + } + + private static int methodA(List posiList, Integer p, Integer s) { + int surprising = s.intValue(); + if (surprising == 0) + return 0; + + int result = 0; + + for (int i = 0; i < surprising && posiList.size() > 0 ; i++) { + posiList.remove(0); + result += 1; + } + + return result; + } +} +" +A21254,"// Dancing With the Googlers + +import java.io.*; + +public class DancingWithGooglers { + public static void main(String[] args) throws Exception { + String inputPath = args[args.length-2]; + String outputPath = args[args.length-1]; + + BufferedReader br = new BufferedReader(new FileReader(inputPath)); + int numberOfTestCases = Integer.parseInt(br.readLine()); + + StringBuilder output = new StringBuilder(); + + for (int i=1; i<=numberOfTestCases; i++) { + String components[] = br.readLine().split("" ""); + int numberOfDancers = Integer.parseInt(components[0]); + int numberOfSurprisingResults = Integer.parseInt(components[1]); + int bestScore = Integer.parseInt(components[2]); + int numberOfBestScores = 0; + + for (int totalScoreIndex=3; totalScoreIndex<(3+numberOfDancers); totalScoreIndex++) { + int totalScore = Integer.parseInt(components[totalScoreIndex]); + int average = totalScore / 3; + int overflow = totalScore % 3; + + if (average >= bestScore) { + numberOfBestScores++; + } else if ((overflow != 0) && ((average+1) >= bestScore)) { + numberOfBestScores++; + } else if (numberOfSurprisingResults != 0) { + if ((overflow == 2) && ((average+overflow) >= bestScore)) { + numberOfBestScores++; + numberOfSurprisingResults--; + } else if ((overflow == 0) && (average > 0) && ((average+1) >= bestScore)) { + numberOfBestScores++; + numberOfSurprisingResults--; + } + } + +// System.out.println(totalScore + "" "" + average + "" "" + overflow + "" "" + numberOfBestScores); + } +// System.out.println(""Case #"" + i + "": "" + numberOfBestScores + ""\n""); + output.append(""Case #"" + i + "": "" + numberOfBestScores + ""\n""); + } + + BufferedWriter bw = new BufferedWriter(new FileWriter(outputPath)); + String outputString = output.toString(); + bw.write(outputString, 0, outputString.length()); + bw.close(); + } +} +" +A21054,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new FileReader( + ""C:\\bInput.txt"")); + BufferedWriter bw = new BufferedWriter(new FileWriter( + ""C:\\bOutput.txt"")); + String strLine; + strLine = br.readLine(); + int size = Integer.parseInt(strLine); + for (int i = 1; i <= size; i++) { + String[] s = br.readLine().split("" ""); + int N = Integer.parseInt(s[0]); + int S = Integer.parseInt(s[1]); + int p = Integer.parseInt(s[2]); + int[] totals = new int[N]; + for(int j=0;j=p) + aboveP++; + else if (totals[i]/3==(p-1)){ + if (totals[i]/3==0)//special exception when 0 can't get lower... + continue; + potentialAboveP++; + } + } + else if (totals[i]%3==2){ + if((totals[i]/3+1)>=p) + aboveP++; + else if ((totals[i]/3+1)==(p-1)) + potentialAboveP++; + } + else{ + if((totals[i]/3+1)>=p) + aboveP++; + } + } + return aboveP + Math.min(S, potentialAboveP); + } + + + +} +" +A21018," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class PB { + + public static void main(String[] args) throws FileNotFoundException { + if (args.length != 1) { + System.exit(1); + } + File inFile = new File(args[0]); + Scanner sc = new Scanner(inFile); + int T = sc.nextInt(); + try (PrintWriter out = new PrintWriter(""out.txt"")) { + for (int i = 0; i < T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = sc.nextInt(); + } + int[][] scores = new int[N][3]; + for (int j = 0; j < N; j++) { + scores[j][0] = t[j] / 3; + scores[j][1] = (t[j] - scores[j][0]) / 2; + scores[j][2] = t[j] - scores[j][0] - scores[j][1]; + } + int count = 0; + for (int j = 0; j < N; j++) { + boolean isSurprise = false; + if (scores[j][2] - scores[j][0] == 2) { + S--; + isSurprise = true; + } + if (scores[j][2] >= p) { + count++; + } else { + if (S > 0 && !isSurprise && (p - scores[j][2]) == 1 && scores[j][1] > 0) { + S--; + scores[j][1]--; + scores[j][2]++; + count++; + } + } + } + out.println(""Case #"" + (i + 1) + "": "" + count); + } + } + System.out.println(""Completed""); + } +} +" +A22636,"package b; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.text.AttributedCharacterIterator; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + public static void main(String[] args) { + InputStream inputStream; + try { + inputStream = new FileInputStream(""input.txt""); + } catch (IOException e) { + throw new RuntimeException(e); + } + OutputStream outputStream; + try { + outputStream = new FileOutputStream(""output.txt""); + } catch (IOException e) { + throw new RuntimeException(e); + } + InputReader in = new InputReader(inputStream); + PrintWriter out = new PrintWriter(outputStream); + Dancing solver = new Dancing(); + int testCases = in.nextInt(); + for (int i = 1; i <= testCases; i++) + solver.solve(i, in, out); + + out.close(); + } +} + +class InputReader { + private BufferedReader reader; + private StringTokenizer tokenizer; + + public InputReader(InputStream stream) { + reader = new BufferedReader(new InputStreamReader(stream)); + tokenizer = null; + } + + public String next() { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + try { + tokenizer = new StringTokenizer(reader.readLine()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return tokenizer.nextToken(); + } + + public boolean haveNextInCurrentLine() { + return (tokenizer != null && tokenizer.hasMoreTokens()); + } + + public int nextInt() { + return Integer.parseInt(next()); + } +} + +class Dancing { + + static final int IMPOSSIBLE = 0, POSSIBLE = 1, ACHIEVED = 2; + + public void solve(int testCase, InputReader in, PrintWriter out) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = in.nextInt(); + } + + System.out.println(""Case #"" + testCase + "": "" + n + "" "" + s + "" "" + p + + "" "" + Arrays.toString(t)); + + int result = n; + if (p > 0) { + int possible = 0; + int achieved = 0; + + for (int i = 0; i < n; i++) { + System.out + .println(""n: "" + (i + 1) + "" = "" + getResult(t[i], p)); + switch (getResult(t[i], p)) { + case ACHIEVED: + achieved++; + break; + case POSSIBLE: + possible++; + break; + } + } + + result = achieved + Math.min(possible, s); + } + + out.println(""Case #"" + testCase + "": "" + result); + System.out.println(""Case #"" + testCase + "": "" + result); + } + + private int getResult(int sum, int p) { + if (sum < p) + return IMPOSSIBLE; + + int third = sum / 3; + if (third >= p) + return ACHIEVED; + + if (sum % 3 == 0) { + if ((sum - 2) / 3 + 2 >= p) + return POSSIBLE; + } else { + if (third + 1 >= p) + return ACHIEVED; + else if ((sum - 2) / 3 + 2 >= p) + return POSSIBLE; + } + + return IMPOSSIBLE; + } +}" +A21477,"import java.util.*; +import java.io.*; + +public class DanceGooglers{ + public static void main(String[] args){ + try{ + FileReader fin = new FileReader(args[0]); + BufferedReader txtFile = new BufferedReader(fin); + + //FileWriter fout = new FileWriter(args[1]); + //BufferedWriter out = new BufferedWriter(fout); + + String line = null; + line = txtFile.readLine(); + int T = Integer.parseInt(line); + //System.out.println(T); + for(int i = 0; i < T; i ++){ + line = txtFile.readLine(); + StringTokenizer st = new StringTokenizer(line, "" ""); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] ts = new int[N]; + for(int i1 = 0; i1 < N; i1 ++) + ts[i1] = Integer.parseInt(st.nextToken()); + + int[][] notSurp = new int[N][3]; + int[][] surp = new int[N][3]; + boolean[] outOfRange = new boolean[N]; + for(int i1 = 0; i1 < N; i1 ++){ + int num = ts[i1]; + if(num % 3 == 0){ + notSurp[i1][0] = num/3; notSurp[i1][1] = num/3; notSurp[i1][2] = num/3; + surp[i1][0] = num/3-1; surp[i1][1] = num/3; surp[i1][2] = num/3+1; + if(surp[i1][0] < 0 || surp[i1][2] > 10) + outOfRange[i1] = true; + else + outOfRange[i1] = false; + } + if(num % 3 == 1){ + notSurp[i1][0] = num/3; notSurp[i1][1] = num/3; notSurp[i1][2] = num/3+1; + surp[i1][0] = num/3-1; surp[i1][1] = num/3+1; surp[i1][2] = num/3+1; + if(surp[i1][0] < 0 || surp[i1][2] > 10) + outOfRange[i1] = true; + else + outOfRange[i1] = false; + } + if(num % 3 == 2){ + notSurp[i1][0] = num/3; notSurp[i1][1] = num/3+1; notSurp[i1][2] = num/3+1; + surp[i1][0] = num/3; surp[i1][1] = num/3; surp[i1][2] = num/3+2; + if(surp[i1][2] > 10) + outOfRange[i1] = true; + else + outOfRange[i1] = false; + } + }//for(int i1 = 0; i1 < N; i1 ++) + + int result = 0; + for(int i1 = 0; i1 < N-1; i1 ++){ + for(int i2 = i1 + 1; i2 < N; i2 ++){ + if(surp[i1][2] > surp[i2][2]){ + int tmp = surp[i1][0]; + surp[i1][0] = surp[i2][0]; + surp[i2][0] = tmp; + + tmp = surp[i1][1]; + surp[i1][1] = surp[i2][1]; + surp[i2][1] = tmp; + + tmp = surp[i1][2]; + surp[i1][2] = surp[i2][2]; + surp[i2][2] = tmp; + + tmp = notSurp[i1][0]; + notSurp[i1][0] = notSurp[i2][0]; + notSurp[i2][0] = tmp; + + tmp = notSurp[i1][1]; + notSurp[i1][1] = notSurp[i2][1]; + notSurp[i2][1] = tmp; + + tmp = notSurp[i1][2]; + notSurp[i1][2] = notSurp[i2][2]; + notSurp[i2][2] = tmp; + + boolean tmp2 = outOfRange[i1]; + outOfRange[i1] = outOfRange[i2]; + outOfRange[i2] = tmp2; + } + }//for + }//for + + /*for(int i1 = 0; i1 < N; i1 ++){ + System.out.println(surp[i1][0]+"" ""+surp[i1][1]+"" ""+surp[i1][2]); + System.out.println(notSurp[i1][0]+"" ""+notSurp[i1][1]+"" ""+notSurp[i1][2]); + }*/ + + int k = 1; + for(int i1 = N-1; i1 >= 0; i1 --){ + if(k <= S && surp[i1][2] >= p && notSurp[i1][2] < p && outOfRange[i1] == false){ + result ++; + k ++; + } + else if(notSurp[i1][2] >= p){ + result ++; + } + } + + System.out.println(""Case #""+Integer.toString(i+1)+"": ""+Integer.toString(result)); + + + }//for(int i = 0; i < T; i ++) + }//try + catch(IOException e) { + e.printStackTrace(); + } + + + } +} +" +A21769,"public class DancingWiththeGooglers { + + public static void main(String[] args) { + //initialize(); + java.util.Scanner sc = new java.util.Scanner(System.in); + int testCases = sc.nextInt(); + sc.nextLine(); + for(int i=0;i= upperBound-2){ + count++; + //processed[i1] = true; + } + else if(sum[i1] > lowerBound){ + //processed[i1] = true; + if(s > 0){ + s--; + count++; + } + } + } + + StringBuffer sb = new StringBuffer(""Case #""); + sb.append(i+1); + sb.append("": ""); + + sb.append(count); + System.out.println(sb); + } + } + +}" +A20498," + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + +public class Dancers { + + public static void main(String[] args) throws FileNotFoundException, IOException { + Scanner scanner = new Scanner(new File(""BLarge.in"")); + int t = scanner.nextInt(); + for (int i = 1; i < t+1; i++) { + System.out.print(""Case #"" + i + "": ""); + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int ace = 3*p; + int cont = 0; + for (int j = 0; j < n; j++) { + int score = scanner.nextInt(); + if ((((score >= ace-4) && (ace-4>0)) && (score < ace-2)) && (s>0)) { + cont++; + s--; + } + if (((score >= ace-2) /*&& (score <= (3*p)+2)) || ((score > (3*p)+2)*/) ) + { + cont++; + } + } + System.out.println(cont); + } + } +} +" +A20634,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package google2012; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author g + */ +public class Google2012 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + BufferedReader reader = new BufferedReader(new FileReader(args[0])); + String line; + int numCases = Integer.parseInt(reader.readLine()); + for (int i=0; i= minSumWithoutSpecial) { + counter++; + continue; + } + if (sum >= minSumWithSpecials && special > 0) { + counter++; + special--; + continue; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + counter); + } + } catch (IOException ex) { + Logger.getLogger(Google2012.class.getName()).log(Level.SEVERE, null, ex); + } + + } +} +" +A20353,"import java.util.Scanner; + + +public class Utils { + + public static int readIntegerLine(Scanner sc) { + String s = readStringLine(sc); + return Integer.parseInt(s); + } + + public static String readStringLine(Scanner sc) { + return sc.nextLine(); + } + + public static int readInteger(Scanner sc) { + return sc.nextInt(); + } + +} +" +A21030,"import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class dancing{ + public static void main(String args[]){ + try{ + PrintWriter out = new PrintWriter(new FileWriter(""output.txt"")); + Scanner sc = new Scanner(new File(args[0])); + int n, s, p, y; + + int t = sc.nextInt(); + sc.nextLine(); + + for(int i=1;i<=t;i++){ + y=0; + n = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + int score; + for(int j=0;j=p){ + y++; + } + else if(score/3+1>=p && s>0 && score!=0){ + y++; + s--; + } + }else if(score%3==1){ + if(score/3+1>=p){ + y++; + } + }else { + if(score/3+1>=p){ + y++; + } + else if(score/3+2>=p && s>0){ + y++; + s--; + } + } + } + out.println(""Case #""+i+"": ""+y); + } + out.close(); + }catch (Exception e){ + } + } +}" +A21762,"package Q1; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + //Open the file for reading + String thisLine; + int numTest = 0; + try { + BufferedReader br = new BufferedReader(new FileReader(""c:\\CodeJam\\Q1\\B-large.in"")); + Writer output = new BufferedWriter(new FileWriter(""c:\\CodeJam\\Q1\\B-large.out"")); + + numTest = Integer.parseInt(br.readLine()); + int ansCount = 0; + for (int i = 0; i < numTest; i++) { + ansCount = 0; + thisLine = br.readLine(); + String[] inputArray = thisLine.split(""\\s+""); + int dancerNum = Integer.parseInt(inputArray[0]); + int surpriseNum = Integer.parseInt(inputArray[1]); + int pNum = Integer.parseInt(inputArray[2]); + + //System.out.println(""Line 1 : d, s, p = ""+dancerNum+"", ""+surpriseNum+"", ""+pNum); + for (int j = 0; j < dancerNum; j++) { + int total = Integer.parseInt(inputArray[3+j]); + if (total < pNum) { + continue; + } + + int middleScore = total/3; + int modScore = total%3; + if (middleScore == 0 && modScore >= pNum) { + ansCount++; + continue; + } + if (middleScore >= pNum) { + ansCount++; + }else if (modScore == 0 && middleScore+1 >= pNum && surpriseNum > 0){ + ansCount++; + surpriseNum--; + }else if (modScore == 1 && middleScore+1 >= pNum) { + ansCount++; + }else if (modScore == 2 && middleScore+1 >= pNum) { + ansCount++; + }else if (modScore == 2 && middleScore+2 >= pNum && surpriseNum > 0) { + ansCount++; + surpriseNum--; + } + + //System.out.println(""total ""+ j +"" : ""+total + "", div = ""+middleScore+"", mod = ""+modScore); + } + + System.out.println(""Case #""+(i+1)+"": ""+ansCount); + + if (i == numTest-1) { + output.write(""Case #""+(i+1)+"": ""+ansCount); + }else { + output.write(""Case #""+(i+1)+"": ""+ansCount+""\n""); + } + + + } // end while + output.close(); + } // end try + catch (IOException e) { + System.err.println(""Error: "" + e); + } + } + +} +" +A20899,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +/** + * + */ + +/** + * @author antonio081014 + * @time: Apr 13, 2012, 5:01:31 PM + */ +public class Main { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + Main main = new Main(); + main.run(); + System.exit(0); + } + + public void run() throws Exception { + BufferedReader br = new BufferedReader(new FileReader(""input.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""output.out"")); + int T = Integer.parseInt(br.readLine()); + for (int t = 1; t <= T; t++) { + out.write(""Case #"" + Integer.toString(t) + "": ""); + String[] str = br.readLine().split(""\\s""); + int surprising = 0; + int partial = 0; + int sum = 0; + int N = Integer.parseInt(str[0]); + int S = Integer.parseInt(str[1]); + int p = Integer.parseInt(str[2]); + for (int i = 0; i < N; i++) { + int a = Integer.parseInt(str[i + 3]); + if ((a == 3 * p - 4 || a == 3 * p - 3) && p >= 2) { + surprising++; + sum++; + } + else if (a >= 3 * p - 2) { + sum++; + partial++; + } + } + // System.out.println(); + // System.out.println(sum); + // System.out.println(surprising); + // System.out.println(partial); + if (surprising >= S) { + out.write(Integer.toString(sum + S - surprising)); + // System.out.println(sum + S - surprising); + } + else { + // if (surprising + partial >= S) { + out.write(Integer.toString(sum)); + // System.out.println(sum); + // } + // else { + // // System.out.println(0); + // out.write(""0""); + // } + } + out.write(""\n""); + } + out.close(); + } +}" +A20023,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +public class InputReader { + private BufferedReader br = null; + + public InputReader(String fileName) { + try { + br = new BufferedReader(new FileReader(fileName)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public ArrayList loadLines() { + ArrayList lines = new ArrayList(); + String[] arrLines = null; + String tmp = null; + try { + while ((tmp = br.readLine()) != null) { + lines.add(tmp); + } + br.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return lines; + } +} +" +A20850,"import java.io.*; + +public class ProblemB { + static int[] cycles; + public static void main(String [] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + for(int i = 0; i < T; i++){ + String[] input = br.readLine().split("" ""); + int N = Integer.parseInt(input[0]); + int S = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + int max = Math.max(3*p - 2, p); // p, p-1, p-1 + int min = Math.max(3*p - 4, p); // p, p-1, p-2 OR p, p-2, p-2 + int count = 0; + for(int j = 0; j < N; j++){ + int sum = Integer.parseInt(input[j+3]); + if(sum >= max) count++; + else if(sum >= min && S > 0){ + //System.out.println(sum); + count++; + S--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + + } + } +} +" +A21015,"import java.io.*; +import java.util.*; + +public class B { + BufferedReader ins; + PrintStream outs; + + static String INPUT = ""B-large.in""; + static String OUTPUT; + + static { + OUTPUT = ""B.out""; + } + + public B(BufferedReader ins, PrintStream outs) { + this.ins = ins; + this.outs = outs; + } + + public int go(List list, int sr, int p) { + //Collections.sort(list); + //Collections.reverse(list); +// System.out.println(""List = "" + list); + // System.out.println(""Surprises = "" + sr); + // System.out.println(""P = "" + p); + + int count = 0; + for(int i = 0; i= p + 2 * Math.max(p-1,0)) { + // System.out.println(""Easy case = "" + list.get(i)); + count++; + } + else if((list.get(i) >= p + 2* Math.max(p-2,0)) && (sr > 0)) { + count++; + sr--; +// System.out.println(""Tough case = "" + list.get(i)); + } else { + // System.out.println(""Oops case = "" + list.get(i)); + } + } + return count; + } + + public void process() throws Exception { + //Read input + int t = Integer.parseInt(ins.readLine()); + + for(int T=1; T<=t;T++) { + String x = ins.readLine().trim().replaceAll("" +"", "" ""); + String[] tokens = x.split("" ""); + int n = Integer.parseInt(tokens[0]); + int sum = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + List list = new ArrayList(); + for(int i = 0; i inp=read_fil(""D:\\google_Jam\\B-large.in""); + // ArrayList inp=read_fil(""D:\\google_Jam\\A-large-practice.in""); + int lin_num=0; + int T=Integer.valueOf(inp.get(lin_num)); + lin_num++; + + for(int kk=0;kk=p){ + y++; + continue; + }else if(S>0 && s2==s3){ + s3++; + s2--; + if(s1+s2+s3==t[i] && s3>=p && s3>=p && s1>=0 && s2>=0 && s3>=0){ + S--; + y++; + continue; + } + } + + } + if(S>0){ + y=0; + for(int i=0;i0 && s2==s3){ + s3++; + s2--; + if(s1+s2+s3==t[i] && s3>=p && s1>=0 && s2>=0 && s3>=0){ + S--; + y++; + continue; + } + }else{ + int max=getmax(s1,s2,s3); + if(max>=p){ + y++; + continue; + } + } + + } + } + + writeFile(""Case #""+(kk+1)+"": ""+y); + + + } + + + } + + + private static int getmax(int s1, int s2, int s3) { + int max=0; + if(max read_fil(String file){ + ArrayList arr=new ArrayList(); + try{ + + FileInputStream fstream = new FileInputStream(file); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + while ((strLine = br.readLine()) != null) { + arr.add(strLine); + } + + in.close(); + }catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + return arr; + } + + public static void writeFile(String ss) { + String fileName = ""D:\\google_Jam\\Output.txt""; + + try { + FileWriter writer = new FileWriter(fileName,true); + writer.write(ss); + writer.write('\n'); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +}" +A21023,"import java.util.*; + +public class DancingGoogler{ + + public static void main(String[] args){ + Scanner scanner = new Scanner(System.in); + scanner.nextLine(); + int count = 1; + while(scanner.hasNextLine()){ + String[] tokens = scanner.nextLine().split("" ""); + int numContestants = Integer.parseInt(tokens[0]); + int numSuprises = Integer.parseInt(tokens[1]); + int minScore = Integer.parseInt(tokens[2]); + int[] scores = new int[numContestants]; + for(int i = 0; i < scores.length; ++i){ + scores[i] = Integer.parseInt(tokens[i + 3]); + } + DancingGoogler d = new DancingGoogler(numSuprises, minScore, scores); + System.out.println(""Case #"" + count + "": "" + d.getNumGooglersWithMinScore()); + ++count; + } + } + + public DancingGoogler(int numSuprises, int minScore, int[] scores){ + this.numSuprises = numSuprises; + this.minScore = minScore; + this.scores = scores; + } + + public int getNumGooglersWithMinScore(){ + int count = 0; + for(int score : scores){ + if(score == 0){ + if(minScore == 0){ + ++count; + } + continue; + } + if(score == 29){ + ++count; + continue; + } + if(score % 3 == 0){ + int av = score / 3; + if(av >= minScore){ + ++count; + }else{ + if(numSuprises > 0 && av >= minScore -1){ + ++count; + --numSuprises; + } + } + continue; + } + int av = score / 3; + int av1 = (score / 3) + 1; + int diffav = score - av * 3; + int diffav1 = av1 * 3 - score; + if(numSuprises > 0){ + if(diffav == 2){ + if(av1 >= minScore){ + ++count; + continue; + }else{ + if(av >= minScore || score - av*2 >= minScore){ + ++count; + --numSuprises; + continue; + } + } + }else{ + if(av >= minScore || score -av * 2 >= minScore){ + ++count; + continue; + } + if(av1 >= minScore){ + ++count; + --numSuprises; + continue; + } + } + }else{ + if(diffav == 2){ + if(av1 >= minScore){ + ++count; + continue; + } + }else{ + if(av >= minScore || score - av*2 >= minScore){ + ++count; + continue; + } + } + } + } + return count; + } + + private int numContestants; + private int numSuprises; + private int minScore; + private int[] scores; +}" +A21347,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +/** + * + * @author Chadi + */ + +class TestCase { + int googlers; + int surprises; + int minScore; + int[] scores; + public TestCase() { + + } + public int[] split(int sum, boolean surprise) { + if (sum == 0) { + return new int[]{0,0,0}; + } + else if (sum == 1) { + return new int[]{0,0,1}; + } + int[] res = new int[3]; + if (surprise == false) { + res[0] = sum/3; + res[1] = (sum - res[0]) / 2; + res[2] = sum - res[0] - res[1]; + } + else { + res[0] = (int)(Math.ceil(sum / 3.0)) + 1; + res[1] = (sum - res[0]) / 2; + res[2] = sum - res[0] - res[1]; + } + Arrays.sort(res); + while (res[2] - res[0] > 2) { + res[0]++; + res[2]--; + Arrays.sort(res); + } + return res; + } + public int solve() { + int count = 0; + for (int i = 0; i < googlers; i++) { + int[] curScores = split(scores[i], false); + //System.out.println(i + ""\t"" + Arrays.toString(curScores)); + if (curScores[2] >= minScore) { + count++; + } + else { + if (surprises > 0) { + //System.out.println(""Using a surprise!""); + int[] curScoresBest = split(scores[i], true); + //System.out.println(i + ""\t"" + Arrays.toString(curScoresBest)); + if (curScoresBest[2] >= minScore) { + count++; + surprises--; + } + } + } + } + + return count; + } +} + +public class B { + public static void main(String[] args) throws FileNotFoundException, IOException { + /* READ INPUT + DATA STRUCTURES */ + //String input = ""B-small-attempt1.in""; + String input = ""B-large.in""; + String output = input.replace("".in"", "".out""); + File f = new File(input); + Scanner sc = new Scanner(f); + + int T = Integer.parseInt(sc.nextLine()); + TestCase[] cases = new TestCase[T]; + for (int i = 0; i < T; i++) { + cases[i] = new TestCase(); + + /* Add inputs to this case */ + cases[i].googlers = sc.nextInt(); + cases[i].surprises = sc.nextInt(); + cases[i].minScore = sc.nextInt(); + + cases[i].scores = new int[cases[i].googlers]; + for (int k = 0; k < cases[i].googlers; k++) { + cases[i].scores[k] = sc.nextInt(); + } + + + + } + /* END READ INPUT + DATA STRUCTURES */ + + File out = new File(output); + if (out.exists()) { + out.delete(); + } + PrintWriter pw = new PrintWriter(new FileOutputStream(out, true)); + + for (int i = 0; i < T; i++) { + System.out.println(""Solving case: "" + ""#"" + (i+1)); + String result = ""Case #"" + (i+1) + "": "" + cases[i].solve(); + if (i <= T-2) { pw.println(result); } + else { pw.print(result); } + } + pw.close(); + } +}" +A20939,"import java.util.Scanner; + +public class DancingWithTheGooglers +{ + public static void main(String[] args) + { + Scanner read = new Scanner(System.in); + int[] scores = null; + int cases = 0; + int googlers = 0; + int suprising = 0; + int least = 0; + int num = 0; + + cases = read.nextInt(); + for (int i = 0; i < cases; i++) + { + num = 0; + googlers = read.nextInt(); + suprising = read.nextInt(); + least = read.nextInt(); + scores = new int[googlers]; + for (int j = 0; j < scores.length; j++) + scores[j] = read.nextInt(); + + if (least == 0) + System.out.println(""Case #"" + (i + 1) + "": "" + googlers); + else + { + for (int j = 0; j < scores.length; j++) + { + if (scores[j] % 3 == 2) + { + if (scores[j] / 3 + 1 >= least) + num++; + else if (scores[j] / 3 + 2 >= least && suprising > 0) + { + num++; + suprising--; + } + } + else if (scores[j] % 3 == 1) + { + if (scores[j] / 3 + 1 >= least) + num++; + } + else if (scores[j] != 0) + { + if (scores[j] / 3 >= least) + num++; + else if (scores[j] / 3 + 1 >= least && suprising > 0) + { + num++; + suprising--; + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + num); + } + } + } +}" +A22079,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingWithGoolers { + public static void main(String args[]) { + try { + BufferedReader inputReader = new BufferedReader(new FileReader( + ""input"")); + String line = inputReader.readLine(); + BufferedWriter outWriter = new BufferedWriter(new FileWriter( + ""output.txt"")); + int number = Integer.parseInt(line); + for ( int i = 1; i <= number; i++ ) { + String result = ""Case #"" + i + "": ""; + line = inputReader.readLine(); + String inputs[] = line.split("" ""); + int num = Integer.parseInt(inputs[0]); + int surprise = Integer.parseInt(inputs[1]); + int point = Integer.parseInt(inputs[2]); + int scores[] = new int[num]; + for ( int j = 0; j < num; j++ ) { + scores[j] = Integer.parseInt(inputs[3 + j]); + } + outWriter.write(result + + getResult(num, surprise, point, scores) + ""\n""); + } + outWriter.flush(); + outWriter.close(); + } catch ( FileNotFoundException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( IOException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static int getResult(int number, int surprise, int point, + int scores[]) { + int surpriseLimit = 3 * point - 4; + if ( surpriseLimit <= 0 ) { + surpriseLimit = point; + } + int acceptableLimit = 3 * point - 2; + if ( acceptableLimit <= 0 ) { + acceptableLimit = point; + } + int surpriseNum = 0; + int acceptableNum = 0; + for ( int i = 0; i < scores.length; i++ ) { + int score = scores[i]; + if ( score < acceptableLimit && score >= surpriseLimit ) { + surpriseNum++; + } else if ( score >= acceptableLimit ) { + acceptableNum++; + } + } + return acceptableNum + Math.min(surpriseNum, surprise); + } +} +" +A22669,"import java.io.File; +import java.io.FileOutputStream; +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.LinkedList; +import java.util.List; +import java.util.Scanner; + + +public class Solver { + + private final static String DIR_PATH = ""e:\\jam\\""; + private final static String IN_FILE_NAME = ""B-large.in""; + private final static String OUT_FILE_NAME = IN_FILE_NAME.replaceAll(""\\..*$"", "".out""); + + private final static File sInFile = new File(DIR_PATH, IN_FILE_NAME); + private final static File sOutFile = new File(DIR_PATH, OUT_FILE_NAME); + + private final PrintStream mOut; + private final Scanner mScanner; + + private static class ProxyOutputStream extends FilterOutputStream { + public ProxyOutputStream(OutputStream out) { + super(out); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + System.out.write(b, off, len); + super.write(b, off, len); + } + } + + public static void main(String[] args) { + try { + Solver solver = new Solver(sInFile, sOutFile); + solver.solve(); + } catch(IOException ex) { + ex.printStackTrace(); + } + } + + public Solver(File inFile, File outFile) throws IOException { + mScanner = new Scanner(inFile); + mOut = new PrintStream(new ProxyOutputStream(new FileOutputStream(outFile))); + } + + private void printSolution(int no, String solution) { + if(no == 0) { + throw new IllegalArgumentException(""Solution number is 0! Should start with 1!""); + } + mOut.println(String.format(""Case #%d: %s"", no, solution)); + } + + private void solve() throws IOException { + int problemsCount = mScanner.nextInt(); + mScanner.nextLine(); + for(int i = 0; i < problemsCount; i++) { + int participants = mScanner.nextInt(); + int surprises = mScanner.nextInt(); + int minBestScore = mScanner.nextInt(); + List scores = new LinkedList(); + for(int s = 0; s < participants; s++) { + scores.add(mScanner.nextInt()); + } + String solution = Integer.toString(solve(scores, minBestScore, surprises)); + printSolution(i + 1, solution); + } + } + + private int solve(List scores, int minBestScore, int surprises) { + int totalPassed = 0; + int almostPassed = 0; + for(Integer score : scores) { + int maxOk = 0; + int maxSurprise = 0; + + if(score > 0) { + int scoreCase = score % 3; + switch(scoreCase) { + case 0: + maxOk = score / 3; + maxSurprise = score / 3 + 1; + break; + case 1: + maxOk = maxSurprise = score / 3 + 1; + break; + case 2: + maxOk = score / 3 + 1; + maxSurprise = score / 3 + 2; + break; + } + } else { + maxOk = 0; + maxSurprise = 0; + } + + if(maxOk >= minBestScore) { + totalPassed++; + } else if(maxSurprise >= minBestScore) { + almostPassed++; + } + } + totalPassed += Math.min(surprises, almostPassed); + return totalPassed; + } +} +" +A22885,"import java.util.List; + + +public class Case implements Runnable { + + private int id; + private String output; + + private int n; + private int s; + private int p; + private List g; + + public Case(int id) { + this.id = id; + } + + public Case(int id, int n, int s, int p, List g) { + super(); + this.id = id; + this.n = n; + this.s = s; + this.p = p; + this.g = g; + } + + public String solve() { + int res = 0; + for (int googler : g) { + int b = googler / 3; + boolean div = googler % 3 == 0; + if (b >= p) { + res++; + continue; + } + if (p == b+1) { + if (div && s > 0 && b > 0) { + res++; + s--; + continue; + } + if (!div) { + res++; + continue; + } + } + if (p == b+2) { + if (3*b+2 == googler && s > 0) { + res++; + s--; + } + } + } + return String.valueOf(res); + } + + @Override + public void run() { + output = solve(); + } + + @Override + public String toString() { + return ""Case #"" + id + "": "" + output; + } + +}" +A22629,"import java.io.*; +import java.util.*; + +public class Googlers{ + + public static void main(String args[]){ + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""textfile.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + FileWriter ffstream = new FileWriter(""./output.txt""); + BufferedWriter out = new BufferedWriter(ffstream); + String strLine; + //Read File Line By Line + int i=0; + strLine = br.readLine(); + i= Integer.parseInt(strLine); + int j=1; + while (j<=i) { + // Print the content on the console + strLine = br.readLine(); + + new GoogleCount(strLine,j,out); + j++; + } + //Close the input stream + in.close(); + out.close(); + } + catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} + +" +A21754,"import java.io.*; + +class Googlers +{ + public static void main(String args[]) throws IOException + { + FileInputStream fstream = new FileInputStream(""B-large.in""); + DataInputStream dstream = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(dstream)); + FileWriter fw = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fw); + int lines = Integer.parseInt(br.readLine()); //lines LINES OF INPUT TO FOLLOW + for(int j=0;j=P) + result++; + else if((P==(divider+1)) && (S!=0)) + { + result++; + S--; + } + } + else if(remainder==1) + { + if(divider+1>=P) + result++; + } + else if(remainder==2) + { + if(divider+1>=P) + result++; + else if((P==(divider+2)) && (S!=0)) + { + result++; + S--; + } + } + + } + out.write(""""+result); + } + out.newLine(); + } + dstream.close(); + out.close(); + } +}" +A20908,"import java.util.Scanner; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int cases = Integer.parseInt(sc.nextLine()); + + for(int i = 0; i < cases; i++) { + Scanner line = new Scanner(sc.nextLine()); + int triplets = line.nextInt(); + int surprise = line.nextInt(); + int threshold = line.nextInt(); + + int enough = 0; + int borderline = 0; + + while(line.hasNextInt()) { + int score = line.nextInt(); + if(score == 0) { + if(threshold == 0) { + enough++; + } + } + else if(score == 1) { + if(threshold <= 1) { + enough++; + } + } + else { + int maxS, maxNS; + + int mod = score % 3; + int div = score / 3; + if(mod == 0) { + maxS = div+1; + maxNS = div; + } + else if(mod == 1) { + maxS = div+1; + maxNS = div+1; + } + else { + maxS = div+2; + maxNS = div+1; + } + + if(threshold <= maxNS) { + enough++; + } + else { + if(threshold <= maxS) { + borderline++; + } + } + + } + } + + System.out.printf(""Case #%d: %d\n"", i+1, enough + Math.min(borderline, surprise)); + } + + } + +} + +" +A22259,"import java.io.*; + + + +public class DancingGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + int T = 0; + int N = 0; + int S = 0; + int p = 0; + int ptr = 0; + int maxCount = 0; + int scoreSum = 0; + int score1 = 0; + int score2 = 0; + int score3 = 0; + String currentCase = null; + String inputFilename = ""B-large.in""; + String outputFilename = ""B-large.out""; + + BufferedWriter out = null; + try { + out = new BufferedWriter(new FileWriter(outputFilename)); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + + FileInputStream fStream = null; + try { + fStream = new FileInputStream(inputFilename); + } catch (FileNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + DataInputStream in = new DataInputStream(fStream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + + try { + T = Integer.parseInt(br.readLine()); + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + for(int i=0;i= p || score2 >= p || score3 >= p) { + maxCount++; + continue; + } + else { + if ((S > 0) && (scoreSum > 0)) { + if (scoreSum < (3*p-4)) { + //Minimum total points required for to get at least 1 ""best result"" + continue; + } + + while ((Math.abs(score1 - score2) < 3) && (Math.abs(score1 - score3) < 3) && (Math.abs(score2 - score3) < 3)) { + if (score1 >= score2 && score1 >= score3) { + if (score2 >= score3) { + if ((score1 + 1) - (score2 - 1) < 3) { + score1++; + score2--; + } + } + else { + if ((score1 + 1) - (score3 - 1) < 3) { + score1++; + score3--; + } + } + } + else if (score2 >= score1 && score2 >= score3) { + if (score1 >= score3) { + if ((score2 + 1) - (score1 - 1) < 3) { + score2++; + score1--; + } + } + else { + if ((score2 + 1) - (score3 - 1) < 3) { + score2++; + score3--; + } + } + } + else if (score3 >= score1 && score3 >= score2) { + if (score1 >= score2) { + if ((score3 + 1) - (score1 - 1) < 3) { + score3++; + score1--; + } + } + else { + if ((score3 + 1) - (score2 - 1) < 3) { + score3++; + score2--; + } + } + } + + if (score1 >= p || score2 >= p || score3 >= p) { + maxCount++; + S--; + break; + } + } + + } + } + + } + + try { + out.write(""Case #""+(i+1)+"": ""+maxCount+'\n'); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} +" +A20460,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + try { + Scanner in = new Scanner(new FileReader(""in.txt"")); + PrintWriter out = new PrintWriter(new FileWriter(""out.txt""), true); + + int t = in.nextInt(); + + for (int i = 1; i <= t; i++) { + int res = 0; + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int tt[] = new int[n]; + for (int j = 0; j < n; j++) { + tt[j] = in.nextInt(); + } + if (p == 0) { + res = n; + } else { + int min = 3 * p - 2; + for (int j = 0; j < n; j++) { + if (min <= tt[j]) res++; + } + int ttt[] = new int[n - res]; + int itr = 0; + for (int j = 0; j < n; j++) { + if (min > tt[j]) ttt[itr++] = tt[j]; + } + int minCrazy = 3 * p - 5; + int ress = 0; + for (int j = 0; j < itr; j++) { + if (minCrazy <= ttt[j] && ttt[j] != 0) ress++; + } + if (ress <= s) { + res += ress; + } else { + res += s; + } + } + + out.println(""Case #"" + i + "": "" + res); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +}" +A20103,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class DancingGooglers { + + private static String in; + private static String[] ins; + private static BufferedReader buf; + private static int cases; + private static File arquivo = new File(""output.txt""); + private static FileOutputStream fos; + + + public static void main(String[] args) { + buf = new BufferedReader(new InputStreamReader(System.in)); + try { + fos = new FileOutputStream(arquivo); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + System.exit(0); + } + + try { + in = buf.readLine(); + cases = Integer.parseInt(in); + } catch (IOException e) { + e.printStackTrace(); + System.exit(0); + } + + for (int i = 1; i <= cases; i++) { + int result = 0; + + try { + in = buf.readLine(); + ins = in.split("" ""); + } catch (IOException e) { + e.printStackTrace(); + System.exit(0); + } + + int N = Integer.parseInt(ins[0]); + int S = Integer.parseInt(ins[1]); + int P = Integer.parseInt(ins[2]); + int[] T = new int[N]; + + for (int j = 3; j < N+3; j++) { + T[j-3] = Integer.parseInt(ins[j]); + } + + for (int j = 0; j < N; j++) { + if (P == 0) { + result = N; + break; + } + + else if (P == 1) { + if (T[j] >= 1){ + result++; + continue; + } + } + + else { + if (T[j] >= 3*P - 2) { + result++; + continue; + } + + + if ((T[j] >= (3*P) - 4) && (S > 0)) { + result++; + S--; + continue; + } + + } + } + + try { + String res = ""Case #"" + i + "": "" + result + System.getProperty(""line.separator""); + fos.write(res.getBytes()); + } catch (IOException e) { + e.printStackTrace(); + System.exit(0); + } + + } + + } + +} +" +A22072,"package hk.polyu.cslhu.codejam.thread; + +import hk.polyu.cslhu.codejam.lib.ResultCollector; +import hk.polyu.cslhu.codejam.solution.Solution; + +import java.util.List; + +import org.apache.log4j.Logger; + +public abstract class JamThread implements Runnable { + public static Logger logger = Logger.getLogger(JamThread.class); + + private ResultCollector resultCollector; + private int indexOfList; + private List> testCaseList; + private Solution solution; + + /** + * Return the solution + * + * @return Solution + */ + public Solution getSolution() { + return solution; + } + + /** + * Set the solution used for test cases + * + * @param solution Solution + */ + public void setSolution(Solution solution) { + this.solution = solution; + } + + /** + * Return the result collector + * + * @return ResultCollector + */ + public ResultCollector getResultCollector() { + return resultCollector; + } + + /** + * Set the result collector + * + * @param resultCollector ResultCollector + */ + public void setResultCollector(ResultCollector resultCollector) { + this.resultCollector = resultCollector; + } + + /** + * Return the index of list + * + * @return int The index of list + */ + public int getIndexOfList() { + return indexOfList; + } + + /** + * Set the index of list + * + * @param indexOfList int The index of list + */ + public void setIndexOfList(int indexOfList) { + this.indexOfList = indexOfList; + } + + /** + * Set the list of test cases + * + * @param testCaseList List> + */ + public void setTestCaseList(List> testCaseList) { + this.testCaseList = testCaseList; + logger.debug(""Total "" + testCaseList.size() + "" test cases have been added""); + } + + /** + * Get the list of test cases + * + * @return List> The list of test cases + */ + public List> getTestCaseList() { + return this.testCaseList; + } + + public abstract void run(); +} +" +A21918," + +import java.io.IOException; +import java.io.InputStream; + +public class Input { + + static final int BUFFER_SIZE = 65535; + static final int STRING_SIZE = 1024; + + InputStream in; + byte[] buffer; + byte[] strBuffer; + int pos; + + public Input(InputStream in) { + this.in = in; + this.buffer = new byte[BUFFER_SIZE]; + this.strBuffer = new byte[STRING_SIZE]; + this.pos = BUFFER_SIZE; + } + + void skipWhitespace() throws IOException { + byte b; + do { + b = readByte(); + } while (b <= ' '); + --pos; + } + + public byte readByte() throws IOException { + if (pos == BUFFER_SIZE) { + in.read(buffer); + pos = 0; + } + return buffer[pos++]; + } + + public int readInt() throws IOException { + skipWhitespace(); + int number = 0; + int digit = readByte(); + int sign = 1; + if (digit == '-') { + sign = -1; + } else { + number = digit - '0'; + } + + digit = readByte(); + while (digit >= '0') { + number *= 10; + number += digit - '0'; + digit = readByte(); + } + + return sign * number; + } + + public long readLong() throws IOException { + skipWhitespace(); + long number = 0; + int digit = readByte(); + int sign = 1; + if (digit == '-') { + sign = -1; + } else { + number = digit - '0'; + } + + digit = readByte(); + while (digit >= '0') { + number *= 10; + number += digit - '0'; + digit = readByte(); + } + + return sign * number; + } + + public double readDouble() throws IOException { + skipWhitespace(); + double number = 0; + int digit = readByte(); + double sign = 1; + if (digit == '-') { + sign = -1; + } else { + number = digit - '0'; + } + + digit = readByte(); + while (digit >= '0') { + number *= 10; + number += digit - '0'; + digit = readByte(); + } + if (digit == '.' || digit == ',') { + digit = readByte(); + double remainder = 0; + int depth = 0; + while (digit >= '0') { + remainder *= 10; + remainder += digit - '0'; + depth++; + digit = readByte(); + } + if (depth == 1) { + number += remainder / 10; + } else { + number += remainder / (Math.pow(10, depth)); + } + + } + return sign * number; + } + public String readString() throws IOException { + skipWhitespace(); + int length = 0; + do { + strBuffer[length++] = readByte(); + } while (strBuffer[length - 1] > ' '); + return new String(strBuffer, 0, length - 1); + } + +} +" +A21862,"package com.codejam2012.qualificationround; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class B { + + public static int nTest; + public static int nGoogler; + public static int nSurprise; + public static int threshold; + public static int[] scores; + public static int nHaveHighScore; + public static int maxScore; + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(new File(""input.txt"")); + FileWriter writer = new FileWriter(new File(""output.txt"")); + + nTest = scanner.nextInt(); + + for (int i=1;i<=nTest;++i) { + nHaveHighScore = 0; + nGoogler = scanner.nextInt(); + nSurprise = scanner.nextInt(); + threshold = scanner.nextInt(); + scores = new int[nGoogler]; + for (int j=0;j= threshold) { + nHaveHighScore++; + } + else if (nSurprise > 0 && maxScore+1 >= threshold && maxScore-1 >= 0) { + nHaveHighScore++; + nSurprise--; + } + } + else if (scores[j] % 3 == 1) { + maxScore = scores[j] / 3 + 1; + if (maxScore >= threshold) { + nHaveHighScore++; + } + } + else if (scores[j] % 3 == 2) { + maxScore = scores[j] / 3 + 1; + if (maxScore >= threshold) { + nHaveHighScore++; + } + else if (nSurprise > 0 && maxScore+1 >= threshold && maxScore-1 >= 0) { + nHaveHighScore++; + nSurprise--; + } + } + } + writer.write(""Case #"" + i + "": "" + nHaveHighScore); + if (i < nTest) { + writer.write(""\n""); + } + writer.flush(); + } + writer.close(); + } +} +" +A20335,"package codejam; + +import java.util.*; +import java.io.*; + +public class DancingWithTheGooglers { + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""in.txt"")); + PrintWriter out = new PrintWriter(new File(""out.txt"")); + + int T = Integer.parseInt(in.readLine()); + for (int t = 1; t <= T; ++t) { + String[] parts = in.readLine().split(""[ ]+""); + int N = Integer.parseInt(parts[0]); + int S = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + int[] scores = new int[N]; + + for (int i = 0; i < N; ++i) + scores[i] = Integer.parseInt(parts[3 + i]); + + Arrays.sort(scores); + int cnt = 0; + for (int i = N - 1; i >= N - S; --i) { + + int mod = scores[i] % 3; + int score = scores[i] / 3; + if (mod == 1 || mod == 2) + ++score; + if (scores[i] > 1 && (mod == 0 || mod == 2)) + ++score; + score = Math.min(score, 10); + if (score >= p) + ++cnt; + //System.out.println(score); + } + + out.println(""Case #"" + t + "": "" + cnt); + } + + in.close(); + out.close(); + System.exit(0); + } +} +" +A21251,"import java.io.*; +import java.util.*; +import static java.lang.System.*; + +public class B +{ + // non-surprising + public static int best1(int x) + { + if (x%3 == 0) return x/3; + else return x/3+1; + } + // surprising + public static int best2(int x) + { + if (x == 0) return 0; + return (x+1)/3+1; + } + public static void main(String[] args) + { + Scanner sc = new Scanner(in); + int t = sc.nextInt(); + for (int c = 1; c <= t; c++) + { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] arr = new int[31]; + for (int i = 0; i < n; i++) arr[sc.nextInt()]++; + int ctr = 0; + for (int i = 30; i >= 0; i--) + { + if (best1(i) >= p) + { + ctr += arr[i]; + } + else + { + if (i > 1 && best2(i) >= p) + { + ctr += Math.min(s, arr[i]); + if (s > arr[i]) s -= arr[i]; + else s = 0; + } + } + } + out.printf(""Case #%d: %d\n"", c, ctr); + } + } +} +" +A22027,"import java.io.*; +import java.text.*; +import java.util.*; + +public class DancingWithGooglers { + + static BufferedReader stdin; + static StringTokenizer st; + + static String LINE() throws Exception { return stdin.readLine(); } + static String TOKEN() throws Exception { + while (st == null || !st.hasMoreTokens())st = new StringTokenizer(LINE()); + return st.nextToken(); + } + static int INT() throws Exception {return Integer.parseInt(TOKEN());} + static long LONG() throws Exception {return Long.parseLong(TOKEN());} + static double DOUBLE() throws Exception {return Double.parseDouble(TOKEN());} + + + static DecimalFormat DF = new DecimalFormat(""0.000"",new DecimalFormatSymbols(Locale.ENGLISH)); + + public static int score(int total) { + return (total + 2) / 3; + } + public static int surpriseScore(int total) { + if(total == 0)return 0; + if(total == 1)return 1; + return 2 + (total-2)/3; + } + + public static void main(String[] args) throws Exception { + String input = ""B-large.in""; + String output = ""B-large.out""; +// String input = ""testa.in""; +// String output = ""testa.out""; + stdin = new BufferedReader(new FileReader(new File(input))); + FileWriter frw = new FileWriter(output); + + int cases = INT(); + int cc = 1; + while(cases-->0) { + System.out.println(cc); + int N = INT(); + int S = INT(); + int p = INT(); + + int[] scores = new int[N]; + for(int i = 0; i < N; i++) { + scores[i] = INT(); + } + Arrays.sort(scores); + int solution = 0; + for(int i = scores.length - 1; i>=0; i--) { + if(score(scores[i]) >= p) { + solution++; + } else if(S > 0 && surpriseScore(scores[i]) >= p) { + S--; + solution++; + } + } + + frw.write(""Case #""+(cc++)+"": ""); + frw.write(""""+solution); + frw.write(""\n""); + + } + frw.flush(); + frw.close(); + + + + } + +} +" +A22627,"import java.io.*; +import java.util.*; + +public class B { + + final static boolean DEBUG = true; + + public Object solve () throws IOException { + int N = sc.nextInt(); + int S = sc.nextInt(); + int P = sc.nextInt(); + + int [] T = new int [N]; + for (int i = 0; i < N; ++i) + T[i] = sc.nextInt(); + + if (P == 0) + return N; + + if (P == 1) { + int cnt = 0; + for (int i = 0; i < N; ++i) + if (T[i] > 0) + ++cnt; + return cnt; + } + + int cnt = 0; + for (int i = 0; i < N; ++i) { + int s = T[i]; + if (s >= 3*P-2) + ++cnt; + else if (s >= 3*P-4 && S > 0) { + ++cnt; --S; + } + } + + return cnt; + } + + void init () { + } + + //////////////////////////////////////////////////////////////////////////////////// + + public B () throws IOException { + init(); + int N = sc.nextInt(); + start(); + for (int n = 1; n <= N; ++n) + print(""Case #"" + n + "": "" + solve()); + exit(); + } + + static MyScanner sc; + static long t; + + static void print (Object o) { + System.out.println(o); + if (DEBUG) + System.err.println(o + "" ("" + ((millis() - t) / 1000.0) + "")""); + } + + static void exit () { + if (DEBUG) { + System.err.println(); + System.err.println((millis() - t) / 1000.0); + } + System.exit(0); + } + + static void run () throws IOException { + sc = new MyScanner (); + new B(); + } + + public static void main(String[] args) throws IOException { + run(); + } + + static long millis() { + return System.currentTimeMillis(); + } + + static void start() { + t = millis(); + } + + static class MyScanner { + String next() throws IOException { + newLine(); + return line[index++]; + } + + char [] nextChars() throws IOException { + return next().toCharArray(); + } + + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + long nextLong() throws IOException { + return Long.parseLong(next()); + } + + String nextLine() throws IOException { + line = null; + return r.readLine(); + } + + + String [] nextStrings() throws IOException { + line = null; + return r.readLine().split("" ""); + } + + int [] nextInts() throws IOException { + String [] L = nextStrings(); + int [] res = new int [L.length]; + for (int i = 0; i < L.length; ++i) + res[i] = Integer.parseInt(L[i]); + return res; + } + + + long [] nextLongs() throws IOException { + String [] L = nextStrings(); + long [] res = new long [L.length]; + for (int i = 0; i < L.length; ++i) + res[i] = Long.parseLong(L[i]); + return res; + } + + boolean eol() { + return index == line.length; + } + + ////////////////////////////////////////////// + + private final BufferedReader r; + + MyScanner () throws IOException { + this(new BufferedReader(new InputStreamReader(System.in))); + } + + MyScanner(BufferedReader r) throws IOException { + this.r = r; + } + + private String [] line; + private int index; + + private void newLine() throws IOException { + if (line == null || index == line.length) { + line = r.readLine().split("" ""); + index = 0; + } + } + } + + static class MyWriter { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + + void print(Object o) { + pw.print(o); + } + + void println(Object o) { + pw.println(o); + } + + void println() { + pw.println(); + } + + public String toString() { + return sw.toString(); + } + } + + char [] toArray (Character [] C) { + char [] c = new char[C.length]; + for (int i = 0; i < C.length; ++i) + c[i] = C[i]; + return c; + } + + char [] toArray (Collection C) { + char [] c = new char[C.size()]; int i = 0; + for (char z : C) + c[i++] = z; + return c; + } + + Object [] toArray(int [] a) { + Object [] A = new Object[a.length]; + for (int i = 0; i < A.length; ++i) + A[i] = a[i]; + return A; + } + + String toString(Object [] a) { + StringBuffer b = new StringBuffer(); + for (Object o : a) + b.append("" "" + o); + return b.toString().trim(); + } + + String toString(int [] a) { + return toString(toArray(a)); + } +} +" +A20978,"package fixjava; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +/** + * Pair: typed 2-tuple + */ +public class Pair { + + private final L left; + private final R right; + + public R getRight() { + return right; + } + + public L getLeft() { + return left; + } + + public Pair(final L left, final R right) { + this.left = left; + this.right = right; + } + + /** Convenience method so type params of pair don't have to be specified: just do Pair.make(l, r) */ + public static Pair make(L left, R right) { + return new Pair(left, right); + } + + // --------------------------------------------------------------------------------------------------- + + private static final boolean objEquals(Object p1, Object p2) { + if (p1 == null) + return p2 == null; + return p1.equals(p2); + } + + @Override + public final boolean equals(Object o) { + if (!(o instanceof Pair)) { + return false; + } else { + final Pair other = (Pair) o; + return objEquals(getLeft(), other.getLeft()) && objEquals(getRight(), other.getRight()); + } + } + + @Override + public int hashCode() { + int hl = getLeft() == null ? 0 : getLeft().hashCode(); + int hr = getRight() == null ? 0 : getRight().hashCode(); + return (hl + (127 * hr)) ^ (hr << 1); + } + + // --------------------------------------------------------------------------------------------------- + + @Override + public String toString() { + return ""("" + getLeft() + "", "" + getRight() + "")""; + } + + // --------------------------------------------------------------------------------------------------- + + public static ArrayList getAllLefts(Iterable> list) { + ArrayList result = new ArrayList(); + for (Pair pair : list) + result.add(pair.getLeft()); + return result; + } + + public static ArrayList getAllRights(Iterable> list) { + ArrayList result = new ArrayList(); + for (Pair pair : list) + result.add(pair.getRight()); + return result; + } + + // --------------------------------------------------------------------------------------------------- + + public static , B> Comparator> comparatorOnLeft(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Pair o1, Pair o2) { + return o1.getLeft().compareTo(o2.getLeft()); + } + }; + } + + public static , B> Comparator> comparatorOnLeftRev(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Pair o1, Pair o2) { + return -o1.getLeft().compareTo(o2.getLeft()); + } + }; + } + + public static > Comparator> comparatorOnRight(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Pair o1, Pair o2) { + return o1.getRight().compareTo(o2.getRight()); + } + }; + } + + public static > Comparator> comparatorOnRightRev(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Pair o1, Pair o2) { + return -o1.getRight().compareTo(o2.getRight()); + } + }; + } + + static , B> Comparator> comparatorOnLeft(Collection> tupleCollection, + final boolean ascending) { + return new Comparator>() { + final int weight = ascending ? 1 : -1; + + @Override + public int compare(Pair o1, Pair o2) { + return o1.getLeft().compareTo(o2.getLeft()) * weight; + } + }; + } + + static > Comparator> comparatorOnRight(Collection> tupleCollection, + final boolean ascending) { + return new Comparator>() { + final int weight = ascending ? 1 : -1; + + @Override + public int compare(Pair o1, Pair o2) { + return o1.getRight().compareTo(o2.getRight()) * weight; + } + }; + } + + // --------------------------------------------------------------------------------------------------- + + /** Sort a List> in-place into order of increasing or decreasing K */ + public static , V> void sortPairsByLeft(List> list, boolean ascending) { + Collections.sort(list, comparatorOnLeft(list, ascending)); + } + + /** Sort a List> in-place into order of increasing K */ + public static , V> void sortPairsByLeft(List> list) { + Collections.sort(list, comparatorOnLeft(list, true)); + } + + /** Sort a List> in-place into order of increasing or decreasing V */ + public static > void sortPairsByRight(List> list, boolean ascending) { + Collections.sort(list, comparatorOnRight(list, ascending)); + } + + /** Sort a List> in-place into order of increasing V */ + public static > void sortPairsByRight(List> list) { + Collections.sort(list, comparatorOnRight(list)); + } + + /** Convert a map into a list of Pair, final order unspecified */ + public static ArrayList> mapToList(HashMap map) { + ArrayList> list = new ArrayList>(); + for (Entry ent : map.entrySet()) + list.add(new Pair(ent.getKey(), ent.getValue())); + return list; + } +} +" +A22587,"package qualifiers; + +import java.io.*; +import java.util.*; +import java.util.concurrent.*; + +public class QualifierB { + class Task implements Runnable { + private int num; + private String line; + + public Task(int num, String line) { + this.num = num; + this.line = line; + } + + @Override + public void run() { + String result = null; + + // BEGIN RESULT COMPUTATION + // ------------------------------------------------------------ + + String[] split_line = line.split("" ""); + int num_googlers = Integer.parseInt(split_line[0]); + int num_surprising = Integer.parseInt(split_line[1]); + int best_points = Integer.parseInt(split_line[2]); + int count = 0; + for (int j = 0; j < num_googlers; ++j) { + int total_points = Integer.parseInt(split_line[j + 3]); + total_points -= best_points; + if (total_points < 0) { + continue; + } + if (best_points * 2 - 2 <= total_points) { + ++count; + continue; + } + if (num_surprising > 0) { + if ((best_points - 2) * 2 <= total_points && total_points <= (best_points + 2) * 2) { + ++count; + --num_surprising; + } + } + } + + result = String.valueOf(count); + + // END RESULT COMPUTATION + // ------------------------------------------------------------ + + System.out.println(result); + reportResult(num, result); + } + } + + public static final int NUM_THREADS = 4; + + private String file_name; + private ArrayList results; + + public QualifierB(String file_name) { + this.file_name = file_name; + } + + public ArrayList calculate() throws IOException, + InterruptedException { + results = new ArrayList(); + ThreadPoolExecutor tpe = new ThreadPoolExecutor(NUM_THREADS, + NUM_THREADS, 2, TimeUnit.SECONDS, + new LinkedBlockingQueue()); + FileReader fr = new FileReader(file_name); + BufferedReader br = new BufferedReader(fr); + String line = br.readLine(); + System.out.println(""Header: "" + line); + String[] ints = line.split("" ""); + + // BEGIN HEADER PARSING + // -------------------------------------------------------------------- + + int total_num = Integer.parseInt(ints[0]); + + // END HEADER PARSING + // -------------------------------------------------------------------- + + for (int i = 0; i < total_num; ++i) { + results.add(""""); + + // BEGIN READING CASE + // ---------------------------------------------------------------- + + line = br.readLine(); + tpe.execute(new Task(i, line)); + + // END READING CASE + // ---------------------------------------------------------------- + + } + + br.close(); + fr.close(); + tpe.shutdown(); + tpe.awaitTermination(8, TimeUnit.MINUTES); + return results; + } + + public synchronized void reportResult(int num, String result) { + results.set(num, result); + } + + public static void main(String[] args) throws IOException, + InterruptedException { + long time0 = System.currentTimeMillis(); + if (args.length < 1) { + System.out.println(""Remember command line argument""); + System.exit(1); + } + QualifierB runner = new QualifierB(args[0]); + ArrayList results = runner.calculate(); + System.out.println(""Run time: "" + (System.currentTimeMillis() - time0) + / 1000 + ""s\n""); + FileWriter fw = new FileWriter(""results.txt""); + BufferedWriter bw = new BufferedWriter(fw); + for (int i = 0; i < results.size(); ++i) { + System.out.println(""Case #"" + (i + 1) + "": "" + results.get(i)); + bw.write(""Case #"" + (i + 1) + "": "" + results.get(i) + ""\n""); + } + bw.close(); + fw.close(); + } +} +" +A20866,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; +import java.util.Vector; + +public class Main { + public static int problemC(Vector V,int N,int S,int P) + { + int Nbr=0; + for(int i=0;i V = new Vector(); + for(int j=0;j inputList = FileIO.readFile(""B-large.in""); + List outputList = new ArrayList(); + + int caseNo = 1 ; + int testCaseCount = Integer.parseInt(inputList.get(0)); + + while (caseNo <= testCaseCount) { + Scores s = new Scores(inputList.get(caseNo)); + outputList.add(""Case #"" +caseNo +"": "" +s.getMaxNumberOfGooglerOverScore()); + + caseNo++; + } + + FileIO.writeFile(""B-large.out"", outputList); + } + +} +" +A22628,"package quialification; + +import base.Base; + +import java.io.PrintStream; +import java.util.Scanner; + +/** + * Created with IntelliJ IDEA. + * User: babulya + * Date: 14.04.12 + * Time: 19:10 + * To change this template use File | Settings | File Templates. + */ +public class B extends Base { + + private static int maxNoSurprising(int googler) { + switch (googler % 3) { + case 0: return googler / 3; + case 1: return googler / 3 + 1; + case 2: return googler / 3 + 1; + } + throw new RuntimeException(""AAA""); + } + + private static int maxSurprising(int googler) { + switch (googler % 3) { + case 0: return googler > 0 ? googler / 3 + 1 : 0; + case 1: return googler / 3 + 1; + case 2: return googler / 3 + 2; + } + throw new RuntimeException(""AAA""); + } + + @Override + protected void solve(Scanner in, PrintStream out) { + int T = in.nextInt(); + for (int i = 0; i < T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] googlers = new int[N]; + for (int j = 0; j < N; j++) { + googlers[j] = in.nextInt(); + } + // + int answer = 0; + for (int googler : googlers) { + if (maxNoSurprising(googler) >= p) { + answer++; + } else if (maxSurprising(googler) >= p && S > 0) { + answer++; + S--; + } + } + // + out.println(String.format(""Case #%d: %d"", (i+1), answer)); + } + } + + public static void main(String[] args) { + new B(); + } +} +" +A20810,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package codejam; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author VISHAL + */ +public class Googlers { + public static void main(String args[]) throws IOException{ + Scanner in=new Scanner(new File(""H:\\in.txt"")); + FileWriter fout=new FileWriter(""H:\\out.txt""); + PrintWriter outfile=new PrintWriter(fout); +// Scanner in=new Scanner(System.in); + int t; + t=in.nextInt(); + for(int i=0;i=3*p-2) + count++; + else if(s!=0 && s1>=3*p-4) + { + s--; + count++; + } + } + outfile.println(""Case #""+(i+1)+"": ""+count); + } + outfile.close(); + } + +} +" +A22221,"package codejam; + +/** + * @author kaaja + * + */ + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.FilenameFilter; + +public class Codejam { + + private static File[] getInputFiles(String filePath) { + File dir = new File(filePath); + // filter .in files + FilenameFilter onlyInFiles = new FilenameFilter() { + public boolean accept(File file, String name) { + return name.endsWith("".in"") || file.isFile(); + } + }; + File[] inputFiles = dir.listFiles(onlyInFiles); + return inputFiles; + } + + private static void processFile(File fileName) { + System.out.println(""Processing file "" + fileName); + try { + // get reader for current file + BufferedReader br = new BufferedReader(new FileReader(fileName)); + // create writer using current file + .out + BufferedWriter bw = new BufferedWriter(new FileWriter( + fileName.getAbsolutePath() + "".out"")); + // get test cases + int testCases = Integer.parseInt(br.readLine()); + // process all test cases + for (int currTestCase = 1; currTestCase <= testCases; currTestCase++) { + String testCaseLine = br.readLine(); + String[] testCaseLineNumbers = testCaseLine.split("" ""); + int N = Integer.parseInt(testCaseLineNumbers[0]); + int S = Integer.parseInt(testCaseLineNumbers[1]); + int p = Integer.parseInt(testCaseLineNumbers[2]); + int minNormalGradesLimit = Math.max(p * 3 - 2, 0); + int minSurprisingGradesLimit = Math.max(minNormalGradesLimit - 2, 0); + int normalBestResults = 0; + int surprisingBestResults = 0; + for (int i = 0; i < N; i++) { + int currentGrades = Integer + .parseInt(testCaseLineNumbers[3 + i]); + if (currentGrades >= minNormalGradesLimit) + normalBestResults++; + else if (currentGrades >= minSurprisingGradesLimit && surprisingBestResults < S && currentGrades > 0) + surprisingBestResults++; + } + String result = Integer.toString(normalBestResults + + surprisingBestResults); + String currTestCaseResult = ""Case #"" + currTestCase + "": "" + + result; + System.out.println(currTestCaseResult); + bw.write(currTestCaseResult); + bw.newLine(); + } + // close the reader and writer + br.close(); + bw.flush(); + bw.close(); + } catch (Exception e) {// catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + System.out.println(""start""); + // get files to process + File[] inputFiles = getInputFiles(""data""); + if (inputFiles != null) { + for (File inputFile : inputFiles) + processFile(inputFile); + } + } + +} +" +A21405,"import java.util.ArrayList; + + +public class Googler { + + private String total; + private ArrayList triplets; + + public Googler(String _total,ArrayList _triplets){ + total=_total; + triplets = _triplets; + } + + public void setTriplets(ArrayList triplets) { + this.triplets = triplets; + } + public ArrayList getTriplets() { + return triplets; + } + public void setTotal(String total) { + this.total = total; + } + public String getTotal() { + return total; + } + + +} +" +A20289,"package ProblemB; + +import java.io.*; +import java.util.StringTokenizer; + +public class Dancing { + + public Dancing() { + // TODO Auto-generated constructor stub + } + + + public static void dancing()throws IOException{ + BufferedReader rdr = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""B.out"")); + int cases = Integer.parseInt(rdr.readLine()); + + for (int i = 0; i < cases; i++) { + String line = rdr.readLine(); + StringTokenizer st = new StringTokenizer(line); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int result = 0; + + for(int j=0; j= p*3 || x == p*2 + (p-1) || x == p + (p-1)*2){ + result++; + } + else{ + if((s>0) && (x == p*2 + (p-2) || x == p + (p-1) +(p-2) || x == p + (p-2)*2 )){ + result++; + s--; + } + } + } + + } + + + pw.println(""Case #""+(i+1)+"": ""+result); + } + + + pw.close(); + rdr.close(); + } + + /** + * @param args + */ + public static void main(String[] args)throws IOException { + // TODO Auto-generated method stub + dancing(); + } + +} +" +A21641,"import java.util.Scanner; + + +public class C { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int no = sc.nextInt(); + + for (int s = 1; s <= no; s++) { + int players = sc.nextInt(); + int stars = sc.nextInt(); + int best = sc.nextInt(); + + int count = 0; + + int k; + for (int i = 0; i < players; i++) { + int j = sc.nextInt(); + k = (int) Math.floor(j / 3); + if (k >= best) { + count++; + } else if (k < best) { + int diff = j - (k * 3); + if (diff == 1 && (diff + k) == best) { + count++; + continue; + } else if (diff == 2) { + if ((k + 1) == best) { + count++; + continue; + } else if (stars > 0 && (k + diff) == best) { + count++; + stars--; + continue; + } + } else if (diff == 0) { + int first = k - 1; + int second = k; + int third = k + 1; + if ((stars > 0) && (third == best) && first >= 0) { + stars--; + count++; + continue; + } + } + } + + + } + System.out.println(""Case #"" + s + "": "" + count); + + } + } +} +" +A21859,"package gs.taral.gcj2012; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +public class Dancing { + public static void main(String[] args) throws NumberFormatException, IOException { + List input = readInput(args[0]); + List output = solve(input); + writeOutput(args[1], output); + } + + private static String solveCase(String line) { + String[] tokens = line.split("" ""); + int n = Integer.parseInt(tokens[0]); + int s = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int[] t = new int[n]; + for (int i = 3; i < tokens.length; i++) + t[i - 3] = Integer.parseInt(tokens[i]); + int definitely = 0; + int possibly = 0; + for (int score : t) { + if (score >= 3 * p - 2) + definitely++; + else if (p > 1 && score >= 3 * p - 4 ) + possibly++; + } + int result = definitely + Math.min(possibly, s); + return String.valueOf(result); + } + + private static List solve(List input) { + List output = new ArrayList(); + for (String line : input) + output.add(solveCase(line)); + return output; + } + + private static List readInput(String filename) throws FileNotFoundException, + IOException { + BufferedReader in = new BufferedReader(new FileReader(filename)); + List input = new ArrayList(); + int n = Integer.parseInt(in.readLine()); + while (true) { + String line = in.readLine(); + if (line == null) + break; + input.add(line); + } + if (input.size() != n) + throw new IllegalArgumentException(); + return input; + } + + private static void writeOutput(String filename, List output) throws IOException { + PrintWriter out = new PrintWriter(new FileWriter(filename)); + for (int i = 0; i < output.size(); i++) { + int caseNumber = i + 1; + String line = output.get(i); + out.println(""Case #"" + caseNumber + "": "" + line); + } + out.close(); + } +} +" +A20627,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancingwiththegooglers; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +/** + * + * @author Kholoud + */ +public class DancingWithTheGooglers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + FileInputStream ifstream = new FileInputStream(""C:\\Users\\Kholoud\\Downloads\\B-large.in""); + DataInputStream in = new DataInputStream(ifstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + int n = Integer.parseInt( br.readLine()); + String line; + for(int i = 0;i0 && surprisePass(Score, p)) + { + count++; + surCount--; + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + count); + } + + } catch (Exception e) { + System.out.print(e.toString()); + } + } + public static boolean pass(int num,int p) + { + if((num%3 == 0 && num/3 >= p) || ((num-1)%3 == 0 && ((num-1)/3)+1 >= p) || ((num-2)%3 == 0 && ((num-2)/3)+1 >= p)) + { + return true; + } + return false; + } + public static boolean surprisePass(int num,int p) + { + if(((num-2)%3 == 0 && ((num-2)/3)+2 >= p) || ((num-3)%3 == 0 && ((num-3)/3)+2 >= p) || ((num-4)%3 == 0 && ((num-4)/3)+2 >= p)) + { + return true; + } + return false; + } +} +" +A21790,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Arrays; + +public class problemB { + + public static void main(String[] args) throws Exception{ + new problemB().run(); + } + + public void run() throws Exception { + BufferedReader in = new BufferedReader(new FileReader(""inputB.txt"")); + PrintWriter out = new PrintWriter(new FileWriter(""output.txt"")); + int T = Integer.parseInt(in.readLine()); + int maxS[] = new int[31]; + int maxJ[] = new int[31]; + Arrays.fill(maxS, -1); + Arrays.fill(maxJ, -1); + for(int x = 0; x<=10; x++) + for(int y = 0; y<=10; y++) + for(int z = 0; z<=10; z++){ + if(Math.abs(x-y) > 2 || Math.abs(x-z)>2 || Math.abs(y-z)>2)continue; + int sum = x+y+z; + if(Math.abs(x-y) == 2 || Math.abs(x-z) == 2 || Math.abs(y-z) == 2) { + maxS[sum] = Math.max(maxS[sum], Math.max(x, Math.max(y, z))); + continue; + } + maxJ[sum] = Math.max(maxJ[sum], Math.max(x, Math.max(y, z))); + } + for(int i=0; i<=30; i++){ + //System.out.println(i+"" maxS = ""+maxS[i]+"" \t maxJ = ""+maxJ[i]); + } + for(int step = 1; step <= T; step++){ + String []sp = in.readLine().split("" ""); + int n = Integer.parseInt(sp[0]), s = Integer.parseInt(sp[1]), p = Integer.parseInt(sp[2]); + int a[] = new int[n]; + for(int i=0; i= p){ + answer++; + used[i] = true; + + } else if(leftS > 0 && maxS[a[i]] >= p){ + leftS--; + answer++; + } + } + //System.out.println(Arrays.toString(used)+"" ""+leftS); + //System.out.println(""Case #""+step+"": ""+answer); + out.println(""Case #""+step+"": ""+answer); + } + out.close(); + } +} +" +A21617,"import java.util.*; + +/** + * + * @author Izhari Ishak Aksa + */ +public class ProblemB { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int t = 1; t <= T; t++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int ret = 0; + + for (int i = 0; i < n; i++) { + int a = sc.nextInt(); + int b = a / 3; + int c = a % 3; + if (b >= p) { + ret++; + } else if (b + 1 >= p && c >= 1) { + ret++; + } else if (b + 2 >= p && c >= 2 && s > 0) { + ret++; + s--; + } else if (b + 1 >= p && s > 0 && b > 1) { + ret++; + s--; + } + } + System.out.println(""Case #"" + t + "": "" + ret); + } + } + +} +" +A20773,"package qualification.Dancing; + +import java.io.*; +import qualification.Tongues.Tongues; + +/** + * + * @author farshid + */ +public class Interface { + + public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, IOException { + + String inPath, outPath; + + IO.println(""Enter input path:""); + inPath = IO.readln(); + IO.println(""Enter output path:""); + outPath = IO.readln(); + + IO.println(""Solving...""); + + Dancing d = new Dancing(); + FileInputStream fis = new FileInputStream(inPath); + InputStreamReader in = new InputStreamReader(fis, ""UTF-8""); + BufferedReader reader = new BufferedReader(in); + + FileOutputStream fos = new FileOutputStream(outPath); + OutputStreamWriter out = new OutputStreamWriter(fos, ""UTF-8""); + BufferedWriter writer = new BufferedWriter(out); + + int count = Integer.parseInt(reader.readLine()); + int[] output = new int[count]; + + for (int i = 0; i < count; i++) { + output[i] = d.solve(reader.readLine()); + } + + reader.close(); + + for (int i = 0; i < count; i++) { + writer.write(""Case #"" + (i + 1) + "": "" + output[i]); + writer.newLine(); + } + + writer.close(); + + IO.println(""Done.""); + IO.readln(); + + } +} +" +A20859,"package utils; + +/** + * + * @author Fabien Renaud + */ +public abstract class Jam implements Runnable, JamParser { + + protected final String[] lines; + protected final JamCase[] cases; + protected final int t; + private final String filenameInput; + private final String filenameOutput; + private final String[] output; + private final StopWatch timer; + private int count; + + protected Jam(String filename) { + this.filenameInput = filename; + this.filenameOutput = filename.replace("".in"", "".out""); + this.count = 0; + this.lines = File.readAllLines(filenameInput); + this.timer = new StopWatch(); + this.t = Integer.parseInt(lines[0]); + this.cases = new JamCase[t]; + this.output = new String[t]; + File.delete(filenameOutput); + } + + protected final synchronized void appendOutput(int number, String result) { + output[number - 1] = String.format(""Case #%1$d: %2$s"", number, result); + count++; + if (count == t) { + timer.stop(); + saveOutput(); + } + } + + private void saveOutput() { + if (count != t) { + System.err.println(String.format(""%1$d results are missing. File not saved."")); + } else { + File.writeAllLines(filenameOutput, output); + System.out.println(""File saved at "" + filenameOutput); + System.out.println(""---------- OUTPUT ----------""); + for (String s : output) { + System.out.println(s); + } + System.out.println(""--- Processed in "" + timer.getElapsedSeconds() + "" seconds.""); + } + } + + @Override + public final void run() { + int j; + count = 0; + + timer.start(); + for (int i = 1; i <= t; i++) { + j = i - 1; + cases[j] = getJamCase(i); + if (cases[j] != null) { + new Thread(cases[j]).start(); + } + } + } +} +" +A21894,"import java.util.*; +import java.io.*; + +public class A +{ + private Scanner reader; + private PrintWriter writer; + + public A(String inFile, String outFile) + { + try { + reader = new Scanner(new File(inFile)); + writer = new PrintWriter(new File(outFile)); + init(); + } + catch (Exception ex ) { + ex.printStackTrace(); + } + } + + private void init() { + int T = reader.nextInt(); + for (int i=1; i<=T; i++) { + int N = reader.nextInt(); + int S = reader.nextInt(); + int p = reader.nextInt(); + int med = p*3; + int vlow = med - 2; + if (vlow < p) + vlow = p; + int slow = med - 4; + if (slow < p) + slow = p; + int res = 0; + for (int j=0; j= vlow) { + res ++; + } + else if ( k >= slow && S > 0) { + res++; + S--; + } + } + + String out = ""Case #""+i+"": "" + res +""\n""; + writer.write(out); + writer.flush(); + } + + writer.close(); + } + + public static void main(String[] args) + { + new A(""/Users/prabhaks/work/workspace/Test/src/in.txt"", ""/Users/prabhaks/work/workspace/Test/src/out.txt""); + } +}" +A20069,"import java.io.*; +import java.util.*; +public class Dancing { + static void solve() throws IOException { + int T = nextInt(); + for(int c = 1; c <= T; c++) { + int N = nextInt(); + int S = nextInt(); + int P = nextInt(); + int[] sc = new int[N]; + for(int i = 0; i < sc.length; i++) + sc[i] = nextInt(); + Arrays.sort(sc); + int res = 0; + for(int i = sc.length - 1, used = S; i >= 0; i--) { + if(3*P - 2 <= sc[i]) + res++; + else { + if(used > 0 && sc[i] >= 2 && (3*P - 4 == sc[i] || 3*P - 3 == sc[i])) { + res++; + used--; + } + } + } + out.println(""Case #"" + c + "": "" + res); + } + } + public static void main(String[] args) { + try { + br = new BufferedReader(new FileReader(""input.txt"")); + out = new PrintWriter(new BufferedWriter(new FileWriter(""output.txt""))); + solve(); + out.close(); + } catch (Throwable e) { + e.printStackTrace(); + System.exit(239); + } + } + static BufferedReader br; + static StringTokenizer st; + static PrintWriter out; + static String nextToken() throws IOException { + while (st == null || !st.hasMoreTokens()) { + String line = br.readLine(); + if (line == null) { + return null; + } + st = new StringTokenizer(line); + } + return st.nextToken(); + } + static int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + static long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + static double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } +} +" +A21399,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class source { + + public static void main(String args[ ]) throws IOException { + + FileInputStream fstream = new FileInputStream(""text.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + int c = 1; + int f = 0; + int sur = 0; + boolean b = false; + + br.readLine(); + while ((strLine = br.readLine()) != null) { + String[] array = strLine.split("" ""); + int[] array2 = new int[array.length]; + + for (int i = 0; i < array.length; i++) { + array2[i] = Integer.parseInt(array[i]); + } + + for (int s = 3; s= array2[2]) || (j >= array2[2]) || (k >= array2[2])) + && ((i-j >= 0) && (i-j <= 1)) + && ((i-k >= 0) && (i-k <= 1)) + && ((k-k >= 0) && (j-k <= 1))) { + b = true; + //System.out.println(i + "" "" + j + "" "" + k); + } + } + } + } + + if (b) { + f++; + b=false; + } + else { + b = false; + for (int i = 0; i <= 10 && !b; i++) { + for (int j = 0; j <= 10 && !b; j++) { + for (int k = 0; k <= 10 && !b; k++) { + + if (i+j+k == array2[s] + && ((i >= array2[2]) || (j >= array2[2]) || (k >= array2[2])) + && ((i-j >= 0) && (i-j <= 2)) + && ((i-k >= 0) && (i-k <= 2)) + && ((k-k >= 0) && (j-k <= 2))) { + b = true; + //System.out.println(i + "" "" + j + "" "" + k); + } + } + } + } + if (b) { + sur++; + b=false; + } + } + } + + if (sur >= array2[1]) { + System.out.println(""Case #"" + c + "": "" + (f + array2[1])); + } + else { + System.out.println(""Case #"" + c + "": "" + (f + sur)); + } + f = 0; + sur = 0; + c++; + } + } +} +" +A22331,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class Dancing_With_the_Googlers { + public static void main(String[] args) { + try { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""B-large.out"")); + Dancing_With_the_Googlers x = new Dancing_With_the_Googlers(); + String str; + in.readLine(); + while ((str = in.readLine()) != null) { + String res = x.convert(str); + out.write(res+""\n""); + } + in.close(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + int count=1; + String convert(String in) + { + String op[] = in.split("" ""); + int no_of_googlers = Integer.parseInt(op[0]); + int suprisingTriplets = Integer.parseInt(op[1]); + int bestresult = Integer.parseInt(op[2]); + int current_googler_score = 0; + int valid_score = 0; + int min_best_score = bestresult+2*(bestresult-1); + if (min_best_score == 0){ valid_score = no_of_googlers;return ""Case #""+(count++)+"": ""+valid_score;} + int sup =0; + for (int i=0; i= min_best_score) { + valid_score++; + } + else if ( current_googler_score == min_best_score-1 || current_googler_score == min_best_score-2 ){ + if ( current_googler_score != 0){ + sup++; + } + } + } + if( suprisingTriplets <= sup ){ + valid_score = valid_score + suprisingTriplets; + } + else { + valid_score = valid_score + sup; + } + return ""Case #""+(count++)+"": ""+valid_score; + } + +} +" +A20993,"package fixjava; + +import java.util.ArrayList; + +/** + * String splitter, this fixes the problem that String.split() has of losing the last token if it's empty. It also uses + * CharSequences rather than allocating new String objects. + */ +public class Split { + + /** + * String splitter, this fixes the problem that String.split() has of losing the last token if it's empty. It also uses + * CharSequences rather than allocating new String objects. + */ + public static ArrayList splitAsList(String str, String sep) { + int strLen = str.length(); + int sepLen = sep.length(); + assert sepLen > 0; + + ArrayList parts = new ArrayList(); + for (int curr = 0; curr <= strLen;) { + // Look for next token + int next = str.indexOf(sep, curr); + // Read to end if none + if (next < 0) + next = strLen; + // Add next token + parts.add(str.subSequence(curr, next)); + // Move to end of separator, or past end of string if we're at the end + // (by stopping when curr <= strLen rather than when curr < strLen, + // we avoid the problem inherent in the Java standard libraries of + // dropping the last field if it's empty; fortunately + // str.indexOf(sep, curr) still works when curr == str.length() + // without throwing an index out of range exception). + curr = next + sepLen; + } + return parts; + } + + public static CharSequence[] splitAsArray(String str, String sep) { + ArrayList list = splitAsList(str, sep); + CharSequence[] arr = new CharSequence[list.size()]; + list.toArray(arr); + return arr; + } + + public static ArrayList splitAsListOfString(String str, String sep) { + ArrayList list = splitAsList(str, sep); + ArrayList listOfString = new ArrayList(list.size()); + for (CharSequence cs : list) + listOfString.add(cs.toString()); + return listOfString; + } + + /** For compatibility only, slower because it creates new String objects for each CharSequence */ + public static String[] split(String str, String sep) { + ArrayList list = splitAsList(str, sep); + String[] arr = new String[list.size()]; + for (int i = 0; i < list.size(); i++) + arr[i] = list.get(i).toString(); + return arr; + } + + // public static void main(String[] args) { + // System.out.println(splitAsList("""", ""\t"")); + // System.out.println(splitAsList(""\t"", ""\t"")); + // System.out.println(splitAsList(""a\t"", ""\t"")); + // System.out.println(splitAsList(""\ta"", ""\t"")); + // System.out.println(splitAsList(""\ta\t"", ""\t"")); + // System.out.println(splitAsList(""a\tb"", ""\t"")); + // System.out.println(splitAsList(""a\tb\t"", ""\t"")); + // System.out.println(splitAsList(""\ta\tb"", ""\t"")); + // System.out.println(splitAsList("""", ""SEP"")); + // System.out.println(splitAsList(""SEP"", ""SEP"")); + // System.out.println(splitAsList(""aSEP"", ""SEP"")); + // System.out.println(splitAsList(""SEPaSEPb"", ""SEP"")); + // System.out.println(splitAsList(""aSEPbSEP"", ""SEP"")); + // } + +} +" +A22736,"package er.dream.codejam.train; + +import java.util.ArrayList; +import java.util.List; + +import er.dream.codejam.helpers.ProblemSolver; + +public class DancingWithGooglers extends ProblemSolver{ + + public static void main(String[] args) { + new DancingWithGooglers().execute(); + } + + @Override + protected List handleInput() { + List result = new ArrayList(); + int[] settings = fileHandler.readIntArray(); + + for(int i=0;i= minimumScoreForUnsurprising) + unsuprising++; + else if(score >= minimumScoreForSurprising) + surprisesMax++; + } + int maxGooglers = unsuprising + Math.min(surprises, surprisesMax); + result.add(""""+maxGooglers); + } + + return result; + } + +} +" +A21495," +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +/** + * + * @author baskara + */ +public class Dancing { + + /** + * @param args the command line arguments + */ + private static File inputFile = new File(""/home/baskara/input.txt""); + + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + int t = Integer.parseInt(reader.readLine()); + for (int i = 0; i < t; i++) { + System.out.print(""Case #"" + (i + 1) + "": ""); + String[] intInString = reader.readLine().split("" ""); + int N = Integer.parseInt(intInString[0]); + int S = Integer.parseInt(intInString[1]); + int p = Integer.parseInt(intInString[2]); + int[] ti = new int[N]; + for (int j = 0; j < ti.length; j++) { + ti[j] = Integer.parseInt(intInString[3 + j]); + } + + System.out.print(calculate(ti, S, p)); + System.out.println(); + } + } + + private static int calculate(int[] ti, int S, int p) { + int availS = S; + int result = 0; + for (int i = 0; i < ti.length; i++) { + if (maxScore(ti[i]) >= p) { + result++; + } else if ((availS > 0) && (maxSuprisingScore(ti[i]) >= p)) { + result++; + availS--; + } + } + return result; + } + + private static int maxScore(int ti) { + if (ti > 1) { + return (ti + 2) / 3; + } else { + return ti; + } + + } + + private static int maxSuprisingScore(int ti) { + if (ti > 2) { + return (ti + 4) / 3; + } else { + return ti; + } + } +} +" +A20697,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.*; + +public class main { + + static int numberPeriod(int n, int len) { + if (len == 2 && n / 10 == n % 10) return 1; + if (len == 4 && n % 100 == n / 100) return 2; + if (len == 6 && n % 100 == n / 10000 && n % 100 == n / 100 % 100) return 2; + if (len == 6 && n % 1000 == n / 1000) return 3; + return len; + } + + static int numberLength(int n) { + int len = 0; + while (n > 0) { + n /= 10; + len++; + } + return len; + } + + main() throws FileNotFoundException { + Scanner sc = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(""result.txt""); + int tests = sc.nextInt(); + for (int t = 1; t <= tests; t++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + Map> map = new TreeMap<>(); + ArrayList scores = new ArrayList<>(); + + for (int m = 0; m < n; m++) { + int g = sc.nextInt(); + scores.add(g); + map.put(g, dec(g)); + //out.println(dec(g).toString()); + } + + int ww = 0; + int w = 0; + int cw = 0; + for (int i = 0; i < n; i++) { + if (isDecomposeThere(map.get(scores.get(i)), p, true) && isDecomposeThere(map.get(scores.get(i)), p, false)) { + ww++; + } else if (isDecomposeThere(map.get(scores.get(i)), p, true)) { + w++; + } else if (isDecomposeThere(map.get(scores.get(i)), p, false)) { + cw++; + } + } + + if (w >= s) { + out.printf(""Case #%d: %d\n"", t, s + cw + ww); + } else { + //s -= w; + out.printf(""Case #%d: %d\n"", t, w + ww + cw); + } + } + out.flush(); + } + + public static void main(String[] args) throws FileNotFoundException { + main m = new main(); + } + + public boolean isDecomposeThere(ArrayList decomposes, int p, boolean surprise) { + for (Decompose dec : decomposes) { + if (dec.a >= p && dec.surprise == surprise) return true; + } + return false; + } + + public ArrayList dec(int n) { + ArrayList list = new ArrayList<>(); + for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= i; j++) { + for (int k = 0; k <= j; k++) { + if (i - j <= 2 && j - k <= 2 && i - k <= 2 && i + j + k == n) { + boolean surprise = (i - j == 2 || j - k == 2 || i - k == 2); + list.add(new Decompose(i, j, k, surprise)); + } + } + } + } + return list; + } + + class Decompose { + int a, b, c; + boolean surprise; + + public Decompose(int a, int b, int c, boolean surprise) { + this.a = a; + this.b = b; + this.c = c; + this.surprise = surprise; + } + + @Override + public String toString() { + return """" + a + "" "" + b + "" "" + c + "" "" + surprise; + } + } + +}" +A22653," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +class Dancing { + + public static void main(String args[]) throws IOException { + Scanner in = new Scanner(new File(""dance.txt"")); + PrintWriter fw = new PrintWriter(new FileWriter(new File(""dance.out""))); + int cases = in.nextInt(); + for (int c = 1; c <= cases; c++) { + int N = in.nextInt(); // number of googlers + int S = in.nextInt(); // number of surprising triplets + int p = in.nextInt(); // best result + ArrayList scores = new ArrayList(); + for (int n = 0; n < N; n++) { + int googler = in.nextInt(); + scores.add(googler); + } + Collections.sort(scores); + int pass = 0; + for (int i = 0; i < scores.size(); i++) { + int score = scores.get(i); + int mod = score % 3; + int max = score / 3; + int low = max; + if (mod > 0) { + max++; + } + if (max >= p) { + pass++; + continue; + } + if (S > 0) { + if (mod % 2 == 0) { + if(mod == 0 && low == 0){ + continue; + } + max++; + if (max >= p) { + pass++; + S--; + continue; + } + } + } + + }// for loop + String fwout = ""Case #"" + c + "": "" + pass; + fw.println(fwout); + } + fw.close(); + } +} +" +A20614,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +//Importing Java.io package classes to perform file management operations + +//DANCE OF GOOGLERS + +public class DanceOfGooglers +{ + DanceOfGooglers() + { + Combinations combinations[] = new Combinations[31]; + for(int i = 0 ; i < 31 ; i++) + { + combinations[i] = new Combinations(); + } + } + + static void doSort(int G[] , int N) + { + for(int i = 0 ; i < (N-1) ; i++) + { + int min = i; + + for(int j = (i + 1) ; j < N ; j++) + { + if(G[j] < G[min]) + { + min = j; + } + } + + if(min != i) + { + int temp = G[min]; + G[min] = G[i]; + G[i] = temp; + } + } + } + + public static void main(String[] args) + { + int limit = 30; + int maxInt = 10; + + //Since there are total 31 Numbers 0-30 (Inclusive) + Combinations combinations [] = new Combinations[31]; + + for(int l = 0 ; l < 31 ; l++) + { + combinations[l] = new Combinations(); + } + + for(int sum = 0 ; sum <= limit ; sum++) + { + for(int i = 0 ; i <= maxInt ; i++) + { + for(int j = 0 ; j <= maxInt ; j++) + { + for(int k = 0 ; k <= maxInt ; k++) + { + if((i + j + k) > sum) + { + break; + } + + if((i + j + k) == sum) + { + combinations[sum].populateSets(i, j, k); + break; + } + } + } + } + } + + try + { + // Open the input file + FileInputStream fistream = new FileInputStream(""B-large.in""); + + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fistream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + //Create output file + File file = new File(""output.out""); + boolean exist = file.createNewFile(); + + if (!exist) + { + System.out.println(""File already exists.""); + System.exit(0); + } + + FileWriter fostream = new FileWriter(""output.out""); + BufferedWriter out = new BufferedWriter(fostream); + + int counter = 0; //Counter purpose + + //Read File Line By Line + int totalNumberOfCases = 0; + while ((strLine = br.readLine()) != null) + { + if(counter == 0) + { + //Ignore the first Line for Conversion + totalNumberOfCases = Integer.parseInt(strLine); + counter++; + continue; + } + + String[] results = strLine.split("" ""); + + int N = Integer.parseInt(results[0]); + int S = Integer.parseInt(results[1]); + int P = Integer.parseInt(results[2]); + int G[] = new int[N]; + + //int suprisesRemaining = 0; + int maxBestResult = 0; + + for (int i = 0 ; i < N ; i++) + { + G[i] = Integer.parseInt(results[i+3]); + } + + doSort(G , N); + + //System.out.println(combinations[G[0]].bestResult[0] + "" "" + combinations[G[0]].bestResult[1]); + + for(int i = 0 ; i < N ; i++) + { + if(combinations[G[i]].bestResult[1] < P) //Non Surprising + { + if(combinations[G[i]].bestResult[0] < P || combinations[G[i]].bestResult[0] == 1000) //Surprising + { + //Ignore + continue; + } + else + { + if(S != 0) + { + maxBestResult++; + S--; + } + } + } + else + { + maxBestResult++; + } + } + + // Print the content in the output file + out.write(""Case #"" + counter + "": "" + maxBestResult); + + + //System.out.println(N + "" "" + S + "" "" + P + "" "" + G[0] + "" "" + G[1] + "" "" + G[2]); + /* + System.out.println(""Displaying Combinations""); + System.out.println(""=======================""); + + for(int i = 0 ; i < 31 ; i++) + { + combinations[i].displayCombinations(i); + } + */ + + if(counter < totalNumberOfCases) + { + out.write(""\n""); + } + counter++; + } + + //Close the input stream + in.close(); + + //Close the output Stream + out.close(); + + } + catch(Exception e) + { + //Catch exception if any + System.err.println(""Error: "" + e.getMessage() + "" : "" + e); + } + } +}" +A21416,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package problem.b.dancing.with.the.googlers; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + +/** + * + * @author Park + */ +public class ProblemBDancingWithTheGooglers { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + PrintStream out = new PrintStream(new File(""/Users/Park/Desktop/output.txt"")); + Scanner in = new Scanner(new File(""/Users/Park/Desktop/B-large.in"")); + int testCase = Integer.parseInt(in.next()); + for (int n = 0; n < testCase; n++) { + int count = 0; + int googlers = Integer.parseInt(in.next()); + int surprising = Integer.parseInt(in.next()); + int wantScores = Integer.parseInt(in.next()); + for (int g = 0; g < googlers; g++) { + int scores = Integer.parseInt(in.next()); + if (scores - (wantScores * 3) >= -2) { + count++; + } else if ((surprising > 0) && (((scores - (wantScores * 3) == -4)&&scores>=2) || ((scores - (wantScores * 3) == -3)&&scores>=3))) { + surprising--; + count++; + } + } + out.println(""Case #"" + (n + 1) + "": "" + count); + System.out.println(""Case #"" + (n + 1) + "": "" + count); + } + in.close(); + out.close(); + } +} +" +A21552,"/** + * + */ +package com.sakthi.demo; + +import java.io.File; +import java.util.Scanner; + +/** + * @author Balaji + * + */ +public class GooglersDance { + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + // TODO Auto-generated method stub + // System.out.println(""check""); + Scanner in = new Scanner(new File(""myinput.in"")); + int numCases = in.nextInt(); + for (int i = 0; i < numCases; i++) { + googlersWithMaxScore(in,i+1); + // findGooglersWithMaxScore(in,i+1); + } + } +private static void googlersWithMaxScore(Scanner in,int t) { + + int noGooglers =in.nextInt(); + int surprises =in.nextInt(); + int pts[]=new int[noGooglers]; + int maxScore=in.nextInt(); + for(int i=0;i= maxScore) { + noGooglerWithMaxScoreCrossed++; + } else if ((overflow != 0) && ((average+1) >= maxScore)) { + noGooglerWithMaxScoreCrossed++; + } else if (surprises != 0) { + if ((overflow == 2) && ((average+overflow) >= maxScore)) { + noGooglerWithMaxScoreCrossed++; + surprises--; + } else if ((overflow == 0) && (average > 0) && ((average+1) >= maxScore)) { + noGooglerWithMaxScoreCrossed++; + surprises--; + } + } + } + System.out.println(""Case #"" + t + "": "" + noGooglerWithMaxScoreCrossed); + + + + + + +} +private static void findGooglersWithMaxScore(Scanner in,int t) { + int noGooglers =in.nextInt(); + int surprises =in.nextInt(); + int pts[]=new int[noGooglers]; + int maxScore=in.nextInt(); + for(int i=0;i=20) { + noGooglerWithMaxScoreCrossed++; + continue; + } + score2 = (totalScore-score1)/2; + score3 = (totalScore-(score1+score2)); + if(((score1+score2+score3)>=totalScore) && Math.abs(score2-score1)<2) { + noGooglerWithMaxScoreCrossed++; + continue; + } + else if(Math.abs(score2-score3)<2) { + noGooglerWithMaxScoreCrossed++; + }*/ + + int a[]=new int[3]; + for(int i=maxScore;i<=10;i++) { + /*if(totalScore<=maxScore) { + score1=i; + score2=(totalScore-score1)/2; + score3=(totalScore-(score1+score2)); + a[0]=score1; + a[1]=score2; + a[2]=score3; + if((score1+score2+score3)>=totalScore) { + + } + noGooglerWithMaxScoreCrossed++; + break; + }*/ + score1 = i; + score2 =(totalScore-score1)/2; + score3 = (totalScore-(score1+score2)); + a[0]=score1; + a[1]=score2; + a[2]=score3; + //diffBtMinAndMax(); + if((score1+score2+score3)>=totalScore) { + if(diffBtMinAndMax(a)==2) { + if(noSurprisingCrossed>=surprises) + continue; + noSurprisingCrossed++; + noGooglerWithMaxScoreCrossed++; + break; + }else if(diffBtMinAndMax(a)<2) { + noGooglerWithMaxScoreCrossed++; + break; + } + + } + + } + + + } + //System.out.println(""Googler ""+noGooglerWithMaxScoreCrossed); + //System.out.println(""Check""); + System.out.println(""Case #"" + t + "": "" + noGooglerWithMaxScoreCrossed); + + +} +private static int diffBtMinAndMax(int a[]) { + for(int i=0;ia[j]) { + int temp =a[i]; + a[i]=a[j]; + a[j]=temp; + //a[i]=a[j]; + } + + } + } + + return Math.abs(a[0]-a[2]); +} +}" +A21042,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class B { + + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""B-large.out"")); + + + int T = new Integer(br.readLine()); + for(int cases =0;cases< T; cases ++) + { + String str = br.readLine(); + StringTokenizer st = new StringTokenizer(str); + int N = new Integer(st.nextToken()); + int S = new Integer(st.nextToken()); + int p =new Integer(st.nextToken()); + + int count =0; + + int[] scores = new int[N]; + for(int i =0;i=0) + { + count++; + } + else if(l==-1 || l==-2) + { + count++; + } + else if((l==-3 || l==-4) && S>0 && score >=3*p-4 && score>p) + { + count++; + S--; + } + + } + pw.println(""Case #"" +(cases+1) +"": "" +count); + } + + pw.close(); + br.close(); + + + } + +} +" +A20435," +public class DancingGooglers { + + private static int sc; + + private static int result = 0; + + private static int p; + + private static void check(int val) { + int x = val % 3; + int n = val / 3; + if (x == 0) { + if (n >= p) { + result++; + } else if (n > 0 && sc > 0 && n + 1 >= p) { + result++; + sc--; + } + } else { + if (n + 1 >= p) { + result++; + } else if (x == 2 && n + 2 >= p && sc > 0) { + result++; + sc--; + } + } + } + + public static void main(String[] args) throws Exception { + String[] in = ProblemUtils.readInput(""/home/laf/Downloads/B-large.in""); + String[] out = new String[in.length]; + for (int i = 0; i < in.length; i++) { + String[] vals = in[i].split("" ""); + int n = Integer.parseInt(vals[0]); + sc = Integer.parseInt(vals[1]); + p = Integer.parseInt(vals[2]); + result = 0; + for (int j = 3; j < 3 + n; j++) { + check(Integer.parseInt(vals[j])); + out[i] = """" + result; + } + } + ProblemUtils.writeOutput(""/home/laf/Desktop/out.txt"", out); + } + +} +" +A20719,"package codejam.b; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Main { + + public static void main(String[] args) { + ProblemB b = new ProblemB(); + List lines = CodejamFile.readLines(""c:\\tmp\\B-small-attempt0.in""); + for (int i = 0; i < lines.size(); i++) { + System.out.printf(""Case #%d: %d\n"", i + 1, b.process(lines.get(i))); + } + } +} + +class ProblemB { + + private int S; // the number of surprising triplets of scores + private int p; // threashold score + + // 3 1 5 15 13 11 -> 3 + // 3 0 8 23 22 21 -> 2 + public int process(String line) { + int possiblity = 0; + //System.out.println(line); + + String[] elements = line.split("" ""); + int N = Integer.parseInt(elements[0]); // the number of Googlers + S = Integer.parseInt(elements[1]); + p = Integer.parseInt(elements[2]); + + for (int i = 0; i < N; i++) { + int score = Integer.parseInt(elements[i + 3]); + //System.out.printf(""%d, %d\n"", score / 3, score % 3); + possiblity += getPossiblity(score) > 0 ? 1 : 0; + } + return possiblity; + } + + private int getPossiblity(int score) { + int r = 0; + int avg = score / 3; + + switch (score % 3) { + case 0: + if (avg > p) { + r = 3; + } else if (avg == p) { + //if (S > 0) { + r = 2; + //S--; + //} + } else if (avg == (p - 1)){ + if (avg == 0) { + break; + } + + if (S > 0) { + r = 1; + S--; + } + } + break; + case 1: + if (avg >= p) { + r = 3; + } else if (avg == (p -1)) { + //if (S > 0) { + //S--; + r = 2; + //} else { + //r = 1; + //} + } + break; + case 2: + if (avg >= p) { + r = 3; + } + if (avg == (p - 1)) { + r = 2; + } + if (avg == (p -2)) { + if (S > 0) { + S--; + r = 1; + } + } + break; + } + + return r; + } +} + +class CodejamFile { + + public static List readLines(String path) { + List lines = new ArrayList(); + + try { + FileReader in = new FileReader(path); + BufferedReader br = new BufferedReader(in); + String line; + // + br.readLine(); // line count + // + while ((line = br.readLine()) != null) { + lines.add(line); + } + br.close(); + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return lines; + } +} +" +A20311,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class CodeJam { + private static final String FILE_NAME = ""E:/download/B-large.in""; + + public static void main(String[] args) throws IOException { + File file = new File(FILE_NAME); + BufferedReader in = new BufferedReader(new FileReader(file)); + StringBuilder builder = new StringBuilder(); + SolverModule solver = new TestTwoSolver(); + builder = solver.process(in, builder); + System.out.println(builder); + file = new File(FILE_NAME.concat("".result"")); + FileWriter fileWriter = new FileWriter(file); + fileWriter.append(builder); + fileWriter.flush(); + fileWriter.close(); + } +} +" +A22970," + +import java.io.*; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author joshuahm + */ +public class codejamB { + public static void main(String[] args) throws FileNotFoundException, IOException { + FileReader inFile = new FileReader(""B-large.in""); + Scanner in = new Scanner(inFile); + FileWriter outFile = new FileWriter(""B-large.out""); + PrintWriter out = new PrintWriter(outFile); + int T= in.nextInt(); + for(int k=0;k3*p-3) + possible++; + else if(total[i]>Math.max(3*p-5,0)) + surprising++; + } + out.println(""Case #""+ (k+1) +"": "" + (possible + Math.min(surprising, S))); + } + in.close(); + out.close(); + } +} +" +A21985,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + + +public class DancingWiththeGooglers +{ +public static void main(String[] args) throws IOException { + FileWriter wr=new FileWriter(""Output.txt""); + BufferedWriter buff=new BufferedWriter(wr); + + FileReader read=new FileReader(""B-large.in""); + BufferedReader buffr=new BufferedReader(read); + + String str; + str=buffr.readLine(); + int n=Integer.parseInt(str); + int j=1; + Scanner sc; + int googleres,s,p; + int list[]; + int i; + int num; + int total=0; + while(j<=n) + { + int non[]={0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; + + int sup[]={-1,-1,-1,2,3,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,10,10,10,-1,-1,-1}; + + total=0; + str=buffr.readLine(); + sc=new Scanner(str); + sc.useDelimiter("" ""); + googleres=sc.nextInt(); + s=sc.nextInt(); + p=sc.nextInt(); + i=1; + list=new int[googleres]; + while(i<=googleres) + { + list[i-1]=sc.nextInt(); + i++; + } + + if(s==0) + { + for(int k=1;k<=googleres;k++) + { + num=list[k-1]; + if(non[num]>=p) + ++total; + } + + } + else + { + + for(int k=1;k<=googleres;k++) + { + if(s!=0) + { + num=list[k-1]; + if(non[num]>=p) + ++total; + else + { + if(sup[num]>=p) + { + --s; + ++total; + } + } + } + else + { + num=list[k-1]; + if(non[num]>=p) + ++total; + } + + } + + } + + StringBuffer temp = new StringBuffer(""Case #""+j+"": ""); + temp=temp.append(Integer.toString(total)); + buff.write(temp.toString()); + buff.newLine(); + j++; + } +buff.close(); +} +} +" +A20279,"package gcj; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + + /** + * @param args + */ + + private static int[] values = null; + private static int[] googlers= null; + private static int total =0; + + public static void main(String[] args) { + + BufferedReader fin = null; + int t = 0; + StringTokenizer str = null; + + try { + fin = new BufferedReader(new FileReader(new File(""B-large.in""))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + + + try { + t = Integer.parseInt(fin.readLine()); + //System.out.println(t); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + values = new int[3]; + + + for(int i=0;i=values[2]) + total++; + else if(remainder==0&&values[1]>0&&(value+1)>=values[2]){ + values[1]--; + total++; + } + else if(remainder>0&&(value+1)>=values[2]) + total++; + + else if(remainder==2&&(value+2)>=values[2]&&values[1]>0){ + total++; + values[1]--; + } + } + System.out.println(total); + } + +} +" +A20503,"import java.io.*; +import java.util.*; +public class Q2{ + static Map m1 = new HashMap(); + static Map m2 = new HashMap(); + static { + for (int i = 0;i<31;i++){ + m1.put(i, max1(i)); + m2.put(i, max2(i)); + } + } + private static int max1(int i){ + if (i % 3 == 0) { + return i/3; + } else if (i%3 == 1){ + return i/3 + 1; + } else { + return i/3 + 1; + } + } + private static int max2(int i){ + if (i == 0) return 0; + if (i % 3 == 0) { + return i/3 + 1; + } else if (i%3 == 1){ + return i/3 + 1; + } else { + return i/3 + 2; + } + } + public static void main(String args[]){ + try { + BufferedReader is = new BufferedReader( + new InputStreamReader(new FileInputStream(new File(""B-large.in"")))); + BufferedWriter os = new BufferedWriter( + new OutputStreamWriter(new FileOutputStream(new File(""q2output.txt"")))); + + int num = Integer.parseInt(in(is)); + + for (int i=0;i= min) { + result++; + } else { + max = m2.get(score); + if (max >= min) { + result++; + spr--; + } + } + } + return """" + (result + ((spr < 0)?spr:0)); + } +} + +" +A21358,"import java.util.Scanner; + +public class ProbB1 { + + public static void main(String arg[]){ + + Scanner in = new Scanner (System.in); + + int T= in.nextInt(); + + for(int i=1;i<=T;i++){ + int N = in.nextInt(); + int S=in.nextInt(); + int p=in.nextInt(); + + int count = 0; + int minN = p*3-4; + + for(int j=0;j=0){ + if(n>=minN+2) + count++; + else if((n>=minN)&&(S>0)){ + S--; + count++; + } + } + else{ + if((n>0)||((n==0)&&(p==0))) count ++ ; + } + + } + System.out.println(""Case #""+i+"": ""+count); + + } + } + } + + +" +A20357,"package gcj2012; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Scanner; + +public class DancingWithTheGooglersClean { + public static void main(String[] args) throws FileNotFoundException { + + Scanner in = new Scanner( + new File( + ""/Users/olvitole/Dropbox/workspace/Googe Code/src/gcj2012/files/B-large.in"")); + int t = Integer.parseInt(in.nextLine()); + OutputStream outStr = new FileOutputStream( + ""/Users/olvitole/Dropbox/workspace/Googe Code/src/gcj2012/files/Bl-output.txt""); + PrintStream printOut = new PrintStream(outStr); + for (int zz = 1; zz <= t; zz++) { + String input = in.nextLine().trim(); + String parts[] = input.split("" ""); + int n = Integer.parseInt(parts[0]); + int s = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + ArrayList triplets = new ArrayList(); + int tempTp = 0; + int tempScore = 0; + int count = 0; + for (int i = 0; i < n; i++) { + tempTp = Integer.parseInt(parts[3 + i]); + + if (tempTp % 3 == 0) { + tempScore = tempTp / 3; + Integer[] tempTrip = { tempScore, tempScore, tempScore }; + triplets.add(tempTrip); + } else if (tempTp % 3 == 1) { + tempScore = tempTp / 3; + Integer[] tempTrip = { tempScore, tempScore, + (tempScore + 1) }; + triplets.add(tempTrip); + } else if (tempTp % 3 == 2) { + tempScore = tempTp / 3; + Integer[] tempTrip = { tempScore, (tempScore + 1), + (tempScore + 1) }; + triplets.add(tempTrip); + } + + } + + for (Integer[] intPrint : triplets) { + if (intPrint[2] >= p) { + count++; + } else { + if ((intPrint[2] + 1 == p) && intPrint[1] > 0 + && (intPrint[2] == intPrint[1])) { + + if (s > 0) { + s--; + count++; + } + } + + } + } + + + String output = count + """"; + printOut.append(""Case #"" + zz + "": "" + output + ""\n""); + } + + System.setOut(printOut); + } + +} +" +A20578,"package Controller; + +import ProblemSolvers.DancingGooglers; +import ProblemSolvers.ProblemSolver; + +public class Main { + public static void main(String[] args) { + + ProblemSolver problem = new DancingGooglers(""dancingGooglers""); + problem.process(); + + } +} +" +A22986,"package com.irabin.google.codejam.problem2; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DanceWithGoogler { + + class Score { + + private Long score; + private Long firstJury; + private Long secondJury; + private Long thirdJury; + + public Score() { + } + + public Long getScore() { + return score; + } + + public void setScore(Long score) { + this.score = score; + } + + public Long getFirstJury() { + return firstJury; + } + + public void setFirstJury(Long firstJury) { + this.firstJury = firstJury; + } + + public Long getSecondJury() { + return secondJury; + } + + public void setSecondJury(Long secondJury) { + this.secondJury = secondJury; + } + + public Long getThirdJury() { + return thirdJury; + } + + public void setThirdJury(Long thirdJury) { + this.thirdJury = thirdJury; + } + + public boolean isSuprisedResult() { + boolean suprise = false; + if (Math.abs(firstJury - secondJury) >= 2 + || Math.abs(firstJury - thirdJury) >= 2 + || Math.abs(secondJury - thirdJury) >= 2) { + suprise = true; + } + return suprise; + } + + } + + private Scanner scanner; + private PrintWriter writer; + + public DanceWithGoogler(InputStream in, OutputStream os) { + scanner = new Scanner(in); + writer = new PrintWriter(os); + } + + public void solve() { + + int n = Integer.parseInt(scanner.nextLine()); + + for (int i = 1; i <= n; i++) { + writer.print(""Case #"" + i + "": ""); + + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + String output = """"; + int totalBetterThanP = 0; + int foundSuprise = 0; + + Score[] scores = new Score[N]; + for (int j = 0; j < N; j++) { + scores[j] = new Score(); + scores[j].setScore(scanner.nextLong()); + } + + // sort ascending + for (int j = 0; j < N; j++) { + for (int k = j + 1; k < N; k++) { + if (scores[k].getScore() > scores[j].getScore()) { + Score tempScore = scores[k]; + scores[k] = scores[j]; + scores[j] = tempScore; + } + } + } + + for (int j = 1; j <= N; j++) { + + Long equalScore = scores[j - 1].getScore() / 3; + + Long firstJury = equalScore; + Long secondJury = equalScore; + Long thirdJury = equalScore; + + Long dividen = scores[j - 1].getScore() % 3; + while (dividen > 0) { + firstJury = firstJury + 1; + dividen = dividen - 1; + if (dividen > 0) { + secondJury = secondJury + 1; + dividen = dividen - 1; + } + if (dividen > 0) { + thirdJury = thirdJury + 1; + dividen = dividen - 1; + } + } + + scores[j - 1].setFirstJury(firstJury); + scores[j - 1].setSecondJury(secondJury); + scores[j - 1].setThirdJury(thirdJury); + } + + for (int j = 1; j <= N; j++) { + + if (scores[j - 1].isSuprisedResult()) { + foundSuprise = foundSuprise + 1; + } else { + if (foundSuprise < S && ((scores[j-1].getFirstJury()

= p || scores[j-1].getSecondJury() >= p || scores[j-1].getThirdJury() >= p) { + totalBetterThanP = totalBetterThanP + 1; + } + + } + output = String.valueOf(totalBetterThanP); + + writer.println(output); + writer.flush(); + } + writer.close(); + + } + + public static void main(String args[]) { + + InputStream input = null; + input = DanceWithGoogler.class.getResourceAsStream(args[0]); + + OutputStream output = null; + try { + output = new FileOutputStream(args[1]); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + DanceWithGoogler practise1 = new DanceWithGoogler(input, output); + practise1.solve(); + } +} +" +A21644,"package round02; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Scanner; + +/** + * Problem B. Dancing With the Googlers + * + * Problem + +You're watching a show where Googlers (employees of Google) dance, and then each dancer is given a triplet of scores by three judges. Each triplet of scores consists of three integer scores from 0 to 10 inclusive. The judges have very similar standards, so it's surprising if a triplet of scores contains two scores that are 2 apart. No triplet of scores contains scores that are more than 2 apart. + +For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. + +The total points for a Googler is the sum of the three scores in that Googler's triplet of scores. The best result for a Googler is the maximum of the three scores in that Googler's triplet of scores. Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? + +For example, suppose there were 6 Googlers, and they had the following total points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising triplets of scores, and you want to know how many Googlers could have gotten a best result of 8 or better. + +With those total points, and knowing that two of the triplets were surprising, the triplets of scores could have been: + + 10 9 10 + 6 6 8 (*) + 2 3 3 + 6 6 6 + 6 6 6 + 6 7 8 (*) + +The cases marked with a (*) are the surprising cases. This gives us 3 Googlers who got at least one score of 8 or better. There's no series of triplets of scores that would give us a higher number than 3, so the answer is 3. + +Input + +The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing integers separated by single spaces. The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. +Output + +For each test case, output one line containing ""Case #x: y"", where x is the case number (starting from 1) and y is the maximum number of Googlers who could have had a best result of greater than or equal to p. +Limits + +1 ¡Â T ¡Â 100. +0 ¡Â S ¡Â N. +0 ¡Â p ¡Â 10. +0 ¡Â ti ¡Â 30. +At least S of the ti values will be between 2 and 28, inclusive. +Small dataset + +1 ¡Â N ¡Â 3. +Large dataset + +1 ¡Â N ¡Â 100. + +ample + +Input + +Output + +4 +3 1 5 15 13 11 +3 0 8 23 22 21 +2 1 1 8 0 +6 2 8 29 20 8 18 18 21 + +Case #1: 3 +Case #2: 2 +Case #3: 1 +Case #4: 3 + + * @author chmin + * + */ +public class DancingWithGooglers { + + static class ScoreHolder { + int s1, s2, s3; + int remainder ; + boolean passed = false; + ScoreHolder (int total){ + s1 = s2 = s3 = total /3 ; + remainder = total % 3; + } + private String asString(int v1, int v2, int v3){ + return """" + v1 + "" "" + v2 + "" "" + v3; + } + public String [] toScores(int p, boolean allowSuprising ) { + ArrayList list = new ArrayList<>(); + int v1 = s1; + int v2 = s2; + int v3 = s3; + + if ( remainder == 0){ + if ( v1 >= p ) + list.add(asString(v1, v2, v3)); + + if ( v1 + 1 >= p && v3 > 0 && allowSuprising ) + list.add(asString(v1+1, v2, v3-1)); + } + if ( remainder == 1 ){ + if ( (v1+1) >= p ) list.add ( asString(v1+1, v2, v3)); + } else if ( remainder == 2 ){ + if ( v3+1 >= p ) { + list.add(asString(v1, v2+1, v3+1)); + } + if ( v3+2 >= p && allowSuprising ) + list.add( asString(v1, v2, v3+2)); + } + + String [] result = new String [list.size()]; + list.toArray(result); + return result; + } + } + + static List readFile ( InputStream in) throws IOException{ + ArrayList list = new ArrayList<>(); + StringBuilder sb = new StringBuilder(); + Scanner scanner = new Scanner(in); + int T = scanner.nextInt(); + + for ( int i = 0 ;i < T ; i++){ + int N = scanner.nextInt(); // the number of googlers + int S = scanner.nextInt(); // the number of surprising triplets of scores + int P = scanner.nextInt(); // min score +// System.out.print (""N("" + N + +// ""), S("" + S + +// ""), p("" + P + +// "") ""); + ScoreHolder [] sh = new ScoreHolder[N]; + for( int k = 0 ; k < N ; k++){ + sh[k] = new ScoreHolder(scanner.nextInt()); + } + + int cnt = 0; + + for ( int k = 0 ; k < sh.length ; k++){ + if ( sh[k].toScores(P, false).length > 0 ){ + cnt ++ ; + sh[k].passed = true; + } + } + + if ( S > 0 ){ + int cntS = S; + String [] vals = null; + for( int k = 0 ; k < sh.length ; k ++ ){ + if ( sh[k].passed ) continue; + vals = sh[k].toScores(P, true); + if ( vals.length > 0 ){ + cnt ++ ; + cntS -- ; + } + if ( cntS == 0)break; + } + } +// System.out.println(""CASE #"" + (i+1) + "": "" + cnt ); + sb.append(""Case #"" + (i+1) + "": "" + cnt + System.getProperty(""line.separator"")); + list.add(sh); + } + + BufferedWriter bw = new BufferedWriter(new FileWriter(""R2-large.out"")); + bw.write(sb.toString()); + bw.close(); + return list; + } + private static void dump(String[] vals) { + for (int j = 0; j < vals.length; j++) { + System.out.print("" => "" + vals[j]); + } + } + /** + * @param args + */ + public static void main(String[] args) { + try { + List lines = readFile( + DancingWithGooglers.class.getResourceAsStream(""R2-large.in"") ); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} +" +A22236,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + private int n, p, a[], memo[][]; + + private void work() throws IOException { + Scanner sc = new Scanner(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""B-large.out"")); + a = new int[200]; + memo = new int[200][200]; + int nc = sc.nextInt(); + for (int tc = 1; tc <= nc; tc++) { + pw.printf(""Case #%d: "", tc); + n = sc.nextInt(); + int s = sc.nextInt(); + p = sc.nextInt(); + for (int i = 0; i < n; i++) { + a[i] = sc.nextInt(); + Arrays.fill(memo[i], Integer.MIN_VALUE); + } + int res = go(0, s); + if (res < 0) + res = 0; + pw.printf(""%d\n"", res); + } + pw.close(); + } + + private int go(int pos, int s) { + if (pos == n) + return s == 0 ? 0 : -200; + if (memo[pos][s] > Integer.MIN_VALUE) + return memo[pos][s]; + int k = a[pos] / 3; + int m = a[pos] % 3; + int max = k; + if (m > 0) + max++; + int maxs = k + 1; + if (m == 2) + maxs++; + int ret = (max >= p ? 1 : 0) + go(pos + 1, s); + if (s > 0 && (k > 0 || m == 2)) { + int t = (maxs >= p ? 1 : 0) + go(pos + 1, s - 1); + if (t > ret) + ret = t; + } + return memo[pos][s] = ret; + } + + public static void main(String[] args) throws IOException { + new B().work(); + } + +} +" +A22528,"import java.io.*; +import java.security.SecureRandom; +import java.util.*; +import java.math.*; +import java.awt.geom.*; + +import static java.lang.Math.*; + +public class Main implements Runnable { + + static String filename = ""B-large""; + + public void solve() throws Exception { + int t = sc.nextInt(); + for (int Case = 1; Case <= t; Case++) { + int n = sc.nextInt(), s = sc.nextInt(), p = sc.nextInt(); + ArrayList[] points = new ArrayList[3]; + for (int i = 0; i < 3; i++) { + points[i] = new ArrayList(); + } + for (int i = 0; i < n; i++) { + int num = sc.nextInt(); + points[num % 3].add(num); + } + for (int i = 0; i < 3; i++) { + Collections.sort(points[i]); + } + int ans = 0; + for (int i = points[0].size() - 1; i >= 0; i--) { + if (points[0].get(i) / 3 >= p) { + ans++; + points[0].remove(i); + } + } + for (int i = points[1].size() - 1; i >= 0; i--) { + if (points[1].get(i) / 3 + 1 >= p) { + ans++; + points[1].remove(i); + } + } + for (int i = points[2].size() - 1; i >= 0; i--) { + if (points[2].get(i) / 3 + 1 >= p) { + ans++; + points[2].remove(i); + } + } + for (int i = points[0].size() - 1; i >= 0 && s > 0; i--) { + if (points[0].get(i) >= 3 && points[0].get(i) / 3 + 1 >= p) { + ans++; + s--; + points[0].remove(i); + } + } + for (int i = points[2].size() - 1; i >= 0 && s > 0; i--) { + if (points[2].get(i) / 3 + 2 >= p) { + ans++; + s--; + points[2].remove(i); + } + } + out.printf(""Case #%d: %d\n"", Case, ans); + } + } + + BufferedReader in; + PrintWriter out; + FastScanner sc; + + + public static void main(String[] args) { + new Thread(null, new Main(), """", 1 << 25).start(); + } + + @Override + public void run() { + try { + init(); + solve(); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + out.close(); + } + } + + void init() throws Exception { + in = new BufferedReader(new FileReader(filename + "".in"")); + out = new PrintWriter(new FileWriter(filename + "".out"")); + sc = new FastScanner(in); + } +} + +class FastScanner { + + BufferedReader reader; + StringTokenizer strTok; + + public FastScanner(BufferedReader reader) { + this.reader = reader; + } + + public String nextToken() throws IOException { + while (strTok == null || !strTok.hasMoreTokens()) { + strTok = new StringTokenizer(reader.readLine()); + } + + return strTok.nextToken(); + } + + public int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + public long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + public double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + public BigInteger nextBigInteger() throws IOException { + return new BigInteger(nextToken()); + } + +} +" +A20738,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class Dancing { + private static Map knowledgeBase = new HashMap(); + + static + { + knowledgeBase.put(""our language is impossible to understand"", ""ejp mysljylc kd kxveddknmc re jsicpdrysi""); + knowledgeBase.put(""there are twenty six factorial possibilities"", ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd""); + knowledgeBase.put(""so it is okay if you want to just give up"", ""de kr kd eoya kw aej tysr re ujdr lkgc jv""); + knowledgeBase.put(""aozq"", ""yeqz""); + } + + + private BufferedReader reader; + private BufferedWriter writer; + + /** + * @param args + */ + public static void main(String[] args) + { + Dancing dancing = new Dancing(args[0]); + dancing.executeTests(); + } + + + public Dancing(String filename) + { + // Open file + File file = new File(filename); + try + { + reader = new BufferedReader(new FileReader(file)); + writer = new BufferedWriter(new FileWriter(file+"".out"")); + } + catch (IOException e) + { + // Failed to open new buffered reader + System.err.println(""Failed to open FileReader""); + e.printStackTrace(); + System.exit(-1); + } + } + + private void executeTests() + { + // Read number of test cases + int numberOfTests = 0; + + try + { + // Read number of tests (first line) + numberOfTests = Integer.parseInt(reader.readLine()); + } + catch (NumberFormatException | IOException e) + { + // Failed to read a line + System.err.println(""Failed to read a line""); + e.printStackTrace(); + System.exit(-1); + } + + for (int testCase = 1; testCase <= numberOfTests; testCase++) + { + String[] input; + + try + { + input = reader.readLine().split(""\\s""); + + int contestants = Integer.parseInt(input[0]); + int surprises = Integer.parseInt(input[1]); + int threshhold = Integer.parseInt(input[2]); + + List scores = new ArrayList(); + + for (int i = 3; i < 3 + contestants; i++) + { + scores.add(Integer.parseInt(input[i])); + } + + int answer = findWinners(surprises, threshhold, scores); + + writer.write(""Case #"" + testCase + "": "" + answer + '\n'); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + try + { + reader.close(); + writer.flush(); + writer.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + + private static int findWinners(int surprises, int threshhold, List scores) + { + int totalPossible = 0; + int surprisesRemaining = surprises; + + for (Integer score : scores) + { + Map maxScores = getMaxScores(score); + + if (maxScores.get(""normal"") >= threshhold) + { + totalPossible++; + } + else if (maxScores.get(""surprise"") >= threshhold && surprisesRemaining > 0) + { + totalPossible++; + surprisesRemaining--; + } + } + + return totalPossible; + } + + private static Map getMaxScores(int totalScore) + { + int maxNormalScore = ((totalScore - 1) / 3) + 1; + int maxSurpriseScore = maxNormalScore; + + if (totalScore % 3 != 1) + { + maxSurpriseScore++; + } + + Map maxScores = new HashMap(); + maxScores.put(""normal"", maxNormalScore); + maxScores.put(""surprise"", maxSurpriseScore); + + // Special case to continue using integer division + if (totalScore == 0) + { + maxScores.put(""normal"", 0); + maxScores.put(""surprise"", 0); + } + + return maxScores; + } +} +" +A21788,"import java.io.IOException; +import java.util.InputMismatchException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.FileInputStream; +import java.io.Writer; +import java.math.BigInteger; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + * @author Egor Kulikov (egor@egork.net) + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream; + try { + inputStream = new FileInputStream(""taskb.in""); + } catch (IOException e) { + throw new RuntimeException(e); + } + OutputStream outputStream; + try { + outputStream = new FileOutputStream(""taskb.out""); + } catch (IOException e) { + throw new RuntimeException(e); + } + InputReader in = new InputReader(inputStream); + OutputWriter out = new OutputWriter(outputStream); + TaskB solver = new TaskB(); + int testCount = Integer.parseInt(in.next()); + for (int i = 1; i <= testCount; i++) + solver.solve(i, in, out); + out.close(); + } +} + +class TaskB { + public void solve(int testNumber, InputReader in, OutputWriter out) { + int count = in.readInt(); + int surprising = in.readInt(); + int required = in.readInt(); + int[] scores = IOUtils.readIntArray(in, count); + int answer = 0; + for (int i : scores) { + if (i < required) + continue; + if (i >= 3 * required - 2) + answer++; + else if (i >= 3 * required - 4 && surprising > 0) { + answer++; + surprising--; + } + } + out.printLine(""Case #"" + testNumber + "":"", answer); + } +} + +class InputReader { + + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + public int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + public static boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + public String next() { + return readString(); + } +} + +class OutputWriter { + private final PrintWriter writer; + + public OutputWriter(OutputStream outputStream) { + writer = new PrintWriter(outputStream); + } + + public OutputWriter(Writer writer) { + this.writer = new PrintWriter(writer); + } + + public void print(Object...objects) { + for (int i = 0; i < objects.length; i++) { + if (i != 0) + writer.print(' '); + writer.print(objects[i]); + } + } + + public void printLine(Object...objects) { + print(objects); + writer.println(); + } + + public void close() { + writer.close(); + } + + } + +class IOUtils { + + public static int[] readIntArray(InputReader in, int size) { + int[] array = new int[size]; + for (int i = 0; i < size; i++) + array[i] = in.readInt(); + return array; + } + + } + +" +A21292,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class DancingWithGooglers { + public String findMaxGooglers(String line) { + String[] tokens = line.split("" ""); + int numGooglers = Integer.parseInt(tokens[0]); + int numSurprising = Integer.parseInt(tokens[1]); + int threshold = Integer.parseInt(tokens[2]); + + int[] pointsArray = new int[numGooglers]; + for (int i = 0; i < numGooglers; ++i) { + pointsArray[i] = Integer.parseInt(tokens[3 + i]); + } + + int maxGooglers = 0; + int numSurprisingBetter = 0; + int numSurprisingEqual = 0; + for (int points : pointsArray) { + int avg = points / 3; + int rem = points - 3 * avg; + if (points >= 2 && points <= 28) { + if (avg >= threshold) { + maxGooglers++; + numSurprisingEqual++; + } else if (avg == threshold - 1) { + if (rem == 0) { + numSurprisingBetter++; + } else { // rem == 1 || rem == 2 + maxGooglers++; + numSurprisingEqual++; + } + } else if (avg == threshold - 2) { + if (rem == 2) { + numSurprisingBetter++; + } else { + numSurprisingEqual++; + } + } else { + numSurprisingEqual++; + } + } else { // points = 0, 1, 29 or 30 + numSurprisingEqual++; + if (avg >= threshold) { + maxGooglers++; + } else if (avg == threshold - 1 && rem > 0) { + maxGooglers++; + } + } + } +// System.out.printf(""%d, %d\n"", numSurprisingBetter, numSurprisingEqual); +// System.out.printf(""%d\n"", numSurprisingBetter + numSurprisingEqual); +// System.out.printf(""Num points: %d\n"", pointsArray.length); +// assert numSurprisingBetter + numSurprisingEqual == pointsArray.length; + + if (numSurprising > 0) { + int n = Math.min(numSurprisingBetter, numSurprising); + numSurprising -= n; + maxGooglers += n; + } + + if (numSurprising > 0) { + int n = Math.min(numSurprisingEqual, numSurprising); + numSurprising -= n; + } + +// assert numSurprising == 0; + + return String.valueOf(maxGooglers); + } + + public static void main(String[] args) { + String inputFileName = null; + if (args.length > 0) { + inputFileName = args[0]; + } else { + return; + } + + File inputFile = new File(inputFileName); + List outputStringList = new ArrayList(); + try { + DancingWithGooglers dwg = new DancingWithGooglers(); + BufferedReader reader = new BufferedReader( + new FileReader(inputFile)); + int numLines = Integer.parseInt(reader.readLine()); + for (int i = 0; i < numLines; ++i) { + outputStringList.add(dwg.findMaxGooglers(reader.readLine())); + } + reader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + File outputFile = new File(""dwg.out""); + FileWriter writer; + try { + writer = new FileWriter(outputFile); + for (int i = 0; i < outputStringList.size(); ++i) { + String s = String.format(""Case #%d: %s\n"", i + 1, + outputStringList.get(i)); + System.out.print(s); + writer.write(s); + } + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A21848,"package dancingWithGooglers; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; + +public class OutputFile +{ + public void writeFile(ArrayList data) throws Exception + { + File file = new File(""C:\\Users\\Nikhil\\Desktop\\googleCodeJam\\output.txt""); + + BufferedWriter bufferedReader = new BufferedWriter(new FileWriter(file)); + + for(int i=0;i=p) + { out++;} + else + { + + if((div+1)>=p&&s>0&&(div+1)<=10) + { + out++; s--; + + } + + } + } + + + else if(rem==2) + { + if((div+1)>=p) + { out++;} + else + { + + if((div+2)>=p&&s>0&&(div+2)<=10) + { + out++; s--; + } + + } + } + else + { + if((div+rem)>=p) + out++; + } + + + } + System.out.println(out); + + } + + + + + + } + catch(Exception ex) + { + System.out.println(ex); + } + } + + } + + +" +A21738,"package com.bertramtruong.utils; + +/** + * This file contains all common + * @author Bertram + */ +public class BT { + /// SETTINGS + + private static boolean debugMode = true; + /// + + /// + // LOGGING FUNCTIONS + /// + /** + * Toggles between debug mode. + * @param debugMode + */ + public static void toggleDebug(boolean debug) { + debugMode = debug; + } + + /** + * Print out an debug message. + * @param + * @param x + */ + public static void db(T... x) { + if (debugMode) { + System.out.print(""DEBUG: ""); + for (T b : x) { + System.out.print(String.valueOf(b)); + } + System.out.println(); + } + } + + /** + * Print out an info message. + * @param + * @param x + */ + public static void info(T... x) { + System.out.print(""INFO: ""); + for (T b : x) { + System.out.print(String.valueOf(b)); + } + System.out.println(); + } + + /** + * Print out an error message. + * @param + * @param x + */ + public static void err(T... x) { + System.out.print(""ERROR: ""); + for (T b : x) { + System.out.print(String.valueOf(b)); + } + System.out.println(); + } + /// + // END LOGGING FUNCTIONS + /// +} +" +A21873,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.Scanner; + +public class Q2 { + + public static void readFile() { + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(""Q2-Small""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + // Read File Line By Line + while ((strLine = br.readLine()) != null) { + // Print the content on the console + System.out.println(strLine); + } + // Close the input stream + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + static int surpriseCount = 0; + static int S = 0; + + static boolean isGreater(int totalNumbers, int p) { + int single = totalNumbers/3; + if(single>=p) { + return true; + } + int remainder = totalNumbers%3; + if(remainder==1) { + single++; + if(single>=p) { + return true; + } + return false; + } + if(remainder==2) { + single++; + if(single>=p) { + return true; + } + if(surpriseCount0) { + single++; + if(single>=p) { + surpriseCount++; + return true; + } + } + return false; + } + if(remainder==0) { + if(surpriseCount0) { + single++; + if(single>=p) { + surpriseCount++; + return true; + } + } + return false; + } + return false; + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + // System.out.println(""Hello""); + try{ + + File file = new File(""Q2_Large_Answer.out""); + PrintStream output = new PrintStream(file); + + + Scanner scanner = new Scanner(new File(""Q2-Large"")); + int numberOfCases = scanner.nextInt(); + // System.out.println(numberOfCases); + int greaterCount = 0; + for (int c = 0;c=P*3-2&&score[i]>=P){ans1++;} + else if(score[i]>=P*3-4&&score[i]>=P){ans2++;} + } + if(ans2<=S){fin=ans2+ans1;} + else{fin=S+ans1;} + System.out.print(fin); + } + +} +" +A21972,"package com.renoux.gael.codejam.utils; + + +public class TechnicalException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public TechnicalException() { + super(); + } + + public TechnicalException(String message, Throwable cause) { + super(message, cause); + } + + public TechnicalException(String message) { + super(message); + } + + public TechnicalException(Throwable cause) { + super(cause); + } + +} +" +A21542,"import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class Dancing_With_Googlers { + public static void main(String[] args) { + try { + // Initialize + InputStreamReader converter = new InputStreamReader(System.in); + BufferedReader in = new BufferedReader(converter); + String curLine = in.readLine(); + String[] googlers; + + // Find number of cases + int N = Integer.parseInt(curLine); + + // Read line by line + for (int line = 0; line < N; line++) { + curLine = in.readLine(); + googlers = curLine.split("" ""); + int numGooglers = Integer.parseInt(googlers[0]); + int numSurprising = Integer.parseInt(googlers[1]); + int p = Integer.parseInt(googlers[2]); + int curSurprising = 0; + int maxGooglers = 0; + + for (int googler = 3; googler < googlers.length; googler++) { + if (Integer.parseInt(googlers[googler]) >= 3*p-4 + && Integer.parseInt(googlers[googler]) <= 3*p-3 + && Integer.parseInt(googlers[googler]) > 0) { + curSurprising++; + } + else if (Integer.parseInt(googlers[googler]) >= 3*p-2) { + maxGooglers++; + } + } + maxGooglers += Math.min(curSurprising, numSurprising); + + System.out.println(""Case #"" + (line+1) + "": "" + maxGooglers); + } + } catch(Exception e) { + System.out.println(""Error: "" + e.getMessage()); + } + } +} +" +A22526,"package net.mauhiz.contest.codejam.qual2012; + +import java.io.IOException; + +import net.mauhiz.contest.codejam.CodejamLineChunkSolver; + +public class DancingGoogler extends CodejamLineChunkSolver { + + public static void main(String... args) throws IOException { + new DancingGoogler().run(args); + } + + @Override + protected String doJamProblem(String[] chunks) { + int n = Integer.parseInt(chunks[0]); + int s = Integer.parseInt(chunks[1]); + int p = Integer.parseInt(chunks[2]); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = Integer.parseInt(chunks[3 + i]); + } + int y = solve(s, p, t); + return Integer.toString(y); + } + + protected int solve(int s, int p, int[] t) { + log.fine(""s "" + s); + log.fine(""p "" + p); + int r = s; // remaining surprises + int y0 = 0, y1 = 0, y2 = 0; + int t0 = 0, t1 = 0, t2 = 0; + for (int i = 0; i < t.length; i++) { + int mod = t[i] % 3; + + switch (mod) { + case 0: + t0++; + int m0 = t[i] / 3; + if (m0 >= p) { + y0++; + } else if (r > 0 && m0 + 1 == p && t[i] >= 3) { + // consume a surprise + r--; + y0++; + } + break; + case 1: + t1++; + int m1 = (t[i] + 2) / 3; + if (m1 >= p) { + y1++; + } + break; + case 2: + t2++; + int m2 = (t[i] + 1) / 3; + if (m2 >= p) { + y2++; + } else if (r > 0 && m2 + 1 == p) { + // consume a surprise + r--; + y2++; + } + break; + } + } + log.fine(""r "" + r); + log.fine(""t0 "" + t0); + log.fine(""t1 "" + t1); + log.fine(""t2 "" + t2); + log.fine(""y0 "" + y0); + log.fine(""y1 "" + y1); + log.fine(""y2 "" + y2); + + return y0 + y1 + y2; + } + + @Override + public String getName() { + return ""DancingGoogler""; + } +} +" +A20149,"package com.d.qual; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + +public class q2 { + + public static final String FILE_NAME = ""B-large.in""; +// public static final String FILE_NAME = ""input.txt""; + public static final String FILE_OUT_NAME = ""output.txt""; + + /** + * @param args + */ + public static void main(String[] args) { + FileReader reader; + FileWriter writer; + try { + reader = new FileReader(FILE_NAME); + writer = new FileWriter(FILE_OUT_NAME); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; + } catch(IOException e){ + e.printStackTrace(); + return; + } + + BufferedReader r = new BufferedReader(reader); + BufferedWriter w = new BufferedWriter(writer); + + String entriesString; + int entries; + try { + entriesString = r.readLine(); + entries = Integer.parseInt(entriesString); + } catch (IOException e) { + e.printStackTrace(); + return; + } + + for(int i=0; i maybeHigh){ + winners++; + System.out.println(""OK ""+winners); + } + else if((curInt >= maybeLow) && (curInt <= maybeHigh)){ + if(score == 1){ + if(curInt < score * 3 - 2){ + continue; + } + } + curSpecials++; + System.out.println(""MAYBE ""+curSpecials); + if(curSpecials <= specials){ + winners++; + System.out.println(""MAYBE YES! ""+winners); + } + } + out = ""-cint ""+curInt+"" yes ""+(score * 3)+"" maybe ""+maybeLow+"" ""+maybeHigh+"" s ""+curSpecials+"" w ""+winners+"" ""; + System.out.println(out); + +// if(curInt < score * 3 - 4){ +// continue; +// } +// +// int[] result = new int[3]; +// result[0] = score; +// result[1] = 0; +// result[2] = 0; +// int leftOver = curInt - result[0]; +// if(leftOver > 20){ +// result[0] += leftOver - 20; +// leftOver = 20; +// } +// float leftOverHalf = (float)leftOver / 2; +// result[1] = leftOver - (int)Math.floor(leftOverHalf); +// result[2] = leftOver - result[1]; +// +// int maxDiff = maxDiff(result); +// if(maxDiff < 2){ +// winners++; +// } +// else if(maxDiff == 2){ +// //special +// curSpecials++; +// if(curSpecials <= specials){ +// winners++; +// } +// } +// else if(maxDiff > 2){ +// +// } +// +// out = curInt+"" ""+result[0]+"" ""+result[1]+"" ""+result[2]+"" maxDiff[""+maxDiff+""] ""; +// System.out.print(out); + } + System.out.println("" - winners ""+winners); + w.write(""""+winners); + w.newLine(); + w.flush(); + + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + try{ + r.close(); + } catch(IOException e){ + e.printStackTrace(); + return; + } finally{ + try{ + w.close(); + } catch(IOException e){ + e.printStackTrace(); + return; + } + } + + + } + + public static boolean isSpecial(int[] data){ + int maxDiff = 0; + for(int i=0; i maxDiff){ + maxDiff = Math.abs(cdiff); + } + } + return maxDiff; + } + +} +" +A20607,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; +import java.util.TreeSet; + +public class GoogleDancers { + private static final List cases = new ArrayList(); + + public static void main(String[] args) throws IOException { + // sanityCheck(); + readInFile(""src/resources/dancers/B-large.in""); + FileWriter fstream = new FileWriter(""src/resources/dancers/B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + + for (int i = 0; i < cases.size(); i++) { + String msg = ""Case #"" + (i + 1) + "": "" + cases.get(i).getResult() + ""\n""; + out.write(msg); + System.out.print(msg); + } + out.close(); + } + + protected static void readInFile(String path) throws NumberFormatException, IOException { + DataInputStream in = new DataInputStream(new FileInputStream(path)); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + int lines = Integer.parseInt(br.readLine()); + for (int i = 0; i < lines; i++) { + cases.add(new Case(br.readLine())); + } + in.close(); + } +} + +class Case { + protected int N; + protected int S; + protected int p; + protected TreeSet dancers = new TreeSet(); + + public Case(String line) { + StringTokenizer tokenizer = new StringTokenizer(line); + N = Integer.parseInt(tokenizer.nextToken()); + S = Integer.parseInt(tokenizer.nextToken()); + p = Integer.parseInt(tokenizer.nextToken()); + for (int i = 0; i < N; i++) { + dancers.add(new Dancer(Integer.parseInt(tokenizer.nextToken()))); + } + } + + public int getResult() { + System.out.println(this); + int ctr = 0; + for (Dancer d : dancers) { + if (d.expected.max() >= p) { + ctr += 1; + } else if ((d.surprising != null) && (d.surprising.max() >= p) && (d.surprising.max() >= d.expected.max()) && (S > 0)) { + ctr += 1; + S -= 1; + } + System.out.println(d); + } + return ctr; + } + + @Override + public String toString() { + return ""N="" + N + "", S="" + S + "", p="" + p; + } +} + +class Dancer implements Comparable { + Triplet expected; + Triplet surprising; + + protected Dancer(int score) { + expected = Triplet.expected(score); + surprising = Triplet.surprising(score); + } + + protected int max() { + if (surprising == null) { + return expected.max(); + } else { + return Math.max(expected.max(), surprising.max()); + } + } + + @Override + public int compareTo(Dancer arg0) { + if (max() < arg0.max()) { + return 1; + } else { + return -1; + } + } + + @Override + public String toString() { + return expected.toString() + "", "" + surprising; + } +} + +/** + * ""Note: this class has a natural ordering that is inconsistent with equals."" + */ +class Triplet implements Comparable { + protected boolean isSurprising = false; + protected int t1, t2, t3; + + protected Triplet(int t1, int t2, int t3) { + this.t1 = t1; + this.t2 = t2; + this.t3 = t3; + isSurprising = (Math.abs(t1 - t2) >= 2) || (Math.abs(t2 - t3) >= 2) || (Math.abs(t1 - t3) >= 2); + } + + protected static Triplet expected(int score) { + if (score == 0) { + return new Triplet(0, 0, 0); + } else if (score % 3 == 0) { + return new Triplet(score / 3, score / 3, score / 3); + } else if (score % 3 == 1) { + return new Triplet(score / 3, score / 3, score / 3 + 1); + } else { + return new Triplet(score / 3, score / 3 + 1, score / 3 + 1); + } + } + + protected static Triplet surprising(int score) { + if (score < 2) { + return null; + } else if (score % 3 == 0) { + return new Triplet(score / 3 - 1, score / 3, score / 3 + 1); + } else if (score % 3 == 1) { + return new Triplet(score / 3 - 1, score / 3 + 1, score / 3 + 1); + } else { + return new Triplet(score / 3, score / 3, score / 3 + 2); + } + } + + public int max() { + return Math.max(t1, Math.max(t2, t3)); + } + + @Override + public int compareTo(Triplet arg0) { + if (max() < arg0.max()) { + return 1; + } else { + return -1; + } + } + + @Override + public String toString() { + return String.format(""(%s, %s, %s) %s [Total=%s]"", t1, t2, t3, ((isSurprising) ? ""*"" : "" ""), (t1 + t2 + t3)); + } +}" +A21187,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam.lib; + +import java.io.File; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +public class Utils { + + private static final String FILE_IN_EXTENSION = "".in""; + private static final String FILE_OUT_EXTENSION = "".out""; + private static final String OUT_DATE_FORMAT = ""_yyyy-MM-dd_HH-mm-ss""; + + public static void solve(String filePath, String fileName, InputConverter inputConverter, SolverBase solver) { + File folder = new File(filePath); + File fin = getInputFile(folder, fileName); + File fout = getOutputFile(folder, fileName); + if (!fout.exists()) { + try { + fout.createNewFile(); + } catch (IOException e) { + System.err.println(""Error creating file "" + fout.getAbsolutePath()); + e.printStackTrace(); + } + } + InputReader reader = null; + SolutionWriter writer = null; + try { + reader = new InputReader(fin, inputConverter); + solver.init(reader); + writer = new SolutionWriter(fout); + + int caseNum = 1; + String solution; + long startTime = System.currentTimeMillis(); + while ((solution = solver.solveNext()) != null) { + writer.writeSolution(caseNum++, solution); + writer.flush(); + } + int time = (int)(System.currentTimeMillis() - startTime); + System.out.println(""Done in "" + (time / 1000) + "" seconds ("" + (time / (caseNum - 1)) + ""ms average)""); + } catch (Exception e) { + System.err.println(""Error solving""); + e.printStackTrace(); + } + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + // do nothing + } + } + if (writer != null) { + writer.flush(); + writer.close(); + } + } + + public static File getInputFile(File folder, String fileName) { + return new File(folder, fileName + FILE_IN_EXTENSION); + } + + public static File getOutputFile(File folder, String fileName) { + DateFormat dateFormat = new SimpleDateFormat(OUT_DATE_FORMAT); + String date = dateFormat.format(Calendar.getInstance().getTime()); + return new File(folder, fileName + date + FILE_OUT_EXTENSION); + } + + public static String[] convertToStringArray(String line) { + return line.split("" ""); + } + + public static int[] convertToIntArray(String line, int count) { + int[] items = new int[count]; + int wordStart = 0; + for (int i = 0; i < count; i++) { + int wordEnd = line.indexOf(' ', wordStart); + if (wordEnd < 0) { + wordEnd = line.length(); + } + int param = Integer.parseInt(line.substring(wordStart, wordEnd)); + items[i] = param; + wordStart = wordEnd + 1; + } + return items; + } + + public static int convertToIntArray(String line, int[] itemsOut) { + int count = 0; + int wordStart = 0; + int length = line.length(); + while (wordStart < length) { + int wordEnd = line.indexOf(' ', wordStart); + if (wordEnd < 0) { + wordEnd = line.length(); + } + int param = Integer.parseInt(line.substring(wordStart, wordEnd)); + itemsOut[count++] = param; + wordStart = wordEnd + 1; + } + return count; + } + +} +" +A20070,"import java.io.*; +public class CodeJamQual2 { + + /** + * @param args + */ + public static void main(String[] args) { + try{ + // Open the file that is the first + // command line parameter + File file = new File(""input.in""); + FileInputStream fstream = new FileInputStream(""input.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + FileWriter fout = new FileWriter(""out2.txt""); + BufferedWriter outprint = new BufferedWriter(fout); + //Read File Line By Line + int i = 0; + while ((strLine = br.readLine()) != null) { + if (i != 0) { + String[] stringArray = strLine.split("" ""); + int NumberofGooglers = Integer.parseInt(stringArray[0]); + int NumberofSurprises = Integer.parseInt(stringArray[1]); + int p = Integer.parseInt(stringArray[2]); + int overshoot = 0; + int safe = 0; + int diff = 0; + + switch (p) { + case 0: overshoot = 0;safe = 0; break; + case 1: overshoot = 1;safe = 1; break; + case 2: overshoot = 2;safe = 4; break; + default: overshoot = p*3-4;safe = p*3-2; break; + } + + int num = 0; + int osnum = 0; + int ssnum = 0; + //System.out.println(""overshoot "" + overshoot + "" "" + ""safe "" + safe); + for (int j = 3; j < stringArray.length; j++) { + num = Integer.parseInt(stringArray[j]); + if (num >= safe){ + ssnum += 1; + } + if (num >= overshoot){ + osnum += 1; + } + } + diff = osnum - ssnum; + if (NumberofSurprises > diff) NumberofSurprises = diff; + + int out = ssnum + NumberofSurprises; + + outprint.write(""Case #"" + i + "": "" + out); + outprint.newLine(); + + System.out.println(""Case #"" + i + "": "" + out); + } + + i++; + + } + + //Close the input stream + in.close(); + //Close the output stream + outprint.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A22565,"package ab.gcj; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class Surprising { + + public static void main(String args[]) + { + + Surprising s = new Surprising(); + } + + public Surprising() + { + try{ + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + + int numOfTests = Integer.parseInt(reader.readLine()); + for(int j = 0 ; j < numOfTests ; j++) + { + String[] tstr = reader.readLine().split("" ""); + int numGooglers = Integer.parseInt(tstr[0]); + int surprising = Integer.parseInt(tstr[1]); + int p = Integer.parseInt(tstr[2]); + int [] t = new int[numGooglers]; + for(int i =0 ; i < t.length; i++) + { + t[i] = Integer.parseInt(tstr[i+3]); + } + + System.out.println(""Case #""+(j+1)+"": ""+test(numGooglers,surprising,p,t) ); + } + }catch(Exception e) + { + + } + } + + public int test(int n , int s , int p, int[] t) + { + int count = 0 ; + int surprising = s; + + for(int i = 0 ; i < t.length; i++) + { + if(t[i] == 0 ) + { + if(p == 0) count++; + continue; + } + int a = t[i]/3; + int b = a * 3; + int rem = t[i] - b; + if(a >= p) { + + count++; + } + else + { + if((surprising != 0) && rem == 0 && (a + 1 >= p)) { + surprising--; + count++; + continue; + } + if( rem == 1 && a+1 >=p) + { + count++; + } + if(rem == 2) + { + if(a + 1 >= p ) + { + count++; + continue; + } + if(surprising != 0 && a+2 >=p) + { + surprising--; + count++; + } + } + } + + + } + + return count; + + } +} +" +A20798,"package com.forthgo.google.g2012r0; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * Created by Xan Gregg. + * Date: 4/14/12 + */ +public class ProblemB { + public static void main(String[] args) { + try { + Scanner in = new Scanner(new File(""B.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""B.out"")); + //PrintWriter out = new PrintWriter(System.out); + int t = in.nextInt(); + for (int i = 0; i < t; i++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int k = solve(in, n, s, p); + out.printf(""Case #%d: %d%n"", i + 1, k); + out.flush(); + } + + } catch (IOException e) { + throw new RuntimeException(); + } + + } + + private static int solve(Scanner in, int n, int s, int p) { + int k = 0; + for (int i = 0; i < n; i++) { + int score = in.nextInt(); + int best = (score / 3) + (score % 3 > 0 ? 1 : 0); + boolean surprise = score >= 2 && score <= 28 && score % 3 != 1; + if (best >= p) { + k++; + } + else if (s > 0 && best == p - 1 && surprise) { + k++; + s--; + } + } + return k; + } + +} +" +A20159,"import java.io.File; +import java.util.Scanner; + +class B{ + + public static void main(String[] args) { + + if(args.length==0){ + System.out.println(""Error :: Please provide input file name as first command line argument""); + System.out.println(""Usage :: java Main ""); + System.out.println(""Example :: java Main A-small-practice.in""); + } + else{ + try{ + Scanner input=new Scanner(new File(""B-small-attempt1.in"")); + //Scanner input=new Scanner(new File(""input.txt"")); + //System.out.println(""Reading Input from ""+ args[0]+"" file""); + + int no=input.nextInt(); + int in[][]=new int[no][100]; + + for(int i=0;i=0;i--){ + for(int j=10;j>=0;j--){ + for(int k=10;k>=0;k--){ + if(Math.abs(i-j)<=2&&Math.abs(j-k)<=2&&Math.abs(k-i)<=2){ + if(Math.abs(i-j)==2||Math.abs(j-k)==2||Math.abs(k-i)==2){ + mat[count][0]=i; + mat[count][1]=j; + mat[count][2]=k; + mat[count++][3]=-1; + } + + else{ + mat[count][0]=i; + mat[count][1]=j; + mat[count++][2]=k; + } + } + } + } + } + + /*for(int i=0;i<179;i++){ + System.out.print(mat[i][0]+"" ""); + System.out.print(mat[i][1]+"" ""); + System.out.print(mat[i][2]+"" ""); + System.out.print(mat[i][3]+"" ""); + System.out.println(); + }*/ + + //Algorithm + for(int i=0;i=in[i][2]||mat[a][1]>=in[i][2]||mat[a][2]>=in[i][2])){ + if(mat[a][3]==-1){ + //System.out.println(mat[a][0]+"" ""+mat[a][1]+"" ""+mat[a][2]); + flags[k][1]=-1; + } + else{ + //System.out.println(mat[a][0]+"" ""+mat[a][1]+"" ""+mat[a][2]); + flags[k][0]=-1; + } + } + } + //System.out.println(flags[k][0]+"" ""+flags[k][1]); + } + int finalCount=0; + int sup=in[i][1]; + for(int r=0;r0){ + finalCount++; + sup--; + } + } + System.out.println(""Case #""+(i+1)+"": ""+finalCount); + } + }catch(Exception e){ + e.printStackTrace(); + } + } + } +}" +A21890,"class CodeJam2012 { + public static void main(String[] args) { + String[] input = ""100 6 2 8 29 20 8 18 18 21 48 25 0 29 19 2 6 4 19 19 14 24 22 2 16 4 23 26 2 30 3 16 23 28 30 20 2 4 16 9 6 4 12 12 19 8 28 26 23 30 28 22 27 15 30 8 16 22 30 6 25 38 7 6 0 3 9 17 28 19 12 1 7 6 17 23 6 19 19 6 23 24 13 29 2 23 1 1 19 4 4 4 7 19 20 7 10 13 11 16 5 15 72 28 9 25 11 21 23 24 23 17 1 21 20 23 23 12 28 4 5 23 23 23 28 23 30 21 24 26 24 8 18 12 23 24 24 8 23 30 24 23 24 23 4 24 24 24 23 1 23 23 8 23 24 24 23 2 0 13 14 15 24 24 23 24 23 25 8 19 23 23 8 24 24 23 24 83 35 10 3 25 7 3 18 0 29 25 6 4 14 21 25 28 26 22 0 6 6 12 10 25 10 19 11 7 9 17 19 7 0 17 23 9 22 27 15 4 28 12 21 23 22 20 13 7 14 9 15 13 3 24 2 27 22 28 26 10 27 13 26 16 8 13 19 3 2 28 14 22 5 28 16 10 4 1 12 23 30 4 22 18 30 15 2 6 15 14 18 25 22 25 15 15 17 26 9 30 12 29 20 67 67 3 23 11 21 12 14 13 25 13 28 9 10 14 9 8 2 22 24 27 12 9 4 9 13 8 2 8 16 13 13 14 14 5 25 24 2 10 8 27 21 11 20 9 5 15 9 13 5 12 22 23 2 13 5 12 25 16 21 9 20 15 4 16 12 16 17 27 19 31 5 2 3 2 2 2 3 3 7 8 2 3 7 3 2 3 2 2 15 3 14 25 2 26 3 24 23 25 2 22 15 2 2 54 4 2 3 23 17 15 3 2 3 5 12 4 8 2 2 15 2 6 6 2 3 3 6 6 22 3 3 2 2 3 6 30 25 2 3 2 3 19 4 1 3 3 13 3 23 3 5 9 3 3 5 2 2 2 27 3 24 1 6 15 14 15 14 9 14 15 14 15 14 20 14 26 1 14 21 15 15 8 12 10 5 30 15 51 38 4 4 28 23 20 15 15 5 27 10 26 25 3 3 9 1 23 17 23 17 28 13 23 23 17 29 28 23 21 4 27 21 7 16 21 27 27 30 19 15 27 19 6 26 8 15 25 0 21 25 18 22 96 6 7 17 17 28 5 1 0 18 18 17 9 0 18 7 18 16 10 21 12 12 22 12 18 17 12 17 21 12 18 14 18 17 9 18 11 17 18 11 20 17 27 18 1 17 18 19 26 17 11 18 14 19 27 28 17 24 18 0 2 17 17 17 18 17 18 17 30 17 12 18 20 17 18 2 8 7 18 17 18 10 18 17 17 17 10 17 10 23 18 18 17 6 18 17 18 23 18 79 15 4 8 28 24 7 24 8 8 0 9 9 9 18 8 26 9 8 30 12 9 8 8 9 8 8 9 29 3 25 8 8 9 8 7 8 8 0 9 2 25 2 8 20 12 9 9 4 7 9 30 7 29 8 1 22 9 8 28 4 15 8 10 26 17 27 8 2 2 26 18 12 8 9 20 26 12 8 18 9 0 85 70 5 7 9 23 26 25 1 8 12 12 7 10 26 20 9 17 27 4 17 18 8 13 0 4 28 23 15 2 29 24 18 30 4 3 0 20 22 7 6 29 25 23 9 2 23 7 8 3 25 7 17 7 0 22 6 1 0 4 3 2 24 15 30 3 1 17 14 5 4 8 2 15 18 5 9 6 26 18 5 13 2 30 29 11 1 1 11 0 5 5 26 0 23 1 27 0 30 29 23 12 10 2 7 24 22 10 12 25 7 30 12 1 13 29 8 9 23 15 28 24 23 14 24 13 23 11 30 24 24 16 23 13 16 26 23 26 2 29 24 23 23 27 16 26 24 19 19 2 15 10 11 13 20 27 5 5 13 23 4 23 2 27 15 17 24 2 11 9 2 2 3 3 3 3 8 3 8 21 4 2 0 10 18 12 50 32 5 28 27 4 26 30 24 0 24 27 7 19 3 20 6 11 14 10 14 20 25 12 14 5 7 15 26 24 3 18 27 3 8 18 17 21 25 11 8 14 1 4 2 11 0 7 29 14 9 21 22 42 8 5 9 25 26 17 18 16 6 14 15 3 22 8 0 7 10 19 9 23 30 21 17 5 6 15 29 1 10 22 29 0 12 27 19 5 23 10 11 30 18 6 21 19 77 49 3 14 6 16 16 28 23 16 12 19 5 6 24 23 6 30 25 6 27 27 30 1 12 26 17 21 5 9 9 30 26 19 9 8 8 8 29 30 8 2 24 28 17 20 7 12 22 5 11 26 19 28 23 6 9 18 25 19 3 12 4 28 4 1 24 21 13 17 3 12 22 14 3 21 22 15 8 30 65 10 6 30 13 27 18 29 10 18 17 22 21 14 0 10 4 26 15 10 7 3 0 12 26 26 7 3 5 2 23 15 20 19 20 1 5 2 18 13 10 5 24 21 10 25 11 10 13 14 18 5 14 23 13 28 25 7 28 26 13 2 1 28 13 4 21 18 14 10 0 17 18 8 18 30 7 10 0 28 20 10 30 23 21 18 12 6 15 24 29 1 1 13 12 17 17 26 2 26 19 28 0 10 3 2 44 26 7 4 5 6 1 3 30 1 6 22 26 5 0 13 11 28 3 0 26 2 25 24 9 13 25 4 30 7 19 7 17 20 30 28 28 3 1 28 1 8 5 8 23 17 10 46 25 6 19 14 10 17 11 7 15 30 27 30 10 2 30 0 20 16 12 30 14 25 21 23 23 25 6 13 2 16 23 23 16 24 19 17 1 10 5 29 1 25 3 15 12 9 30 22 81 8 6 14 8 14 15 14 15 14 30 25 15 14 14 14 0 9 15 6 23 15 15 14 14 15 15 20 14 15 25 23 15 8 28 14 8 21 14 11 14 15 24 0 14 14 15 14 1 16 14 8 20 15 14 19 14 14 15 27 15 30 15 15 15 24 3 4 15 15 14 14 14 26 2 15 16 14 11 25 15 20 22 15 82 29 8 1 8 2 20 21 0 0 21 21 4 15 21 14 25 21 20 20 21 3 12 21 21 20 21 21 17 21 12 20 21 20 16 12 6 21 20 25 16 28 21 11 18 27 5 16 20 5 21 21 11 19 12 21 3 20 21 21 23 16 6 20 23 11 20 0 20 24 21 27 27 0 3 20 1 1 4 20 6 21 29 21 7 21 21 2 16 3 3 15 14 5 16 4 14 7 11 14 9 6 14 2 23 23 17 23 4 71 23 9 4 24 26 9 8 6 20 11 7 18 12 21 20 4 30 22 14 26 4 8 20 12 1 9 20 20 28 20 5 19 7 27 2 29 7 27 11 6 23 27 9 29 22 22 2 3 21 11 20 11 16 9 9 9 10 25 0 28 20 15 5 1 14 10 22 26 24 26 12 25 19 64 34 6 12 9 12 11 17 10 20 27 13 12 11 29 16 11 28 14 21 9 8 3 0 17 11 22 6 1 2 27 28 13 11 18 7 25 3 15 16 25 4 27 5 5 8 1 28 25 21 7 30 22 7 12 14 18 25 14 7 1 23 24 30 29 21 5 91 12 7 23 7 2 8 6 29 17 3 14 8 5 27 30 26 29 16 12 12 22 28 18 11 12 30 2 21 7 29 24 29 20 3 18 19 9 20 13 25 6 17 18 30 10 5 20 9 25 19 21 20 20 5 6 18 7 30 30 27 9 23 23 28 3 18 14 1 20 22 23 10 10 20 29 1 14 16 16 18 18 16 21 28 24 20 29 9 4 4 18 9 6 21 20 1 8 6 12 24 9 3 12 12 17 17 3 16 19 0 4 9 2 28 8 16 15 42 6 8 20 21 17 14 30 15 10 20 9 17 21 20 20 19 27 20 20 21 28 29 12 20 20 21 20 21 25 18 11 20 24 11 24 30 21 6 0 21 21 18 21 20 87 8 6 8 12 30 29 3 9 26 15 14 8 15 15 14 30 15 7 14 15 28 15 26 15 15 15 5 14 20 28 0 14 14 14 27 14 12 29 14 3 17 25 15 3 15 14 15 15 15 24 15 15 14 19 14 13 12 15 9 18 7 13 11 14 5 15 8 14 14 24 15 15 29 26 19 24 27 27 14 15 4 14 14 10 16 15 14 15 14 79 26 4 25 8 20 9 24 9 9 8 12 13 5 9 10 16 12 0 4 13 9 22 13 5 9 9 8 8 9 26 8 8 9 20 28 8 8 9 9 9 27 8 22 9 8 9 9 4 18 20 22 6 23 9 8 18 9 8 8 9 19 17 25 9 8 8 15 9 8 9 23 9 9 8 4 8 8 9 8 8 9 56 10 6 14 5 22 27 1 14 2 6 17 3 23 29 18 26 22 30 3 12 1 0 14 11 1 23 22 29 25 5 5 1 30 29 20 12 13 29 4 2 16 18 30 1 14 11 18 3 10 17 4 29 26 3 24 9 22 27 84 84 3 3 14 10 7 3 5 2 28 4 22 6 20 8 26 15 24 14 18 5 4 21 15 22 16 17 27 20 19 17 20 15 3 7 16 12 7 24 10 5 9 24 19 18 10 16 9 13 5 11 6 2 23 19 21 5 3 12 8 3 5 10 10 23 28 16 21 10 5 21 13 21 21 14 21 17 5 17 23 3 23 17 10 11 20 50 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 16 4 21 19 4 21 28 0 28 14 5 4 20 0 6 25 18 4 10 13 16 20 11 12 8 20 11 2 20 18 27 1 5 10 11 22 29 3 23 4 20 20 23 20 28 5 11 5 25 27 5 9 2 29 24 8 22 15 13 4 17 24 21 28 27 30 12 21 5 13 23 14 15 25 30 29 22 17 12 25 27 1 1 28 27 16 15 2 6 13 16 9 8 28 16 17 11 1 22 10 1 10 63 1 10 27 26 23 26 26 9 26 27 6 6 26 23 26 24 26 27 27 26 27 2 26 27 16 22 27 26 29 26 26 27 27 6 16 13 8 27 8 1 23 25 18 28 19 0 4 5 27 26 26 26 23 27 27 27 23 26 26 12 20 27 8 6 3 84 24 7 17 17 14 2 14 17 17 10 17 10 18 17 13 17 18 17 18 29 17 29 23 2 10 17 17 5 18 29 20 17 24 0 22 18 17 18 18 0 17 25 23 6 18 5 9 21 18 17 8 7 12 18 13 2 18 17 17 18 17 5 2 18 30 18 26 18 18 11 14 6 18 18 18 18 21 1 17 30 15 16 11 17 17 8 22 10 8 7 17 1 17 28 8 3 13 3 8 23 16 1 15 12 29 2 23 30 22 25 15 39 19 4 8 9 9 8 10 30 9 8 8 24 8 17 15 27 9 22 8 8 5 8 8 8 9 9 23 9 19 30 27 9 8 9 26 8 9 9 5 8 0 59 49 8 24 6 11 26 1 12 8 1 14 28 1 8 13 4 12 10 20 10 3 22 21 9 12 9 1 11 20 15 6 28 11 11 4 17 8 10 7 4 3 5 23 3 22 2 11 8 18 5 8 20 15 24 12 20 20 24 21 20 7 66 29 9 3 14 25 2 24 20 15 18 30 3 30 18 29 9 26 18 26 12 25 12 23 23 15 3 3 28 17 28 20 29 16 7 5 25 0 25 7 10 14 10 27 3 11 4 12 18 30 13 12 10 13 6 3 4 4 17 3 18 13 17 16 2 11 6 1 27 96 31 10 15 30 0 7 24 2 16 21 11 23 30 9 2 4 13 7 1 28 27 20 28 13 14 8 26 21 0 22 23 30 27 27 8 8 16 12 13 16 11 11 27 2 16 28 11 18 17 17 27 11 8 12 22 0 24 30 19 30 1 22 22 8 29 23 30 29 10 9 6 20 1 20 8 24 3 23 4 13 12 30 5 22 13 25 5 17 2 27 0 27 11 0 19 12 18 27 58 0 7 30 12 12 18 18 11 26 17 4 17 20 17 1 26 30 18 18 18 18 17 8 7 11 1 26 18 18 17 17 17 23 24 7 25 18 14 20 17 18 8 27 17 18 18 15 17 17 18 24 6 5 17 17 18 17 18 18 25 63 38 4 20 18 8 29 22 17 8 8 15 8 29 20 24 28 1 10 21 14 18 21 30 22 13 26 11 5 24 5 30 8 22 17 18 6 17 20 7 27 18 15 14 19 28 1 17 14 13 24 15 10 14 26 0 8 23 23 14 26 13 9 9 11 25 48 48 8 22 6 23 12 7 2 13 10 14 9 20 16 13 6 8 21 24 12 19 12 11 19 5 8 7 20 19 13 27 10 20 27 26 12 8 18 21 4 26 6 15 26 12 25 2 24 16 3 1 0 8 26 39 11 6 15 14 15 12 13 11 18 18 15 15 7 15 7 15 9 15 14 14 8 20 14 14 14 15 12 15 14 25 17 15 22 14 14 14 15 11 29 15 15 29 0 8 0 21 20 21 2 21 17 20 20 20 21 22 21 21 26 30 20 21 21 30 21 28 20 20 20 21 21 8 23 88 22 7 17 9 10 17 17 14 19 17 9 17 17 22 18 28 17 18 6 7 17 17 18 3 12 17 18 17 18 17 18 0 18 17 17 16 17 22 18 17 18 30 18 18 18 18 17 17 16 28 18 18 18 17 12 0 17 18 6 29 14 26 13 21 15 8 17 17 17 18 6 7 17 17 18 18 10 4 1 18 16 28 18 17 20 17 17 16 3 17 59 13 7 21 16 18 8 17 12 17 23 15 24 10 2 17 17 17 7 22 19 0 26 5 30 18 12 8 18 18 17 28 18 17 17 17 17 15 20 25 17 20 17 18 22 17 24 27 9 30 17 11 17 4 9 17 12 17 25 18 18 2 21 21 7 27 26 16 25 4 5 24 11 25 18 3 26 23 12 12 22 19 11 26 28 11 10 10 1 21 25 6 21 11 20 23 13 11 16 78 25 1 18 14 6 28 29 23 1 6 16 25 30 2 29 23 14 12 3 17 26 30 4 16 18 22 28 17 0 26 24 24 14 26 11 2 3 15 12 1 30 24 22 25 11 30 9 17 14 30 10 30 21 13 20 9 16 0 27 5 9 13 3 26 13 6 11 28 20 22 6 6 20 11 27 11 15 5 29 6 20 2 6 12 19 15 24 15 21 12 29 20 0 14 28 30 25 4 14 25 2 24 28 47 0 3 15 27 1 12 0 28 11 4 23 18 10 23 27 20 26 6 18 5 30 4 17 11 7 22 15 19 0 3 28 20 21 17 6 2 23 21 2 22 13 29 7 1 21 13 15 23 18 38 38 7 21 15 20 6 27 20 2 20 12 27 9 2 9 20 24 23 17 20 6 19 14 5 16 11 21 11 24 8 6 5 6 22 17 15 24 16 4 4 33 27 9 24 17 5 22 10 0 30 29 14 29 20 4 6 26 1 2 7 26 25 16 4 22 26 2 10 3 19 26 13 4 18 12 0 37 0 9 6 25 22 23 24 1 18 9 29 9 25 8 28 7 7 7 18 29 10 0 21 16 3 24 24 7 3 7 22 11 13 15 20 4 18 7 3 43 43 0 2 28 24 16 24 19 18 6 19 13 18 28 12 11 22 13 4 17 19 21 16 10 8 17 19 20 3 22 13 18 4 22 9 24 22 17 15 25 9 10 8 8 15 8 3 2 3 3 27 3 16 2 2 2 45 8 2 20 2 26 11 28 3 12 7 20 15 2 23 21 17 13 0 2 8 12 26 29 0 5 11 9 19 11 27 17 9 24 27 26 15 0 30 26 13 0 29 25 10 19 1 30 48 9 8 12 21 20 14 30 21 8 21 25 20 4 20 12 27 20 0 16 29 4 4 22 28 4 26 20 14 1 24 13 21 21 16 4 21 20 19 2 12 20 28 14 20 20 19 20 13 21 27 71 29 7 0 0 0 28 1 11 3 4 12 3 4 8 20 20 15 22 25 11 21 4 27 29 19 12 22 11 26 11 8 9 27 9 7 23 4 30 3 6 29 24 8 23 5 27 1 17 14 5 20 6 8 13 1 4 17 4 24 6 10 2 20 29 20 8 5 2 8 20 2 8 8 78 4 7 22 27 24 17 3 16 17 29 27 12 18 10 6 17 18 18 17 12 17 27 18 17 18 18 11 7 18 17 21 3 18 29 17 18 18 18 1 28 18 17 21 18 17 2 29 29 17 26 30 18 12 18 12 15 28 0 16 18 16 14 18 18 1 20 18 27 18 8 17 17 18 18 12 17 18 30 13 7 14 0 0 14 28 11 28 14 8 17 13 24 18 21 4 21 26 81 30 3 29 2 30 0 21 10 16 25 16 10 22 8 26 8 19 21 8 30 17 21 22 12 19 18 24 14 14 25 4 16 8 22 0 15 12 26 9 21 29 18 13 20 29 5 28 25 22 6 24 24 25 18 9 9 9 2 4 16 21 25 20 24 3 12 17 10 8 5 27 4 16 7 17 10 26 26 19 10 23 2 27 49 25 7 23 29 22 15 1 19 7 28 11 29 5 19 9 15 1 15 23 13 0 9 2 11 27 18 5 1 24 22 2 15 18 10 22 29 10 26 30 3 4 7 1 23 19 30 4 16 17 14 29 38 0 5 22 0 18 13 1 10 9 0 19 4 26 1 3 13 15 21 25 29 1 5 17 3 19 25 19 8 10 23 12 24 9 10 10 10 5 22 20 9 11 11 7 28 2 23 5 24 6 24 2 19 26 3 85 0 7 25 7 27 25 16 9 4 10 30 30 21 21 18 20 19 12 11 10 24 14 25 12 23 20 25 8 13 27 4 19 21 14 25 19 5 18 0 18 11 21 2 20 22 15 1 22 6 19 13 14 21 16 25 17 15 19 18 7 9 5 15 13 11 7 16 25 11 12 21 12 23 29 27 27 24 22 17 8 1 5 30 20 13 23 9 98 28 4 8 10 9 10 24 9 4 3 27 9 26 9 12 28 4 8 8 7 20 28 9 8 7 15 8 12 8 8 5 29 8 9 21 9 16 21 16 8 17 29 30 9 11 30 28 8 9 11 18 8 26 8 8 9 9 29 9 9 8 12 13 9 9 28 9 9 24 8 29 9 9 9 8 5 9 8 9 8 8 4 25 15 8 8 8 10 6 9 1 9 29 8 8 5 9 4 9 9 32 0 10 21 8 14 30 29 9 9 27 21 10 27 9 3 17 10 23 12 27 17 12 19 15 13 12 8 29 24 18 18 26 20 0 79 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 34 34 2 21 10 15 19 9 20 23 4 20 10 15 12 15 26 21 18 19 15 8 12 22 27 4 22 6 22 2 7 2 19 7 16 13 12 89 33 7 17 21 17 18 18 9 17 0 17 17 17 18 2 30 25 17 20 24 1 17 12 18 17 0 18 18 8 17 18 8 24 30 5 8 17 17 28 18 9 12 17 4 8 7 25 17 17 12 0 12 17 17 25 7 17 18 18 2 28 19 5 18 18 7 21 18 20 4 17 8 17 24 18 17 17 12 18 4 9 17 17 10 18 18 4 17 18 26 18 44 5 6 1 15 14 14 17 15 1 15 13 15 15 8 14 14 15 15 15 10 16 2 22 21 15 16 18 14 14 15 9 24 14 29 16 14 15 6 14 14 13 3 15 24 8 15 17 9 5 16 0 20 26 22 1 1 17 13 28 2 9 1 3 28 13 30 39 27 3 8 23 25 16 7 15 21 4 1 21 7 12 2 21 19 8 29 13 28 1 24 1 30 3 11 20 8 1 7 9 28 24 1 1 15 15 25 1 28 72 51 9 27 20 20 28 25 8 4 17 23 7 15 27 9 6 26 14 15 19 19 5 4 7 7 27 4 4 18 6 3 1 8 9 16 1 1 2 14 26 29 26 11 3 30 15 6 5 16 7 26 23 2 2 0 15 26 2 12 21 7 8 0 26 10 0 23 22 15 15 1 29 8 13 98 0 10 4 25 12 12 8 8 27 14 2 28 15 28 1 15 6 4 11 28 2 12 15 8 23 25 27 19 8 0 8 25 16 10 9 24 28 27 14 4 13 23 12 12 0 3 29 3 14 22 13 20 28 0 16 16 8 29 6 28 0 0 20 26 8 27 5 22 11 25 26 30 1 30 23 12 9 19 9 9 25 1 1 23 30 7 19 26 29 3 28 30 30 6 8 3 29 18 22 23 59 10 10 20 30 3 29 0 30 2 24 29 9 24 17 12 16 11 17 30 12 29 28 0 4 12 11 12 5 8 23 15 21 20 4 15 14 30 6 0 30 24 15 11 14 16 17 3 19 12 26 6 29 14 26 16 9 30 5 14 9 30 77 44 2 8 0 6 9 17 30 13 27 17 8 21 22 8 12 28 11 0 8 23 23 29 25 7 12 15 7 26 18 11 30 6 16 10 30 29 15 0 7 18 28 16 12 28 18 20 11 8 29 2 6 0 20 1 26 3 27 9 8 24 4 1 5 28 10 15 27 4 6 5 22 12 28 5 22 5 19 4 71 38 8 28 17 28 27 8 4 15 23 24 19 11 27 2 13 2 22 13 24 0 6 16 24 17 25 21 21 24 26 3 17 5 22 23 26 24 1 13 14 3 2 3 29 17 27 14 9 14 1 3 7 8 30 25 15 6 17 26 14 22 16 30 2 30 5 23 28 28 13 1 1 23 27 0 7 14 18 7 17 28 18 17 18 5 14 17 22 14 18 11 21 0 17 18 17 17 16 18 17 21 25 17 45 4 10 26 6 25 10 21 16 13 27 21 1 22 17 14 8 19 17 17 15 6 21 18 28 15 7 26 10 9 0 6 12 22 25 30 23 19 29 8 19 21 8 25 4 11 4 9 39 6 5 19 8 29 14 17 29 17 4 2 28 0 29 9 2 22 5 27 26 10 29 10 20 12 20 27 7 10 18 7 14 19 2 3 17 27 27 19 10 28 86 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 79 28 10 26 27 27 11 26 10 27 27 7 26 27 28 17 26 27 26 17 27 28 12 27 7 13 5 26 20 8 27 29 26 26 8 12 26 27 5 27 18 27 27 14 7 26 26 14 11 10 9 27 27 16 26 27 26 21 5 27 0 26 27 6 26 26 27 26 6 26 27 9 8 18 26 27 11 28 1 27 27 26 68 49 7 18 30 30 2 23 15 21 5 28 6 4 13 3 29 3 25 11 8 10 10 2 21 15 27 16 9 20 17 3 26 19 10 6 29 26 5 10 29 5 11 20 12 1 26 18 26 3 3 20 9 17 12 19 15 5 14 14 20 14 21 21 10 8 1 11 17 30 27 27 0 10 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 42 12 9 5 27 4 24 19 21 29 25 16 7 25 17 11 28 13 27 30 14 1 1 10 24 23 25 13 24 0 24 16 16 12 27 4 14 5 14 25 26 24 0 15 29 57 11 3 6 5 5 17 30 22 0 6 19 5 9 4 5 6 28 6 6 5 17 6 24 22 19 5 26 29 6 5 5 6 5 26 6 28 16 16 27 6 6 10 6 6 22 6 11 4 5 3 14 28 20 29 6 6 3 5 5 87 7 7 23 18 8 12 15 21 17 17 17 24 26 25 18 3 28 17 28 11 17 16 26 18 18 17 16 8 18 6 11 17 20 18 4 18 18 17 18 18 2 17 5 18 24 17 20 17 11 17 18 22 6 18 18 17 25 5 18 18 25 17 18 6 24 2 1 18 8 18 17 17 18 5 18 17 24 17 17 18 18 17 21 17 10 17 29 11 23 "".split("" ""); + QuestionA(input); + } + + + + static void QuestionA(String[] input){ + int inputCounter = 0, T, N, S, p, nonSupprising, supprising, googlers, thresholdSmall, thresholdLarge; + T=Integer.valueOf(input[inputCounter]); + inputCounter++; + + for (int i=0; i=thresholdLarge){ + nonSupprising++; + } + else if(googlers>=thresholdSmall){ + supprising++; + } + } + System.out.print(""Case #""+(i+1)+"": ""+(nonSupprising+Math.min(supprising, S))+""\n""); + } + + } +}" +A21063,"package com.seol.codejam; + + +import java.io.File; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + +/** + * Solution for http://code.google.com/codejam/contest/1150485/dashboard#s=p1 + */ +public class DancingWithTheGooglers { + + public static int solveCase(int[] scores, int surpriseNum, int neededScore) { + int len = scores.length; + int maxWithNeeded = neededScore*3; + int suprCnt = surpriseNum; + int res=0; + for(int i = 0; i < len; i++) { + if(scores[i] < neededScore) { + continue; + }else if(scores[i] >= maxWithNeeded || maxWithNeeded - scores[i] <= 2) { + res++; + } else if (maxWithNeeded - scores[i] <= 4 && suprCnt > 0){ + suprCnt--; + res++; + } + } + + return res; + } + + + + public static void main(String[] args) throws Exception { + + solveAllCases(""D:/worspaces/google_codejam/test_data/dance3""); + } + + public static void solveAllCases(String fileName) throws Exception { + Scanner sc = new Scanner(new File(fileName)); + int cases = sc.nextInt(); +// String tmp = sc.nextLine(); + for (int i = 0; i < cases; i++) { + int n = sc.nextInt(); + int surp = sc.nextInt(); + int score = sc.nextInt(); + int[] ar = new int[n]; + for(int q =0; q < n; q++) { + ar[q] = sc.nextInt(); + } + int res = solveCase(ar, surp, score); + + System.out.println(""Case #"" + (i + 1) + "": "" + res); + // System.out.printf(""Case #%1$d: %2$.7f \n"" , (i+1), res); + + } + // System.out.println(""MAX:"" + max); + } + +} +" +A20249," + +import java.util.Scanner; + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int i = 1; i <= T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int t[] = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = sc.nextInt(); + } + + int count = 0; + for (int j = 0; j < N; j++) { + int r = t[j] - p; + if(r >= 2*Math.max(0, p-1)) + ++count; + else if(S > 0 && r >= 2*Math.max(0, p-2)) { + ++count; + --S; + } + } + System.out.println(""Case #"" + i + "": "" + count); + } + } + +} +" +A21092,"package com.google; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class Googlers { + public static void main(String[] args) throws IOException { + final Scanner reader = new Scanner(new File(""in.txt"")); + final FileWriter writer = new FileWriter(new File(""out.txt"")); + + final int N = reader.nextInt(); + reader.nextLine(); + + for (int i = 0; i < N; i++) { + final int n = reader.nextInt(); + final int exceptions = reader.nextInt(); + final int winScore = reader.nextInt(); + + final int [] participants = new int [n]; + for (int j = 0; j < n; j++) { + participants[j] = reader.nextInt(); + } + + writer.write(String.format(""Case #%d: %d"", (i + 1), howManyCanWin(exceptions, winScore, participants))); + if (i < N - 1) { + writer.write(""\n""); + } + } + + writer.close(); + } + + public static int howManyCanWin(final int exceptions, final int winScore, final int [] participants) { + int remainException = exceptions; + int res = 0; + + for (int i : participants) { + final int thirdPart = i / 3; + final int lastPart = i % 3; + + if ((thirdPart >= winScore) || + (lastPart == 1 && thirdPart + 1 >= winScore) || + (lastPart == 2 && thirdPart + 1 >= winScore)) { + res++; + continue; + } + + if ((lastPart == 0 && thirdPart + 1 >= winScore && thirdPart - 1 >= 0 && remainException > 0) || + (lastPart == 2 && thirdPart + 2 >= winScore && remainException > 0) ){ + remainException --; + res++; + continue; + } + } + + return res; + } +} +" +A22517,"package org.digiharbor.gene; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.Console; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + +public class CJ2012 { + public static void main(String[] args) throws FileNotFoundException, IOException { + new CJ2012(); + } + public CJ2012() throws FileNotFoundException, IOException { + BufferedReader sysin = new BufferedReader(new InputStreamReader(System.in)); + + String stage = ""Qual""; + System.out.printf(""Stage %s Problem to run: (ae, a0, a1, al, be...): "", stage); + String cmd = sysin.readLine().toUpperCase().trim(); + char problem = cmd.charAt(0); + String fname = """"; + if (cmd.charAt(1) == 'E') + fname = stage + ""/"" + problem + ""-example""; + else if (cmd.charAt(1) == 'L') + fname = stage + ""/"" + problem + ""-large""; + else + fname = stage + ""/"" + problem + ""-small-attempt"" + cmd.charAt(1); + + String inf = fname+"".in""; + String outf = fname+"".out""; + BufferedReader f = new BufferedReader(new FileReader(inf)); + BufferedWriter out = new BufferedWriter(new FileWriter(outf)); + int cnt = Integer.parseInt(f.readLine()); + + long start = System.currentTimeMillis(); + System.out.printf(""Running %s => %s ..."", inf, outf); + switch (problem) { + case 'A': + new A_SpeakingInTongues(cnt, f, out); + break; + case 'B': + new B_DancingWithTheGooglers(cnt, f, out); + break; + case 'C': + new C_RecycledNumbers(cnt, f, out); + break; + case 'D': + new D_HallOfMirrors(cnt, f, out); + break; + } + long finish = System.currentTimeMillis(); + System.out.printf("" %dmsec"", finish-start); + f.close(); + out.close(); + } + + class A_SpeakingInTongues { + public A_SpeakingInTongues(int cnt, BufferedReader infile, BufferedWriter outfile) throws IOException { + String key = ""yhesocvxduiglbkrztnwjpfmaq""; + for (int i = 0; i < cnt; i++) { + String ln = infile.readLine(); + String res = """"; + for (int p = 0; p < ln.length(); p++) { + if (ln.charAt(p) == ' ') + res += ' '; + else + res += key.charAt(ln.charAt(p) - 'a'); + } + outfile.write(String.format(""Case #%d: %s\r\n"", i + 1, res)); + } + } + } + class B_DancingWithTheGooglers { + public B_DancingWithTheGooglers(int cnt, BufferedReader infile, BufferedWriter outfile) throws IOException { + Scanner in = new Scanner(infile); + for (int i=0; i=22 ensures a best of 8 (8,7,7) + if (surescore < 0) surescore = 0; + int surprisescore = surescore - 2; // i.e. 20,21 could get an 8 with a surprise (8,7,6) (8,6,6) + if (surprisescore < 0) surprisescore = 0; + for (int j=0; j=best && total >= surescore) bestcnt++; + else if (total>=best && total >= surprisescore) surprises++; + } + int res = bestcnt + (nSurprise >= surprises? surprises : nSurprise); + outfile.write(String.format(""Case #%d: %d\r\n"", i + 1, res)); + } + } + } + class C_RecycledNumbers { + public C_RecycledNumbers(int cnt, BufferedReader infile, BufferedWriter outfile) throws IOException { + + } + } + class D_HallOfMirrors{ + public D_HallOfMirrors(int cnt, BufferedReader infile, BufferedWriter outfile) throws IOException { + + } + } +} +" +A21671,"package com.google.codejam.p2; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class Problem2 { + + private ArrayList cases = new ArrayList(); + + public void loadInput() { + try{ + FileInputStream fstream = new FileInputStream(""input2.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = br.readLine(); //read number of lines + while ((strLine = br.readLine()) != null) { + String[] info = strLine.split("" ""); + int N = Integer.parseInt(info[0]); + int S = Integer.parseInt(info[1]); + int p = Integer.parseInt(info[2]); + ArrayList scores = new ArrayList(); + for (int i=1; i<=N; i++) + scores.add(Integer.parseInt(info[2+i])); + cases.add(new TestCase(N, S, p, scores)); + } + in.close(); + } + catch (Exception e) { } + } + + public static boolean isAtLeastP(int score, int p, boolean usingSurprisingTriplet) { + int minus1 = (p-1<0?0:p-1); + int minus2 = (p-2<0?0:p-2); + if (score >= p+minus1+minus1) + return true; + if (usingSurprisingTriplet) { + if (score >= p+minus2+minus2) + return true; + } + return false; + } + + public void getOutput() { + for (int i=0; i 0) { + if (isAtLeastP(score, tc.p, true)) { + total++; + tc.S--; + } + } + } + System.out.println(""Case #"" + (i+1) + "": "" + total); + } + } + + + public static void main(String args[]) { + Problem2 p = new Problem2(); + p.loadInput(); + p.getOutput(); + } + +} +" +A20216,"import java.io.*; + +class code3 +{ + public static void main(String args[]) throws Exception + { + File ii = new File (""B-large.in""); + FileInputStream fis = new FileInputStream(ii); + BufferedReader br = new BufferedReader(new InputStreamReader (fis)); + int cases = Integer.parseInt(br.readLine()); + FileOutputStream fout = new FileOutputStream (""output.txt""); + DataOutputStream dout = new DataOutputStream (fout); + int total=0; + for(int i=0;i=best||second>=best||third>=best){total++;continue;} + if(sum>=(3*best-4)&&sum<=(3*best+4)&&sur!=0&&sum!=0) + { + total++;sur--; + + } + + }dout.writeBytes(""Case #""+(i+1)+ "": ""+total+""\n""); + total=0; + + } + } +}" +A20805,"package be.mokarea.gcj.common; + +public abstract class TestCaseReader { + public abstract T nextCase() throws Exception; + + public abstract int getMaxCaseNumber(); +} +" +A22255,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.List; +import java.util.Scanner; + +public class ProblemB { + public static void main(String[] args) throws IOException { + BufferedReader consoleIn = new BufferedReader(new InputStreamReader(System.in)); + String line = consoleIn.readLine(); + int T = Integer.valueOf(line); + for(int i = 0; i < T; i++){ + line = consoleIn.readLine(); + Scanner sc = new Scanner(line); + int N = sc.nextInt(); + int S = sc.nextInt(); + int P = sc.nextInt(); + + int[] scores = new int[N]; + for(int j = 0; j < N; j++){ + scores[j] = sc.nextInt(); + } + + int[] supMax = new int[N]; + int[] norMax = new int[N]; + for(int j = 0; j < N; j++){ + int score = scores[j]; + int res = score % 3; + + supMax[j] = (score - res) / 3 + 1; + if(res == 2){ + supMax[j]++; + } + + norMax[j] = (score - res) / 3 + 1; + if(res == 0){ + norMax[j]--; + } + + if(score == 0 || score == 1 || score == 30 || score == 29 || score == 28){ + supMax[j] = norMax[j]; + } + } + + int needSup = 0; + int nor = 0; + for(int j = 0; j < N; j++){ + if(norMax[j] >= P){ + nor++; + } else if(supMax[j] >= P){ + needSup++; + } + } + + int result; + if(needSup <= S){ + result = nor + needSup; + } else { + result = nor + S; + } + + StringBuilder sb = new StringBuilder(); + + System.out.printf(""Case #%d: %d"", i+1, result); + System.out.println(sb.toString()); + } + } +} +" +A23065,"import java.io.*; +import java.util.*; + +public class B { + + public static BufferedReader in; + public static StringTokenizer st; + + public static void main(String[] args) throws IOException{ + in = new BufferedReader(new FileReader(""B.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""B.out"")); + + int test = readInt(); + for (int t=1; t<=test; t++){ + out.print(""Case #""+t+"": ""); + + int num = readInt(); + int surp = readInt(); + int cutoff = readInt(); + + int first = cutoff*3-2; + int sec = cutoff*3-4; + + if (cutoff==1){ + sec = 1; + } + + int counter = 0; + for (int i=0; i0){ + counter++; + surp--; + } + } + + out.println(counter); + } + + in.close(); + out.close(); + } + + public static String readLine() throws IOException{ + return in.readLine(); + } + + public static String readToken() throws IOException{ + if (st==null || !st.hasMoreTokens()) + st = new StringTokenizer(readLine()); + + return st.nextToken(); + } + + public static int readInt() throws IOException{ + return Integer.parseInt(readToken()); + } +} +" +A21306,"package fun.codeslam.dancers; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + + BufferedReader reader = new BufferedReader(new InputStreamReader( + System.in)); + + Integer testCaseCount = Integer.parseInt(reader.readLine()); + + for (Integer testCaseNumber = 1; testCaseNumber <= testCaseCount; testCaseNumber++) { + System.out.append(""Case #"" + testCaseNumber + "": ""); + System.out.append(new Result(new TestCase(reader.readLine())).toString()); + System.out.append('\n'); + } + } +} +" +A22766,"import java.util.Scanner; + + +public class QualB +{ + public static void main(String args[]) + { + Scanner kb = new Scanner(System.in); + + int ntc = kb.nextInt(); + for(int tc=0;tc= 3*p-2) + { + y++; + } + else if(ti >= 3*p-4 && ti >= p && sc= sum * 3 ) + { + ans++; + continue; + } + + if ( sum * 3 - 2 < 0 ) + { + continue; + } + else if (allInput[i] >= sum * 3 - 2 ) + { + ans++; + continue; + } + + if ( sum * 3 - 4 < 0 ) + { + continue; + } + else if (allInput[i] >= sum * 3 - 4 && numSurprise > 0 ) + { + ans++; + numSurprise--; + continue; + } + + } +// System.out.println(ans); + + System.out.println(""Case #"" + count++ + "": "" + ans); + + } + in.close(); + } + catch (Exception e) + { + System.err.println(e); + } + + } + +} +" +A22533,"/******************************************************************************* + * Copyright (c) 2012 by Institute of Computing Technology, + * Chinese Academic of Sciences, Beijing, China. + * + * Author: Ruijian Wang + * File: B.java + * Date: 2012-04-14 + * Time: 13:29:55 + ******************************************************************************/ + +package gcj12; + +import java.util.Scanner; + +/** + * Todo. + *

+ * User: Ruijian Wang + * Date: 4/14/12 + * Time: 1:29 PM + * + * @author Ruijian Wang
+ * @version 1.0.0 2012-04-14
+ */ +public class B { + void solve() { + int tCase, n, s, p; + Scanner scan = new Scanner(System.in); + tCase=scan.nextInt(); + for (int i = 1; i <= tCase; i++) { + int num = 0; + n = scan.nextInt(); + s = scan.nextInt(); + p = scan.nextInt(); + int t; + for (int j = 0; j < n; j++) { + t = scan.nextInt(); + int m = t % 3; + int max = -1; + if (m == 1) { + max = t / 3 + 1; + if (max >= p) { + num ++; + } + } else if (m == 2) { + max = t / 3 + 1; + if (max >= p) { + num ++; + } else if (s > 0 && max + 1 >= p) { + s--; + num++; + } + } else { + max = t / 3; + if (max >= p) { + num++; + } else if (s > 0 && t >= 3 && max + 1 >= p) { + s--; + num++; + } + } + } + System.out.println(""Case #"" + i + "": "" + num); + } + } + + public static void main(String[] args) { + new B().solve(); + } +} +" +A20725," + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Scanner; +import java.lang.reflect.Array; +import java.math.BigInteger; + +import javax.rmi.CORBA.Util; + +public class B { + + + private static String fileIN = ""./A.in""; //archivo de entrada (en el dir local del programita) + private static String fileOUT = ""./out.txt""; //salida + + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(fileIN)); + PrintWriter out = new PrintWriter(new File(fileOUT)); + int T = in.nextInt(); + for (int i = 0; i < T; i++) { + String s = ""Case #"" + (i + 1) + "": "" + new B().solve(in); + out.println(s); + System.out.println(s); + } + out.close(); + } +/** +* Retorna la solucion a un caso +**/ + private String solve(Scanner in) { + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + ArrayList scores = new ArrayList(N); + + for(int i = 0; i< N; i++){ + scores.add(in.nextInt()); + } + Collections.sort(scores); + + int min= 2*(Math.max(P-1, 0)) +P; + int minS= 2*(Math.max(P-2, 0)) +P; + System.out.println(min); + System.out.println(minS); + int cant = 0; + for(int i = 0; i< N; i++){ + if(scores.get(N-i-1)>= min) cant++; + else if(scores.get(N-i-1)>= minS){ + S--; + if(S<0) break; + cant++; + } + } + return String.valueOf(cant); + + } + +} +" +A20451,"package QualifiactionRound; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class DancingWiththeGooglers { + + /** + * @param args + */ + + public static void writeToFile(String text) { + try { + BufferedWriter bw = new BufferedWriter( + new FileWriter(new File(""C:\\B-large.out""), true)); + bw.write(text); + bw.newLine(); + bw.close(); + } catch (Exception e) { + } +} + + static int[] detail(String ch){ + int N=0; + if(ch.charAt(1)==' ') N=Integer.parseInt((String) ch.subSequence(0, 1)) ; + else if(ch.charAt(2)==' ') N=Integer.parseInt( (String) ch.subSequence(0, 2)) ; + else N=Integer.parseInt((String) ch.subSequence(0, 3)) ; + //System.out.println(""N ""+N); + + String dh =""""; + int[] tab=new int[N+3]; + int t=0; + for(int i=0;i: ""+tab[3+j]); + + if(tab[3+j]>=p){ + if(tab[3+j]/3>=p) result++; + else if ((tab[3+j]-p)/2>=p-1) result++; + else if(((tab[3+j]-p)/2>=p-2) && S>0) { + result++; + S--; + } + } + + } + writeToFile(""Case #""+nbr+"": ""+result); + System.out.println (""Case #""+nbr+"": ""+result); + + + nbr++; + } + in.close(); + } + catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + + + } + +} +" +A22194,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class DancingGoogle { + + public static void main(String[] args) { + + try { + FileWriter fout = new FileWriter(""B-large.out""); + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter out = new BufferedWriter(fout); + + int T = Integer.parseInt(in.readLine()); + String[] input; + + + for(int i=0; i= p && p < 2) + overs++; + else if(Integer.parseInt(input[j+3]) >= ((p*3)-2) && ((p*3)-2) > 0){ + overs++; + System.out.println(input[j+3] + "" is bigger than or equal to "" + ((p*3)-2)); + } + else if(Integer.parseInt(input[j+3]) >= ((p*3)-4) && ((p*3)-4) > 0) { + if(surprises > 0) { + overs++; + surprises--; + System.out.println(input[j+3] + "" is bigger than or equal to "" + ((p*3)-4) + "" if we use a surprise.""); + } + else System.out.println(input[j+3] + "" is not bigger enough.""); + } + else System.out.println(input[j+3] + "" is not bigger enough.""); + } + System.out.println(""Case #"" + (i+1) + "": "" + overs); + fout.write(""Case #"" + (i+1) + "": "" + overs); + out.newLine(); + out.flush(); + } + in.close(); + out.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A20910,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.LinkedList; + + +public class Dancers { + + static LinkedList scores; + static int googlers = 0; + static int surprising = 0; + static int p; + + + public static void main(String[] args) { + String text = """"; + int tests = 0; + int test_index=0; + int result; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + try{ + tests = Integer.parseInt(br.readLine()); + while ((text = br.readLine()) != null && test_index < tests){ + test_index++; + String[] testcase = text.split("" ""); + googlers = Integer.parseInt(testcase[0]); + surprising = Integer.parseInt(testcase[1]); + p = Integer.parseInt(testcase[2]); + int i = 3; + scores = new LinkedList(); + while(i= okLimit) { result++; } + if(x >= surpriseLimit && x < okLimit && surprising > 0){ + surprising--; + result++; + } + + } + return result; + } + +} +" +A22337," + +//Author KNIGHT0X300 + +import java.util.Scanner; + + + + +public class Main { + + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int t=s.nextInt(); + + for(int i=0;i=2) + { if(S>0) + { if((A==(3*p-4))||(A==(3*p-3))) + { tot++; S--; } + } + if(A>=3*p-2) + tot++; + } + if(p==0) + { + tot++; + } + if(p==1) + { + if(A>=1) + {//System.out.println(""sdk""); + tot++;} + }} + + + + System.out.println(""Case #""+(i+1)+"": ""+tot); + + + } + + } +} +" +A20637,"package codejam.world2012.qualification.b; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + + +public class B { + + private static class Triplet { + public boolean surprising = false; + public boolean unsurprising = false; + + public Triplet() {} + + public Triplet(boolean surprising, boolean unsurprising) { + this.surprising = surprising; + this.unsurprising = unsurprising; + } + + @Override + public String toString() { + return ""[ "" + (surprising?""surprising"":"""") + "" "" + (unsurprising?""unsurprising"":"""") + "" ]""; + } + } + + + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""src/codejam/world2012/qualification/b/large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""src/codejam/world2012/qualification/b/large.out"")); + + HashMap> matrix = new HashMap>(); + + for (int q = 0; q<=10; q++) { + HashMap row = new HashMap(); + for (int r=0; r<31; r++) row.put(r, new Triplet(false, false)); + matrix.put(q, row); + } + + for (int i = 10; i>= 0; i--) { + for (int j=i; j >= i-2; j--) { + if (j < 0) continue; + + for (int k = i; k >= i-2; k--) { + if (k < 0) continue; + + int ti = i+j+k; + + Triplet triplet = matrix.get(i).get(ti); + if (triplet == null) triplet = new Triplet(); + + if ((i-j == 2) || (i-k == 2) || (j-k == 2)) { + // surprising + triplet.surprising = true; + } else { + // unsurprising + triplet.unsurprising = true; + } + matrix.get(i).put(ti, triplet); + } + + } + } + + for (int ti=0; ti<31; ti++) { + Triplet triplet = new Triplet(false, false); + for (int p = 10; p>= 0; p--) { + if (matrix.get(p).get(ti).surprising) triplet.surprising = true; + if (matrix.get(p).get(ti).unsurprising) triplet.unsurprising = true; + matrix.get(p).put(ti, new Triplet(triplet.surprising, triplet.unsurprising)); + } + } + + int T = 0; + T = Integer.parseInt(in.readLine()); + + for (int t = 0; t < T; t++) { + String[] line = in.readLine().split("" ""); + + Long N = Long.parseLong(line[0]); + Long S = Long.parseLong(line[1]); + Integer p = Integer.parseInt(line[2]); + List scoresList = new ArrayList(); + + Long answer = 0L; + + for (int i = 3; i< line.length; i++) { + scoresList.add(Integer.parseInt(line[i])); + } + + for (Integer ti : scoresList) { + + Triplet triplet = matrix.get(p).get(ti); + + if (triplet.surprising && !triplet.unsurprising) { + if (S > 0) { + answer++; + S--; + } + } else if (triplet.unsurprising) { + answer++; + } + } + + out.write(""Case #""+String.valueOf(t+1) +"": ""+answer.toString()); + if (t < T-1) out.write(System.getProperty(""line.separator"")); + + /* + for (Long totalScore : scoresList) { + Long diff = totalScore - p; + Long first = Math.round((double) diff/2); + + if (p - first > 2) { + // impossible + continue; + } + + Long second = diff - first; + if (p - second > 2) { + // impossible + continue; + } + + + } + + + for (Long totalScore : scoresList) { + + // ceiling + Long ceil = Math.round(Math.ceil(totalScore/3)); + Long floor = Math.round(Math.floor(totalScore/3)); + + if (ceil == floor) { + // nice + + } else { + + if (ceil*3 - totalScore < 3) { + + } + + if (totalScore - floor*3 < 3) { + + } + + } + + //System.err.println(""total: "" + totalScore + "", average: "" + average); + Long diff = average*3 - totalScore; // diff > 0 + + Long max = 0L; + if (diff > 0) max = average + diff; + else max = average; + if (max >= p) answer++; + if ((Math.abs(diff) > 1) && (S > 0)) S--; + } + + if (S == 0) { + System.err.println(""Case #""+String.valueOf(t+1) +"": ""+answer.toString()); + continue; + } + + // S > 0 + + for (Long totalScore : scoresList) { + Long average = Math.round((double) totalScore/3); + Long diff = totalScore - average*3; + + Long max = 0L; + if (diff > 0) max = average + diff; + else max = average; + + if (Math.abs(diff) > 0) continue; + if (max >= p) continue; + if (S == 0) break; + max = average + 1; + S--; + if (max >= p) answer++; + } + System.err.println(""Case #""+String.valueOf(t+1) +"": ""+answer.toString()); + */ + } + + out.close(); + } + +} +" +A21244,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.StringTokenizer; + + +public class Dancing { + + + public static void main(String[] arg) throws Exception { + Dancing pg = new Dancing(); + + pg.go(); + } + + Dancing() + { + + + } + + + private int addThisScore(int totalPoints, int p) + { + int avg = totalPoints / 3; + int low = Math.max(0, avg - 2); + int high = Math.min(10, avg + 2); + int bestResult; + + int S, NS; + S = 0; + NS = 0; + + for(int i = low; i <=high; i++) + { + for(int j = low; j <=high; j++) + { + for(int k = low; k <=high; k++) + { + if((i + j + k) != totalPoints) + continue; + + if(Math.abs(i-j) > 2 || Math.abs(j-k) > 2 || Math.abs(i-k) > 2) + continue; + + bestResult = Math.max(Math.max(i, j),k); + if(bestResult < p) + continue; + + //System.out.println(""Triplet = "" +i +"" ""+j +"" ""+k); + + if(bestResult >= p) + { + //is this a surprising triplet + if(Math.abs(i-j) == 2 || Math.abs(j-k) == 2 || Math.abs(i-k) == 2) + { + S = 2; + } + else + NS = 1; + } + + } + + } + + } + return S + NS; + } + public void go() + { + String line = """"; + try { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + + StringBuilder outString = new StringBuilder(); + StringTokenizer tokens; + + + int caseNo = 0; + + int T = Integer.parseInt(in.readLine().trim()); + int N, S, p, t; + int totalGooglers; + int totalSurprisingTriplets; + while(caseNo++ < T) + { + line = in.readLine().trim(); + totalGooglers = 0; + totalSurprisingTriplets = 0; + tokens = new StringTokenizer(line); + N = Integer.parseInt(tokens.nextToken().trim()); + S = Integer.parseInt(tokens.nextToken().trim()); //noof surprises + p = Integer.parseInt(tokens.nextToken().trim()); + int res; + while(N > 0) + { + t = Integer.parseInt(tokens.nextToken().trim()); + // System.out.println(""**** "" + t +"" ****""); + res = addThisScore(t, p); + + if(res != 0) + { + if(res == 2) + { + totalSurprisingTriplets++; + } + else + totalGooglers++; + } + N--; + } + if(S < totalSurprisingTriplets) + { + totalSurprisingTriplets = S; + } + + totalGooglers += totalSurprisingTriplets; + + outString.append(""Case #"" + caseNo + "": "" + totalGooglers); + + outString.append(""\n""); + } + BufferedWriter pwr = new BufferedWriter(new FileWriter(""output.txt"")); + pwr.write(outString.toString()); + pwr.close(); + in.close(); + } + catch (Exception e) + { + e.printStackTrace(); + System.out.println(""processing : "" + line); + } + } +} +" +A22182,"import java.io.*; +import java.util.*; + +public class DancingWithTheGooglers { + + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static Scanner sc = new Scanner(br); + + public static void main ( String [] args ) throws IOException + { + int N = Integer.parseInt(br.readLine()); + + for(int i = 0;i < N; i++) { + System.out.print(""Case #"" + (i+1) + "": ""); + new DancingWithTheGooglers().cal(); + } + } + + + + private void cal() throws IOException + { + int ret = 0; + + int number = sc.nextInt(); + int[] numberArray = new int[number]; + + int surprising = sc.nextInt(); + int p = sc.nextInt(); + + + int sDeadLine = p*3-4; + int deadLine = p*3-2; + if (p == 0){ + sDeadLine = 100; + deadLine = 0; + } + if (p == 1){ + sDeadLine = 100; + deadLine = 1; + } + + boolean[] okay = new boolean[number]; + boolean[] sOkay = new boolean[number]; + + int okayCounter = 0, sOkayCounter = 0; + + + for(int i = 0; i < number; i++){ + numberArray[i] = sc.nextInt(); + if (numberArray[i] >= deadLine){ + okay[i] = true; okayCounter++; + sOkay[i] = true; sOkayCounter++; + } else if( numberArray[i] >= sDeadLine ){ + okay[i] = false; + sOkay[i] = true; sOkayCounter++; + } else { + okay[i] = false; + sOkay[i] = false; + } + } + + ret = okayCounter; + ret += (sOkayCounter - okayCounter) > surprising? surprising : (sOkayCounter - okayCounter); + + System.out.println(ret); + + + } + +} + + +" +A21371,"import java.util.*; + +public class Dancing { + public static void main( String[] args ) { + Scanner scan = new Scanner(System.in); + int cases = scan.nextInt(); + for (int i = 0; i < cases; i++) { + int count = 0; + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + for( int j = 0; j < n; j++) { + int score = scan.nextInt(); + if( reg(score) >= p ) { + count++; + } + else if( s > 0 && spec(score) >= p ) { + count++; + s--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } + + public static int reg(int n) { + if( n == 0) { + return 0; + } + else if(n == 2 || n == 1) { + return 1; + } + else if( (n%3) == 0) { + return (n/3); + } + else if( (n%3) == 1) { + return (n/3) + 1; + } + else if( (n%3) == 2) { + return (n/3)+1; + } + return 0; + } + + public static int spec(int n) { + if( n== 0 ) { + return 0; + } + else if(n == 1) { + return 1; + } + else if(n == 2) { + return 2; + } + else if( (n%3) == 0) { + return (n/3)+1; + } + else if( (n%3) == 1) { + return (n/3) + 1; + } + else if( (n%3) == 2) { + return (n/3)+2; + } + return 0; + } +} +" +A21208,"public interface Problem { + + void solve(); + + void print(); + + Object getSolution(); + +} +" +A20380,"package gcj_2012; + +/** + * Time: 5:10:03 PM, Apr 13, 2012 + * @author Maya is the best :-) + */ +import java.util.Scanner; +import java.io.PrintWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +public class B { + + static Scanner in; + static String path = ""src/gcj_2012/""; + static String taskname = ""B-large""; + + public static String solve() { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int y = 0; + int t[] = new int[N]; + for (int i =0; i= (3*p - 2) ) + y++; + else if ( t[i] >= (3*p - 4) && S>0 && t[i]!=0) + { + y++; + S--; + } + } + + return """" + y; + } + + public static void main(String[] args) { + PrintWriter pW = null; + + try { + pW = new PrintWriter(new FileOutputStream(path + + taskname + "".out"")); + try { + in = new Scanner(new FileInputStream(path + + taskname + "".in"")); + int T = in.nextInt(); + for (int caseNumber = 1; caseNumber <= T; caseNumber++) { + pW.println(""Case #"" + caseNumber + "": "" + solve()); + } + in.close(); + pW.close(); + } catch (IOException e) { + System.out.println(""Can not find file "" + taskname + "".in""); + } + } catch (IOException e) { + System.out.println(""Open or create exception with "" + + taskname + "".out""); + } + } +} +" +A20541,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Googlers { + public static void main(String[] args) throws IOException { + BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(read.readLine()); + for (int i = 1; i <= t; i++){ + String[] a = read.readLine().split("" ""); + int n = Integer.parseInt(a[0]); + int s = Integer.parseInt(a[1]); + int p = Integer.parseInt(a[2]); + int result = 0; + int temp = 0; + for (int j = 0; j < n; j++){ + temp = Integer.parseInt(a[3+j]); + if (temp == 0 && p > 0); + else if (temp < p); + else if (temp >= 3*p) + result++; + else { + temp = temp - p; + double d = temp/2.0; + double e = p; + if (e - d<= 1.0) { + result++; + } + else if (e - d <= 2.0 && s > 0) { + result++; + s--; + } + } + } + System.out.println(""Case #""+ i + "": ""+ result); + } + } +}" +A22821,"package mgg.utils; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * @author manolo + * @date 13/04/12 + */ +public class FileUtil { + + FileReader reader; + FileWriter writer; + + public FileUtil(String input, String output) { + try { + reader = new FileReader(input); + writer = new FileWriter(output); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public String getLine(){ + try { + + StringBuilder builder = new StringBuilder(); + char c = (char) reader.read(); + while (c != '\n') { + builder.append(c); + //System.out.println(""\t\t\t> char: '"" + c + ""'""); + c = (char) reader.read(); + } ; + + System.out.println(""\t\t\t----------> line: '"" + builder.toString() + ""'""); + + return builder.toString(); + + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } + + public void printLine(int lineNumber, String line){ + try { + writer.write(""Case #"" + lineNumber + "": "" + line + ""\n""); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void closeFiles(){ + try { + reader.close(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} +" +A21297," +import java.io.File; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +/** + * + * @author Igor + */ +public class Dancing { + + public static void main(String[] args) throws Exception { + Scanner in = new Scanner(new File(""input.txt"")); + PrintWriter out = new PrintWriter(""output.txt""); + int testCount = in.nextInt(); + for (int test = 0; test < testCount; test++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] score = new int[n]; + for (int i = 0; i < n; i++) { + score[i] = in.nextInt(); + } + Arrays.sort(score); + int res = 0; + for (int i = n - 1; i >= 0; i--) { + if (3 * p <= score[i]) { + res++; + } else { + if (s > 0) { + if (3 * p - 2 <= score[i]) { + res++; + } else { + if (3 * p - 4 <= score[i] && 3 * p - 4 >= 0) { + res++; + s--; + } + } + } else { + if (3 * p - 2 <= score[i]) { + res++; + } + } + } + } + out.println(""Case #"" + (test + 1) + "": "" + res); + } + out.close(); + } +} +" +A20381," + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class ProbB { + + public static void main(String[] args) throws Exception { + FileReader fr = new FileReader(""B-large.in""); + BufferedReader br = new BufferedReader(fr); + + FileWriter fw = new FileWriter(""outB.txt""); + BufferedWriter bw = new BufferedWriter(fw); + + String a = br.readLine(); + int cases = Integer.parseInt(a); + + int n=0, s=0, p=0, num=0; + + for (int i = 1; i < cases+1; i++) { + String testCase = br.readLine(); + String tokens[] = testCase.split("" ""); + n= Integer.parseInt(tokens[0]); + s = Integer.parseInt(tokens[1]); + p = Integer.parseInt(tokens[2]); + + int count = 0; + for (int j = 3; j < n + 3; j++) { + num = Integer.parseInt(tokens[j]); + if ((num - p) >= 2 * (p - 1) && (num - p) >= 0) { + count++; + } else if ((num - p) < 2 * (p - 1) && (num - p) >= 0) { + if (s != 0 && (num - p) >= 2 * (p - 2)) { + count++; + s--; + } + } + } + String result = ""Case #"" + (i) + "": "" + count; + bw.write(result); + bw.newLine(); + + } + + bw.close(); + fw.close(); + + br.close(); + fr.close(); + } +} +" +A20222,"package codejam2; + +public interface CodejamCase { + public void compute(); + public String getOutput(); +} +" +A22964,"import java.io.*; +import java.math.BigInteger; +import java.util.*; + +public class GB { + String s = null; + String[] sp = null; + + + + public void run() throws Exception{ + + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + + BufferedWriter bw = new BufferedWriter(new FileWriter(""OUTPUT.txt"")); + s = br.readLine(); + int T = Integer.parseInt(s); + + + int t = 1; + while(t <= T){ + s = br.readLine(); + sp = s.split("" ""); + int N = Integer.parseInt(sp[0]); + int S = Integer.parseInt(sp[1]); + int p = Integer.parseInt(sp[2]); + + int[] sco = new int[N]; + for(int i = 0; i < N; i++){ + sco[i] = Integer.parseInt(sp[i+3]); + } + + int ans = 0; + + if(p == 0){ + ans = N; + } + else if(p == 1){ + for(int i = 0; i < sco.length; i++){ + if(sco[i] > 0){ + ans++; + } + } + } + else{ + + int ut = p * 3 - 2; + int bt = p * 3 - 4; + int bn = 0; + for(int i = 0; i < sco.length; i++){ + if(sco[i] >= ut){ + ans++; + } + else if(sco[i] >= bt){ + bn++; + } + } + ans += Math.min(S, bn); + } + + bw.write(""Case #"" + t + "": "" + ans + ""\n""); + + t++; + } + + bw.close(); + } + + + + + + public static void main(String[] args) throws Exception { + GB b = new GB(); + b.run(); + } + +} +" +A21221,"import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.Arrays; + +/** + * Google Code Jam 2012. Qualification. Problem B. + * + * @author Ivan Pryvalov (ivan.pryvalov@gmail.com) + */ +public class GCJ_2012_Q_B implements Runnable{ + + private void solve() throws IOException { + int T = scanner.nextInt(); + for (int test = 0; test < T; test++) { + int N = scanner.nextInt(); + int S = scanner.nextInt();//surp + int p = scanner.nextInt(); + + int[] total = new int[N]; + for (int i = 0; i < N; i++) { + total[i] = scanner.nextInt(); + } + + int answer = 0; + for (int i = 0; i < N; i++) { + int tot = total[i]; + int[] pts = new int[3]; + Arrays.fill(pts, tot / 3); + if (tot%3>0){ + pts[1]++; + } + if (tot%3>1){ + pts[2]++; + } + Arrays.sort(pts); + + if (pts[2]>=p){ + answer++; + }else if (S>0 && pts[1]==p-1){ + //try surprise + pts[2]++; + pts[1]--; + Arrays.sort(pts); + if (pts[0]>=0 && pts[2]<=10 && pts[2] - pts[0] == 2){ + answer++; + S--; + } + } + } + out.println(""Case #""+(test+1)+"": ""+answer); + } + } + + ///////////////////////////////////////////////// + final int BUF_SIZE = 1024 * 1024 * 8;//important to read long-string tokens properly + final int INPUT_BUFFER_SIZE = 1024 * 1024 * 8 ; + final int BUF_SIZE_INPUT = 1024; + + final int BUF_SIZE_OUT = 1024; + + boolean inputFromFile = true; + String filenamePrefix = ""B-large""; + String inSuffix = "".in""; + String outSuffix = "".out""; + + //InputStream bis; + //OutputStream bos; + PrintStream out; + ByteScanner scanner; + ByteWriter writer; + + @Override + public void run() { + try{ + InputStream bis = null; + OutputStream bos = null; + //PrintStream out = null; + if (inputFromFile){ + File baseFile = new File(getClass().getResource(""/"").getFile()); + bis = new BufferedInputStream( + new FileInputStream(new File( + baseFile, filenamePrefix+inSuffix)), + INPUT_BUFFER_SIZE); + bos = new BufferedOutputStream( + new FileOutputStream( + new File(baseFile, filenamePrefix+outSuffix))); + out = new PrintStream(bos); + }else{ + bis = new BufferedInputStream(System.in, INPUT_BUFFER_SIZE); + bos = new BufferedOutputStream(System.out); + out = new PrintStream(bos); + } + scanner = new ByteScanner(bis, BUF_SIZE_INPUT, BUF_SIZE); + writer = new ByteWriter(bos, BUF_SIZE_OUT); + + solve(); + out.flush(); + }catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + public interface Constants{ + final static byte ZERO = '0';//48 or 0x30 + final static byte NINE = '9'; + final static byte SPACEBAR = ' '; //32 or 0x20 + final static byte MINUS = '-'; //45 or 0x2d + + final static char FLOAT_POINT = '.'; + } + + public static class EofException extends IOException{ + } + + public static class ByteWriter implements Constants { + + int bufSize = 1024; + byte[] byteBuf = new byte[bufSize]; + OutputStream os; + + public ByteWriter(OutputStream os, int bufSize){ + this.os = os; + this.bufSize = bufSize; + } + + public void writeInt(int num) throws IOException{ + int byteWriteOffset = byteBuf.length; + if (num==0){ + byteBuf[--byteWriteOffset] = ZERO; + }else{ + int numAbs = Math.abs(num); + while (numAbs>0){ + byteBuf[--byteWriteOffset] = (byte)((numAbs % 10) + ZERO); + numAbs /= 10; + } + if (num<0) + byteBuf[--byteWriteOffset] = MINUS; + } + os.write(byteBuf, byteWriteOffset, byteBuf.length - byteWriteOffset); + } + + /** + * Please ensure ar.length <= byteBuf.length! + * + * @param ar + * @throws IOException + */ + public void writeByteAr(byte[] ar) throws IOException{ + for (int i = 0; i < ar.length; i++) { + byteBuf[i] = ar[i]; + } + os.write(byteBuf,0,ar.length); + } + + public void writeSpaceBar() throws IOException{ + byteBuf[0] = SPACEBAR; + os.write(byteBuf,0,1); + } + + } + + public static class ByteScanner implements Constants{ + + InputStream is; + + public ByteScanner(InputStream is, int bufSizeInput, int bufSize){ + this.is = is; + this.bufSizeInput = bufSizeInput; + this.bufSize = bufSize; + + byteBufInput = new byte[this.bufSizeInput]; + byteBuf = new byte[this.bufSize]; + } + + public ByteScanner(byte[] data){ + byteBufInput = data; + bufSizeInput = data.length; + bufSize = data.length; + byteBuf = new byte[bufSize]; + byteRead = data.length; + bytePos = 0; + } + + private int bufSizeInput; + private int bufSize; + + byte[] byteBufInput; + byte by=-1; + int byteRead=-1; + int bytePos=-1; + + byte[] byteBuf; + int totalBytes; + + boolean eofMet = false; + + private byte nextByte() throws IOException{ + + if (bytePos<0 || bytePos>=byteRead){ + byteRead = is==null? -1: is.read(byteBufInput); + bytePos=0; + if (byteRead<0){ + byteBufInput[bytePos]=-1;//!!! + if (eofMet) + throw new EofException(); + eofMet = true; + } + } + return byteBufInput[bytePos++]; + } + + /** + * Returns next meaningful character as a byte.
+ * + * @return + * @throws IOException + */ + public byte nextChar() throws IOException{ + while ((by=nextByte())<=0x20); + return by; + } + + /** + * Returns next meaningful character OR space as a byte.
+ * + * @return + * @throws IOException + */ + public byte nextCharOrSpacebar() throws IOException{ + while ((by=nextByte())<0x20); + return by; + } + + /** + * Reads line. + * + * @return + * @throws IOException + */ + public String nextLine() throws IOException { + readToken((byte)0x20); + return new String(byteBuf,0,totalBytes); + } + + public byte[] nextLineAsArray() throws IOException { + readToken((byte)0x20); + byte[] out = new byte[totalBytes]; + System.arraycopy(byteBuf, 0, out, 0, totalBytes); + return out; + } + + + /** + * Reads token. Spacebar is separator char. + * + * @return + * @throws IOException + */ + public String nextToken() throws IOException { + readToken((byte)0x21); + return new String(byteBuf,0,totalBytes); + } + + /** + * Spacebar is included as separator char + * + * @throws IOException + */ + private void readToken() throws IOException { + readToken((byte)0x21); + } + + private void readToken(byte acceptFrom) throws IOException { + totalBytes = 0; + while ((by=nextByte())=acceptFrom){ + byteBuf[totalBytes++] = by; + } + } + + public int nextInt() throws IOException{ + readToken(); + int num=0, i=0; + boolean sign=false; + if (byteBuf[i]==MINUS){ + sign = true; + i++; + } + for (; i { + private TestCaseReader caseReader; + private final PrintWriter outputWriter; + + public Transformation(TestCaseReader caseReader, PrintWriter outputWriter) { + this.caseReader = caseReader; + this.outputWriter = outputWriter; + } + + public void transformAll() throws Exception { + T testCase = caseReader.nextCase(); + while (testCase != null) { + outputWriter.println(transform(testCase)); + testCase = caseReader.nextCase(); + }; + + } + + protected abstract String transform(T testCase); +} +" +A21652,"package de.johanneslauber.codejam.model; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + + +/** + * + * @author Johannes Lauber - joh.lauber@googlemail.com + * + */ +public abstract class BaseProblem implements IProblem { + + protected List listOfCases; + private BufferedWriter out; + private int countOutputLines = 0; + + public BaseProblem() { + try { + out = new BufferedWriter(new FileWriter(""output/output.out"")); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } + + @Override + public void setListOfCases(List listOfCases) { + this.listOfCases = listOfCases; + } + + /** + * + * @author Johannes Lauber - joh.lauber@googlemail.com + * @param stringArray + * @return + */ + protected int[] toIntArray(String[] stringArray) { + int[] intArray = new int[stringArray.length]; + + for (int i = 0; i < stringArray.length; i++) { + intArray[i] = Integer.valueOf(stringArray[i]); + } + return intArray; + } + + /** + * + * @author Johannes Lauber - joh.lauber@googlemail.com + * @param line + */ + protected void writeToFile(String line) { + countOutputLines++; + try { + out.write(""Case #"" + countOutputLines + "": "" + line); + out.newLine(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * + * @author Johannes Lauber - joh.lauber@googlemail.com + */ + protected void closeWriter() { + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}" +A20735," +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Reader; + +public class Processor { + + public void process(TestCaseFactory factory, String filenameIn, + String filenameOut) throws IOException, MalformedInputFileException { + System.out.println(""Started!""); + + final Reader in = new FileReader(filenameIn); + final BufferedReader br = new BufferedReader(in); + + final PrintWriter out = new PrintWriter(new File(filenameOut)); + + final String str1 = br.readLine(); + final int ncases = Integer.parseInt(str1); + + for (int i = 0; i < ncases; i++) { + final TestCase item = factory.getInstance(i); + item.readInput(br); + item.solve(); + item.writeOutput(out); + } + + in.close(); + out.close(); + + System.out.println(""Finished!""); + } +}" +A20946,"package org.moriraaca.codejam; + +public enum DebugOutputLevel { + SOLUTION, IMPORTANT, ALL; +} +" +A20780,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class DancingWithTheGoogler { + + public static void main(String[] args) { + + try { + + FileInputStream fstream = new FileInputStream(args[0]); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + int count = 0; + int noCases = 0; + while ((strLine = br.readLine()) != null) { + if (count > noCases) + break; + + if (count == 0) { + noCases = Integer.valueOf(strLine); + } else { + compute(count, strLine); + } + count++; + } + + in.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } + + private static void compute(int caseNo, String str) { + + String[] tokens = str.split("" ""); + int N = Integer.valueOf(tokens[0]); + int S = Integer.valueOf(tokens[1]); + int P = Integer.valueOf(tokens[2]); + + int count = 0; + + for (int i = 3; i < N + 3; i++) { + int candidate = Integer.valueOf(tokens[i]); + int top = getCommonDigit(candidate, false); + if (top >= P) { + count++; + } else { + if (S > 0) { + if (getCommonDigit(candidate, true) >= P) { + count++; + S--; + } + } + } + } + + System.out.println(String.format(""Case #%s: %s"", caseNo, count)); + + } + + private static int getCommonDigit(int no, boolean special) { + + if (no == 0) + return 0; + int initialDigits = no / 3; + int toShare = no % 3; + + if (special == false) { + if (toShare == 0) + return initialDigits; + else + return initialDigits + 1; + } else { + if (toShare == 2) + return initialDigits + 2; + else { + return initialDigits + 1; + } + } + + } +} +" +A20006,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class DancingWithGooglers { + + public int max(int s, int q, int[] score){ + int pass = 0, fail = 0, pos = 0; + for(int sc : score){ + if(sc == 0){ + if(q == 0) + pass++; + else fail++; + } + else if(sc == 1){ + if(q <= 1) + pass++; + else fail++; + } + else if( (sc + 2) / 3 >= q) + pass++; + else if( (sc +1) / 3 +1 < q) + fail++; + else + pos++; + } + + return pass + Math.min(pos, s); + + } + + + public static void main(String[] args) throws FileNotFoundException { + DancingWithGooglers d = new DancingWithGooglers(); +// int[] c1 = {15,13,11}; +// System.out.println(d.max(1,5,c1)); +// +// int[] c2 = {23,22,21}; +// System.out.println(d.max(0,8,c2)); +// +// int[] c3 = {8, 0}; +// System.out.println(d.max(1,1,c3)); +// +// int[] c4 = {29,20, 8, 18, 18, 21}; +// System.out.println(d.max(2,8,c4)); + + File f = new File(args[0]); + Scanner sc = new Scanner(f); + int l = Integer.parseInt(sc.nextLine()); + for(int i = 1; i <= l ;i++){ + String[] line = sc.nextLine().split("" ""); + int[] c = new int[Integer.parseInt(line[0])]; + int s = Integer.parseInt(line[1]); + int q = Integer.parseInt(line[2]); + for(int j = 0; j < c.length; j++) + c[j] = Integer.parseInt(line[j+3]); + System.out.printf(""Case #%d: %s\n"", i, d.max(s, q, c)); + } + } + +} +" +A20193,"package com.bakes; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; + +public class C { + public static void main(String[] args) { + C park = new C(); + park.calculate(); + + } + + private long lcm(long a, long b) + { + return (a*b)/gcd(a,b); + } + + public static long gcd(long i1, long i2) { + // using Euclid's algorithm + long a=i1, b=i2, temp; + while (b!=0) { + temp=b; + b=a%temp; + a=temp; + } + return a; + } + + private void calculate() { + BufferedReader in; + String strLine1; + String strLine2; + String strLine3; + PrintWriter out; + try { + in = new BufferedReader(new FileReader(""B-large.in"")); + in.readLine(); + FileWriter outFile = new FileWriter(""output.txt""); + out = new PrintWriter(outFile); + int n = 0; + + while ((strLine1 = in.readLine()) != null) { + n++; + + String[] data = strLine1.split("" ""); + + int N = Integer.parseInt(data[0]); + int s = Integer.parseInt(data[1]); + int p = Integer.parseInt(data[2]); + int count = 0; + for (int i = 3; i < 3 + N; i++) + { + int d = Integer.parseInt(data[i]); + if ((d - 3*p) >= -2) + { + count++; + } + else if ((d-3*p) >= -4 && s >0 && d >=2) + { + count++; + s--; + } + } + String result = ""Case #""+n+"": ""+count; + out.println(result); + System.out.println(result); + } + out.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + +} +" +A21902,"import java.io.*; + +public class dancing { + + static int N; + static int S; + static int p; + static int[] t; + + public static boolean normal(int tot){ + int max = tot%3==0?tot/3:tot/3+1; + return max>=p; + } + + public static boolean surprising(int tot){ + int max = tot==0?0:(tot+1)/3+1; + + return max>=p; + } + + + public static int solve(){ + int DB=0; + int SDB = S; + for(int i=0; i 0 && surprising(t[i])){ + DB++; SDB--; + } + } + + return DB; + } + + public static void main (String args[]) throws IOException{ + + + BufferedReader be = new BufferedReader(new FileReader(""B-large.in"")); + int T = Integer.parseInt(be.readLine()); + for(int i=1; i<=T; i++){ + String s = be.readLine(); + N = Integer.parseInt(s.split("" "")[0]); + S = Integer.parseInt(s.split("" "")[1]); + p = Integer.parseInt(s.split("" "")[2]); + t = new int[N]; + for(int j = 0; j < N; j++) + t[j] = Integer.parseInt(s.split("" "")[j+3]); + System.out.println(""Case #""+i+"": ""+solve()); + } + be.close(); + } +} + +" +A20178,"package codejam; + +import codejam.fileHandler; + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + fileHandler file = new fileHandler(""DancingWiththeGooglersLarge.in"", + ""DancingWiththeGooglersLargeout.in""); + int noOfCases = file.readCase(); + for (int i = 1; i <= noOfCases; i++) { + int numberArray[] = file.readIntegers(); + int N = numberArray[0]; + int s = numberArray[1]; + int p = numberArray[2]; + int upperLimit = 3 * p - 2; + int lowerLimit = 3 * p - 4; + if(p==0){ + upperLimit = lowerLimit = 0; + } + if(p == 1){ + upperLimit = lowerLimit = 1; + } + int count = 0; + for (int j = 3; j < numberArray.length; j++) { + if (s == 0) { + if (numberArray[j] >= upperLimit) { + count++; + } + } + else{ + if(numberArray[j] >= lowerLimit){ + if(numberArray[j] == lowerLimit){ + s--; + } + else if(numberArray[j] == (lowerLimit + 1)){ + s--; + } + count++; + } + } + } + String print = ""Case #"" + i + "": "" + count + ""\n""; + file.writeToOutput(print); + } + System.out.println(""Done""); + } + +} +" +A22581,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.HashMap; + + +public class Googlers { + + private static int testcases = 0; + + public static void main(String[] args) + { + String DataLine = """"; + int line = 0; + PrintWriter out; + + try + { + File inFile = new File(""./config/B-small-attempt1.txt""); + BufferedReader br = new BufferedReader(new InputStreamReader( + new FileInputStream(inFile))); + + out = new PrintWriter(new BufferedWriter(new FileWriter(""./config/out3"" + "".txt""))); + + while((DataLine = br.readLine()) != null) + { + + if(line == 0) + { + testcases = Integer.parseInt(DataLine.trim()); + line++; + } + else + { + if(line<=testcases) + { + String[] datas = DataLine.split("" ""); + + int N = Integer.parseInt(datas[0]); + int S = Integer.parseInt(datas[1]); + int P = Integer.parseInt(datas[2]); + int[] pnts = new int[N]; + for(int i=0;i 1) + { + + if(((P-2)*3)+2 <= check ) + { + resCount++; + + if(((P-2)*3)+2 == check || ((P-2)*3)+2 == check-1) + temp++; + } + } + else + { + if(((P-1)*3)+1 <= check ) + resCount++; + } + } + return resCount; + } +} +" +A22437,"import java.io.*; +import java.util.*; +import java.lang.Math.*; +public class gcj2 +{ + public static void main(String args[])throws Exception + { + //Scanner in=new Scanner(System.in); + //BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + //BufferedReader br = new BufferedReader(new FileReader(""gcj2.in"")); + //PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(""gcj2.out""))); + //PrintWriter pw = new PrintWriter(System.out); + BufferedReader br = new BufferedReader(new FileReader(""C:\\Users\\rahul\\Desktop\\gcj2.in"")); + PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(""C:\\Users\\rahul\\Desktop\\gcj2.out""))); + StringTokenizer st; + int a[]={0,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,10,10}; + int c[]={-1,-1,2,5,8,11,14,17,20,23,26}; + int t=Integer.parseInt(br.readLine()); + int ctr=0; + while(t>0) + { + t--; + ctr++; + int need=0,best=0; + st=new StringTokenizer(br.readLine()); + int n=Integer.parseInt(st.nextToken()); + int s=Integer.parseInt(st.nextToken()); + int p=Integer.parseInt(st.nextToken()); + + for(int i=0;i=p) + { + if(p>=2 && (val==c[p] || val==c[p]+1)) + { + need++; + } + + else best++; + } + } + best=best + Math.min(s,need); + pw.println(""Case #"" + ctr + "": "" +best); + } + + pw.flush(); + pw.close(); + } +}" +A22367,"package com.blah; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.util.TreeMap; +import java.util.TreeSet; + +class Triplet { + int numbers[] = new int[3]; + + public Triplet(int number) { + numbers[0] = numbers[1] = numbers[2] = number; + // TODO Auto-generated constructor stub + } + + boolean hasBestResultOrMore(int p){ + return numbers[0]>=p || numbers[1]>=p || numbers[2]>=p; + } + @Override + public String toString() { + // TODO Auto-generated method stub + return ""["" + numbers[0] +"","" + numbers[1] +"","" + numbers[2] +""]""; + } +} + + +class ComponentNumber { + + @Override + public String toString() { + // TODO Auto-generated method stub + return ""Number ""+total+"" : ""+primary+"",""+secondary+"" (*)"" ; + } + int total; + boolean marked = false; + Triplet primary,secondary = null;//secondary is a surprising result always + + boolean hasBestResultOrMore(int p){ + return primary.hasBestResultOrMore(p); + } + + boolean hasSurprisingBestResultOrMore(int p){ + return secondary!=null && secondary.hasBestResultOrMore(p); + } + + public ComponentNumber(int totalPoints) { + total = totalPoints; + int base = totalPoints/3; + primary = new Triplet(base); + if(totalPoints==0){ + //do nothing, 0 = 0 + 0 + 0 + } + else if(totalPoints==1){ + primary.numbers[2] = 1; + //1 = 0 + 0 + 1 or any other permutation + } + else { + switch(totalPoints%3){ + case 2: + primary.numbers[1] = primary.numbers[2] = base + 1; + secondary = new Triplet(base); + secondary.numbers[2] = base + 2; + break; + case 1: + primary.numbers[2] = base + 1; + secondary = new Triplet(base); + secondary.numbers[0] = base - 1; + secondary.numbers[1] = secondary.numbers[2] = base + 1; + break; + case 0: + secondary = new Triplet(base); + secondary.numbers[0] = base - 1; + secondary.numbers[2] = base + 1; + break; + } + } + } + +} + +class Case { + int googlers; + int surprising; + int bestResult; + ArrayList results; + int components[][] = new int[3][2]; + + Case(String g,String s,String p){ + googlers = Integer.parseInt(g); + surprising = Integer.parseInt(s); + bestResult = Integer.parseInt(p); + results = new ArrayList(); + } + + void addResult(String result){ + results.add(Integer.parseInt(result)); + } +} + +public class MainProblem3 { + public static void main(String[] args) { + + ArrayList cases = new ArrayList(); + try { + System.setOut(new PrintStream(""data.out"")); + BufferedReader br = new BufferedReader(new FileReader(""data.in"")); + int numCases = Integer.parseInt(br.readLine()); + StringTokenizer st; + Case aCase; + for (int i = 0; i < numCases; i++) { + st = new StringTokenizer(br.readLine()); + aCase = new Case(st.nextToken(), st.nextToken(), st.nextToken()); + for (int j = 0; j < aCase.googlers; j++) { + aCase.addResult(st.nextToken()); + } + cases.add(aCase); + } + resolver(cases); + + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + + + + + } + + private static void resolver(ArrayList cases) { + Case aCase; + for (int j = 0; j < cases.size(); j++) { + aCase = cases.get(j); + int p = aCase.bestResult; + int s = aCase.surprising; + ArrayList theBest = new ArrayList(); + ArrayList theSurprises = new ArrayList(); + ComponentNumber aCandidate; + for (int k = 0; k < aCase.googlers; k++) { + aCandidate = new ComponentNumber(aCase.results.get(k)); + //System.out.println(aCandidate); + if(aCandidate.hasBestResultOrMore(p)){ + theBest.add(aCandidate); + } + else if(aCandidate.hasSurprisingBestResultOrMore(p)){ + theSurprises.add(aCandidate); + } + } + int totalBest = theBest.size() + Math.min(theSurprises.size(), s); + System.out.println(""Case #""+(j+1)+"": ""+totalBest); + } + } + +}" +A20592,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package a2012; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Scanner; +/** + * + * @author G + */ +public class B { + static File home=new File(""F:/Documents/Downloads/""); + public static void main(String...args)throws Exception{ + Scanner sc = new Scanner(new File(home,""B-large.in"")); + new File(home,""B"").mkdir(); + System.setOut(new PrintStream(new File(""b.out""))); + final int casos=sc.nextInt(); + for(int caso=1;caso<=casos;caso++){ + int N=sc.nextInt(); + int S=sc.nextInt(); + int p =sc.nextInt(); + int m=0; + int[] ns=new int[40]; + for(int e=0;e0;m++,S--){ + if(p>2&&p+p+p-4>=0&&ns[p+p+p-4]>0)ns[p + p + p - 4]--; + else if(p>1&&p+p+p-3>=0&&ns[p + p + p - 3] > 0)ns[p + p + p - 3]--; + else{ + break; + } + } + } + for(int e=Math.max(p + p + p - 2,0);e surprising; + HashMap notsurprising; + List surp,nonsurp,both,potnsurp; + + private class triplet { + int a,b,c; + + triplet(int a, int b, int c) { + this.a = a; + this.b = b; + this.c = c; + } + + public boolean surpising() { + if(Math.abs(a - b) ==2 || Math.abs(a - c) == 2 || Math.abs(b - c) == 2) + return true; + return false; + } + + public boolean best(int p) { + if( a >= p || b >= p || c >= p) + return true; + return false; + } + + } + + public Solver(InputReader in, PrintWriter out) { + this.in = in; + this.out = out; + surprising = null; + notsurprising = null; + surp = null; + nonsurp = null; + both = null; + potnsurp = null; + } + + public void preprocess() { + if(surprising == null || notsurprising == null) { + surprising = new HashMap(); + notsurprising = new HashMap(); + surp = new ArrayList(); + nonsurp = new ArrayList(); + both = new ArrayList(); + potnsurp = new ArrayList(); + generateTriplets(); + } + } + + public void solve() { + preprocess(); + int numTc = in.nextInt(); + int numGoog,numSurp,bestScore,soln = 0,score,numberOfSurp; + triplet temp; + + for ( int i = 0; i < numTc; i++ ) { + numGoog = in.nextInt(); + numSurp = in.nextInt(); + bestScore = in.nextInt(); + surp.clear(); + nonsurp.clear(); + both.clear(); + numberOfSurp = 0; + for ( int j = 0; j < numGoog; j++ ) { + score = in.nextInt(); + if(surprising.containsKey(score) && notsurprising.containsKey(score)) { + temp = surprising.get(score); + if(temp.best(bestScore)) { + temp = notsurprising.get(score); + if(temp.best(bestScore)) + both.add(j); + else + surp.add(j); + } + else { + temp = notsurprising.get(score); + if(temp.best(bestScore)) + nonsurp.add(j); + else + numberOfSurp++; + } + } + else { + if(notsurprising.containsKey(score)) { + temp = notsurprising.get(score); + if(temp.best(bestScore)) + nonsurp.add(j); + } + } + } + if(numSurp <= numberOfSurp + surp.size() + both.size()) + soln = countMax(numSurp,numberOfSurp); + else + soln = 0; + out.println(""Case #""+(i+1)+"": ""+soln); + } + } + + public int countMax(int numSurp, int numberOfSurp) { + int count = both.size() + nonsurp.size(); + + if(numSurp < surp.size()) + return count + numSurp; + + return count + surp.size(); + } + + public void generateTriplets() { + int sum = 0; + for ( int i = 0; i < 11; i++ ) { + for ( int j = 0; j < 11; j++ ) { + if(Math.abs(j - i) > 2) + continue; + for ( int k = 0; k < 11; k++ ) { + if(Math.abs(k-j) > 2 || Math.abs(k-i) > 2) + continue; + sum = i+j+k; + triplet temp = new triplet(i,j,k); + if(temp.surpising()) + surprising.put(sum, temp); + else + notsurprising.put(sum, temp); + } + } + } + } + + public int bruteforce() { + + return 0; + } + + } +} + +" +A22622,"import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class dancing { + + static int max(int a){ + if (a % 3 == 0) + return a/3; + return a/3 + 1; + } + static int maxs(int a){ + if (a > 1 && a % 3 != 1) + return max(a)+1; + else return max(a); + } + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + FileInputStream file = new FileInputStream(args[0]); + //DataInputStream in = new DataInputStream(file); + Scanner ins = new Scanner(file); + BufferedWriter out = new BufferedWriter(new FileWriter(args[1])); + int n = ins.nextInt(); + for (int i = 0; i < n; i++){ + int answ = 0; + int t,s,p; + t = ins.nextInt(); s = ins.nextInt(); p = ins.nextInt(); + for (int j = 0; j < t; j++){ + int tmp = ins.nextInt(); + if(max(tmp) >= p){ + answ++; + }else if(maxs(tmp) >= p && s > 0){ + s--; answ++; + } + } + out.write(""Case #""+ (i+1) +"": ""+answ); + out.newLine(); + } + ins.close(); + out.close(); + file.close(); + + } + +} +" +A20792,"import IO.InputDelegate; +import IO.OutputDelegate; + + +public class Main { + InputDelegate reader; + OutputDelegate writer; + + public static void main(String[] args) { + new Main().init(); + } + + public Main() { + this.reader = new InputDelegate(""input.in""); + this.writer = new OutputDelegate(""output.out""); + } + + public void init() { + String readedLine = null; + + int numLines = Integer.parseInt(this.reader.readLine()); + readedLine = this.reader.readLine(); + + // Read all lines + for (int i = 0; i < numLines; i++, readedLine = this.reader.readLine()) { + String[] splittedLine = readedLine.split("" "", 4); + + int numSurprising = Integer.parseInt(splittedLine[1]); + int controlValue = Integer.parseInt(splittedLine[2]); + + String valuesStr = splittedLine[3]; + String[] splittedValues = valuesStr.split("" ""); + + int foundedDancer = 0; + for (int j = 0; j < splittedValues.length; j++) { + int value = Integer.parseInt(splittedValues[j]); + + if (value >= controlValue * 3 - 2) { // Not surprising + foundedDancer++; + } else if (value >= controlValue && value >= controlValue * 3 - 4 && numSurprising > 0) { // Surprising + foundedDancer++; + numSurprising--; + } + } + + this.writer.writeLine(String.format(""Case #%d: %d"", i + 1, foundedDancer)); + } + + this.reader.close(); + this.writer.flush(); + this.writer.close(); + } +} +" +A22635,"import java.io.File; +import java.io.PrintWriter; +import java.util.Locale; +import java.util.Scanner; + +public class B { + + final static String PREFIX = ""C:\\codejam\\B""; + // final static String FILE_NAME = PREFIX + ""-test""; +// final static String FILE_NAME = PREFIX + ""-small-attempt0""; + final static String FILE_NAME = PREFIX + ""-large""; + + private Scanner in; + private PrintWriter out; + + public static void main(String[] args) throws Exception { + Locale.setDefault(Locale.US); + new B().solveAll(); + } + + private void solveAll() throws Exception { + in = new Scanner(new File(FILE_NAME + "".in"")); + out = new PrintWriter(new File(FILE_NAME + "".out"")); + int tcn = in.nextInt(); + for (int tc = 1; tc <= tcn; tc++) { + solve(tc); + } + out.close(); + } + + private void solve(int tc) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = in.nextInt(); + } + + int res = 0; + for (int i = 0; i < n; i++) { + int max = t[i] / 3; + int x = t[i] - max * 3; + if (x > 0) { + max++; + } + if (max >= p) { + res++; + } else if (s > 0) { + if (x == 2 || (x == 0 && t[i] != 0)) { + max++; + } + if (max >= p) { + res++; + s--; + } + } + } + out.format(""Case #%d: %s\n"", tc, res); + System.out.format(""Case #%d: %s\n"", tc, res); + } +} +" +A22294,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.util.LinkedList; +import java.util.Scanner; + +public class DancingWiththeGooglers { + + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(""B-large.in"")); +// Scanner in = new Scanner(System.in); + BufferedWriter out = null; + try { + FileWriter fstream = new FileWriter(""out.txt""); + out = new BufferedWriter(fstream); + int cases = in.nextInt(); + int N; + int S; + int P; + LinkedList googlers; + for (int i = 0; i < (cases); i++) { + int result = 0; + int surprising = 0; + int canBe = 0; + N = in.nextInt(); + S = in.nextInt(); + P = in.nextInt(); + googlers = new LinkedList(); + for (int j = 0; j < N; j++) { + int t = in.nextInt(); + // if (t != 0) + googlers.add(t); + } + for (int j = 0; j < googlers.size(); j++) { + int temp = googlers.get(j) - (3 * P); + if (temp == -3 || temp == -4) { + if (googlers.get(j) != 0) { + surprising++; + } + } else if (temp >= -2) { + result++; + if (googlers.get(j) != 29 || googlers.get(j) != 30) { + canBe++; + } + } + } + int answer = 0; + int tempo = 0; + if (S <= surprising) { + tempo = S; + } else { + tempo = surprising; + // if(tempo<=canBe) + // answer=result; + // tempo = Math.abs(tempo - canBe); + } +// System.out.println(result + "" "" + tempo); + answer = result + tempo; + out.write(""Case #"" + (i + 1) + "": "" + answer + ""\n""); + System.out.println(""Case #"" + (i + 1) + "": "" + answer); + } + out.close(); + } catch (Exception e) {// Catch exception if any + } + + } +} +" +A23002,"import java.io.*; +import java.util.*; + + + + + +public class CodeJamProblem implements Runnable { + + + public int getRisultato(int n, int s, int p, int[] points) { + // n=6 s=2 p=8 29 20 8 18 18 21 + int vincitori = 0; + int suprise = s; + //Arrays.sort(points); + System.out.println(""CASE:""+Arrays.toString(points)); + for(int i =0;i=p) + { + vincitori++; + } + else + { + // check for surprise case: + if (suprise > 0 && base > 0 &&base + 1 >= p) + { + vincitori++; + suprise--; + } + } + break; + case 1: + if (base >= p || base + 1 >= p) + { + vincitori++; + } + else + { + // surprise case: + if (suprise > 0 && base + 1 >= p) + { + vincitori++; + suprise--; + } + } + break; + case 2: + if (base + 1 >= p || base >= p) + { + vincitori++; + } + else + { + if (suprise > 0 && base + 2 >= p) + { + System.out.println(""Winner""); + vincitori++; + suprise--; + } + } + + break; + } + } + System.out.println(""Winner[""+p+"",""+s+""]:""+ vincitori); + return vincitori; + } + + + public void solve() throws IOException { + String test = ""small""; + //String test = ""large""; + Scanner in = new Scanner(new File(""B-large.in"")).useDelimiter(System.getProperty(""line.separator"")); + PrintWriter out = new PrintWriter(new File(""B-large.out"")); + + int lineNum = 0; + int testNum = 0; + int totalTests = 0; + + /* + 3 1 5 15 13 11 + 3 0 8 23 22 21 + 2 1 1 8 0 + 6 2 8 29 20 8 18 18 21 + */ + + int n = 0; + int s = 0; + int p = 0; + int[] points = new int[1]; + /* + String[] x = (""3 1 5 15 13 11"").split("" ""); + for(int i = 0;i2) { + if(i==3) points = new int[n]; + points[i-3] = Integer.parseInt(x[i]); + } + } + int risultato = getRisultato(n,s,p,points); + */ + + while (in.hasNext()) { + String currentLine = in.next(); + if(lineNum ==0 ) { + //Do Nothing! + totalTests = Integer.parseInt(currentLine); + lineNum++; + continue; + } + if(lineNum>0) { + String[] x = currentLine.split("" ""); + for(int i = 0;i2) { + if(i==3) points = new int[n]; + points[i-3] = Integer.parseInt(x[i]); + } + } + + int risultato = getRisultato(n,s,p,points); + System.out.println(""Case #""+(testNum+1)+"": ""+ risultato); + out.println(""Case #""+(testNum+1)+"": ""+ risultato); + testNum++; + } + lineNum++; + } + in.close(); + out.close(); + + + } + public void run() { + try { + solve(); + } catch (IOException e) { + System.exit(1); + } + } + + public static void main(String[] s) { + new Thread(new CodeJamProblem()).start(); + } + + + +} +" +A21530,"package gcj2012.qual; + +import java.io.*; +import java.util.*; +import java.math.*; + +import static java.lang.Math.*; +import static java.lang.Character.*; +import static java.util.Arrays.*; +import static java.util.Collections.*; +import static java.math.BigInteger.*; + +public class B { + static final char PROB = B.class.getSimpleName().charAt(0); + static final boolean PRAC = false; + + static final double EPS = 1e-12; + static final int INF = 1 << 20; + static final int[] di = { -1, 0, 0, 1 }; + static final int[] dj = { 0, -1, 1, 0 }; + static Scanner sc = new Scanner(System.in); + + final int N, S, p, t[]; + + public B() { + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + t = new int[N]; + for (int i = 0; i < N; i++) + t[i] = sc.nextInt(); + } + + public String solve() { + int s = 0; + int n = 0; + for (final int tt : t) + if (tt + 2 >= p * 3) + n++; + else if (tt > 0 && tt + 4 >= p * 3) + s++; + return """" + (n + min(s, S)); + } + + public static void main(String... args) { + large(); + int T = Integer.parseInt(sc.nextLine()); + for (int t = 1; t <= T; t++) { + System.err.printf(""Case #%s%n"", t); + System.out.printf(""Case #%s: %s%n"", t, new B().solve()); + } + System.err.println(""done.""); + } + + public static void small() { + String in = PROB + ""-small"" + (PRAC ? ""-practice"" : ""-attempt"" + 0) + "".in""; + String out = PROB + ""-small.out""; + if (!PRAC) + for (int i = 1; new File(PROB + ""-small"" + ""-attempt"" + i + "".in"").exists(); i++) + in = PROB + ""-small"" + ""-attempt"" + i + "".in""; + try { + System.setIn(new BufferedInputStream(new FileInputStream(in))); + System.setOut(new PrintStream(out)); + } catch (Exception e) { + e.printStackTrace(); + System.exit(0); + } + sc = new Scanner(System.in); + } + + public static void large() { + String in = PROB + ""-large"" + (PRAC ? ""-practice"" : """") + "".in""; + String out = PROB + ""-large.out""; + try { + System.setIn(new BufferedInputStream(new FileInputStream(in))); + System.setOut(new PrintStream(out)); + } catch (Exception e) { + e.printStackTrace(); + System.exit(0); + } + sc = new Scanner(System.in); + } + + private static void debug(Object... os) { + System.err.println(deepToString(os)); + } +}" +A21713,"import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + + +public class B { + + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(""B-large.in"")); + FileWriter f = new FileWriter(""B.out""); + int N,S,p; + int googler; + int kol,ost; + int br; + int T=sc.nextInt(); + + for(int t=1;t<=T;t++){ + br=0; + sc.nextLine(); + N=sc.nextInt(); + S=sc.nextInt(); + p=sc.nextInt(); + for(int i=0;i=p){ + br++; + continue; + } + + if(ost==0){ + if(kol+1>=p&&S>0&&kol-1>=0){ + S--; + br++; + + } + continue; + } + + if(ost==1){ + if(kol+1>=p){ + br++; + + } + continue; + } + //ost==2 + if(kol+1>=p){ + br++; + continue; + } + if(kol+2>=p&&S>0){ + S--; + br++; + } + } + f.write(""Case #""+t+"": ""+br+""\n""); + } + + f.close(); + } + +} +" +A20271,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class B { + static int[][] dp; + static int[] sum; + static int p; + + public static int abs(int a) { + return (a < 0) ? -a : a; + } + + public static int go(int i, int j) { + if (j < 0) + return -1000; + if (i == sum.length) { + if (j != 0) + return -1000; + else + return 0; + } + + else if (dp[i][j] != -1) + return dp[i][j]; + else { + int max = 0; + for (int a = 0; a <= 10 && a <= sum[i]; a++) + for (int b = a; b <= a + 2 && b <= 10 && a + b <= sum[i]; b++) + for (int c = a; c <= a + 2 && c <= 10 + && a + b + c <= sum[i]; c++) { + if (a + b + c == sum[i]) { + int cool = 0; + int awesome = 0; + if (b - a == 2 || c - a == 2) + cool = 1; + if (a >= p || b >= p || c >= p) + awesome = 1; + max = Math.max(max, awesome + go(i + 1, j - cool)); + } + } + return dp[i][j] = max; + } + } + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new InputStreamReader( + new FileInputStream(""B.in""))); + PrintWriter out = new PrintWriter(""B.out""); + int tc = Integer.parseInt(in.readLine()); + for (int cc = 1; cc <= tc; cc++) { + StringTokenizer strtok = new StringTokenizer(in.readLine(), "" ""); + int n = Integer.parseInt(strtok.nextToken()); + int s = Integer.parseInt(strtok.nextToken()); + p = Integer.parseInt(strtok.nextToken()); + dp = new int[n][s + 1]; + for (int[] a : dp) + Arrays.fill(a, -1); + sum = new int[n]; + for (int i = 0; i < n; i++) + sum[i] = Integer.parseInt(strtok.nextToken()); + out.printf(""Case #%d: %d\n"", cc, go(0, s)); + } + out.close(); + in.close(); + } +} +" +A22349,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; + + +public final class Googlers { + + /** + * @param args + */ + public static void main(String[] args) { +// * /3 %3 +// 0 0 000 0 0 +// 1 1 100 0 1 +// 2 1 2 110 200* 0 2 +// 3 1 2 111 210* 1 0 +// 4 2 2 112 022* 1 1 +// 5 2 3 122 113* 1 2 +// 6 2 3 222 123* 2 0 +// 7 3 3 223 133* 2 1 +// 8 3 4 233 224* 2 2 +// 9 3 4 333 234* 3 0 +// ... +// 28 10 10 9 9 10 9 1 +// 29 10 10 9 10 10 9 2 +// 30 10 10 10 0 + // max = x/3 + x%3>=1 + // *max = x/3 + x%3=2 + +//prepare table + int[][] max = new int[31][2]; + max[0][0] = 0; + max[0][1] = 0; + for (int i = 1; i <=27; i++) { + int quotient = i / 3; + int reminder = i % 3; + max[i][0] = quotient + (reminder>=1?1:0); + max[i][1] = quotient + (reminder==2?2:1); + } + max[28][0] = 10; + max[28][1] = 10; + max[29][0] = 10; + max[29][1] = 10; + max[30][0] = 10; + max[30][1] = 10; + BufferedReader br = null; + BufferedWriter bw = null; + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream(""test.txt""))); + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""solution.txt""))); + int count = 1; + int cases = Integer.valueOf(br.readLine()); + String input; + while (((input = br.readLine()) != null) && (count <= cases)) { + String output = ""Case #""+(count++)+"": ""+process(input, max); + System.out.println(output); + bw.write(output); + bw.newLine(); + } + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } finally { + if (br!=null) try { br.close(); } catch(IOException e) {} + if (bw!=null) try { + bw.flush(); + bw.close(); + } catch(IOException e) {} + } + + } + + private static final int process(String input, int[][] max) { + String[] s = input.split("" ""); + int N = Integer.valueOf(s[0]); + int S = Integer.valueOf(s[1]); + int p = Integer.valueOf(s[2]); + //int t[] = new int[N]; + int count = 0; + for (int i = 0; i < N; i++) { + int t = Integer.valueOf(s[i+3]); + if (max[t][0] >= p) count++; + else if (S > 0 && max[t][1] >= p) { + count++; + S--; + } + } + return count; + } + +} +" +A20992,"package fixjava; + +import java.util.Iterator; + +/** + * Create an iterator that keeps track of the current index into the Iterable. + * + * Usage: + * + * + + public static void main(String[] args) { + + // Iterate over a list: + ArrayList list = new ArrayList(); + list.add(""apple""); + list.add(""banana""); + list.add(""pear""); + for (IndexedItem it : IndexedItem.iterate(list)) + System.out.println(it.getIndex() + "": "" + it.getItem()); + + // Iterate over an array: + String[] arr = new String[] {""a"", ""b"", ""c""}; + for (IndexedItem it : IndexedItem.iterate(arr)) + System.out.println(it.getIndex() + "": "" + it.getItem()); + } + + + * + * @author (c) Luke Hutchison 2010. Covered under the BSD license. + * + * @param + * The type of the Iterable. + */ +public class IndexedItem { + private T item; + private int index = -1; + + /** Get the current item in the iteration. */ + public T getItem() { + return item; + } + + /** Get the index of the current item (zero-indexed). */ + public int getIndex() { + return index; + } + + private static class IndexedIterator implements Iterable>, Iterator> { + + private final Iterator collectionIter; + private final IndexedItem currItem = new IndexedItem(); + + public IndexedIterator(Iterable collection) { + this.collectionIter = collection.iterator(); + } + + public IndexedIterator(final U[] array) { + collectionIter = new Iterator() { + U[] arr = array; + IndexedItem it = currItem; + + @Override + public boolean hasNext() { + return it.index + 1 < arr.length; + } + + @Override + public U next() { + return arr[it.index + 1]; + } + + @Override + public void remove() { + for (int i = it.index + 2; i < arr.length; i++) + arr[i] = arr[i + 1]; + } + }; + } + + @Override + public Iterator> iterator() { + return this; + } + + @Override + public boolean hasNext() { + return collectionIter.hasNext(); + } + + @Override + public IndexedItem next() { + currItem.item = collectionIter.next(); + currItem.index++; + return currItem; + } + + @Override + public void remove() throws UnsupportedOperationException, IllegalStateException { + collectionIter.remove(); + currItem.index--; + currItem.item = null; + } + } + + /** Iterate over an Iterable and keep track of the index */ + public static Iterable> iterate(Iterable collection) { + return new IndexedIterator(collection); + } + + /** Iterate over an array T[] and keep track of the index */ + public static Iterable> iterate(T[] array) { + return new IndexedIterator(array); + } +} + +" +A21606,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * + * @author ysan + * + */ + +public class Problem_B_small { + + + public static void main(String[] args) throws NumberFormatException, + IOException { + + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""B-large-output.txt"")); + + int cases = Integer.parseInt(in.readLine()); + + for (int i = 1; i <= cases; i++) { + String text = in.readLine().trim(); + + String[] val = text.split("" ""); + + int count = 0; + int n = Integer.parseInt(val[0]); + int s = Integer.parseInt(val[1]); + int p = Integer.parseInt(val[2]); + int j; + + + + for(int h=3; h0) + { + if(l>0) + {r[0] = r[0] + 1;l--;} + if(l>0) + {r[1] = r[1] + 1;l--;} + if(l>0) + {r[2] = r[2] + 1;l--;} + } + + boolean flag = false; + + for(int c =0; c<3; c++) + if(r[c] >= p){count++;flag=true;break;} + + if(!flag && s > 0) + { + int t = (target - p); + ro = t/2; + l = t%2; + int r2[] = new int[3]; + if(target > p){ + + r2[0] = p; + r2[1] = ro; + r2[2] = ro; + while(l>0) + { + if(l>0) + {r2[1] = r2[1] + 1;l--;} + if(l>0) + {r2[2] = r2[2] + 1;l--;} + } + if(r2[0] - r2[1]<=2 && r2[0] - r2[2]<=2) + { + r[0] = r2[0]; + r[1] = r2[1]; + r[2] = r2[2]; + s--; + } + } + + for(int c =0; c<3; c++) + if(r[c] >= p){count++;break;} + } + } + + + + out.write(""Case #""+ i +"": "" + count); + out.newLine(); + + } + + + + + + + + + + + + in.close(); + out.close(); + + + + } + + static void makeCombinations(int n, int p) + { + int sum,x,y,z; + + for(x=p ; x>=0 ; x--) + { + for(y=x ; y>=0 ; y--) + { + sum =x+y; + if(sum==n) + { + continue; + } + else + { + for(z=p ; z>=0 ; z--) + { + sum=sum+z; + if(sum { + + private int input; + + @Override + public boolean readLine(String data) { + input = Integer.parseInt(data); + return false; + } + + @Override + public Integer generateObject() { + return input; + } + +} +" +A22942,"package com.jedruch.utils; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class Files { + + public interface LineReader { + public void onNewLine(String line, int lineNumber); + } + + public static void readFileByLine(String path, LineReader reader) { + try (BufferedReader r = new BufferedReader(new FileReader(path))) { + String line = null; + int no =1; + while ((line = r.readLine()) != null) { + reader.onNewLine(line, no); + no++; + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A20462," +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + + + +public class DancingWithGooglers{ + public static void main(String[] args) throws IOException{ + String testCases; + //BufferedReader brTestCases = new BufferedReader(new InputStreamReader(System.in)); + File inFile = new File(""C:/Users/AbhilashR/Downloads/B-large.in"" ); + Scanner sc = new Scanner(inFile); + testCases = sc.nextLine();//(String)brTestCases.readLine(); + Integer noOfTestCases = null; + try{ + noOfTestCases = Integer.parseInt(testCases); + }catch (NumberFormatException e){ + System.out.println(""The entered value is not a Number""); + } + ArrayList inputData = new ArrayList(); + for(int i =0;i inputDataObj = new ArrayList(); + for(int i =0;i scoreList = new ArrayList(); + for(int j = 0; j< numberOfEmployees; j++){ + scoreList.add(Integer.parseInt((String)dataObj[j+3])); + } + Collections.sort(scoreList); + for(int j =0;j0){ + if(totScore%3 == 1){ + if(totScore/3 >= minimumBestResult){ + numberOfPeopleWithMinimumBest++; + }else if(1+totScore/3 >= minimumBestResult){ + numberOfPeopleWithMinimumBest++; + } + }else if(totScore%3 == 2){ + if(totScore/3 >= minimumBestResult){ + numberOfPeopleWithMinimumBest++; + }else if(1+totScore/3 >= minimumBestResult){ + numberOfPeopleWithMinimumBest++; + }else if(2+totScore/3 >= minimumBestResult && numberOfSurprisingTriplets >0){ + numberOfPeopleWithMinimumBest++; + numberOfSurprisingTriplets--; + } + } + }else{ + if(totScore/3 >= minimumBestResult){ + numberOfPeopleWithMinimumBest++; + }else if(1+totScore/3 >= minimumBestResult && numberOfSurprisingTriplets >0 && totScore !=0){ + numberOfPeopleWithMinimumBest++; + numberOfSurprisingTriplets--; + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+numberOfPeopleWithMinimumBest); + } + } + +}" +A20806,"package be.mokarea.gcj.googledancers; + +import java.io.FileInputStream; +import java.io.PrintWriter; + +import be.mokarea.gcj.common.GoogleCodeJamBase; +import be.mokarea.gcj.common.TestCaseReader; +import be.mokarea.gcj.common.Transformation; + +public class GoogleDancer extends GoogleCodeJamBase { + private final String outputFileName; + private final String inputFileName; + /** + * @param args + */ + public static void main(String[] args) { + new GoogleDancer(args[0], args[1]).execute(); + } + + GoogleDancer(String inputFileName,String outputFileName) { + this.inputFileName = inputFileName; + this.outputFileName = outputFileName; + } + + @Override + protected Transformation createTransformation( + TestCaseReader testCaseReader, + PrintWriter outputWriter) throws Exception { + return new GoogleDancerTransformation(testCaseReader,outputWriter); + } + + @Override + protected String getOutputFileName() throws Exception { + return outputFileName; + } + + @Override + protected TestCaseReader getTestCaseReader() + throws Exception { + return new GoogleDancerTestCaseReader(new FileInputStream(inputFileName)); + } + + +} +" +A22115,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DWiGoogler { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""out.txt"")); + int T = Integer.parseInt(in.readLine()); + int cnt = 0; + while(T > 0){ + T--; + cnt++; + int result = 0; + String str1 = in.readLine(); + String[] str2= str1.split("" ""); + int n = Integer.parseInt(str2[0]); + int s = Integer.parseInt(str2[1]); + int p = Integer.parseInt(str2[2]); + int [] x = new int[n]; + for(int i=0; i=p){ + result++; + }else if(p-min==1 && rest>0){ + result++; + }else if((s>0 && rest==0 && p-min==1 && min != 0) || (s>0 && rest==2 && p-min==2 && min !=0)){ + result++; + s--; + } + } + out.write(""Case #""+ cnt +"": "" + result+""\n""); + } + in.close(); + out.close(); + } + +} +" +A20305,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class dancing { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st = new StringTokenizer(""""); + + public static String next() throws Exception { + while (true) { + if (st.hasMoreTokens()) + return st.nextToken(); + String s = br.readLine(); + if (s == null) + return null; + st = new StringTokenizer(s); + } + } + + public static int nextInt() throws Exception { + return Integer.parseInt(next()); + } + + + public static void main(String[] args) throws Exception { + + int T = nextInt(); + + for(int t = 1 ; t <= T ; t++){ + int N = nextInt(); + int S = nextInt(); + int p = nextInt(); + + + int count = 0; + + for(int i = 0 ; i < N ; i ++){ + int x = nextInt(); + if(x==0){ + if(p==0) + count++; + continue; + } + if(x==1){ + if(p<=1) + count++; + continue; + } + + if(x % 3 == 0){ + if(x/3 >= p){ + count++; + }else if(S>0&&x/3 + 1 >= p){ + count ++; + S--; + } + }else if(x%3 == 1){ + if(x/3 +1>= p){ + count++; + } + }else { + if(x/3+1 >= p){ + count++; + }else if(S>0&&x/3 +2 >= p){ + count ++; + S--; + } + } + } + System.out.println(""Case #""+t+"": ""+count); + } + + } +} +" +A20693," +/* +ID: codeKNIGHT +LANG: JAVA +TASK: +*/ +import java.util.*; +import java.math.*; +import java.io.*; +class dancingWithGooglers +{ + public static void main(String args[])throws IOException + { + //Scanner in=new Scanner(System.in); + Scanner in=new Scanner(new FileReader(""C:\\Users\\Lokesh\\Desktop\\B-large.in"")); + //PrintWriter out=new PrintWriter(System.out); + //BufferedReader br=new BufferedReader(new FileReader(""C:\\Users\\Lokesh\\Desktop\\input.in"")); + PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(""E:\\programss\\GCJ\\output.txt""))); + int t=in.nextInt(),test,i,j,k; + int s,p,n,total; + for(test=1;test<=t;test++) + { + n=in.nextInt(); + s=in.nextInt(); + p=in.nextInt(); + int max=n; + int x=0,y=0; + for(i=0;i=2&&total<=28) + { + j=(total-2)/3+2; + k=(total+2)/3; + if(j=p&&k0) + s--; + else max--; + } + + } + else if(total<2) + { + if(p>total) + max--; + } + + } + out.println(""Case #""+test+"": ""+max); + } + out.flush(); + System.exit(0); + } +} +" +A20242,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package gcj2012; + +/** + * + * @author allegea + */ +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.StringTokenizer; + +/** + * + * @author Allegea + */ +public class DancingWiththeGooglers { + + public static void main(String[] args) throws IOException,FileNotFoundException{ + + + + String name = ""B-small-attempt0""; + + BufferedReader in = new BufferedReader(new FileReader(name+"".in"")); + + // BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + FileWriter archivo = new FileWriter(name+"".out""); + PrintWriter out = new PrintWriter(archivo); + out.flush(); + + + + String line; + StringBuilder buil = new StringBuilder(); + line = in.readLine(); + int cases = Integer.parseInt(line); + int act = 0; + while (act++=max)count++; + continue; + } + if(avg>=max) + { + count++; + continue; + } + + if(res==0) + { + if(avg+1==max)sup++; + }else if (res ==1){ + if(avg+1==max)count++; + }else{ + if(avg+1==max)count++; + else if(avg+2==max)sup++; + } + + } + //System.out.println(sup+"" - ""+count); + count+=Math.min(p, sup); + + + + System.out.println(""Case #""+act+"": ""+count); + out.println(""Case #""+act+"": ""+count); + // System.out.println(line); + + } + + + in.close(); + out.close(); + System.exit(0); + + + + + + } + + + +} + +" +A20286,"import java.io.*; +import java.util.*; +import java.math.*; + +public class Main implements Runnable +{ + static Scanner scanner; + static BufferedReader input; + static PrintWriter pw; + + public static void main(String[] args) throws Exception + { + new Thread(new Main()).start(); + } + + public void run() + { + try + { + input = new BufferedReader(new FileReader(""input.txt"")); + scanner = new Scanner(input); + pw = new PrintWriter(new File(""output.txt"")); + + solve(); + pw.close(); + } + catch(Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } + + public void solve() throws Exception + { + int T = scanner.nextInt(); + for(int t = 0; t < T; t++) + { + int N = scanner.nextInt(); // the number of Googlers + int S = scanner.nextInt(); // the number of surprising triplets of scores + int P = scanner.nextInt(); // Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? + + int [] ti = new int[N]; // the total points of the Googlers. + for(int i = 0; i < N; i++){ + ti[i]=scanner.nextInt(); + } + + //--- judge + + int r, s; + int ans = 0; + int cand = 0; + for(int i = 0; i < N; i++){ + r = ti[i]/3; + s = ti[i]%3; + + if ( s == 0 ) { + if ( r >= P ) { + ans++; + } else if ( r+1 >= P && r-1 >=0 ) { + cand++; + } + } else if ( s == 1 ) { + if ( r+1 >= P ) { + ans++; + } + } else { + if ( r+1 >= P ) { + ans++; + } else if ( r+2 >= P ) { + cand++; + } + } + } + ans = ans + Math.min (cand, S); + pw.println(""Case #"" + (t+1) + "": "" + ans); + } + } +} +" +A20360,"import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Gcj12B { + public static void main(String[] args) throws IOException { + if (args.length < 1) { + System.err.println(""Missing input filename as argument.""); + System.exit(1); + } + final BufferedReader in = new BufferedReader(new FileReader(args[0])); + final PrintWriter out = + new PrintWriter(new BufferedOutputStream(System.out)); + + final int nbrTestCases = Integer.parseInt(in.readLine()); + for (int testCase = 1; testCase <= nbrTestCases; testCase++) { + final StringTokenizer st1 = new StringTokenizer(in.readLine()); + final int n = Integer.parseInt(st1.nextToken()); + final int s = Integer.parseInt(st1.nextToken()); + final int p = Integer.parseInt(st1.nextToken()); + final int[] totalScores = new int[n]; + for (int i = 0; i < n; i++) { + totalScores[i] = Integer.parseInt(st1.nextToken()); + } + + final int[][] scores = new int[n][3]; + final int scoreCutoff = p*3; + final ArrayList surprises = new ArrayList(s); + final ArrayList canSurprise = new ArrayList(s); + + //System.err.println(""scores 1""); + for (int i = 0; i < n; i++) { + final int totalScore = totalScores[i]; + final int avg = totalScore / 3; + final int m = totalScore % 3; + scores[i][0] = avg; + scores[i][1] = avg; + scores[i][2] = avg; + if (m >= 1) { + scores[i][2]++; + } + if (m == 2) { + scores[i][1]++; + } + if (totalScore >= (scoreCutoff - 4) && totalScore <= (scoreCutoff - 3) && totalScore >= 2) { + surprises.add(i); + } else if (totalScore >= 2 && totalScore <= 28) { + canSurprise.add(i); + } + //System.err.println(Arrays.toString(scores[i])); + } + + int surprisesLeft = s; + int k = 0; + while (surprisesLeft > 0 && k < surprises.size()) { + final int googler = surprises.get(k); + final int totalScore = totalScores[googler]; + final int m = totalScore % 3; + switch (m) { + case 0: + scores[googler][0]--; + scores[googler][2]++; + break; + case 2: + scores[googler][1]--; + scores[googler][2]++; + break; + default: + assert false; + break; + } + surprisesLeft--; + k++; + } + /*System.err.println(""scores 2""); + for (int i = 0; i < n; i++) { + System.err.println(Arrays.toString(scores[i])); + }*/ + + k = 0; + while (surprisesLeft > 0) { + final int googler = canSurprise.get(k); + final int totalScore = totalScores[googler]; + final int m = totalScore % 3; + switch (m) { + case 0: + scores[googler][0]--; + scores[googler][2]++; + break; + case 1: + scores[googler][0]--; + scores[googler][1]++; + break; + case 2: + scores[googler][1]--; + scores[googler][2]++; + break; + default: + assert false; + break; + } + surprisesLeft--; + k++; + } + /*System.err.println(""scores 3""); + for (int i = 0; i < n; i++) { + System.err.println(Arrays.toString(scores[i])); + }*/ + + int nbrGreater = 0; + for (int i = 0; i < n; i++) { + boolean isGreater = false; + for (int j = 0; j < 3; j++) { + isGreater |= scores[i][j] >= p; + } + if (isGreater) { + nbrGreater++; + } + } + out.printf(""Case #%d: "", testCase); + out.println(nbrGreater); + } + + out.flush(); + } +} +" +A22118,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + + +public class Inputter { + + public static ArrayList getProblems(String file) throws NumberFormatException, IOException { + + BufferedReader in = new BufferedReader(new FileReader(file)); + + int numOfProblems = Integer.parseInt(in.readLine()); + + ArrayList problems = new ArrayList(numOfProblems); + + String curLine = in.readLine(); + while (curLine != null) { + String[] values = curLine.split(""[ \t]""); + + int googlers = Integer.parseInt(values[0]); + int suprising = Integer.parseInt(values[1]); + int best = Integer.parseInt(values[2]); + + int[] totals = new int[googlers]; + + for (int i = 3; i < values.length; i++) { + totals[i - 3] = Integer.parseInt(values[i]); + } + + problems.add(new Problem(googlers, suprising, best, totals)); + + curLine = in.readLine(); + } + + in.close(); + + return problems; + } +} +" +A20196,"package com.whitecrow.codejam2012.qualification; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + + String filename = ""B-small-attempt0""; + + FileReader input; + FileWriter output; + try { + input = new FileReader(filename + "".in""); + output = new FileWriter(filename + "".out""); + + BufferedReader reader = new BufferedReader(input); + BufferedWriter writer = new BufferedWriter(output); + + // String in = """"; + String out = """"; + + int T = Integer.parseInt(reader.readLine()); + + int N; + int S; + int p; + for (int i = 0; i < T; i++) { + StringTokenizer token = new StringTokenizer(reader.readLine(), "" ""); + int result = 0; + int suprising = 0; + + N = Integer.parseInt(token.nextToken()); + S = Integer.parseInt(token.nextToken()); + p = Integer.parseInt(token.nextToken()); + /* + * for (int j = 0; j < token.countTokens(); j++) { } + */ + + int t = 0; + int m; + int e; + for (int j = 0; j < N; j++) { + t = Integer.parseInt(token.nextToken()); + m = t / 3; + e = t % 3; + + if (m >= p || (m >= p - 1 && e >= 1)) { // Qualified + result++; + } else if ((m + e != 0) && ((m == p - 1 && e == 0) || (m == p - 2 && e == 2))) { // Surprising + suprising++; + if (S >= suprising) { + result++; + } + } + } + + out = ""Case #"" + (i + 1) + "": "" + result; + System.out.println(out + ""\tSuprising : "" + suprising); + writer.write(out+""\n""); + } + + reader.close(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + System.exit(0); + } + } +} +" +A20959,"package qual2012; + +import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws Exception { + Scanner in = new Scanner(System.in); + //PrintWriter out = new PrintWriter(System.out); + PrintWriter out = new PrintWriter(new File(""B.out"")); + + for (int t = in.nextInt(), cs = 1; t > 0; t--, cs++) { + int n = in.nextInt(), s = in.nextInt(), p = in.nextInt(); + int ans = 0; + for (int i = 0; i < n; i++) { + int x = in.nextInt(); + if ((x+2)/3 >= p) { + ans++; + } + else if (s > 0 && can(x, p)) { + s--; + ans++; + } + } + out.println(""Case #"" + cs + "": "" + ans); + } + + out.flush(); + } + + static boolean can(int x, int y) { + if (x == 0) return y == 0; + int max = (x+2)/3; + if (x%3 != 1) { + max++; + } + return max <= 10 && max >= y; + } +} +" +A21855,"import java.io.*; +import java.util.*; +import java.awt.Point; +import java.lang.Math; + +class Case{ + int num0,num1,num2,num3; + String result=""""; + public Case(File aFile) { + + try{ + StringBuilder contents = new StringBuilder(); + BufferedReader input = new BufferedReader(new FileReader(aFile)); + String line = input.readLine(); + num0 = Integer.valueOf(line).intValue(); + int i=1; + while (i<=num0 && ( line = input.readLine()) != null){ + + StringTokenizer st = new StringTokenizer(line,"" ""); + num1=Integer.valueOf(st.nextToken()).intValue(); + num2=Integer.valueOf(st.nextToken()).intValue(); + num3=Integer.valueOf(st.nextToken()).intValue(); + + Vector v1=new Vector(); + for (int j=0; j=noSurpriseScore){ + re_y++; + } else if (n2>0 && score>=needSurpriseScore){ + re_y++; + n2--; + } + } + + +//*** output + System.out.println("" ""); + System.out.println(""case=""+c+"": ""+n1+"":""+n2+"":""+n3+"" ""+vv); +//*** + re=re_y+""""; + result+=""Case #""+c+"": ""+re+System.getProperty(""line.separator""); + } + + + + + + + + + + +} + +public class ReadWriteTextFile { + static public String getContents(File aFile) { + StringBuilder contents = new StringBuilder(); + try { + BufferedReader input = new BufferedReader(new FileReader(aFile)); + try { + String line = null; + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty(""line.separator"")); + } + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + return contents.toString(); + } + static public void setContents(File aFile, String aContents) + throws FileNotFoundException, IOException { + if (aFile == null) { + throw new IllegalArgumentException(""File should not be null.""); + } + if (!aFile.exists()) { + throw new FileNotFoundException (""File does not exist: "" + aFile); + } + if (!aFile.isFile()) { + throw new IllegalArgumentException(""Should not be a directory: "" + aFile); + } + if (!aFile.canWrite()) { + throw new IllegalArgumentException(""File cannot be written: "" + aFile); + } + Writer output = new BufferedWriter(new FileWriter(aFile)); + try { + output.write( aContents ); + } + finally { + output.close(); + } + } + public static void main (String... aArguments) throws IOException { + File testFile = new File(""D:\\java\\readwritetext\\Dancing With the Googlers\\source.txt""); + File testFile2 = new File(""D:\\java\\readwritetext\\Dancing With the Googlers\\result.txt""); + Case allcases = new Case(testFile); + setContents(testFile2, allcases.getResult()); + } +} + + + + + + + + + + + + + + + + + + + +" +A22601,"package qualification; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Scanner; + +public class ProblemB { + static int numberOfSurprises; + static int atLeastP; + + public static void main(String[] args) throws FileNotFoundException { + Scanner scanner = new Scanner(new FileReader(""B-large.in"")); + int testCases = scanner.nextInt(); + + for (int i = 0; i < testCases; i++) { + int numberOfGooglers = scanner.nextInt(); + numberOfSurprises = scanner.nextInt(); + atLeastP = scanner.nextInt(); + + int total = 0; + for (int j = 0; j < numberOfGooglers; j++) { + int score = scanner.nextInt(); + HashSet> combinations = computeCombinationsForThisScore(score); + // printCombinations(combinations); + total += solve(score, combinations); + } + System.out.format(""Case #%d: %d\n"", (i + 1), total); + } + } + + private static int solve(int score, HashSet> combinationsForThisScore) { + List> listaSemChance = new ArrayList>(); + for (List list : combinationsForThisScore) { + Integer a = list.get(0); + Integer b = list.get(1); + Integer c = list.get(2); + if (Math.abs(a - b) < 2 && Math.abs(a - c) < 2 && Math.abs(b - c) < 2) { + listaSemChance.add(list); + } + } + + for (List list : listaSemChance) { + for (Integer integer : list) { + if (integer >= atLeastP) { + return 1; + } + } + } + + List> listaComChance = new ArrayList>(); + for (List list : combinationsForThisScore) { + Integer a = list.get(0); + Integer b = list.get(1); + Integer c = list.get(2); + if (Math.abs(a - b) == 2 || Math.abs(a - c) == 2 || Math.abs(b - c) == 2) { + listaComChance.add(list); + } + } + + for (List list : listaComChance) { + for (Integer integer : list) { + if (integer >= atLeastP && numberOfSurprises > 0) { + numberOfSurprises--; + return 1; + } + } + } + + return 0; + } + + private static void printCombinations(HashSet> combinations) { + for (List list : combinations) { + for (Integer integer : list) { + System.out.print(integer + "" ""); + } + System.out.println(); + } + System.out.println(); + } + + private static HashSet> computeCombinationsForThisScore(int score) { + HashSet> hashSet = new HashSet>(); + for (int a = 10; a >= 0; a--) { + for (int b = 10; b >= 0; b--) { + for (int c = 10; c >= 0; c--) { + if (a + b + c != score) { + continue; + } + + if (Math.abs(a - b) > 2 || Math.abs(a - c) > 2 || Math.abs(b - c) > 2) { + continue; + } + + // System.out.format(""Score: %d -> %d %d %d\n"", score, a, b, + // c); + List list = giveThemOrderedInAList(a, b, c); + hashSet.add(list); + } + } + } + return hashSet; + } + + private static List giveThemOrderedInAList(int a, int b, int c) { + ArrayList list = new ArrayList(); + list.add(a); + list.add(b); + list.add(c); + Collections.sort(list); + return list; + } +} +" +A21452,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlejam2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author Nomeir + */ +public class GoogleJam2 { + + private String inputFile = ""B-large.in""; + // "".\\A-small-attempt0.in""; + // "".\\A-small-practice.in""; + //// "".\\A-large-practice.in""; +// "".\\test2.in""; + private String outputFile = "".\\out.txt""; + private String line = ""start""; + private FileReader reader; + private BufferedReader buffer; + private FileWriter writer; + private BufferedWriter printer; + + public GoogleJam2() { + try { + new File(outputFile).createNewFile(); + reader = new FileReader(inputFile); + buffer = new BufferedReader(reader); + new File(outputFile).createNewFile(); + writer = new FileWriter(outputFile); + printer = new BufferedWriter(writer); + } catch (IOException ex) { + System.out.println(""The file couldn't be created ...""); + } + } + + public void endOperations() { + try { + if (reader != null) { + reader.close(); + } + if (buffer != null) { + buffer.close(); + } + if (printer != null) { + printer.flush(); + printer.close(); + } + if (writer != null) { + writer.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + + } + int lines; + + public void readInfo() { + try { + line = buffer.readLine(); + if (line != null) { + lines = Integer.valueOf(line); +// int i = 0, j = 0; +// L = Integer.valueOf(line.substring(0, i = line.indexOf("" ""))); +// D = Integer.valueOf(line.substring(++i, j = line.indexOf("" "", i))); +// N = Integer.valueOf(line.substring(++j, line.length())); + } + } catch (FileNotFoundException ex) { + System.err.println(""Source file not found .. !""); + } catch (IOException e) { + e.printStackTrace(); + } catch (StringIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + int googlersSize, surprisings, leastBest; + int totalPossibi, expectedSurp, totalWithoutSurp, leastSurp; + int S; + ArrayList googlers; + + private void readInfoLines() { + try { + for (int i = 0; i < lines;) { + line = buffer.readLine(); + googlers = new ArrayList(); + recurser(line, googlers); + googlersSize = googlers.get(0); + surprisings = googlers.get(1); + leastBest = googlers.get(2); + totalPossibi = 0; + expectedSurp = 0; + totalWithoutSurp = 0; + S = 0; + if (googlersSize > 0) { + leastSurp = (3 * leastBest) - 4; + for (int g = 3; g < googlers.size(); g++) { + if (leastSurp > 0) { + if (googlers.get(g) >= leastSurp) { + totalPossibi++; + } + if (googlers.get(g) >= leastSurp + 2) { + totalWithoutSurp++; + } + if (googlers.get(g) == leastSurp || googlers.get(g) == leastSurp + 1) { + expectedSurp++; + } + } else { + if (googlers.get(g) >= leastBest) { + totalPossibi++; + } + } + } + } + if (expectedSurp > surprisings) { + S = totalWithoutSurp + surprisings; + } else { + S = totalPossibi; + } + printer.write(""Case #"" + ++i + "": "" + S); + printer.newLine(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void recurser(String s, ArrayList links) { + int i = 0, k = 0; + if (s != null) { + if ((i = s.indexOf("" "")) >= 0) { + if (links.size() == 0) { + links.add(Integer.valueOf("""" + s.substring(0, i))); + } + if ((k = s.indexOf("" "", ++i)) >= 0) { + links.add(Integer.valueOf("""" + s.substring(i, k))); + s = s.substring(k); + recurser(s, links); + } else { + links.add(Integer.valueOf(s.substring(i, s.length()))); + } + } + } + } + +// public void printTestCases() { +// try { +// printer.write(""Case #"" + "" "" + "": "" + "" ""); +// printer.newLine(); +// } catch (IOException ex) { +// ex.printStackTrace(); +// } +// } + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + long t = System.currentTimeMillis(); + GoogleJam2 obj = new GoogleJam2(); + obj.readInfo(); + obj.readInfoLines(); +// obj.printTestCases(); + obj.endOperations(); + t = System.currentTimeMillis() - t; + System.out.println(""Time elapsed "" + t); + } +} +" +A22786,"package google.contest.A; + +import google.loader.Challenge; +import google.problems.AbstractReader; + +public class AReader extends AbstractReader { + + @Override + protected Challenge createChallenge(int number) { + int theLine = getActualLine(); + String[] lines = getLines(); + AChallenge chal = new AChallenge(theLine,lines[theLine]); + setActualLine(theLine+1); + return chal; + } + +} +" +A21963,"package codejam2012.qualification; + +import java.io.*; +import java.util.*; + +public class DancingWithTheGooglers { + + // general part + private static final String INPUT = ""src/main/resources""; + private static final String OUTPUT = ""target/output""; + private static final String ROUND = ""codejam2012/qualification""; + + private static final String SAMPLE = ""B-sample.in""; + private static final String SMALL = ""B-small-attempt0.in""; + private static final String LARGE = ""B-large.in""; + + private Scanner scanner; + private PrintWriter writer; + + public DancingWithTheGooglers(InputStream is, OutputStream os) { + scanner = new Scanner(is); + writer = new PrintWriter(os); + } + + public void close() { + scanner.close(); + writer.flush(); + } + + private static void runTest(String fileName, boolean isConsole) throws Exception { + InputStream is = initInputStream(fileName); + OutputStream os = initOutputStream(fileName, isConsole); + + DancingWithTheGooglers problem = new DancingWithTheGooglers(is, os); + problem.solve(); + problem.close(); + + doneStreams(isConsole, is, os); + } + + private static InputStream initInputStream(String fileName) throws FileNotFoundException { + File inputDir = new File(INPUT + File.separator + ROUND); + File inputFile = new File(inputDir, fileName); + InputStream is = new FileInputStream(inputFile); + return is; + } + + private static OutputStream initOutputStream(String fileName, boolean isConsole) throws FileNotFoundException { + OutputStream os = System.out; + if (isConsole) { + System.out.println(fileName); + System.out.println("" ---] cut [---""); + } else { + File outputDir = new File(OUTPUT + File.separator + ROUND); + outputDir.mkdirs(); + + File outputFile = new File(outputDir, fileName.replace("".in"", "".out"")); + os = new PrintStream(new FileOutputStream(outputFile)); + } + return os; + } + + private static void doneStreams(boolean isConsole, InputStream is, OutputStream os) throws IOException { + is.close(); + if (isConsole) { + System.out.println("" ---] cut [---""); + System.out.println(""""); + } else { + os.close(); + } + } + + public static void main(String[] args) { + try { + runTest(SAMPLE, true); + runTest(SMALL, false); + runTest(LARGE, false); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // problem part + + /** + * Solve the problem + */ + public void solve() { + int t = scanner.nextInt(); + + for (int i = 1; i <= t; i++) { + writer.print(""Case #""); + writer.print(i + "": ""); + + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + + int[] googlers = new int[n]; + + for (int j = 0; j < n; j++) { + googlers[j] = scanner.nextInt(); + } + + writer.println(solve(s, p, googlers)); + } + } + + private int solve(int s, int p, int[] googlers) { + List withoutSurprize = new LinkedList(); + List withSurprize = new LinkedList(); + for(int g: googlers){ + int two = g-p; + if(two < 0) + continue; + + if (two >= 2*(p-1)) { + withoutSurprize.add(g); + } else { + if( two >= 2*(p-2)) { + withSurprize.add(g); + } + } + } + int ress = withoutSurprize.size(); + int ws = (withSurprize.size() <= s) ? withSurprize.size() : s; + return ress += ws; + } +}" +A21484,"package google.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class Problem2 { + public Problem2() { + super(); + } + + private static int convert(String input) { + + String[] inputArray = input.split("" ""); + + int noOfCases = Integer.parseInt(inputArray[0]); + int noOfSurpriseCasesPossible = Integer.parseInt(inputArray[1]); + int p = Integer.parseInt(inputArray[2]); + + List cases = new ArrayList(); + for(int i = 3;i=minNonSurprisingSum) + countNonSurprisingCases++; + else if(score>=minSurprisingSum) + countSurprisingCases++; + } + + countNonSurprisingCases+=Math.min(countSurprisingCases, noOfSurpriseCasesPossible); + + //System.out.println(countNonSurprisingCases); + + return countNonSurprisingCases; + } + + public static void main(String[] args) { + try { + BufferedReader reader = new BufferedReader(new FileReader(""D:\\codejam\\2012\\B.in"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""D:\\codejam\\2012\\B.out"")); + + //... Loop as long as there are input lines. + String line = null; + reader.readLine(); + int i=1; + while ((line=reader.readLine()) != null) { + writer.write(""Case #""+i+"": ""+convert(line)); + writer.newLine(); // Write system dependent end of line. + i++; + } + + //... Close reader and writer. + reader.close(); // Close to unlock. + writer.close(); // Close to unlock and flush to disk. + + } + catch(Exception ex) { + ex.printStackTrace(); + } + } +} +" +A22543,"import java.io.*; +import java.util.StringTokenizer; + +public class DancingWithGooglers { + + BufferedReader br; + StringTokenizer st = new StringTokenizer(""""); + + private void solve() throws IOException { +// final String IO_FILE = null; + + final String IO_FILE = ""./B/B-large""; + final PrintWriter pw; + if (IO_FILE == null) { + br = new BufferedReader(new InputStreamReader(System.in)); + pw = new PrintWriter(System.out); + } else { + br = new BufferedReader(new FileReader(IO_FILE + "".in"")); + pw = new PrintWriter(IO_FILE + "".out""); + } + int testCases = nextInt(); + for (int ti = 1; ti <= testCases; ti++) { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] pointSums = new int[n]; + for (int i = 0; i < n; i++) { + pointSums[i] = nextInt(); + } + int ans = find(n, s, p, pointSums); + pw.println(""Case #"" + ti + "": "" + ans); + } + br.close(); + pw.close(); + } + + private int find(int n, int s, int p, int[] pointSums) { + int[][] d = new int[n + 1][s + 1]; + d[0][0] = 0; + for (int i = 0; i < n; i++) { + final int sum = pointSums[i]; + for (int j = 0; j <= s; j++) { + int maxRegularPoint = calcMaxRegularPoint(sum); + if (p <= maxRegularPoint) { + d[i + 1][j] = Math.max(d[i + 1][j], d[i][j] + 1); + } + else { + d[i + 1][j] = Math.max(d[i + 1][j], d[i][j]); + int maxSurprisingPoint = calcMaxSurprisingPoint(sum); + if (sum >= 2 && p <= maxSurprisingPoint && j != s) { + d[i + 1][j + 1] = Math.max(d[i + 1][j + 1], d[i][j] + 1); + } + } + } + } + int ans = 0; + for (int j = 0; j <= s; j++) { + ans = Math.max(ans, d[n][j]); + } + return ans; + } + + private int calcMaxRegularPoint(int sum) { + return (sum + 2) / 3; + } + + int calcMaxSurprisingPoint(int sum) { + return (sum + 4) / 3; + } + + String nextString() throws IOException { + while (!st.hasMoreTokens()) { + st = new StringTokenizer(br.readLine()); + } + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(nextString()); + } + + public static void main(String[] args) throws IOException { + new DancingWithGooglers().solve(); + } +} +" +A20402,"package qualification.taskC; + + +public class Task { + + private int a; + private int b; + private boolean[][] table; + + public Task(int a, int b, boolean[][] table) { + this.a = a; + this.b = b; + this.table = table; + } + + public String execute() { + int result = 0; + for (int i = a; i <= b; i++){ + for(int p = a; p <= b; p++){ + if(table[i][p]){ + result++; + } + } + } + return result/2 + """"; + } + +} +" +A20515,"package com.googlerese.core; + +import java.util.HashMap; +import java.util.Map; + +import com.googlerese.file.FileRead; +import com.googlerese.file.FileWrite; +import com.googlerese.file.GooglersBean; + +public class GooglerDanceScorer { + + private static final String inputFileName = ""C:/Documents and Settings/garan14/Desktop/input.txt""; + + private static final String outputFileName = ""C:/Documents and Settings/garan14/Desktop/out.txt""; + + public static void main( String[] args ) { + GooglerDanceScorer convertor = new GooglerDanceScorer(); + Map input = FileRead.getInstance().read( inputFileName ); + int testCases = input.size(); + Map output = new HashMap( testCases ); + + for ( int i = 1; i <= testCases; i++ ) { + String outputStr = convertor.convert( input.get( i ) ); + System.out.println( ""Output : "" + outputStr ); + output.put( i, outputStr ); + } + FileWrite.getInstance().write( outputFileName, output ); + } + + private String convert( final GooglersBean input ) { + + int[] scores = input.getScores(); + int numGooglers = input.getNumGooglers(); + int surprising = input.getSurprising(); + int maxResult = input.getResult(); + int max = 0; + for ( int i = 0; i < numGooglers; i++ ) { + int score = scores[i]; + + int score1 = score / 3; + score = score - score1; + + int score2 = score / 2; + score = score - score2; + int score3 = score; + + if ( score3 >= maxResult ) { + max++; + } else if ( surprising > 0 ) { + if ( score3 > 0 && ( score3 == score2 ) && ( score3 == ( maxResult - 1 ) ) ) { + max++; + surprising--; + } + } + + } + + return """" + max; + } +} +" +A22131,"package cats; + +import java.io.*; +import java.util.ArrayList; +import java.util.Collections; + +public class Main { + public Main() throws Exception{ + FileReader fr = new FileReader(new File(""input.txt"")); + BufferedReader in = new BufferedReader(fr); + + File outFile = new File(""output.txt""); + outFile.createNewFile(); + FileWriter fw = new FileWriter(outFile); + BufferedWriter out = new BufferedWriter(fw); + + + + int numTests = Integer.parseInt(in.readLine()); + for(int x = 0; x totals = new ArrayList(numPeople); + for(int p = 0; p= scoreToBeat+(scoreToBeat-1)*2){ + count++; + }else if(t >= scoreToBeat+(scoreToBeat-2)*2 && surprisesLeft > 0){ + surprisesLeft--; + count++; + }else break; + } + out.write(""Case #"" + (x+1) + "": "" + count + ""\n""); + } + + + in.close(); + out.close(); + } + + + + + public static void main(String[] args) throws Exception{ + new Main(); + } +} +" +A21437,"package template; + +import java.util.ArrayList; + +public class TestCaseSolver implements Runnable { + + private ArrayList testCases; + private int ref; + + public TestCaseSolver(ArrayList tcs, int ref) { + testCases = tcs; + this.ref = ref; + } + + public TestCaseSolver(TestCase tc, int ref) { + ArrayList tcs = new ArrayList<>(); + tcs.add(tc); + testCases = tcs; + this.ref = ref; + } + + public int getRef() { + return ref; + } + + @Override + public void run() { + for (TestCase tc : testCases) { + long startTime = System.nanoTime(); + solve(tc); + long duration = System.nanoTime() - startTime; + double secs = (double)duration / (1000000000d); + tc.setTime(secs); + System.out.println(""Thread "" + ref + "" solved testcase "" + tc.getRef() + "" in "" + String.format(""%.2f"", secs) + "" secs.""); + } + } + + private void solve(TestCase tc) { + ArrayList totals = tc.getIntegerList(""props""); + int num = totals.remove(0); + int surp = totals.remove(0); + int p = totals.remove(0); + + if (num != totals.size()) {Utils.die(""err count"");} + + int deffo = 0; + int maybe = 0; + for (Integer i : totals) { + if (i >= (3 * p - 2)) { + deffo++; + continue; + } + if (i >= (3 * p - 4) && i > 0) { + maybe++; + } + } + + if (maybe > surp) {maybe = surp;} + + + + tc.setSolution(new Integer(deffo + maybe)); + } +} +" +A22421,"import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + + + public static void main(String[] args) throws IOException { + + Scanner sc = new Scanner(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""outputB1.txt"")); + + int caseCount = sc.nextInt(); + sc.nextLine(); + + for (int caseNum = 0; caseNum < caseCount; caseNum++) { + + //System.out.println(caseNum); + int dancerCount = sc.nextInt(); + int surprisingCount = sc.nextInt(); + + + int p = sc.nextInt(); + int pCount = 0; + int sCount = 0; + + for (int dancerNum = 0; dancerNum < dancerCount; dancerNum++) { + int score = sc.nextInt(); + int d = checkScore(score, p); + if (d == 1) + pCount++; + else if (d == 2) + sCount++; + } + + //System.out.println(pCount + "" "" + sCount + "" "" + surprisingCount); + int count = pCount; + if (sCount < surprisingCount) { + count += sCount; + } + else { + count += surprisingCount; + } + + pw.write(""Case #"" + (caseNum + 1) + "": ""); + pw.write(count + ""\n""); + } + + pw.flush(); + pw.close(); + sc.close(); + } + + private static int checkScore(int score, int p) { + + boolean sScore = false; + + for (int a = 0; a <= 10; a++) { + for (int b = 0; b <= 10; b++) { + for (int c = 0; c <= 10; c++) { + + if (a + b + c == score && + (a >= p || b >= p || c >= p)) { + + int ab = Math.abs(a-b); + int ac = Math.abs(a-c); + int bc = Math.abs(b-c); + + if (ab < 2 && ac < 2 && bc < 2) { + //System.out.println(""P "" + a + "" "" + b + "" "" + c); + return 1; + } + else if (ab < 3 && ac < 3 && bc < 3) { + //System.out.println(""S "" + a + "" "" + b + "" "" + c); + sScore = true; + } + } + + } + } + } + + if(sScore == true) { + return 2; + } + + return 0; + } +} +" +A22518," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + + + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException + { + //BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""B-small-attempt3.in""))); + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""B-large.in""))); + //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter out = new BufferedWriter(new FileWriter(""DancingWithTheGooglers.txt"")); + int cases = Integer.parseInt(reader.readLine()); + + for(int i=1; i <= cases; i++) + { + + String line = reader.readLine(); + //out.write(line+""\n""); + String[] l = line.split("" ""); + int n = Integer.parseInt(l[0]); + int s = Integer.parseInt(l[1]); + int p = Integer.parseInt(l[2]); + int[] t = new int[n]; + + for(int j = 0; j < n; j++) t[j] = Integer.parseInt(l[j+3]); + Arrays.sort(t); + //out.write(Arrays.toString(t)+""\n""); + int count = 0; + for(int j = n-1; j >=0 ; j--) + if(p==0) count++; + else if(p==1) + { + if(t[j] >= 1) count++; + else break; + }else + { + if(t[j] >= p*3-2) + count++; + else if (t[j] >= p*3-4 && s>0) { + s--; + count++; + } + else break; + } + + + //out.write((p*3-2) + "" "" + (p*3-4) + ""\n""); + System.out.print(""Case #"" + i+ "": "" + count+""\n""); + out.write(""Case #"" + i+ "": "" + count+""\n""); + } + out.close(); + + } +}" +A22428,"import java.io.*; + +public class template { + public static void main(String[] args) throws IOException { + StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); + PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); + //PrintWriter out = new PrintWriter(""output.txt""); + + in.nextToken(); int count = (int)in.nval; + + for(int c = 1 ; c <= count ; c++) { + in.nextToken(); int googlers = (int) in.nval; + in.nextToken(); int surprisings = (int) in.nval; + in.nextToken(); int passScore = (int) in.nval; + + int pass = 0; + int passWithSurprising = 0; + + // loop through scores + for(int i = 0 ; i < googlers ; i++) { + in.nextToken(); int score = (int) in.nval; + + int division = score / 3; + int modulo = score % 3; + + if (modulo > 0) division++; + + if (division >= passScore) { + pass++; + } else if (division+1 == passScore && modulo!=1 && score!=0) { + passWithSurprising++; + } + } + + out.println(""Case #"" + c + "": "" + (pass + Math.min(passWithSurprising, surprisings))); + } + + out.flush(); + out.close(); + } +} +" +A21385,"package my.codejam.y12.qualification; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Stack; + +public class ProblemB { + + static void runIt() throws IOException { + +// String inFName = ""resource/B-small-attempt0.in""; + String inFName = ""resource/B-large.in""; +// String outFName = ""resource/B-small.out""; + String outFName = ""resource/B-large.out""; + + BufferedReader in = new BufferedReader(new FileReader(inFName)); + PrintWriter out = new PrintWriter(new File(outFName)); + + int testCases = Integer.parseInt(in.readLine()); + + for (int i = 0; i < testCases; ++i) { + + String line = in.readLine(); + System.out.println(line); + StringBuilder output = new StringBuilder(); + output.append(""Case #"" + (i + 1) + "": ""); + + int googlers = 0; + int surprisedGooglers = 0; + + String[] t = line.split("" ""); + int N = Integer.parseInt(t[0]); + int S = Integer.parseInt(t[1]); + int p = Integer.parseInt(t[2]); + + for (int j = 3; j < t.length; ++j) { + int score = Integer.parseInt(t[j]); + int diff = score - (p * 3); + if ((p == 1 && diff > -2) || (p != 1 && diff > -3)) { + googlers++; + } else if (p != 1 && diff > -5) { + surprisedGooglers++; + } + } + + surprisedGooglers = surprisedGooglers > S ? S : surprisedGooglers; + googlers += surprisedGooglers; + + output.append(googlers); + System.out.println(output); + out.println(output); + } + + in.close(); + out.flush(); + out.close(); + } + + public static void main(String[] args) { + + try { + ProblemB.runIt(); + } catch (IOException e) { + + System.out.println(e.getMessage()); + e.printStackTrace(); + + } catch (Exception e) { + + System.out.println(e.getMessage()); + e.printStackTrace(); + + } + } +} +" +A20007,"import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.Scanner; + +public class QB { + public static int cal(Scanner sc){ + int result = 0; + + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + if(p > 1){ + int tmp1 = p*3-2; + int tmp2 = tmp1-2; + for(int i=0; i= tmp1){ + result++; + } else if(t >= tmp2 && S > 0){ + S--; + result++; + } + } + } else if(p == 1){ + for(int i=0; i=min||res[k][1]>=min||res[k][2]>=min)) + { + count++; + b=true; + break; + } + } + + if(!b&&surprise>0) + { + for(int k=0;k=min||res[k][1]>=min||res[k][2]>=min)) + { + count++; + surprise--; + b=true; + break; + } + } + } + } + + + + System.out.println(""Case #""+(i+1)+"": ""+count); + write.write(""Case #""+(i+1)+"": ""+count+""\n""); +} + +boolean surprise(int i,int j,int k) + { + if(Math.abs(i-j)==2||Math.abs(j-k)==2||Math.abs(i-k)==2)return true; + return false; +} +int [][] generateTriplet(int p) + { + l=0; + int res[][]=new int[100][3]; + int i=Math.max(0, p/3-3); + for(;i<=p/3+3;i++) + for(int j=i-2;j<=i+2;j++) + for(int k=i-2;k<=i+2;k++) + { + if(i+j+k!=p||i>10||j>10||k>10||i<0||j<0||k<0)continue; + if(Math.abs(i-j)<=2&&Math.abs(k-j)<=2&&Math.abs(i-k)<=2) + { + res[l][0]=i; + res[l][1]=j; + res[l][2]=k; + l++; + } + } + return res; +} + +} +" +A21749,"import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; + +@SuppressWarnings(""CallToThreadDumpStack"") +public class Utils +{ + private static FileOutputStream outStream; + private static BufferedReader reader; + private static boolean debug = false; + + public static void openOutFile(String str, boolean debug) + { + Utils.debug = debug; + try { outStream = new FileOutputStream(str, false); } + catch (Exception e) { e.printStackTrace(); } + } + + public static void openInFile(String str) + { + try { reader = new BufferedReader(new FileReader(str)); } + catch (Exception e) { e.printStackTrace(); } + } + + public static void closeOutFile() + { + try { outStream.close(); } + catch (Exception e) { e.printStackTrace(); } + } + + public static void closeInFile() + { + try { outStream.close(); } + catch (Exception e) { e.printStackTrace(); } + } + + public static String readFromFile() + { + try { return reader.readLine(); } + catch (Exception e) { e.printStackTrace(); } + return null; // shouldn't get here + } + public static void writeToFile(String str) + { + if (debug) System.out.println(str); + try + { + for(int k=0; k0&&avg!=0) +{ +S=S-1; +Flag=Flag+1;} +break; +} +case 1: +{ +if(P<=avg+1) +Flag=Flag+1; +break; +} +case 2: +{ +if(P<=avg+1) +Flag=Flag+1; +if(P==avg+2&&S>0) +{ +S=S-1; +Flag=Flag+1; +} +break; +} + +} //switch close +//System.out.println(Flag); +} +//System.out.println(Flag); +out.write(""Case #""+j+"": ""+Flag+""\r\n""); +j=j+1; +} + +out.close(); +input.close();}catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } +} +} +" +A21586," +/** + * Write a description of class dancing here. + * + * @author (your name) + * @version (a version number or a date) + */ +import java.io.*; + +public class dancing +{ + public static void main(String args[]) throws IOException + { + int tcase,ng,sur,max; + int i, j, m, x, y=0,s,flag=0,sum,best,counter; + int g[]=new int[100]; + char ch,newline=13; + String result; + FileInputStream fis; + + fis = new FileInputStream(""B-large.in""); + + + DataInputStream dis = new DataInputStream(fis); + BufferedReader br = new BufferedReader(new InputStreamReader(dis)); + + + File fout = new File(""B-large-sol.op""); + FileOutputStream fo = new FileOutputStream(fout); + + byte buf[]; + + + String strline; + + strline = br.readLine(); + + tcase = Integer.parseInt(strline); + // System.out.println(tcase); + for(m=1;m<=tcase;m++) + { +//System.out.println(""testcase""+m); + s=0; + ch=(char)br.read(); + // cout<=max) + { + // System.out.println(""best""+best); + counter++; + } + else{ + if((max-(g[i]-max)/2) == 2 && sur > 0) + {//System.out.println(""surprise""); + counter++; + sur--; + } + } + } + + + result= ""Case #""+m+"": ""+counter+'\n'; + // System.out.println(""Case #""+m+"": ""+counter); + buf=result.getBytes(); + try{ + fo.write(buf); + } + catch(Exception e){System.out.println(""hey"");} + + + } + try{ + fo.close(); + fis.close(); + } + catch(Exception e){} +} +} +" +A20552,"package CodeJam; + +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; + +public class CodeJam { + + public static void main(String[] args) throws IOException { + String outputFile = System.getenv(""USERPROFILE"") + + ""\\Documents\\B-small.out""; + String inputFile = System.getenv(""USERPROFILE"") + + ""\\Documents\\B-small.in""; + + BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile)); + DataInputStream reader = new DataInputStream(new FileInputStream( + inputFile)); + + int T = Integer.valueOf(reader.readLine()); + for (int k = 1; k <= T; k++) { + + String line = reader.readLine(); + + int nbreDancers = Integer.valueOf(line.substring(0, + line.indexOf("" ""))); + line = line.substring(line.indexOf("" "") + 1); + int s = Integer.valueOf(line.substring(0, line.indexOf("" ""))); + line = line.substring(line.indexOf("" "") + 1); + int p = Integer.valueOf(line.substring(0, line.indexOf("" ""))); + line = line.substring(line.indexOf("" "") + 1); + line += "" ""; + int q = 0; + int n = 0; + if (3 * p - 4 < 0) + s = 0; + for (int j = 0; j < nbreDancers; j++) { + int sum = Integer.valueOf(line.substring(0, line.indexOf("" ""))); + line = line.substring(line.indexOf("" "") + 1); + if (sum >= 3 * p - 4) { + if (((sum == 3 * p - 4) || (sum == 3 * p - 3))) { + q++; + if (q <= s) { + n++; + } + } else { + n++; + } + } + } + writer.write(""Case #"" + k + "": "" + n); + writer.newLine(); + } + writer.close(); + } +}" +A21610,"import java.util.Scanner; + + +public class QuestionB extends Question{ + + private int N; + private int S; + private int p; + private int[] dancers; + + public QuestionB(Result result, Counter counter) + { + super(result, counter); + } + + @Override + public void readInput(Scanner scanner) { + N = scanner.nextInt(); + S = scanner.nextInt(); + p = scanner.nextInt(); + dancers = new int[N]; + for (int i = 0; i < N; i++) { + dancers[i] = scanner.nextInt(); + } + } + + @Override + public String solution() { + int counter = 0; + for (int i = 0; i < N; i++) { + if (dancers[i]>=3*p-Math.min(2,dancers[i]*2)) + counter++; + else if (dancers[i]>=3*p-Math.min(4,dancers[i]*2) && S>0) { + S--; + counter++; + } + } + return Integer.toString(counter); + } + + +} +" +A21406," +public class Triplet implements Comparable { + + private int s1; + private int s2; + private int s3; + + public Triplet(int _s1,int _s2,int _s3){ + s1=_s1; + s2=_s2; + s3=_s3; + } + + @Override + public int compareTo(Triplet o) { + return new Integer(o.getMax()).compareTo(this.getMax()); + } + + public boolean isSurprising(){ + if(Math.abs(s1-s2)==2 || Math.abs(s1-s3)==2 || Math.abs(s2-s3)==2) return true; + return false; + } + + public int getMax(){ + if(s1>s2 && s1>s3) return s1; + else if (s2>s3) return s2; + else return s3; + } + + public void setS1(int s1) { + this.s1 = s1; + } + public int getS1() { + return s1; + } + public void setS2(int s2) { + this.s2 = s2; + } + public int getS2() { + return s2; + } + public void setS3(int s3) { + this.s3 = s3; + } + public int getS3() { + return s3; + } + + + +} +" +A22452,"package util.graph; + +public abstract class State implements Comparable{ + +} +" +A21438,"package template; + +import java.io.*; +import java.util.ArrayList; +import java.util.Random; + +public class Utils { + + static String logfile = """"; + + public static BufferedWriter newBufferedWriter(String filename, boolean append) { + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(filename, append)); + } catch (IOException ex) { + die(""Exception in newBufferedWriter""); + } + return bw; + } + + public static void writeLn(BufferedWriter bw, String line) { + try { + bw.write(line); + bw.newLine(); + } catch (IOException ex) { + die(""Exception in writeLn""); + } + } + + public static void closeBw(BufferedWriter bw) { + try { + bw.flush(); + bw.close(); + } catch (IOException ex) { + die(""Exception in closeBw""); + } + + } + + public static BufferedReader newBufferedReader(String filename) { + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(filename)); + } catch (IOException ex) { + die(""Exception in newBufferedReader""); + } + return br; + } + + public static String readLn(BufferedReader br) { + String s = null; + try { + s = br.readLine(); + } catch (IOException ex) { + die(""Exception in readLn""); + } + return s; + } + + public static Integer readInteger(BufferedReader br) { + return new Integer(readLn(br)); + } + + public static ArrayList readIntegerList(BufferedReader br) { + return readIntegerList(br, null); + } + + public static ArrayList readIntegerList(BufferedReader br, Integer expectedLength) { + String[] s = readLn(br).split("" ""); + ArrayList l = new ArrayList<>(); + for (int x = 0; x < s.length; x++) { + l.add(new Integer(s[x])); + } + if (expectedLength != null) { + if (l.size() != expectedLength.intValue()) { + die(""Incorrect length in readIntegerList""); + } + } + return l; + } + + public static ArrayList readMultipleIntegers(BufferedReader br, Integer rows) { + ArrayList l = new ArrayList<>(); + for (int x = 0; x < rows; x++) { + String s = readLn(br); + l.add(new Integer(s)); + } + return l; + } + + public static ArrayList> readIntegerMatrix(BufferedReader br, Integer rows) { + return readIntegerMatrix(br, rows, null); + } + + public static ArrayList> readIntegerMatrix(BufferedReader br, Integer rows, Integer expectedLength) { + ArrayList> l = new ArrayList<>(); + for (int x = 0; x < rows.intValue(); x++) { + l.add(readIntegerList(br, expectedLength)); + } + return l; + } + + public static Double readDouble(BufferedReader br) { + return new Double(readLn(br)); + } + + public static ArrayList readDoubleList(BufferedReader br) { + return readDoubleList(br, null); + } + + public static ArrayList readDoubleList(BufferedReader br, Integer expectedLength) { + String[] s = readLn(br).split("" ""); + ArrayList l = new ArrayList<>(); + for (int x = 0; x < s.length; x++) { + l.add(new Double(s[x])); + } + if (expectedLength != null) { + if (l.size() != expectedLength.intValue()) { + die(""Incorrect length in readDoubleList""); + } + } + return l; + } + + public static ArrayList readMultipleDoubles(BufferedReader br, Integer rows) { + ArrayList l = new ArrayList<>(); + for (int x = 0; x < rows; x++) { + String s = readLn(br); + l.add(new Double(s)); + } + return l; + } + + public static ArrayList> readDoubleMatrix(BufferedReader br, Integer rows) { + return readDoubleMatrix(br, rows, null); + } + + public static ArrayList> readDoubleMatrix(BufferedReader br, Integer rows, Integer expectedLength) { + ArrayList> l = new ArrayList<>(); + for (int x = 0; x < rows.intValue(); x++) { + l.add(readDoubleList(br, expectedLength)); + } + return l; + } + + public static Long readLong(BufferedReader br) { + return new Long(readLn(br)); + } + + public static ArrayList readLongList(BufferedReader br) { + return readLongList(br, null); + } + + public static ArrayList readLongList(BufferedReader br, Integer expectedLength) { + String[] s = readLn(br).split("" ""); + ArrayList l = new ArrayList<>(); + for (int x = 0; x < s.length; x++) { + l.add(new Long(s[x])); + } + if (expectedLength != null) { + if (l.size() != expectedLength.intValue()) { + die(""Incorrect length in readLongList""); + } + } + return l; + } + + public static ArrayList readMultipleLongs(BufferedReader br, Integer rows) { + ArrayList l = new ArrayList<>(); + for (int x = 0; x < rows; x++) { + String s = readLn(br); + l.add(new Long(s)); + } + return l; + } + + public static ArrayList> readLongMatrix(BufferedReader br, Integer rows) { + return readLongMatrix(br, rows, null); + } + + public static ArrayList> readLongMatrix(BufferedReader br, Integer rows, Integer expectedLength) { + ArrayList> l = new ArrayList<>(); + for (int x = 0; x < rows.intValue(); x++) { + l.add(readLongList(br, expectedLength)); + } + return l; + } + + public static String readString(BufferedReader br) { + return new String(readLn(br)); + } + + public static ArrayList readStringList(BufferedReader br) { + return readStringList(br, null); + } + + public static ArrayList readStringList(BufferedReader br, Integer expectedLength) { + String[] s = readLn(br).split("" ""); + ArrayList l = new ArrayList<>(); + for (int x = 0; x < s.length; x++) { + l.add(new String(s[x])); + } + if (expectedLength != null) { + if (l.size() != expectedLength.intValue()) { + die(""Incorrect length in readStringList""); + } + } + return l; + } + + public static ArrayList readMultipleStrings(BufferedReader br, Integer rows) { + ArrayList l = new ArrayList<>(); + for (int x = 0; x < rows; x++) { + String s = readLn(br); + l.add(new String(s)); + } + return l; + } + + public static ArrayList> readStringMatrix(BufferedReader br, Integer rows) { + return readStringMatrix(br, rows, null); + } + + public static ArrayList> readStringMatrix(BufferedReader br, Integer rows, Integer expectedLength) { + ArrayList> l = new ArrayList<>(); + for (int x = 0; x < rows.intValue(); x++) { + l.add(readStringList(br, expectedLength)); + } + return l; + } + + public static Boolean readBoolean(BufferedReader br) { + return new Boolean(readLn(br)); + } + + public static ArrayList readBooleanList(BufferedReader br) { + return readBooleanList(br, null); + } + + public static ArrayList readBooleanList(BufferedReader br, Integer expectedLength) { + String[] s = readLn(br).split("" ""); + ArrayList l = new ArrayList<>(); + for (int x = 0; x < s.length; x++) { + l.add(new Boolean(s[x])); + } + if (expectedLength != null) { + if (l.size() != expectedLength.intValue()) { + die(""Incorrect length in readBooleanList""); + } + } + return l; + } + + public static ArrayList readMultipleBooleans(BufferedReader br, Integer rows) { + ArrayList l = new ArrayList<>(); + for (int x = 0; x < rows; x++) { + String s = readLn(br); + l.add(new Boolean(s)); + } + return l; + } + + public static ArrayList> readBooleanMatrix(BufferedReader br, Integer rows) { + return readBooleanMatrix(br, rows, null); + } + + public static ArrayList> readBooleanMatrix(BufferedReader br, Integer rows, Integer expectedLength) { + ArrayList> l = new ArrayList<>(); + for (int x = 0; x < rows.intValue(); x++) { + l.add(readBooleanList(br, expectedLength)); + } + return l; + } + + public static void closeBr(BufferedReader br) { + try { + br.close(); + } catch (IOException ex) { + die(""Exception in closeBr""); + } + + } + + public static void die(String reason) { + sout(""Die: "" + reason); + System.exit(0); + } + + public static void sout(String s) { + System.out.println(s); + } + + public static void sout(int i) { + System.out.println(i); + } + + public static void sout(Object o) { + System.out.println(o); + } + + public static void log(String line) { + BufferedWriter bw = newBufferedWriter(logfile, true); + writeLn(bw, line); + closeBw(bw); + } + + public static void clearFile(String filename) { + BufferedWriter bw = newBufferedWriter(filename, false); + closeBw(bw); + } + + public static int minInt(ArrayList l) { + int i = l.get(0).intValue(); + for (Integer j : l) { + if (j.intValue() < i) { + i = j.intValue(); + } + } + return i; + } + + public static int maxInt(ArrayList l) { + int i = l.get(0).intValue(); + for (Integer j : l) { + if (j.intValue() > i) { + i = j.intValue(); + } + } + return i; + } + + public static String joinArray(ArrayList l, String delim) { + String s = """"; + for (int i = 0; i < l.size(); i++) { + s += l.get(i).toString(); + if (i < (l.size() - 1)) { + s += delim; + } + } + return s; + } + + public static ArrayList splitToChars(String source) { + ArrayList chars = new ArrayList<>(); + for (int i = 0; i < source.length(); i++) { + chars.add(source.substring(i, i + 1)); + } + return chars; + } + + public static ArrayList> allPairs(int lower1, int upper1, int lower2, int upper2, int style) { + //Style: + //0 all pairs + //1 (1) <= (2) + //2 (1) < (2) + + ArrayList> out = new ArrayList<>(); + + for (int index1 = lower1; index1 <= upper1; index1++) { + for (int index2 = lower2; index2 <= upper2; index2++) { + ArrayList thisPair = new ArrayList<>(); + thisPair.add(new Integer(index1)); + thisPair.add(new Integer(index2)); + + switch (style) { + case 0: + out.add(thisPair); + break; + case 1: + if (index1 <= index2) { + out.add(thisPair); + } + break; + case 2: + if (index1 < index2) { + out.add(thisPair); + } + break; + default: + die(""Unrecognised case in allPairs""); + } + + + } + } + + return out; + } + + public static ArrayList> cloneALALI(ArrayList> in) { + ArrayList> out = new ArrayList<>(); + for (ArrayList inALI : in) { + ArrayList outALI = new ArrayList<>(inALI); + out.add(outALI); + } + return out; + } + + public static int[][] cloneInt2D(int[][] in) { + if (in.length == 0) {return new int[0][0];} + + int[][] out = new int[in.length][]; + for (int i = 0; i < in.length; i++) { + out[i] = new int[in[i].length]; + System.arraycopy(in[i], 0, out[i], 0, in[i].length); + } + return out; + } + + public static double[][] cloneDouble2D(double[][] in) { + if (in.length == 0) {return new double[0][0];} + + double[][] out = new double[in.length][]; + for (int i = 0; i < in.length; i++) { + out[i] = new double[in[i].length]; + System.arraycopy(in[i], 0, out[i], 0, in[i].length); + } + return out; + } + + public static ArrayList> allPerms(int n) { + //returns an arraylist of arraylists of integers + //showing all permutations of Integers 0 to n-1 + //works realistically up to n=10 + if (n == 0) { + return new ArrayList>(); + } + return allPerms_recurse(n, n); + } + + public static ArrayList> allPerms_recurse(int level, int n) { + if (level == 1) { + ArrayList single = new ArrayList<>(); + single.add(new Integer(n - level)); + ArrayList> list = new ArrayList<>(); + list.add(single); + return list; + } + + ArrayList> prev = allPerms_recurse(level - 1, n); + ArrayList> out = new ArrayList<>(); + + + for (int placeAt = 0; placeAt < level; placeAt++) { + //clone prev + ArrayList> prevClone = cloneALALI(prev); + + //insert + for (ArrayList prevItem : prevClone) { + prevItem.add(placeAt, new Integer(n - level)); + } + + //append to out + out.addAll(prevClone); + } + return out; + } + + public static ArrayList> allCombs(int n) { + //returns an arraylist of arraylists of integers + //showing all combinations of Integers 0 to n-1 + //works realistically up to n=7 + if (n == 0) { + return new ArrayList>(); + } + return allCombs_recurse(n, n); + } + + public static ArrayList> nCombs(int count, int n) { + //returns an arraylist of arraylists of integers + //showing all combinations of Integers 0 to n-1 --- of length ""count"" + //i.e. base ""n"" counting up to (n^count - 1). In order. + if (count == 0) { + return new ArrayList>(); + } + return allCombs_recurse(count, n); + } + + public static ArrayList> allCombs_recurse(int level, int n) { + if (level == 1) { + ArrayList> list = new ArrayList<>(); + for (int i = 0; i < n; i++) { + ArrayList single = new ArrayList<>(); + single.add(new Integer(i)); + list.add(single); + } + return list; + } + + ArrayList> prev = allCombs_recurse(level - 1, n); + ArrayList> out = new ArrayList<>(); + + + for (int initial = 0; initial < n; initial++) { + //clone prev + ArrayList> prevClone = cloneALALI(prev); + + //insert + for (ArrayList prevItem : prevClone) { + prevItem.add(0, new Integer(initial)); + } + + //append to out + out.addAll(prevClone); + } + return out; + } + + public static ArrayList grepFull(ArrayList inList, String pattern) { + //pattern must match full text + ArrayList outList = new ArrayList<>(); + for (String s : inList) { + if (s.matches(pattern)) { + outList.add(new String(s)); + } + } + + return outList; + } + + public static int[] randomIntegerArray(int count, int low, int high, long seed) { + //a list of ""count"" ints from low to high inclusive. + Random rng = new Random(); + if (seed != -1) { + rng.setSeed(seed); + } + int[] out = new int[count]; + for (int x = 0; x < count; x++) { + out[x] = rng.nextInt(high - low + 1) + low; + } + return out; + } + + public static double[] randomDoubleArray(int count, double low, double high, long seed) { + //a list of ""count"" ints from low inclusive to high exclusive. + Random rng = new Random(); + if (seed != -1) { + rng.setSeed(seed); + } + double[] out = new double[count]; + for (int x = 0; x < count; x++) { + out[x] = rng.nextDouble() * (high - low) + low; + } + return out; + } + + public static int[] randomPermutation(int count, long seed) { + //random permutation of the array 0..(count-1). + Random rng = new Random(); + if (seed != -1) { + rng.setSeed(seed); + } + + int[] out = new int[count]; + for (int x = 0; x < count; x++) { + out[x] = x; + } + for (int x = 0; x < count - 1; x++) { + int takeFrom = rng.nextInt(count - x) + x; + int tmp = out[takeFrom]; + out[takeFrom] = out[x]; + out[x] = tmp; + } + return out; + } + + public static ArrayList randomiseArray(ArrayList in, long seed) { + //alternatively, Collections.shuffle(in, new Random(seed)) + ArrayList out = new ArrayList(); + int[] r = randomPermutation(in.size(), seed); + for (int i : r) { + out.add(in.get(i)); + } + return out; + } + + public static ArrayList arrayToArrayList(int[] in) { + ArrayList out = new ArrayList<>(); + for (int i : in) { + out.add(i); + } + return out; + } + + public static ArrayList arrayToArrayList(double[] in) { + ArrayList out = new ArrayList<>(); + for (double d : in) { + out.add(d); + } + return out; + } + + public static int[] arrayListToArrayInt(ArrayList in) { + int[] out = new int[in.size()]; + int x = 0; + for (Integer i : in) { + out[x] = i.intValue(); + x++; + } + return out; + } + + public static double[] arrayListToArrayDouble(ArrayList in) { + double[] out = new double[in.size()]; + int x = 0; + for (Double d : in) { + out[x] = d.doubleValue(); + x++; + } + return out; + } + + public static String toString(int[] in) { + if (in.length == 0) { + return ""[]""; + } + String s = ""[""; + for (int x = 0; x < in.length - 1; x++) { + s += in[x] + "", ""; + } + s += in[in.length - 1] + ""]""; + return s; + } + + public static String toString(double[] in) { + if (in.length == 0) { + return ""[]""; + } + String s = ""[""; + for (int x = 0; x < in.length - 1; x++) { + s += in[x] + "", ""; + } + s += in[in.length - 1] + ""]""; + return s; + } + + public static String toString(int[][] in) { + if (in.length == 0) { + return ""[]""; + } + String s = ""[""; + for (int x = 0; x < in.length - 1; x++) { + s += toString(in[x]) + "", ""; + } + s += toString(in[in.length - 1]) + ""]""; + return s; + } + + public static String toString(double[][] in) { + if (in.length == 0) { + return ""[]""; + } + String s = ""[""; + for (int x = 0; x < in.length - 1; x++) { + s += toString(in[x]) + "", ""; + } + s += toString(in[in.length - 1]) + ""]""; + return s; + } +} +" +A20129,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + + +public class main3 { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader m = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(m.readLine()); + + for (int i = 0; i < n; i++) { + String cas = m.readLine(); + String [] a = cas.split("" ""); + int nofGoogler = Integer.parseInt(a[0]); + int nofsurprising = Integer.parseInt(a[1]); + int p = Integer.parseInt(a[2]); + int check = (3*p) - 2; + if (nofsurprising >0) + check -=2; + int count = 0 ; + int co = 0 ; + for (int j = 3; j < a.length; j++) { + int c = Integer.parseInt(a[j]); + if (c >= p && c >=check ){ + count++; + if(nofsurprising >0 && c < (check+2)) + co++; + } + } + if (co > nofsurprising) + count -= (co-nofsurprising); + System.out.print(""Case #""+(i+1)+"": ""+count); + + System.out.print(""\n""); + } + + } + +} +" +A20586,"import java.io.BufferedReader; +import java.io.InputStreamReader; + +/** + * + * @author andy + */ +public class DancingWithGooglers { + + public static void main(String[] args) throws Exception { + + //char sd = '1'; + //int[] sdf = new int[ 10 ]; + + //System.out.println( Math.ceil( 17 / 3.0 ) ); + + String map = ""yhesocvxduiglbkrztnwjpfmaq""; + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + String s = in.readLine(); + + int numTestCases = Integer.parseInt(s); + + for( int testCase = 1 ; testCase <= numTestCases ; testCase ++ ) + { + String strCase = in.readLine(); + + String[] arrCase = strCase.split("" ""); + + int count = 0; + + int numDancers = Integer.parseInt( arrCase[ 0 ] ); + int numSurprises = Integer.parseInt( arrCase[ 1 ] ); + int cutoff = Integer.parseInt( arrCase[ 2 ] ); + + for( int i = 0 ; i < numDancers ; i ++ ) + { + int score = Integer.parseInt(arrCase[ i + 3 ]); + + int modThree = score % 3; + + int divThree = score / 3; + + if( modThree > 0 ) divThree ++; + + if( divThree >= cutoff ) + { + count ++; + }else if( numSurprises > 0 && (modThree == 0 || modThree == 2) && divThree > 1 && divThree + 1 >= cutoff) + { + numSurprises --; + count ++; + } + + } + + System.out.println(""Case #"" + testCase + "": "" + count); + + } + } +}" +A22664,"import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintWriter; + +public class Googlers { + public static void main(String[] args) throws Exception { + BufferedReader input = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter output = new PrintWriter(new FileOutputStream(""output_large.txt"")); + + int T = Integer.parseInt(input.readLine()); + String line; + String[] Ts = new String[103]; + + int N, S, P, M, Ti; + + for (int i = 1; i <= T; i++) { + line = input.readLine(); + Ts = line.split("" ""); + N = Integer.parseInt(Ts[0]); + S = Integer.parseInt(Ts[1]); + P = Integer.parseInt(Ts[2]); + M = 0; + + for (int j = 0; j < N; j++) { + Ti = Integer.parseInt(Ts[j+3]); + if (P == 0) { + M++; + } else if(Ti > 0) { + if (Ti >= 3*P-2) { + M++; + } else if (Ti >= 3*P-4 && S > 0) { + M++; + S--; + } + } + } + + output.println(""Case #"" + i + "": "" + M); + } + + input.close(); + output.close(); + } +} +" +A20689,"package qualification.b; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +/** + * + * Problem + +You're watching a show where Googlers (employees of Google) dance, and then each dancer is given a triplet of scores by three judges. Each triplet of scores consists of three integer scores from 0 to 10 inclusive. The judges have very similar standards, so it's surprising if a triplet of scores contains two scores that are 2 apart. No triplet of scores contains scores that are more than 2 apart. +For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. +The total points for a Googler is the sum of the three scores in that Googler's triplet of scores. The best result for a Googler is the maximum of the three scores in that Googler's triplet of scores. Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? +For example, suppose there were 6 Googlers, and they had the following total points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising triplets of scores, and you want to know how many Googlers could have gotten a best result of 8 or better. +With those total points, and knowing that two of the triplets were surprising, the triplets of scores could have been: +10 9 10 +6 6 8 (*) +2 3 3 +6 6 6 +6 6 6 +6 7 8 (*) +The cases marked with a (*) are the surprising cases. This gives us 3 Googlers who got at least one score of 8 or better. There's no series of triplets of scores that would give us a higher number than 3, so the answer is 3. + +Input +The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing integers separated by single spaces. The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. + +Output +For each test case, output one line containing ""Case #x: y"", where x is the case number (starting from 1) and y is the maximum number of Googlers who could have had a best result of greater than or equal to p. + +Limits +1 ≤ T ≤ 100. +0 ≤ S ≤ N. +0 ≤ p ≤ 10. +0 ≤ ti ≤ 30. +At least S of the ti values will be between 2 and 28, inclusive. +Small dataset +1 ≤ N ≤ 3. +Large dataset +1 ≤ N ≤ 100. +Sample + +Input +4 +3 1 5 15 13 11 +3 0 8 23 22 21 +2 1 1 8 0 +6 2 8 29 20 8 18 18 21 +Output +Case #1: 3 +Case #2: 2 +Case #3: 1 +Case #4: 3 + + + * 2012.04.14. 15:09 - 15:44 + * @author Chei + */ +public class DancingWithTheGooglers { + Scanner scanner; + public static void main(String[] args) throws FileNotFoundException { + new DancingWithTheGooglers().solve(); + } + + void solve() throws FileNotFoundException { + scanner = new Scanner(new File(""resources/B-large.in"")); + //scanner = new Scanner(new File(""resources/B-example.in"")); + int numberOfTestCases = scanner.nextInt(); + for (int testCaseIndex = 1; testCaseIndex <= numberOfTestCases; testCaseIndex++) { + int result = solveTestCase(); + System.out.format(""Case #%d: %d%n"", testCaseIndex, result); + } + } + + int solveTestCase() { + int dancerCount = scanner.nextInt(); + int surpriseCount = scanner.nextInt(); + int bestResultToReach = scanner.nextInt(); + int result = 0; + for (int i = 1; i <= dancerCount; i++) { + int totalPoints = scanner.nextInt(); + + int margin = 3 * (bestResultToReach - 1); + // enough points without surprise + if (totalPoints > margin) { + result++; + } else { + if (surpriseCount > 0 && totalPoints > 0 && totalPoints + 2 > margin) { + result++; + surpriseCount--; + } + } + } + return result; + } +} +" +A20926,"import java.util.*; +import java.io.*; + +public class B{ + void solve() throws FileNotFoundException{ + File fin = new File(""data.in""); + File fout = new File(""data.out""); + Scanner cin = new Scanner(fin); + PrintWriter cout = new PrintWriter(fout); + + int T, n, s, p; + T = cin.nextInt(); + for(int k = 0; k < T; k++){ + n = cin.nextInt(); s = cin.nextInt(); p = cin.nextInt(); + int [] num = new int[n]; + for(int i = 0; i < n; i++) num[i] = cin.nextInt(); + int ans = 0; + for(int i = 0; i < n; i++){ + if(num[i]/3>=p || (num[i]%3>0 && num[i]/3+1>=p)){ + ans++; + continue; + } + if(num[i]%3==2 && num[i]/3+2>=p && s>0){ + s--; + ans++; + } + if(num[i]%3==0 && num[i]/3+1>=p && num[i]/3>0 && s>0){ + s--; + ans++; + } + } + cout.printf(""Case #%d: %d\n"", k+1, ans); + } + + cout.flush(); + } + public static void main(String [] args) throws Exception{ + B test = new B(); + test.solve(); + } +} + + + + + + + + + + + + +" +A22073,"package hk.polyu.cslhu.codejam.thread; + +import hk.polyu.cslhu.codejam.lib.ResultCollector; +import hk.polyu.cslhu.codejam.solution.Solution; +import hk.polyu.cslhu.codejam.solution.impl.StoreCredit; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.apache.log4j.Logger; + +public class JamThreadManager { + public static Logger logger = Logger.getLogger(JamThreadManager.class); + + private final ExecutorService pool; + private Solution solutionPrototype; + private List> testCaseList; + private boolean allowMultiThreads; + private int numOfThreads; + private ResultCollector resultCollector; + + /** + * Constructs an instance of JamThreadManager + * + * @param solutionPrototype Solution The prototype of solution + * @param testCaseList List> The data of test cases + * @param resultFile String The location of result file + * @param allowMultiThreads boolean The multi-threads mode is enabled if true; otherwise single thread is used + */ + public JamThreadManager( + Solution solutionPrototype, List> testCaseList, String resultFile, String resultPattern, boolean allowMultiThreads) { + this.pool = Executors.newCachedThreadPool(); + this.solutionPrototype = solutionPrototype; + this.testCaseList = testCaseList; + this.allowMultiThreads = allowMultiThreads; + this.numOfThreads = this.allowMultiThreads ? Runtime.getRuntime().availableProcessors() : 1; + this.resultCollector = new ResultCollector(testCaseList.size(), resultFile, resultPattern); + } + + /** + * Initialize the threads to set off + * @throws CloneNotSupportedException + */ + public void runThreads() throws CloneNotSupportedException { + List>> subTasks = this.divideTestCases(); + int testCaseIndex = 1; + + for (List> subTask : subTasks) { + JamThread jamThread = this.createJamThread(); + jamThread.setSolution(this.solutionPrototype.clone()); + jamThread.setIndexOfList(testCaseIndex); + jamThread.setTestCaseList(subTask); + jamThread.setResultCollector(this.resultCollector); + + // update testCaseIndex + testCaseIndex++; + + // run the thread + this.pool.execute(jamThread); + } + } + + /** + * Divide the test cases into numOfThreads pieces + * + * @return List>> The subtasks + */ + private List>> divideTestCases() { + // TODO Auto-generated method stub + List>> subTasks = new ArrayList>>(); + + // set the number of test cases per subtask + int numOfTestCasesPerSubtask = this.testCaseList.size(); + + if (this.allowMultiThreads) { + if (this.testCaseList.size() < this.numOfThreads) + numOfTestCasesPerSubtask = 1; + else + numOfTestCasesPerSubtask = (int) Math.floor(this.testCaseList.size() / this.numOfThreads); + } + + // dive the test case list + for (int i = 0; i < Math.min(this.testCaseList.size(), this.numOfThreads); i++) { + int fromIndex = i * numOfTestCasesPerSubtask; + int toIndex = (i == this.numOfThreads - 1) ? this.testCaseList.size() : (i + 1) * numOfTestCasesPerSubtask; + subTasks.add(this.testCaseList.subList(fromIndex, toIndex)); + } + + return subTasks; + } + + // Factory method of creating jam thread + private JamThread createJamThread() { + // TODO Auto-generated method stub + return new JamThread() { + + @Override + public void run() { + // TODO Auto-generated method stub + List result = new ArrayList(); + + for (List testCase : this.getTestCaseList()) { + this.getSolution().setProblem(testCase); + this.getSolution().solve(); + result.add(this.getSolution().getResult()); + } + + this.getResultCollector().updateResult(this.getIndexOfList(), result); + } + }; + } +} +" +A21680,"import java.io.File; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + static int[] arr = new int[32]; + + public static void main(String[] args) throws Exception { + Scanner s = new Scanner(new File(""B.in"")); + PrintWriter out = new PrintWriter(new File(""B.out"")); + + int T = s.nextInt(); + for (int tc = 1; tc <= T; tc++) { + out.print(""Case #"" + tc + "": ""); + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + + Arrays.fill(arr, 0); + for (int i = 0; i < N; i++) arr[s.nextInt()]++; + int ans = 0; + for (int i = Math.max(3 * p - 2, 0); i <= 30; i++) ans += arr[i]; + int potential = 0; + if (3 * p - 4 >= 2) potential += arr[3 * p - 4]; + if (3 * p - 3 >= 2) potential += arr[3 * p - 3]; + System.out.println(potential); + ans += Math.min(potential, S); + out.println(ans); + } + out.close(); + } +} +" +A20147,"import java.io.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.StringTokenizer; + +/** + * Created by IntelliJ IDEA. + * User: 875k + * Date: 4/14/12 + * Time: 12:08 AM + * To change this template use File | Settings | File Templates. + */ +public class prQB { + public static boolean notSurprising(int a, int b, int c) { + return Math.abs(a - b) <= 1 && Math.abs(a - c) <= 1 && Math.abs(b - c) <= 1; + } + public static boolean surprising(int a, int b, int c) { + return !notSurprising(a, b, c) && Math.abs(a - b) <= 2 && Math.abs(a - c) <= 2 && Math.abs(b - c) <= 2; + } + public static int[] points; + public static int[] surpriseMax; + public static int[] normalMax; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(""prQB.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""prQB.out""))); + points = new int[101]; + surpriseMax = new int[101]; + normalMax = new int[101]; + int T = Integer.parseInt(br.readLine()); + for(int i = 0; i < T; i++) { + Arrays.fill(points, -1); + Arrays.fill(surpriseMax, -1); + Arrays.fill(normalMax, -1); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + for(int j = 0; j < N; j++) { + points[j] = Integer.parseInt(st.nextToken()); + boolean found = false, founds = false; + for(int a = Math.min(10, points[j]); a >= 0 && !(found && founds); a--) { + for(int b = Math.max(0, points[j] - a); b >= 0; b--) { + int c = points[j] - a - b; + if(notSurprising(a, b, c) && a >= normalMax[j]) { + found = true; + normalMax[j] = a; + } + if(surprising(a, b, c) && a >= surpriseMax[j]) { + founds = true; + surpriseMax[j] = a; + } + } + } + } + //for(int j = 0; j < N; j++) { System.out.print(points[j] + ""-"" + normalMax[j] + ""-"" + surpriseMax[j] + "", ""); } System.out.println(); + HashSet hs = new HashSet(); + for(int j = 0; j < N && S > 0; j++) { + if(surpriseMax[j] >= p && normalMax[j] < p) { + hs.add(j); + S--; + } + } + int c = hs.size(); + for(int j = 0; j < N; j++) { + if(normalMax[j] >= p && !hs.contains(j)) c++; + } + out.println(""Case #"" + (i + 1) + "": "" + c); + } + out.close(); + System.exit(0); + } +} +" +A21791,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dance; + +/** + * + * @author ALEX + */ +public class Scores { + int first; + int second; + int third; + int total; + boolean s; + public Scores(int total) + { + this.total=total; + } + public int getMaxS() + { + int max=0; + for(int i=0;i<=10;i++) + for(int j=i;(j<=i+2)&&(j<=10);j++) + for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) + if((i+j+k==total)&&(i+2==j||i+2==k)){ + if(i>max) + max=i; + if(j>max) + max=j; + if(k>max) + max=k; + } + return max; + } + public int getMaxUnS() + { + int max=0; + for(int i=0;i<=10;i++) + for(int j=i;(j<=i+2)&&(j<=10);j++) + for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) + if((i+j+k==total)&&(i+2!=j&&i+2!=k)){ + if(i>max) + max=i; + if(j>max) + max=j; + if(k>max) + max=k; + } + return max; + } + public void setFirstSurprize() + { + for(int i=0;i<=10;i++) + for(int j=i;(j<=i+2)&&(j<=10);j++) + for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) + if((i+j+k==total)&&(i+2==j||i+2==k)){ + first=i; + second=j; + third=k; + s=true; + return; + } + } + public void setFirstNormal(){ + for(int i=1;i<=10;i++) + for(int j=i;(j<=i+2)&&(j<=10);j++) + for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) + if((i+j+k==total)&&(i+2==j||i+2==k)){} + else { + first=i; + second=j; + third=k; + s=false; + return; + } + } +} +" +A22206,"package br.com.atama.google.jam.dancing; + +public enum Context { + INSTANCE; + + private int numSurprises; + private int threshold; + + public int getNumSurprises() { + return numSurprises; + } + + public void setNumSurprises(int numSurprises) { + this.numSurprises = numSurprises; + } + + public int getThreshold() { + return threshold; + } + + public void setThreshold(int threshold) { + this.threshold = threshold; + } + +} +" +A21612,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + + +public class CodeJamWriter implements ICounterZeroEvent{ + + //public static String inputFile = ""C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\A-test""; + //public static String inputFile = ""C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\A-small-attempt0""; + //public static String inputFile = ""C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\B-test""; + //public static String inputFile = ""C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\B-small-attempt0""; + public static String inputFile = ""C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\B-large""; + + public int T; + public Result[] results; + + public static void main(String[] args) { + CodeJamWriter codeJamWriter = new CodeJamWriter(); + codeJamWriter.readInput(); + } + + private void readInput() { + Scanner scanner = null; + File input = new File(inputFile+"".in""); + try { + scanner = new Scanner(input); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + T = scanner.nextInt(); + scanner.nextLine(); + results = new Result[T+1]; + Counter counter = new Counter(T, this); + for (int i=1;i<=T;++i) + { + results[i] = new Result(i); + Question q = new QuestionB(results[i], counter); + q.readInput(scanner); + q.start(); + } + scanner.close(); + } + + private void writeOutput() { + FileOutputStream fos = null; + PrintStream printer = null; + File output = new File(inputFile+"".out""); + try { + fos = new FileOutputStream(output); + printer = new PrintStream(fos); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + for (int i=1;i<=T;++i) + { + printer.println(results[i]); + } + System.out.println(""FINISHED!!!""); + + printer.close(); + + } + + @Override + public void fireEvent() { + writeOutput(); + } + +} +" +A20523,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Qualifier2012.b; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; + +/** + * + * @author Ant Ongun Kefeli + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + FileInputStream fis = new FileInputStream(""src\\Qualifier2012\\b\\B-large.in""); + Scanner sc = new Scanner(fis); + + FileWriter fw = new FileWriter(""src\\Qualifier2012\\b\\output.out""); + BufferedWriter out = new BufferedWriter(fw); + + int caseCount = 0; + caseCount = sc.nextInt(); + for (int i = 0; i < caseCount; i++) { + int numberOfGoogler = sc.nextInt(); + int[] googlers = new int[numberOfGoogler]; + int numberOfSurprising = sc.nextInt(); + int limit = sc.nextInt(); + for (int j = 0; j < numberOfGoogler; j++) { + googlers[j] = sc.nextInt(); + } + + doit(out, i + 1, googlers, numberOfSurprising, limit); + + } + + out.close(); + sc.close(); + } + + private static void doit(BufferedWriter out, int casec, int googlers[], int numberOfSurprising, int limit) throws IOException { + + int res = 0; + int surp = 0; + for (int i = 0; i < googlers.length; i++) { + int j1; + int dancer = googlers[i]; + if (dancer % 3 == 0) { + j1 = dancer / 3; + if (j1 <= 10 && j1 >= limit) { + res++; + } else if (j1 == limit - 1 && j1 >= 1 && surp < numberOfSurprising) { + res++; + surp++; + } + } else if (dancer % 3 == 1) { + j1 = dancer / 3 + 1; + if (j1 <= 10 && j1 >= limit) { + res++; + } + } else if (dancer % 3 == 2) { + j1 = dancer / 3 + 1; + if (j1 <= 10 && j1 >= limit) { + res++; + } else if (j1 == limit - 1 && surp < numberOfSurprising) { + res++; + surp++; + } + } + + } + + out.write( + ""Case #"" + casec + "": "" + res + ""\n""); + } +} +" +A20250,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package codejam2012; + +import java.util.Scanner; + +/** + * + * @author Kumudu + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + String out=""""; + Scanner in = new Scanner(System.in); + String read = in.nextLine(); + int N = Integer.valueOf(read); + for (int i = 0; i < N; i++) { + read = in.nextLine(); + String [] str_vals = read.split("" ""); + int sup = Integer.valueOf(str_vals[1]); + int min = Integer.valueOf(str_vals[2]); + int min_tot = 3*min - 4; + if(min<=1){ + min_tot = min; + } + int both=0; + int non_sup=0; + for (int j = 3; j < str_vals.length; j++) { + if(Integer.valueOf(str_vals[j]) >= min_tot){ + both++; + } + if(Integer.valueOf(str_vals[j]) >= (min_tot+2)){ + non_sup++; + } + } + if(min>=2){ + System.out.println(""Case #""+(i+1)+"": ""+(non_sup + Math.min(sup, (both-non_sup)))); + } + if(min<=1){ + //System.out.println(""ddr""); + System.out.println(""Case #""+(i+1)+"": ""+both); + } + } + + } + +} +" +A21506,"package dancingwiththegooglers; + +import java.util.ArrayList; +import java.util.List; + +public class TestCase { + int numberOfGooglers; + public int getNumberOfGooglers() { + return numberOfGooglers; + } + public int getSurprisingScores() { + return surprisingScores; + } + public int getBestResult() { + return bestResult; + } + int surprisingScores; + int bestResult; + + List scores = null; + + public TestCase(int numberOfGooglers, int surprisingScores, int bestResult, List scores){ + this.numberOfGooglers = numberOfGooglers; + this.surprisingScores = surprisingScores; + this.bestResult = bestResult; + this.scores = new ArrayList(scores); + } + + public int execute(){ + int bestScorers = 0; + for(int score : this.scores){ + if(canItBeTheBestScorer(score, bestResult)) + bestScorers++; + } + return bestScorers; + } + private boolean canItBeTheBestScorer(int score, int bestResult2) { + if(score < bestResult2) + return false; + if(bestResult2 == 0) + return true; + if(bestResult2 == 1) + if(score > 0) + return true; + else + return false; + if(score >= (bestResult2 * 3) - 2){ + return true; + }else if(score >= (bestResult2 * 3) - 4){ + if(this.surprisingScores > 0){ + this.surprisingScores--; + return true; + } + return false; + } + return false; + } + +} +" +A22707,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Arrays; + +public class B { + BufferedReader in; + BufferedWriter out; + static String inputFile = ""B-large.in""; + static String outputFile = ""B-large.out""; + + public String readWord() throws Exception { + int c = in.read(); + while (c>=0 && c<=' ') { + c = in.read(); + } + if (c < 0) { + return """"; + } + StringBuilder builder = new StringBuilder(); + while( c > ' ' ) { + builder.append((char)c); + c = in.read(); + } + return builder.toString(); + } + + public int nonsurpMax(int totalP) { + int result = totalP/3; + if (totalP - result*3 > 0) result++; + return result; + } + + public void solve() throws Exception { + int cases = Integer.parseInt(readWord()); + for (int i = 0; i= p) count++; + if ((max<10) && (max > 0) && (max == p-1) && (S>0)) { + count++; + S--; + } + } + builder.append("""" + count); + if (i < cases-1) builder.append(""\n""); + out.write(builder.toString()); + } + } + + public static void main(String[] args) { + B start = new B(); + start.run(); + } + + public void run() { + try { + in = new BufferedReader(new FileReader(inputFile)); + out = new BufferedWriter(new FileWriter(outputFile)); + solve(); + out.flush(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +} +" +A21917,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class Drugi { + + public static void main (String [] args) throws IOException { + + PrintWriter out2 = new PrintWriter(new BufferedWriter(new FileWriter(""output.txt""))); + Input in= new Input(new FileInputStream(new File(""B-large.in""))); + //BufferedReader in = new BufferedReader(new FileReader(""Asmall.in"")); + + + int t= in.readInt(); + int n,s,p,zbroj,irr, m; + + for(int i=0; i=3*p-2) zbroj++; + else if(m>=3*p-4) irr++; + } + zbroj += min(irr,s); + out2.print(""Case #""); + out2.print(i+1); + out2.print("": ""); + out2.println(zbroj); + out2.flush(); + } + } + + private static int min(int irr, int s) { + if(irr>s) return s; + return irr; + } +} +" +A20845,"import java.util.Scanner; + + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + + int T=in.nextInt(); + for(int t=1; t<=T; t++) { + int max=0; + + int N = in.nextInt(), S = in.nextInt(); + int p = in.nextInt(); + + int sMin = (p==0)?0:(3*p-2); + int strictMin = (p<=2)?p:(3*p-4); + + while(N-->0) { + int s = in.nextInt(); + if(s >= sMin) + max++; + else if(s >= strictMin && S>0) { + max++; + S--; + } + } + + System.out.println(""Case #""+t+"": ""+max); + } + } +} +" +A21577,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.common; + +import java.io.IOException; + +/** + * + * @author jim + */ +public class AbstractMain { + public static void main(String[] args, AbstractProcessor p) { + + FileLoader fileLoader = new FileLoader(); + try { + Input input = new Input(fileLoader.loadFile(args[0]), 1); + Output output = p.process(input); + output.export(args.length < 2 ? null : args[1]); + } + catch (IOException ioe) { + System.out.println(ioe); + ioe.printStackTrace(); + } + } +} +" +A21880,"package codejam; + +import java.util.HashMap; +import java.util.Scanner; + +public class DanceScores { + + public static void main(String[] args) { + HashMap best = new HashMap(); + best.put(1 , new int[]{1,1}); + best.put(2 , new int[]{2,3}); + best.put(3 , new int[]{4,6}); + best.put(4 , new int[]{7,9}); + best.put(5 , new int[]{10,12}); + best.put(6 , new int[]{13,15}); + best.put(7 , new int[]{16,18}); + best.put(8 , new int[]{19,21}); + best.put(9 , new int[]{22,24}); + best.put(10, new int[]{25,27}); + + Scanner in = new Scanner(System.in); + int cases = in.nextInt(); + for(int i=1; i<=cases; i++){ + int n = in.nextInt(); //Number of scores + int s = in.nextInt(); //Number of surprising score triplets + int p = in.nextInt(); //The minimum criterion + + /********* Boundary Cases ********/ + if(p==0){ + System.out.println(""Case #""+i+"": ""+n); + in.nextLine(); //Ignore remaining line + continue; + } + + int[] range = best.get(p); //The range where the best score p can be achieved only in case of surprising triplet. + int definite = 0, probable=0; + + for(int j=0;j=range[0] && score <=range[1]) + probable++; + else if(score>range[1]) + definite++; + } + System.out.println(""Case #""+i+"": ""+(definite+Math.min(probable, s))); + } + } + +} +" +A22381,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.TreeMap; + + +public class DancingWithGooglers { + + public static int isPossible(int score, int pointUnderConsideration, + int surprisingTriplets) + { + int twoScore = score - pointUnderConsideration; + + if (twoScore < 0) { + return 0; + } + + // pt_under_con = 4; total score = 24; 8 8 8; 24 - 4 >= 2*4; + if (twoScore >= pointUnderConsideration * 2) { + return 1; + } + + // 8 7 7; pt under consideration is 8; 16 - 14 <= 2; + if ((pointUnderConsideration * 2) - twoScore <= 2) { + return 1; + } + + if ((pointUnderConsideration * 2) - twoScore > 2 && + (pointUnderConsideration * 2) - twoScore <=4 && + surprisingTriplets > 0) + { + return 2; + } + return 0; + } + + public static int parseTestCase(String line) + { + String [] splitLine = line.split("" ""); + + int numGooglers = Integer.parseInt(splitLine[0]); + int surprisingTriplets = Integer.parseInt(splitLine[1]); + int minPt = Integer.parseInt(splitLine[2]); + + int toRet = 0; + + for (int i = 0 + 3; i < numGooglers + 3; i++) { + int score = Integer.parseInt(splitLine[i]); + + int retValOfFun = DancingWithGooglers.isPossible(score, minPt, surprisingTriplets); + if (retValOfFun > 0) { + toRet++; + } + if (retValOfFun == 2) { + surprisingTriplets--; + } + } + return toRet; + } + + public static void main(String [] args) throws IOException + { +// System.out.println(DancingWithGooglers.parseTestCase(""2 1 1 8 0"")); + + DataInputStream in = new DataInputStream(System.in); + + + System.out.println(""Enter the input file name : ""); + String fileName = in.readLine(); + + BufferedReader br = new BufferedReader(new FileReader(fileName)); + + BufferedWriter bw = new BufferedWriter(new FileWriter(""c:/gcj/myOp2.txt"")); + + int numCases = Integer.parseInt(br.readLine()); + + + for (int i = 0; i < numCases; i++) { + String line = br.readLine(); + bw.write(""Case #"" + (i+1) + "": "" + DancingWithGooglers.parseTestCase(line) + ""\n""); + } + bw.close(); + br.close(); + } +} + " +A22939,"import java.io.*; +import java.util.*; + +public class Dance +{ + public static void main(String[] args) throws IOException + { + Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new File(""dance_large.in"")); + //Scanner in = new Scanner(System.in); + + int runs = Integer.parseInt(in.nextLine().trim()); + int count = 0; + while(++count <= runs) + { + out.print(""Case #"" + count + "": ""); + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] scores = new int[n]; + + for(int i = 0; i < n; i++) + scores[i] = in.nextInt(); + + int min = Math.max(p, (p*3)-2); + int surprise = Math.max(p, (p*3)-4); + + int num = 0; + for(int i = 0; i < n; i++) { + if(scores[i] >= min) + num++; + else if(scores[i] >= surprise && s > 0) { + num++; + s--; + } + } + + out.println(num); + } + + out.close(); + } +} +" +A22358,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class DancingGooglers { + + public static int num (int c,int p,int [] g){ + int n = 0; + for (int i =0;i=p+p+p-2){ + n++; + } + else if (g[i]>=p+p+p-4){ + if (c>0){ + n++; + c--; + } + } + } + return n; + } + + public static void main (String [] args) throws NumberFormatException, IOException{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + int t = Integer.parseInt(br.readLine()); + for (int i =0;i1){ + System.out.printf(""Case #%d: %d\n"",i+1,num(c,p,g)); + } + else { + int n = 0; + for (int j =0;j=p+p+p-2){ + n++; + } + } + System.out.printf(""Case #%d: %d\n"",i+1,n); + } + } + } +} +" +A22496,"package aao; + +import java.io.*; +import java.util.regex.Pattern; + +/** + * @author aoboturov + */ +public class DansingWithGooglers { + + public LineNumberReader lineNumberReader; + + public DansingWithGooglers(final String inputFileName) throws Exception { + lineNumberReader = new LineNumberReader( + new BufferedReader( + new InputStreamReader( + getClass().getClassLoader().getResourceAsStream(inputFileName) + ) + )); + } + + public int readNumberOfTestCases() throws Exception { + return Integer.parseInt(lineNumberReader.readLine()); + } + + public void solve(final String outputFileName) throws Exception { + final FileOutputStream fos = new FileOutputStream(new File(outputFileName)); + + final int numberOfTestCases = readNumberOfTestCases(); + final Pattern pattern = Pattern.compile(""[\\s]+""); + for ( int caseNumber = 1; caseNumber <= numberOfTestCases; caseNumber++) { + // Init of counters. + int guaranteedNumberOfGooglersHavingBestResult = 0; + int holdOutNumberOfGooglersHavingBestResult = 0; + // Init of base parameters. + final String[] splitInput = pattern.split(lineNumberReader.readLine()); + final int numberOfGooglers = Integer.parseInt(splitInput[0]); + final int numberOfSurprises = Integer.parseInt(splitInput[1]); + final int requiredBestResult = Integer.parseInt(splitInput[2]); + // Compute required values. + for ( int googler = 0; googler < numberOfGooglers; googler++) { + final int googlerScore = Integer.parseInt(splitInput[3 + googler]); + // Filter evident cases: + if ( googlerScore >= 3*requiredBestResult) { + guaranteedNumberOfGooglersHavingBestResult++; + continue; + } + if ( googlerScore <= (3*requiredBestResult - 5)) { + continue; + } + // case p=k,k,k + if ( googlerScore == (3*requiredBestResult - 0)) { + guaranteedNumberOfGooglersHavingBestResult++; + continue; + } + // case p=k,k+1,k+1 + if ( googlerScore == (3*requiredBestResult - 1) && (googlerScore - 2) >= 0) { + guaranteedNumberOfGooglersHavingBestResult++; + continue; + } + // case p=k,k,k+1 + if ( googlerScore == (3*requiredBestResult - 2) && (googlerScore - 1) >= 0) { + guaranteedNumberOfGooglersHavingBestResult++; + continue; + } + // case p=k,k+1,k+2 + if ( googlerScore == (3*requiredBestResult - 3) && (googlerScore - 3) >= 0) { + holdOutNumberOfGooglersHavingBestResult++; + continue; + } + // case p=k,k+2,k+2 + if ( googlerScore == (3*requiredBestResult - 4) && (googlerScore - 2) >= 0) { + holdOutNumberOfGooglersHavingBestResult++; + continue; + } + } + final StringBuilder sb = new StringBuilder(""Case #"").append(caseNumber).append("": "") + .append(guaranteedNumberOfGooglersHavingBestResult+Math.min(holdOutNumberOfGooglersHavingBestResult, numberOfSurprises)) + .append(""\n""); + System.out.print(sb.toString()); + fos.write(sb.toString().getBytes()); + } + } + + + public static void main(String args[]) throws Exception { + new DansingWithGooglers(""B-large.in.txt"").solve(""output.xml""); + } +} +" +A20744,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + + +public class Dance { + + /* Returns pair (max if not surprising, max if surprising */ + private static int[] max(int score) { + int max, maxsurpr; + + if(score == 0) { + max = 0; + maxsurpr = 0; + } else if(score == 1) { + max = 1; + maxsurpr = 1; + } else if(score == 2) { + max = 1; + maxsurpr = 2; + } else if((score % 3) == 0) { + max = score/3; + maxsurpr = score/3 + 1; + } else if((score % 3) == 1) { + max = score/3 + 1; + maxsurpr = score/3 + 1; + } else { + max = score/3 + 1; + maxsurpr = score/3 + 2; + } + + return new int[] {max, maxsurpr}; + } + + private static int process(String l) { + String[] parts = l.split("" ""); + int N = Integer.parseInt(parts[0]); + int S = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + + if(parts.length != N+3) { + System.err.println(""Error: "" + l); + } + + int good = 0; + + for(int i=0; i= p) good++; + else { + if(max[1] >= p && S > 0) { + good++; + S--; + } + } + } + + return good; + } + + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(args[0])); + PrintWriter out = new PrintWriter(args[1]); + + // number of testcases + String sCount = in.readLine(); + int count = Integer.parseInt(sCount); + + for(int idx=1; idx<=count; idx++) { + String l = in.readLine(); + out.println(""Case #"" + idx + "": "" + process(l)); + } + + out.close(); + } + +} +" +A20176,"package codejam; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +public class fileHandler { + FileInputStream input; + FileOutputStream output; + BufferedReader buf; + public fileHandler(String in, String out) { + try { + input = new FileInputStream(in); + + output = new FileOutputStream(out); + buf = new BufferedReader(new InputStreamReader(input)); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public String readLineFromInput(){ + String str = null; + try { + str = buf.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return str; + } + public int readCase(){ + int i = -1; + String str = null; + try { + str = buf.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + i = Integer.parseInt(str); + return i; + } + + public int[] readIntegers(){ + int temp[]; + String str = null; + try { + str = buf.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String split[] = str.split("" ""); + temp = new int[split.length]; + for(int i=0;i=(3*p-2)) { + max++; + } + else if (t>=(3*p-4) && p>=2 && S!=0) { + max++; + S--; + } + } + out.println(""Case #""+i+"": ""+max); + } + + in.close(); + out.flush(); + out.close(); + + } +} +" +A22621,"package qualification; + +import java.util.ArrayList; +import java.util.List; + +import loader.InputReader; +import loader.OutPutWriter; + +public class GoogleDance { + + static String inputName = ""B-large.in""; + + /** + * @param args + */ + public static void main(String[] args) { + start(); + + } + + public static void start(){ + InputReader reader = new InputReader(); + reader.read(inputName); + List inputs = reader.getInputs(); + List outputs = new ArrayList(); + for(String in: inputs){ + List aLine = transfer(in); + int out = process(aLine); + outputs.add(new Integer(out).toString()); + } + + OutPutWriter writer = new OutPutWriter(); + writer.write(""question2_large.out"", outputs); + } + + + public static int process(List aLine){ + int res = 0; + int number = aLine.get(0); + int avaliableSup = aLine.get(1); + int p = aLine.get(2); + + if(p == 0) + return number; + + int standard = p*3; + + int mustSuccessCounter = 0; + int needSup = 0; + for(int i=3; i= standard-2) mustSuccessCounter++; + if((t == standard-3 || t == standard-4) && (standard-3>0))needSup++; + } + + res = mustSuccessCounter + (Math.min(avaliableSup, needSup)); + + return res; + } + + private static List transfer(String s){ + List l = new ArrayList(); + String[] arrayString = s.split("" ""); + for(int i=0; i=1) res++; + } + else if (g>=p+(p-1)+(p-1)) res++; + else if (S>0 && g>=p+(p-2)+(p-2)) { + res++; + S--; + } + } + + + //StringBuffer res = new StringBuffer(); + + //System.out.println(res.toString()); + out.write(""Case #""+(i+1)+"": ""+String.valueOf(res)+""\n""); + } + } + + public static void main(String[] args) throws IOException { + try { + in = new BufferedReader(new FileReader(inFile)); + out = new BufferedWriter(new FileWriter(outFile)); + sc = new Scanner(in); + solve(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + in.close(); + out.close(); + } + + } +} + +" +A21470,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlecodejam2012; + +import java.io.FileNotFoundException; + +/** + * + * @author Pavlos + */ +public class ProblemB { + + public static void main(String[] args) throws FileNotFoundException { + Read.OpenFile(""B-large.in""); + Write.OpenFile(""solB.txt""); + int T = Read.readInt(); + for (int zz = 1; zz <= T; zz++) { + int N = Read.readInt(); + int S = Read.readInt(); + int p = Read.readInt(); + int t[] = new int[N]; + for (int i = 0; i < t.length; i++) { + t[i] = Read.readInt(); + } + int counter = 0; + for (int i = 0; i < t.length; i++) { + if(t[i] >= p){ + int temp = t[i] - 3*p; + if(temp >= -2) + counter++; + else if(temp >= -4 && temp < -2 && S > 0) + { + counter++; + S--; + } + } + + } + //counter -= S; + + if(counter > 3) + counter = 3; + Write.WriteToFile(String.format(""Case #%d: %d\n"",zz, counter)); + + }//end zz + Write.CloseFile(); + } +} + +" +A22488,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +class dance { + + int single[][] = new int[4][3]; + int doublex[][] = new int[54][3]; + + dance() { + single[0][0] = 0; + single[0][1] = 0; + single[0][2] = 0; + + single[1][0] = 0; + single[1][1] = 0; + single[1][2] = 1; + + single[2][0] = 10; + single[2][1] = 10; + single[2][2] = 9; + + single[3][0] = 10; + single[3][1] = 10; + single[3][2] = 10; + } + + int[][] gen_tuple(int num) { + int tup[][] = new int[2][3]; + if (num % 3 == 0) { + tup[0][0] = num / 3; + tup[0][1] = num / 3; + tup[0][2] = num / 3; + + tup[1][0] = num / 3 - 1; + tup[1][1] = num / 3; + tup[1][2] = num / 3 + 1; + + } else if (num % 3 == 1) { + tup[0][0] = num / 3; + tup[0][1] = num / 3; + tup[0][2] = num / 3 + 1; + + tup[1][0] = num / 3 + 1; + tup[1][1] = num / 3 + 1; + tup[1][2] = num / 3 - 1; + + } else if (num % 3 == 2) { + tup[0][0] = num / 3; + tup[0][1] = num / 3 + 1; + tup[0][2] = num / 3 + 1; + + tup[1][0] = num / 3; + tup[1][1] = num / 3; + tup[1][2] = num / 3 + 2; + + } + return tup; + } + + int maxx(int a, int b, int c) { + int temp = Math.max(a, b); + temp = Math.max(temp, c); + return temp; + + } + + public static void main(String[] args) throws IOException { + + dance my = new dance(); + for (int i = 2; i < 29; i++) { + int temp[][] = my.gen_tuple(i); + // System.out.println((i - 2) * 2); + my.doublex[(i - 2) * 2][0] = temp[0][0]; + my.doublex[(i - 2) * 2][1] = temp[0][1]; + my.doublex[(i - 2) * 2][2] = temp[0][2]; + + my.doublex[(i - 2) * 2 + 1][0] = temp[1][0]; + my.doublex[(i - 2) * 2 + 1][1] = temp[1][1]; + my.doublex[(i - 2) * 2 + 1][2] = temp[1][2]; + + // System.out.print(my.doublex[(i - 2) * 2][0] + "" ""); + // System.out.print(my.doublex[(i - 2) * 2][1] + "",""); + // System.out.print(my.doublex[(i - 2) * 2][2] + "",""); + // System.out.print(my.doublex[(i - 2) * 2 + 1][0] + "",""); + // System.out.print(my.doublex[(i - 2) * 2 + 1][1] + "",""); + // System.out.println(my.doublex[(i - 2) * 2 + 1][2] + "",""); + + } + + String Path = ""C:\\Users\\Dell\\Desktop\\B-large.in""; + Scanner read = new Scanner(new File(Path)); + + File file = new File(""C:\\Users\\Dell\\Desktop\\out.txt""); + PrintWriter Fout = new PrintWriter(new BufferedWriter(new FileWriter( + file)), true); + + String line = read.nextLine(); + int iter = 0; + + while (read.hasNextLine()) { + iter = iter + 1; + line = read.nextLine(); + + String d = ""[ ]+""; + String[] SplitD = line.split(d); + for (int x = 0; x < SplitD.length; x++) { + // System.out.println(SplitD[x]); + } + + int N = Integer.parseInt(SplitD[0]); + int S = Integer.parseInt(SplitD[1]); + int p = Integer.parseInt(SplitD[2]); + + int count = 0; + int surp = 0; + + for (int j = 0; j < N; j++) { + + int val = Integer.parseInt(SplitD[j + 3]); + + if (val < 2) { + + if (my.maxx(my.single[val][0], my.single[val][1], + my.single[val][2]) >= p) { + count += 1; + } + + } else if (val > 28) { + if (my.maxx(my.single[val - 27][0], my.single[val - 27][1], + my.single[val - 27][2]) >= p) { + count += 1; + } + } else { + if (my.maxx(my.doublex[(val - 2) * 2][0], + my.doublex[(val - 2) * 2][1], + my.doublex[(val - 2) * 2][2]) >= p) { + count += 1; + } else if (my.maxx(my.doublex[(val - 2) * 2 + 1][0], + my.doublex[(val - 2) * 2 + 1][1], + my.doublex[(val - 2) * 2 + 1][2]) >= p) { + surp += 1; + } + } + } + + if (surp > S) { + count = count + S; + } else { + count = count + surp; + } + String output_str = ""Case #"" + iter + "": "" + count; + Fout.println(output_str); + } + read.close(); + } + +}" +A22332,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.TreeMap; + +public class Gcj2 { + private static Map> pointsTripletMap = new TreeMap>(); + + private static void loadPointsTripletMap() { + for (int i = 0; i <= 30; i++) { + pointsTripletMap.put(Integer.valueOf(i), + new LinkedHashSet()); + } + + for (int a = 0; a <= 10; a++) { + for (int b = 0; b <= 10; b++) { + for (int c = 0; c <= 10; c++) { + try { + int pointsSum= a + b + c; + Triplet triplet = new Triplet(a,b,c); + pointsTripletMap.get(Integer.valueOf(pointsSum)).add( + triplet); + } catch (NotValidTripletRuntimeException ex) { + //bad practice! + } + } + } + } + } + + static { + loadPointsTripletMap(); + System.out.println(pointsTripletMap); + } + + /** + * @param args + */ + public static void main(String[] args) { + String input = args[0]; + String output = args[1]; + + try { + File fileInput = new File(input); + System.out.println(fileInput.getAbsolutePath()); + FileReader fr = new FileReader(fileInput); + BufferedReader br = new BufferedReader(fr); + + File fileOutput = new File(output); + FileWriter fw = new FileWriter(fileOutput); + BufferedWriter bw = new BufferedWriter(fw); + + String numberOfCases = br.readLine(); + Integer n = Integer.parseInt(numberOfCases.trim()); + + for (int i = 0; i < n; i++) { + int result = 0; + String line = br.readLine(); + String[] lineArgs = line.split("" ""); + int googlers = Integer.parseInt(lineArgs[0]); + int surprisingTriplets = Integer.parseInt(lineArgs[1]); + int pointsNumberMin = Integer.parseInt(lineArgs[2]); + + int[] googlersResults = new int[lineArgs.length - 3]; + for (int m = 3; m < lineArgs.length; m++) { + int mGooglerResult = Integer.parseInt(lineArgs[m]); + googlersResults[m - 3] = mGooglerResult; + } + + Arrays.sort(googlersResults); + + for (int m = 0; m < googlersResults.length; m++) { + LinkedHashSet triplets = pointsTripletMap + .get(Integer.valueOf(googlersResults[m])); + + Triplet choosenTriplet = null; + for (Triplet triplet : triplets) { + if (triplet.getC() >= pointsNumberMin) { + if (choosenTriplet == null) { + choosenTriplet = triplet; + } else if (choosenTriplet.isSurprising() + && !triplet.isSurprising()) { + choosenTriplet = triplet; + } + } + } + + if (choosenTriplet != null) { + if (!choosenTriplet.isSurprising()) { + result++; + } else if (surprisingTriplets > 0) { + result++; + surprisingTriplets--; + } + } + } + + String msg = ""Case #"" + (i + 1) + "": "" + result; + System.out.println(msg); + if (i > 0) { + bw.newLine(); + } + bw.write(msg); + + } + + bw.flush(); + bw.close(); + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} + +class Triplet { + private final int pointsA, pointsB, pointsC; + + + public Triplet(int pointsA, int pointsB, int pointsC) { + int[] ints = new int[3]; + ints[0] = pointsA; + ints[1] = pointsB; + ints[2] = pointsC; + + Arrays.sort(ints); + + if (ints[2] - ints[0] > 2) { + throw new NotValidTripletRuntimeException( + ""Points in triplet can't vary more than 2 points!""); + } + + this.pointsA = ints[0]; + this.pointsB = ints[1]; + this.pointsC = ints[2]; + } + + boolean isSurprising() { + if (pointsC - pointsA > 1) { + return true; + } else { + return false; + } + } + + public int getA() { + return pointsA; + } + + public int getB() { + return pointsB; + } + + public int getC() { + return pointsC; + } + + private int[] getMinMax(int... ints){ + int[] minMax = new int[2]; + minMax[0]=10; + minMax[1]=0; + for (int i : ints) { + minMax[0] = Math.min(minMax[0], i); + minMax[1] = Math.max(minMax[1], i); + } + return minMax; + } + + @Override + public int hashCode() { + // Using Joshua Bloch's recipe: + int result = 17; + result = 37 * result + pointsA; + result = 37 * result + pointsB; + result = 37 * result + pointsC; + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj instanceof Triplet) { + Triplet triplet = (Triplet) obj; + if (this.getA() == triplet.getA() && this.getB() == triplet.getB() + && this.getC() == triplet.getC()) { + return true; + } + } + + return false; + } + + @Override + public String toString() { + return """" + pointsA + "","" + pointsB + "","" + pointsC; + } +} + +class NotValidTripletRuntimeException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public NotValidTripletRuntimeException(String message) { + super(message); + } + +} + +" +A21509,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public class Dancing +{ + /** + * @param args + */ + public static void main(String[] args) + { + try { + FileReader fs = new FileReader(""/tmp/dancing.in""); + BufferedReader in = new BufferedReader(fs); + FileWriter fso = new FileWriter(""/tmp/dancing.out""); + BufferedWriter out = new BufferedWriter(fso); + + String strLine; + int i=0; + int matches; + + while ((strLine = in.readLine()) != null) + { + if (i > 0) { + // parse input line + String[] strings = strLine.split("" ""); + final int[] ints = new int[strings.length]; + for (int j = 0; j < strings.length; j++) { + ints[j] = Integer.parseInt(strings[j]); + } + + matches = findMatches(ints[1], ints[2], Arrays.copyOfRange(ints, 3, 3+ints[0])); + + out.write(new StringBuilder(""Case #"").append(i) + .append("": "").append(matches).append(""\n"") + .toString()); + } + i++; + } + + in.close(); + out.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + private static int findMatches(int surprises, int bestResult, int[] ts) + { + int matches = 0; + + List totalScores = new ArrayList(ts.length); + for (int index = 0; index < ts.length; index++){ + totalScores.add(ts[index]); + } + Collections.sort(totalScores, Collections.reverseOrder()); + System.out.print(""Surprises: "" + surprises + "" Best: "" + bestResult + "" Scores: "" + totalScores); + + for (int totalScore : totalScores) + { + int min = totalScore / 3; + int delta = totalScore % 3; + int max = min + delta; + + System.out.print("" [Min: "" + min + "" / Max: "" + max + ""]""); + + if ((max == bestResult) && (delta == 2) && (surprises > 0)) { + matches++; + surprises--; + } else if ((min + 1 == bestResult) && (max + 1 == bestResult) && (min > 0) && (surprises > 0)) { + matches++; + surprises--; + } else if ((min + 1 >= bestResult) && (max >= bestResult)) { + matches++; + } + } + + System.out.println("" Result: "" + matches); + return matches; + } +}" +A20649,"import java.util.*; +import java.io.*; +class Dancing{ + public static void main(String args[]) + { + File file = new File(""B-large.in""); + try{ + FileWriter fstream = new FileWriter(""result.txt""); + BufferedWriter out = new BufferedWriter(fstream); + Scanner sc = new Scanner(file); + int tcs = sc.nextInt(); //test cases + + for(int tc = 1; tc <=tcs; tc++) + { + int words = sc.nextInt(); + int surprising = sc.nextInt(); + int p = sc.nextInt(); + int converted = 0; + int normal = p + (p-1) + (p - 1); + int snormal = normal - 2; + while(words-- > 0) + { + int candidate = sc.nextInt(); + if(candidate < p) continue; + if(candidate >= normal) + { + converted += 1; + } + else if(surprising > 0 && candidate >= snormal) + { + surprising--; + converted++; + } + } + out.write(""Case #"" + tc + "": ""+converted+""\r\n""); + } + out.close(); + } catch (Exception e) {e.printStackTrace();} + } +}" +A23074,"package com.first; + +public class BDancingWiththeGooglers { + + ReadWriteFileForCodeJam flatFile; + + public BDancingWiththeGooglers() { + flatFile = new ReadWriteFileForCodeJam(); + initializeFlatFileParameters(); + performSolution(); + finalizeSolutionFileToSend(); + } + + private void performSolution(){ + String[] items; + int noDancers, noOfSurprises, bestScore; + int maxGooglers; + int maxAchieved; + boolean surprise; + for(int i=1; i<=Integer.parseInt(flatFile.GetSingleLineFromFile(1)); i++){ + maxGooglers = 0; + surprise = true; + items = flatFile.GetSingleLineFromFile(i + 1).split("" ""); + noDancers = Integer.parseInt(items[0]); + noOfSurprises = Integer.parseInt(items[1]); + bestScore = Integer.parseInt(items[2]); + flatFile.setFileContentToWrite(""Case #"" + i + "":"", true, true); + for(int j=0; j=p){ + if(Math.max(0, 3*p-2) <= t) + count++; + else if (Math.max(0, 3*p-4) <= t && s>0){ + count++; + s--; + } + } + } + fw.write(count+""\n""); + + } + sc.close(); + fw.close(); + } + +} +" +A22805,"/** + * Copyright Carma Systems, Inc. All rights reserved. + */ +package com.jessehutton.codejam.qualification2012; + +import com.jessehutton.codejam.util.IOHandler; + +import java.io.IOException; + +/** + * + * @author Jesse Hutton + */ +public class DancingWithGooglers { + + public static void main(String[] args) throws NumberFormatException, IOException { + String inFile = ""/home/jesse/Downloads/B-large.in""; + String outFile = ""/home/jesse/Desktop/Dancing-googlers-large.out""; + + IOHandler io = new IOHandler(new String[] {inFile, outFile}) { + @Override + public String formatCase(int caseNum, Object result) { + return String.format(""Case #%d: %s"", caseNum, result); + } + }; + + int T = Integer.parseInt(io.line().trim()); + for (int c = 1; c <= T; c++) { + String[] tokens = io.line().split("" ""); + int nGoo = Integer.parseInt(tokens[0]); + int sups = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int results = 0; + + for (int t = 3; t < 3 + nGoo; t++) { + int tot = Integer.parseInt(tokens[t]); + int fact = tot / 3; + int rem = tot % 3; + + if (tot == 0) { + if (p == 0) { + results++; + } + continue; + } + + if (fact >= p) { + results++; + continue; + } + + int diff = p - fact; + if (diff > 2) { + continue; + } + + // can arrange without using a sup + // + if (diff == 1 && rem >= 1) { + results++; + continue; + } + + // can arrange with using a sup + // + if (diff == 1 && rem == 0 && sups > 0) { + results++; + sups--; + continue; + } + + // diff == 2 + // + if (sups > 0 && rem == 2) { + sups--; + results++; + } + } + io.recordCase(c, results); + } + io.finish(); + } + +} +" +A20411,"package MyAllgoritmicLib; + +import java.util.ArrayList; + +public class Dejkstra { + // --------------------------------------------------------------------------- + // Àëãîðèòì Äåéêñòðû.ïîèñêà êðàò÷àéøåãî ïóòè + + int v; + + int infinity=Integer.MAX_VALUE; // Áåñêîíå÷íîñòü + int p= 6; // Êîëè÷åñòâî âåðøèí â ãðàôå + int a[][]={ {0,1,0,0,1,3}, // Ìàòðèöà ñìåæíîñòè ãðàôà + { 1,0,5,0,0,1}, + { 0,5,0,5,20,1}, + { 0,0,5,0,3,2}, + { 1,0,20,3,0,10}, + { 3,1,1,2,10,0 }}; + + // Áóäåì èñêàòü ïóòü èç âåðøèíû s â âåðøèíó g + public ArrayList search(int s, int g){ + ArrayList result = new ArrayList(); + int x[] = new int[p]; // Ìàññèâ, ñîäåðæàùèé åäèíèöû è íóëè äëÿ êàæäîé âåðøèíû, + // x[i]=0 - åùå íå íàéäåí êðàò÷àéøèé ïóòü â i-þ âåðøèíó, + // x[i]=1 - êðàò÷àéøèé ïóòü â i-þ âåðøèíó óæå íàéäåí + int t[] = new int[p]; // t[i] - äëèíà êðàò÷àéøåãî ïóòè îò âåðøèíû s â i + int h[] = new int[p]; // h[i] - âåðøèíà, ïðåäøåñòâóþùàÿ i-é âåðøèíå + // íà êðàò÷àéøåì ïóòè + + // Èíèöèàëèçèðóåì íà÷àëüíûå çíà÷åíèÿ ìàññèâîâ + int u; // Ñ÷åò÷èê âåðøèí + for (u=0;ut[v]+a[v][u]) // Åñëè äëÿ âåðøèíû u åùå íå + // íàéäåí êðàò÷àéøèé ïóòü + // è íîâûé ïóòü â u êîðî÷å ÷åì + // ñòàðûé, òî + { + t[u]=t[v]+a[v][u]; // çàïîìèíàåì áîëåå êîðîòêóþ äëèíó ïóòè â + // ìàññèâ t è + h[u]=v; // çàïîìèíàåì, ÷òî v->u ÷àñòü êðàò÷àéøåãî + // ïóòè èç s->u + } + } + + // Èùåì èç âñåõ äëèí íåêðàò÷àéøèõ ïóòåé ñàìûé êîðîòêèé + int w=infinity; // Äëÿ ïîèñêà ñàìîãî êîðîòêîãî ïóòè + v=-1; //  êîíöå ïîèñêà v - âåðøèíà, â êîòîðóþ áóäåò + // íàéäåí íîâûé êðàò÷àéøèé ïóòü. Îíà ñòàíåò + // òåêóùåé âåðøèíîé + for(u=0;u result = dejkstra.search(3, 6); + result = dejkstra.search(0, 2); + result = null; + System.out.println(result); + } + + } +" +A20370,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Dancing { + + private static BufferedReader bufferedReader = new BufferedReader( + new InputStreamReader(System.in)); + + public static void main(String[] args) throws IOException { + String line = bufferedReader.readLine(); + int cases = Integer.parseInt(line); + + for (int i = 1; i <= cases; i++) { + line = bufferedReader.readLine(); + String[] split = line.split("" ""); + + int googlers = Integer.parseInt(split[0]); + int surprises = Integer.parseInt(split[1]); + int p = Integer.parseInt(split[2]); + + int[] totals = new int[googlers]; + for (int j = 0; j < googlers; j++) { + totals[j] = Integer.parseInt(split[3 + j]); + } + + Arrays.sort(totals); + + int answer = 0; + int usedSurprises = 0; + + for (int j = 0; j < googlers; j++) { + if (p == 0) { + answer++; + } else if (totals[j] >= p + 2 * (p - 1) && p >= 1) { + answer++; + } else if (usedSurprises < surprises) { + if (totals[j] >= p + 2 * (p - 2) && p >= 2) { + answer++; + usedSurprises++; + } + } + } + + System.out.println(""Case #"" + i + "": "" + answer); + } + } + +} +" +A20521,"import java.util.*; +import java.io.*; + +public class DancingGooglers { + + private static int numTest; + private static Scanner input; + private static PrintWriter output; + + public static void main(String[] args) throws FileNotFoundException, IOException { + + // Initialization of Input/Output streams + input = new Scanner(new File(args[0])); + output = new PrintWriter(new File(""output"")); + + // Reads char by char the input dimension + numTest = input.nextInt(); + input.nextLine(); // reads the \n character + + // Solves the problem + for(int i = 1; i <= numTest; i++) { + + output.print(""Case #"" + i + "": ""); + + // N, the number of Googlers + int n = input.nextInt(); + // System.err.println(i + "" N: "" + n); + + // S, the number of surprising triplets of scores + int s = input.nextInt(); + // System.err.println(i + "" S: "" + s); + + // p, the value of the best result for a googler + int p = input.nextInt(); + // System.err.println(i + "" P: "" + p); + + // y is the maximum number of Googlers who could have had a best result of greater than or equal to p. + int y = 0; + + for(int j = 0; j < n; j++) { + + int totalScore = input.nextInt(); + int remainder = totalScore - 3 * p; + + if(remainder >= 0 || ((p - 1) >= 0 && remainder >= -2)) + y++; + + else if(((p - 2) >= 0 && remainder >= -4) && s > 0) { + y++; + s--; + } + + // System.err.println(i + "" Y: "" + y); + + } + + output.println(y); + + if(input.hasNextLine()) + input.nextLine(); + + } + + output.flush(); + + } + +}" +A21090,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class Dance { + public static void main(String[] args) throws FileNotFoundException { + File file = new File(""input.in""); + Scanner in = new Scanner(file); + + int cases = in.nextInt(); + + for (int i = 0; i < cases; i++) { + int N = in.nextInt(); //googlers + int S = in.nextInt(); //surprising scores + int p = in.nextInt(); + int [] scores = new int[N]; + for (int j = 0; j < scores.length; j++) { + scores[j] = in.nextInt(); + } + int max = 0; + + for (int j = 0; j < scores.length; j++) { + if (scores[j] >= (3*p-2)) { + max++; + } else if (scores[j] >= (3*p-4) && S > 0 && !((3*p-4) <= 0) ) { + max++; + S--; + } + } + System.out.println(""Case #""+ (i+1) + "": "" + max); + } + } +} +" +A22824,"package mgg.utils; + +import java.util.List; + +public class ListUtils { + + public static String pureList(List list) { + StringBuilder builder = new StringBuilder(); + for (Object elem : list) { + builder.append("" "" + elem); + } + return builder.substring(1).toString(); + } + +} +" +A23014,"package tr0llhoehle.cakemix.utility.googleCodeJam; + +import java.text.ParseException; + +/** + * This class is a base class for all concrete problems. It is used to define + * some methods necessary for the IOManager to work. It is crucial that the + * addValue-Method gets extended and called (super.addValue(o)) by the extending + * class. + * + * @author Cakemix + * @see IOManager + * @see Solver + */ +public abstract class Problem { + + protected SupportedTypes[] types; + protected int cntr = 0; + protected boolean isInitialised = false; + + /** + * Returns an array of SupportedTypes which define exactly what data is + * stored in this problem. + * + * The attribute ""types"" needs to be initialized in the constructor of the + * extending class. + * + * @return An array of SupportedTypes which define exactly what data is + * stored in this problem. + * @see SupportedTypes + */ + public SupportedTypes[] getTypes() { + return types; + } + + public void addValue(Object o) throws ParseException { + if (!isInitialised) { + cntr++; + isInitialised = (cntr == types.length); + } else { + throw new ParseException(""Tried to add another value to this Problem even though all values are set."", cntr); + } + } +} +" +A20456,"import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class dancers { + public static void main(String[] args) { + try { + Scanner input = new Scanner(new File(""c:\\files\\B-small-attempt0.in"")); + FileWriter fw = new FileWriter(""c:\\files\\douts.txt""); + PrintWriter output = new PrintWriter(fw); + int n = input.nextInt(); + for(int i=0;i=3*points-2) + count++; + else if(surprise>0 && (total[dIndex]==3*points-3 || total[dIndex]==3*points-4) && total[dIndex]>0) + { + surprise--; + count++; + } + else + break; + } + output.println(""Case #""+(i+1)+"": ""+count); + } + output.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A22569,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintStream; + + +public class Solver { + + protected final static String IN_FILE = ""in""; + protected final static String OUT_FILE = ""out""; + protected final static String OUT_PREFIX = ""Case #$: ""; + protected BufferedReader in; + protected int cases; + + + public Solver() throws Throwable { + File inFile = new File(IN_FILE); + if (!inFile.exists()) { + throw new RuntimeException(); + } + in = new BufferedReader(new FileReader(inFile)); + cases = Integer.parseInt(in.readLine()); + + + File outFile = new File(OUT_FILE); + if (outFile.exists()) { + outFile.delete(); + } + outFile.createNewFile(); + System.setOut(new PrintStream(outFile) ); + + for (int i = 0; i < cases; i++) { + ProblemCase c = new DancingGooglersProblemCase(in); + System.out.println(OUT_PREFIX.replaceAll(""[$]"", (new Integer(i+1)).toString()) + c.getResult()); + } + } + + public static void main(String[] args) throws Throwable { + new Solver(); + } +} +" +A21116," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author aliakbars + */ +public class Googlers { + + public static void main(String[] args) { + Googlers gr = new Googlers(); + FileInputStream fstream = null; + FileWriter fwrite; + int jml; + int s; + int p; + int okay; + try { + fstream = new FileInputStream(""B-large.in""); + fwrite = new FileWriter(""B-large.out""); + BufferedWriter ofile = new BufferedWriter(fwrite); + DataInputStream ifile = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(ifile)); + String num = br.readLine(); + for (int i = 0; i < Integer.parseInt(num); i++) { + String[] input = br.readLine().split("" ""); + jml = Integer.parseInt(input[0]); + s = Integer.parseInt(input[1]); + p = Integer.parseInt(input[2]); + okay = 0; + for (int j = 0; j < jml; j++) { + int x = Integer.parseInt(input[3+j]); + if (x / 3 >= p) { + okay++; + } else { + if (x / 3 + 1 >= p && x != 0) { + if (x - (x / 3) * 3 + (x / 3) >= p) { + okay++; + } else { + if (s > 0) { + okay++; + s--; + } + } + } else if (x / 3 + 2 >= p && x != 0) { + if ((x / 3) * 3 + 2 == x) { + if (s > 0) { + okay++; + s--; + } + } + } + } + } + try { + ofile.write(""Case #"" + (i + 1) + "": "" + okay); + ofile.newLine(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + System.out.println(""Case #"" + (i + 1) + "": "" + okay); + } + ofile.close(); + } catch (IOException ex) { + Logger.getLogger(Googlerese.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + fstream.close(); + } catch (IOException ex) { + Logger.getLogger(Tutorial.class.getName()).log(Level.SEVERE, null, ex); + } + } + } +} +" +A20790,"import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + + +public class Dancing { + + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(""./src/B-large.txt"")); + FileWriter fw = new FileWriter(""./src/output-large.txt""); + int total = sc.nextInt(); + for(int turn = 1; turn <= total; turn++) { + int res = 0; + int pos = 0; + int N = sc.nextInt(), S = sc.nextInt(), p = sc.nextInt(); +// fw.write(N + "" "" + S + "" "" + p + ""\n""); + for(int i = 0; i < N; i++) { + int next = sc.nextInt(); +// fw.write(next + "" "" + (3*p-2) + ""\n""); + if (next >= (3*p-2)) {res++;} + else + if ((p>=2) && (next >= 3*p-4)) {pos++;} + } + if (pos < S){res = res+pos;} + else {res = res + S;} + + fw.write(""Case #"" + turn + "": "" + res + ""\n""); + } + fw.flush(); + fw.close(); + } +} +" +A21236,"package org.pokuri; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * @author Pokuri + * @since Apr 14, 2012 + * org.pokuri.Googlers + */ +public class Googlers{ + + private BufferedReader reader = null; + + /** + * @param filePath + * @return + */ + protected void openFile(String filePath){ + try { + reader = new BufferedReader(new FileReader(new File(filePath))); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + protected void closeFile(){ + try { + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + protected BufferedWriter openOutputFile(String filePath){ + try { + return new BufferedWriter(new FileWriter(new File(filePath))); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + protected int noOfTestCases(){ + try { + return Integer.parseInt(reader.readLine()); + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return 0; + } + + protected String nextCase(){ + try { + return reader.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + protected void generateOutput() throws IOException { + + openFile(""input/Googlers.input""); + int cases = noOfTestCases(); + BufferedWriter outputFile = openOutputFile(""output/Googlers.txt""); + for(int i=1; i<=cases; i++){ + String nextCase = nextCase(); + String[] split = nextCase.split("" ""); + int noOfSurprises = Integer.parseInt(split[1]); + int minBestScore = Integer.parseInt(split[2]); + + int bestScoreGooglers = 0; + // for each score find it'shad best score or not + for(int k=3; k= minBestScore){ + // now find the max score that can be when all triplets are min.best score + int multiplied = minBestScore*3; + // if score is more than sum of tripltes -2 then we can arrange them to form at lest a best score in it + if(score >= multiplied - 2){ + bestScoreGooglers++; + } + // if not found then check we left with any surprises of not. + // the use that surpeise to make that score good enough for forming min.best score in triplets + else if(noOfSurprises > 0 && score >= multiplied - 4){ + bestScoreGooglers++; + noOfSurprises--; + } + } + } + outputFile.write(""Case #""+i+"": ""+bestScoreGooglers); + outputFile.newLine(); + } + outputFile.flush(); + outputFile.close(); + closeFile(); + + } + + public static void main(String[] args) throws IOException { + + Googlers googlers = new Googlers(); + googlers.generateOutput(); + + } + +} +" +A22136,"/** + * + */ +package asem.googe.codejam.qround; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * @author A.Alathwari + * + * Problem C : + * + */ +public class ProblemC implements Runnable { + + asem.core.util.InputReader fin; + java.io.PrintWriter fout; + + /** + * @param fin + * @param fout + */ + public ProblemC(asem.core.util.InputReader fin, PrintWriter fout) { + this.fin = fin; + this.fout = fout; + } + + /** + * @param fin + * @param fout + * @throws IOException + * @throws FileNotFoundException + */ + public ProblemC(String fin, String fout) throws FileNotFoundException, IOException { + this.fin = new asem.core.util.InputReader(new FileReader(fin)); + this.fout = new PrintWriter(System.out); + } + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + // TODO Auto-generated method stub + try { + + for (int tNum = 1, inT = fin.readInt(); tNum <= inT; tNum++) { + + System.out.println(""Case #"" + tNum + "": "" + """"); + } + + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +}" +A22393,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancingwithgoogler; + +/** + * + * @author WC + */ +public class DancingWithGoogler { + private int numberOfSurprising = 0; + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + (new DancingWithGoogler()).getMaximumBestResults(""B-large.in"", ""B-large.out"", ""\n""); + } + + private void getMaximumBestResults(String filename, String outputFilename, String separator) { + int numOfTestCases = CodeJamFileManager.getIntFromFirstLineOfFile(filename, separator); + String[] testCases = CodeJamFileManager.getTextLinesOfFile(filename, separator); + String output = """"; + for (int i = 1; i <= numOfTestCases; i++) { + output += ""Case #"" + i + "": "" + getMaximumBestResultOccurence(testCases[i]) + (i != numOfTestCases ? separator : """"); + } + CodeJamFileManager.saveOutputFile(output, outputFilename, separator); + } + + private int getMaximumBestResultOccurence(String testCase) { + int[] intFigures = getIntArrayFromString(testCase.split("" "")); + int numberOfGooglers = intFigures[0]; + numberOfSurprising = intFigures[1]; + int bestResultOf = intFigures[2]; + int counter = 3; + int maxBestResultOccurence = 0; + boolean canBeSurprising = true; + while (counter < intFigures.length) { + if (numberOfSurprising == 0) + canBeSurprising = false; + if (googlerHasBestResult(intFigures[counter], bestResultOf, canBeSurprising)) + maxBestResultOccurence++; + counter++; + } + return maxBestResultOccurence; + } + + private boolean googlerHasBestResult(int score, int bestScoreToBeat, boolean canBeSurprising) { + int remainder = score % 3; + int avgScore = score / 3; + if (avgScore >= bestScoreToBeat) { + return true; + } + else if (bestScoreToBeat - avgScore == 1) { + if (remainder != 0) { + return true; + } + else if (canBeSurprising && avgScore != 0) { + numberOfSurprising--; + return true; + } + } + else if (bestScoreToBeat - avgScore == 2) { + if (remainder == 2 && canBeSurprising) { + numberOfSurprising--; + return true; + } + return false; + } + return false; + } + + private int[] getIntArrayFromString(String[] intStrArray) { + int[] intArray = new int[intStrArray.length]; + int i = 0; + for (String intStr : intStrArray) { + intArray[i++] = Integer.parseInt(intStr); + } + return intArray; + } +}" +A20235,"import java.util.*; + +public class Main{ + public static void main(String[] args) { + Scanner console = new Scanner(System.in); + int t = console.nextInt(); + for (int i = 0; i < t; i++) { + System.out.print(""Case #"" + (i + 1) + "": ""); + int n = console.nextInt(); + int s = console.nextInt(); + int p = console.nextInt(); + int k = 0; + int m = 0; + for (int j = 0; j < n; j++) { + int score = console.nextInt(); + if (score % 3 == 0) { + if (score / 3 >= p) { + m++; + } else if (score != 0 && score / 3 + 1 >= p) { + k++; + } + } else if (score % 3 == 1) { + if (score / 3 >= p - 1) { + m++; + } + } else { + if (score / 3 >= p) { + m++; + } else if (score / 3 + 1 >= p) { + m++; + } else if (score / 3 + 2 >= p) { + k++; + } + } + } + if (k <= s) { + m += k; + } else { + m += s; + } + System.out.println(m); + } + } +}" +A23017,"package tr0llhoehle.cakemix.googleCodejam; + +import java.io.IOException; +import java.text.ParseException; + +import tr0llhoehle.cakemix.utility.googleCodeJam.IOManager; + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length >= 1) { + IOManager io = new IOManager( + new DWGSolver(), + (Class) new DWGProblem().getClass()); + + try { + io.start(args[0]); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + +} +" +A22474,"import java.io.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) throws Exception { + Scanner s = new Scanner(new File(""input"")); + BufferedWriter w = new BufferedWriter(new FileWriter(new File(""output""))); + int cases = s.nextInt(); + for (int i = 0; i < cases; i++) { + s.nextLine(); + int n = s.nextInt(); + int surprising = s.nextInt(); + int target = s.nextInt(); + + + int answer = 0; + if (target == 0) { + answer = n; + } else { + int lowestBound = target * 3 - 4; + ArrayList l = new ArrayList(); + + for (int j = 0; j < n; j++) { + int si = s.nextInt(); + if (si >= lowestBound && si >= target) { + l.add(si); + } + } + + Collections.sort(l); + Collections.reverse(l); + + for (int si : l) { + int roundedAverage = si / 3; + int mod = si % 3; + if (mod == 0) { + if (roundedAverage >= target) { + answer++; + } else if (roundedAverage + 1 == target && surprising > 0) { + answer++; + if (--surprising == 0) { + break; + } + } + } else if (mod == 1) { + answer++; + } else { + if (roundedAverage + 1 >= target) { + answer++; + } else if (roundedAverage + 2 >= target && surprising > 0) { + answer++; + if (--surprising == 0) { + break; + } + } + } + } + } + + w.write(""Case #""); + w.write(String.valueOf(i + 1)); + w.write("": ""); + + w.write(String.valueOf(answer)); + + w.write(""\n""); + } + w.close(); + } + +} +" +A21307,"package fun.codeslam.dancers; + +public class TestCase +{ + + private Integer numberOfGooglers; + + private Integer numberOfSurprises; + + private Integer pointsNeeded; + + private Integer[] sumsOfPoints; + + public TestCase(String line) + { + String[] elements = line.split("" ""); + numberOfGooglers = Integer.valueOf(elements[0]); + numberOfSurprises = Integer.valueOf(elements[1]); + pointsNeeded = Integer.valueOf(elements[2]); + sumsOfPoints = new Integer[numberOfGooglers]; + for (Integer key = 0; key < numberOfGooglers; key++) + { + sumsOfPoints[key] = Integer.valueOf(elements[key + 3]); + } + } + + public Integer getNumberOfGooglers() + { + return numberOfGooglers; + } + + public Integer getNumberOfSurprises() + { + return numberOfSurprises; + } + + public Integer getPointsNeeded() + { + return pointsNeeded; + } + + public Integer getSumOfPoints(Integer dancerIndex) + { + return sumsOfPoints[dancerIndex]; + } + +} +" +A22836,"import java.io.*; +import java.util.Arrays; + +public class Main{ + + public static void main(String[] args) throws Exception { + int t = Integer.parseInt(finB.readLine()); + int test = 1; + while(test <= t){ + int n = fnextInt(); + int s = fnextInt(); + int p = fnextInt(); + int[] a = new int[n]; + for(int i = 0; i < n; i++){ + a[i] = fnextInt(); + } + print(n + "" "" + s + "" "" + p + "" ""); + for(int i = 0; i < n; i++){ + print(a[i] + "" ""); + } + int[] max = new int[n]; + for(int i = 0; i < n; i++){ + if(a[i] / 3 == 0){ + if(p == 2 && a[i] == 2 && s > 0){ + max[i] = a[i]; + s--; + continue; + } + else if(a[i] == 2) max[i] = 1; + else max[i] = a[i]; + continue; + } + if(a[i] % 3 == 0 && a[i] / 3 < p){ + if(s > 0 && a[i] / 3 + 1 == p){ + max[i] = a[i] / 3 + 1; + s--; + continue; + } + } + if(a[i] % 3 == 2 && a[i] / 3 + 1 < p){ + if(s > 0 && a[i] / 3 + 2 == p){ + max[i] = a[i] / 3 + 2; + s--; + continue; + } + } + max[i] = a[i] % 3 > 0 ? a[i] / 3 + 1 : a[i] / 3; + } + int ans = 0; + for(int i = 0; i < n; i++){ + if(max[i] >= p) ans++; + } + fout.println(""Case #"" + test + "": "" + ans); + println(""Case #"" + test + "": "" + ans); + test++; + } + fout.flush(); + } + + private static PrintWriter out; + private static BufferedReader inB; + private static BufferedReader finB; + private static PrintWriter fout; + + + static { + try { + finB = new BufferedReader(new InputStreamReader(new FileInputStream(""input.in""))); + fout = new PrintWriter(new FileOutputStream(""output.txt"")); + out = new PrintWriter(System.out); + inB = new BufferedReader(new InputStreamReader(System.in)); + } catch(Exception e) {e.printStackTrace();} + } + + private static StreamTokenizer in = new StreamTokenizer(inB); + private static StreamTokenizer fin = new StreamTokenizer(finB); + + private static void exit(Object o) throws Exception { + out.println(o); + out.flush(); + System.exit(0); + } + private static void println(Object o) throws Exception{ + out.println(o); + out.flush(); + } + private static void print(Object o) throws Exception{ + out.print(o); + out.flush(); + } + private static int fnextInt() throws Exception { + fin.nextToken(); + return (int)fin.nval; + } + private static int nextInt() throws Exception { + in.nextToken(); + return (int)in.nval; + } + private static String nextString() throws Exception { + in.nextToken(); + return in.sval; + } +} " +A21609," +public interface ICounterZeroEvent { + public void fireEvent(); +} +" +A20723,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.FileReader; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.StringTokenizer; +import java.util.ArrayList; + +public class TestJAM +{ + public static void main (String[] args) + { + BufferedReader br = null; + PrintStream ps = null; + + try + { + int t; + int n; + int s; + int p; + + int count; + int countsurprisingoblig; + int countimp; + + ArrayList scores; + + String line; + StringTokenizer st; + + br = new BufferedReader (new FileReader (""B-large.in"")); + ps = new PrintStream (new FileOutputStream (""B-large.out"")); + + line = br.readLine (); + t = Integer.parseInt (line); + + for (int testCase = 0; testCase < t; testCase++) + { + count = 0; + countsurprisingoblig = 0; + countimp = 0; + + line = br.readLine (); + st = new StringTokenizer (line); + + n = Integer.parseInt (st.nextToken ()); + s = Integer.parseInt (st.nextToken ()); + p = Integer.parseInt (st.nextToken ()); + + scores = new ArrayList (); + + for (int scoreInputIndex = 0; scoreInputIndex < n; scoreInputIndex++) + { + scores.add (Integer.parseInt (st.nextToken ())); + } + + for (int score : scores) + { + int diff = (int) Math.abs (score - (3*p)); + + if ((score < (3 * p)) && ((diff == 3 || diff == 4)) && (score != 0) && (p > 0)) + { + countsurprisingoblig++; + } + else if (((score < (3 * p)) && (diff > 4)) || ((score == 0) && (p > 0))) + { + countimp++; + } + } + + count = scores.size () - countimp - countsurprisingoblig; + + if (countsurprisingoblig > s) + { + count += s; + } + else + { + count += countsurprisingoblig; + } + +// System.out.println (count); +// System.out.println (n + "" "" + s + "" "" + p + "" "" + scores.toString ()); +// System.out.println (""Case #"" + (testCase + 1) + "": "" + s); + + ps.println (""Case #"" + (testCase + 1) + "": "" + count); + } + + +// ps.println (""test1 test1 test1""); + +// System.out.println (""Hola Mundo!!!""); + } + catch (IOException ioe) + { + ioe.printStackTrace (); + } + catch (NumberFormatException nfe) + { + nfe.printStackTrace (); + } + finally + { + if (ps != null) + { + ps.close (); + } + if (br != null) + { + try + { + br.close (); + } + catch (IOException ioe) + { + ioe.printStackTrace (); + } + } + } + } +} + + + + +" +A21289,"import java.io.*; +import java.util.*; +import static java.lang.Integer.*; +import static java.lang.Math.*; +public class CodeJamB { + static boolean is(int a){ + return a>=0&&a<=10; + } + static int normal(int n){ + int max=0; + if(n%3==0)max=n/3; + if((n+1)%3==0&&is((n+1)/3)&&is((n+1)/3-1))max=max(max,(n+1)/3); + if((n-1)%3==0&&is((n-1)/3)&&is((n-1)/3+1))max=max(max,(n-1)/3+1); + return max; + } + static int aNormal(int n){ + int max=0; + if((n-3)%3==0&&is((n-3)/3)&&is((n-3)/3+1)&&is((n-3)/3+2))max=(n-3)/3+2; + if((n+2)%3==0&&is((n+2)/3)&&is((n+2)/3-2))max=max(max,(n+2)/3); + if((n-2)%3==0&&is((n-2)/3)&&is((n-2)/3+2))max=max(max,(n-2)/3+2); + return max; + } + static long f(int i,int s){ + if(s<0)return MIN_VALUE; + if(i==arr.length)return 0; + if(mem[i][s]>-1)return mem[i][s]; + return mem[i][s]=max(f(i+1,s-1)+(aNormal(arr[i])>=p?1:0),f(i+1,s)+(normal(arr[i])>=p?1:0)); + } + static int arr[],p; + static long[][] mem; + public static void main(String args[]) throws Throwable { + System.setOut(new PrintStream(""B-Large.out"")); + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + for (int t=0,T=parseInt(in.readLine().trim());t++ list = new ArrayList(); + + for(int i=0; i= p){ + ret ++; + } + // surprising候補 + else{ + list.add(new Integer(t[i])); + } + } + + // surprising候補を降順にソート + Collections.sort(list, new Comparator(){ + public int compare(Integer t1, Integer t2) { + return t2 - t1; + } + }); + + for(Integer ii : list){ + if(S>0){ + // surprisingで+1操作できる条件 + // - 合計値が2以上 + // - 合計値を構成する3つの数値のうち、3つが同じ数 または 大きい方の2つが同じ数 + if(ii.intValue() >= 2 && (ii.intValue()%3 != 1)){ + // 合計値を3で割った値を切り上げて最大値とする + if(Math.ceil((double)ii.intValue()/3) >= p-1){ + //System.out.println(""includes surprising "" + ii.intValue() + ""->"" + (Math.ceil((double)ii.intValue()/3)+1) + "","" + ""other""); + ret ++; + S --; + if(S == 0){ + break; + } + } + } + } + } + + return ret; + } + + public static void main(String[] args){ + if(args.length == 0){ + System.exit(1); + } + + try{ + FileReader fr = new FileReader(args[0]); + BufferedReader br = new BufferedReader(fr); + + FileOutputStream fos = new FileOutputStream(""output.out""); + OutputStreamWriter osw = new OutputStreamWriter(fos , ""UTF-8""); + BufferedWriter bw = new BufferedWriter(osw); + + String tmp_str; + + tmp_str = br.readLine(); + + int numOfCases = Integer.parseInt(tmp_str); + int caseIndex = 0; + + while((tmp_str = br.readLine()) != null){ + caseIndex++; + + StringTokenizer st = new StringTokenizer(tmp_str, "" ""); + int numOfTokens = st.countTokens(); + String[] tokenOfLine = new String[numOfTokens]; + for(int i=0; i= 0; j--) + { + if(p == 0) + count++; + else if(totals[j] == 0) + break; + else if(p + 2*(p-1) <= totals[j]) + count++; + else if(s > 0 && p >=2 && p + 2*(p-2) <= totals[j] ) + { + count ++; + s --; + } + else + break; + } + + out.write(""Case #"" + i + "": "" + count + ""\n""); + } + out.close(); + } +} + +" +A22755,"import java.util.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +//SRM525 +public class ggcjblarge { + static int counter = 0; + static int dp[][] = new int[100][3]; + + public static int store(int t, int p){ + int divided = t/3; + + int a = divided,b = divided,c = divided; + int remain = t % 3; + if(remain == 2){ + a++; + b++; + } + if(remain == 1){ + a++; + } + dp[counter][0] = a; + dp[counter][1] = b; + dp[counter][2] = c; + //System.out.println(a); + //System.out.println(b); + //System.out.println(c); + //System.out.println(p); + counter++; + if(a >= p || b >= p || c >= p){ + return 1; + } + return 0; + } + + public static int check(int N, int s, int p){ + int supply = 0; + for(int i = 0; i < N; i++){ + if(dp[i][0] < p && s > 0){ + dp[i][0]++; + dp[i][1]--; + if(dp[i][0] < p ||dp[i][0] - dp[i][1] > 2 || dp[i][1] < 0){ + continue; + } + else{ + supply++; + s--; + } + } + } + //System.out.println(supply); + return supply; + } + + public static void main(String[] args) throws FileNotFoundException { + int answer = 0; + Scanner scan = new Scanner(System.in); + int max = scan.nextInt(); + + + //int dp[][] = new int[3][3]; + + for(int i = 1; i <= max; i++){ + int N = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + for(int j = 1; j <= N; j++){ + int n = scan.nextInt(); + answer = answer + store(n, p); + } + int supply = check(N, s, p); + //System.out.println(supply); + answer = answer + supply; + System.out.println(""Case #"" + i + "": "" + answer); + counter = 0; + answer = 0; + } + } + +} +" +A20292,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B_DancingWiththeGooglers { + public static void main(String[] args) throws FileNotFoundException { + Scanner sc = new Scanner(new File(""file2.in"")); + PrintWriter writer = new PrintWriter(new File(""file2.out"")); + int t = sc.nextInt(); + for (int i = 1; i <= t; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] a = new int[n]; + for (int j = 0; j < n; j++) + a[j] = sc.nextInt(); + + int min1 = p - 1 + p - 1 + p; + int min2 = p - 2 + p - 1 + p - 1; + int count = 0; + for (int j = 0; j < n; j++) + if (a[j] >= p) { + if (a[j] >= min1) + count++; + else { + if (a[j] >= min2 && s > 0) { + s--; + count++; + } + } + } + writer.println(""Case #"" + i + "": "" + count); + } + writer.close(); + } +} +" +A20264,"package problemB; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.Writer; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws Exception { + + Writer write = new FileWriter(new File(""out.txt"")); + Writer writer = new BufferedWriter(write); + + Scanner scan = new Scanner(new File(""B-large.in.txt"")); + + int t = scan.nextInt(); + + for(int i = 1; i<=t; i++) { + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + Score[] score = new Score[n]; + for(int j = 0; j=score) return true; + } + return false; + } + + public boolean bestScoreOther(int score) { + if(surprising==null) return false; + for(int i : surprising) { + if(i>=score) return true; + } + return false; + } + + private void buildScores(int num) { + int i = 0; + while(iStandard input
. This class provides methods for reading strings + * and numbers from standard input. + *

+ * The Locale used is: language = English, country = US. This is consistent + * with the formatting conventions with Java floating-point literals, + * command-line arguments (via Double.parseDouble()) + * and standard output (via System.out.print()). It ensures that + * standard input works with the input files used in the textbook. + *

+ * For additional documentation, see Section 1.5 of + * Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne. + */ +public final class StdIn { + + // assume Unicode UTF-8 encoding + private static String charsetName = ""UTF-8""; + + // assume language = English, country = US for consistency with System.out. + private static Locale usLocale = new Locale(""en"", ""US""); + + // the scanner object + private static Scanner scanner = new Scanner(new BufferedInputStream(System.in), charsetName); + + // static initializer + static { scanner.useLocale(usLocale); } + + // singleton pattern - can't instantiate + private StdIn() { } + + + /** + * Is there only whitespace left on standard input? + */ + public static boolean isEmpty() { + return !scanner.hasNext(); + } + + /** + * Return next string from standard input + */ + public static String readString() { + return scanner.next(); + } + + /** + * Return next int from standard input + */ + public static int readInt() { + return scanner.nextInt(); + } + + /** + * Return next double from standard input + */ + public static double readDouble() { + return scanner.nextDouble(); + } + + /** + * Return next float from standard input + */ + public static float readFloat() { + return scanner.nextFloat(); + } + + /** + * Return next short from standard input + */ + public static short readShort() { + return scanner.nextShort(); + } + + /** + * Return next long from standard input + */ + public static long readLong() { + return scanner.nextLong(); + } + + /** + * Return next byte from standard input + */ + public static byte readByte() { + return scanner.nextByte(); + } + + /** + * Return next boolean from standard input, allowing ""true"" or ""1"" for true, + * and ""false"" or ""0"" for false + */ + public static boolean readBoolean() { + String s = readString(); + if (s.equalsIgnoreCase(""true"")) return true; + if (s.equalsIgnoreCase(""false"")) return false; + if (s.equals(""1"")) return true; + if (s.equals(""0"")) return false; + throw new java.util.InputMismatchException(); + } + + /** + * Does standard input have a next line? + */ + public static boolean hasNextLine() { + return scanner.hasNextLine(); + } + + /** + * Return rest of line from standard input + */ + public static String readLine() { + return scanner.nextLine(); + } + + /** + * Return next char from standard input + */ + // a complete hack and inefficient - email me if you have a better + public static char readChar() { + // (?s) for DOTALL mode so . matches a line termination character + // 1 says look only one character ahead + // consider precompiling the pattern + String s = scanner.findWithinHorizon(""(?s)."", 1); + return s.charAt(0); + } + + /** + * Return rest of input from standard input + */ + public static String readAll() { + if (!scanner.hasNextLine()) return null; + + // reference: http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html + return scanner.useDelimiter(""\\A"").next(); + } + + /** + * Read rest of input as array of ints + */ + public static int[] readInts() { + String[] fields = readAll().trim().split(""\\s+""); + int[] vals = new int[fields.length]; + for (int i = 0; i < fields.length; i++) + vals[i] = Integer.parseInt(fields[i]); + return vals; + } + + /** + * Read rest of input as array of doubles + */ + public static double[] readDoubles() { + String[] fields = readAll().trim().split(""\\s+""); + double[] vals = new double[fields.length]; + for (int i = 0; i < fields.length; i++) + vals[i] = Double.parseDouble(fields[i]); + return vals; + } + + /** + * Read rest of input as array of strings + */ + public static String[] readStrings() { + String[] fields = readAll().trim().split(""\\s+""); + return fields; + } + + + + /** + * Unit test + */ + public static void main(String[] args) { + + System.out.println(""Type a string: ""); + String s = StdIn.readString(); + System.out.println(""Your string was: "" + s); + System.out.println(); + + System.out.println(""Type an int: ""); + int a = StdIn.readInt(); + System.out.println(""Your int was: "" + a); + System.out.println(); + + System.out.println(""Type a boolean: ""); + boolean b = StdIn.readBoolean(); + System.out.println(""Your boolean was: "" + b); + System.out.println(); + + System.out.println(""Type a double: ""); + double c = StdIn.readDouble(); + System.out.println(""Your double was: "" + c); + System.out.println(); + + } + +} +" +A21129,"public class DataModel extends Thread { + + private int googlersNo; + private int suprScore; + private int minScore; + private int[] googScore; + private int caseNo; + private int output; + private boolean stateCalc; + + public DataModel(String input, int caseNo) { + this.caseNo = caseNo; + String[] temp = input.split("" ""); + stateCalc = false; + try { + googlersNo = Integer.parseInt(temp[0]); + suprScore = Integer.parseInt(temp[1]); + minScore = Integer.parseInt(temp[2]); + googScore = new int[googlersNo]; + for(int i = 0;i 0) { + temp[0] += 1; + if(diff > 1 && minDiff < 3 && minDiff > 0 && suprScore > 0) { + temp[0] += 1; + suprScore--; + } else if(diff > 1) { + temp[1] += 1; + } + } else if (minDiff == 1 && temp[0]!=0 && suprScore > 0) { + temp[0] += 1; + temp[2] -= 1; + suprScore--; + } + return (temp[0]>=minScore||temp[1]>=minScore||temp[2]>=minScore); + } + + @Override + public void run() { + for(int i = 0;i= v_minScoreWithoutSurprises) + { + v_answer++; + } + else if(v_numSurprises > 0 && v_totalPoints >= v_minScoreWithSurprises) + { + v_answer++; + v_numSurprises--; + } + } + m_outputFile.escrever(String.valueOf(v_answer)); + + if(p_numTestCase != m_numTestCases) + { + m_outputFile.escreverLinha(""""); + } + } +} +" +A22733,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Array; + +public class GCJ2 { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + GCJ2 g = new GCJ2(); + +// int i1 = g.calculate(3, 1, 3, 6, 6, 3); +// System.out.println(i1); + +// int i1 = g.calculate(3, 1, 5, 15, 13, 11); +// int i2 = g.calculate(3, 0, 8, 23, 22, 21); +// int i3 = g.calculate(2, 1, 1, 8, 0); +// int i4 = g.calculate(6, 2, 8, 29, 20, 8, 18, 18, 21); +// +// System.out.println(i1); +// System.out.println(i2); +// System.out.println(i3); +// System.out.println(i4); + + try { + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream( + ""C:/PROG/java/work/tc/src/gcj2.txt""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + // Read File Line By Line + int lineNum = 1; + br.readLine(); + + while ((strLine = br.readLine()) != null) { + // Print the content on the console + + +// System.out.print(strLine+""\t""); + String[] val = strLine.split(""\\s""); + int[] valI = new int[val.length-3]; + for (int i = 3; i < val.length; i++) { + + valI[i-3] = Integer.valueOf(val[i]); + + // System.out.print(val[i]+""_""+valI[i]); + + } + System.out.print(""Case #"" + lineNum + "": ""); + System.out + .println(g.calculate(Integer.valueOf(val[0]), + Integer.valueOf(val[1]), + Integer.valueOf(val[2]), valI)); +// System.out.println(); + + // System.out.println(strLine.charAt(0)); + lineNum++; + } + // Close the input stream + in.close(); + } catch (Exception e) {// Catch exception if any + e.printStackTrace(); + } + } + + public int calculate(int n, int surprises, int p, int... tArray) { + + int counterGreaterThanP = 0; + int surpriseRemaining = surprises; + + for (int t : tArray) { + + int d = t / 3; + int r = t % 3; + int max = 0; + int maxS = 0; + + if (t == 0) { + max = 0; + maxS = 0; + } else if (t == 30) { + max = 10; + maxS = 10; + } else if (t == 1) { + max = 1; + maxS = 1; + } else if (t == 2) { + max = 1; + maxS = 2; + } else { + + if (r == 0) { + max = d; + maxS = d + 1; + } else if (r == 1) { + max = d + 1; + maxS = d + 1; + } else if (r == 2) { + max = d + 1; + maxS = d + 2; + } + + } + if (max >= p) { + counterGreaterThanP++; + } else if (maxS >= p && surpriseRemaining > 0) { + counterGreaterThanP++; + surpriseRemaining--; + } + } + + return counterGreaterThanP; + } + +} +" +A22173,"package com.brootdev.gcj2012.problemB; + +import com.brootdev.gcj2012.common.Data; + +import java.io.IOException; + +public class Main { + + private Data data; + private long casesNumber; + private long currentCase; + + public static void main(String[] args) throws IOException { + new Main().go(args[0], args[1]); + } + + public void go(String inFile, String outFile) throws IOException { + data = new Data(inFile, outFile); + casesNumber = data.readLongLine(); + for (currentCase = 0; currentCase < casesNumber; currentCase++) { + data.writeCaseHeader(currentCase); + processCase(); + } + + data.out.flush(); + } + + private void processCase() throws IOException { + long[] longs = data.readLongsArrayLine(); + long N = longs[0]; + long S = longs[1]; + long p = longs[2]; + long p3 = p * 3; + + long sum = 0; + long s = 0; + for (int g = 3; g < longs.length; g++) { + long pts = longs[g]; + if (pts < p) { + continue; + } + if (pts >= p3 - 2) { + sum++; + } else if (pts >= p3 - 4) { + s++; + } + } + sum += Math.min(S, s); + + data.out.println(sum); + } +} +" +A22180,"import java.io.*; +import java.util.*; + +public class Java{ + + public static void main(String[] args) { + try { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + int cases = Integer.parseInt(in.readLine()); + for (int i = 1; i <= cases; i ++){ + String[] temp = (in.readLine()).split("" ""); + int players = Integer.parseInt(temp[0]); + int surprise = Integer.parseInt(temp[1]); + int best = Integer.parseInt(temp[2]); + int[] totals = new int [players]; + for (int k = 0; k < players; k ++) + totals[k] = Integer.parseInt(temp[k+3]); + logic(players, surprise, best, totals, i); + } + in.close(); + } catch (IOException e) { + System.out.println(""INPUT ERROR""); + } + } + + public static void logic(int numOfPlayers, int surprise, int bestScore, int[] totals, int caseNum){ + int result = 0; + int maybe = 0; + for (int i = 0; i < numOfPlayers; i ++){ + int min = totals[i]/3; + if (min >= bestScore) result ++; + else if (totals[i] != 0) { + int x = totals[i] - (2 * min); + if (x >= bestScore && ((x-1 == min) || (x-1 == bestScore))) result ++; + else if ((x >= bestScore) || ((x == min) && (x+1 == bestScore) && (bestScore - min < 2))) maybe ++; + } + } + if (maybe > surprise) System.out.println(""Case #"" + caseNum + "": "" + (result + surprise)); + else System.out.println(""Case #"" + caseNum + "": "" + (result + maybe)); + } +}" +A20841,"import java.util.*; +import static java.lang.Math.*; + +public class Bsmall { + public static void main(String[] args){ + Scanner input = new Scanner(System.in); + + //```````````````````````````````````````````````````````````````````` + // Read in how many cases there will be, and print a new line + int T = input.nextInt(); + input.skip(""\n""); + System.out.println(); + + //``````````````````````````````````````````````````````````````````` + // For each line calculate max number of googlers with score p + for(int caseNumber = 1; caseNumber <= T; caseNumber++){ + // Read in N, the number of Googlers + int N = input.nextInt(); + + //Read in S, the number of surprising triplets + int S = input.nextInt(); + + // Read in p + int p = input. nextInt(); + + // Read in the next N integers and count how many googlers have a best + // result of at least p + int count = 0; + for (int i =0; i < N; i++) { + int totalValue = input.nextInt(); + int j = totalValue / 3; + int k = (totalValue - j) / 2; + int l = totalValue - (j + k); + + // Test to see if l >= p + // If not, see if it can be made into a special triplet with l < p + if(l >= p){ + count += 1; + continue; + } + else if (S > 0) { + int a = j - 1; + int b = l + 1; + if (a >= 0 && b >= 0 && a <= 10 && b <= 10 && b - a < 3 && b >= p) { + count += 1; + S = S -1; + continue; + } + a = k - 1; + b = l + 1; + if (a >= 0 && b >= 0 && a <= 10 && b <= 10 && b - a < 3 && b >= p) { + count += 1; + S = S -1; + continue; + } + } + } + + // Print results + System.out.format(""Case #%d: %d\n"", caseNumber, count); + } + } +} +" +A22021,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) + { + try{ + // Open the file that is the first + // command line parameter +// FileInputStream fstream = new FileInputStream(""C-small-practice.in""); + FileInputStream fstream = new FileInputStream(""B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + FileWriter foutstream = new FileWriter(""output.out""); + BufferedWriter out = new BufferedWriter(foutstream); + System.out.println (br.readLine()); + int Case = 0; + while ((strLine = br.readLine()) != null) + { + Case+=1; + out.write(""Case #"" + Case + "": ""); + System.out.println (strLine); + String str[] = strLine.split("" ""); + int N = Integer.parseInt(str[0]); + int S = Integer.parseInt(str[1]); + int p = Integer.parseInt(str[2]); + int g[] = new int[str.length-3]; + int y = 0; + for (int i = 3;i=2*p)) + y++; + else if (g[i]==0) ; + else if (((g[i]-p)+4>=2*p)) + { + if (S>0) + { + y++; + S--; + } + + } + System.out.println(y); + //if (((g[i]-p)+4>=2*p)); + + } + out.write(Integer.toString(y)); + out.newLine(); + + + } + out.close(); + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage() + "" "" + e.getCause()); + } + System.exit(-1); + } + + public static void swap (int A[], int x, int y) + { + int temp = A[x]; + A[x] = A[y]; + A[y] = temp; + } + + // Reorganizes the given list so all elements less than the first are + // before it and all greater elements are after it. + public static int partition(int A[], int f, int l) + { + int pivot = A[f]; + while (f < l) + { + // if (A[f] == pivot || A[l] == pivot) + { + // System.out.println(""Only distinct integers allowed - C321""); + // System.out.println(""students should ignore this if statement""); + + } + while (A[f] < pivot) f++; + while (A[l] > pivot) l--; + swap (A, f, l); + } + if (A[f]==A[l]) + return f--; + return f; + } + + public static void Quicksort(int A[], int f, int l) + { + if (f >= l) return; + int pivot_index = partition(A, f, l); + Quicksort(A, f, pivot_index); + Quicksort(A, pivot_index+1, l); + } + public static void bubbleSort1(int[] x) { + int n = x.length; + for (int pass=1; pass < n; pass++) { // count how many times + // This next loop becomes shorter and shorter + for (int i=0; i < n-pass; i++) { + if (x[i] < x[i+1]) { + // exchange elements + int temp = x[i]; x[i] = x[i+1]; x[i+1] = temp; + } + } + } + } + } + + +" +A21583,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.dancingwiththegooglers; + +import uk.co.epii.codejam.common.AbstractProcessor; +import uk.co.epii.codejam.common.Processor; + + +/** + * + * @author jim + */ +public class DancingWithTheGooglersProcessor extends AbstractProcessor { + + public int[] getB(int t) { + switch (t) { + case 0: return new int[] {0,0}; + case 29: return new int[] {10,10}; + case 30: return new int[] {10,10}; + } + switch (t % 3) { + case 0: + return new int[] {t /3, t / 3 + 1}; + case 1: + return new int[] {(t + 2) / 3, (t + 2) / 3}; + case 2: + return new int[] {(t + 1) / 3, (t + 4) / 3}; + } + throw new IllegalArgumentException(""Your t value has defied the "" + + ""peano axioms""); + } + + @Override + public String processLine(String line) { + DataRow dr = new DataRow(line); + int mustReach = 0; + int canOnlyReachWithSurprisingResult = 0; + for (int t : dr.t) { + int[] b = getB(t); + if (b[0] >= dr.p) + mustReach++; + else if (b[1] >= dr.p) + canOnlyReachWithSurprisingResult++; + } + int surprisingContribution = Math.min(dr.S, + canOnlyReachWithSurprisingResult); + return (mustReach + surprisingContribution) + """"; + } + + +} +" +A22998,"import java.io.*; +import java.util.*; +import static java.lang.Math.*; + +public class B { + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""B-large-output.txt"")); + int T = sc.nextInt(); // number of test cases + int numResult; + for (int k=1; k <= T; k++) { + numResult = 0; + + int N = sc.nextInt(); // number of Googlers + int B = sc.nextInt(); // number of surprising triplet scores + int p = sc.nextInt(); // ""best result"" (max of triplets) + int t[] = new int[N]; // total points for a given Googler (b/t 0 & 30) + + int minInd[] = new int[B]; + int minCount = 0; + + for (int i=0; i=num1; num2--) { + for (int num3=min(num1+2,10); num3>=num1; num3--) { + if ((num1+num2+num3)==t[i]) { + if (max(num2, num3)>=p) { + if (max(num2, num3) > (num1+1)) { + surpriseCount++; + } + numResult++; + break firstScore; + } + } + } + } + } + } else { + firstScore: for (int num1=0; num1<11; num1++) { + for (int num2=min(num1+1,10); num2>=num1; num2--) { + for (int num3=min(num1+1,10); num3>=num1; num3--) { + if ((num1+num2+num3)==t[i]) { + if (max(num2, num3)>=p) { + numResult++; + break firstScore; + } + } + } + } + } + } + } + pw.format(""Case #%d: %d\n"", k, numResult); + } + + pw.flush(); + pw.close(); + sc.close(); + } +}" +A20161,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class DancingWithTheGooglers { + + public static void main(String[] args) { + + if (args.length != 2) { + System.out.println(""Usage: java DancingWithTheGooglers ""); + System.exit(0); + } + + try { + + DancingGooglerScoreProcessor processor = + new DancingGooglerScoreProcessor(new FileReader(args[0]), new FileWriter(args[1])); + processor.process(); + + } catch (Exception e) { + + System.out.println(""Sorry, there was a fatal error:""); + e.printStackTrace(); + System.exit(0); + } + } +} + +class DancingGooglerScoreProcessor { + + private final BufferedReader reader; + private final PrintWriter writer; + + public DancingGooglerScoreProcessor(Reader in, Writer out) throws IOException { + + reader = new BufferedReader(in); + writer = new PrintWriter(out); + } + + public void process() throws IOException { + + String line = reader.readLine(); + int numTests = Integer.parseInt(line); + + for (int i = 0; i < numTests; i++) { + + line = reader.readLine(); + writer.printf(""Case #%d: %d"", i + 1, processLine(line)); + writer.println(); + } + + writer.flush(); + writer.close(); + reader.close(); + } + + private int processLine(String line) { + + String[] tokens = line.split("" ""); + int[] scores = new int[Integer.parseInt(tokens[0])]; + int S = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + for (int i = 0; i < scores.length; i++) { + scores[i] = Integer.parseInt(tokens[3+i]); + } + + int numSurprises = 0; + int n = 0; + + for (int score : scores) { + + Set triplets = getPossibleTriplets(score); + removeTripletsThatWillNeverHappen(triplets); + if (hasBestResultOrBetterNoSurprise(p, triplets)) { + n++; + } else { + if (numSurprises < S && hasBestResultOrBetterSurprising(p, triplets)) { + n++; + numSurprises++; + } + } + } + + return n; + } + + private void removeTripletsThatWillNeverHappen(Set triplets) { + + for (Iterator itr = triplets.iterator(); itr.hasNext();) { + Triplet t = itr.next(); + if (t.willNeverHappen()) { + itr.remove(); + } + } + } + + private boolean hasBestResultOrBetterNoSurprise(int bestResult, Set triplets) { + + return hasBestResultOrBetter(bestResult, triplets, false); + } + + private boolean hasBestResultOrBetterSurprising(int bestResult, Set triplets) { + + return hasBestResultOrBetter(bestResult, triplets, true); + } + + private boolean hasBestResultOrBetter(int bestResult, Set triplets, boolean surprisingAllowed) { + + for (Triplet t : triplets) { + if (t.getBestResult() >= bestResult) { + if (t.isSurprising() && !surprisingAllowed) { + continue; + } + return true; + } + } + return false; + } + + private Set getPossibleTriplets(int totalScore) { + + Set possibleTriplets = new HashSet(); + + for (int a = 0; a <= 10; a++) { + for (int b = 0; b <= 10; b++) { + for (int c = 0; c <= 10; c++) { + if ((a + b + c) == totalScore) { + possibleTriplets.add(new Triplet(a, b, c)); + } + } + } + } + + return possibleTriplets; + } +} + +class Triplet { + + private int[] scores = new int[3]; + private boolean surprising = false; + private boolean neverHappen = false; + + public Triplet(int a, int b, int c) { + + scores[0] = a; + scores[1] = b; + scores[2] = c; + Arrays.sort(scores); + + int diff1 = scores[2] - scores[0]; + int diff2 = scores[2] - scores[1]; + int diff3 = scores[1] - scores[0]; + surprising = (diff1 > 1) || (diff2 > 1) || (diff3 > 1); + neverHappen = (diff1 > 2) || (diff2 > 2) || (diff3 > 2); + } + + public int getBestResult() { + return scores[2]; //since the array is sorted in ascending order + } + + public boolean isSurprising() { + return surprising; + } + + public boolean willNeverHappen() { + return neverHappen; + } + + public boolean equals(Object t) { + + if (t == null) { + return false; + } + + if (!(t instanceof Triplet)) { + return false; + } + + Triplet that = (Triplet)t; + return Arrays.equals(scores, that.scores); + } + + public int hashCode() { + + return Arrays.hashCode(scores); + } + + public String toString() { + + StringBuffer sb = new StringBuffer(""[""); + sb.append(scores[0]); + sb.append("",""); + sb.append(scores[1]); + sb.append("",""); + sb.append(scores[2]); + sb.append(""]""); + if (isSurprising()) { + sb.append(""*""); + } + return sb.toString(); + } +} +" +A20990,"package fixjava; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Set; + +/** + * Simple multimap class. + + MultiMap map = MultiMapKeyToSet.make(); + map.put(""a"", ""x""); + map.put(""a"", ""x""); + map.put(""a"", ""y""); + map.put(""b"", ""z""); + System.out.println(Join.joinRecursive(map.entrySet(), "", "", ""["", ""]"")); + + + * + * @author luke + */ +public class MultiMapKeyToSet { + + HashMap> map = new HashMap>(); + + public static MultiMapKeyToSet make() { + return new MultiMapKeyToSet(); + } + + /** Return true if this multimap did not already contain the specified value at the specified key. */ + public boolean put(S key, T value) { + HashSet set = map.get(key); + if (set == null) { + set = new HashSet(); + map.put(key, set); + } + return set.add(value); + } + + public void putAll(S key, Iterable values) { + boolean putSomething = false; + for (T val : values) { + put(key, val); + putSomething = true; + } + if (!putSomething && !map.containsKey(key)) + // If putting an empty collection, need to create an empty set at the key + map.put(key, new HashSet()); + } + + public void putAll(S key, T[] values) { + if (values.length == 0 && !map.containsKey(key)) + // If putting an empty collection, need to create an empty set at the key + map.put(key, new HashSet()); + else + for (T val : values) + put(key, val); + } + + public HashSet get(S key) { + return map.get(key); + } + + /** + * Get the single value mapped to by the key, or null if no value mapped to for this key. + * + * @throws IllegalRuntimeException + * if there is more than one value mapped to by this key. + */ + public T getSingleVal(S key) { + HashSet set = map.get(key); + return CollectionUtils.getSingleVal(set); + } + + public boolean containsKey(S key) { + return map.containsKey(key); + } + + public int sizeKeys() { + return map.size(); + } + + public Set>> entrySet() { + return map.entrySet(); + } + + /** + * Return the union of all values in all mapped sets (i.e. the union of all values mapped to by some key in this MultiMap). + * NOTE: creates a new HashSet with the current union on every invocation, so if you modify the contents of the returned + * HashSet, it won't affect the map. + */ + public HashSet valuesUnion() { + return CollectionUtils.union(map.values()); + } + + public HashMap> getRawMap() { + return map; + } + + public Set keySet() { + return map.keySet(); + } + + /** Invert the mapping */ + public MultiMapKeyToSet invert() { + MultiMapKeyToSet inv = new MultiMapKeyToSet(); + for (Entry> ent : map.entrySet()) { + S key = ent.getKey(); + for (T val : ent.getValue()) + inv.put(val, key); + } + return inv; + } + + public ArrayList>> toList() { + ArrayList>> result = new ArrayList>>(); + for (Entry> ent : map.entrySet()) + result.add(Pair.make(ent.getKey(), ent.getValue())); + return result; + } + + /** Write out to a TSV file */ + public void writeOutToFile(String tsvFile) throws IOException { + PrintWriter writer = new PrintWriter(tsvFile); + for (Entry> ent : map.entrySet()) { + S key = ent.getKey(); + StringBuilder buf = new StringBuilder(); + buf.append(key); + for (T val : ent.getValue()) + buf.append(""\t"" + val); + writer.println(buf.toString()); + } + writer.close(); + } + + /** Read in a String->String map from a TSV file */ + public static MultiMapKeyToSet readFromFile(String tsvFile) throws IOException { + MultiMapKeyToSet map = new MultiMapKeyToSet(); + for (String line : new FileLineIterator(tsvFile)) { + String[] parts = Split.split(line, ""\t""); + String key = parts[0]; + for (int i = 1; i < parts.length; i++) + map.put(key, parts[i]); + } + return map; + } +} +" +A21735,"import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(new File(""c:\\eclipse\\2\\B-large.in"")); + int numTc = scanner.nextInt(); + for (int index = 0; index < numTc; index++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int result = 0; + for (int i = 0; i < n; i++) { + int ti = scanner.nextInt(); + if (ti == 0 && p != 0) { + continue; + } + int score = ti / 3; + if (score >= p) { + result++; + continue; + } + if (score <= (p - 3)) { + continue; + } + int rem = ti - (score * 3); + if (score == (p - 1)) { + if (rem > 0) { + result++; + continue; + } else if (s > 0) { + s--; + result++; + continue; + } + } + if (score == (p - 2)) { + if (rem > 1 && s > 0) { + s--; + result++; + continue; + } + } + } + System.out.println(""Case #"" + (index + 1) + "": "" + result); + + } + } +}" +A22499,"/** + * + * + * @Author :Yasith Maduranga(Merlin) + * @version :1.0 + * @Date :2012/4/14 + * @Copyright GSharp Lab, All Rights Reserved.... + */ +import java.io.*; +import java.util.*; + +class dancinwith { + public static void main(String args[]){ + try{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + + int noOfCases = Integer.parseInt(br.readLine()); + + for(int i=0;i=bestResult){ + maximumNo++; + }else{ + if(noOfSuprisingScores>0 && mod>0 && mod+1>=bestResult){ + maximumNo++; + noOfSuprisingScores--; + } + } + break; + } + case 1:{ + if(mod>=bestResult || mod+1>=bestResult ){ + maximumNo++; + }else{ + if(noOfSuprisingScores>0 && mod+1>=bestResult){ + maximumNo++; + noOfSuprisingScores--; + } + } + break; + } + case 2:{ + if(mod+1>=bestResult || mod>=bestResult){ + maximumNo++; + }else{ + if(noOfSuprisingScores>0 && mod+2>=bestResult){ + maximumNo++; + noOfSuprisingScores--; + } + } + break; + } + } + } + + + out.println(""Case #""+(i+1)+"": ""+maximumNo); + } + + + + out.close(); + }catch(Exception e){ + e.printStackTrace(); + } + System.exit(0); + } +} +" +A23034," +/** + * @(#)gcjB.java + * + * + * @author + * @version 1.00 2012/4/14 + */ +import java.io.*; +public class gcjB { + + /** + * Creates a new instance of gcjB. + */ + public gcjB() { + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + + int lineCount; + String[] lines; + try + { + + + BufferedReader in = new BufferedReader(new FileReader(""Bl.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""Bl.out"")); + String text = in.readLine(); + lineCount = Integer.parseInt(text); + lines = new String[lineCount]; + + + + int x =0, y =0, z =0, sup =0; + + Integer[] maxs = new Integer[lineCount]; + Integer[] maxws = new Integer[lineCount]; + Integer matrix[][] = new Integer[lineCount][2]; + + String surp = new String(""""); + String norm = new String(""""); + for(int i = 0; i < lineCount ; i ++) + { + maxs[i] = 0; + maxws[i] = 0; + for(x=10;x>=0;x--) + { + for(y=x; y>=0;y--) + { + for(z=y;z>=0;z--) + { + if((x+y+z) == i) + { + if(delta(x, y, z) == 1) + { + //ah! surprized + maxs[i] = java.lang.Math.max(maxs[i], maxi(x, y, z)); + } + else if(delta(x, y, z) == 2) + { + //eh, not surprized + maxws[i] = java.lang.Math.max(maxws[i], maxi(x, y, z)); + } + else + { + //don't care + } + } + else + { + //don't care + } + } + } + } + + matrix[i][0] = maxs[i]; + matrix[i][1] = maxws[i]; + } + + + + int Ng = 0 ; + int Spz = 0; + int NgMax = 0; + + int sx = 0; + + int MaxGo = 0; + + for(sx = 0; sx < lineCount; sx++) + { + String[] whatIsLeft; + lines[sx] = in.readLine().trim(); + + whatIsLeft = lines[sx].split("" ""); + + Ng = Integer.parseInt(whatIsLeft[0]); + Spz = Integer.parseInt(whatIsLeft[1]); + NgMax = Integer.parseInt(whatIsLeft[2]); + + + + for(int i=3;i 0) + { + if(matrix[Integer.parseInt(whatIsLeft[i])][1] >= NgMax) + { + MaxGo++; + } + else if(matrix[Integer.parseInt(whatIsLeft[i])][0] >= NgMax) + { + Spz--; + MaxGo++; + } + } + else + { + if(matrix[Integer.parseInt(whatIsLeft[i])][1] >= NgMax) + { + MaxGo++; + } + } + + } + + out.print(""Case #""+(sx+1)+"": ""+MaxGo); + if(sx < lineCount-1) + { + out.println(); + } + MaxGo=0; + } + + in.close(); + out.close(); + } + catch(Exception e) + { + System.out.println(e); + } + } + + public static int delta(int x, int y, int z) + { + if((java.lang.Math.abs(x-y) < 3) && ((java.lang.Math.abs(y-z)) < 3) && (java.lang.Math.abs(z-x) < 3)) + { + if((java.lang.Math.abs(x-y) ==2) || ((java.lang.Math.abs(y-z)) ==2) || (java.lang.Math.abs(z-x) ==2)) + { + return 1; + } + else if((java.lang.Math.abs(x-y) < 2) || ((java.lang.Math.abs(y-z)) < 2) || (java.lang.Math.abs(z-x) < 2)) + { + return 2; + } + } + return 0; + } + public static int maxi(int x, int y, int z) + { + int maxim = x; + maxim = java.lang.Math.max(maxim, y); + maxim = java.lang.Math.max(maxim, z); + + return maxim; + } +} +" +A21237,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Writer; +import java.util.Arrays; + +/** + * Competition + * @author shibink + * + */ +public class DancingScore { + + public static int getCount(String googleLang) { + int count = 0; + + if ((googleLang == null) || (googleLang.isEmpty())) { + return 0; + } + + String[] strArray = googleLang.split("" ""); + + // Min 1 player should be there + if (strArray.length <= 3) { + return 0; + } + int numPlayers = Integer.parseInt(strArray[0]); + + int numSurprises = Integer.parseInt(strArray[1]); + int key = Integer.parseInt(strArray[2]); + int [] totalPoints = new int [numPlayers]; + boolean isSurprise = false; + + if (key == 0) { + return numPlayers; + } + for (int i =0, j = 3; i=0; i--) { + isSurprise = false; + if (key == 1) { + if (totalPoints[i] != 0) { + count++; + } + continue; + } + if ((key * 3) <= totalPoints[i]) + { + count++; + continue; + } + + if (key + ((key - 2) * 2) <= totalPoints[i]) { + + if (((key * 3) == totalPoints[i]) || (((key * 2) + key-1) == totalPoints[i]) + || ((((key-1)*2) + key) == totalPoints[i]) || (((key * 2) + key+1) == totalPoints[i]) + || ((((key+1)*2) + key) == totalPoints[i])) { + isSurprise = false; + } else { + isSurprise = true; + } + + if (isSurprise) { + if (numSurprises > 0) { + numSurprises--; + count++; + } + } else { + count++; + } + } + else { + // No more triplets can be part of the target count since array is sorted + break; + } + } + + return count; + } + + public static void processFile(String fileName) throws IOException { + FileInputStream fstream = new FileInputStream(fileName); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + // use buffering + Writer output = new BufferedWriter(new FileWriter(""output.txt"")); + + try { + String strLine = null; + int numPlayers = 0; + int count = 0; + + if ((strLine = br.readLine()) != null) { + count = Integer.parseInt(strLine); + } + // Read File Line By Line + for (int i = 1; i <= count; i++) { + if ((strLine = br.readLine()) == null) { + return; + } + + numPlayers = getCount(strLine); + System.out.println(""Case #"" + i + "": "" + numPlayers); + + StringBuffer outBuff = new StringBuffer(""Case #"" + i + "": "" + numPlayers + ""\n""); + output.write(outBuff.toString()); + } + + } finally { + // Close the input stream + in.close(); + output.close(); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + String fileName = ""input.in""; + try { + processFile(fileName); + } catch (IOException e) { + // TODO Log error + } + return; + } +} +" +A20339,"import java.io.*; +import java.util.Scanner; + +public class B { + + + static final String IN_FILE = ""B-large.in.in""; + + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(IN_FILE)); + Writer out = new BufferedWriter(new FileWriter(IN_FILE+"".out"")); +// Writer out = new OutputStreamWriter(System.out); + + + Scanner sc = new Scanner(in); + int cases = sc.nextInt(); + sc.nextLine(); + for(int caseNo=1; caseNo<=cases; caseNo++){ + out.write(""Case #"" + caseNo + "": ""); + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int res = 0; + for(int i = 1; i <= N; i ++){ + int sum = sc.nextInt(); + int k = (sum - p) / 2; + if(p > sum){ + continue; + }if(p-k <=1) { + res ++; + } else if(p-k<=2 && S > 0){ + res ++; + S --; + } + } + out.write(Integer.toString(res)); + + if(caseNo cases = new ArrayList(); + + private void readFile(String filepath) { + try { + Scanner sc = new Scanner(new FileInputStream(new File(filepath))); + noCases = Integer.parseInt(sc.nextLine()); + for (int i = 1; i <= noCases; i++) { + String[] line = sc.nextLine().split("" ""); + int N = Integer.parseInt(line[0]); + int S = Integer.parseInt(line[1]); + int p = Integer.parseInt(line[2]); + int[] t = new int[N]; + for (int n = 3; n < line.length; n++) { + t[n - 3] = Integer.parseInt(line[n]); + } + cases.add(new Case(i, S, p, t)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) { + + Dancing d = new Dancing(); + d.readFile(args[0]); + for (Case c : d.cases) { + System.out.println(c); + } + } + + private class Case { + private int caseID; + private int noSurprising; + private int minScore; + private ArrayList scores = new ArrayList(); + + public Case(int caseID, int noSurprising, int minScore, + int[] scores) { + this.caseID = caseID; + this.noSurprising = noSurprising; + this.minScore = minScore; + + for (int sc : scores) { + this.scores.add(new Score(sc)); + } + } + + private int answer() { + int ans = 0; + for (Score sc : scores) { + if (sc.unsurprising >= minScore) { + ans++; + sc.visited = true; + } + } + for (Score sc : scores) { + if (noSurprising == 0) { + break; + } + if (!sc.visited) { + if (sc.surprising >= minScore) { + ans++; + sc.visited = true; + noSurprising--; + } + } + } + return ans; + } + + @Override + public String toString() { + return ""Case #"" + this.caseID + "": "" + this.answer(); + } + + private class Score { + int surprising; + int unsurprising; + boolean visited = false; + + public Score(int sc) { + switch(sc % 3) { + case 0: + unsurprising = sc / 3; + surprising = sc / 3 + 1; + break; + case 1: + unsurprising = sc / 3 + 1; + surprising = sc / 3 + 1; + break; + case 2: + unsurprising = sc / 3 + 1; + surprising = sc / 3 + 2; + break; + } + if (sc < 2 || sc > 28) { + surprising = -1; + } + } + } + } +}" +A21348,"import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; + + +public class Solver { + Scanner inFile=null; + PrintWriter outFile=null; + int N=0;//number of googlers + int S=0;//surprising triplet + int p=0; + int t[]; + int caseNo; + int candidatecount=0; + public Solver(int caseNo){ + this.caseNo=caseNo; + } + public void processInput(Scanner inFile,PrintWriter outFile){ + this.inFile=inFile; + this.outFile=outFile; + readInput(); + produceoutput(); + + } + private void produceoutput() { + + + outFile.printf(""Case #""+caseNo+"": %d\n"",candidatecount); + + } + public void readInput(){ + String s=""""; + if(inFile.hasNext()){ + //get the store credit + N=Integer.parseInt(inFile.next().trim()); + S=Integer.parseInt(inFile.next().trim()); + p=Integer.parseInt(inFile.next().trim()); + + t=new int[N]; + for(int i=0;i0){ + candidatecount++; + S--; + } + } + if(inFile.hasNext())inFile.nextLine(); + } + } + +} +" +A20379,"import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; + +public class MainClass { + + /** + * @param args + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + Scanner sc = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new File(""Dancing-large.out"")); + + int T = sc.nextInt(); + for (int i = 0; i < T; i++) { + int ans = 0; + + int N = sc.nextInt(), S = sc.nextInt(), p = sc.nextInt(); + ArrayList sums = new ArrayList(); + for (int j = 0; j < N; j++) { + sums.add(sc.nextInt()); + } + for (int j = 0; j < N; j++) { + int tempP = p; + + int sum = sums.get(j); + int sumBackup = sum; + while (tempP <= 10 && tempP <= sumBackup) { + sum = sums.get(j); + sum -= tempP; + int half = sum / 2; + int half2 = sum - half; + + if ((Math.abs(half2 - half) <= 1) + && (Math.abs(half2 - tempP) <= 1) + && (Math.abs(tempP - half) <= 1)) { + ans++; + int test = sums.remove(j); + // System.out.println(test + ""\t "" + tempP + ""\t"" + half + // + ""\t"" + half2); + j--; + N--; + break; + } + tempP++; + + } + + } + // System.out.println(S); + outer: for (int j = 0; j < N; j++) { + int tempP = p; + + int sum = sums.get(j); + int sumBackup = sum; + while (tempP <= 10 && tempP <= sumBackup) { + sum = sums.get(j); + sum -= tempP; + int half = sum / 2; + int half2 = sum - half; + if ((Math.abs(half2 - half) <= 2) + && (Math.abs(half2 - tempP) <= 2) + && Math.abs(tempP - half) <= 2) { + if (S != 0) { + + ans++; + S--; + + int test = sums.remove(j); + // System.out.println(test + ""\t "" + tempP + ""\t"" + // + half + ""\t"" + half2 + ""\t"" + S); + + j--; + N--; + break; + } + if (S == 0) { + // System.out.println(""broke""); + break outer; + } + } + tempP++; + + } + + } + /* System.out.println(sums); */ + out.println(""Case #"" + (i + 1) + "": "" + ans); + } + out.close(); + + } +} +" +A20894,"import java.io.*; +import java.math.BigInteger; +import java.util.InputMismatchException; + +/** + * Created by César Passoni + */ +public class TaskB implements Runnable +{ + private InputReader in; + private PrintWriter out; + + public static void main(String[] args) { + new Thread(new TaskB()).start(); + } + + public TaskB() { + try { + String fileName; +// fileName = ""sampleB.in""; +// fileName = ""B-small-attempt9.in""; + fileName = ""B-large.in""; + + System.setIn(new FileInputStream(fileName)); + System.setOut(new PrintStream(new FileOutputStream(fileName.replace(""in"", ""out"")))); + } catch (FileNotFoundException e) { + throw new RuntimeException(); + } + in = new InputReader(System.in); + out = new PrintWriter(System.out); + } + + public void run() { + int numTests = in.readInt(); + for (int testNumber = 0; testNumber < numTests; testNumber++) { + out.print(""Case #"" + (testNumber + 1) + "": ""); + int n = in.readInt(); + int s = in.readInt(); + int p = in.readInt(); + + boolean surprise = s!=0; + int count = 0; + int countSurprise = 0; + for (int i = 0 ; i < n ; i ++) + { + int testCase = in.readInt(); + + if (testCase == 0) + { + if (p == 0) + { + count ++; + } + } + else if (testCase >= (p*3-2)) + { + count ++; + } + + else if (testCase >= (p*3-4) && surprise) + { + count ++; + countSurprise ++; + if (countSurprise >= s) + { + surprise = false; + } + } + +// if (testCase == 0) +// { +// if (s == 0) +// { +// count ++; +// } +// } +// +// else if (testCase%3 == 0) +// { +// if ((testCase/3 ) >= p) +// { +// count ++; +// } +// else if ((testCase/3 + 1) >= p && surprise) +// { +// count ++; +// countSurprise ++; +// if (countSurprise >= s) +// { +// surprise = false; +// } +// } +// +// } +// else +// { +// if ((testCase/3 + 1) >= p) +// { +// count ++; +// +// } +// else if ((testCase/3 + 2) >= p && surprise) +// { +// count ++; +// countSurprise ++; +// if (countSurprise >= s) +// { +// surprise = false; +// } +// } +// } + + } +// System.out.println(""CASE "" + (testNumber + 1) +""countSurprise "" +countSurprise + "" s "" + s); + out.println(count); + + } + out.close(); + } + + private static class InputReader { + private InputStream stream; + private byte[] buf = new byte[1000]; + private int curChar, numChars; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + private int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public long readLong() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + long res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + private boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + private String readLine0() { + StringBuffer buf = new StringBuffer(); + int c = read(); + while (c != '\n' && c != -1) { + buf.appendCodePoint(c); + c = read(); + } + return buf.toString(); + } + + public String readLine() { + String s = readLine0(); + while (s.trim().length() == 0) + s = readLine0(); + return s; + } + + public String readLine(boolean ignoreEmptyLines) { + if (ignoreEmptyLines) + return readLine(); + else + return readLine0(); + } + + public BigInteger readBigInteger() { + try { + return new BigInteger(readString()); + } catch (NumberFormatException e) { + throw new InputMismatchException(); + } + } + + public char readCharacter() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + return (char) c; + } + + public double readDouble() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + double res = 0; + while (!isSpaceChar(c) && c != '.') { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } + if (c == '.') { + c = read(); + double m = 1; + while (!isSpaceChar(c)) { + if (c < '0' || c > '9') + throw new InputMismatchException(); + m /= 10; + res += (c - '0') * m; + c = read(); + } + } + return res * sgn; + } + } +} +" +A20299,"package org.cb.projectb.dancingwiththegooglers; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.StringTokenizer; + +public class Contest { + + public static void main(String[] args) throws FileNotFoundException { + File input = new File(System.getProperty(""user.dir"") + ""/"" + ""resources/projectB/B-large.in""); + Scanner sc = new Scanner(input); + + List contests = new ArrayList(); + + if (sc.hasNext()) { + Integer.parseInt(sc.nextLine()); // number of cases - ignored + while (sc.hasNext()) { + String contestString = sc.nextLine(); + + StringTokenizer contestTokenizer = new StringTokenizer(contestString); + + int contestants = Integer.parseInt(contestTokenizer.nextToken()); + int surprisingTriplets = Integer.parseInt(contestTokenizer.nextToken()); + int scoreWeCareAbout = Integer.parseInt(contestTokenizer.nextToken()); + List scores = new ArrayList(); + for(int i = 0; i < contestants; i ++) { + scores.add(Integer.parseInt(contestTokenizer.nextToken())); + } + + contests.add(new DanceOff(contestants, surprisingTriplets, scoreWeCareAbout, scores)); + } + } + + for(int i = 1; i <= contests.size(); i ++) { + DanceOff danceoff = contests.get(i-1); + + System.out.println(""Case #"" + i + "": "" + danceoff.getNumberAllowedToBeImportant()); + } + } + + private static class DanceOff { + private final int contestants; + private final int surprisingTriplets; + private final int scoreWeCareAbout; + private final List contestantScores; + private final int numberAllowedToBeImportant; + + public DanceOff(int contestants, int surprisingTriplets, int scoreWeCareAbout, List contestantScores) { + this.contestants = contestants; + this.surprisingTriplets = surprisingTriplets; + this.scoreWeCareAbout = scoreWeCareAbout; + this.contestantScores = contestantScores; + + this.numberAllowedToBeImportant = fillInDetails(); + } + + private int fillInDetails() { + int importantScores = 0; + + List allProbableScores = new ArrayList(); + + for(Integer score: contestantScores) { +// System.out.print(score + "" - ""); + + int baseScore = score / 3; + int remaining = score % 3; + Integer[] scoresArray = new Integer[]{baseScore, baseScore, baseScore}; + + for(int i = 0; i < remaining; i++) { + scoresArray[i] = scoresArray[i] + 1; + } + +// System.out.print(""Probable tripplet: [""); +// for(int i = 0; i < scoresArray.length; i++) { +// System.out.print(scoresArray[i] + "" ""); +// } +// System.out.println(""]""); + + allProbableScores.add(scoresArray); + } + + + int freebeeImportantScores = 0; + int ableToBeImportantIfSurprising = 0; + for (Integer[] scoresList : allProbableScores) { + // count how many in scores array are already important + boolean isImportant = false; + boolean canBeSurprising = false; + + for (Integer integer : scoresList) { + if(integer >= this.scoreWeCareAbout) { + isImportant = true; + break; + } + } + if(isImportant) { + freebeeImportantScores++; + } else { + // see how many i can make 'surprising' to then care about + if(scoresList[0] + 1 >= this.scoreWeCareAbout) { + if(scoresList[0] == scoresList[1] && scoresList[0] != 0) { + canBeSurprising = true; + } + } + if(canBeSurprising) { + ableToBeImportantIfSurprising++; + } + } + } + + + + // take min of allowed surprising & how many could be surprised + int numToMakeSpecial = Math.min(ableToBeImportantIfSurprising, this.surprisingTriplets); + + // add min to current important scores + importantScores = freebeeImportantScores + numToMakeSpecial; + +// System.out.println(""Freebee important: "" + freebeeImportantScores); +// System.out.println(""Can be Made Important with surprising Score: "" + ableToBeImportantIfSurprising); +// System.out.println(""Num Of Scores we are making surprising: "" + numToMakeSpecial); +// System.out.println(""Max Special Scores: "" + importantScores); +// System.out.println(); + + return importantScores; + } + + public int getNumberAllowedToBeImportant() { + return numberAllowedToBeImportant; + } + + @Override + public String toString() { + return ""DanceOff [contestants = "" + contestants + + "", surprisingTriplets = "" + surprisingTriplets + + "", scoreWeCareAbout = "" + scoreWeCareAbout + + "", contestantScores = "" + contestantScores + ""]""; + } + } + +} +" +A22512,"import java.io.*; + +class GoogleDance{ + + + public static int isSurprise(int total, int p) + { + int mod = total % 3; + if(p>total) + { + return 2; + } + if(mod==0) + { + if(p<=total/3) + { + return 0; + } + else if(p==total/3+1) + { + return 1; + } + } + else if(mod==1) + { + if(p<=total/3+1) + { + return 0; + } + + } + else if(mod==2) + { + if(p<=total/3+1) + { + return 0; + + } + else if(p==total/3+2) + { + return 1; + } + } + return 2; + } + + public static void main(String[] args) throws IOException + { + String filename =""dancers.txt""; + FileReader fr = new FileReader(""B-large.in""); + BufferedReader br = new BufferedReader(fr); + FileWriter fstream = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + int testcases = Integer.parseInt(br.readLine()); + + for (int i=1;i<=testcases;i++) + { + String line = br.readLine(); + + int N = Integer.parseInt(line.substring(0, line.indexOf(' '))); + line = line.substring(line.indexOf(' ')+1); + int S = Integer.parseInt(line.substring(0, line.indexOf(' '))); + line = line.substring(line.indexOf(' ')+1); + + int p = Integer.parseInt(line.substring(0, line.indexOf(' '))); + line = line.substring(line.indexOf(' ')+1); + + int[] dancers = new int[N]; + for(int k=0;k0) + { + count++; + S--; + } + + } + + out.write(""Case #""+i+"": ""+count); + if(i!=testcases) + { + out.write(""\n""); + } + } + br.close(); + out.close(); + } +}" +A21722,"import java.io.*; +import java.util.Arrays; +import java.util.Comparator; + +public class Qualify { + + public static void main(String[] args) { + try { + BufferedReader reader = new BufferedReader(new FileReader(new File(""B-small-attempt3.in""))); + int cases = Integer.parseInt(reader.readLine()); + for (int d = 0; d < cases; d++) { + + // parse + String line = reader.readLine(); + String[] spLine = line.split("" ""); + int googs = Integer.parseInt(spLine[0]); + int surprises = Integer.parseInt(spLine[1]); + int prize = Integer.parseInt(spLine[2]); + Googler[] googArr = new Googler[googs]; + + // find the solutions for each googler + for (int r = 0; r < googs; r++) { + googArr[r] = new Googler(); + Integer total = Integer.parseInt(spLine[(r + 3)]); + googArr[r].poss(total, prize); + + } + + // sort the array based on how many possibilities it has + Arrays.sort(googArr, new Comparator() { + @Override + public int compare(Googler o1, Googler o2) { + // TODO Auto-generated method stub + return new Integer(o1.trueCounter) + .compareTo(o2.trueCounter); + } + }); + + int surCounter = 0; + int winCounter = 0; + /* + * boolean prizeSurprise = false; boolean prizeNoSurprise = + * false; boolean failSurprise = false; boolean failNoSurprise = + * false; + */ + for (int i = 0; i < googs; i++) { + if (googArr[i].trueCounter == 1) { + if (googArr[i].prizeSurprise == true) { + winCounter++; + surCounter++; + googArr[i].used = true; + } else if (googArr[i].prizeNoSurprise == true) { + winCounter++; + googArr[i].used = true; + } else if (googArr[i].failSurprise == true) { + surCounter++; + googArr[i].used = true; + } else { + // nothing to do with this + googArr[i].used = true; + } + } + } + + for (int i = 0; i < googs && surCounter < surprises; i++) { + if (googArr[i].used == false) { + if (googArr[i].prizeSurprise == true && googArr[i].prizeNoSurprise == false) { + winCounter++; + surCounter++; + googArr[i].used = true; + break; + } + } + } + + for (int i = 0; i < googs && surCounter < surprises; i++) { + if (googArr[i].used == false) { + if (googArr[i].prizeSurprise == true) { + winCounter++; + surCounter++; + googArr[i].used = true; + break; + } + } + } + + for (int i = 0; i < googs && surCounter < surprises; i++) { + if (googArr[i].used == false) { + if (googArr[i].failSurprise == true) { + surCounter++; + googArr[i].used = true; + } + } + } + + for (int i = 0; i < googs; i++) { + if (googArr[i].used == false) { + if (googArr[i].prizeNoSurprise) { + winCounter++; + googArr[i].used = true; + } + } + } + + System.out.println(""Case #"" + (d+1) + "": "" + winCounter); + + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + + } + +} +" +A21017,"package bchang; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +/** + * Created with IntelliJ IDEA. + * User: bchang + * Date: 4/14/12 + * Time: 9:08 PM + * To change this template use File | Settings | File Templates. + */ +public class ProblemB { + + private static int process(String line) { + StringTokenizer st = new StringTokenizer(line); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int counter = 0; + for (int j = 0; j < n; j++) { + int ti = Integer.parseInt(st.nextToken()); + int r = ti - p; + if (r >= 0) { + if (r >= p * 2 - 2) { + counter++; + } + else if (s > 0 && r >= p * 2 - 4) { + counter++; + s--; + } + } + } + return counter; + } + + public static void main(String[] args) throws Exception { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(reader.readLine()); + for (int i = 0; i < t; i++) { + String line = reader.readLine(); + int result = process(line); + System.out.println(""Case #"" + (i + 1) + "": "" + result); + } + } + finally { + if (reader != null) { + try { + reader.close(); + } + catch (IOException e) { + } + } + } + + } +} +" +A20737,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; + +class Factory implements TestCaseFactory { + + @Override + public TestCase getInstance(int number) { + return new DancingWithGooglers(number); + } +} + +public class DancingWithGooglers extends TestCase { + + int caseItem; + + int ngooglers; + int[] scores; + int surprising; + int target; + + int max; + + public DancingWithGooglers(int caseItem) { + this.caseItem = caseItem; + } + + @Override + public void readInput(BufferedReader in) throws IOException, + MalformedInputFileException { + final String str1 = in.readLine(); + final String[] tokens = str1.split(""\\s""); + ngooglers = Integer.parseInt(tokens[0]); + surprising = Integer.parseInt(tokens[1]); + target = Integer.parseInt(tokens[2]); + scores = new int[ngooglers]; + for (int i = 0; i < ngooglers; i++) { + scores[i] = Integer.parseInt(tokens[i + 3]); + } + } + + private int guaranteedMax(int googler) { + if (scores[googler] == 0) { + return 0; + } else { + return (scores[googler] - 1) / 3 + 1; + } + } + + private int higherScores(int googler) { + if (scores[googler] == 3) { + return 0; + } else { + return (scores[googler] - 1) % 3 + 1; + } + } + + @Override + public void solve() { + int guaranteed = 0; + int marginal = 0; + for (int googler = 0; googler < ngooglers; googler++) { + final int guaranteedMax = guaranteedMax(googler); + if (guaranteedMax >= target) { + guaranteed++; + } else if (guaranteedMax == target - 1 + && higherScores(googler) >= 2 && scores[googler] > 0) { + marginal++; + } + } + max = guaranteed + Math.min(marginal, surprising); + } + + @Override + public void writeOutput(PrintWriter out) { + out.print(""Case #"" + (caseItem + 1) + "": ""); + out.print(max); + out.print(""\n""); + + } + + public static void main(String[] args) throws IOException, + MalformedInputFileException { + new Processor().process(new Factory(), args[0], args[1]); + } +}" +A23012," +import java.io.*; +import java.util.*; + +public class CodeJam2012_Q_B { + + public int calc(int N, int S, int p, int[] score) { + int cnt=0; + for(int i=0; i= p+Math.max(p-1, 0)*2) { + cnt++; + } else if(score[i]>=p+Math.max(p-2, 0)*2 && S>0) { + cnt++; + S--; + } + } + + return cnt; + } + + public static void main(String[] args) { + try{ + (new CodeJam2012_Q_B()).exec(""B-large.in"", ""2012_Q_B-large.out""); + }catch(Exception ex) { + + } + } + + public final void exec(String inFileName, String outFileName) throws Exception{ + BufferedReader inReader = new BufferedReader(new FileReader(inFileName)); + PrintWriter outWriter = new PrintWriter(new BufferedWriter(new FileWriter(outFileName))); + int caseNums=0; + caseNums = Integer.parseInt(inReader.readLine()); + + for(int i=0; i= theScoreToBeat[whichLine]) + { + numberOfNaturalWinners[whichLine]++; + wasNatural[whichLine][i] = true; + } + } + + for (int i = 0; i < numberOfDancers[whichLine]; i++) + { + if (surprises[theScores[whichLine][i]] >= theScoreToBeat[whichLine] && wasNatural[whichLine][i] == false) + { + numberOfSurprisingWinners[whichLine]++; + } + } + + + if (numberOfSurprisingWinners[whichLine] > numberOfSurprises[whichLine]) + { + numberOfSurprisingWinners[whichLine] = numberOfSurprises[whichLine]; + } + + return numberOfNaturalWinners[whichLine] + numberOfSurprisingWinners[whichLine]; + } +}" +A22278," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Akash Agrawal + */ +public class DWG { + + public static void main(String [] args) throws FileNotFoundException, IOException + { + Scanner scan= new Scanner(new File(""inp.txt"")); + + int n=scan.nextInt(); + //System.out.println(n); + int cas=1; + while(n--!=0) + { + int t=scan.nextInt(); + int s=scan.nextInt(); + int p=3*scan.nextInt(); + + int count =0; + for(int i=0;i=p-2)count++; + else if(temp>=p-4 && s>0 ) + {count++;s--;} + + } + + System.out.println(""Case #""+cas+++"": ""+count); + + } + } + +} +" +A22731,"public class JudgeScores{ + int jc1; + int jc2; + int jc3; + private boolean isSurprising = false; + + public JudgeScores(int jc1, int jc2, int jc3) { + this.jc1 = jc1; + this.jc2 = jc2; + this.jc3 = jc3; + } + public JudgeScores(int jc1, int jc2, int jc3, boolean isSurprising) { + this.jc1 = jc1; + this.jc2 = jc2; + this.jc3 = jc3; + this.isSurprising = isSurprising; + } + + public int getJC1(){ + return jc1; + } + + public int getJC2(){ + return jc2; + } + + public int getJC3(){ + return jc3; + } + + public void isSurprising(boolean isSurprising){ + this.isSurprising = isSurprising; + } + + public boolean isSurprising(){ + return this.isSurprising; + } + + public int getMaxScore(){ + return Math.max(Math.max(jc1, jc2), jc3); + } + + public int getMinScore(){ + return Math.min(Math.min(jc1, jc2), jc3); + } +}" +A20290,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + + +public class Dance { + private File file = new File(""D:\\Sources\\GoogleCodeJam\\files\\B-large.in""); + private File outFile = new File(""D:\\Sources\\GoogleCodeJam\\files\\result.out""); + + private Integer[] results; + private Integer solved = 0; + + public void readData() { + boolean first = true; + Scanner scanner; + try { + scanner = new Scanner(file); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + Scanner scan = new Scanner(line); + if (first) { + results = new Integer[scan.nextInt()]; + first = false; + } else { + int[] googlers = new int[scan.nextInt()]; + int sup = scan.nextInt(); + int above = scan.nextInt(); + for (int i = 0; i < googlers.length; i++) { + googlers[i] = scan.nextInt(); + } + results[solved] = solveProblem(googlers, sup, above); + solved++; + } + } + printResult(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private Integer solveProblem(int[] googlers, int sup, int above) { + if(above == 0) + return googlers.length; + int notSup = 0; + int suprising = 0; + for (int i = 0; i < googlers.length; i++) { + if(above * 3 - 2 <= googlers[i]) { + notSup++; + } else if(above > 1 && above * 3 - 4 <= googlers[i]) { + suprising++; + } + } + + return suprising > sup ? notSup + sup : notSup + suprising; + } + + private void printResult() { + try { + FileWriter fstream = new FileWriter(outFile); + BufferedWriter out = new BufferedWriter(fstream); + for (int i = 0; i < results.length; i++) { + out.write(""Case #"" + (i + 1) + "": "" + results[i]); + out.newLine(); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A21197,"package dancingWithTheGooglers; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class DancingWithTheGooglers { + public static void main(String[] args) { + File inFile = new File( + ""C:\\Users\\Stef\\workspace\\Google Code Jam\\src\\dancingWithTheGooglers\\large.in""); + FileInputStream fis = null; + Scanner in = null; + + FileWriter outFile; + try { + outFile = new FileWriter( + ""C:\\Users\\Stef\\workspace\\Google Code Jam\\src\\dancingWithTheGooglers\\large.out""); + BufferedWriter out = new BufferedWriter(outFile); + + try { + fis = new FileInputStream(inFile); + + in = new Scanner(fis); + int cases, googlers, surprises, result, no; + cases = in.nextInt(); + + for (int i = 0; i < cases; i++) { + googlers = in.nextInt(); + surprises = in.nextInt(); + result = in.nextInt(); + no = 0; + int[] totalScore = new int[googlers]; + for (int j = 0; j < googlers; j++) + totalScore[j] = in.nextInt(); + for (int j = 0; j < googlers; j++) + if (totalScore[j] % 3 == 0) { + if (totalScore[j] / 3 >= result) + no++; + else if (totalScore[j] / 3 == result - 1 && totalScore[j]>0) + if (surprises > 0) { + no++; + surprises--; + } + } else if (totalScore[j] % 3 == 1) { + if (totalScore[j] / 3 >= result - 1) + no++; + } else { + if (totalScore[j] / 3 >= result - 1) + no++; + else if (totalScore[j] / 3 == result - 2 && totalScore[j]<29) + if (surprises > 0) { + no++; + surprises--; + } + } + out.write(""Case #"" + (i + 1) + "": "" + no + ""\n""); + } + + fis.close(); + in.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + out.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } +} +" +A21152,"/** + * + */ +package google.jam.code; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * @author walir + * + */ +public class DancingGooglers { + + private HashMap s = new HashMap(); + private HashMap ns = new HashMap(); + + private BufferedReader bufferedReader; + + public DancingGooglers() throws FileNotFoundException { + setUpS(); + setUpNS(); + File file = new File(""C:/test""); + InputStreamReader in = new InputStreamReader(new FileInputStream(file)); + bufferedReader = new BufferedReader(in); + } + + private void setUpS() { + s.put(0, 0); + s.put(1, 1); + s.put(2, 2); + s.put(3, 2); + s.put(4, 2); + s.put(5, 3); + s.put(6, 3); + s.put(7, 3); + s.put(8, 4); + s.put(9, 4); + s.put(10, 4); + s.put(11, 5); + s.put(12, 5); + s.put(13, 5); + s.put(14, 6); + s.put(15, 6); + s.put(16, 6); + s.put(17, 7); + s.put(18, 7); + s.put(19, 7); + s.put(20, 8); + s.put(21, 8); + s.put(22, 8); + s.put(23, 9); + s.put(24, 9); + s.put(25, 9); + s.put(26, 10); + s.put(27, 10); + s.put(28, 10); + s.put(29, 10); + s.put(30, 10); + } + + private void setUpNS() { + ns.put(0, 0); + ns.put(1, 1); + ns.put(2, 1); + ns.put(3, 1); + ns.put(4, 2); + ns.put(5, 2); + ns.put(6, 2); + ns.put(7, 3); + ns.put(8, 3); + ns.put(9, 3); + ns.put(10, 4); + ns.put(11, 4); + ns.put(12, 4); + ns.put(13, 5); + ns.put(14, 5); + ns.put(15, 5); + ns.put(16, 6); + ns.put(17, 6); + ns.put(18, 6); + ns.put(19, 7); + ns.put(20, 7); + ns.put(21, 7); + ns.put(22, 8); + ns.put(23, 8); + ns.put(24, 8); + ns.put(25, 9); + ns.put(26, 9); + ns.put(27, 9); + ns.put(28, 10); + ns.put(29, 10); + ns.put(30, 10); + } + + public static void main(String[] args) throws NumberFormatException, IOException{ + DancingGooglers dancingGooglers = new DancingGooglers(); + dancingGooglers.bp(); + } + + private void bp() throws IOException { + int numberOfCases = Integer.valueOf(bufferedReader.readLine()); + + for (int i = 1; i <= numberOfCases; i++) { + String s[] = bufferedReader.readLine().split("" ""); + int googlers = Integer.valueOf(s[0]); + int noOfSurprise = Integer.valueOf(s[1]); + int minScore = Integer.valueOf(s[2]); + ArrayList scores = new ArrayList(); + for(int j=0;j scores) { + int r = 0; + int tS = noOfSurprise; + for(int i=0;i=minScore){ + r++; + } else if(s.get(scr)>=minScore && tS>0){ + r++; + tS--; + } + } + return r; + } + +} +" +A22901,"import java.awt.datatransfer.StringSelection; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * Created by IntelliJ IDEA. + * User: Дмитрий + * Date: 14.04.12 + * Time: 16:41 + * To change this template use File | Settings | File Templates. + */ +public class Problem{ + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(System.in); + PrintWriter out = new PrintWriter(new FileOutputStream(""result.txt"")); + + + int cc = in.nextInt(); + in.nextLine(); + for(int zz=1;zz<=cc;++zz){ + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + + int res = 0; + + for(int i=0;i0) + res++; + } + else { + int p1,p2; + p1 = p-1; + p2 = p-2; + if (p+p1+p1<=t){ + res++; + } else if (s>0 && p+p2+p2<=t){ + res++; + --s; + } + } + } + + out.println(""Case #""+zz+"": ""+res); + } + out.close(); + } +} +" +A20831,"package score; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Score1 { + public static void main(String[] args)throws IOException { + File file = new File(""B-large.in""); + BufferedWriter saida = new BufferedWriter(new FileWriter(""saida.out"")); + Scanner scan = new Scanner(file); + int casos; + String[] divisao = {}; + String linha; + + casos = Integer.parseInt(scan.nextLine()); + + + for (int i =1; i <= casos;i++){ + saida.write(""Case #"" + i + "": ""); int alcancou = 0; + int podeSurpresa = 0; + linha = scan.nextLine(); + divisao = linha.split(""\\s+""); + int competidores = Integer.parseInt(divisao[0]); + int surpresas = Integer.parseInt(divisao[1]); + int notaMin = Integer.parseInt(divisao[2]); + + + ArrayList placar = new ArrayList(competidores); + + for(int j = 0; j < competidores ; j++){ + placar.add(j, Integer.parseInt(divisao[3+j])); + } + for(int j = 0;j < competidores;j++){ + if(placar.get(j) == 3*notaMin-4 || placar.get(j) == 3*notaMin-3 && 3*notaMin - 4 >= 0 ){ + if(podeSurpresa < surpresas){ + podeSurpresa++; + alcancou++; + } + } + else if(placar.get(j) > 3*notaMin-3){ + alcancou++; + } + } + saida.write(alcancou + """"); + saida.newLine(); + } + + if (saida != null){ + saida.flush(); + saida.close(); + } + + } + +} +" +A22446,"import java.io.File; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws Exception { + Scanner in = new Scanner(new File(""input.in"")); + int t, n, s, p, ans; + int scores[]; + t = in.nextInt(); + for (int tc = 1; tc <= t; tc++) { + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + ans = 0; + scores = new int[n]; + for (int i = 0; i < scores.length; i++) { + scores[i] = in.nextInt(); + } + + for (int i = 0; i < scores.length; i++) { + if (scores[i] == 0 && p != 0) + continue; + if (scores[i] / 3 >= p) { + ans++; + continue; + } + if ((double) scores[i] / 3 == scores[i] / 3) { + if (p - scores[i] / 3 == 1 && s > 0) { + ans++; + s--; + continue; + } + } else { + double temp = (double) scores[i] / 3; + if (scores[i] - 3 * Math.floor(temp) < 2 + && scores[i] - 2 * Math.floor(temp) >= p) + ans++; + else if (scores[i] - 3 * Math.ceil(temp) < 2 + && (scores[i] - 2 * Math.ceil(temp) >= p || Math + .ceil(temp) >= p)) + ans++; + else if (scores[i] - 3 * Math.floor(temp) == 2 && s != 0 + && scores[i] - 2 * Math.floor(temp) >= p) { + ans++; + s--; + } else if (scores[i] - 3 * Math.ceil(temp) == 2 && s != 0 + && scores[i] - 2 * Math.ceil(temp) >= p) { + ans++; + s--; + } + } + + } + System.out.println(""Case #"" + tc + "": "" + ans); + + } + } +} +" +A21020,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.Scanner; + +/** + * @author Mark Devine + * + */ +public class B { + static final boolean DEBUG = false; + static Scanner in; + static PrintStream out; + + public static void main(String[] args) throws FileNotFoundException { + if (DEBUG) { + in = new Scanner(new File(""t"")); + out = System.out; + } else { + in = new Scanner(new File(B.class.getName() + "".in"")); + out = new PrintStream(B.class.getName() + "".out""); + } + int T = i(); + for (int i = 0; i < T; i++) { + pl(f(""Case #%d: %s"", i + 1, solve())); + } + out.close(); + in.close(); + System.out.println(""Done""); + } + + static String solve() { + int Number = i(); + int Surprising = i(); + int minResult = i(); + + int supMin = 3 * minResult - 4; + int regMin = 3 * minResult - 2; + + if (supMin == -1) { + supMin = 1; + } + if (supMin <= 0) { + supMin = 0; + } + if (regMin < 0) { + regMin = 0; + } + + Integer[] results = new Integer[Number]; + for (int i = 0; i < Number; i++) { + results[i] = i(); + } + Arrays.sort(results, Collections.reverseOrder()); + +// pl(f(""Suprising min: %d, %d"", minResult, supMin)); +// pl(Arrays.toString(results)); + for (int i = 0; i < Number; i++) { + if (results[i] >= regMin) { + continue; + } else if (results[i] >= supMin && Surprising > 0) { + Surprising--; + continue; + } else { + return i + """"; + } + } + + return Number + """"; + } + + static void p(String x) { + out.print(x); + } + + static void pl(String x) { + out.println(x); + } + + static String f(String format, Object... args) { + return String.format(format, args); + } + + static int i() { + return in.nextInt(); + } + + static long l() { + return in.nextLong(); + } + + static String s(String pattern) { + return in.next(pattern); + } + + static String li() { + return in.nextLine(); + } +}" +A22754,"package qualification.dancingWithTheGooglers; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + // Input + // + // 4 + // 3 1 5 15 13 11 + // 3 0 8 23 22 21 + // 2 1 1 8 0 + // 6 2 8 29 20 8 18 18 21 + // + // 1 ≤ T ≤ 100. + // 0 ≤ S ≤ N. + // 0 ≤ p ≤ 10. + // 0 ≤ ti ≤ 30. + // At least S of the ti values will be between 2 and 28, inclusive. + + /** + * @param args + */ + public static void main(String[] args) { + try { + Scanner scan = new Scanner( + new File( + ""D:\\eclipse\\Ghani\\GCJ\\src\\qualification\\dancingWithTheGooglers\\B-large.in"")); + // new File( + // ""D:\\eclipse\\Ghani\\GCJ\\src\\qualification\\dancingWithTheGooglers\\test.txt"")); + try { + int nbCas = Integer.parseInt(scan.nextLine()); + String result = new String(); + for (int i = 0; i < nbCas; i++) { + int nbG = scan.nextInt(); + int nbS = scan.nextInt(); + int p = scan.nextInt(); + + ArrayList scores = new ArrayList(); + + for (int j = 0; j < nbG; j++) { + scores.add(scan.nextInt()); + } + + int reponse = bestResult(scores, nbS, p); + result += printCase(i, reponse); + } + System.out.print(result); + } finally { + scan.close(); + } + } catch (IOException ioe) { + System.out.println(""Erreur --"" + ioe.toString()); + } + + } + + private static int bestResult(ArrayList scores, int nbS, int p) { + int result = 0; + int surprising = 0; + if (p > 0 && p < 30) { + for (Integer integer : scores) { + // System.out.println(integer); + if (integer < (3 * (p - 1)) - 1 || integer == 0) { + result += 0; + // System.out.println(""aucun""); + } else if (integer >= (3 * p) - 2) { + result += 1; + // System.out.println(""tous""); + } else { + surprising += 1; + // System.out.println(""ça depend""); + } + + } + result += Math.min(surprising, nbS); + } else if (p == 10) { + for (Integer integer : scores) { + if (integer == 30) { + result += 1; + } + } + } else { + result = scores.size(); + } + return result; + } + + public static String printCase(int i, int reponse) { + + String ligne = ""Case #"" + (i + 1) + "": "" + reponse + ""\n""; + return ligne; + } + +} +" +A22440," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author UDDAMA + */ +public class Dance { + + private int danceManager(String inputLine) { + + int count = 0; + + String[] info = inputLine.split("" ""); + int players = Integer.parseInt(info[0]); + int suprise = Integer.parseInt(info[1]); + int p = Integer.parseInt(info[2]); + + for (int i = 3; i < info.length; i++) { + + int thisscore = Integer.parseInt(info[i]); + int tobe = info.length - i; + + if (tobe > suprise) { + + if (hasacount(withoutsuprise(thisscore), p)) { + count++; + } else if (hasacount(withsuprise(thisscore), p) && thisscore > 1 && thisscore < 29 && suprise > 0) { + count++; + suprise--; + } + + } else if (tobe <= suprise) { + + if (hasacount(withsuprise(thisscore), p) && thisscore > 1 && thisscore < 29 && suprise > 0) { + count++; + suprise--; + } + + } + + + } + + return count; + } + + private boolean hasacount(int[] inputset, int pval) { + + for (int j = 0; j < inputset.length; j++) { + if (inputset[j] >= pval) { + return true; + } + } + return false; + } + + private int[] withsuprise(int input) { + int[] out = new int[3]; + int n = input / 3; + + if (input % 3 == 0) { + out[0] = n - 1; + out[0] = n; + out[0] = n + 1; + } else if (input % 3 == 1) { + out[0] = n - 1; + out[0] = n + 1; + out[0] = n + 1; + } else if (input % 3 == 2) { + out[0] = n; + out[0] = n; + out[0] = n + 2; + } + return out; + } + + private int[] withoutsuprise(int input) { + + int[] out = new int[3]; + int n = input / 3; + + if (input % 3 == 0) { + out[0] = n; + out[0] = n; + out[0] = n; + } else if (input % 3 == 1) { + out[0] = n; + out[0] = n; + out[0] = n + 1; + } else if (input % 3 == 2) { + out[0] = n; + out[0] = n + 1; + out[0] = n + 1; + } + return out; + } + + public static void main(String[] args) throws IOException { + + + BufferedReader is = new BufferedReader(new InputStreamReader(System.in)); + String inputLine = is.readLine(); + Dance d = new Dance(); + + int cases = Integer.parseInt(inputLine); + + for (int i = 0; i < cases; i++) { + + inputLine = is.readLine(); + System.out.println(""Case #"" + (i + 1) + "": "" + d.danceManager(inputLine)); + + + } + + } +} +" +A20317,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class SecondQuestion { + + public static int findBestScore(double[] scores, int surprise, int p){ + + int count = 0; + for(int i = 0; i < scores.length; i++) + { + if(scores[i] > 0) + { + double app = scores[i] / 3; + app = Math.ceil(app); + if(app >= p) + count++; + else + { + if(surprise > 0) + { + if((app + 1) >= p) + { + if(((app + 1) + (app - 1) + (app - 1)) == scores[i] || + ((app + 1) + (app - 1) + (app)) == scores[i] || + ((app + 1) + (app) + (app)) == scores[i]) + { + surprise--; + count++; + } + } + } + } + } + else + { + if(p == 0) + count++; + } + } + + return count; + + } + + public static void main(String args[]) { + try{ + int numLines; + String result = """"; + FileInputStream fstream = new FileInputStream(""B-large.in""); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + numLines = Integer.parseInt(br.readLine()); + for(int i = 0; i < numLines; i++) + { + String[] str = br.readLine().split("" ""); + double[] scores = new double[Integer.parseInt(str[0])]; + int surprise = Integer.parseInt(str[1]); + int p = Integer.parseInt(str[2]); + for(int j = 3; j < str.length; j++) + scores[(j-3)] = Double.parseDouble(str[j]); + result = result + ""Case #"" + (i+1) + "": "" + findBestScore(scores, surprise, p) + ""\n""; + } + in.close(); + + //write the solution to file + FileWriter outstream = new FileWriter(""solution.txt""); + BufferedWriter out = new BufferedWriter(outstream); + out.write(result); + //Close the output stream + out.close(); + + } catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A21390,"package de.hg.codejam.tasks.dance.service; + +import de.hg.codejam.tasks.dance.domain.Case; + +public abstract class Calculator { + + public static int[] calculate(Case[] cases) { + int[] results = new int[cases.length]; + + for (int i = 0; i < cases.length; i++) + results[i] = calculate(cases[i]); + + return results; + } + + public static int calculate(Case c) { + int result = 0; + + short upperBorder = calculateUpperBorder(c.getBestResult()); + short lowerBorder = calculateLowerBorder(c.getBestResult()); + + int numberOfSurprisingTriplets = c.getNumberOfSurprisingTriplets(); + + for (byte points : c.getTotalPoints()) { + if (points >= upperBorder) + result++; + else if (points >= lowerBorder && numberOfSurprisingTriplets > 0) { + result++; + numberOfSurprisingTriplets--; + } + } + + return result; + } + + private static short calculateUpperBorder(short bestResult) { + if (bestResult < 1) + return bestResult; + + return (short) (bestResult + 2 * (bestResult - 1)); + } + + private static short calculateLowerBorder(short bestResult) { + if (bestResult < 2) + return bestResult; + + return (short) (bestResult + 2 * (bestResult - 2)); + } + +} +" +A21950,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + + +public class Googlers { + + + public static void main(String[] args) { + + try{ + + File dance = new File(""C:\\Users\\Moeen\\Documents\\0 ECLIPSE\\IO Folder\\Input\\B-large.in""); + FileWriter outFile = new FileWriter(""C:\\Users\\Moeen\\Documents\\0 ECLIPSE\\IO Folder\\Output\\B-large.out""); + PrintWriter dancePrint = new PrintWriter(outFile); + + Scanner scan = new Scanner(dance); + String inputString = new String(); + ArrayList numbersArray = new ArrayList(); + + inputString = scan.nextLine(); + int totalNoCases = Integer.parseInt(inputString); + System.out.println(""Total Number of Cases: "" + totalNoCases); + + for (int caseNo = 1; caseNo <= totalNoCases; caseNo++){ + System.out.println(""Case #"" + caseNo + "": ""); + dancePrint.print(""Case #"" + caseNo + "": ""); + + inputString = scan.nextLine(); + + int startIndex = 0; + for (int itemCounter = 0; itemCounter < inputString.length(); itemCounter++){ + if (inputString.charAt(itemCounter) == ' '){ + numbersArray.add(Integer.parseInt(inputString.substring(startIndex, itemCounter))); + startIndex = (itemCounter +1); + } + } + numbersArray.add(Integer.parseInt(inputString.substring(startIndex))); + + int nGooglers = numbersArray.get(0); + int sSurprising = numbersArray.get(1); + int pBestResult = numbersArray.get(2); + int bestCounter = 0; + + + numbersArray.remove(0); + numbersArray.remove(0); + numbersArray.remove(0); + + int [] tripArray = new int[3]; + + for (int scores = 0; scores < nGooglers; scores++){ + + //System.out.println(numbersArray.get(scores)); + int tripScores = numbersArray.get(scores)/3; + tripArray[0] = tripScores; + tripArray[1] = tripScores; + tripArray[2] = tripScores; + + int remainder = (numbersArray.get(scores) - (tripScores*3)); + + if (remainder > 0){ + for (int i = 0; i < remainder; i++){ + tripArray[i]++; + } + } + Arrays.sort(tripArray); + + if (tripArray[2] >= pBestResult){ + bestCounter++; + } + else if( sSurprising != 0 && tripArray[2] != 0){ + if(tripArray[2] +1 >= pBestResult){ + bestCounter++; + sSurprising--; + } + } + + } + + System.out.println(bestCounter); + dancePrint.println(bestCounter); + numbersArray.clear(); + } + + scan.close(); + dancePrint.close(); + + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + catch (IOException e1){ + System.out.println(""Error"" + e1); + } + + + } + +} +" +A20179,"package CodeJam2012.Qualification; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + +public class ProblemB { + + private static final String DIRECTORIO = ""D:\\CodeJam\\CodeJam2012\\Qualification\\ProblemB\\""; + + private static final String FILE_IN = ""ejemplo.in""; + //private static final String FILE_IN = ""A-small-practice.in""; + // private static final String FILE_IN = ""A-small-attempt0.in""; + // private static final String FILE_IN = ""A-large.in""; + + private static final String FILE_OUT = ""ejemplo.out""; + //private static final String FILE_OUT = ""a-small-practice.out""; + // private static final String FILE_OUT = ""a-small.out""; + // private static final String FILE_OUT = ""a-large.out""; + + public static void main(String[] args) throws Exception { + + // Se prepara para leer del fichero y escribir + FileReader fr = new FileReader(DIRECTORIO + FILE_IN); + BufferedReader bf = new BufferedReader(fr); + File ficheroOut = new File(DIRECTORIO + FILE_OUT); + ficheroOut.delete(); + BufferedWriter bw = new BufferedWriter(new FileWriter(ficheroOut)); + + int casosPrueba = Integer.parseInt(bf.readLine()); + + // Se hace cada caso de prueba + for (int index = 1; index <= casosPrueba; index++) { + + String[] entrada = bf.readLine().split("" ""); + + int concursantes = Integer.parseInt(entrada[0]); + int numeroSorpresas = Integer.parseInt(entrada[1]); + int notaCorte = Integer.parseInt(entrada[2]); + + ArrayList puntuacionesTotales = new ArrayList(); + + + int cumplidores=0; + int posiblesSorpresas=0; + + for (int i = 0; i < concursantes; i++) { + int puntuacionConcursante = Integer.parseInt(entrada[3 + i]); + + int parejaMenos = puntuacionConcursante - notaCorte; + + if (parejaMenos >= (notaCorte-1)*2 && parejaMenos >=0){ + cumplidores++; + }else if (parejaMenos >= (notaCorte-2)*2 && parejaMenos >=0){ + posiblesSorpresas++; + } + } + + + int maximasSorpresas =0; + if (posiblesSorpresas >= numeroSorpresas){ + maximasSorpresas = numeroSorpresas; + }else{ + maximasSorpresas = posiblesSorpresas; + } + + + + + // Se escribe la solución del caso en pantalla y en fichero + String solucion = ""Case #"" +index +"": "" + (maximasSorpresas+cumplidores); + bw.write(solucion); + bw.newLine(); + System.out.println(solucion); + } + + // Se cierra el buffer de escritura + bw.close(); + } + + + + +} + + +" +A20745,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlecodejam2012; + +import java.io.*; + +/** + * + * @author Stephen + */ +public class GoogleCodeJam2012Num2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try + { + FileInputStream fs = new FileInputStream(""input.txt""); + DataInputStream in = new DataInputStream(fs); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + FileWriter fws = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fws); + String numLine = br.readLine(); + System.out.println(numLine); + int numCases = Integer.parseInt(numLine); + String caseLine; + for(int i = 1; i <= numCases; i++) + { + caseLine = br.readLine(); + System.out.println(""Case #""+i); + String[] splitted = caseLine.split("" ""); + int numGooglers = Integer.parseInt(splitted[0]); + int surprising = Integer.parseInt(splitted[1]); + int p = Integer.parseInt(splitted[2]); + System.out.println(numGooglers+"" Googlers, ""+surprising+"" surprising results, p=""+p); + //int[] util = new int[numGooglers]; + int maxResult = 0; + for(int j = 0; j < numGooglers; j++) + { + int totalScore = Integer.parseInt(splitted[j+3]); + int maxScore = totalScore/3+1; + if(totalScore%3 == 0) + maxScore--; + if(maxScore >= p) + maxResult++; + else + { + if(totalScore%3 != 1 && surprising > 0 && maxScore+1 == p && maxScore != 0) + { + surprising--; + maxResult++; + } + } + System.out.println(""Total: ""+totalScore+"" Max: ""+maxScore); + } + System.out.println(""Max Result: ""+maxResult); + out.write(""Case #""+i+"": ""+maxResult+""\r\n""); + } + in.close(); + out.close(); + + displayOutput(); + } + catch (Exception e) + { + System.err.println(""Oops! Error occured: "" + e.getMessage()); + } + } + + public static String gDecode(String input) + { + String decoded = """"; + for(int i = 0; i < input.length(); i++) + { + if(input.charAt(i) == ' ') + decoded += ' '; + else + decoded += decodeChar(input.charAt(i)-'a'); + } + return decoded; + } + + public static String googleKey = ""yhesocvxduiglbkrztnwjpfmaq""; + + public static char decodeChar(int encoded) + { + return googleKey.charAt(encoded); + } + + public static void displayOutput() + { + System.out.println(""START OUTPUT\n-------------------""); + try + { + FileInputStream fs = new FileInputStream(""output.txt""); + DataInputStream in = new DataInputStream(fs); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String readLine; + while ((readLine = br.readLine()) != null) { + System.out.println(readLine); + } + } + catch (Exception e) + { + System.err.println(""Oops! Error occured: "" + e.getMessage()); + } + System.out.println(""---------------------\nEND OUTPUT""); + } +} +" +A21798,"import java.io.*; +import java.util.*; +import java.awt.Point; + +class Case{ + long num1,Ngoogle,Special,p; + int total; + String result=""""; + public Case(File aFile) + { + try{ + StringBuilder contents = new StringBuilder(); + BufferedReader input = new BufferedReader(new FileReader(aFile)); + String line = input.readLine(); + num1 = Integer.valueOf(line).intValue(); + + int i=1; + total=0; + + System.out.println(""nmber of ttal cases""+ num1 +""testing""); + + while (i<=num1 && ( line = input.readLine()) != null) + { + + StringTokenizer st = new StringTokenizer(line,"" ""); + + Ngoogle=Integer.valueOf(st.nextToken()); + // System.out.println(""ngooge #""+ Ngoogle); + + Special=Integer.valueOf(st.nextToken()); + // System.out.println(""Special #""+ Special); + + p=Integer.valueOf(st.nextToken()); + // System.out.println(""p #""+ p); + + // use this for testing + long normalP=p*3-2; + long specialP=p*3-4; + int ii=1; + + while (ii<=Ngoogle) + { + long temp=Integer.valueOf(st.nextToken()); + // okay test the temp integer + + if(p==0) + { + total++; + } + else if(p==1) + { + if(temp>=1) + total++; + } + else if(temp>=normalP) + { + total++; + } + else if(Special>0 && temp>=specialP) + { + total++; + Special--; + } + ii++; + } + + + //System.out.println(result); + // output total... or save to vector. + // System.out.println(""Case #""+ i +""total""+ total); + oneCase(i, total); + total=0; + i++; + + } + + } + catch (IOException ex){ + ex.printStackTrace(); + } + } + + public String getResult (){ + + return result; + + } + + + public void oneCase (int c, int total){ + + // System out Case #c: total + System.out.println(""Case #""+ c +"":"" +total); + result+=""Case #""+c+"": ""+total+System.getProperty(""line.separator""); + } + + +} + + +public class ReadWriteTextFile { + static public String getContents(File aFile) { + StringBuilder contents = new StringBuilder(); + try { + BufferedReader input = new BufferedReader(new FileReader(aFile)); + try { + String line = null; + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty(""line.separator"")); + } + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + return contents.toString(); + } + static public void setContents(File aFile, String aContents) + throws FileNotFoundException, IOException { + if (aFile == null) { + throw new IllegalArgumentException(""File should not be null.""); + } + if (!aFile.exists()) { + throw new FileNotFoundException (""File does not exist: "" + aFile); + } + if (!aFile.isFile()) { + throw new IllegalArgumentException(""Should not be a directory: "" + aFile); + } + if (!aFile.canWrite()) { + throw new IllegalArgumentException(""File cannot be written: "" + aFile); + } + Writer output = new BufferedWriter(new FileWriter(aFile)); + try { + output.write( aContents ); + } + finally { + output.close(); + } + } + public static void main (String... aArguments) throws IOException { + File testFile = new File(""B-large.in""); + File testFile2 = new File(""result.txt""); + Case allcases = new Case(testFile); + setContents(testFile2, allcases.getResult()); + } +} + + + + + + + + + + +" +A21639,"public class CodeJamLineParser { + private final String[] tokens; + private int position; + + public CodeJamLineParser(String line) { + tokens = line.split(""\\s""); + position = 0; + } + + public boolean hasNextField() { + return hasNextFields(1); + } + + public int remainingFields() { + return tokens.length - position; + } + + public boolean hasNextFields(int count) { + return remainingFields() >= count; + } + + public String readNextStr() { + return tokens[position++]; + } + + public int readNextInt() { + return Integer.parseInt(readNextStr()); + } + + public int[] readNextIntList(int numOfInts) { + int[] result = new int[numOfInts]; + for (int i = 0; i < numOfInts; ++i) { + result[i] = readNextInt(); + } + return result; + } +} +" +A20444,"import java.util.Scanner; + + +public class B { + public static void main(String args[]) { + Scanner in = new Scanner(System.in); + + int cases; + cases = in.nextInt(); + in.nextLine(); + + for(int i = 0; i < cases; i ++ ) { + int n = in.nextInt(); + int surprises = in.nextInt(); + int threshold = in.nextInt(); + + int passed = 0; + for( int j = 0; j < n; j ++ ) { + int score = in.nextInt(); + if( score/3.0 >= threshold) { + passed++; + continue; + } + score -= threshold; + if( score < 0 ) { + continue; + } + int test1 = score - ( threshold - 1 ); + if( test1 >= 0 ) { + if( test1 >= ( threshold - 1 ) && test1 <= ( threshold + 1 ) ) { + passed++; + continue; + } + } + test1++; + if( test1 < 0 ) { + continue; + } + if( test1 >= ( threshold - 2 ) && test1 <= ( threshold + 2 ) ) { + if( surprises > 0 ) { + passed++; + surprises--; + continue; + } + } + } + System.out.println(""Case #"" + (i+1) + "": "" + passed); + } + } +} +" +A22798,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.Arrays; + +public class Speak implements Runnable { + + BufferedReader in; + BufferedWriter out; + static String inputFile = """"; + static String outputFile = """"; + + static { + inputFile = Speak.class.getName() + "".in""; + outputFile = Speak.class.getName() + "".out""; + } + + public int iread() throws Exception { + return Integer.parseInt(readword()); + } + + public double dread() throws Exception { + return Double.parseDouble(readword()); + } + + public long lread() throws Exception { + return Long.parseLong(readword()); + } + + public String readword() throws Exception { + int c = in.read(); + while( c >= 0 && c <= ' ' ) { + c = in.read(); + } + if( c < 0 ) return """"; + StringBuilder bld = new StringBuilder(); + while( c > ' ' ) { + bld.append((char)c); + c = in.read(); + } + return bld.toString(); + } + + public void solve() throws Exception { + + int t = iread(); + for (int i = 0; i < t; i++) { + int r = 0; + int n = iread(); + int s = iread(); + int p = iread(); + //if (p == 0) { + //r = n; + //} else { + int p3 = 3 * p; + for (int j = 0; j < n; j++) { + int score = iread(); + if (score == 0) { + continue; + } else if (score >= p3 - 2) { + r++; + } else if (score >= p3 - 4 && s != 0) { + r++; + s--; + } + } + //} + if(p==0){ + r=n; + } + out.write(""Case #"" + (i + 1) + "": "" + r + ""\n""); + } + } + + public void run() { + try { + in = new BufferedReader( new FileReader( inputFile )); + out = new BufferedWriter( new FileWriter( outputFile )); +// in = new BufferedReader( new InputStreamReader(System.in)); +// out = new BufferedWriter( new OutputStreamWriter(System.out)); + solve(); + out.flush(); + } catch( Exception e ) { + e.printStackTrace(); + } + } + public static void main(String[] args) { + new Thread( new Speak()).start(); + } + +} +" +A22757,"import java.io.*; +import java.util.Scanner; + +public class dancingWithTheGooglers +{ + + public static void main (String[] args) throws IOException + { + + File file = new File(""in.txt""); + Scanner input = null; + try + { + input = new Scanner(file); + } + catch(IOException e){} + + int T = input.nextInt(); + int N, S, p, t[]; + int scoreDiv, scoreMod; + int score[] = new int[3]; + int solution; + for (int i = 0; i < T; i++) + { + N = input.nextInt(); + S = input.nextInt(); + p = input.nextInt(); + t = new int[N]; + solution = 0; + + for (int j = 0; j < N; j++) + { + t[j] = input.nextInt(); + scoreDiv = t[j] / 3; + scoreMod = t[j] % 3; + + score[0] = scoreDiv; + score[1] = scoreDiv; + score[2] = scoreDiv; + for (int k = 0; k < scoreMod; k++) + { + score[k]++; + } + if(score[0] >= p || score[1] >= p || score[2] >= p) + solution++; + else + { + if (S > 0) + { + if (scoreMod == 0 || scoreMod == 2) + { + if (score[1] > 0) + { + score[0]++; + score[1]--; + } + if (score[0] >= p) + { + solution++; + S--; + } + } + else if (scoreMod == 1) + { + if (score[2] > 0) + { + score[1]++; + score[2]--; + } + if (score[0] >= p) + { + solution++; + S--; + } + } + } + } + } + + System.out.println(""Case #"" + (i + 1) + "": "" + solution); + } + + } + +}" +A21001,"/** + * + */ +package fixjava; + +public class ConcurrentCounter { + private int count = 0; + + public synchronized int getAndIncrement() { + return count++; + } +}" +A20131,"package qualifying; + +import java.util.*; + +public class DancingWithGooglers { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + + final int T = in.nextInt(); + for (int testCase = 1; testCase <= T; ++testCase) { + + // initialize parameters + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int[] t = new int[N]; + for (int i = 0; i < N; ++i) + t[i] = in.nextInt(); + Arrays.sort(t); + + // make as many people as possible >= p + int overCount = 0; + for (int i = N - 1; i >=0; --i) { + int disagree = minDisagreement(t[i], p); + if (disagree > 2) { + break; + } else if (disagree == 2 && S == 0) { + break; + } else if (disagree == 2) { + --S; + } + ++overCount; + } + assert (S == 0); + System.out.printf(""Case #%d: %d\n"", testCase, overCount); + + } + } + + private static int minDisagreement(int total, int minHighScore) { + if (total >= 3 * minHighScore) + return 0; + else if (total < minHighScore) + return Integer.MAX_VALUE; //i.e. impossible + else + return minHighScore - (total - minHighScore)/2; + } + +} +" +A22472,"package com.google.codejam.B; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class Triplet { + public static void main(String[] args) { + String line = null; + BufferedReader reader = null; + File file = new File(""c:\\write.txt""); + BufferedWriter output = null; + try { + output = new BufferedWriter(new FileWriter(file)); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + reader = new BufferedReader(new FileReader(""c:\\temp1.txt"")); + line = reader.readLine(); + int n = Integer.parseInt(line); + for (int i=0;i=p){ + count++; + continue; + } + if (noOfSurprizing>0){ + if (result+1>=p){ + count++; + noOfSurprizing--; + continue; + } + } + break; + case 1: + if (result+1>=p){ + count++; + } + break; + case 2: + if (result+1>=p){ + count++; + continue; + } + if (noOfSurprizing>0){ + if (result+2>=p){ + count++; + noOfSurprizing--; + continue; + } + } + break; + default: + break; + } + + } + output.write(count+""""); + + if (i!=n-1) + output.write(""\n""); + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally{ + try { + reader.close(); + output.close(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } + +} +" +A21255,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class Dancing { + static int s; + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + int [] a; + int n, p, res; + StringTokenizer st; + for (int i = 1; i <= T; i++) { + res = 0; + st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + s = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + // System.out.println(n+ "" "" +s+ "" "" + p); + a = new int [n]; + for(int j = 0 ; j < n ; j ++) + a[j] = Integer.parseInt(st.nextToken()); + for(int j = 0 ; j < n ; j ++) + res += check(a[j], p); + System.out.println(""Case #"" + i + "": ""+res); + } + } + private static int check(int i, int p) { + int a,b,c; + a = i/3; + b = (i-a)/2; + c = i - (a+b); + // System.out.println(i + "" lol"" +a+"" hena"" + c); + if(c >= p) + return 1; + if((c == a || c == b ) && c+1 >= p && (a != 0 || b != 0)&& s > 0){ + s--; + return 1; + } + return 0; + } +} +" +A22775,"package lt.kasrud.gcj.common.io; + +import java.io.*; +import java.util.List; + +public class Writer { + private static String formatCase(int caseNr, String output){ + return String.format(""Case #%d: %s"", caseNr, output); + } + + public static void writeFile(String filename, List data) throws IOException { + BufferedWriter writer = new BufferedWriter(new FileWriter(filename)); + for (int i = 0; i < data.size(); i++) { + String output = formatCase(i+1, data.get(i)); + writer.write(output + ""\n""); + } + writer.close(); + } +} +" +A21636,"public class InvalidInputException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -3613289305328322102L; + + public InvalidInputException() { + super(); + // TODO Auto-generated constructor stub + } + + public InvalidInputException(String arg0, Throwable arg1, boolean arg2, + boolean arg3) { + super(arg0, arg1, arg2, arg3); + // TODO Auto-generated constructor stub + } + + public InvalidInputException(String arg0, Throwable arg1) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + public InvalidInputException(String arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public InvalidInputException(Throwable arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + +} +" +A22455,"import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public abstract class JamProblem { + + int caseCount; + int lastLine; + + abstract String solveCase(JamCase jamCase); + abstract JamCase parseCase(List file, int line); + List loadFile() throws IOException { + FileReader inputStream = new FileReader(""C:\\projekt\\codejam\\src\\input.txt""); + BufferedReader reader = new BufferedReader(inputStream); + List list = new ArrayList(); + while (true) { + String line = reader.readLine(); + if (line == null) { + break; + } + list.add(line); + } + return list; + } + + void go() throws IOException { + List file = loadFile(); + + + parseFirstLine(file); + FileWriter writer = new FileWriter(""C:\\projekt\\codejam\\src\\otput.txt""); + for (int c=0; c< caseCount; c++) { + JamCase casee= parseCase(file, lastLine); + lastLine += casee.lineCount; + String s = solveCase(casee); + writer.write(""Case #"" + (c+1) +"": "" + s + ""\n""); + } + writer.close(); + } + + void parseFirstLine(List file) { + int[] firstLine = JamUtil.parseIntList(file.get(0), 1); + this.caseCount = firstLine[0]; + lastLine = 1; + } +} +" +A23051,"package dancing; + +import java.io.BufferedReader; +import java.io.FileReader; + +public class MaxScoreDetector { + + /** + * @param args + */ + public static void main(String[] args) { + String fileName = null; + if(args.length == 1){ + fileName = args[0]; + }else{ + System.err.println(""Requires a command line argument: fileName""); + System.exit(1); + }; + + new MaxScoreDetector(fileName); + + } + + public MaxScoreDetector(String fileName){ + try{ + BufferedReader in = new BufferedReader(new FileReader(fileName)); + int cases = Integer.parseInt(in.readLine()); + for(int i=0; i= min || Math.ceil(avg)>=min){ + count++; + continue; + } + if(Math.round(avg) == (int)avg + 1 && Math.round(avg) + 1 >= min && over > 0){ + count++; + over--; + continue; + } + if(avg == (int)avg && avg + 1 >= min && over > 0){ + over--; + count++; + continue; + } + + } + return count; + } + +} +" +A20390,"package codejam; +import java.io.*; +public class FileWrite { + String fileName; + BufferedWriter bw; + FileWriter fw; + FileWrite(String fileName){ + this.fileName=fileName; + File f=new File(""K:\\CodeJam\\Results\\""+fileName); + try{ + fw=new FileWriter(f); + bw=new BufferedWriter(fw); + }catch(Exception e){ + System.out.println(""Invalid file name.""); + } + } + + public void writeLine(String str){ + try { + bw.write(str+""\n""); + } catch (IOException e) { + System.out.println(""Error writing to file""); + } + + } + + public void close(){ + try { + bw.close(); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} +" +A21057,"package QualificationRound; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream(""dancingwiththegooglers.in"")); + System.setOut(new PrintStream(""dancingwiththegooglers.out"")); + + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(bf.readLine()); + for(int t = 1; t <= T; t++) { + System.out.print(""Case #"" + t + "": ""); + + String[] parts = bf.readLine().trim().split(""[ ]+""); + int N = Integer.parseInt(parts[0]); + int S = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + int[] scores = new int[N]; + for(int i = 3; i < parts.length; i++) + scores[i - 3] = Integer.parseInt(parts[i]); + + if(p == 0) { + System.out.println(N); + continue; + } + if(p == 1) { + int count = 0; + for(int i = 0; i < N; i++) + if(scores[i] > 0) count++; + + System.out.println(count); + continue; + } + + //p = 8 + // 6 6 8 = 20 surprising + // 6 7 8 = 21 surprising + // surprising -> 3 * p - 4 && 3 * p - 3 + + int normal = 0, surprising = 0; + for(int i = 0; i < N; i++) { + if(scores[i] < 3 * p - 4) continue; + + if(scores[i] < 3 * p - 2) surprising++; + else normal++; + } + + if(surprising > S) surprising = S; + + System.out.println((normal + surprising)); + } + } + +} +" +A22926,"package com.vp.common; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintStream; +import java.util.Scanner; + +public class InputOutputProcessor { + + private int numberOfCases; + private boolean doesInputHaveDataSetLines; + private int indexOfDataSetLine; + private int numberOfDataSetLines; + private final static String DELIMITER = "" ""; + + private Scanner scanInput; + + public void initializeInput(String strInputFileName) { + readInput(strInputFileName); + numberOfCases = Integer.parseInt(scanInput.nextLine()); + } + + /* + * read input + */ + private void readInput(String strInputFileName) { + try { + scanInput = new Scanner(new BufferedReader(new FileReader( + strInputFileName))); + } + + catch (Exception exp) { + // exp.printStackTrace(); + System.out.println("" Please provide File Name with proper location ""); + } + } + + public String[] getDataSet() throws Exception { + String[] dataSet; + String strDataSetLine = """"; + + strDataSetLine = scanInput.nextLine(); + + // System.out.println(""strDataSetLine: "" + strDataSetLine); + + if (doesInputHaveDataSetLines) { + String[] DataSetLineArray = strDataSetLine.split(DELIMITER); + numberOfDataSetLines = Integer + .parseInt(DataSetLineArray[indexOfDataSetLine]); + } + + dataSet = new String[numberOfDataSetLines]; + dataSet[0] = strDataSetLine; + + for (int i = 1; i < numberOfDataSetLines; i++) { + dataSet[i] = scanInput.nextLine(); + } + return dataSet; + } + + /** + * * @return Returns the numberOfDataSetLines. + */ + public int getNumberOfDataSetLines() { + return numberOfDataSetLines; + } + + /** + * @param numberOfDataSetLines + * The numberOfDataSetLines to set. + */ + public void setNumberOfDataSetLines(int numberOfDataSetLines) { + this.numberOfDataSetLines = numberOfDataSetLines; + } + + /** + * * @return Returns the numberOfCases. + */ + public int getNumberOfCases() { + return numberOfCases; + } + + /** + * * @return Returns the doesInputHaveDataSetLines. + */ + public boolean isDoesInputHaveDataSetLines() { + return doesInputHaveDataSetLines; + } + + /** + * @param doesInputHaveDataSetLines + * The doesInputHaveDataSetLines to set. + */ + public void setDoesInputHaveDataSetLines(boolean doesInputHaveDataSetLines) { + this.doesInputHaveDataSetLines = doesInputHaveDataSetLines; + } + + /** + * * @return Returns the indexOfDataSetLine. + */ + public int getIndexOfDataSetLine() { + return indexOfDataSetLine; + } + + /** + * @param indexOfDataSetLine + * The indexOfDataSetLine to set. + */ + public void setIndexOfDataSetLine(int indexOfDataSetLine) { + this.indexOfDataSetLine = indexOfDataSetLine; + } + + public void closeScanner() { + scanInput.close(); + } + + public void writeOutput(String outputFileName, String[] resultArray) { + // To be moved out + PrintStream out = null; + try { + out = new PrintStream(new FileOutputStream(outputFileName)); + for (int i = 0; i < resultArray.length; i++) { + out.print(resultArray[i]); + out.print(""\n""); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(0); + } + + } + +} +" +A20986,"package fixjava; + +import java.util.concurrent.Callable; +import java.util.concurrent.Future; + +import fixjava.ParallelWorkQueue.CallableFactory; + +public class ArrayStats { + public final double[][] data; + public final int n, k; + + private double[][] centered; + private double[] mean; + private double[][] cov; + private double[] stddev = null; + private double[][] corr = null; + + /** Calculate covariance matrix */ + public ArrayStats(double[][] data) { + if (data == null || data.length < 2 || data[0].length < 2) + throw new IllegalArgumentException(""Invalid data""); + this.data = data; + this.n = data.length; + this.k = data[0].length; + } + + /** Compute mean for each dimension */ + public double[] mean() { + if (mean == null) { + mean = new double[k]; + for (int dim = 0; dim < k; dim++) { + double tot = 0; + for (int pt = 0; pt < n; pt++) + tot += data[pt][dim]; + mean[dim] = tot / n; + } + } + return mean; + } + + /** Compute stddev for each dimension */ + public double[] stddev() { + if (stddev == null) { + // Make sure means are computed + mean(); + + stddev = new double[k]; + for (int dim = 0; dim < k; dim++) { + for (int pt = 0; pt < n; pt++) { + double diff = data[pt][dim] - mean[dim]; + stddev[dim] += diff * diff; + } + stddev[dim] = Math.sqrt(stddev[dim] / n); + } + } + return stddev; + } + + /** Re-center data by subtracting mean from each dimension */ + public double[][] centered() { + if (centered == null) { + // Make sure means are computed + mean(); + + centered = new double[n][k]; + for (int pt = 0; pt < n; pt++) + for (int dim = 0; dim < k; dim++) + centered[pt][dim] = data[pt][dim] - mean[dim]; + } + return centered; + } + + /** Compute covariance matrix */ + public double[][] cov() { + if (cov == null) { + // Make sure centered version of data is computed + centered(); + + // Work on transposed array for cache coherence + final double[][] centeredT = ArrayUtils.transpose(centered); + + cov = new double[k][k]; + + try { + //final DecimalFormat formatPercent1dp = new DecimalFormat(""0.0%""); + for (Future res : new ParallelWorkQueue(/* numThreads = */25, + ParallelWorkQueue.makeIntRangeIterable(k), new CallableFactory() { + //IntegerMutable counter = new IntegerMutable(); + + @Override + public Callable newInstance(final Integer ii) { + return new Callable() { + int dim1 = ii.intValue(); + double[][] centeredTLocal = centeredT; + double[][] covLocal = cov; + + @Override + public Void call() { + for (int dim2 = dim1; dim2 < k; dim2++) { + double numer = 0.0; + for (int pt = 0; pt < n; pt++) + numer += centeredTLocal[dim1][pt] * centeredTLocal[dim2][pt]; + int denom = n - 1; + covLocal[dim1][dim2] = covLocal[dim2][dim1] = denom == 0 ? 0 : numer / denom; + } + // int count = counter.increment(); + // if (count % 10 == 0) + // System.out.println(formatPercent1dp.format((count / (float) (k - 1)))); + return null; + } + }; + } + })) + // Barricade + res.get(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + return cov; + } + + /** Compute correlation matrix */ + public double[][] corr() { + if (corr == null) { + // Make sure per-dim stddevs and covariance matrix are computed + stddev(); + cov(); + + corr = new double[k][k]; + for (int dim1 = 0; dim1 < k; dim1++) { + for (int dim2 = dim1; dim2 < k; dim2++) { + double prod = stddev[dim1] * stddev[dim2]; + corr[dim1][dim2] = corr[dim2][dim1] = prod == 0.0 ? 0.0 : cov[dim1][dim2] / prod; + } + } + } + return corr; + } +} +" +A20469,"import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * Created with IntelliJ IDEA. + * User: vors + * Date: 4/14/12 + * Time: 6:40 PM + * To change this template use File | Settings | File Templates. + */ +public class B { + public static void main(String[] args) throws Exception { + B b = new B(); + b.go(); + } + + private void go() throws Exception { + Scanner in = new Scanner(new File(""b.in"")); + PrintWriter out = new PrintWriter(new File(""b.out"")); + int T = in.nextInt(); + for (int cas=1; cas<=T; cas++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] t = new int[N]; + int res = 0; + for (int i=0; i= p) { + res++; + break; + } + if (x / 3 + 1 >= p && x / 3 > 0 && S > 0) { + S--; + res++; + break; + } + break; + } + case 1 : { + if (x / 3 + 1 >= p) { + res++; + break; + } + break; + } + case 2 : { + if (x / 3 + 1 >= p) { + res++; + break; + } + if (x / 3 + 2 >= p && x / 3 > 0 && S > 0) { + S--; + res++; + break; + } + break; + } + default: throw new RuntimeException(""Unreachable "" + x % 3); + } + } + out.printf(""Case #%d: %d\n"", cas, res); + } + out.close(); + } +} +" +A21758,"package Dancing; + +import java.io.FileWriter; +import java.io.FileReader; +import java.io.PrintWriter; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.lang.Character; +import java.util.ArrayList; + +public class DancingWithGooglers +{ + static String path = ""C:\\Users\\hao\\Documents\\NetBeansProjects\\CodeJam2012\\src\\Dancing\\Bl.in""; + static String out_path = ""C:\\Users\\hao\\Documents\\NetBeansProjects\\CodeJam2012\\src\\Dancing\\Bl.txt""; + static BufferedReader inputStream; + static PrintWriter outputStream; + + public static void main( String args[] ) + { + try + { + inputStream = new BufferedReader( new FileReader(path)); + outputStream = new PrintWriter( new FileWriter(out_path)); + + String num_tc = inputStream.readLine(); + int tc = Integer.parseInt(num_tc); + + for( int i = 0 ; i < tc ; i++ ) + { + String get = inputStream.readLine(); + int info[] = ProcessInput(get); + int fre = Process(info); + String ot = ""Case #""+(i+1)+"": ""; + ot += fre; + //System.out.println(ot); + outputStream.write(ot+""\n""); + } + + if( outputStream != null ) + outputStream.close(); + if( inputStream != null ) + inputStream.close(); + } + catch( IOException e ) + { + ; + } + } + + private static int Process( int[] info ) + { + int no_employee = info[0]; + int suprise = info[1]; + int points = info[2]; + + for( int i = 3 ; i < info.length-1 ; i++ ) + { + for( int j = i+1 ; j < info.length ; j++ ) + { + if( info[i] < info[j] ) + { + int temp = info[i]; + info[i] = info[j]; + info[j] = temp; + } + } + } + + int emp[][] = new int[no_employee][3]; + for( int i = 0 ; i < no_employee ; i++ ) + { + for( int j = 0 ; j < 3 ; j++ ) + { + emp[i][j] = 0; + } + } + + for( int i = 0 ; i < no_employee ; i++ ) + { + int pts = info[3+i]; + for( int j = 0 ; j < pts ; j++ ) + { + emp[i][j%3]++; + } + } + + for( int i = 0 ; i < no_employee ; i++ ) + { + for( int j = 0 ; j < 3 ; j++ ) + { + //System.out.print(emp[i][j]+"" ""); + } + //System.out.println(); + } + + //System.out.println(""suprise""); + int count = 0; + for( int i = 0 ; i < no_employee ; i++ ) + { + if( count == suprise ) + { + break; + } + + if( !Check(emp[i],points)) + { + int r[] = Suprise( emp[i]); + + if( r[0] != -1 && r[1] != -1 ) + { + if( r[0] == 0 && r[1] ==1 ) + { + emp[i][0]++; + emp[i][1]--; + } + else if( r[0] == 0 && r[1] == 2) + { + emp[i][0]++; + emp[i][2]--; + } + else + { + emp[i][1]++; + emp[i][2]--; + } + count++; + } + } + } + + /* + for( int i = 0 ; i < no_employee ; i++ ) + { + for( int j = 0 ; j < 3 ; j++ ) + { + System.out.print(emp[i][j]+"" ""); + } + System.out.println(); + } + * + */ + return CheckNum(emp,points); + + } + + private static int CheckNum( int[][] emp , int max ) + { + //System.out.println(""max: ""+max); + for( int i = 0 ; i < emp.length ; i++ ) + { + for( int j = 0 ;j < emp[i].length ;j++) + { + //System.out.print(emp[i][j]+"" ""); + } + //System.out.println(); + } + int fre = 0; + for( int i = 0 ; i < emp.length ; i++ ) + { + if( emp[i][0] >= max ) + { + fre++; + } + } + //System.out.println(fre); + return fre; + } + private static boolean Check( int[] pts, int max ) + { + boolean valid = false; + for( int i = 0 ; i < pts.length ; i++ ) + { + if( pts[i] >= max ) + { + valid = true; + break; + } + } + + return valid; + } + + private static int[] Suprise( int[] pts) + { + int r[] = new int[2]; + if( (Math.abs((pts[0]+1)-(pts[1]-1)) == 2) && (pts[1]>0) && (pts[0]>0)) + { + r[0] = 0; + r[1] = 1; + } + else if((Math.abs((pts[1]+1)-(pts[2]-1)) == 2)&& (pts[1]>0) && (pts[2]>0)) + { + r[0] = 1; + r[1] = 2; + } + else if((Math.abs((pts[0]+1)-(pts[2]-1)) == 2)&& (pts[0]>0) && (pts[2]>0)) + { + r[0] = 0; + r[1] = 2; + } + else + { + r[0] = -1; + r[1] = -1; + } + + return r; + } + private static int[] ProcessInput( String get ) + { + String token = """"; + int N = 0; + int S = 0; + int P = 0; + int i = 0; + + for( ; get.charAt(i) != ' '; i++) + { + token += get.charAt(i); + } + N = Integer.parseInt(token); + token = """"; + i++; + + + for( ; get.charAt(i) != ' '; i++ ) + { + token += get.charAt(i); + } + S = Integer.parseInt(token); + token = """"; + i++; + + for( ; get.charAt(i) != ' ';i++) + { + token += get.charAt(i); + } + P = Integer.parseInt(token); + token = """"; + i++; + + int val[] = new int[N]; + int n = 0; + for( ; i < get.length() ; i++ ) + { + if( get.charAt(i) == ' ') + { + val[n] = Integer.parseInt(token); + n++; + token = """"; + i++; + } + token += get.charAt(i); + } + val[n] = Integer.parseInt(token); + + + int r[] = new int[3+N]; + r[0] = N; + r[1] = S; + r[2] = P; + + /* + System.out.println(N); + System.out.println(S); + System.out.println(P); + + * + */ + for(int z = 0,x=3 ; z < val.length ; z++,x++ ) + { + //System.out.println(val[z]); + r[x] = val[z]; + } + + return r; + } +} +" +A21195,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; +import java.util.StringTokenizer; + + +public class Solution implements Runnable { + + private BufferedReader in; + private StringTokenizer st; + private PrintWriter out; + + private void solve() throws IOException { + int t = nextInt(); + for (int test = 1; test <= t; test++) { + int answer = readAndSolve(); + out.println(""Case #"" + test + "": "" + answer); + } + } + + private int readAndSolve() throws IOException { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = nextInt(); + } + int[] maxNorm = calcMaxNormal(t); + int[] maxStrange = calcMaxStrange(t); + int[][] a = new int[n + 1][n + 1]; + for (int i = 0; i <= n; i++) { + for (int j = 0; j <= n; j++) { + a[i][j] = -1; + } + } + a[0][0] = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j <= i; j++) { + if (a[i][j] >= 0) { + int[] d = {maxNorm[i], maxStrange[i]}; + for (int k = 0; k < d.length; k++) { + if (d[k] >= 0) { + a[i + 1][j + k] = Math.max(a[i + 1][j + k], a[i][j] + (d[k] >= p ? 1 : 0)); + } + } + } + } + } + return a[n][s]; + } + + private int[] calcMaxNormal(int[] t) { + int[] result = new int[t.length]; + for (int i = 0; i < t.length; i++) { + result[i] = calcMaxNormal(t[i]); + } + return result; + } + + private int calcMaxNormal(int sum) { + return (sum + 2) / 3; + } + + private int[] calcMaxStrange(int[] t) { + int[] result = new int[t.length]; + for (int i = 0; i < t.length; i++) { + result[i] = calcMaxStrange(t[i]); + } + return result; + } + + private int calcMaxStrange(int sum) { + int result; + if (sum % 3 == 2) { + result = sum / 3 + 2; + } else { + result = sum / 3 + 1; + } + if (result - 2 < 0 || result > 10) { + return -1; + } + return result; + } + + @Override + public void run() { + try { + solve(); + } catch (Throwable e) { + apstenu(e); + } finally { + out.close(); + } + } + + private int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + private String next() throws IOException { + while (!st.hasMoreTokens()) { + String line = in.readLine(); + if (line == null) { + return null; + } + st = new StringTokenizer(line); + } + return st.nextToken(); + } + + private void apstenu(Throwable e) { + e.printStackTrace(); + System.exit(1); + } + + public Solution(String filename) { + try { + in = new BufferedReader(new FileReader(filename + "".in"")); + st = new StringTokenizer(""""); + out = new PrintWriter(new FileWriter(filename + "".out"")); + } catch (IOException e) { + apstenu(e); + } + } + + public static void main(String[] args) { + Locale.setDefault(Locale.US); + new Solution(""data"").run(); + } + +} +" +A20615,"public class Combinations +{ + /* + * Since for a given number 0 - 30, + * MAXIMUM only 2 valid set (distinct combinations) + * of 3 integers (0 - 10) + * which add up to give the number as sum + * are available, + * We consider two such set for all the numbers from 0-30 + */ + + int countPopultatedSet; + + int s[][] = {{0,0,0},{0,0,0}}; + Surprising surprising[] = new Surprising [2]; + + int bestResult[] = {1000 , 1000}; //1000 represents default value + //Index 0 => for Surprising Result + //Index 1 => for Non Surprising Result + + Combinations() + { + countPopultatedSet = 0; + surprising[0] = new Surprising(); + surprising[1] = new Surprising(); + } + + boolean ignore(int x , int y , int z , int whichSurprising) + { + int d1 = x - y; + int d2 = y - z; + int d3 = z - x; + + if(d1 >= -2 && d1 <= 2) + { + if(d2 >= -2 && d2 <= 2) + { + if(d3 >= -2 && d3 <= 2) + { + if(d3 == -2 || d3 == 2 || d2 == -2 || d2 == 2 || d1 == -2 || d1 == 2) + { + + surprising[whichSurprising].isSurprising = 'Y'; + } + else + { + surprising[whichSurprising].isSurprising = 'N'; + } + return false; + } + } + } + + return true; + } + + void populateSets(int x , int y , int z) + { + switch(countPopultatedSet) + { + case 0: + if(!(ignore(x, y, z, 0))) + { + s[0][0] = x; + s[0][1] = y; + s[0][2] = z; + + int tempIndex; + + if(surprising[0].isSurprising == 'Y') + { + tempIndex = 0; + } + else + { + tempIndex = 1; + } + + bestResult[tempIndex] = (x > y) ? ((x > z) ? x : z) :((y>z) ? y : z); + + countPopultatedSet++; + } + break; + + case 1: + if(!(ignore(x, y, z, 1))) + { + if( + !( + (x == s[0][0] && (y == s[0][1] || y == s[0][2])) || + (x == s[0][1] && (y == s[0][2] || y == s[0][0])) || + (x == s[0][2] && (y == s[0][0] || y == s[0][1])) + ) + ) + { + //Condition to Avoid repeat while adding + s[1][0] = x; + s[1][1] = y; + s[1][2] = z; + + int tempIndex; + + if(surprising[1].isSurprising == 'N') + { + tempIndex = 1; + } + else + { + tempIndex = 0; + } + + bestResult[tempIndex] = (x > y) ? ((x > z) ? x : z) :((y>z) ? y : z); + + countPopultatedSet++; + } + } + break; + } + } + + void displayCombinations(int x) + { + System.out.println(x + ""a => ""); + + System.out.println(s[0][0] + "","" + s[0][1] + "","" + s[0][2] + "" : "" + surprising[0].isSurprising + "" Best = "" + ((surprising[0].isSurprising) == 'Y' ? bestResult[0] : bestResult[1])); + + if(countPopultatedSet == 2) + { + System.out.println(s[1][0] + "","" + s[1][1] + "","" + s[1][2] + "" : "" + surprising[1].isSurprising + "" Best = "" + ((surprising[1].isSurprising) == 'Y' ? bestResult[0] : bestResult[1])); + } + } +}" +A22028,"import java.util.*; + +public class Scores { + public static int tests = 0; + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + tests = Integer.parseInt(scan.nextLine()); + + for (int i=1; i<=tests; i++) { + String[] input = scan.nextLine().split(""\\s+""); +// int g = Integer.parseInt(input[0]); + int surprises = Integer.parseInt(input[1]); + int goal = Integer.parseInt(input[2]); + + int numGoal = 0; + + for (int j=3; j=goal) + numGoal++; + } + else if (score == 29 || score == 30) { + if (10>=goal) + numGoal++; + } + else if (score % 3 == 0) { + if (max >= goal) + numGoal++; + else + if (max+1 >= goal && surprises > 0){ + numGoal++; + surprises--; + } + } + else if (score % 3 == 1) { + if (max+1 >= goal) + numGoal++; + } + else if (score % 3 == 2) { + if (max+1 >= goal) + numGoal++; + else + if (max+2 >= goal && surprises > 0) { + numGoal++; + surprises--; + } + } + } + else if (score==0 && max>=goal) + numGoal++; + } + + System.out.println(""Case #"" + i + "": "" + numGoal); + } + } +} +" +A20962,"import java.util.Scanner; + + +public class DancingWiththeGooglers { + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + int T = Integer.parseInt(sc.nextLine()); + int r[] = new int[T]; + + for (int i = 0; i < T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + for (int j = 0; j < N; j++) { + int total = sc.nextInt(); + if (total >= p) { + if ((p*3 - 2) <= total) { + r[i]++; + } else if ((p*3 - 4) <= total && S > 0) { + S--; + r[i]++; + } + } + } + } + + for (int i = 0; i < r.length; i++) { + System.out.println(""Case #"" + (i + 1) + "": "" + r[i]); + } + } +}" +A20674,"package com.spelchec.codejam.project2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + +public class Main { + public static void main (String[] args) throws IOException { + final String outputTemplate = ""Case #%d: %d\n""; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int run = Integer.parseInt(br.readLine()); + for (int r = 1; r <= run; r++) { + Scanner scan = new Scanner(br.readLine()); + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int[] results = new int[N]; + for (int i = 0; i < N; i++) { + results[i] = scan.nextInt(); + } + System.out.print(String.format(outputTemplate, r, solve(N, S, p, results))); + } + } + + private static int solve(int N, int S, int p, int[] results) { + int count = 0; + + for (int i = 0; i < results.length; i++) { + int r = results[i]; + int threshold = p*3-2; + if (r >= threshold) { + count++; + } else if (S > 0 && r >= threshold - 2 && r >= 2) { + count++; S--; + } + } + + return count; + } +} + " +A22116,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class Read { + int noOfTestCases; + + +int []N; +int []S; +int []p; +int [][]all; + public void test() throws FileNotFoundException{ + File file = new File(""out""); + File file2 = new File(""out2""); + Scanner scanner = new Scanner(file); + Scanner scanner2 = new Scanner(file2); + while(scanner.hasNext()){ + String l1 = scanner.nextLine(); + String l2 = scanner2.nextLine(); + if(!l2.equals(l1)){ + System.out.println(l1); + System.out.println(l2); + System.out.println(""wrong""); + } + } + } + + public void Read(String name) { + File file = new File(name); + + try { + + Scanner scanner = new Scanner(file); + String line = scanner.nextLine(); + noOfTestCases = Integer.parseInt(line); + N = new int[noOfTestCases]; + S = new int[noOfTestCases]; + p = new int[noOfTestCases]; + all = new int[noOfTestCases][]; + int i=0; + while(i ggl = new ArrayList<>(n); + List ggl_sprd = new ArrayList<>(n); + for (int i = 0; i < n; i++) { + int newP = Integer.parseInt(strtok.nextToken()); + if (surprised(newP) && (highP(newP) <= 10)) { + ggl_sprd.add(newP); + } else { + ggl.add(newP); + } + } + Collections.sort(ggl_sprd); + int maxG = 0; + for (int i = 0; i < ggl.size(); i++) { + if (highP(ggl.get(i)) >= p) { + maxG++; + } + } + int sCount = s; + int indx = ggl_sprd.size(); + for (int i = 0; i < ggl_sprd.size(); i++) { + if (sCount == 0) { + indx = i; + break; + } + if (highP(ggl_sprd.get(i)) >= p) { + maxG++; + sCount--; + } + } + if (sCount == 0) { + for (int i = indx; i < ggl_sprd.size(); i++) { + if (highP_woS(ggl_sprd.get(i)) >= p) { + maxG++; + } + } + } + out.println(""Case #"" + (z+1) + "": "" + maxG); + } + sc.close(); + out.close(); + } + + static boolean surprised(int total) { + if (total % 3 == 2 || total % 3 == 0) { + return true; + } + return false; + } + + static int highP(int total) { + if (total == 0) { + return 0; + } + int highestP = 0; + if (total % 3 == 0) { + highestP = (int) (total / 3) + 1; + } else { + highestP = (int) (total / 3) + (total % 3); + } + if (highestP > 10) { + highestP = 10; + } + return highestP; + } + + static int highP_woS(int total) { + int highestP = (int) (total / 3); + if (total % 3 != 0) { + highestP++; + } + return highestP; + } +} +" +A22701," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Formatter; +import java.util.Locale; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author edemairy + */ +public class Main { + + private final static Logger logger = Logger.getLogger(Main.class.getName()); + private static int nbTC; + private static StringBuilder result = new StringBuilder(); + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + logger.setLevel(Level.OFF); +// Scanner scanner = new Scanner(System.in); + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + nbTC = readInt(reader); +// scanner.nextLine(); + for (int tc = 1; tc <= nbTC; ++tc) { + result.append(""Case #"" + tc + "": ""); + result.append(oneTestCase(reader)); + result.append('\n'); + } + System.out.print(result); + } + private static int N; + private static int S; + private static int P; + private static int T[] = new int[101]; + + private static StringBuilder oneTestCase(BufferedReader reader) throws IOException { + N = readInt(reader); + S = readInt(reader); + P = readInt(reader); + for (int i = 0; i < N; ++i) { + T[i] = readInt(reader); + } + Formatter formatter = new Formatter(); + StringBuilder result = new StringBuilder(); + for (int i = 0; i < 102; ++i) { + Arrays.fill(v[i], -2); + } + result.append(val(S, 0)); +// for (int i = 0; i < 5; ++i) { +// formatter.format(""%3d"", n[i]); +// } +// result.append(formatter.out()); + return result; + } + public static int[][] v = new int[102][102]; + + public static int val(int s, int pos) { + if (v[s][pos] != -2) { + return v[s][pos]; + } + + int result; + if (pos >= N) { + if (s == 0) { + result = 0; + } else { + result = -1; + } + } else { + int surprising = -1; + if (s > 0) { + surprising = valSurprising(T[pos], P); + int rem = val(s - 1, pos + 1); + if ((surprising == -1) || (rem == -1)) { + surprising = -1; + } else { + surprising += rem; + } + } + int remNotSurprising = val(s, pos + 1); + int notSurprising = valNotSurprising(T[pos], P); + if ((notSurprising == -1) || (remNotSurprising == -1)) { + notSurprising = -1; + } else { + notSurprising += remNotSurprising; + } + if ((surprising == -1) && (notSurprising == -1)) { + result = -1; + } else if (surprising == -1) { + result = notSurprising; + } else if (notSurprising == -1) { + result = surprising; + } else { + result = Math.max(surprising, notSurprising); + } + } + v[s][pos] = result; + return result; + } + + private static int readInt(BufferedReader reader) throws IOException { + int result = 0; + boolean positive = true; + char currentChar = (char) reader.read(); + + while ((currentChar == ' ') || (currentChar == '\n')) { + currentChar = (char) reader.read(); + } + if (currentChar == (char) -1) { + throw new IOException(""end of stream""); + } + if (currentChar == '-') { + positive = false; + currentChar = (char) reader.read(); + } + while ((currentChar >= '0') && (currentChar <= '9')) { + result = result * 10 + currentChar - '0'; + currentChar = (char) reader.read(); + } + if (positive) { + return result; + } else { + return -result; + } + } + + private static char readChar(BufferedReader reader) throws IOException { + return (char) reader.read(); + } + + public static int valNotSurprising(int t, int p) { + if ((t < 0) || (t > 30)) { + return -1; + } + int m = t / 3; + // searching a and b such as t = a*m+ b*(m+1) + + int b = t - (3*m); + int a = 3 - b; + int result = 0; + if (m >= p) { + result = 1; + } + if ((b!=0) && (m + 1 >= p)) { + result = 1; + } + return result; + } + + public static int valSurprising(int t, int p) { + if ((t < 2) || (t > 28)) { + return -1; + } + int result = 0; + foralpha: + for (int alpha = 0; alpha < 3; ++alpha) { + + int remn = (t - 2 - alpha) % 3; + if (remn != 0) { + continue foralpha; + } + int n = (t - 2 - alpha) / 3; + int resultLoop = 0; + if (n >= p) { + resultLoop = 1; + } + if ((n + 2) >= p) { + resultLoop = 1; + } + if ((n + alpha) >= p) { + resultLoop = 1; + } + result = Math.max(result, resultLoop); + } + return result; + } +} +" +A22874,"package com.google.codejam.googlers; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; + +/** + * + * Class to generate Test Report. + * @author Sushant Deshpande + */ +public class OutputRecorder { + + /** + * Method for generating Test Report. + * @param testCases List list of test cases for report is to be generated. + * @param outputFile String output file for writing TestReport. + */ + public static void generateTestReport(final List testCases, final String outputFile) { + BufferedWriter writer = null; + try { + writer = new BufferedWriter(new PrintWriter(outputFile)); + for(TestCase testCase : testCases) { + writer.write(testCase.printTestResult()); + writer.flush(); + } + writer.flush(); + } catch(IOException ie) { + System.out.println(""Some error occured while generating test report "" + ie.getMessage()); + System.out.println(""Printing result to standard output""); + for(TestCase testCase : testCases) { + System.out.println(testCase.printTestResult()); + } + } finally { + if(writer != null) { + try { + writer.close(); + } catch(IOException ie) { + System.out.println(""Some error occured while closing output stream""); + } + } + } + } + +}" +A22459,"import java.io.IOException; +import java.lang.reflect.Array; +import java.util.*; + +public class MBHappy extends JamProblem { + + + Map baseMap; + Map minMap = new HashMap<>(); + int ile = 0; + + void prepare() { + + SetUtil.cycleSubsets(bases.size(), new SetUtil.SubsetCallBack() { + @Override + public void run(long subset, int size) { + clearCache(); + System.out.println(minMap.size()); + if (size == 0) { + return; + } + List list = SetUtil.getList(subset, bases.size()); + List bas = ArrayUtil.fromIndexList(list, bases); + long forList = SetUtil.getForList(baseMap, bas); + int max = 2; + for (int j = 0; j < bases.size(); j++) { + long without = subset ^ SetUtil.getOne(j); + Integer withMin = minMap.get(without); + if (withMin != null) { + max = Math.max(max, withMin); + } + } + int num = max; + while (true) { + int tested = 0; + for (Integer base : bas) { + System.out.println("""" + ca + ""\t"" + base + ""\t"" + num); + if (!isHappy(num, base)) { + break; + } + tested++; + } + if (tested == bas.size()) { + ca++; + minMap.put(subset, num); + return; + } + if (cache.size() > 100000) { + clearCache(); + } + num++; + } + } + + }); + } + + private void clearCache() { + cache.clear(); + for (Integer base : bases) { + cache.put(new MBAddr(1, base), Happy.HAPPY); + } + } + + public MBHappy() { + for (int i = 2; i <= 10; i++) { + bases.add(i); + } + baseMap = ArrayUtil.listToMap(bases); + } + + Map cache = new HashMap<>(); + + List bases = new ArrayList<>(); + + public static void main(String[] args) throws IOException { + MBHappy h = new MBHappy(); + h.prepare(); + h.go(); + } + + boolean isHappy(int num, int base) { + MBAddr addr1 = new MBAddr(num, base); + Happy isHappy = cache.get(addr1); + if (isHappy != null) { + if (isHappy == Happy.HAPPY) { + return true; + } + + if (isHappy == Happy.UNHAPPY) { + return false; + } + } + + List integers = MathUtil.convertToBase(num, base); + int sum = MathUtil.sumSquaredList(integers); + + isHappy = cache.get(new MBAddr(sum, base)); + if (isHappy != null) { + if (isHappy == Happy.HAPPY) { + cache.put(addr1, Happy.HAPPY); + return true; + } + + if (isHappy == Happy.UNHAPPY) { + cache.put(addr1, Happy.UNHAPPY); + return false; + } + + if (isHappy == Happy.UNKNOWN) { + cache.put(addr1, Happy.UNHAPPY); + return false; + } + } + cache.put(addr1, Happy.UNKNOWN); + boolean happy = isHappy(sum, base); + if (happy) { + cache.put(addr1, Happy.HAPPY); + return true; + } else { + cache.put(addr1, Happy.UNHAPPY); + return false; + } + + } + + int ca = 0; + + @Override + String solveCase(JamCase jamCase) { + int num = 2; + MBHCase cas = (MBHCase) jamCase; + + return """" + minMap.get(SetUtil.getForList(baseMap, cas.bases)); + } + + @Override + JamCase parseCase(List file, int line) { + MBHCase cas = new MBHCase(); + cas.lineCount = 1; + cas.bases = JamUtil.parseIntList(file.get(line)); + return cas; + } +} + +class MBHCase extends JamCase { + List bases; +} + +class MBAddr { + int number; + int base; + + MBAddr(int number, int base) { + this.number = number; + this.base = base; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MBAddr mbAddr = (MBAddr) o; + + if (base != mbAddr.base) return false; + if (number != mbAddr.number) return false; + + return true; + } + + @Override + public int hashCode() { + int result = number; + result = 31 * result + base; + return result; + } +} + +class MBNum { + int number; + int base; + boolean isHappy; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MBNum mbNum = (MBNum) o; + + if (base != mbNum.base) return false; + if (isHappy != mbNum.isHappy) return false; + if (number != mbNum.number) return false; + + return true; + } + + @Override + public int hashCode() { + int result = number; + result = 31 * result + base; + result = 31 * result + (isHappy ? 1 : 0); + return result; + } +} + +enum Happy { + HAPPY, UNHAPPY, UNKNOWN; +} + + +" +A20505,"import java.io.*; +import java.math.BigInteger; +import java.util.InputMismatchException; + +/** + * @author Malvino Juwono (malvino.juwono@gmail.com) + * + */ +public class ProblemB implements Runnable { + private InputReader in; + private PrintWriter out; + + public static void main(String[] args) { + new Thread(new ProblemB()).start(); + } + + public ProblemB() { + try { + System.setIn(new FileInputStream(""input.txt"")); + System.setOut(new PrintStream(new FileOutputStream(""output.txt""))); + } catch (FileNotFoundException e) { + e.printStackTrace(System.err); + } + in = new InputReader(System.in); + out = new PrintWriter(System.out); + } + + public void run() { + + int numTests = in.readInt(); + for (int testNumber = 0; testNumber < numTests; testNumber++) { + out.print(String.format(""Case #%d: "", (testNumber + 1))); + + int numPeople = in.readInt(); + int numSuprise = in.readInt(); + int minScore = in.readInt(); + int[] scores = new int[numPeople]; + + for (int i = 0; i < numPeople; ++i) { + scores[i] = in.readInt(); + } + + int numTopScorers = getNumTopScorers(numPeople, numSuprise, minScore, scores); + + System.err.println(String.valueOf(numTopScorers)); + out.write(String.valueOf(numTopScorers) + ""\n""); + } + out.close(); + } + + private int getNumTopScorers(int numPeople, int numSurprise, int minScore, int[] scores) { + int numTopScorers = 0; + + + for (int score : scores) { + int base = score / 3; + + int avgScoreMod = score % 3; + if (avgScoreMod == 0) { + // regular case: + if (base >= minScore) { + numTopScorers++; + + // check for numSurprise case: + } else if (numSurprise > 0 && base > 0 && base + 1 >= minScore) { + numTopScorers++; + numSurprise--; + } + } else if (avgScoreMod == 1) { + // regular case: + if (base >= minScore || base + 1 >= minScore) { + numTopScorers++; + + // check for numSurprise case: + } else if (numSurprise > 0 && base + 1 >= minScore) { + numTopScorers++; + numSurprise--; + } + } else if (avgScoreMod == 2) { + // regular case: + if (base + 1 >= minScore || base >= minScore) { + numTopScorers++; + + // check for numSurprise case: + } else if (numSurprise > 0 && base + 2 >= minScore) { + numTopScorers++; + numSurprise--; + } + } + } + + return numTopScorers; + } + + + private static class InputReader { + private InputStream stream; + private byte[] buf = new byte[1000]; + private int curChar, numChars; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + private int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public long readLong() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + long res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + private boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + private String readLine0() { + StringBuffer buf = new StringBuffer(); + int c = read(); + while (c != '\n' && c != -1) { + buf.appendCodePoint(c); + c = read(); + } + return buf.toString(); + } + + public String readLine() { + String s = readLine0(); + while (s.trim().length() == 0) + s = readLine0(); + return s; + } + + public String readLine(boolean ignoreEmptyLines) { + if (ignoreEmptyLines) + return readLine(); + else + return readLine0(); + } + + public BigInteger readBigInteger() { + try { + return new BigInteger(readString()); + } catch (NumberFormatException e) { + throw new InputMismatchException(); + } + } + + public char readCharacter() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + return (char) c; + } + + public double readDouble() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + double res = 0; + while (!isSpaceChar(c) && c != '.') { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } + if (c == '.') { + c = read(); + double m = 1; + while (!isSpaceChar(c)) { + if (c < '0' || c > '9') + throw new InputMismatchException(); + m /= 10; + res += (c - '0') * m; + c = read(); + } + } + return res * sgn; + } + } +} +" +A22308,"import java.io.*; + +public class DancingGooglers { + private static final String IN_FILE = ""B-large.in""; + private static final String OUT_FILE = ""B-large_output.txt""; + + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new FileReader(IN_FILE)); + BufferedWriter bw = new BufferedWriter(new FileWriter(OUT_FILE)); + String line = br.readLine(); + final int T_CASES = Integer.parseInt(line); + + for (int t = 1; t <= T_CASES; t++) { + line = br.readLine(); + String parts[] = line.split("" ""); + final int N = Integer.parseInt(parts[0]); // number of Googlers + final int S = Integer.parseInt(parts[1]); // number of surprising triplets of scores + final int P = Integer.parseInt(parts[2]); // best result of at least p + + int[] totalPoints = new int[N]; + for (int i = 0; i < N; i++) { + totalPoints[i] = Integer.parseInt(parts[i + 3]); + } + + int result = processCase(N, S, P, totalPoints); + bw.write(""Case #"" + t + "": "" + result); + bw.newLine(); + } + + bw.close(); + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static int processCase(int n, int s, int p, int[] totalPoints) { + int result = 0; + + for (int t : totalPoints) { + switch (p) { + case 0: + result++; + break; + case 1: + if (t >= 1) { + result++; + } + break; + default: + // p is between 2 to 10 + if (t >= 3 * p - 2) { + result++; + } else if (s > 0 && t >= 3 * p - 4) { + s--; + result++; + } + break; + } + } + + return result; + } + +} +" +A21839,"import java.util.*; + + +public class CodeJamB { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int t = scan.nextInt(); + for (int i = 1; i <= t; i++) { + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int a = 0; + int b = 0; + for (int j = 0; j < n; j++) { + int x = scan.nextInt(); + if ((x + 2) / 3 >= p) + a++; + else if ((x % 3 == 0 && x >= 3 || x % 3 != 0) && (x + 4) / 3 >= p) + b++; + } + System.out.printf(""Case #%d: %d%n"", i, a + Math.min(b, s)); + } + } + +}" +A20240,"import java.io.*; + +/** + * User: Andrii Baranov + * Date: 14.04.12 + * Time: 12:59 + */ +public class DancingGooglers { + + public static void main(String args[]) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + + int testCases = Integer.parseInt(br.readLine()); + int[] maximumGooglers = new int[testCases]; + + String paramString; + int surprising, maxRes, googlersNumber; + for (int i = 0; i < testCases; ++i) { + paramString = br.readLine(); + String params[] = paramString.split("" ""); + + googlersNumber = Integer.parseInt(params[0]); + surprising = Integer.parseInt(params[1]); + maxRes = Integer.parseInt(params[2]); + + int[] sumOfResults = new int[googlersNumber]; + for (int j = 0; j < googlersNumber; ++j) { + sumOfResults[j] = Integer.parseInt(params[3 + j]); + } + + maximumGooglers[i] = numOfBestResults(googlersNumber, surprising, maxRes, sumOfResults); + } + br.close(); + + BufferedWriter bw = new BufferedWriter(new FileWriter(""B-large-out.txt"")); + for (int i = 0; i < maximumGooglers.length; i++) { + bw.write(""Case #"" + (i + 1) + "": "" + maximumGooglers[i]); + if (i + 1 < maximumGooglers.length) { + bw.write(""\n""); + } + } + bw.close(); + + } + + private static int numOfBestResults(int googlersNumber, int surprising, int maxRes, int[] sumOfResults) { + int res = 0; + int transformSurprising = 0; + + if(maxRes == 0){ + return googlersNumber; + } + if(maxRes == 1){ + for(int i =0; i < googlersNumber; i++){ + if (sumOfResults[i]> 0){ + res++; + } + } + return res; + } + + + + for (int i = 0; i < googlersNumber; ++i) { + + if ((sumOfResults[i] / 3 + 1) >= maxRes) { + if ((sumOfResults[i] % 3 == 0) && ((sumOfResults[i] / 3 + 1) == maxRes)) { + transformSurprising++; + res++; + } else { + res++; + } + + } else if ((sumOfResults[i] % 3 == 2) && ((sumOfResults[i] / 3 + 2) == maxRes)) { + transformSurprising++; + res++; + } + } + + if (transformSurprising > surprising) { + return res - (transformSurprising - surprising); + } + return res; + } +} +" +A21841,"package com.sam.googlecodejam.speakingtoungue; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import com.sam.googlecodejam.helper.InputReader; + +/** + * This class generates the mapping based on the samples that have been provided. + * @author Saifuddin Merchant + * + */ +public class TranslatorMapping { + + public Map iAvalableLines = new HashMap<>(); + public Map iLetterMapping = new TreeMap<>(); + + public TranslatorMapping() { + iAvalableLines.put(""ejp mysljylc kd kxveddknmc re jsicpdrysi"", ""our language is impossible to understand""); + iAvalableLines.put(""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"", ""there are twenty six factorial possibilities""); + iAvalableLines.put(""de kr kd eoya kw aej tysr re ujdr lkgc jv"", ""so it is okay if you want to just give up""); + } + + public void mapLetters() + { + for(Entry lineEntry: iAvalableLines.entrySet()) + { + String keyLine = lineEntry.getKey(); + String keyValue = lineEntry.getValue(); + int index=0; + for(Character keyChar:keyLine.toCharArray()) + { + iLetterMapping.put(keyChar, keyValue.charAt(index++)); + } + } + iLetterMapping.put('z', 'q');//add the missing mappings + iLetterMapping.put('q', 'z');//add the missing mappings + //System.out.println(iLetterMapping.size()); + //System.out.println(iLetterMapping); + } + + public void translate(String pInput) + { + for(Character translateChar:pInput.toCharArray()) + { + System.out.print(iLetterMapping.get(translateChar)); + } + } + + public static void main(String[] args) { + TranslatorMapping mapping = new TranslatorMapping(); + mapping.mapLetters(); + + InputReader reader = new InputReader(""c://input.in""); + reader.readNextLine(); //read the line number off - we don't need it + + String lineRead = null; + int i=1; + while((lineRead=reader.readNextLine())!=null ) + { + System.out.print(""Case #""+i+"": ""); i++; + mapping.translate(lineRead); + System.out.println(); + } + } +} +" +A20560,"import java.util.Scanner; +import java.util.Arrays; + +public class Main { + private final static int N_MAX = 1024; + + public static void main(String[] args) { + int T,N,S,P; + + Scanner stdin = new Scanner(System.in); + T = stdin.nextInt(); + + for(int i = 1;i <= T;++i) { + N = stdin.nextInt(); + S = stdin.nextInt(); + P = stdin.nextInt(); + + int[] score = new int[N]; + for(int j = 0;j < N;++j) + score[j] = stdin.nextInt(); + Arrays.sort(score); + + int res = 0; + + for(int j = N - 1;j >= 0; --j) + if(score[j] >= P * 3 - 2) + ++res; + else if(P != 1 && score[j] >= P * 3 - 4 && S != 0) { + ++res; + --S; + } + + System.out.println(""Case #"" + i + "": "" + res); + } + } +} +" +A21496,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.HashMap; + + +public class B { + +public static int b(String str){ + + int retVal = 0; + + String arr[] = str.split("" ""); + + int N = Integer.parseInt(arr[0]); + int S = Integer.parseInt(arr[1]); + int P = Integer.parseInt(arr[2]); + + if(P == 0){ + return N; + } + + int sum = 3*P - 2; + + for(int i = 3; i < arr.length ; i++){ + + int Ti = Integer.parseInt(arr[i]); + if(Ti >= sum){ + retVal++; + } + else if(S >0 && Ti > 0 && Ti >= sum - 2){ + retVal++; + S--; + } + } + + + return retVal; +} + +public static void main(String args[]){ + + File file = new File(""B-large.in""); + + int T = 0; + try{ + FileInputStream fstream = new FileInputStream(file); + + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + if ((strLine = br.readLine()) != null) { + T = Integer.parseInt(strLine); + } + int currentCase = 1; + while(T > 0 && currentCase <= T){ + + String str= br.readLine(); + + System.out.println(""Case #""+currentCase+"": "" + b(str)); + currentCase++; + } + + in.close(); + }catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + + + + } + +} +" +A20424,"import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.*; + +public class Dance { + private static int raw_num; + private static int pot_num; + public static void main(String[] args) throws FileNotFoundException{ + Scanner in = new Scanner(System.in); + PrintWriter out = new PrintWriter(""dance_out.txt""); + int t = in.nextInt(); + for (int i = 0; i < t; i++){ + raw_num = pot_num = 0; + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + for (int j = 0; j < n; j++){ + process(in.nextInt(), p); + } + if (pot_num < s) + raw_num += pot_num; + else + raw_num += s; + out.printf(""Case #%d: %d%n"", i+1, raw_num); + } + out.close(); + } + private static void process(int score, int p){ + switch (score % 3) { + case 0: + if (score / 3 >= p) + raw_num++; + else { + if (score / 3 + 1 >= p && score / 3 - 1 > 0) + pot_num++; + } + break; + case 1: + if (score / 3 + 1 >= p) + raw_num++; + break; + case 2: + if (score / 3 + 1 >= p) + raw_num++; + else { + if (score / 3 + 2 >= p) + pot_num++; + } + default: + break; + } + } +} +" +A21220,"package qualification; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class b { + + public static void main(String[] args){ + if(args.length<1){ + System.out.println(""Usage: ""); + } + String fn = args[0]; + String fnOut = toFnOut(fn); + try{ + System.out.println(""dir : ""+System.getProperty(""user.dir"")); + BufferedReader br = new BufferedReader(new FileReader(fn)); + BufferedWriter bw = new BufferedWriter(new FileWriter(fnOut)); + int NCase = Integer.valueOf(br.readLine().trim()); + long stime = System.currentTimeMillis(); + for(int icase=0;icase=(3*p)){ + result++; + }else if( q>=p-2){ + if(q==p-1 && r!=0){ + result++; + } + else if(s>0 && canBeSurprising(a[i], p)){ + s--; + result++; + } + } + } + return result; + } + + static boolean canBeSurprising(int n,int s){ + boolean result = false; + int r = n%3; + int q = (n-r)/3; + if(q==s-2){ + if(r==2) return true; + } + if(q==s-1){ + if(r==0 && s>=2)return true; + } + + return result; + } + + static int[] toIntArray(String line){ + String[] p = line.trim().split(""\\s+""); + int[] out = new int[p.length]; + for(int i=0;i= p) { + ans++; + } else if (SCORE <= 1) { + //nothing + } else if (SCORE % 3 != 1 && MAX_NORM+1 >= p && S > 0) { + ans++; + S--; + } + } + + System.out.printf(""Case #%d: %s\n"",ii,ans); + } + } +}" +A23039,"import java.util.*; +import java.io.*; + +public class DancingWithGooglers +{ + public static void main(String args[]) throws IOException + { + int case_no; + String result = """"; + File inputFile = new File("".in""); + FileInputStream fin = new FileInputStream(inputFile); + Scanner in = new Scanner(fin); + + PrintWriter out = new PrintWriter(new FileWriter("".out"", true)); + + case_no = in.nextInt(); + + for( int i = 0; i < case_no; i++ ) + { + int num_googlers, t_surprise, point, max_number_overp = 0, number_overp_temp = 0; + PriorityQueue _pq = new PriorityQueue(); + result += ""Case #""+ (i+1) + "": ""; + num_googlers = in.nextInt(); + t_surprise = in.nextInt(); + point = in.nextInt(); + + for( int j = 0; j < num_googlers; j++ ) + { + _pq.add(new Integer(in.nextInt())); + } + + + + while( _pq.size()!= 0 ) + { + int temp = _pq.poll().intValue(); + + if( (temp <= 3*(point-1))&&(temp>=(3*(point-1)-1))) + { + if( (number_overp_temp < t_surprise)&&(temp > 0) ) + { + number_overp_temp++; + max_number_overp++; + } + } + else if (temp > 3*(point-1)) + { + max_number_overp++; + + } + } + + result += """" + max_number_overp; + out.println(result); + result = """"; + } + in.close(); + out.close(); + + } +} +" +A22586," +package javaapplication6; + +import java.io.*; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class JavaApplication6 { + + public static void main(String[] args) { + try + { + BufferedReader in = new BufferedReader(new FileReader(""e:\\B-small-attempt0.in"")); + FileWriter out=new FileWriter(""e:\\B-small-attempt0.txt""); + String ts=in.readLine(); + int T=Integer.parseInt(ts); + int counter=0; + String output=""""; + + for(int cases=1;cases<=T;cases++) + { + StringTokenizer st=new StringTokenizer(in.readLine()); + int N=Integer.parseInt(st.nextToken()); + int surprise=Integer.parseInt(st.nextToken()); + int passmarks=Integer.parseInt(st.nextToken()); + System.out.println(""XXX""+N+"":""+surprise+"":""+passmarks); + counter=0; + output+=""Case #""+cases+"": ""; + for(int i=0;i=passmarks) + { + counter++; + } + else if(passmarks-tolldiv==1 && rem>0) + { + counter++; + } + else if(passmarks-tolldiv==1 && surprise>0 && tolldiv>0) + { + counter++; + surprise--; + } + else if(passmarks-tolldiv==2 && rem==2 && surprise>0) + { + counter++; + surprise--; + } + } + output=output+counter; + if(cases!=T) + output=output+""\n""; + } + out.write(output); + out.close(); + + }catch(Exception e) + { + System.out.println(e); + } + } +} +" +A21821,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class B { + + + public static void main(String[] args) throws IOException { +// Scanner in = new Scanner(new File(""in/B/test.in"")); +// Scanner in = new Scanner(new File(""in/B/small.in"")); + Scanner in = new Scanner(new File(""in/B/big.in"")); +// BufferedWriter bw = new BufferedWriter(new FileWriter( +// ""out/B/test.out"")); +// BufferedWriter bw = new BufferedWriter(new FileWriter( +// ""out/B/small.out"")); + BufferedWriter bw = new BufferedWriter(new FileWriter( + ""out/B/big.out"")); + int cases = in.nextInt(); + for(int c = 1; c <= cases; c++){ + int competitors = in.nextInt(); + int surprises = in.nextInt(); + int minNote = in.nextInt(); + int winners = 0; + for(int i = 0; i < competitors; i++){ + int max = 0, normal = 0; + int note = in.nextInt(); + System.err.println(note); + if(note == 0){ + max = 0; + normal = 0; + }else if(note == 1){ + max = 1; + normal = 1; + }else if(note > 27){ + max = 10; + normal = 10; + }else{ + int mod = note%3; + max = note/3 + (mod==0?1:mod); + normal = max - (mod!=1?1:0); + } + if(normal >= minNote){ + winners++; + continue; + } + if(max == minNote && surprises > 0){ + surprises--; + winners++; + continue; + } + } + bw.write(""Case #"" + (c) + "": ""+winners); + System.err.println(""Case #"" + (c) + "": ""+winners); + bw.newLine(); + } + in.close(); + bw.flush(); + bw.close(); + } +} +" +A23083,"package codejam2012.qr.dancing; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author fedez + */ +public class DancerSolver +{ + + private static Logger logger = Logger.getLogger(DancerSolver.class.getName()); + + public static int solve(int googlers, int[] scores, int suprises, int scoreTopass) + { + AtomicInteger surprisesLeft; + int numberOfPasses = 0; + int score, i, possible; + + surprisesLeft = new AtomicInteger(suprises); + for (i = 0; i < googlers; i++) + { + score = scores[i]; + possible = isItPossible(score, surprisesLeft, scoreTopass); + logger.log(Level.INFO, ""Score:{0}, surprisesLeft:{1}, scoreTopass:{2}, result:{3}"", new Object[] + { + score, surprisesLeft, scoreTopass, possible + }); + + numberOfPasses += possible; + } + + return numberOfPasses; + } + + private static int isItPossible(double score, AtomicInteger surprisesLeft, int scoreTopass) + { + double remainder, leftValues, lowestValue; + + if (scoreTopass == 0) + { + return 1; + } + + remainder = score - scoreTopass; + if (remainder < 0) + { + return 0; + } + + leftValues = remainder / 2d; + if (remainder % 2 == 0) + { + lowestValue = leftValues; + } + else + { + lowestValue = Math.floor(leftValues); + } + if (scoreTopass - lowestValue <= 1) + { + return 1; + } + else if (scoreTopass - lowestValue <= 2 && surprisesLeft.get() > 0) + { + surprisesLeft.decrementAndGet(); + return 1; + } + else + { + return 0; + } + } +} +" +A20652,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.math.BigDecimal; +import java.sql.Savepoint; +import java.util.Arrays; +import java.util.Vector; + + +public class Scoring { + + static Vector questions = null; //new Vector(); + static int count = -1; + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + questions = readFile(""input.txt""); + String result = process(); + + savetoFile(""out.txt"", result); + } + + + private static String process() { + // TODO Auto-generated method stub + String ret = """"; + for (int i=0; i=p){ + answ ++; + System.out.print(mod+""Y""+score+""fp ""); + } + else if (mod==0){ + if (s>0 && floor+1>=p && floor-1>0) + // if ( ) + { + answ++; + + s--; + System.out.print(mod+""Y""+( floor+1 )+""o ""); + } + } + else if (mod==1 && floor+1>=p){ + answ++; + System.out.print(mod+""Y""+score+""m1 ""); + }else if (mod==2){ + if (1+floor>=p) + { + answ++; + + System.out.print(mod+""Y""+score+"" ""); + } + else if (s!=0 && floor+mod>=p) + { + answ++; + s--; + System.out.print(mod+""Y""+score+""s ""); + } + //System.out.print(mod+""Y""+score+""s ""); + } + else System.out.print(mod+""x""+score+"" ""); + + + + + /* + Input + + Output + + 4 + 3 1 5 15 13 11 + 3 0 8 23 22 21 + 2 1 1 8 0 + 6 2 8 29 20 8 18 18 21 + Case #1: 3 + Case #2: 2 + Case #3: 1 + Case #4: 3 +*/ + } + System.out.println(answ); + ret += ""Case #""+(i+1)+"": ""+answ+""\n""; + } + + return ret; + } + + + static public Vector readFile(String filename) + { + Vector retval = new Vector(); + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(filename); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + // Print the content on the console + System.out.print(strLine+""\n""); + if (count==-1) + count = Integer.parseInt(strLine.trim()); + else + retval.add(strLine); + } + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + return retval; + } + + public static void savetoFile(String filename, String s){ + try{ + // Create file + FileWriter fstream = new FileWriter(filename); + BufferedWriter out = new BufferedWriter(fstream); + + out.write(s); + + //Close the output stream + out.close(); + } catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A20559,"package googlers; + +import java.io.File; + +import io.Reader; + +public class DanceParty { + public static void main(String[] args){ + new DanceParty(); + } + + + + public DanceParty(){ + String[] lines = Reader.getInput(new File(""B-large.in"")); + //String[] lines = Reader.getInput(new File(""danceInput.in"")); + + + for (int i = 0; i < lines.length; i++){ + String line = lines[i]; + String[] peicesString = line.split("" ""); + int[] peices = new int[peicesString.length]; + for(int j = 0; j=N){ + numPossible++; + } + else if (numPossibleSurprises=N-2 && sc>=minBestResult){ + numPossibleSurprises++; + } + } + + numPossible+=numPossibleSurprises; + if (numPossible>numGooglers)numPossible=numGooglers; + if (numPossible<0)numPossible=0; + + System.out.println(""Case #""+(i+1)+"": ""+numPossible); + } + + + } +} +" +A22444,"package com.monochromeiguana.codejam; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Arrays; +import java.util.List; + +/** + * Hello world! + * + */ +public class Main { + + static BufferedReader in; + static BufferedWriter out; + static String inputFile = ""in.txt""; + static String outputFile = ""outfile.txt""; + + private static class Parser { + + public final int numDancers; + public final int numSurprises; + public final int minScore; + public final int index; + public final int answer; + + public Parser(String line, int ix) { + index = ix; + List parts = Lists.newArrayList(Arrays.asList(line.split("" ""))); + numDancers = Integer.parseInt(parts.remove(0)); + numSurprises = Integer.parseInt(parts.remove(0)); + minScore = Integer.parseInt(parts.remove(0)); + + Iterable dancers = Iterables.transform(parts, new Function() { + + public Dancer apply(String f) { + return new Dancer(Integer.parseInt(f), minScore); + } + }); + + int winners = Iterables.size(Iterables.filter(dancers, new Predicate() { + + public boolean apply(Dancer t) { + return t.win(); + } + })); + + int surprises = Math.min(Iterables.size(Iterables.filter(dancers, new Predicate() { + + public boolean apply(Dancer t) { + return t.possibleSurprise(); + } + })), numSurprises); + + answer = winners + surprises; + } + + public String output() { + return ""Case #"" + index + "": "" + answer; + } + } + + private static class Dancer { + + public final int score; + public final int minScore; + public final int remainder; + public final int average; + + public Dancer(int scr, int min) { + score = scr; + minScore = min; + remainder = scr % 3; + average = scr / 3; + } + + // If remainder = 0, we either have 3 * avg or avg - 1 & avg & avg + 1 (surprising) + // If remainder = 1, we either have avg-1 & 2 * avg+1 (surprising) or 2 * avg & avg + 1 + // If remainder = 2, we either have 2 * avg & avg + 2 (surprising) or avg & 2 * avg + 1 + public boolean win() { + if (remainder == 0) { + return average >= minScore; + } else { + return average >= minScore - 1; + } + } + + public boolean possibleSurprise() { + if (win()) { + return false; + } + if (remainder == 0) { + return average > 0 && average == minScore - 1; + } else if (remainder == 1) { + return false; + } else { + return average == minScore - 2; + } + } + } + + public static void main(String[] args) throws Exception { + + in = new BufferedReader(new FileReader(inputFile)); + out = new BufferedWriter(new FileWriter(outputFile)); + try { + String line = in.readLine(); + int nbCases = Integer.parseInt(line); + int index = 0; + while ((line = in.readLine()) != null) { + index++; + Parser p = new Parser(line, index); + out.write(p.output()); + out.newLine(); + } + } finally { + in.close(); + } + out.flush(); + } +} +" +A21792,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dance; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; + +/** + * + * @author ALEX + */ +public class Dance { + + public ArrayList al; + public Dance() + { + al=new ArrayList(); + } + /** + * @param args the command line arguments + */ + public void readFile() + { + try { + FileReader fin=new FileReader(""B-large.in""); + BufferedReader in = new BufferedReader(fin); + FileWriter fout=new FileWriter(""result.txt""); + BufferedWriter out=new BufferedWriter(fout); + int nrt; + nrt=Integer.valueOf(in.readLine()); + String [] med; + for(int i=1;i<=nrt;i++) + { + String str=in.readLine(); + med=str.split("" ""); + int nrs = Integer.valueOf(med[0]); + int su = Integer.valueOf(med[1]); + int pe = Integer.valueOf(med[2]); + for(int j=1;j<=nrs;j++){ + Scores ob=new Scores(Integer.valueOf(med[j+2])); + al.add(ob); + } + out.write(""Case #""+i+"": ""+workFun(su,pe)); + out.newLine(); + al.clear(); + } + in.close(); + fin.close(); + out.close(); + fout.close(); + } + catch(Exception e){} + } + public int workFun(int sup,int pes) + { + int nr=0; + int sp=0; + for(int i=0;i=pes && sp=pes){ + nr++; + } + } + } + return nr; + } + public static void main(String[] args) { + // TODO code application logic here + Dance d=new Dance(); + d.readFile(); + /*System.out.println(d.isSurprize(23,8,0)); + System.out.println(d.isSurprize(22,8,0)); + System.out.println(d.isSurprize(21,8,0)); + System.out.println(d.nr); + System.out.println(d.b);*/ + } +} +" +A21643,"import java.io.File; +import java.io.FileInputStream; +import java.io.PrintWriter; +import java.util.Random; +import java.util.Scanner; + + +public class DancingWithGooglers { + public static void main(String[] args) { + + + try { + File output = new File(""output.txt""); + + if (output.exists()) { + output.delete(); + } + + PrintWriter pw = new PrintWriter(output); + + Scanner s = new Scanner(new FileInputStream(""input.txt"")); + + int T = s.nextInt(); + s.nextLine(); + + for (int i = 0; i < T; i++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] ts = new int[N]; + + for (int j = 0; j < N; j++) { + ts[j] = s.nextInt(); + } + + DancingWithGooglers solve = new DancingWithGooglers(ts, S, p); + + pw.println(String.format(""Case #%d: %d"", (i+1), solve.compute())); + } + + pw.close(); + + System.out.println(""Done !""); + } catch (Exception ex) { + System.out.println(""ERROR""); + System.out.println(ex.getMessage()); + ex.printStackTrace(); + } + } + + private int[] totals; + private int surprising; + private int max; + + public DancingWithGooglers(int[] totals, int surprising, int max) { + this.totals = totals; + this.surprising = surprising; + this.max = max; + } + + public int compute() { + System.out.println(""Trying...""); + + int found = 0; + int surprisingLeft = surprising; + for (int i = 0; i < totals.length; i++) { + int t = totals[i]; + System.out.println(String.format(""S = %d, p = %d, t = %d"", surprising, max, t)); + boolean foundNormal = findNormal(t); + boolean foundSurprising = findSurprising(t); + + if (foundNormal) found++; + + if (!foundNormal && foundSurprising && surprisingLeft > 0) { + found++; + surprisingLeft--; + } + + System.out.println(String.format(""#%d: %s / %s"", (i+1), foundNormal, foundSurprising)); + } + System.out.println(String.format(""Suprising left : %d"", surprisingLeft)); + System.out.println(""----------------------------""); + return found; + } + + private boolean findNormal(int total) { + boolean result = false; + for (int s1 = 10; s1 >= 0; s1--) { + if (s1 > total) continue; + for (int s2 = s1; s2 >= Math.max(s1-1, 0); s2--) { + if (s1 + s2 > total) continue; + for (int s3 = s2; s3 >= Math.max(s1-1, 0); s3--) { + if (s1 + s2 + s3 != total) continue; + + if (s1 >= max || s2 >= max || s3 >= max) { + System.out.println(String.format(""%d %d %d"", s1, s2, s3)); + result = true; + } + } + } + } + return result; + } + + private boolean findSurprising(int total) { + boolean result = false; + for (int s1 = 10; s1 >= 0; s1--) { + if (s1 > total) continue; + for (int s2 = s1; s2 >= Math.max(s1-2, 0); s2--) { + if (s1 + s2 > total) continue; + for (int s3 = s2; s3 >= Math.max(s1-2, 0); s3--) { + if (s1 + s2 + s3 != total) continue; + + if (s1-s3 != 2) continue; + + if (s1 >= max || s2 >= max || s3 >= max) { + System.out.println(String.format(""%d %d %d (*)"", s1,s2,s3)); + result = true; + } + } + } + } + return result; + } +} +" +A20950,"package org.moriraaca.codejam; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface SolverConfiguration { + OutputDestination outputDestination() default OutputDestination.STDOUT; + + String inputFileName() default ""sample.in""; + + DebugOutputLevel debugOutputLevel() default DebugOutputLevel.SOLUTION; + + Class parser(); +} +" +A22020,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +/** + * + */ + +/** + * @author Pandapotan Christian + * + */ +public class DancingWithGooglers { + /* + * Write string to a file with specified path + */ + public static void writeFile(String filePath, String content){ + try{ + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filePath))); + out.write(content); + out.close(); + } + catch(IOException e){ + e.printStackTrace(); + } + } + + /* + * Return array that contains each lines of the input file, null if the reading process failed + */ + public static ArrayList getLines(String filePath){ + ArrayList lines = null; + + try{ + lines = new ArrayList(); + + String s; + BufferedReader in = new BufferedReader( new FileReader(filePath)); + while ((s = in.readLine()) != null) { + lines.add(s); + } + in.close(); + }catch(IOException e){ + e.printStackTrace(); + } + + return lines; + } + + /** + * Replace value with the real path + */ + public static final String fileIn = ""D:\\CodeJam\\DancingGooglers-large.in""; + + /** + * @param args + */ + public static void main(String[] args) { + + //get input from file + ArrayList lines = getLines(fileIn); + + //process data + if(lines!=null){ + System.out.println(""System Start""); + long systemStart = System.currentTimeMillis(); + + String firstLine = lines.get(0); + int T = Integer.parseInt(firstLine); + + //Main Algorithm + StringBuffer result = new StringBuffer(); + for(int testIdx = 1; testIdx<=T; testIdx++){ + System.out.println(""Test Case Number: ""+testIdx); + long start = System.currentTimeMillis(); + + String param[] = lines.get(testIdx).split("" ""); + int N = Integer.parseInt(param[0]); + int S = Integer.parseInt(param[1]); + int p = Integer.parseInt(param[2]); + int[] t = new int[N]; + for(int i=0; i> possibilities = getPossibilities(); + + //2. traverse through loop + for (int score : t) { + //3. check whether have values >p, + if(containNeededValue(possibilities.get(score), p)){ + //4. if yes check have if need surprising or not. if need, then total++ and S-- + if(needSurprising(possibilities.get(score), p)){ + if(S>0){ + total++; + S--; + } + } + //5. if yes and no need surprising then only total++ + else + total++; + } + } + + return total; + } + + public static ArrayList> getPossibilities(){ + ArrayList> result = new ArrayList>(); + + for(int number = 0; number<=30; number++){ + ArrayList possibilities = new ArrayList(); + for(int first = 0; first<=10; first++) + for(int second = 0; second<=10; second++) + for(int third = 0; third<=10; third++){ + if((first+second+third==number) && !(Math.abs(first-second)>2 || Math.abs(first-third)>2 || Math.abs(second-third)>2)) + possibilities.add(first+"" ""+second+"" ""+third+ (isSurprising(first, second, third)?"" S"":"""") ); + } + result.add(possibilities); + } + + return result; + } + + public static boolean isSurprising(int first, int second, int third){ + return Math.abs(first-second)==2 || Math.abs(first-third)==2 || Math.abs(second-third)==2; + } + + public static boolean containNeededValue(ArrayList list, int p){ + boolean isExist = false; + for (String string : list) { + String[] numbers = string.split("" ""); + isExist = (Integer.parseInt(numbers[0])>=p || Integer.parseInt(numbers[1])>=p || Integer.parseInt(numbers[2])>=p ); + if(isExist) break; + } + return isExist; + } + + public static boolean needSurprising(ArrayList list, int p){ + boolean noNeed = false; + for (String string : list) { + String[] numbers = string.split("" ""); + noNeed = (Integer.parseInt(numbers[0])>=p || Integer.parseInt(numbers[1])>=p || Integer.parseInt(numbers[2])>=p ) && !string.contains(""S""); + if(noNeed) break; + } + return !noNeed; + } +} +" +A23001,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package dance; +import java.io.*; +import java.util.*; +/** + * + * @author karam.yaaqna + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + String line ; + StringTokenizer st ; + try{ + int num = 0; + int s = 0; + int p = 0; + int minLimit = 0; + int maxLimit = 0; + int score = 0; + int out =0 ; + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter writer = new PrintWriter(new FileOutputStream(""output.txt"")); + int testCase = Integer.parseInt(reader.readLine()); + line = reader.readLine(); + st = new StringTokenizer(line); + for(int tc = 1;tc<=testCase;tc++){ + st = new StringTokenizer(line); + num = Integer.parseInt(st.nextToken()); + s = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + minLimit = p * 3 - 4; + maxLimit = p*3 - 2; + // System.out.println(""im here""+num); + while(st.hasMoreTokens()){ + score = Integer.parseInt(st.nextToken()); + if(score>=maxLimit){ + out++; + }else + {if (score>=minLimit ) + if(p>1 && s>0){ + out++; + s--; + } + } + + } + // System.out.println(out); + writer.println(""Case #""+tc+"": ""+out); + line = reader.readLine(); + out = 0; + + } + writer.close(); + }catch(Exception e){ + } + + } + +} +" +A22677,"package ru.guredd.codejam; + +import java.util.StringTokenizer; + +public class Qualification2012B { + public void solve() { + int count = Integer.valueOf(Main.inputData.get(0)); + for (int i = 0; i < count; i++) { + int result = 0; + + String data = Main.inputData.get(i + 1); + + StringTokenizer st = new StringTokenizer(data, "" ""); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int P = Integer.parseInt(st.nextToken()); + + for (int j = 0; j < N; j++) { + int tScore = Integer.parseInt(st.nextToken()); + + if (tScore == 0) { + if(P == 0) result++; + } else { + int d = tScore / 3; + if (d + 1 == P && tScore % 3 == 0 && S > 0) { + S--; + result++; + } else if (d + 1 >= P && !(d + 1 == P && tScore % 3 == 0)) { + result++; + } else if (d + 2 == P && tScore % 3 == 2 && S > 0) { + S--; + result++; + } + } + } + Main.outputData.add(""Case #"" + (i + 1) + "": "" + result); + } + } +} +" +A21281,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class DancingGooglers { + + + + public DancingGooglers() { + + Integer maxInputs; + String line; + Integer output; + Integer N, S, p; + try { + BufferedReader read = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(""input""))); + BufferedWriter write = new BufferedWriter(new FileWriter(""output"")); + maxInputs = new Integer(read.readLine()); + for(int i = 1 ; i <= maxInputs ; i++) + { + int success = 0, surprise = 0; + line = read.readLine(); + String[] numbers = line.split("" ""); + N = new Integer(numbers[0]); + S = new Integer(numbers[1]); + p = new Integer(numbers[2]); + + for( int j = 3; j < N+3; j++) + { + //Do calculations for each number + Integer t = new Integer(numbers[j]); + switch(check(t,p)) + { + case 0: + success++; + break; + case 1: + if(surprise < S) + { + surprise++; + success++; + } + break; + } + } + + output = new Integer(success); + write.write(""Case #""+i+"": ""); + write.write(output.toString()); + write.write(""\n""); + } + write.close(); + + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** + * @param args + */ + public static void main(String[] args) { + + long startTime = System.nanoTime(); + new DancingGooglers(); + long endTime = System.nanoTime();; + System.out.println(""Took ""+(endTime - startTime) + "" ns""); + } + + int check(int t, int p) + { + if(p == 0) + return 0; + int minNorm = 3*p - 2; + int minVal = 3*p - 4; + if(minVal < 0) + minVal = 1; + if( t >= minNorm) + return 0; + if( t < minVal ) + return 2; + return 1; + } + +} +" +A22139,"package codeJam; + +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; + +/** + * Created by IntelliJ IDEA. + * User: vsaurabh + * Date: 4/14/12 + * Time: 6:10 AM + * To change this template use File | Settings | File Templates. + */ +public class DancingWithTheGooglers { + + public static void main(String args[]) throws Exception { + String inputPath = ""C:\\myTestProj\\src\\codeJam\\B-large.in""; + String outputPath = ""C:\\myTestProj\\src\\codeJam\\B-large.out""; + + DancingWithTheGooglers dwg = new DancingWithTheGooglers(); + String[] str = dwg.readFromFile(inputPath); + + str = dwg.solution(str); + dwg.writeToFile(outputPath, str); + } + + private String[] solution(String[] str){ + String[] strNew = new String[str.length-1]; + for(int i=0; i 0){ + max2=2; + } + if(max2 >= p){ + s--; + } + } + else if(x%3 == 0){ + max1 = x/3; + if(s > 0 && max1= p){ + s--; + } + + } + } + else if(x%3 == 1){ + max1 = x/3 + 1; + } + else{ + max1 = x/3 + 1; + if(s > 0 && (x/3 + 2) <= 10 && max1= p){ + s--; + } + } + } + if(max1>=p || max2>=p){ + y++; + } + } + + return y; + } + + + + public String[] readFromFile(String inputPath) throws FileNotFoundException,IOException { + FileInputStream fis = null; + DataInputStream dis = null; + BufferedReader br = null; + ArrayList strArrList = new ArrayList(); + try{ + fis = new FileInputStream(inputPath); + dis = new DataInputStream(fis); + br = new BufferedReader(new InputStreamReader(dis)); + String strLine; + while ((strLine = br.readLine()) != null) { + strArrList.add(strLine); + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally{ + try{ + if (br != null) { + br.close(); + } + if (dis != null) { + dis.close(); + } + if (fis != null) { + fis.close(); + } + } catch(IOException e) { + e.printStackTrace(); + } + } + return strArrList.toArray(new String[strArrList.size()]); + } + + public void writeToFile(String outputPath, String[] strArr) { + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(outputPath)); + + for(int i=0; i= nonSurprisingScore) + numScores++; + else if(surprises > 0 && score !=0 && score + 2 >= nonSurprisingScore) + { + numScores++; + surprises--; + } + } + out.println(""Case #"" + (j+1) + "": "" + numScores); + } + in.close(); + out.close(); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} +" +A21109," +import java.util.Arrays; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author alvin + */ +public class DancingWithTheGooglers implements Comparable { + + public int a, b, c; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int nTC = sc.nextInt(); + for (int tc = 1; tc <= nTC; tc++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + DancingWithTheGooglers skor[] = new DancingWithTheGooglers[n]; + for (int i = 0; i < n; i++) { + skor[i] = new DancingWithTheGooglers(sc.nextInt()); + } + + Arrays.sort(skor); + + int hasil = 0; + for (int i = 0; i < n; i++) { + if (skor[i].a >= p || skor[i].b >= p || skor[i].c >= p) { + ++hasil; + } else if (s > 0) { + if ((skor[i].a == skor[i].b) && (skor[i].a + 1 >= p) && (skor[i].b - 1 >= 0)) { + ++hasil; + --s; + } else if ((skor[i].b == skor[i].c) && (skor[i].b + 1 >= p) && (skor[i].c - 1 >= 0)) { + ++hasil; + --s; + } + } + } + + System.out.format(""Case #%d: %d\n"", tc, hasil); + } + } + + public DancingWithTheGooglers(int skor) { + a = skor / 3; + b = skor / 3; + c = skor / 3; + + int sisa = skor - (a + b + c); + if (sisa == 1) { + ++a; + } else if (sisa == 2) { + ++a; ++b; + } + } + + @Override + public int compareTo(DancingWithTheGooglers o) { + if (a != o.a) { + return (o.a - a); + } else if (b != o.b) { + return (o.b - b); + } else if (c != o.c) { + return (o.c - c); + } else { + return 0; + } + } + +} + +" +A21158,"package com.google.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; + +public class Utils { + static final String outputFileName = ""D:\\output.txt""; + static ArrayList outputData = new ArrayList(); + + public static void run(Class cls){ + Object obj = null; + try { + obj = cls.newInstance(); + } catch (Exception e1) { + e1.printStackTrace(); + } + outputData.clear(); + + String[] args = Utils.readInput(cls); + Method method = getMethod(obj.getClass()); + executeMethod(obj, args, method); + writeToFile(); + } + + private static void executeMethod(Object obj, String[] args, Method method) { + int index = 0; + int n = Integer.valueOf(args[index++]); + if (n == args.length - 1){ + for(int i = 0; i < n; i++){ + Class[] t = method.getParameterTypes(); + Object[] par = new Object[t.length]; + for (int j = 0; j < t.length; j++) { + par[j] = parseParameter(args[index++], t[j]); + } + try { + printOutput(i+1, method.invoke(obj, par)); + } catch (Exception e) { + e.printStackTrace(); + } + } + }else{ + for(int i = 0; i < n; i++){ + Class[] t = method.getParameterTypes(); + Object[] par = new Object[t.length]; + + String[] sp = args[index++].split("" ""); + if(t.length == sp.length){ + for (int j = 0; j < t.length; j++) { + String[] sArr = new String[Integer.valueOf(sp[j])]; + for (int k = 0; k < sArr.length; k++) { + sArr[k] = args[index++]; + } + par[j] = sArr; + } + } + try { + printOutput(i+1, method.invoke(obj, par)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + } + + private static String[] readInput(Class cls){ + String fileName = cls.getSimpleName() + "".in""; + BufferedReader in = new BufferedReader(new InputStreamReader(cls.getResourceAsStream(fileName))); + ArrayList res = new ArrayList(); + + String s; + try { + while((s = in.readLine()) != null){ + res.add(s); + } + } catch (IOException e) { + e.printStackTrace(); + } + return res.toArray(new String[]{}); + } + + private static Method getMethod(Class cls){ + Method[] methods = null; + try { + methods = cls.getDeclaredMethods(); + for(Method m : methods) + if(Modifier.isPublic(m.getModifiers())) return m; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static Object parseParameter(String arg, Class cls) { + if(cls == int.class){ + return Integer.valueOf(arg); + }else if(cls == int[].class){ + String[] split = arg.split("" ""); + int[] res = new int[split.length]; + for (int i = 0; i < res.length; i++) { + res[i] = Integer.valueOf(split[i]); + } + return res; + }else if(cls == long[].class){ + String[] split = arg.split("" ""); + long[] res = new long[split.length]; + for (int i = 0; i < res.length; i++) { + res[i] = Long.valueOf(split[i]); + } + return res; + }else if(cls == String.class){ + return arg; + } + return null; + } + + private static void printOutput(int count, Object res) { + Class cls = res.getClass(); + String data = ""Case #"" + count + "": ""; + if(cls == int[].class){ + int[] array = (int[]) res; + for (int i = 0; i < array.length; i++) { + data += array[i] + "" ""; + } + data = data.substring(0, data.length() - 1); + }else{ + data += res; + } + System.out.println(data); + outputData.add(data); + } + + + private static void writeToFile() { + try { + FileWriter fstream = new FileWriter(outputFileName); + BufferedWriter out = new BufferedWriter(fstream); + for(String s : outputData){ + out.write(s); + out.newLine(); + } + out.close(); + fstream.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } +}" +A22718,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package javaapplication3; + +import java.io.*; +import java.math.*; +import java.util.*; + +public class Dance { + + public static final String INPUT = ""dance""; + + @SuppressWarnings(""unchecked"") + private static void solve() throws IOException { + int T = 0; + + T = nextInt(); + int googlers = 0; + int suprise = 0; + int prog = 0; + int wynik = 0; + int triplet = 0; + + int licznik = 0; + System.out.println(""START""); + try { + for (int t = 0; t < T; t++) { + wynik = 0; + googlers = nextInt(); + suprise = nextInt(); + prog = nextInt(); + // System.out.println(""googlers = "" + googlers); + // System.out.println(""suprise = "" + suprise); + // System.out.println(""prog = "" + prog); + + if (prog > 0) { + // System.out.println(""prog >0""); + for (int i = 0; i < googlers; i++) { + triplet = nextInt(); + // System.out.println(""TRIPLET = "" + triplet); + if (triplet > 2) { + if (triplet % 3 == 0) { + if (triplet / 3 >= prog) { + // System.out.println(""triplet / 3 >= prog""); + wynik++; + } else if (((triplet / 3) + 1 == prog) && (suprise > 0)) { + // System.out.println(""((triplet / 3) + 1 == prog) && (suprise > 0)""); + wynik++; + suprise--; + } + } else if (triplet % 3 == 1) { + if ((triplet + 2) / 3 >= prog) { + // System.out.println(""((triplet + 2) / 3 >= prog""); + wynik++; + } + } else { + if ((triplet + 1) / 3 >= prog) { + // System.out.println(""(triplet + 1) / 3 >= prog""); + wynik++; + } else { + if ((suprise > 0) && (triplet < 27)) { + // System.out.println(""(suprise > 0) && (triplet < 27)""); + if ((triplet + 4) / 3 >= prog) { + // System.out.println(""((triplet + 4) / 3 >= prog)""); + wynik++; + suprise--; + } + } + } + } + } else if (((triplet == 2) || (triplet == 1)) && (prog == 1)) { + wynik++; + } else if ((triplet == 2) && (prog == 2) && (suprise > 0)) { + wynik++; + suprise--; + } + } + } else if (prog == 0) { + for (int i = 0; i < googlers; i++) { + triplet = nextInt(); + // System.out.println(""(prog == 0)""); + wynik = googlers; + } + } + + // if (suprise < 0) { + // wynik = wynik + suprise; + // } + licznik = t + 1; + System.out.println(""Case #"" + licznik + "" "" + wynik); + out.println(""Case #"" + licznik + "": "" + wynik); + } + + System.out.println(""STOP""); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static String zmienLitere(String znak) { + String nowyZnak = """"; + HashMap hashMap = new HashMap(); + hashMap.put(""a"", ""y""); + hashMap.put(""b"", ""h""); + hashMap.put(""c"", ""e""); + hashMap.put(""d"", ""s""); + hashMap.put(""e"", ""o""); + hashMap.put(""f"", ""c""); + hashMap.put(""g"", ""v""); + hashMap.put(""h"", ""x""); + hashMap.put(""i"", ""d""); + hashMap.put(""j"", ""u""); + hashMap.put(""k"", ""i""); + hashMap.put(""l"", ""g""); + hashMap.put(""m"", ""l""); + hashMap.put(""n"", ""b""); + hashMap.put(""o"", ""k""); + hashMap.put(""p"", ""r""); + hashMap.put(""q"", ""z""); + hashMap.put(""r"", ""t""); + hashMap.put(""s"", ""n""); + hashMap.put(""t"", ""w""); + hashMap.put(""u"", ""j""); + hashMap.put(""v"", ""p""); + hashMap.put(""w"", ""f""); + hashMap.put(""x"", ""m""); + hashMap.put(""y"", ""a""); + hashMap.put(""z"", ""q""); + + + nowyZnak = (String) hashMap.get(znak); + + + // if (""a"".equals(znak)) { + // nowyZnak = ""y""; + // } else { + // nowyZnak = znak; + // } + + return nowyZnak; + } + + private static long dajSume(ArrayList cuksy) { + long lewa = 0; + long prawa = 0; + long lewaSum = 0; + long prawaSum = 0; + long max = 0; + for (int i = 1; i < cuksy.size() - 1; i++) { + lewaSum = 0; + prawaSum = 0; + for (int j = 0; j < i; j++) { + lewa = lewa ^ Long.parseLong(cuksy.get(j)); + lewaSum = lewaSum + Long.parseLong(cuksy.get(j)); + } + for (int k = i; k < cuksy.size(); k++) { + prawa = prawa ^ Long.parseLong(cuksy.get(k)); + prawaSum = prawaSum + Long.parseLong(cuksy.get(k)); + } + if (prawa == lewa) { + // System.out + // .println(i + "" lewa "" + lewaSum + "" prwa "" + prawaSum); + if ((prawaSum > max) && (prawaSum > lewaSum)) { + // System.out.println(i); + max = prawaSum; + } else if ((lewaSum > max) && (prawaSum < lewaSum)) { + // System.out.println(i); + max = lewaSum; + } + + } + } + //System.out.println("" max "" + max); + return max; + } + // ----------------------------------------------- + private static BufferedReader br; + private static StringTokenizer _st; + private static PrintWriter out; + + private static String next() throws IOException { + while (_st == null || !_st.hasMoreTokens()) { + String s = br.readLine(); + if (s == null) { + return s; + } + _st = new StringTokenizer(s); + } + return _st.nextToken(); + } + + private static int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + private static long nextLong() throws IOException { + return Long.parseLong(next()); + } + + private static double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + private static String nextLine() throws IOException { + _st = null; + return br.readLine(); + } + + public static void run() { + long startTime = System.nanoTime(); + try { + br = new BufferedReader(new FileReader( + ""c:/software/Projects/"" + INPUT + "".in"")); + out = new PrintWriter(""c:/software/Projects/"" + INPUT + "".output""); + try { + solve(); + } finally { + out.close(); + } + } catch (IOException e) { + System.err.println(e.getClass().getName() + "": "" + e.getMessage()); + e.printStackTrace(); + } + long finishTime = System.nanoTime(); + System.err.printf(""%.3f\n"", (finishTime - startTime) / 1e9); + } + + public static void main(String[] args) { + run(); + } +} +" +A20886,"//package dancing_with_googler; + +import java.io.BufferedInputStream; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.util.Scanner; + +public class Solution { + + /** + * @param args + */ + public void doit() throws Exception{ + BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new + FileOutputStream(java.io.FileDescriptor.out), ""ASCII""), 512); + Scanner s = new Scanner(new BufferedInputStream(System.in)); + int cases = s.nextInt(); + for(int i=0;i0&&surprising[P]<=score[j]){ + S--;count++; + } + } + out.append(""Case #"" + (i+1) + "": "" + count); + out.append('\n'); + } + out.flush(); + } + public static void main(String[] args) { + // TODO Auto-generated method stub + Solution s = new Solution(); + try{ + s.doit(); + }catch(Exception e){ + e.printStackTrace(); + } + } + +} +" +A20794,"import java.io.*; +import java.util.*; + +public class GCJ_Q_B +{ +// public static String +// public static int +// ArrayList list = new ArrayList(); +// HashMap map = new HashMap(); +// HashSet set = new HashSet(); + +// for(int i=0;i<;i++) + +// for(int j=0;j<;j++) + +// for(int k=0;k<;k++) + +// System.out.println(); +// System.out.print(); +// System.out.printf("""", new Object{}); +// System.out.printf("""", new Integer{}); +// System.out.printf("""", new Long{}); + + public static void main(String[] args) throws Exception + { + // Scanner scanner = new Scanner(new FileInputStream(""B.txt"")); + // Scanner scanner = new Scanner(new FileInputStream(""B-small-attempt0.in"")); + Scanner scanner = new Scanner(new FileInputStream(""B-large.in"")); + + BufferedWriter writer = new BufferedWriter(new FileWriter(""B.out"")); + + int N = scanner.nextInt(); + // scanner.nextLine(); + for(int q=1;q<=N;q++) + { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int[] t = new int[n]; + for(int i=0;i= 1) + c++; + } + else + { + int min = p*3-4; + int ok = p*3-2; + for(int i=0;i= min) + { + if(t[i] >= ok) + c++; + else if(s>0) + { + s--; + c++; + } + } + } + + return c+""""; + } + + + + // 素因数分解 + static boolean[] primeList = null; + + public static int[] dividePrime(int num) + { + if(primeList==null) + primeList = primeListOfEratosthenes(10000); + + if(primeList[num] || num==1) + return new int[]{num}; + + ArrayList list1 = new ArrayList(); + for(int i=2;true;i++) + { + if(num==1) + break; + + if(num%i==0) + { + list1.add(new Integer(i)); + num /= i; + i--; + } + } + + int[] ret = new int[list1.size()]; + for(int i=0;i { + + private final A field0; + private final B field1; + private final C field2; + + public A getField0() { + return field0; + } + + public B getField1() { + return field1; + } + + public C getField2() { + return field2; + } + + public Tuple3(final A field0, final B field1, final C field2) { + this.field0 = field0; + this.field1 = field1; + this.field2 = field2; + } + + /** Convenience method so type params of pair don't have to be specified: just do Tuple3.make(a, b, c) */ + public static Tuple3 make(A field0, B field1, C field2) { + return new Tuple3(field0, field1, field2); + } + + // --------------------------------------------------------------------------------------------------- + + private static final boolean objEquals(Object p1, Object p2) { + if (p1 == null) + return p2 == null; + return p1.equals(p2); + } + + @Override + public final boolean equals(Object o) { + if (!(o instanceof Tuple3)) { + return false; + } else { + final Tuple3 other = (Tuple3) o; + return objEquals(getField0(), other.getField0()) && objEquals(getField1(), other.getField1()) + && objEquals(getField2(), other.getField2()); + } + } + + @Override + public int hashCode() { + int h0 = getField0() == null ? 0 : getField0().hashCode(); + int h1 = getField1() == null ? 0 : getField1().hashCode(); + int h2 = getField2() == null ? 0 : getField2().hashCode(); + return h0 + 53 * h1 + 97 * h2; + } + + // --------------------------------------------------------------------------------------------------- + + public static , B, C> Comparator> comparatorOnField0(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple3 o1, Tuple3 o2) { + return o1.getField0().compareTo(o2.getField0()); + } + }; + } + + public static , B, C> Comparator> comparatorOnField0Rev(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple3 o1, Tuple3 o2) { + return -o1.getField0().compareTo(o2.getField0()); + } + }; + } + + public static , C> Comparator> comparatorOnField1(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple3 o1, Tuple3 o2) { + return o1.getField1().compareTo(o2.getField1()); + } + }; + } + + public static , C> Comparator> comparatorOnField1Rev(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple3 o1, Tuple3 o2) { + return -o1.getField1().compareTo(o2.getField1()); + } + }; + } + + public static > Comparator> comparatorOnField2(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple3 o1, Tuple3 o2) { + return o1.getField2().compareTo(o2.getField2()); + } + }; + } + + public static > Comparator> comparatorOnField2Rev(Collection> tupleCollection) { + return new Comparator>() { + @Override + public int compare(Tuple3 o1, Tuple3 o2) { + return -o1.getField2().compareTo(o2.getField2()); + } + }; + } + + // --------------------------------------------------------------------------------------------------- + + @Override + public String toString() { + return ""("" + getField0() + "", "" + getField1() + "", "" + getField2() + "")""; + } +} +" +A22198,"package gcodejam2012; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; +/** + * @author alei + */ +public class B { + public static void main(String[]Args) throws FileNotFoundException{ + Scanner sn = new Scanner(new FileInputStream(""B.in"")); + System.setOut(new PrintStream(""B.out"")); + int nCases = sn.nextInt(); + for(int i=0;i=min){ + m++; + if(point==s1 || point==s2||point==s3||point==s4){ + int n1 = (point+2)/3; + if(n1>=P){ + //System.out.println(""sns++->""+point); + sns++; + } + c++; + } + else{ + int n1 = (point+2)/3; + if(n1>=P){ + ssp++; + } + } + } + else if(point >max){ + gigants++; + m++; + } + else{ + a++; + } + } + //System.out.println(""m->""+m+""->gig->""+gigants+""->a->""+a+""->S->""+S+""->c->""+c+""<->nsp->""+ssp); + + if(S>c){ + S-=c; + if(S>0){ + S-=gigants; + if(S>0){ + S-=a; + if(S>0){ +// System.out.println(""finalSubst->""+m+""-s:""+S); + int reaNsp = Math.min(S, ssp); + m = m-S+reaNsp; + } + } + } + } + else{ + //sns = Math.min(S, sns); + int fns = c-S; + //System.out.println(""fns->""+fns+""<->sns->""+sns); + if(sns>=fns){ + + } + else{ + m = m - fns + sns; + } + } + + return m; + } +} +" +A22461,"import com.sun.org.apache.xerces.internal.impl.xs.opti.DefaultXMLDocumentHandler; +import util.graph.DynDjikstra; +import util.graph.Edge; +import util.graph.Node; +import util.graph.State; + +import javax.xml.crypto.dsig.CanonicalizationMethod; +import java.io.IOException; +import java.math.BigInteger; +import java.util.List; +import java.util.PriorityQueue; +import java.util.SortedSet; +import java.util.TreeSet; + +public class CrossingRoad extends JamProblem { + + public static void main(String[] args) throws IOException { + CrossingRoad p = new CrossingRoad(); + p.go(); + } + @Override + String solveCase(JamCase jamCase) { + CrossCase ca = (CrossCase) jamCase; + CrossState crossState = new CrossState(); + crossState.time = 0; + ca.startNode.last = crossState; + CrossState state = (CrossState) DynDjikstra.FindShortest(ca.startNode, ca.stopNode); + + + return """" + state.time; + } + + @Override + JamCase parseCase(List file, int line) { + String first = file.get(line++); + int[] size = JamUtil.parseIntList(first, 2); + CrossCase ca = new CrossCase(); + ca.n = size[0]; + ca.m = size[1]; + ca.lineCount = ca.n + 1; + ca.map = new Crossing[ca.n][ca.m]; + Node[][][][] nodes = new Node[ca.n][ca.m][2][2]; + Node start = null; + Node end = null; + for (int y = 0; y < ca.n; y++) { + String row = file.get(line++); + int[] data = JamUtil.parseIntList(row, 3 * ca.m); + for (int x = 0; x < ca.m; x++) { + Crossing cr = new Crossing(); + ca.map[y][x] = cr; + cr.minTime = Integer.MAX_VALUE; + cr.s = data[3*x]; + cr.w = data[3*x+1]; + cr.t = data[3*x+2]; + cr.x = x; + cr.y = y; + Node ne = new CrossNode(); + + Node se = new CrossNode(); + Node sw = new CrossNode(); + Node nw = new CrossNode(); + CrossStreetSNEdge snEdge1 = new CrossStreetSNEdge(); + snEdge1.s =cr.s; + snEdge1.w = cr.w; + snEdge1.t = cr.t; + CrossStreetWEEdge weEdge = new CrossStreetWEEdge(); + weEdge.s= cr.s; + weEdge.w=cr.w; + weEdge.t=cr.t; + + snEdge1.biConnect(ne,se); + snEdge1.biConnect(nw,sw); + weEdge.biConnect(ne,nw); + weEdge.biConnect(se,sw); + + Node[][] pack = nodes[y][x]; + pack[0][0] = nw; + pack[0][1] = ne; + pack[1][1] = se; + pack[1][0] = sw; + ((CrossNode)nw).label = ""y "" + y + "" x "" + x + "" nw""; + ((CrossNode)ne).label = ""y "" + y + "" x "" + x + "" ne""; + ((CrossNode)se).label = ""y "" + y + "" x "" + x + "" se""; + ((CrossNode)sw).label = ""y "" + y + "" x "" + x + "" sw""; + if (y==0 && x ==ca.m-1) { + ca.stopNode = pack[0][1]; + } + + if (y==ca.n-1 && x == 0) { + ca.startNode = pack[1][0]; + } + + if (y>0) { + CrossBlockEdge b1 = new CrossBlockEdge(); + b1.biConnect(nodes[y][x][0][1],nodes[y-1][x][1][1]); + b1.biConnect(nodes[y][x][0][0],nodes[y-1][x][1][0]); + } + + if (x>0) { + CrossBlockEdge b1 = new CrossBlockEdge(); + b1.biConnect(nodes[y][x][0][0], nodes[y][x - 1][0][1]); + b1.biConnect(nodes[y][x][1][0],nodes[y][x-1][1][1]); + } + } + } + return ca; + } +} + +class CrossCase extends JamCase { + int n, m; + Crossing[][] map; + public Node startNode; + public Node stopNode; +} + +class Crossing implements Comparable{ + int s, w, t, minTime,x,y; + + @Override + public int compareTo(Crossing o) { + return Integer.compare(minTime,o.minTime); + } +} + +class CrossState extends State { + + long time; + @Override + public int compareTo(Object o) { + return Long.compare(time,((CrossState)o).time); + } +} + +class CrossBlockEdge extends Edge { + @Override + public State travel(State current) { + CrossState old = (CrossState) current; + CrossState newS = new CrossState(); + newS.time = old.time + 2; + return newS; + } +} + +class CrossStreetSNEdge extends Edge { + long s,w,t; + @Override + public State travel(State current) { + CrossState old = (CrossState) current; + CrossState newS = new CrossState(); + long adjusted = old.time - t; + long period = s + w; + long inCycle = adjusted % period; + if (inCycle < s) { + newS.time = old.time + 1; + return newS; + } + newS.time = old.time + (period-inCycle); + return newS; + } +} + +class CrossStreetWEEdge extends Edge { + long s,w,t; + @Override + public State travel(State current) { + CrossState old = (CrossState) current; + CrossState newS = new CrossState(); + long adjusted = old.time - t; + long period = s + w; + long inCycle = adjusted % period; + if (inCycle >= s) { + newS.time = old.time + 1; + return newS; + } + newS.time = old.time + (s-inCycle); + return newS; + } +} + +class CrossNode extends Node { + String label; + CrossNode() { + last = new CrossState(); + } + + @Override + public String toString() { + return label; + } +} +" +A21772,"import java.util.*; + +public class B +{ + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + int test = 1, cases = sc.nextInt(); + int n, s, p, g, score, count, even, extra; + + while(test <= cases) + { + count = 0; + n = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + + for(g = 0; g < n; g++) + { + score = sc.nextInt(); + even = score / 3; + extra = score - even * 3; + + if(extra > 0) + even++; + + if(even >= p) + count++; + else if(s > 0) + { + score--; + even = score / 3; + extra = score - even * 3; + + if(extra > 0) + even += 2; + + if(even >= p) + { + count++; + s--; + } + } + } + + System.out.println(""Case #"" + test + "": "" + count); + + test++; + } + } +}" +A22574,"package es.saspelo.codejam.dancingwiththegooglers; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.Scanner; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.martiansoftware.jsap.FlaggedOption; +import com.martiansoftware.jsap.JSAP; +import com.martiansoftware.jsap.JSAPResult; + +import es.saspelo.codejam.commons.CodeJamProblem; + +public class DancingWithTheGooglers implements CodeJamProblem { + + private static final Logger log = LoggerFactory.getLogger(DancingWithTheGooglers.class); + + private static class DancingWithTheGooglersData { + + private int googlers = 0; + private int surprisingTriplets = 0; + private int score = 0; + private List points = null; + + public int getGooglers() { + return googlers; + } + + public void setGooglers(int googlers) { + this.googlers = googlers; + } + + public int getSurprisingTriplets() { + return surprisingTriplets; + } + + public void setSurprisingTriplets(int surprisingTriplets) { + this.surprisingTriplets = surprisingTriplets; + } + + public int getScore() { + return score; + } + + public void setScore(int score) { + this.score = score; + } + + public List getPoints() { + return points; + } + + public void setPoints(List points) { + this.points = points; + } + + @Override + public String toString() { + return ""DancingWithTheGooglersData [googlers="" + googlers + "", surprisingTriplets="" + surprisingTriplets + + "", score="" + score + "", points="" + points + ""]""; + } + } + + public void execute(InputStream in, OutputStream out) throws IOException { + + int testCases = 1; + + final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); + + final List problemDatas = readInput(in); + + if (log.isDebugEnabled()) { + log.debug(""==== starting problem '{}' ===="", DancingWithTheGooglers.class.getSimpleName()); + } + + try { + for (DancingWithTheGooglersData data : problemDatas) { + int bestResultReached = 0; + + Collections.sort(data.getPoints()); + Collections.reverse(data.getPoints()); + + log.debug(""points: '{}' | score: '{}' | surprising: '{}'"", + new Object[] { data.getPoints(), data.getScore(), data.getSurprisingTriplets() }); + + int surprising = data.getSurprisingTriplets(); + List tripletList = new ArrayList(); + for (int i = 0; i < data.getGooglers(); i++) { + int[] triplet = new int[3]; + + int div = data.getPoints().get(i) / 3; + int rest = data.getPoints().get(i) % 3; + + triplet[0] = div; + triplet[1] = div; + triplet[2] = div; + + int t = 0; + while (rest > 0) { + triplet[t++]++; + rest--; + } + + Arrays.sort(triplet); + + // adjust points to max + if (triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 + && ((triplet[2] + 1) - (triplet[0] - 1) < 2)) { + triplet[2]++; + triplet[0]--; + } + + if (triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 + && ((triplet[2] + 1) - (triplet[1] - 1) < 2)) { + triplet[2]++; + triplet[1]--; + } + + boolean nothingToDoIn1 = false; + boolean nothingToDoIn2 = false; + while (surprising > 0 && !nothingToDoIn1 && !nothingToDoIn2) { + if ((triplet[2] < data.getScore()) && triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 + && (((triplet[2] + 1) - (triplet[0] - 1)) == 2)) { + triplet[2]++; + triplet[0]--; + surprising--; + nothingToDoIn1 = false; + + } else { + nothingToDoIn1 = true; + } + nothingToDoIn2 = true; + if (surprising > 0) { + if ((triplet[2] < data.getScore()) && triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 + && (((triplet[2] + 1) - (triplet[1] - 1)) == 2)) { + triplet[2]++; + triplet[1]--; + surprising--; + nothingToDoIn2 = false; + } + } + } + + tripletList.add(triplet); + log.debug(""googler '{}'-> triplet: '{}'"", new Object[] { i, triplet }); + } + + for (int[] triplet : tripletList) { + if (triplet[2] >= data.getScore()) { + bestResultReached++; + } + } + + writer.write(""Case #"" + testCases + "": "" + bestResultReached + ""\n""); + writer.flush(); + testCases++; + } + } finally { + writer.close(); + } + } + + private List readInput(InputStream in) { + + final Scanner sc = new Scanner(in); + + int testCases = sc.nextInt(); + if (log.isDebugEnabled()) { + log.debug(""testCases: '{}'"", testCases); + } + + List problemData = new ArrayList(testCases); + + for (int i = 0; i < testCases; i++) { + DancingWithTheGooglersData data = new DancingWithTheGooglersData(); + + data.setGooglers(sc.nextInt()); + data.setSurprisingTriplets(sc.nextInt()); + data.setScore(sc.nextInt()); + + List points = new ArrayList(); + + for (int j = 0; j < data.getGooglers(); j++) { + points.add(sc.nextInt()); + } + + data.setPoints(points); + + if (log.isDebugEnabled()) { + log.debug(""data: '{}'"", data); + } + + problemData.add(data); + + } + + sc.close(); + return problemData; + } + + public static void main(String[] args) throws Exception { + final JSAP jsap = new JSAP(); + + final FlaggedOption inputFileName = new FlaggedOption(""input"").setStringParser(JSAP.STRING_PARSER) + .setShortFlag('i').setLongFlag(JSAP.NO_LONGFLAG); + + final FlaggedOption outputFileName = new FlaggedOption(""output"").setStringParser(JSAP.STRING_PARSER) + .setShortFlag('o').setLongFlag(JSAP.NO_LONGFLAG); + + inputFileName.setHelp(""File name with input for the problem""); + outputFileName.setHelp(""File name for problem output file""); + + jsap.registerParameter(inputFileName); + jsap.registerParameter(outputFileName); + + final JSAPResult config = jsap.parse(args); + + if (!config.success()) { + + System.err.println(); + + // print out specific error messages describing the problems + // with the command line, THEN print usage, THEN print full + // help. This is called ""beating the user with a clue stick."" + for (Iterator errs = config.getErrorMessageIterator(); errs.hasNext();) { + System.err.println(""Error: "" + errs.next()); + } + + System.err.println(); + System.err.println(""Usage: java "" + DancingWithTheGooglers.class.getName()); + System.err.println("" "" + jsap.getUsage()); + System.err.println(); + System.err.println(jsap.getHelp()); + System.exit(1); + } + + InputStream in = System.in; + OutputStream out = System.out; + + if (config.getString(""input"") != null) { + in = new FileInputStream(new File(config.getString(""input""))); + } + + if (config.getString(""output"") != null) { + out = new FileOutputStream(new File(config.getString(""output""))); + } + + DancingWithTheGooglers problem = new DancingWithTheGooglers(); + + problem.execute(in, out); + } +} +" +A20058,"package com.google.codejam; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class GoogleDance2 { + + public static void main(String[] args) throws Exception { + Scanner in = new Scanner(new BufferedReader(new FileReader(""/Users/sunny/Desktop/B-small-attempt0.in""))); + PrintWriter out=new PrintWriter(new FileWriter(""/Users/sunny/Desktop/B-small.out"")); + int t = in.nextInt(); int n, s, p ; String line; + for( int i = 1 ; i <= t ; i++){ + n = in.nextInt() ; s = in.nextInt() ; p = in.nextInt() ; + int []scores = new int[n]; + for(int j = 0 ; j < n ; j++) { + scores[j] = in.nextInt() ; + } + line = ""Case #""+i+"": ""+findMax(n, s, p, scores); + System.out.println(line); + out.println(line); + } + out.close() ; + } + + private static int findMax(int n, int s, int p, int[] scores) { + int d ; + List c= new ArrayList(); + boolean gp = true, surp = true; + for(int i = 0 ; i < n ; i++) { + d = scores[i]/3 ; + switch (scores[i]%3) { + case 0 : + if(d>=p) { + c.add(new Combination(gp, !surp)); + } + else if (d+1 >=p && d-1>=0){ + c.add(new Combination(gp, surp)); + } + else { + c.add(new Combination(!gp,!surp)); + } + break ; + case 1 : + c.add(new Combination(d+1>=p, !surp)); + break ; + case 2 : + if(d+1 >=p) { + c.add(new Combination(gp, !surp)); + } + else if (d+2 >=p) { + c.add(new Combination(gp, surp)); + } + else { + c.add(new Combination(!gp, !surp)); + } + break ; + } + } + + return colAlgo(c, n, s); + } + + private static int colAlgo(List cs, int n, int s) { + int count = 0 ; + Combination c ; + for(int i = 0 ; i < n ; i++) { + c = cs.get(i); + if(c.gp){ + if(c.sur) { + if(s>0){ + s--; + count++ ; + } + } + else{ + count++ ; + } + } + } + return count; + } + + private static class Combination { + public Combination(boolean gp, boolean surp) { + this.gp = gp ; + this.sur = surp ; + } + boolean sur ; + boolean gp ; + } +} +" +A20658," +package codejam; + +import java.io.*; + +public class DancingWithTheGooglers { + + private BufferedReader br; + private BufferedWriter wr; + + public DancingWithTheGooglers(String filein,String fileout){ + try{ + br = new BufferedReader(new + InputStreamReader(new FileInputStream(filein))); + wr = new BufferedWriter(new FileWriter(fileout)); + + int num = 0; + num = Integer.parseInt(br.readLine()); + + for (int i = 1;i<=num;i++){ + String buf = br.readLine(); + String[] bufarray = buf.split("" ""); + int n = Integer.parseInt(bufarray[0]); + int s = Integer.parseInt(bufarray[1]); + int p = Integer.parseInt(bufarray[2]); + int numgood = 0; + for (int j = 3;j= p){ + numgood++; + }else if (s > 0 && div > 0 && div+1 >= p){ + numgood++; + s--; + } + break; + case 1: + if (div >= p || div+1 >= p){ + numgood++; + } + break; + case 2: + if (div >= p || div+1 >= p){ + numgood++; + }else if (s > 0 && div+2 >= p){ + numgood++; + s--; + } + break; + } + } + String out = ""Case #""+i+"": ""+numgood; + wr.write(out); + if (i != num) + wr.newLine(); + } + + br.close(); + wr.close(); + }catch (IOException e){ + System.out.println(""IO failure""); + } + } + + public static void main(String[] args) { + DancingWithTheGooglers sp = new DancingWithTheGooglers(""B-large.in"",""B-large.out""); + } +} +" +A22599,"package com.Qualification_2012; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class DancingWithGooglers { + private static int S = 0; + public static void main(String[] args) { + try { + Scanner sc = new Scanner(new FileReader(""D:/Nandan/Project/GoogleCodeJam/Qualification-2012/B-small.in"")); + int T = sc.nextInt(); + for(int t=1; t<=T; t++){ + int N = sc.nextInt(); + S = sc.nextInt(); + int p = sc.nextInt(); + int count = 0; + for(int i=0; i 0 && actualScore > 2){ + S--; + return true; + } + + if(secondRemainder == 0 && Math.abs(p-b) == 1 && S > 0 && actualScore > 2){ + S--; + return true; + } + + if((a >= p) || (b >= p) || (c >= p)){ + return true; + } + return false; + } +} +" +A20516,"package com.googlerese.file; + +import java.io.*; +import java.util.HashMap; +import java.util.Map; + +public class FileRead { + + private static FileRead instance = new FileRead(); + + private FileRead() { + } + + public static FileRead getInstance() { + return instance; + } + + public Map read( final String fileName ) { + FileInputStream fstream = null; + DataInputStream in = null; + BufferedReader br = null; + Map input = null; + try { + // Open the file that is the first + // command line parameter + fstream = new FileInputStream( fileName ); + // Get the object of DataInputStream + in = new DataInputStream( fstream ); + br = new BufferedReader( new InputStreamReader( in ) ); + String strLine; + //Read File Line By Line + int count = 0; + while ( ( strLine = br.readLine() ) != null ) { + // Print the content on the console + if ( count == 0 ) { + input = new HashMap( Integer.parseInt( strLine ) ); + } else { + System.out.println( count + "" : "" + strLine ); + GooglersBean bean = new GooglersBean(); + String[] arr = strLine.split( ""\\s+"" ); + bean.setNumGooglers( Integer.parseInt( arr[0] ) ); + bean.setSurprising( Integer.parseInt( arr[1] ) ); + bean.setResult( Integer.parseInt( arr[2] ) ); + for ( int i = 3; i < arr.length; i++ ) { + bean.addScore( ( i - 3 ), Integer.parseInt( arr[i] ) ); + } + input.put( count, bean ); + } + count++; + } + } catch ( Exception e ) {//Catch exception if any + System.err.println( ""Error: "" + e.getMessage() ); + } finally { + //Close the input stream + try { + if ( br != null ) { + br.close(); + } + if ( in != null ) { + in.close(); + } + if ( fstream != null ) { + fstream.close(); + } + } catch ( IOException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return input; + } +} +" +A21456,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Googlers { + public static void main(String[] args) throws FileNotFoundException { + + Scanner in = new Scanner(new FileReader(new File(""B-large.in""))); + + PrintWriter out = new PrintWriter(new File(""B-large.out"")); + + int t = in.nextInt(); + in.nextLine(); + + for(int i=0; i=p || v3>=p) { + System.out.println("" >=p""); + r++; + } + else { + if (s>0) { + if (v1+1>=p && v1-1>=0) { + System.out.println("" special""); + + r++; + s--; + } else { + System.out.println("" can't make special""); + } + } else { + System.out.println("" no more spec""); + } + } + } + + System.out.println(""------------""); + System.out.println(""r="" + r); + System.out.println(""============""); + + + in.nextLine(); + + out.println(""Case #"" + (i+1)+ "": "" + r); + } + out.close(); + } +} +" +A21135,"import java.util.*; +import java.io.*; +public class B { + public static void main(String[]args) throws IOException { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(in.readLine()); + for(int x=1;x=p) { + cases++; + } + else + if (s > 0 && base > 0 && base + 1 >= p) { + cases++; + s--; + } + break; + case 1: + if(base+1>=p) { + cases++; + } + else + if (s > 0 && base + 1 >= p) { + cases++; + s--; + } + break; + case 2: + if(base+1>=p) { + cases++; + } + else + if (s > 0 && base + 2 >= p) { + cases++; + s--; + } + break; + } + } + System.out.println(""Case #""+x+"": ""+cases); + } + } +}" +A22959,"package com.qualification; + +import com.qualification.ScoreCombo.Score; +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public class Three { + public static void main(String[] args) throws FileNotFoundException, IOException { + FileReader fr = new FileReader(""/Users/minerva/Desktop/input.txt""); + FileWriter fw = new FileWriter(""/Users/minerva/Desktop/output.txt""); + + BufferedReader br = new BufferedReader(fr); + PrintWriter pr = new PrintWriter(fw); + + int numInputs = Integer.valueOf(br.readLine()); + + for(int i=0;i scores = new ArrayList(); + for (int indx = 3;numInputs > 0; numInputs--,indx++) { + Score result = new ScoreCombo(inputs[indx]).testBest(best); + if (result != null) scores.add(result); + } + + int supCount = 0; + int num = scores.size(); + + for(Score item:scores) + if (item.isSurprising()) + supCount++; + + + if (supCount > surprising) { + num -= (supCount - surprising); + } + + return num; + } +} + +class ScoreCombo { + private Score normalScore; + private Score surprisingScore; + + public ScoreCombo(int total) { + int rem = total % 3; + int avg = total / 3; + + if (total == 0) { + normalScore = new Score(0,false); + } else if (total == 1) { + normalScore = new Score(1,false); + } else if (total == 2) { + normalScore = new Score(1,false); + surprisingScore = new Score(2,true); + } else { + if(rem == 0) { + normalScore = new Score(avg,false); + surprisingScore = new Score(avg + 1,true); + } else if(rem == 1) { + normalScore = new Score(avg + 1,false); + surprisingScore = new Score(avg + 1,true); + } else if(rem == 2) { + normalScore = new Score(avg + 1,false); + surprisingScore = new Score(avg + 2,true); + } + } + } + + public class Score { + private int maxScore; + private boolean flag; + + private Score(int maxScore, boolean flag) { + this.maxScore = maxScore; + this.flag = flag; + } + + public boolean isSurprising() { + return flag; + } + + public boolean testBest(int testValue) { + return maxScore >= testValue; + } + } + + public Score testBest(int minScore) { + if (normalScore.testBest(minScore)) + return normalScore; + else if (surprisingScore != null && surprisingScore.testBest(minScore)) + return surprisingScore; + else + return null; + } +} +" +A21545,"package com.jp.common; + +import java.util.HashMap; + +import com.codejam.two12.GooglerDance.GDSmallProblem; +import com.codejam.two12.GooglerDance.GooglerDance; +import com.codejam.two12.RecyledNumbers.RecycledNumbers; +import com.codejam.two12.tongue.SpeakingTongues; +import com.jp.storeCredit.StoreCredit; + +public class PuzzleFactory { + + public static Puzzle getPuzzleSolution(String puzzleName){ + + HashMap hmPuzzleSolvers = new HashMap(); + hmPuzzleSolvers.put(""StoreCredit"", new StoreCredit()); + hmPuzzleSolvers.put(""SpeakingTongues"", new SpeakingTongues()); + hmPuzzleSolvers.put(""GooglerDance"", new GooglerDance()); + hmPuzzleSolvers.put(""RecycledNumbers"", new RecycledNumbers()); + hmPuzzleSolvers.put(""GDSmallProblem"", new GDSmallProblem()); + return hmPuzzleSolvers.get(puzzleName); + + } +} +" +A22808,"import java.util.Scanner; + + +public class Dancing { + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for(int i=0; i= p) numPass++; + else if(normalMax + 1 == p) + { + if(S > 0 && ((score % 3) != 1) && score != 0) + { + S--; + numPass++; + } + } + } + + System.out.println(""Case #"" + (i+1) + "": "" + numPass); + } + } +} +" +A22290,"import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + + +public class B { + public static void main(String[] args) throws IOException { + int[][] arr = new int[31][11]; + for(int[] a : arr) { + Arrays.fill(a, 1000); + } + for(int i = 0; i <= 10; i++) { + for(int j = i; j <= 10 && j <= i+2; j++) { + for(int k = j; k <= 10 && k <= i+2; k++) { + int sum = i+j+k; + if(k-i <= 1) { + for(int l = k; l >= 0; l--) { + arr[sum][l] = 1; + } + } else { + for(int l = k; l >= 0; l--) { + arr[sum][l] = Math.min(arr[sum][l], 2); + } + } + } + } + } + + PrintWriter out = new PrintWriter(new File(""B.out"")); + Scanner in = new Scanner(System.in); + int cases = in.nextInt(); + for(int caseOn = 1; caseOn <= cases; caseOn++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int ans = 0; + for(int i = 0; i < n; i++) { + int t = in.nextInt(); + if(arr[t][p]==1000) + continue; + if(arr[t][p]==2) { + if(s>0) { + s--; + ans++; + } + } + if(arr[t][p]==1) { + ans++; + } + } + out.printf(""Case #%d: %d\n"",caseOn,ans); + } + out.close(); + } +} +/* + +7 +3 1 5 15 13 11 +3 0 8 23 22 21 +2 1 1 8 0 +6 2 8 29 20 8 18 18 21 +3 1 5 5 5 5 +3 1 5 11 11 11 +3 1 5 15 15 15 + + +*/" +A21453,"//import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class jammo { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + Scanner scanner = new Scanner(new File(""input.txt"")); + //FileWriter fstream = new FileWriter(""output.txt""); + //BufferedWriter out = new BufferedWriter(fstream); + PrintWriter out = new PrintWriter(new FileWriter(""output.txt"")); + int inputSet,partC,surpC,minDM,curTot,noSurp,surpCo,total; + inputSet = scanner.nextInt(); + + for(int i=1; i<=inputSet; i++) + { + partC = scanner.nextInt(); + surpC = scanner.nextInt(); + minDM = scanner.nextInt(); + noSurp = 0; + surpCo = 0; + + for(int j=0; j=1) + noSurp++; + else if(curTot>=3*minDM-2) + noSurp++; + else if(curTot>=3*minDM-4) + surpCo++; + } + + total = noSurp + Math.min(surpC,surpCo); + out.println(""Case #""+i+"": ""+total); + System.out.print(""Case #""+i+"": ""+total+""\n""); + } + + out.close(); + return; + } +} +" +A20755,"import java.io.File; +import java.io.FileReader; +import java.io.LineNumberReader; +import java.util.ArrayList; +import java.util.List; + +public class CodeJam2 +{ + public static void calcMax(int numLines, String[] gLines) + { + int numGoog; + int numSurp; + int minScore; + + for (int i = 0; i< numLines; i++) { + int result = 0; + int numSurpUsed = 0; + String[] data = gLines[i].split("" ""); + numGoog = Integer.parseInt(data[0]); + numSurp = Integer.parseInt(data[1]); + minScore = Integer.parseInt(data[2]); + for (int j = 0; j< numGoog; j++) { + int googlerScore = Integer.parseInt(data[j+3]); + if ((googlerScore+4) < minScore*3) continue; + if (googlerScore <= 1) { + if (googlerScore >= minScore) result++; + continue; + } + if ((googlerScore)% 3 == 0) { + if ((googlerScore/3) >= minScore) result++; + else if ((googlerScore/3) +2 >= minScore && (numSurpUsed < numSurp)) { + result++; + numSurpUsed++; + } + } + else if ((googlerScore+1)% 3 == 0) { + googlerScore += 1; + if ((googlerScore/3) >= minScore) result++; + else if ((googlerScore/3) +1 >= minScore && (numSurpUsed < numSurp)) { + result++; + numSurpUsed++; + } + } + else if ((googlerScore-1)% 3 == 0) { + googlerScore -= 1; + if ((googlerScore/3) +1 >= minScore) result++; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + result); + } + } + + public static void main(String[] args) { + File f = new File(args[0]); + if (!f.isFile()) { + System.out.println(""The argument must be a file""); + return; + } + int numLines = -1, i = 0; + String[] gLines = null; + String currentLine; + try { + LineNumberReader lineReader = new LineNumberReader(new FileReader(args[0])); + try { + while ((currentLine = lineReader.readLine()) != null) { + if (numLines < 0) { + numLines = Integer.parseInt(currentLine); + gLines = new String[numLines]; + } + else { + gLines[i] = currentLine; + i++; + if (i == numLines) break; + } + } + } + catch(Exception e) {e.printStackTrace();} + finally { + lineReader.close(); + } + } + catch(Exception e) {e.printStackTrace();} + CodeJam2.calcMax(numLines, gLines); + } +} + +" +A21170,"import java.util.*; +import java.io.*; + +public class B{ + + public static void main(String[] args) throws IOException{ + Scanner inp = new Scanner(new File(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""b-large.out"")); + + int numCases = inp.nextInt(); + + for (int cas = 0; cas < numCases; cas++){ + pw.print(""Case #"" + (cas+1) + "": ""); + + /* case input */ + int N = inp.nextInt(); + int S = inp.nextInt(); + int p = inp.nextInt(); + int[] t = new int[N]; + for (int i = 0; i < N; i++){ + t[i] = inp.nextInt(); + } + /* end case input */ + + /* main logic */ + int ans = 0; + + int bNoS = 3*p - 2; + if (bNoS < 0){ + bNoS = 0; + } + + int bS = 3*p - 4; + if (bS < 2){ + bS = 2; + } + + for (int i = 0; i < N; i++){ + int ti = t[i]; + if (ti >= bNoS){ + ans++; + continue; + } + else if (ti >= bS){ + if (S > 0){ + S--; + ans++; + continue; + } + else{ + continue; + } + } + else{ + continue; + } + } + + pw.println(ans); + } + pw.close(); + } +} +" +A20105,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + + +public class ProblemB { + public void write(String m){ + try{ + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + out.write(m); + out.close(); + } + catch (Exception e){//Catch exception if any + System.err.println(""Error: in writing"" + e.getMessage()); + } + } + public static void main(String[] args) { + ProblemB r = new ProblemB(); + String result = """"; + try{ + FileInputStream fstream = new FileInputStream(""input.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = br.readLine(); + int cases = Integer.parseInt(strLine); + for (int i = 0 ; i < cases ; i++){ + String []m = br.readLine().split("" ""); + int size =0 ; + int surprise=0; + int high=0; + int c = 0; + int value = 0; + for (int j = 0 ; j < m.length ; j++){ + if (j == 0) + size = Integer.parseInt(m[j]); + else if(j ==1) + surprise = Integer.parseInt(m[j]); + else if (j ==2){ + high = Integer.parseInt(m[j]); + if (high < 2) + high = high + 0 + 0; + else + high = high + (high-2) + (high-2); + } + else { + value = Integer.parseInt(m[j]); + if (value >= high && value <= 30){ + if (high < 2){ + c++; + } + else if(value == high || (value-high) ==1){ + if (surprise > 0){ + surprise--; + c++; + } + } + else + c++; + } + } + } + result += ""Case #""+(i+1)+"": ""+c+""\n""; + } + + in.close(); + } + catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + r.write(result); + } +} +" +A20283,"package google2012; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Scanner; +import java.util.Stack; + +public class QRound_B { + static public void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new FileReader(""d:/in.txt"")); + int i=0; + while (true) { + String x = br.readLine(); + if (x==null) break; + if (i!=0) + run (x, i); + i++; + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + static private void run(String input, int caseid) { + int res=0; + Scanner sc =new Scanner(input); + int n=sc.nextInt(); + int s=sc.nextInt(); + int p=sc.nextInt(); + if (p>0) { + for (int i=0;i=3*p-2) res++; + else if (s>0) {s--;res++;} + } + } + else { + res=n; + } + System.out.printf(""Case #%d: %d%n"", caseid, res); + } +}" +A21132,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +import javax.swing.JOptionPane; + +public class GoogleDancers { + public static String rootDir = System.getProperty(""user.dir"") + + File.separator; + public static String filesDir = rootDir + ""files"" + File.separator; + private FileWriter fw; + private FileWriter fw2; + + private int tests; + private int[] numGooglers; + private int[] numSurprises; + private int[] target; + private int[][] points; + + public static void main(String[] args) { + GoogleDancers g = new GoogleDancers(); + //g.makeTest(100); + g.loadFile(); + g.go(); +// Compare c = new Compare(); +// try { +// c.go(""dancingAns.txt"",""dancingtest1Ans.txt""); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } + } + + public GoogleDancers() { + + } + + private void loadFile() { + try { + Scanner input = new Scanner(new File(filesDir + ""dancing.txt"")); + tests = Integer.parseInt(input.nextLine()); + numGooglers = new int[tests]; + numSurprises = new int[tests]; + target = new int[tests]; + points = new int[tests][]; + Scanner line; + + for (int i = 0; i < tests; i++) { + line = new Scanner(input.nextLine()); + + numGooglers[i] = line.nextInt(); + numSurprises[i] = line.nextInt(); + target[i] = line.nextInt(); + points[i] = new int[numGooglers[i]]; + + for (int j = 0; j < numGooglers[i]; j++) { + points[i][j] = line.nextInt(); + } + + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.exit(0); + } } + + private void go() { + + int s; + int count; + int high; + int total; + int[] surprises; + int[] normals; + boolean[] marks; + open(""dancingAns.txt""); + for (int c = 0; c < tests; c++) { +// System.out.println(""\nTEST CASE "" + (c + 1)); +// System.out.println(""Target is "" + target[c]); + count = 0; + s = numSurprises[c]; + // surprises = new int[numGooglers[c]]; + // normals = new int[numGooglers[c]]; + + for (int i = 0; i < numGooglers[c]; i++) { +// System.out.println("" # Surprises = "" + s); +// System.out.println("" Total Score is "" + points[c][i]); +// System.out.println("" Best Normal Score is "" +// + normalHigh(points[c][i])); + if (points[c][i] == 0) { + if (0 >= target[c]) + count++; + continue; + } else if (points[c][i] == 30) { + if (10 >= target[c]) + count++; + continue; + } + + if (normalHigh(points[c][i]) >= target[c]) { +// System.out.println("" Qualifies""); + count++; + } else if (s > 0) { +// System.out.println("" Does not qualify""); + if (surpriseHigh(points[c][i]) >= target[c]) { + +// System.out.println("" Best Surprise Score is "" +// + surpriseHigh(points[c][i])); +// System.out.println("" Qualifies""); + count++; + s--; + //System.out.println(""# Surprises = "" + s); +// System.out.println("" Does not qualify""); + } + } + // System.out.println(""# Qualified Scores = "" + count); + + // surprises[i] = surpriseHigh(points[c][i]); + // normals[i] = normalHigh(points[c][i]); + // + // if (points[c][i] == 0) + // surprises[i] = 0; + // else if (points[c][i] == 10) + // surprises[i] = 10; + } + + System.out.println(""Case #"" + (c + 1) + "": "" + count); + //System.out.println("" Surprises Left = "" + s); + write(""Case #"" + (c + 1) + "": "" + count); + if (c != tests - 1) + write(""\n""); + } + close(); + } + + private int surpriseHigh(int score) { + switch (score % 3) { + case 0: + return score / 3 + 1; + case 1: + return score / 3 + 1; + case 2: + return score / 3 + 2; + default: + System.out.println(""Error in surpriseHigh method""); + return 0; + } + } + + private int normalHigh(int score) { + switch (score % 3) { + case 0: + return score / 3; + case 1: + return score / 3 + 1; + case 2: + return score / 3 + 1; + default: + System.out.println(""Error in normalHigh method""); + return 0; + } + } + + private void open(String fileName) { + try { + fw = new FileWriter(new File(filesDir + fileName)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void openAnother(String fileName) { + try { + fw2 = new FileWriter(new File(filesDir + fileName)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void closeOther() { + try { + fw2.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void writeOther(String s) { + try { + fw2.write(s); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void close() { + try { + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void write(String s) { + try { + fw.write(s); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void makeTest(int numTests) { + int maxNumGooglers = 5; + + open(""dancingtest1.txt""); + openAnother(""dancingtest1Ans.txt""); + write(numTests + ""\n""); + + int numGs; + int numSs; + int testTarget; + int[][] scores; + for (int c = 0; c < numTests; c++) { + numGs = (int)(Math.random()*((double)maxNumGooglers) + 1.0); + write(numGs + "" ""); + print(numGs + "" ""); + + numSs = 0; + + testTarget = (int)(Math.random()*11.0); + + scores = generateScores(numGs); + + for (int[] s : scores) { + if (isSurprising(s)) + numSs++; + } + + write(numSs + "" ""); + write(testTarget + """"); + print(numSs + "" ""); + print(testTarget + """"); + + for (int[] s : scores) { + write("" "" + (s[0]+s[1]+s[2])); + print("" "" + (s[0]+s[1]+s[2])); + } + + write(""\n""); + print(""\n""); + + writeOther(""Case #"" + (c+1) + "": "" + answer(scores,testTarget,numSs)); + + if (c != numTests-1) + writeOther(""\n""); + } + close(); + closeOther(); + } + + private int answer(int[][] scores,int testTarget,int surprises) { + int answer = 0; + int ss = surprises; + + for (int[] s : scores) { + if (s[0]+s[1]+s[2] == 0) { + if (0 >= testTarget) + answer++; + continue; + } + + if (s[0]+s[1]+s[2] == 30) { + if (10 >= testTarget) + answer++; + continue; + } + + if (max(s) >= testTarget) + answer++; + else if ((s[0]+s[1]+s[2])%3 == 0 || (s[0]+s[1]+s[2])%3 == 2) { + if (surpriseHigh(s[0]+s[1]+s[2]) >= testTarget && (ss > 0)) { + answer++; + ss--; + } + } + } + return answer; + } + + private int max(int[] scores) { + int max = scores[0]; + + if (scores[1] > max) + max = scores[1]; + if (scores[2] > max) + max = scores[2]; + return max; + } + + private void print(String s) { + System.out.print(s); + } + + private boolean isSurprising(int[] scores) { + return (Math.abs(scores[0] - scores[1]) == 2) || (Math.abs(scores[0] - scores[2]) == 2) || (Math.abs(scores[1] - scores[2]) == 2); + } + + private int[][] generateScores(int numScores) { + int[][] scores = new int[numScores][3]; + + int temp; + int temp2; + for (int[] s : scores) { + s[0] = (int)(Math.random() * 11.0); + + do { + temp = ((int)(Math.random() * 5.0) - 2) + s[0]; + } while (temp < 0 || temp > 10); + + s[1] = temp; + + if (Math.abs(s[1]-s[0]) == 2) { // first two scores are two apart + if (s[0] > s[1]) + temp2 = s[1]; + else temp2 = s[0]; + + do { + temp = (int)(Math.random()*3.0) + temp2; + } while (temp < 0 || temp > 10); + } else if (Math.abs(s[1]-s[0]) == 1) { // first two scores are adjacent + if (s[0] > s[1]) + temp2 = s[1]; + else temp2 = s[0]; + + do { + temp = ((int)(Math.random() * 4.0)) + temp2 - 1; + } while (temp < 0 || temp > 10); + } else { // first two scores are equal + do { + temp = ((int)(Math.random() * 5.0) - 2) + s[0]; + } while (temp < 0 || temp > 10); + } + + s[2] = temp; + + //print(""["" + s[0] + "" "" + s[1] + "" "" + s[2] + ""]""); + } + + return scores; + } +} +" +A22705," +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Wilmer + */ +public class main { + int numeroCasos; + + public void leerArchivo(File archivo) throws FileNotFoundException, IOException{ + FileReader fr = new FileReader (archivo); + BufferedReader br = new BufferedReader(fr); + + String linea = br.readLine(); + numeroCasos = Integer.parseInt(linea.trim()); + + String[] datos = null; + int resultado = 0; + int googlers=0; + int numeroDeSorpresas = 0; + int objetivo = 0; + + int puntajeActual=0; + int validos = 0; + int validoSorpresa = 0; + int noValidoSorpresa = 0; + int sorpresasPorEncontrar=0; + + for(int i=1; i<=numeroCasos; i++){ + + linea = br.readLine(); + datos = linea.split("" ""); + + googlers = Integer.parseInt(datos[0]); + numeroDeSorpresas = Integer.parseInt(datos[1]); + objetivo = Integer.parseInt(datos[2]); + + puntajeActual=0; + validos = 0; + validoSorpresa = 0; + noValidoSorpresa = 0; + sorpresasPorEncontrar=0; + + + for(int j = 3; j= ((objetivo*3)-2) ){ + validos++; + }else{ + if( puntajeActual < ((objetivo*3)-2) && puntajeActual >= ((objetivo*3)-4) && puntajeActual>1){ + validoSorpresa++; + }else{ + if(puntajeActual>1){ + noValidoSorpresa++; + } + } + } + } + + //System.out.println(validos+""*""+validoSorpresa+""*""+noValidoSorpresa+""*-*""+numeroDeSorpresas); + + //sorpresasPorEncontrar = sorpresasPorEncontrar - noValidoSorpresa; + + if(validoSorpresa > numeroDeSorpresas && numeroDeSorpresas>=0){ + validoSorpresa = numeroDeSorpresas; + } + + resultado = validos + validoSorpresa; + + System.out.println(""Case #""+i+"": ""+resultado); + + } + } + + + public static void main(String[] args) throws FileNotFoundException, IOException{ + + File archivo = new File(""B-large.in""); + main m = new main(); + m.leerArchivo(archivo); + } + +} +" +A22768,"import static java.lang.Math.*; +import static java.util.Arrays.*; +import java.io.*; +import java.util.*; + +public class B { + Scanner sc = new Scanner(System.in); + + int N, S, p; + int[] ts; + + void read() { + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + ts = new int[N]; + for (int i = 0; i < N; i++) ts[i] = sc.nextInt(); + } + + void solve() { + int res = 0; + for (int i = 0; i < N; i++) { + if (p * 3 - 2 <= ts[i]) res++; + else if (p <= ts[i] && p * 3 - 4 <= ts[i] && S-- > 0) res++; + } + System.out.println(res); + } + + void run() { + int caseN = sc.nextInt(); + for (int caseID = 1; caseID <= caseN; caseID++) { + read(); + System.out.printf(""Case #%d: "", caseID); + solve(); + System.out.flush(); + } + } + + void debug(Object...os) { + System.err.println(deepToString(os)); + } + + public static void main(String[] args) { + try { + System.setIn(new BufferedInputStream(new FileInputStream(args.length > 0 ? args[0] : (B.class.getName() + "".in"")))); + } catch (Exception e) { + } + new B().run(); + } +} +" +A20647,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; +import java.util.StringTokenizer; + + +public class ProblemBDancingWithTheGooglers { + + private static int lines; + private static Scanner input; + private static String [] outputs; + + public static void main(String[] args) { + try { + input = new Scanner(new FileReader(args[0])); + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.exit(-1); + } + lines = Integer.parseInt(input.nextLine()); + outputs = new String [lines]; + for(int i = 1; i<=lines; i++) + { + int maxVal; + int num; + int supriseCase; + int iAns = 0; + String ans = ""Case #"" + i + "": ""; + StringTokenizer str = new StringTokenizer(input.nextLine()); + num = Integer.parseInt(str.nextToken()); + supriseCase = Integer.parseInt(str.nextToken()); + maxVal = Integer.parseInt(str.nextToken()); + for(int j = 0; j=maxVal) + { + iAns++; + } + else if(supriseCase>0 && (t.highest() + 1)>= maxVal && t.highest() != t.sum && t.canBeSuprise()) + { + supriseCase--; + iAns++; + } + + } + ans += iAns; + outputs[i-1] = ans; + + } + try{ + + File file =new File(""outputB.txt""); + + //if file doesnt exists, then create it + if(!file.exists()){ + file.createNewFile(); + } + + FileWriter fw = new FileWriter(file.getName()); + BufferedWriter bw = new BufferedWriter(fw); + for(int k = 0; kz); + } + public static boolean allEqual() + { + return (x==y && x==z); + } + public static int highest() + { + if(x>=y) + { + if (x>=z) + { + return x; + } + else + { + return z; + } + } + else + { + if(y>=z) + { + return y; + } + else + { + return z; + } + } + } + } + +} +" +A20407,"package MyAllgoritmicLib; + +public class BinaryPower { + public static int binpow (int a, int n) + { + int r = 1; + while (n > 0) + if (n % 2 == 0) + { + a *= a; + n /= 2; + } + else + { + r *= a; + --n; + } + return r; + } + + public static long binpow (long a, int n) + { + long r = 1; + while (n > 0) + if (n % 2 == 0) + { + a *= a; + n /= 2; + } + else + { + r *= a; + --n; + } + return r; + } + + public static double binpow (double a, int n) + { + double r = 1; + while (n > 0) + if (n % 2 == 0) + { + a *= a; + n /= 2; + } + else + { + r *= a; + --n; + } + return r; + } +} +" +A22487,"package qualification; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + public static void main(String[] Args) throws IOException { + Scanner sc = new Scanner(new FileReader(""B-small.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""output.txt"")); + + int caseCnt = sc.nextInt(); + System.out.println(caseCnt); + for (int caseNum=1; caseNum <= caseCnt; caseNum++) { + System.out.println(caseNum); + int N=sc.nextInt(); + int S=sc.nextInt(); + int p=sc.nextInt(); + int[] score = new int[N]; + int total=0; + for(int i=0;i=3*p-2) { + total++; + } else if(score[i]>=3*p-4 && S>0 && score[i]>=p) { + total++; + S--; + } + } + pw.println(""Case #"" + caseNum + "": "" + total); + } + + pw.flush(); + pw.close(); + sc.close(); + } + +} +" +A20307,"import java.io.PrintStream; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws Exception { + System.setOut(new PrintStream(""out"")); + + Scanner s = new Scanner(System.in); + int T = s.nextInt(); + for (int t = 1; t <= T; t++) { + int N = s.nextInt(); + int S = s.nextInt(); + int P = s.nextInt(); + + int[][] matrix = { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, -1 }, { 0, -1, 0 }, { 0, -1, -1 }, { 1, 0, 0 }, { 1, 0, 1 }, + { 1, 1, 0 }, { 1, 1, 1 }, { -1, 0, 0 }, { -1, 0, -1 }, { -1, -1, 0 }, { -1, -1, -1 } }; + + int[][] matrix2 = { { 1, 1, -1 }, { 1, -1, 0 }, { 1, -1, 1 }, { 1, -1, -1 }, { 1, 0, -1 }, { 1, 1, -1 }, { 1, -1, 0 }, { 1, -1, 1 }, { 1, -1, -1 }, + { 1, 0, -1 }, { 1, 1, -1 }, { 1, -1, 0 }, { 1, -1, 1 }, { 1, -1, -1 } }; + + int max = 0; + + for (int n = 0; n < N; n++) { + int x = s.nextInt(); + + boolean ok = false; + int m = x / 3; + for (int i = 0; i < matrix.length; i++) { + int a = m + matrix[i][0]; + int b = m + matrix[i][1]; + int c = m + matrix[i][2]; + + if (a == 7 && b == 6 && c == 9) + continue; + + if (a + b + c == x && a >= 0 && b >= 0 && c >= 0 && a <= 10 && b <= 10 && c <= 10) { + if (Math.max(a, Math.max(b, c)) >= P) { + max++; + ok = true; + break; + } + } + } + + if (ok == false) { + m = x / 3 + 1; + for (int i = 0; i < matrix.length; i++) { + int a = m + matrix[i][0]; + int b = m + matrix[i][1]; + int c = m + matrix[i][2]; + + if (a == 7 && b == 6 && c == 9) + continue; + + if (a + b + c == x && a >= 0 && b >= 0 && c >= 0 && a <= 10 && b <= 10 && c <= 10) { + if (Math.max(a, Math.max(b, c)) >= P) { + max++; + ok = true; + break; + } + } + } + } + + if (ok == false) { + m = x / 3 - 1; + for (int i = 0; i < matrix.length; i++) { + int a = m + matrix[i][0]; + int b = m + matrix[i][1]; + int c = m + matrix[i][2]; + + if (a == 7 && b == 6 && c == 9) + continue; + + if (a + b + c == x && a >= 0 && b >= 0 && c >= 0 && a <= 10 && b <= 10 && c <= 10) { + if (Math.max(a, Math.max(b, c)) >= P) { + max++; + ok = true; + break; + } + } + } + } + + if (ok == false && S > 0) { + m = x / 3; + for (int i = 0; i < matrix2.length; i++) { + int a = m + matrix2[i][0]; + int b = m + matrix2[i][1]; + int c = m + matrix2[i][2]; + + if (a == 7 && b == 6 && c == 9) + continue; + + if (a + b + c == x && a >= 0 && b >= 0 && c >= 0 && a <= 10 && b <= 10 && c <= 10) { + if (Math.max(a, Math.max(b, c)) >= P) { + max++; + S--; + ok = true; + break; + } + } + } + } + + if (ok == false && S > 0) { + m = x / 3 + 1; + for (int i = 0; i < matrix2.length; i++) { + int a = m + matrix2[i][0]; + int b = m + matrix2[i][1]; + int c = m + matrix2[i][2]; + + if (a == 7 && b == 6 && c == 9) + continue; + + if (a + b + c == x && a >= 0 && b >= 0 && c >= 0 && a <= 10 && b <= 10 && c <= 10) { + if (Math.max(a, Math.max(b, c)) >= P) { + max++; + S--; + ok = true; + break; + } + } + } + } + if (ok == false && S > 0) { + m = x / 3 - 1; + for (int i = 0; i < matrix2.length; i++) { + int a = m + matrix2[i][0]; + int b = m + matrix2[i][1]; + int c = m + matrix2[i][2]; + + if (a == 7 && b == 6 && c == 9) + continue; + + if (a + b + c == x && a >= 0 && b >= 0 && c >= 0 && a <= 10 && b <= 10 && c <= 10) { + if (Math.max(a, Math.max(b, c)) >= P) { + max++; + S--; + ok = true; + break; + } + } + } + } + } + + System.out.println(""Case #"" + t + "": "" + max); + } + + } +} +" +A21056,"import java.io.*; +import java.util.*; + +public class ProblemB { + + + + /* + * Takes an input file and output file as inputs. + */ + public static void main(String file[]) throws IOException{ + + BufferedReader in; + BufferedWriter out; + int numCases, numGooglers, numSurp, p, score; + Integer result; + + + // Open the file and create a reader + in = new BufferedReader(new FileReader(file[0])); + + // Create an output file and a writer + out = new BufferedWriter(new FileWriter(file[1])); + + numCases = Integer.parseInt(in.readLine()); + + // for each case + for (int i = 0; i < numCases; i++) { + out.write(""Case #"" + (i+1) + "": ""); + + // prepare variables + String line = in.readLine(); + String[] numbers = line.split("" ""); + numGooglers = Integer.parseInt(numbers[0]); + numSurp = Integer.parseInt(numbers[1]); + p = Integer.parseInt(numbers[2]); + result = 0; + for (int j = 0; j < numGooglers; j++) { + score = Integer.parseInt(numbers[j+3]); + + // first check if it could give p without being surprising + if (score >= 3*p-2) { + result++; + if (score < p) + result--; + } + // otherwise see if it could give p being a surprise and + // also if we even have any suprises left + else if (numSurp > 0 && score >= 3*p-4) { + result++; + numSurp--; + if (score < p) { + result--; + numSurp++; + } + } + } + out.write(result.toString()); + out.newLine(); + } + in.close(); + out.close(); + } +} + + " +A22013,"import java.io.*; +import java.util.*; +import java.math.*; + +public class B { + public static void main(String[] args) throws IOException { + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(""B-large.in"")); + BufferedReader br = new BufferedReader(new InputStreamReader(bis)); + PrintWriter out = new PrintWriter(""B-large.out""); + int cases = Integer.parseInt(br.readLine().trim()); + StringTokenizer st; + for (int c = 1; c <= cases; c++) { + st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int res = 0; + for (int i = 0; i < N; i++) { + int curr = Integer.parseInt(st.nextToken()); + int currBest = curr/3+Math.min(curr%3, 1); + int curSurBest = curr/3+Math.max(1, curr%3); + if(curr == 0) + res += p>0?0:1; + else if(currBest >= p) + res++; + else if(s > 0 && curSurBest >= p) { + res++; + s--; + } + } + out.println(""Case #"" + c + "": "" + res); + } + out.close(); + } +}" +A22724,"import java.util.*; +import java.io.*; +import static java.lang.Math.*; + +public class B{ + public static void main(String[] args) throws Exception{ + new B().run(); + } + + void run() throws Exception{ + Scanner sc = new Scanner(System.in); + //BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); + // only sc.readLine() is available + int T = sc.nextInt(); + for(int o = 1; o <= T; o++){ + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int ans = 0; + for(; n > 0; n--){ + int t = sc.nextInt(); + if(t >= p*3){ + ans++; + continue; + } + int d = t / 3; + if(t%3>0)d++; + if(d >= p){ + ans++; + }else if(s > 0){ + boolean ok = false; + loop: + for(int i = 0; i <= t; i++) + for(int j = i; j <= t; j++) + for(int k = j; k <= t; k++) + if(i+j+k==t){ + int mn = min(i, min(j, k)); + int mx = max(i, max(j, k)); + if(mx >= p && mx - mn <= 2){ + ok = true; + break loop; + } + } + if(ok){ + ans++; + s--; + } + } + } + System.out.printf(""Case #%d: %d\n"", o, ans); + } + } +} +" +A22163,"import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + +public class DancingWithTheGooglers { + private static final boolean DEBUG = false; + private static final String FILENAME = ""dancing""; + + public static void main(String[] args) throws IOException { + long startTime = System.nanoTime(); + + if(DEBUG) { + System.setIn(new BufferedInputStream(new FileInputStream(FILENAME + ""_example.in""))); + } else { + System.setIn(new BufferedInputStream(new FileInputStream(FILENAME + "".in""))); + System.setOut(new PrintStream(FILENAME + "".out"")); + } + + Scanner sc = new Scanner(System.in); + + int numTestCases = sc.nextInt(); + for(int caseNum = 1; caseNum <= numTestCases; caseNum++) { + int numGooglers = sc.nextInt(); + int numSurprising = sc.nextInt(); + int scoreMaxLowerBound = sc.nextInt(); + + int numGooglersWithBetter = 0; + + for(int i = 0; i < numGooglers; i++) { + int totalScore = sc.nextInt(); + + if(totalScore <= 1) { + if(totalScore >= scoreMaxLowerBound) { + numGooglersWithBetter++; + } + } else { + int maxScore; + if(totalScore % 3 == 0) { + maxScore = totalScore / 3; + } else { + maxScore = totalScore / 3 + 1; + } + + if(maxScore >= scoreMaxLowerBound) { + numGooglersWithBetter++; + } else if(numSurprising > 0) { + maxScore++; + + if(maxScore >= scoreMaxLowerBound) { + numGooglersWithBetter++; + numSurprising--; + } + } + } + } + + System.out.println(""Case #"" + caseNum + "": "" + numGooglersWithBetter); + } + + if(DEBUG) System.out.println(""Total time: "" + ((System.nanoTime() - startTime) / 1000.0 / 1000.0 / 1000.0) + ""s""); + } +}" +A20239,"package B; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + + /* Input File */ + BufferedReader reader = new BufferedReader(new FileReader(""G:/projects/CodeJam12/src/B/in.txt"")); + + /* Output File */ + PrintWriter writer = new PrintWriter(new FileWriter(""G:/projects/CodeJam12/src/B/out.txt"")); + + /* Getting number of test cases */ + int noOfTestCases = Integer.parseInt(reader.readLine()); + System.out.println(""No of Test Cases : ""+noOfTestCases); + + /* Iterating for every test case */ + for ( int i=1; i <= noOfTestCases;i++){ + + /* Getting input test case line */ + String ipline = reader.readLine(); + System.out.println(""\n\nTest Case ""+i+"" : ""+ipline); + + /* Split the test case string */ + String elements []= ipline.split("" ""); + int iElements [] = new int[elements.length]; + + /* Parsing elements to integer */ + for ( int j=0; j= bestResultP ) { + maxGooglersWithBestResultP++; + + // Check for surprising triplet + }else if ( noOfSuprisingTriplets > 0 + && (iElements[j] % 3 ) != 1 + && (avgCeilMarks + 1) <= iElements[j] + && (avgCeilMarks + 1) >= bestResultP ){ + + maxGooglersWithBestResultP++; + noOfSuprisingTriplets --; + } + } + + System.out.println(""No of Surprising Triplets Left ( In-effective Surprising Triplets ) : ""+noOfSuprisingTriplets); + + /* print output */ + System.out.println(""Case #""+i+"": ""+maxGooglersWithBestResultP); + writer.println(""Case #""+i+"": ""+maxGooglersWithBestResultP); + } + + /* closing streams */ + System.out.println(""\n\nClosing streams...""); + writer.close(); + reader.close(); + System.out.println(""Streams closed.""); + } +} +" +A20163,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +public class CodeJam { + public static void main(String a[]){ + try { + FileReader f = new FileReader(""B-large.in""); + BufferedReader in = new BufferedReader(f); + FileWriter fwrite = new FileWriter(""output""); + BufferedWriter out = new BufferedWriter(fwrite); + int n = Integer.parseInt(in.readLine().toString()); + int i = 0; + int j=0; + int numOfGooglers = 0; + int numOfSurprise = 0; + int bestResult = 0; + String line = null; + int[] sums = new int[100]; + triplet [] goo = new triplet[100]; + int surpDone=0; + boolean curSurp = false; + int count = 0; + while(i=2 && surpDone < numOfSurprise){ + if(test(setScore(sums[j],false,bestResult), bestResult)==true) + curSurp = false; + else if(test(setScore(sums[j], true, bestResult),bestResult)==true){ + surpDone+=1; + curSurp = true; + } + else if(test(setScore(sums[j], true, bestResult),bestResult)==false){ + curSurp = false; + } + else { + curSurp = true; + +// System.out.print(""here""); + surpDone++;} + } + goo[j] = setScore(sums[j], curSurp,bestResult); + if(goo[j].one >= bestResult || goo[j].two >= bestResult|| goo[j].three >= bestResult) + count++; +// System.out.print(sums[j]+"" ""+goo[j].one+"" ""+goo[j].two+"" ""+goo[j].three+"" ""+goo[j].surprise+"" ""); + j++; + } + +// System.out.println(count); + out.write(String.valueOf(count)); + out.newLine(); + i++; + } + in.close(); + out.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + public static boolean test(triplet t,int best){ + if(t.one>=best||t.two>=best||t.three>=best){ +// System.out.print(""positive""); + return true; + } +// System.out.print(""negative""); + return false; + + } + public static triplet setScore(int sum, boolean surp, int best){ + triplet score = new triplet(); + int a,b,c; + + int div = sum/3; + int mod = sum%3; + a=b=c=div; + if(mod==1){ + if(surp ==false) + a=a+1; + else{ + a=a+1 ; + b=b+1; + c=c-1; + if(a>=best||b>=best||c>=best){ + score.flag=true; +// System.out.println(""here""+a+b+c+best); + } + + } + }else if(mod==2){ + if(surp ==false ){ + a=a+1; + b=b+1; + } + else{ + a=a+2; + if(a>=best||b>=best||c>=best){ + score.flag=true; +// System.out.println(""here""); + } + + } + }else { + if(surp==true){ + a=a+1; + b=b-1; + if(a>=best||b>=best||c>=best){ + score.flag=true; +// System.out.println(""here""); + } + } + } + score.one=a; + score.two=b; + score.three=c; + score.surprise=surp; + return score; + + } +}" +A21845,"package dancingWithGooglers; + +import java.util.ArrayList; + +public class MainClass +{ + public static void main(String[] z)throws Exception + { + String string =""""; + ArrayList list = new InputFile().readFile(); + int caseNumber =1; + ArrayList output = new ArrayList(); + for(int i=0 ;i 0) && (p + 2 * Math.max(p-2, 0) <= k)) { + s--; + nr++; + } + } + + ps.println(nr); + } + + + public void run(String[] args) throws FileNotFoundException { + sc = new Scanner(new File(""B.in"")); + ps = System.out; // new PrintWriter(""B.out""); + int num_tests = sc.nextInt(); + sc.nextLine(); + + for (int test=1; test<=num_tests; test++) { + ps.print(""Case #""+test+"": ""); + + solve(); + + } + ps.close(); + + } + + public static void main(String[] args) throws FileNotFoundException { + B a = new B(); + a.run(args); + } +} +" +A22396,"package gdwg; + +import java.io.*; + +/** + * + * @author alexho + */ +public class GDWG { + + private static int [] result; + + + private void readInput (String infn) throws FileNotFoundException, IOException { + String line = null; + int testCases = 0; + BufferedReader bufRdr = null; + String delimiter = "" ""; + File file = new File(infn); + bufRdr = new BufferedReader(new FileReader(file)); + + testCases = Integer.valueOf(bufRdr.readLine()); + GDWG.result = new int [testCases]; + + int index=0; + + while ( (line = bufRdr.readLine()) != null ) { + + String [] temp; + temp = line.split(delimiter); + this.computeMax(temp, index); + index++; + + } + bufRdr.close(); + + + } + + private void output (String outfn) throws IOException { + PrintWriter out = new PrintWriter(new FileWriter(outfn)); + for (int i=0;i Nti) { + // do nothing + } else if (Nti/3 >= p) { + max++; + } else if (p - Nti/3 <=2 && p - Nti/3 > 0 ) { + if ( 3*p == Nti) { + max++; + } else if (3*p+1 == Nti) { + max++; + } else if (3*p-1 == Nti) { + max++; + } else if (3*p-2 == Nti) { + max++; + } else if (3*p+2 == Nti) { + max++; + } else if (3*p-3 == Nti && S > 0) { + S--; + max++; + } else if (3*p+3 == Nti && S > 0) { + S--; + max++; + } else if (3*p-4 == Nti && S > 0) { + S--; + max++; + } else if (3*p+4 == Nti && S > 0) { + S--; + max++; + } + + } else { + + } + + + + } + GDWG.result[index]=max; + } + + public GDWG () { + + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + + String infn = args[0]; + String outfn = args[1]; + GDWG gdwg = new GDWG(); + gdwg.readInput(infn); + gdwg.output(outfn); + for (int i=0;i= 0; i--) { + int a = v[i]; + /*0 <= k <= 2 + x + x + 2 + x + k = a + 3x + 2 + k = a + 3x + k = a - 2 + a - 3 + x + 2 >= best*/ + if ((a + 2) / 3 >= best) { + count++; + // out.println(""A: "" + a); + } else if (surp > 0 && a >= 2 && (a - 2) / 3 + 2 >= best) { + // out.println(""B: "" + a); + count++; + surp--; + } + } + out.println(""Case #"" + cas + "": "" + count); + } + } +} +" +A21139,"import java.io.*; +import java.util.*; + +public class B { + + public static void main(String[] args) { + new B().run(); + } + + BufferedReader br; + StringTokenizer st; + PrintWriter out; + boolean eof = false; + Random rand = new Random(1235446); + + private void run() { + try { + br = new BufferedReader(new FileReader(FNAME + "".in"")); + out = new PrintWriter(FNAME + "".out""); + solve(); + out.close(); + } catch (Throwable e) { + e.printStackTrace(); + System.exit(566); + } + } + + String nextToken() { + while (st == null || !st.hasMoreTokens()) { + try { + st = new StringTokenizer(br.readLine()); + } catch (Exception e) { + eof = true; + return ""0""; + } + } + return st.nextToken(); + } + + int nextInt() { + return Integer.parseInt(nextToken()); + } + + long nextLong() { + return Long.parseLong(nextToken()); + } + + double nextDouble() { + return Double.parseDouble(nextToken()); + } + + String FNAME = ""b""; + + private void solve() throws IOException { + int tests = nextInt(); + for (int test = 1; test <= tests; test++) { + out.print(""Case #"" + test + "": ""); + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] a = new int[n]; + for (int i = 0; i < a.length; i++) { + a[i] = nextInt(); + } + int good = 0; + int almost = 0; + int b1 = p + 2 * Math.max(p - 1, 0); + int b2 = p + 2 * Math.max(p - 2, 0); + for (int i = 0; i < a.length; i++) { + if (a[i] >= b1) { + good++; + } else if (a[i] >= b2) { + almost++; + } + } + int ans = good + Math.min(almost, s); + out.println(ans); + } + } + +} +" +A20971,"package dancing; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class Main { + + public static void main(String[] args) throws IOException { + File file = new File(""B-large.in""); + FileReader fr = new FileReader(file); + BufferedReader in = new BufferedReader(fr); + + String line = in.readLine(); + String[] tokens; + int num = Integer.parseInt(line); + int i = 1, N, s, p, t, minAlways, minSurprising, always, surprising, finalCount; + while (i <= num) { + line = in.readLine(); + tokens = line.split("" ""); + N = Integer.parseInt(tokens[0]); + s = Integer.parseInt(tokens[1]); + p = Integer.parseInt(tokens[2]); + if (p >= 2) { + minAlways = 3 * p - 2; + minSurprising = 3 * p - 4; + } else { + minAlways = p; + minSurprising = 1; + } + + always = 0; + surprising = 0; + + for (int j = 0; j < N; j++) { + t = Integer.parseInt(tokens[3 + j]); + if (t >= minAlways) { + always++; + } else if (t >= minSurprising) { + surprising++; + } + } + + finalCount = always + Math.min(s, surprising); + + System.out.println(""Case #"" + i + "": "" + finalCount); + i++; + } + } + +} +" +A20673,"package com.google.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + + + bestScoresFinder(args[0]); + +// System.out.println(""No of Max. Scorers "" + noOfMaxScorers(""2 0 5 12 19"")); +// System.out.println(""No of Max. Scorers "" + noOfMaxScorers(""3 0 8 23 22 21"")); +// System.out.println(""No of Max. Scorers "" + noOfMaxScorers(""2 1 1 8 0"")); +// System.out.println(""No of Max. Scorers "" + noOfMaxScorers(""6 2 8 29 20 8 18 18 21"")); + } + + private static void bestScoresFinder(String fileName) { + File f = new File(fileName); + BufferedReader fin; + try { + fin = new BufferedReader(new InputStreamReader(new FileInputStream(f))); + + int noOfInputs = Integer.valueOf(fin.readLine()); + String[] inputs = readSamplesFromFile(noOfInputs, fin); + + BufferedWriter fout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(""/Users/asachwani/Desktop/CodeJam/Output.txt""))); + + for (int i = 0; i < noOfInputs; i++) { + System.out.println(i + 1 + "" ------- "" + inputs[i]); + fout.write(""Case #"" + (i + 1) + "": "" + noOfMaxScorers(inputs[i]) + ""\n""); + } + + fout.flush(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NumberFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private static int noOfMaxScorers(String input) { + String[] data = input.split("" ""); + int noOfContestants = Integer.valueOf(data[0]); + int noOfSurprises = Integer.valueOf(data[1]); + int maxScore = Integer.valueOf(data[2]); + int noOfMaxScorers = 0; + System.out.println(""No. of Surprises: "" + noOfSurprises); + + for (int i = 3; i < data.length; i++) { + int score = Integer.valueOf(data[i]); + int minScore = score / 3; + if (minScore >= maxScore) { + noOfMaxScorers++; + continue; + } else + + if (score <= maxScore) { + continue; + } + + boolean found = false; + boolean surprise = false; + + for (int x = -2; x < 3; x++) { + for (int y = -2; y <= x; y++) { + if (((minScore * 3) + x + y) == score) { + + if (Math.abs(x) + Math.abs(y) > 2) { + break; + } + + if ((minScore + x) >= maxScore) { + System.out.println(score + "" "" + minScore + "" "" + (minScore + x) + "" "" + (minScore + y) + "" "" + x + "" "" + y); + found = true; + surprise = false; + + if (2 - (x - y) <= 0) { + System.out.println(""X matched Surprise""); + surprise = true; + } else { + noOfMaxScorers++; + System.out.println(""X matched""); + break; + } + + } else if ((minScore + y) >= maxScore) { + System.out.println(score + "" "" + minScore + "" "" + (minScore + x) + "" "" + (minScore + y) + "" "" + x + "" "" + y); + found = true; + + surprise = false; + + if (x - y <= 0) { + System.out.println(""Y matched Surprise""); + surprise = true; + } else { + noOfMaxScorers++; + System.out.println(""Y matched""); + break; + } + } + } + + } + + if (surprise && noOfSurprises > 0) { + noOfMaxScorers++; + noOfSurprises--; + break; + } + + if (found) { + + break; + } + } + System.out.println(""No. of Surprises: "" + noOfSurprises); + System.out.println(""No of Max. Scorers "" + noOfMaxScorers); + System.out.println(); + + } + return noOfMaxScorers; + } + + private static String[] readSamplesFromFile(int noOfInputs, BufferedReader fin) throws IOException { + String[] samples = new String[noOfInputs]; + + for (int i = 0; i < noOfInputs; i++) { + samples[i] = fin.readLine(); + } + + return samples; + } + +} +" +A20547,"import java.util.Scanner; + +public class Dancing { + private static Scanner stdIn = new Scanner(System.in); + + public static void getMax(int arr[]) + { + for (int i = 0; i < arr.length; i++) + { + int t = arr[i]; + if ((t % 3) == 0) + { + arr[i] = t / 3; + } else + { + arr[i] = (t / 3) + 1; + } + } + } + + public static int howMany(int scores[], int surprising, int p) + { + int total = 0; + + getMax(scores); + + for (int i = 0; i < scores.length; i++) + { + int t = scores[i]; + + if (t >= p) + { + total++; + } else if ((surprising > 0) && (t == (p - 1)) && (t > 0)) + { + total++; + surprising--; + } + } + + return total; + } + + public static void main(String args[]) + { + int T; // number of test cases + int caseNo = 1; // number of current case + + // scan number of test cases + T = stdIn.nextInt(); + + // while there's cases to process + while (T-- != 0) + { + // case variables + int N, S, p; + int scores[]; // array to hold scores + + // read variables + N = stdIn.nextInt(); + S = stdIn.nextInt(); + p = stdIn.nextInt(); + scores = new int[N]; + + // read scores + for (int i = 0; i < N; i++) + { + scores[i] = stdIn.nextInt(); + } + + // print results + System.out.println(""Case #"" + caseNo++ + "": "" + howMany(scores, S, p)); + } + } +} +" +A22174,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +//1 +//3 1 5 15 13 11 +// +public class DancingWiththeGooglersCodeJam2012Q { + + public int solves(int N,int S,int P,int scores[]){ + int i = 0 ; + int sol = 0 ; + Arrays.sort(scores); + int TT = scores.length ; + for ( i = 0 ; i < TT ;i++){ + if ( scores[i] = P){ + for ( int j = 0 ; j <=10 ;j++){ + for (int k = 0 ; k <=10 ;k++){ + for (int l = 0 ; l <=10;l++){ + if( l+j+k != scores[i] ) continue; + + if( l+j+k == scores[i] && + ( Math.abs(j-k) < 2 && Math.abs(k-l) < 2 && Math.abs(l-j) < 2 ) && + ( l >= P || j >= P || k >= P ) + + ){ + //System.out.println(j + "" "" + k + "" "" + l + "" "" + scores[i] + "" "" + sol ); + scores[i]= -1 ; + ++sol; + } + } + } + } + } + } + for ( i = 0 ; i < TT && S>0 ;i++){ + if ( scores[i] !=-1 && scores[i]>= P){ + for ( int j = 0 ; j <=10 ;j++){ + for (int k = 0 ; k <=10 ;k++){ + for (int l = 0 ; l <=10;l++){ + if( l+j+k != scores[i] ) continue; + if( l+j+k == scores[i] && ( + ( Math.abs(j-k) ==2 && Math.abs(k-l) <= 2 && Math.abs(l-j) <=2 ) || + ( Math.abs(j-k) <=2 && Math.abs(k-l) == 2 && Math.abs(l-j) <=2 ) || + ( Math.abs(j-k) <=2 && Math.abs(k-l) <= 2 && Math.abs(l-j) ==2 ) ) && + ( l >= P || j >= P || k >= P ) + + ){ + //System.out.println("" FF"" + j + "" "" + k + "" "" + l + "" "" + scores[i] + "" "" + sol ); + scores[i]= -1 ; + --S; + ++sol; + } + } + } + } + } + } + + //System.out.println("" sol3 : "" + sol); + return sol; + + } + + public static void main(String[] args) throws IOException { + DancingWiththeGooglersCodeJam2012Q si = new DancingWiththeGooglersCodeJam2012Q(); + + int T ; + String CurLine = """"; + + InputStreamReader converter = new InputStreamReader(System.in); + BufferedReader in = new BufferedReader(converter); + CurLine = in.readLine(); + T= Integer.parseInt(CurLine); + String s[] = new String[T]; + for(int i = 0 ; i < T;i++) { + CurLine = in.readLine(); + + String []input = CurLine.split("" ""); + + + int N = Integer.parseInt(input[0]); + int S = Integer.parseInt(input[1]); + int P = Integer.parseInt(input[2]); + int scores[] = new int [N]; + for( int j = 0 ; j < N;j++){ + scores[j] = Integer.parseInt(input[j+3]); + + } + System.out.println(""Case #""+ (i+1)+"": ""+si.solves(N,S,P,scores)); + + } + } +} +" +A21387,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class DanceScores { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + BufferedReader f = new BufferedReader(new FileReader(""test.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""dance.out""))); + + int numberCases = Integer.parseInt(f.readLine()); + String log; + StringTokenizer st; + int dancers; + int bestResult; + int surprisingTriples; + int triplesThatSatisfy; + + for (int i = 1; i <= numberCases; i++) + { + log = ""Case #"" + i + "": ""; + st = new StringTokenizer(f.readLine()); + + dancers = Integer.parseInt(st.nextToken()); + surprisingTriples = Integer.parseInt(st.nextToken()); + bestResult = Integer.parseInt(st.nextToken());; + + triplesThatSatisfy = calculateNumTriples(dancers, surprisingTriples, bestResult, st); + + log += triplesThatSatisfy; + out.println(log); + } + + out.close(); + System.exit(0); + } + + private static int calculateNumTriples(int dan, int sur, int bes, StringTokenizer st) + { + int result = 0; + int surprising = sur; + int total; + + //deal with p = 0 and p = 1, as these cases are special + if (bes == 0) + { + return dan; + } + else if (bes == 1) + { + while (st.hasMoreTokens()) + { + if ((Integer.parseInt(st.nextToken())) != 0) + { + result++; + } + } + + return result; + } + else + { + while (st.hasMoreTokens()) + { + total = Integer.parseInt(st.nextToken()); + + if (total >= 3*bes - 2) + { + result++; + } + else if ((3*bes - 4 <= total) && + (total <= 3*bes - 3)) + { + if (surprising > 0) + { + surprising--; + result++; + } + } + } + + return result; + } + } + +} +" +A20042,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +public class GoogleDancers { + static BufferedWriter bw = null; + static long time = System.currentTimeMillis(); + + public static void main(String[] args) throws Exception { + try { + Scanner sc = new Scanner(new File(""B-large.in"")); + bw = new BufferedWriter(new FileWriter(""output.txt"")); + long totalCases = sc.nextLong(); + for (int i = 1; i <= totalCases; i++) { + long numContestants = sc.nextLong(); + long numSurprises = sc.nextLong(); + long maxScore = sc.nextLong(); + long minSurpriseTotalScore = maxScore + getMinimumScore(maxScore, 2) + getMinimumScore(maxScore, 2); + long minTotalScore = maxScore + getMinimumScore(maxScore, 1) + getMinimumScore(maxScore, 1); + long qualifiers = 0; + for (int j = 0; j < numContestants; j++) { + long nextScore = sc.nextLong(); + if ((nextScore >= minTotalScore)) { + qualifiers++; + } else if (((nextScore < minTotalScore) && ((nextScore >= minSurpriseTotalScore) && (numSurprises > 0)))) { + qualifiers++; + numSurprises--; + } + } + bw.append(""Case #"" + i + "": ""); + bw.append(String.valueOf(qualifiers)); + bw.append(""\n""); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + + bw.flush(); + bw.close(); + System.out.println((System.currentTimeMillis() - time) / 1000); + } + + } + + private static long getMinimumScore(long maxScore, long subtract) { + return (maxScore - subtract) < 0 ? 0 : (maxScore - subtract); + } + +} +" +A20492,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; + + +public class Second { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + FileReader fr; + try + { + fr = new FileReader(""B-large.in""); + FileWriter f1 = new FileWriter(""B-large.out""); + + BufferedReader br = new BufferedReader(fr); + + int i=1; + String s; + StringBuffer strbuf = new StringBuffer(); + + br.readLine(); + while((s = br.readLine())!=null) + { + int count=0; + strbuf.delete(0, strbuf.length()); + StringTokenizer st = new StringTokenizer(s,"" ""); + + int no = Integer.parseInt(st.nextToken()); + int buf = Integer.parseInt(st.nextToken()); + int max = Integer.parseInt(st.nextToken()); + + System.out.println(no+"" ""+buf+"" ""+max); + + + for(int j=0;j=max) + { + if(cur >= ((max*3)-2)) + { + count++; + continue; + }else if((cur+4 >= (max*3)) && buf>0) + { + buf--; + count++; + } + } + + + } + + strbuf.insert(0, ""Case #""+i+"": ""+count+""\n""); + i++; + + char[] buffer = new char[strbuf.length()]; + s = strbuf.toString(); + System.out.println(s); + s.getChars(0, s.length(), buffer, 0); + + f1.write(buffer); + } + f1.close(); + fr.close(); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} +" +A21932,"package jp.funnything.competition.util; + +import java.math.BigDecimal; + +/** + * Utility for BigDeciaml + */ +public class BD { + public static BigDecimal ZERO = BigDecimal.ZERO; + public static BigDecimal ONE = BigDecimal.ONE; + + public static BigDecimal add( final BigDecimal x , final BigDecimal y ) { + return x.add( y ); + } + + public static BigDecimal add( final BigDecimal x , final double y ) { + return add( x , v( y ) ); + } + + public static BigDecimal add( final double x , final BigDecimal y ) { + return add( v( x ) , y ); + } + + public static int cmp( final BigDecimal x , final BigDecimal y ) { + return x.compareTo( y ); + } + + public static int cmp( final BigDecimal x , final double y ) { + return cmp( x , v( y ) ); + } + + public static int cmp( final double x , final BigDecimal y ) { + return cmp( v( x ) , y ); + } + + public static BigDecimal div( final BigDecimal x , final BigDecimal y ) { + return x.divide( y ); + } + + public static BigDecimal div( final BigDecimal x , final double y ) { + return div( x , v( y ) ); + } + + public static BigDecimal div( final double x , final BigDecimal y ) { + return div( v( x ) , y ); + } + + public static BigDecimal mul( final BigDecimal x , final BigDecimal y ) { + return x.multiply( y ); + } + + public static BigDecimal mul( final BigDecimal x , final double y ) { + return mul( x , v( y ) ); + } + + public static BigDecimal mul( final double x , final BigDecimal y ) { + return mul( v( x ) , y ); + } + + public static BigDecimal sub( final BigDecimal x , final BigDecimal y ) { + return x.subtract( y ); + } + + public static BigDecimal sub( final BigDecimal x , final double y ) { + return sub( x , v( y ) ); + } + + public static BigDecimal sub( final double x , final BigDecimal y ) { + return sub( v( x ) , y ); + } + + public static BigDecimal v( final double value ) { + return BigDecimal.valueOf( value ); + } +} +" +A21529,"package quals; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(reader.readLine()); + for (int i=1; i<=T; i++) { + String line = reader.readLine(); + StringTokenizer tok = new StringTokenizer(line); + int N = Integer.parseInt(tok.nextToken()); + int S = Integer.parseInt(tok.nextToken()); + int p = Integer.parseInt(tok.nextToken()); + int most = 0; + while (tok.hasMoreTokens()) { + int sum = Integer.parseInt(tok.nextToken()); + if (sum >= p*3-2) most++; + else if (sum >= p*3-4 && S>0 && p>1) { + most++; + S--; + } + } + System.out.printf(""Case #%d: %d\n"", i, most); + } + } + +} +" +A21812,"package qualitfy; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class Test { + public static void main (String args[]) throws FileNotFoundException { + Scanner in = new Scanner(new File (""src//qualitfy/input.in"")); + int T = in.nextInt(); + for (int i = 0; i < T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int count = 0; + int n1=0,n2=0,n3=0; + for (int j = 0; j < N; j++) { + int no = in.nextInt(); + int div = no % 3; + n1 = n2 = n3 = no/3; + if (div==1) + n3 = n3 + 1; + if (div == 2) + n2 = n3 = n3 + 1; + + if (n3 >= p) + count++; + else if (S != 0 && no >= 2) { + if(n2 == n3) { + n3 = n3 + 1; + n2 = n2 - 1; + if (n3 >= p) { + count++; + S--; + } + } + } + } + + System.out.println(""Case #"" + (i + 1) + "": "" + count); + } + } + +}" +A20084,"package codeJam2012_Qualification; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithTheGooglers { + private String FILE_NAME = ""2012_QB_dancing_B-large""; + + private int solve(String input) { + Scanner sc = new Scanner(input); + + int googlers = sc.nextInt(); + int surprising = sc.nextInt(); + int best = sc.nextInt(); + + int ok = 0; + int surprises = 0; + + for (int i=0;i=best+Math.max(0, 2*(best-1))) + ok++; + else if (points>=best+Math.max(0,2*(best-2))) + surprises++; + } + } + + return ok+(Math.min(surprises,surprising)); + } + + public void run() throws IOException { + Scanner sc = new Scanner(new FileReader(FILE_NAME+"".in"")); + PrintWriter pw = new PrintWriter(new FileWriter(FILE_NAME+"".out"")); + + int cases = Integer.valueOf(sc.nextLine()); + for (int i=1;i<=cases;i++) { + String input = sc.nextLine(); + System.out.println(""Input #""+i+"": ""+input); + + String output = ""Case #""+i+"": ""+solve(input); + pw.println(output); + System.out.println(output); + } + + pw.flush(); + pw.close(); + sc.close(); + } + public static void main(String[] args) throws IOException { + new DancingWithTheGooglers().run(); + } +} +" +A21567,"package exercicio.b; + +import java.awt.List; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class ExerciocioB { + + public static void main(String args[]) throws IOException { + + int[][] combinacoes = new int[1331][3]; + + for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= 10; j++) { + for (int k = 0; k <= 10; k++) { + combinacoes[i * 121 + j * 11 + k][0] = i; + combinacoes[i * 121 + j * 11 + k][1] = j; + combinacoes[i * 121 + j * 11 + k][2] = k; + } + } + } + + File fileInput = new File(""src/exercicio/b/input.txt""); + + FileReader fileReaderInput = new FileReader(fileInput); + + BufferedReader leitorInput = new BufferedReader(fileReaderInput); + + String numeroLinhas = leitorInput.readLine(); + Integer numero = new Integer(numeroLinhas); + + String linhaInput = null; + for (int j = 0; j < numero; j++) { + linhaInput = leitorInput.readLine(); + String[] linha = linhaInput.split("" ""); + + Integer numeroGoo = new Integer(linha[0]); + Integer numeroSurp = new Integer(linha[1]); + Integer minScore = new Integer(linha[2]); + + int[] pontos = new int[numeroGoo]; + + for(int b = 0; b< numeroGoo; b++){ + pontos[b] = new Integer(linha[b+3]); + } + + boolean[] semSurp = new boolean[numeroGoo]; + boolean[] comSurp = new boolean[numeroGoo]; + for (int k = 0; k < numeroGoo; k++) { + comSurp[k] = false; + semSurp[k]=false; + for (int i = 0; i < combinacoes.length; i++) { + if (Math.abs(combinacoes[i][0] - combinacoes[i][1]) <= 1 + && Math.abs(combinacoes[i][0] - combinacoes[i][2]) <= 1 + && Math.abs(combinacoes[i][1] - combinacoes[i][2]) <= 1 + && (combinacoes[i][0] + combinacoes[i][1] + combinacoes[i][2]) == pontos[k] + && (combinacoes[i][0] >= minScore || combinacoes[i][1] >= minScore || combinacoes[i][2] >= minScore)) { + semSurp[k] = true; + break; + } + } + + for (int i = 0; i < combinacoes.length; i++) { + if (Math.abs(combinacoes[i][0] - combinacoes[i][1]) <= 2 + && Math.abs(combinacoes[i][0] - combinacoes[i][2]) <= 2 + && Math.abs(combinacoes[i][1] - combinacoes[i][2]) <= 2 + && (combinacoes[i][0] + combinacoes[i][1] + combinacoes[i][2]) == pontos[k] + && (combinacoes[i][0] >= minScore || combinacoes[i][1] >= minScore || combinacoes[i][2] >= minScore)) { + comSurp[k] = true; + break; + } + } + } + + int contaMaior = 0; + for(int a = 0; a < numeroGoo; a++){ + if(semSurp[a] == true) + contaMaior++; + } + for(int a = 0; a < numeroGoo; a++){ + if(comSurp[a] == true && numeroSurp >0 && !semSurp[a]){ + contaMaior++; + numeroSurp--; + } else if (numeroSurp == 0){ + break; + } + } + + System.out.println(""Case #"" + (j + 1) + "": ""+contaMaior); + } + } +} +" +A20086,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; +import java.util.StringTokenizer; + + + +class roundtwo { + public static void main(String[] args) { + String text = """"; + if( args.length > 0) { + text = args[0]; + } else { + try { + FileInputStream fos = new FileInputStream( ""text2.txt""); + Scanner scanner = new Scanner(new FileInputStream(""text2.txt"")); + try { + while (scanner.hasNextLine()){ + text += scanner.nextLine() + ""\n""; + } + } + finally{ + scanner.close(); + } + try { + fos.read(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + StringTokenizer st = new StringTokenizer(text, ""[\r\n]+"", false); + int cases = Integer.parseInt(st.nextToken()); + + for (int x=1; x<= cases; x++) { + + StringTokenizer st2 = new StringTokenizer(st.nextToken(), ""[ ]+"", false); + + int number = Integer.parseInt(st2.nextToken()); + int suprise = Integer.parseInt(st2.nextToken()); + int score_target = Integer.parseInt(st2.nextToken()); + int[] data = new int[30]; + for( int i = 0; i < 30; i++){ + data[i] = 0; + } + int for_sure = 0; + int mabey = 0; + for( int i = 0; i < number; i++){ + int current = Integer.parseInt(st2.nextToken()); + int base = current / 3; + if( base >= score_target) { + for_sure++; + } + if( base == (score_target - 1)) { + int remainder = current % 3; + if( remainder > 0) {for_sure++;} + else if( base != 0){mabey++;} + } + if( base == (score_target - 2)) { + int remainder = current % 3; + if( remainder == 2) {mabey++;} + } + } + int number_possible = for_sure; + if( suprise >= mabey) { + number_possible += mabey; + } else { + number_possible += suprise; + } + System.out.println( ""Case #"" + x + "": "" + number_possible); + } + } +}" +A21493,"import java.io.*; +public class GoogJam2 +{ + public static void main(String args[]) + { + try{ + + BufferedReader br=new BufferedReader(new FileReader(args[0])); + int T=Integer.parseInt(br.readLine()); + BufferedWriter bw=new BufferedWriter(new FileWriter(""output.txt"",true)); + for(int i1=0;i1=p)||((b[i][0]==p-1)&&(b[i][1]==1))||((b[i][0]==p-1)&&(b[i][1]==2))) + {//System.out.println(""c1""); + count++; + } + else if(s>0) + { + if((b[i][0]==p-1)&&(b[i][1]==0)) + {if(a[i]>=1) + {//System.out.println(b[i][0]+"" c2""); + count++; + s--; + } + } + else if((b[i][0]==p-2)&&(b[i][1]==2)) + {//System.out.println(b[i][0]+"" ""+b[i][1]+""\n""); + if(a[i]>=2) + {//System.out.println(b[i][0]+"" c2""); + count++; + s--; + } + } + } + } + bw.write(""Case #""+(i1+1)+"": ""+count+""\n""); + //System.out.println(count); + } + bw.close(); + br.close(); + } + catch(Exception e) + {} + + } +}" +A22855,"package qualification.q1; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by IntelliJ IDEA. + * User: ofer + * Date: 14/04/12 + * Time: 17:10 + * To change this template use File | Settings | File Templates. + */ +public class Q1Solver { + + private Map mapping; + + public Q1Solver(){ + mapping = new HashMap(); + mapping.put('y','a'); + mapping.put('n','b'); + mapping.put('f','c'); + mapping.put('i','d'); + mapping.put('c','e'); + mapping.put('w','f'); + mapping.put('l','g'); + mapping.put('b','h'); + mapping.put('k','i'); + mapping.put('u','j'); + mapping.put('o','k'); + mapping.put('m','l'); + mapping.put('x','m'); + mapping.put('s','n'); + mapping.put('e','o'); + mapping.put('v','p'); + mapping.put('z','q'); + mapping.put('p','r'); + mapping.put('d','s'); + mapping.put('r','t'); + mapping.put('j','u'); + mapping.put('g','v'); + mapping.put('t','w'); + mapping.put('h','x'); + mapping.put('a','y'); + mapping.put('q','z'); + mapping.put(' ',' '); + + } + + public String convertString(String encrypted){ + StringBuilder resString = new StringBuilder(""""); + for (int i = 0 ; i < encrypted.length() ; i++){ + char decryptedChar = mapping.get(encrypted.charAt(i)); + resString.append(decryptedChar); + } + return resString.toString(); + } +} +" +A20324,"import java.io.*; +import java.util.*; + +public class GoogleDancer { + public static void main(String[] args) throws IOException + { + Scanner sc = new Scanner(new FileReader(""Dancer.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""Dancer.out""), true); + int T = sc.nextInt(); + for (int c = 1; c<=T; c++) + { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + int[] points = new int[N]; + for (int d = 0; d < N; d++) + { + points[d] = sc.nextInt(); + } + int num = calc(N, S, p, points); + String x = String.format(""Case #%d: %d"", c, num); + pw.println(x); + } + + + pw.close(); + } + public static int calc(int N, int S, int p, int[] points) + { + int total = 0; + int min = ((p-2)<0? 0 : p-2)*2 + p; + for (Integer n : points) + { + + if (n < min) continue; + int avg = n/3; + if (n%3 == 0) + { + if (avg >= p) total++; + else if ((avg+1) >= p && S>0) + { + total++; + S--; + } + }else if (n%3 == 1) + { + if ((avg+1) >= p)total++; + }else + { + if ((avg+1) >= p) total++; + else if ((avg+2)>= p && S > 0) + { + total++; + S--; + } + } + } + return total; + } +} +" +A22608," +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + public static void main(String args[]) { + Scanner in = new Scanner(System.in); + int t = in.nextInt(); + for (int i = 0; i < t; i++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int ans = 0; + + int a[] = new int[n]; + int b[] = new int[n]; + for (int j = 0; j < n; j++) { + a[j] = in.nextInt(); + if (a[j] % 3 == 0) { + b[j] = a[j] / 3; + } else if ((a[j] > 0) && (a[j] - 1) % 3 == 0) { + b[j] = (a[j] - 1) / 3 + 1; + } else if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { + b[j] = (a[j] - 2) / 3 + 1; + } + } + for (int j = 0; j < n && s > 0; j++) { + if (a[j] >= 0 && b[j] < p) { + int x = -1; + if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { + x = (a[j] - 2) / 3 + 2; + } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { + x = (a[j] - 3) / 3 + 2; + } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { + x = (a[j] - 4) / 3 + 2; + } + if (x >= p) { + ans++; + a[j] = -1; + s--; + } + } + } + for (int j = 0; j < n && s > 0; j++) { + if (a[j] >= 0 && b[j] < p) { + int x = -1; + if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { + x = (a[j] - 2) / 3 + 2; + } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { + x = (a[j] - 3) / 3 + 2; + } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { + x = (a[j] - 4) / 3 + 2; + } + if (x != -1) { + a[j] = -1; + s--; + } + } + } + for (int j = 0; j < n && s > 0; j++) { + if (a[j] >= 0 && b[j] >= p) { + int x = -1; + if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { + x = (a[j] - 2) / 3 + 2; + } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { + x = (a[j] - 3) / 3 + 2; + } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { + x = (a[j] - 4) / 3 + 2; + } + if (x >= p) { + ans++; + a[j] = -1; + s--; + } + } + } + + for (int j = 0; j < n && s > 0; j++) { + if (a[j] >= 0 && b[j] >= p) { + int x = -1; + if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { + x = (a[j] - 2) / 3 + 2; + } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { + x = (a[j] - 3) / 3 + 2; + } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { + x = (a[j] - 4) / 3 + 2; + } + if (x != -1) { + ans--; + a[j] = -1; + s--; + } + } + } + for (int j = 0; j < n; j++) { + if (a[j] >= 0 && b[j] >= p) { + ans++; + } + } + System.out.println(""Case #""+(i+1)+"": ""+ans); + } + } +} +" +A22412,"package jam2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class Test2 { + public static void main(String argv[]){ + Test2 tb = new Test2(); + ArrayList strin = tb.readFile(""B-large.in""); + ArrayList> intin = tb.getInt(strin); + + tb.printInt(intin); + + ArrayList strout = new ArrayList(); + + tb.computeDancer(intin, strout); + + tb.writeResult(strout, ""outtest2_large.txt""); + } + + public void computeDancer(ArrayList> intin, + ArrayList strout){ + if(intin==null || strout==null || intin.size()==0) return; + int nTest = intin.get(0).get(0); + for(int i=1; i<=nTest; ++i){ + + int ndancer = intin.get(i).get(0); + if(ndancer!=(intin.get(i).size()-3)){ + System.out.println(""dancer do not match!""); + return; + } + + int nsurprise = intin.get(i).get(1); + int thresh = intin.get(i).get(2); + final int tri =3; + + int ng = 0; //the googlers have score above threshold + for(int j=3; j (tri*(thresh-1))){ + ng++; + }else if(score>(tri*(thresh-2)+1)){ + int div = score/tri; + int residule = score%tri; + if(nsurprise > 0){ + if(residule <=1 && div==0) continue; // + ng++; + nsurprise --; + } + } + } + + //write out the results + String line = ""Case #""+i+"": ""+ng; + System.out.println(line); + strout.add(line); + } + + + } + + public void printInt(ArrayList> intin){ + if(intin==null ) return; + for(ArrayList arr:intin){ + for(Integer i: arr){ + System.out.print(i+"",""); + } + System.out.println(); + } + } + + public ArrayList> getInt(ArrayList strlist){ + if(strlist == null) return null; + ArrayList> intlist = new ArrayList>(); + for(String s:strlist){ + ArrayList tarr = new ArrayList(); + String astr[] = s.split("" ""); + for(int i=0; i readFile(String inname){ + if(inname == null) return null; + + ArrayList arr = new ArrayList(); + try{ + FileInputStream fstream = new FileInputStream(inname); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + while ((strLine = br.readLine()) != null) { + arr.add(strLine); + } + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + return arr; + } + + public void writeResult(ArrayList res, String fname){ + if(res == null || res.size()==0) return; + try{ + FileWriter fstream = new FileWriter(fname); + BufferedWriter out = new BufferedWriter(fstream); + + for(int i=0; i alwaysAboveSum) { + googlersAbove++; + } else if (scoreSums[i] >= alwaysUnderSum) { + couldBeSurprising++; + } + } + return googlersAbove + + Math.min(numberSuprisingScores, couldBeSurprising); + } + + private int numberScoresAtLeastOne() { + int result = 0; + for (int i = 0; i < scoreSums.length; i++) { + if (scoreSums[i] >= 1) { + result++; + } + } + return result; + } + +} +" +A21633,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author user + */ +public class CodeJam { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + FileReader fin = null; + FileWriter fout = null; + try { + fin = new FileReader(""input.txt""); + fout = new FileWriter(""Output.txt""); + BufferedWriter out = new BufferedWriter(fout); + BufferedReader in = new BufferedReader(fin); + int t; + t = Integer.parseInt(in.readLine()); + int j = 0,N,S,P; + String[] k; + while (t > j) { + k = in.readLine().split("" ""); + N = Integer.parseInt(k[0]); + S = Integer.parseInt(k[1]); + P = Integer.parseInt(k[2]); + int arr; + int count = 0; + int f,mod,ml,temp; + for (int i = 0; i < N; i++) { + arr = Integer.parseInt(k[i + 3]); + f = arr / 3; + mod = arr%3; + if (f>= P) { + count++; + } + else if(f == P-1) + { + if(mod >= 1) + { + count++; + } + else + { + if(f != 0 && S > 0) + { + count++; + S--; + } + } + } + else if(f == P-2&& S > 0) + { + if(mod >= 2) + { + count++; + S--; + } + } +// if(P == 0) +// { +// count++; +// continue; +// } +// if(arr == 0) { +// continue; +// } +// f = arr / P; +// mod = arr%P; +// if (f >= 3) { +// count ++; +// } +// else if(f == 1) +// { +// continue; +// } +// else +// { +// ml = P; +// temp = (ml - mod)/2; +// ml -= temp; +// mod += temp; +// if (P - mod > 2) { +// continue; +// } +// else if (P - mod == 2) +// { +// if(S > 0) +// { +// S --; +// count ++; +// } +// } +// else +// { +// count ++; +// } +// } + } + out.write(""Case #"" + (j + 1) + "": "" + count + ""\n""); + out.flush(); + j ++; + } + } catch (IOException ex) { + Logger.getLogger(CodeJam.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + fin.close(); + fout.close(); + } catch (IOException ex) { + Logger.getLogger(CodeJam.class.getName()).log(Level.SEVERE, null, ex); + } + } + + } +} +" +A20709,"import java.util.*; +import java.io.*; +public class b{ + public static int[] nums; + public static int[][] memo; + public static int p; + public static void main(String[] args) throws IOException{ + Scanner br = new Scanner(new File(""b.in"")); + PrintWriter out = new PrintWriter(new File(""b.out"")); + int cases = br.nextInt(); + for(int c = 0;c 2){ + continue; + } + if(k-i == 2 && left > 0){ + best = Math.max(best, go(pos+1, left-1)+ (k >= p ? 1 : 0)); + } + else if(k-i < 2){ + best = Math.max(best, go(pos+1, left)+ (k >= p ? 1 : 0)); + } + } + } + return memo[pos][left] = best; + + } +} +" +A22700,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing; + +/** + * + * @author Serban + */ +public class Dancing { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + Input in = new Input(""B-large.in""); + } +} +" +A22061," +import java.io.*; +import java.util.*; + +public class Q2 { + public static void main(String[] args) { + Q2 q = new Q2(); + //q.test(); + //q.answerSmall(); + q.answerLarge(); + } + + public void answerSmall(){ + read(""B-small-attempt0.IN"", ""Q2_small_output.txt""); + } + + public void answerLarge(){ + read(""B-large.IN"", ""Q2_large_output.txt""); + } + + public void test(){ + read(""Test2_input.txt"", ""Test2_output.txt""); + } + + public void read(String readFrom, String writeTo){ + try{ + Scanner in = new Scanner(new File(readFrom)); + File f = new File(writeTo); + FileWriter fw = new FileWriter(f); + int T = Integer.parseInt(in.nextLine()); + int N,S,p, max, average, remainder, score; + String[] scores; + String answer; + + for(int i = 1; i <= T; i++) { + scores = in.nextLine().split("" ""); + N = Integer.parseInt(scores[0]); + S = Integer.parseInt(scores[1]); + p = Integer.parseInt(scores[2]); + max = 0; + for(int a = 3; a < N + 3; a++) { + score = Integer.parseInt(scores[a]); + average = score / 3; + remainder = score % 3; + + if(average >= p) { + max++; + }else if(remainder >= 1 && average + 1 >= p) { + max++; + }else if(remainder == 2 && average + 2 >= p){ + if(S > 0){ + S--; + max++; + } + }else if(remainder == 0 && average - 1 >= 0 && average + 1 >= p) { + if(S > 0){ + S--; + max++; + } + } + } + answer = """" + max; + if(i + 1 <= T) + answer += ""\r\n""; + fw.write(""Case #"" + i + "": "" + answer); + + } + + + fw.close(); + }catch(Exception ex) { + System.out.println(ex); + } + } +} +" +A22067,"package hk.polyu.cslhu.codejam.solution.impl.qualificationround; + +import java.util.ArrayList; +import java.util.List; + +import hk.polyu.cslhu.codejam.solution.Solution; + +public class DancingWithTheGooglers extends Solution { + private int N, S, p; + private List totalPointList; + + @Override + public void setProblem(List problemDesc) { + // TODO Auto-generated method stub + String[] splitArray = problemDesc.get(0).split("" ""); + + this.N = Integer.valueOf(splitArray[0]); + this.S = Integer.valueOf(splitArray[1]); + this.p = Integer.valueOf(splitArray[2]); + + this.totalPointList = new ArrayList(); + for (int i = 3; i < splitArray.length; i++) { + this.totalPointList.add(Integer.valueOf(splitArray[i])); + } + + if (this.totalPointList.size() != this.N) + logger.error(""Found an error for "" + problemDesc.get(0)); + } + + @Override + public void solve() { + // TODO Auto-generated method stub + int minNotSupSum = this.p * 3 - 2; + int minSupSum = this.p > 1 ? (this.p * 3 - 4) : 1; + + int totalNotSup = 0; + int totalSup = 0; + + for (Integer point : this.totalPointList) { + if (point >= minNotSupSum) + totalNotSup++; + else if (point >= minSupSum) + totalSup++; + } + + if (totalSup + totalNotSup < this.S) + logger.error(""Found an error for suprising cases""); + + this.result = String.valueOf(totalNotSup + Math.min(totalSup, this.S)); + } + +} +" +A20621," + +package b; +import java.io.*; + +public class Main { + + + public static void main(String[] args) { + new Main().go(); + } + + + public void go() { + BufferedReader in = null; + BufferedWriter out = null; + try{ + in = new BufferedReader(new FileReader(""B-large.in"")); + out = new BufferedWriter(new FileWriter(""B-large.out"")); + int T = Integer.parseInt(in.readLine()); + System.out.println(""T=""+T); + + for(int i=0;i=p){ + win++; + } else { + if(ok+2>=p && s>0){ + s--; + win++; + } + } + break; + + case 1: + if(ok+1>=p){ + win++; + } + break; + + case 0: + if(ok>=p){ + win++; + } else { + if(ok>0 && s>0 && (ok+1)>=p){ + s--; + win++; + } + } + break; + } + + } + + + out.write(""Case #""+(i+1)+"": ""+win+""\n""); + System.out.print(""Case #""+(i+1)+"": ""+win+""\n""); + } + in.close(); + out.close(); + }catch(Exception e){ + e.printStackTrace(); + try{ + in.close(); + out.close(); + }catch(Exception e1){ + e1.printStackTrace(); + } + } + System.out.print(""DONE\n""); + } +} +" +A22572,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.HashMap; +import java.util.StringTokenizer; +import java.util.Vector; + + +public class Algorithm2 { + + static final String input_path = ""F://workspace//GoogleContest2012//src//input.txt""; + static final String output_path = ""F://workspace//GoogleContest2012//src//output.txt""; + static int total_case; + + static int findMax(String line){ + StringTokenizer token = new StringTokenizer(line); + int num = Integer.parseInt((String)token.nextElement()); + int surprising = Integer.parseInt((String)token.nextElement()); + int mscore = Integer.parseInt((String)token.nextElement()); + int goodline = 3*mscore - 2; + int middline = 3*mscore - 4; + goodline = goodline>0?goodline:0; + middline = middline>0?middline:1; + int[] scores = new int[num]; + int good = 0, middle = 0; + for(int i = 0; i< num;i++){ + scores[i] = Integer.parseInt((String)token.nextElement()); + if(scores[i]>=goodline){ + good++; + }else if(scores[i]>=middline){ + middle++; + } + } + + return good + (middle>=surprising?surprising:middle); + } + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + int i = 0; + Vector outputs = new Vector(); + try{ + File file = new File(input_path); + BufferedReader reader =new BufferedReader(new FileReader(file)); + String line = reader.readLine(); //skip number + total_case = Integer.parseInt(line); + while(i=normal)res++; + else if(score>=surprise && S>0) { + res++; + S--; + } + } + + out.println(""Case #""+(caseNum+1)+"": ""+res); + } + } +} + +" +A23086,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +import java.io.*; +import java.util.*; + +/** + * + * @author Tareq: + * I want to dance with a googler too! ;( + */ +public class Dance { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + String line; + StringTokenizer st; + int T; + int N,S,p; + try{ + BufferedReader reader = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileOutputStream(""Dance-large.out"")); + T = Integer.parseInt(reader.readLine()); + for(int k=1;k<=T;k++) + { + int numOfBest =0; + int minScore; + line = reader.readLine(); + st = new StringTokenizer(line); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + minScore = p*3; + for(int i=0;i=minScore-2) + numOfBest++; + else if(tscore>=minScore-4) + if(S>0 && p>1) + { numOfBest++; + S--; + } + } + pw.println(""Case #""+k+"": ""+numOfBest); + } + + pw.close(); + }catch(Exception e){System.out.println(""hmm""+e);} + } +} +" +A22252,"package de.pat.dev.y2012.qualification.b; + +import java.util.Arrays; +import java.util.Collections; + +/** + * @author pat.dev@alice.de + */ +public class ScoreStatistics { + private final int numberOfSurprises; + private final int[] scores; + + public ScoreStatistics(int numberOfSurprises, int[] scores) { + this.numberOfSurprises = numberOfSurprises; + this.scores = scores;Arrays.sort(scores); + } + + public int numberOfGooglersReaching(int bestScore) { + final int bestScoreSum=3*bestScore; + int numberOfSuccessfulGooglers=0; + int surprises=numberOfSurprises; + + for (int i=scores.length-1;i>=0;i--) { + int diff = scores[i]-bestScoreSum; + if (diff >= -2) { // e.g. : t=13, p=5 => t=4+4+5, diff=-t-3*p=13-3*5=-2 + numberOfSuccessfulGooglers++; + } else { // diff < -2 + if (surprises>0 && diff >= -4 && scores[i]>0) { // -4 <= diff < -2, e.g.: t=11, p=5 => t=3+5+3=11, diff=11-15=-4 + numberOfSuccessfulGooglers++; + surprises--; + } else break; + } + } + return numberOfSuccessfulGooglers; + } + + @Override + public String toString() { + return ""ScoreStatistics{"" + + ""numberOfSurprises="" + numberOfSurprises + + "", scores="" + Arrays.toString(scores) + + '}'; + } +} +" +A21645,"package t2012.classification; + +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Scanner; + +public class ExB { + + + + + + public void exec(String filename, String out_filename) + { + try{ + FileInputStream fis = new FileInputStream(filename); + Scanner s = new Scanner(fis); + + FileWriter output_fstream = new FileWriter(out_filename); + BufferedWriter out = new BufferedWriter(output_fstream); + + // The problem + int T = Integer.parseInt(s.nextLine()); + for(int testNum = 1; testNum <=T; testNum++) + { + System.out.println(testNum); + String line = s.nextLine(); + String[] list = line.split("" ""); + int N = Integer.parseInt(list[0]); + int S = Integer.parseInt(list[1]); + int p = Integer.parseInt(list[2]); + int numGood = 0; + int numSurp = 0; + int discarded = 0; + for(int i = 3; i < N+3; i++) + { + int sum = Integer.parseInt(list[i]); + if(sum >= 3*p-2 && sum >=p) + { + numGood++; + } + else if(sum < 3*p-2 && sum >= 3*p-4 && sum >=p) + { + numSurp++; + } + else + { + discarded++; + } + } + int result = numGood + Math.min(numSurp,S); + out.write(""Case #""+testNum+"": ""+result+""\n""); + + } + + // End the problem + + out.close(); + output_fstream.close(); + }catch(Exception e) + { + System.out.println(""Some error occurred""); + } + } + + + public static void main(String args[]) + { + String PATH= ""/home/pau/development/workspace/CodeJam/testfiles/2012/""; + ExB a = new ExB(); + a.exec(PATH + ""B-large.in"", PATH + ""B-large.out""); + //a.exec(PATH + ""B-large-practice.in"", PATH + ""B-large-practice.out""); + } + +} +" +A20419,"import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class DancingWiththeGooglers { + BufferedReader reader; + char [] charInput; + String [] inputArray; + int index; + DancingWiththeGooglers()throws Exception{ + String input=null; + reader = new BufferedReader(new InputStreamReader(System.in)); + while(reader.ready()){ + if (input==null){ + input =reader.readLine(); + } + else{ + input =input+ "" "" + reader.readLine(); + } + } + inputArray=input.trim().split("" ""); + index=0; + } + String nextInput()throws Exception{ + if(index(best-1)){ + maxBest++; + } + else if(total%3!=1 && ((double)total)/3>(best-2) && total<28 && total>1){ + if (surprising>0){ + maxBest++; + surprising--; + } + } + } + System.out.printf(""Case #%d: %d"", i+1,maxBest); + if (i!=numCases-1){ + System.out.println(); + } + maxBest=0; + } + } +} + +" +A22896,"import static java.lang.Math.*; +import static java.util.Arrays.*; +import java.io.*; +import java.util.*; + +public class B { + int[][] allno=new int[31][2]; + Scanner sc; + + void solve(int caseID) { + int res=0; + int n=sc.nextInt(); + int s=sc.nextInt(); + int p=sc.nextInt(); + int[] nos=new int[n]; + for(int i=0;i=p) + res++; + else if(s>0 && allno[nos[i]][1]>=p) + { + res++; + s--; + } + } + System.out.println(""""+res); + } + + void run() { + long time = System.currentTimeMillis(); + update(); + sc = new Scanner(System.in); + int caseN = sc.nextInt(); + for (int caseID = 1; caseID <= caseN; caseID++) { + //double t = (System.currentTimeMillis() - time) * 1e-3; + //if (!SAMPLE) System.err.printf(""%03d/%03d %.3f/%.3f%n"", caseID, caseN, t, t / (caseID - 1) * caseN); + System.out.printf(""Case #%d: "", caseID); + solve(caseID); + System.out.flush(); + } + } + + void update() + { + int rem; + int no; + for(int i=1;i<=30;i++) + { + rem=i%3; + no=i/3; + switch(rem) + { + case 0: + allno[i][0]=no; + allno[i][1]=no+1; + break; + case 1: + allno[i][0]=no+1; + allno[i][1]=no+1; + break; + case 2: + allno[i][0]=no+1; + allno[i][1]=no+2; + break; + } + } + } + + void debug(Object...os) { + System.err.println(deepToString(os)); + } + + public static void main(String[] args) { + try { + System.setIn(new FileInputStream(""B.in"")); + System.setOut(new PrintStream(new FileOutputStream(""B.out""))); + } catch (IOException e) { + } + new B().run(); + } + +}" +A20285,"import java.io.*; +import java.util.Scanner; + +public class surprisingTriplets +{ + public static Scanner sc; + + + public static void main(String args[]) throws IOException + { + Scanner sc = new Scanner(System.in); + int numCasos = sc.nextInt(); + int numConcursants; + int surprisingTriplets; + int p; + int resultat; + + int qt = 0; + while(qt < numCasos) + { + numConcursants = sc.nextInt(); + surprisingTriplets = sc.nextInt(); + p = sc.nextInt(); + resultat = totalPoints(numConcursants,surprisingTriplets,p,sc); + System.out.println(""Case #""+(qt+1)+"": ""+resultat); + qt++; + } + } + + + public static int totalPoints(int numConcursants, int surprisingTriplets, int p, Scanner sc) + { + int qt = 0; + int bons=0; + int votacio; + + int minimNormal; + int minimSurprising; + if(p > 1){ minimSurprising = p + (p-2) + (p-2); minimNormal = p + (p-1) + (p-1);} + else if(p == 1){ minimSurprising = 1; minimNormal = 1;} + else{ minimSurprising = 0; minimNormal = 0;} + + while(qt < numConcursants) + { + votacio = sc.nextInt(); + if(votacio >= minimNormal) + { + bons++; + } + else + { + if(votacio >= minimSurprising && surprisingTriplets > 0) + { + bons++; + surprisingTriplets--; + } + } + qt++; + } + return bons; + } + +}" +A21420,"package qualificationround; + +import java.io.*; +import java.util.Scanner; + +public class ProblemB { + + /** + * @param args + */ + public static void main(String[] args) throws IOException{ + Scanner sc = new Scanner(new FileReader(""B.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""B.out"")); + int t = sc.nextInt(); + for (int caseNum = 1; caseNum <= t; caseNum++) + { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int count = 0; + for (int i = 0; i=p) + count++; + else if (p-score == 1 && s>0 && pscore >=2) + { + s--; + count++; + } + } + out.println(""Case #""+caseNum+"": ""+count); + } + out.close(); + } + + public static int getScore(int num) + { + if (num % 3 == 0) + return num/3; + else + return num/3+1; + } + +} +" +A20882,"package google.codejam; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Stark_B { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub + Scanner sc = new Scanner(new FileReader(""B.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""B.out"")); + + int total = sc.nextInt(); + + + + for(int i=0; i=thold || (x==(thold-1) && y>0)) done++; + else if(((x==(thold-1)&&y==0)||(x==(thold-2) && y==2))&&(x>0)) mid++; + else cant++; + + } + + if(surprise= p ) + notsurp++; + else if ( p * 3 <= t + 4 && t >= p ) + surp++; + } + return Integer.toString(notsurp + (surp <= S ? surp : S)); + } + + public static void main(String[] args) throws Exception { + Scanner in = new Scanner(System.in.available() > 0 ? System.in : + new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + "".practice.in"")); + int T = in.nextInt(); + for(int i = 1; i <= T; i++) + System.out.format(""Case #%d: %s\n"", i, process(in)); + } +} +" +A20696,"package home.lviv; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class Main { + public static void proA(BufferedReader reader, BufferedWriter writer) + throws NumberFormatException, IOException { + Map map = new HashMap(32); + String text = ""zejp mysljylc kd kxveddknmc re jsicpdrysi"" + + ""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"" + + ""de kr kd eoya kw aej tysr re ujdr lkgc jvq"", mapping = ""qour language is impossible to understand"" + + ""there are twenty six factorial possibilities"" + + ""so it is okay if you want to just give upz""; + for (int i = 0; i < text.length(); i++) { + map.put(Character.valueOf(text.charAt(i)), + Character.valueOf(mapping.charAt(i))); + } + int T; + T = Integer.parseInt(reader.readLine()); + for (int t = 0; t < T; t++) { + String in, out = """"; + in = reader.readLine(); + for (int i = 0; i < in.length(); i++) { + if (map.get(in.charAt(i)) == null) { + System.out.println(""null is "" + in.charAt(i)); + } + out += map.get(in.charAt(i)); + } + writer.write(""Case #"" + (t + 1) + "": "" + out + ""\n""); + } + } + + public static void proB(BufferedReader reader, BufferedWriter writer) + throws NumberFormatException, IOException { + int T = Integer.parseInt(reader.readLine()); + for (int t = 0; t < T; t++) { + String[] temp = reader.readLine().split("" ""); + int N = Integer.parseInt(temp[0]), S = Integer.parseInt(temp[1]), p = Integer + .parseInt(temp[2]), G = 0; + int[] n = new int[N]; + ArrayList integers = new ArrayList(N); + for (int i = 0; i < N; i++) { + n[i] = Integer.parseInt(temp[3 + i]); + if (((n[i] / 3) >= p)) { + G++; + continue; + } else { + if (((n[i] / 3) >= p - 1) && (n[i] > 0) && (n[i] % 3 > 0)) { + G++; + continue; + } + if (((n[i] / 3) >= p - 1) && (n[i] > 0) && (S > 0)) { + G++; + S--; + continue; + } + if (((n[i] / 3) >= p - 2) && (n[i] > 0) && (n[i] % 3 > 1) + && (S > 0)) { + G++; + S--; + continue; + } + } + } + writer.write(""Case #"" + (t + 1) + "": "" + (G) + ""\n""); + } + } + + public static void main(String[] args) throws IOException { + BufferedReader input = new BufferedReader(new InputStreamReader( + new FileInputStream(""/home/taras/codejam/data.in""))); + BufferedWriter output = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(""/home/taras/codejam/data.out""))); + proB(input, output); + input.close(); + output.close(); + } +} +" +A20623,"import static java.util.Arrays.deepToString; + +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Scanner; + +public class QB { + + public static void main(String[] args) throws Exception + { + new QB().run(); + + } + + void run() throws Exception + { + //Scanner sc = new Scanner(System.in); + //PrintWriter pw = new PrintWriter(System.out); + + Scanner sc = new Scanner(new FileReader(""B-small-attempt1.in"")); + + FileWriter fstream = new FileWriter(""out.in""); + BufferedWriter out = new BufferedWriter(fstream); + + + //PrintWriter pw = new PrintWriter(new FileWriter(""Asmall.out"")); + + int ntest = Integer.valueOf(sc.nextLine()); + + for(int test=1;test<=ntest;++test) + { + int playerNum = sc.nextInt(); + int surpNum = sc.nextInt(); + int min = sc.nextInt(); + //debug(playerNum); + int score = 0; + int criteria = min*3 - 4; + + for(int i=0; i= min) + { + if(current >= criteria + 2) + { + score ++; + } else if(current >= criteria) + { + if(surpNum > 0) + { + surpNum --; + score++; + } + } + } + + } + + //debug(score); + out.write(""Case #"" + test + "": ""); + out.write(score + """"); + out.write(""\n""); + } + out.close(); + sc.close(); + + } + + void debug(Object...os) + { + System.err.println(deepToString(os)); + } + + void debugArray(Object[]...os) + { + System.err.println(deepToString(os)); + } +} +" +A22319,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +//package codejam2012; + +import java.io.*; + +/** + * + * @author BUDDHIMA + */ +public class codejamQB { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(new File(""outputB-large.txt""))); + + int tests = Integer.parseInt(br.readLine()); + + for (int testIndex = 1; testIndex <= tests; testIndex++) { + + String[] lineParts = br.readLine().split("" ""); + + int googlers = Integer.parseInt(lineParts[0]); + int suptrip = Integer.parseInt(lineParts[1]); + int bestVal = Integer.parseInt(lineParts[2]); + + int count = 0; + + int[] totals = new int[googlers]; + + // Fill googler total array + for (int n = 0; n < googlers; n++) { + + totals[n] = Integer.parseInt(lineParts[3 + n]); + + } + + + for (int index = 0; index < totals.length; index++) { + + int full = totals[index] / 3; + int deci = totals[index] % 3; + + if (totals[index] < bestVal) { + } else if ((full == bestVal - 2 && deci == 2) || (full == (bestVal - 1) && deci == 0)) { // chance to waste supprising values + if (suptrip > 0) { + suptrip--; + count++; + } + } else if (full >= bestVal - 1) { // can compose triplets without using supprising values + + count++; + + } + + + } + + + System.out.println(count); + + + if(testIndex==tests) + out.write(""Case #"" + testIndex + "": "" + count ); + else out.write(""Case #"" + testIndex + "": "" + count + ""\n""); + + + + } + + + + + out.close(); + } +} +" +A21573,"package qualify; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws Exception { + Scanner input = new Scanner(new FileInputStream(""B-large.in"")); + PrintWriter output = new PrintWriter(new FileOutputStream(""B-large.out"")); + + int T,ca; + int N,S,p,t; + int r; + + T = input.nextInt(); + for(ca=1;ca<=T;ca++) { + N = input.nextInt(); + S = input.nextInt(); + p= input.nextInt(); + + r = 0; + for(int i=0;i= p ) { + r++; + } else if((t+4)/3 >= p && (t+4)/3 >= 2) { + S--; + if(S>=0) + r++; + } + } + + output.println(String.format(""Case #%d: %d"", ca,r)); + } + + input.close(); + output.close(); + + } + +} +" +A20030,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class GoogleB { + + /** + * @param args + */ + public String szamol(String input){ + String result=""""; + String a=input; + Integer countgooglers=Integer.parseInt(a.substring(0,a.indexOf(' '))); + a=a.substring(a.indexOf(' ')+1); + Integer surprize=Integer.parseInt(a.substring(0,a.indexOf(' '))); + a=a.substring(a.indexOf(' ')+1); + + Integer[] totalscore=new Integer[countgooglers]; + Integer all=0; + Integer sur=0; + if (countgooglers>0) { + Integer minscore=Integer.parseInt(a.substring(0,a.indexOf(' '))); + a=a.substring(a.indexOf(' ')+1); + + for (int i=0; i=27) + maxscore=10; + if (maxscore28) all++; + else sur++; + } + else all++; + } + } + int maxgooglers=all; + maxgooglers+=(sur= 2 && totalPoints <= 28) { + possibleCombinations = new int[2][3]; + if (remainder == 0) { + possibleCombinations[1] = new int[]{averagePoint, averagePoint, averagePoint}; + possibleCombinations[0] = new int[]{averagePoint + 1, averagePoint, averagePoint - 1}; + } else if (remainder == 1) { + possibleCombinations[1] = new int[]{averagePoint + 1, averagePoint, averagePoint}; + possibleCombinations[0] = new int[]{averagePoint + 1, averagePoint + 1, averagePoint - 1}; + } else { //remainder == 2 + possibleCombinations[1] = new int[]{averagePoint + 1, averagePoint + 1, averagePoint}; + possibleCombinations[0] = new int[]{averagePoint + 2, averagePoint, averagePoint}; + } + } else { + possibleCombinations = new int[1][3]; + if (totalPoints == 0) { + possibleCombinations[0] = new int[]{0, 0, 0}; + } else if (totalPoints == 1) { + possibleCombinations[0] = new int[]{1, 0, 0}; + } else if (totalPoints == 29) { + possibleCombinations[0] = new int[]{10, 10, 9}; + } else if (totalPoints == 30) { + possibleCombinations[0] = new int[]{10, 10, 10}; + } + } + return possibleCombinations; + } + + static boolean isBestScoreMet(int[] possibleCombination, int bestScore) { + for (int i = 0; i < possibleCombination.length; i++) { + return possibleCombination[i] >= bestScore; + } + return false; + } + + static boolean isSurprisingTriplet(int[] possibleCombination) { + for (int i = 0; i < possibleCombination.length; i++) { + for (int j = i + 1; j < possibleCombination.length; j++) { + return Math.abs(possibleCombination[i] - possibleCombination[j]) == 2; + } + } + return false; + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(""/Users/vikash/DancingGooglersIn.txt"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""/Users/vikash/DancingGooglersOut.txt"")); + int testCases = Integer.parseInt(br.readLine()); + int currentTest = 1; + while (currentTest <= testCases) { + String[] numbers = br.readLine().split("" ""); + int numberOfGooglers = Integer.parseInt(numbers[0]); + int numberOfSurprisingTriplets = Integer.parseInt(numbers[1]); + int minBestResult = Integer.parseInt(numbers[2]); + int[] googlersTotalScore = new int[numberOfGooglers]; + for (int i = 3; i < numbers.length; i++) { + googlersTotalScore[i - 3] = Integer.parseInt(numbers[i]); + } + Arrays.sort(googlersTotalScore); + int qualifyingGooglers = 0; + boolean minConditionMet = false; + int optionalSurprisingTriplets = 0; + for (int i = 0; i < googlersTotalScore.length; i++) { +// if (minConditionMet) { +// qualifyingGooglers++; +// } else { + int[][] possibleCombinations = getPossibleCombinations(googlersTotalScore[i]); + boolean isBestResultMet = isBestScoreMet(possibleCombinations[0], minBestResult); + if (isBestResultMet && numberOfSurprisingTriplets <= 0 && optionalSurprisingTriplets == 0) { + if (possibleCombinations.length == 2) { + isBestResultMet = isBestScoreMet(possibleCombinations[1], minBestResult); + } + } + if (isBestResultMet) { + if(numberOfSurprisingTriplets<=0) { + optionalSurprisingTriplets--; + } + qualifyingGooglers++; + if (googlersTotalScore[i]/3 >= minBestResult) { + minConditionMet = true; + } + } + if (possibleCombinations.length == 2 && numberOfSurprisingTriplets > 0) { + numberOfSurprisingTriplets--; + if(!isBestResultMet) { + optionalSurprisingTriplets++; + } + } +// } + } + bw.write(""Case #"" + currentTest + "": "" + qualifyingGooglers); + bw.newLine(); + currentTest++; + } + bw.close(); + br.close(); + } +} +" +A20214,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; +class process implements Runnable { + Thread t; + int c=0,n=0,s=0,p=0; + int[] sc; + int res=0; + String a=""""; + process(int i,int a,int b,int e,int[] d) { + c=(i+1); + n=a; + s=b; + p=e; + sc=d; + t = new Thread(this); + t.run(); + } + + public void run() { + float avg=0; + for(int i=0;i=1.5) + { + sc[i]=99; + } + else + { + if(avg>=p) + { + ++res; + a=a+sc[i]+"" ""; + sc[i]=99; + } + if( (p-avg)<1 && (p-avg)>0 ) + { + ++res; + a=a+sc[i]+"" ""; + sc[i]=99; + } + } + } + int i=0; + while(s>0 && i1 && (p-avg)<1.5 ) + { + ++res; + --s; + a=a+sc[i]+"" ""; + sc[i]=99; + } + ++i; + } + + } + public void print() + { + System.out.println(""Case #""+c+"": ""+res); + //System.out.println(a); + + } + +} + +public class Main { + public static void main(String[] args) throws Exception { + StringTokenizer st; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t=Integer.parseInt(br.readLine()); + process[] pr=new process[t]; + for(int i=0;i 1) { + ps.println(); + } + String data = sc.nextLine(); + String[] dataParts = data.split("" ""); + int googlers = Integer.parseInt(dataParts[0]); + int surprising = Integer.parseInt(dataParts[1]); + int minScore = Integer.parseInt(dataParts[2]); + int found = 0; + for (int person = 0; person < googlers; person++) { + int theirScore = Integer.parseInt(dataParts[person + 3]); + if (findUnsurprisingFor(theirScore).containsAtLeast( + minScore)) { + found++; + continue; + } else if (surprising > 0) { + Set surprisingScores = findSurprisingFor(theirScore); + for (Triplet score : surprisingScores) { + if (score.containsAtLeast(minScore)) { + found++; + surprising--; + break; + } + } + } + } + System.out.println(""Case #"" + i + "": "" + found); + ps.print(""Case #"" + i + "": "" + found); + } + sc.close(); + ps.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public static Triplet findUnsurprisingFor(int number) { + int biggestBit = (int) Math.ceil(number / 3.0); + int smallerBit = biggestBit - 1; + Triplet answer = new Triplet(); + for (int i = 0; i < 3; i++) { + if ((3 - i) * biggestBit + i * smallerBit == number) { + for (int j = 0; j < 3 - i; j++) { + answer.addComponent(biggestBit); + } + for (int j = 0; j < i; j++) { + answer.addComponent(smallerBit); + } + break; + } + } + return answer; + } + + public static Set findSurprisingFor(int number) { + Set solutions = new HashSet(); + for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= 10; j++) { + for (int k = 0; k <= 10; k++) { + if (i + j + k == number) { + if (Math.abs(k - i) <= 2 && Math.abs(k - j) <= 2 + && Math.abs(j - i) <= 2) { + if (Math.abs(k - i) == 2 || Math.abs(k - j) == 2 + || Math.abs(j - i) == 2) { + solutions.add(new Triplet(i, j, k)); + } + } + } + } + } + } + return solutions; + } + + public static class Triplet { + public int x, y, z; + private int idx = 0; + boolean isOrdered = false; + + public Triplet() { + } + + private Triplet(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + this.idx = 3; + this.isOrdered = true; + } + + public void addComponent(int component) { + if (idx == 0) { + x = component; + } else if (idx == 1) { + y = component; + } else { + z = component; + } + idx++; + } + + public boolean containsAtLeast(int num) { + return (x >= num || y >= num || z >= num); + } + + public Triplet orderedSet() { + List t = Arrays.asList(new Integer[] { x, y, z }); + Collections.sort(t); + return new Triplet(t.get(0), t.get(1), t.get(2)); + + } + + @Override + public int hashCode() { + if (isOrdered) { + final int prime = 31; + int result = 1; + result = result * prime + x; + result = result * prime + y; + result = result * prime + z; + return result; + } else { + return orderedSet().hashCode(); + } + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Triplet other = ((Triplet) obj).orderedSet(); + if (isOrdered) { + if (x != other.x) + return false; + if (y != other.y) + return false; + if (z != other.z) + return false; + return true; + } else { + Triplet myOrder = orderedSet(); + if (myOrder.x != other.x) + return false; + if (myOrder.y != other.y) + return false; + if (myOrder.z != other.z) + return false; + return true; + } + } + } + +} +" +A20308,"package codejam.qual2012; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; + +public class B { + + public int count(int target, int surprise, int[] scores) { + + int a = target; + int b = target - 1; + int c = target - 2; + + if (b < 0) + b = 0; + if (c < 0) + c = 0; + + int good = a + b + b; + int goodWSurprize = a + c + c; + + int count = 0; + + for (int i : scores) { + if (i >= good) { + count++; + } else if (i >= goodWSurprize && surprise > 0) { + count++; + surprise--; + } + } + + return count; + } + + public static void main(String[] args) throws IOException { + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + PrintStream out = new PrintStream(new BufferedOutputStream(System.out)); + + String line = in.readLine(); + int testCases = Integer.parseInt(line); + + B b = new B(); + + // Read in all test cases + for (int testCase = 1; testCase <= testCases; testCase++) { + line = in.readLine(); + String[] data = line.split("" ""); + + int target = Integer.parseInt(data[2]); + int surprise = Integer.parseInt(data[1]); + int[] scores = new int[data.length - 3]; + + for (int i = 3; i < data.length; i++) { + scores[i - 3] = Integer.parseInt(data[i]); + } + + out.println(""Case #"" + testCase + "": "" + + b.count(target, surprise, scores)); + } + + out.flush(); + } + +} +" +A20201,"package com.google.codejam.dancewithgooglers; + +import java.io.*; + +public class DanceWithGooglers { + + private static String filename = ""large""; + + public static void main(String[] args) throws Exception { + RandomAccessFile input = new RandomAccessFile(filename + ""_in.txt"", ""r""); + RandomAccessFile output = new RandomAccessFile(filename + ""_out.txt"", ""rw""); + + int cases = Integer.valueOf(input.readLine()); + for(int i = 0; i < cases; i++){ + String[] line = input.readLine().split("" ""); + + int N = Integer.valueOf(line[0]); + int S = Integer.valueOf(line[1]); + int p = Integer.valueOf(line[2]); + + int[] t = new int[N]; + for(int j = 0; j < N; j++)t[j] = Integer.valueOf(line[j + 3]); + + int solved = solve(t, S, p); + + System.out.println(""Case #"" + (i + 1) + "": "" + solved); + output.writeBytes(""Case #"" + (i + 1) + "": "" + solved + ""\n""); + } + + output.close(); + input.close(); + } + + private static int solve(int[] scores, int S, int p){ + int found = 0; + int surprising = 0; + + for(int i : scores){ + boolean[] result = permute(i, p); + if(!result[0])continue; + if(!result[1]){ + found++; + }else{ + surprising++; + } + } + + if(S > surprising)return found + surprising; + return found + S; + } + + private static boolean[] permute(int value, int search){ + boolean found = false; + boolean surprising = false; + + for(int a = 0; a <= 10; a++){ + for(int b = a; b <= a + 2; b++){ + if(b > 10)continue; + for(int c = a; c <= a + 2; c++){ + if(c > 10)continue; + if((a + b + c) != value)continue; + + if((a >= search) || (b >= search) || (c >= search)){ + found = true; + + if((Math.abs(a - b) == 2) || (Math.abs(a - c) == 2) || (Math.abs(b - c) == 2)){ + surprising = true; + }else{ + return new boolean[]{ true, false }; + } + } + } + } + } + return new boolean[]{ found, surprising }; + } +} +" +A22859,"package codejam; + +public class Dancer extends CodeJam{ + + public Dancer() { + super(""B-large""); + } + + public static void main(String[] args) { + new Dancer().run(); + } + + @Override + protected String solve() { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + + if (p == 0){ + scanner.nextLine(); + return n + """"; + } + + if (p == 1){ + s = 0; + } + + int sum = 3*p - 2; + int sum2 = 3*p - 4; + int count = 0; + for (int i = 0 ; i < n ; i++){ + int v = scanner.nextInt(); + if (v >= sum){ + count++; + } else if (v >= sum2 && s-- > 0){ + count++; + } + } + return count + """"; + } +} +" +A20422,"package ulohy; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Codejam_2 { + + static byte cases; + static int[] googlers = new int[100]; + static int[] supr_triplets = new int[100]; + static int[][] total_scores = new int[100][100]; + static int[][] max = new int[100][100]; + static int[][] supr_max = new int[100][100]; + static int[] treshold = new int[100]; + static int[] result = new int[100]; + + public static void read_input() { + + Scanner s = null; + try { + s = new Scanner(new FileReader(""./src/ulohy/B-small-attempt0.in"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + cases = s.nextByte(); + + for (int i = 0; i < cases; i++) { + googlers[i] = s.nextInt(); + supr_triplets[i] = s.nextInt(); + treshold[i] = s.nextInt(); + for (int j = 0; j < googlers[i]; j++) { + total_scores[i][j] = s.nextInt(); + } + } + + s.close(); + } + + public static void write_output() { + FileWriter outFile; + try { + outFile = new FileWriter(""./src/ulohy/output""); + PrintWriter out = new PrintWriter(outFile); + for (int i = 1; i <= cases; i++) { + out.println(""Case #""+i+"": ""+result[i-1]); + } + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void main(String args[]) { + + read_input(); + + for (int i = 0; i < cases; i++) { + for (int j = 0; j < googlers[i]; j++) { + if (total_scores[i][j] > 0) { + switch (total_scores[i][j] % 3) { + case 0: + max[i][j] = total_scores[i][j]/3; + supr_max[i][j] = total_scores[i][j]/3 + 1; + break; + case 1: + max[i][j] = total_scores[i][j]/3 + 1; + supr_max[i][j] = total_scores[i][j]/3 + 1; + break; + case 2: + max[i][j] = total_scores[i][j]/3 + 1; + supr_max[i][j] = total_scores[i][j]/3 + 2; + break; + default: + break; + } + } + } + + for (int j = 0; j < googlers[i]; j++) { + if (max[i][j] >= treshold[i]) { + result[i]++; + } else { + if (supr_max[i][j] >= treshold[i] && supr_triplets[i] > 0) { + result[i]++; + supr_triplets[i]--; + } + } + } + } + + write_output(); + + } + +} +" +A22447,"import java.io.IOException; +import java.text.NumberFormat; +import java.util.List; + +public class Welcome extends JamProblem { + + String welc = ""welcome to code jam""; + + public static void main(String[] args) throws IOException { + Welcome p = new Welcome(); + p.go(); + } + + @Override + String solveCase(JamCase jamCase) { + WelcomeCase cas = (WelcomeCase) jamCase; + int length = welc.length(); + int strL = cas.str.length(); + String str = cas.str; + + int[][] tab = new int[length][strL]; + for (int i = length - 1; i >= 0; i--) { + char c = welc.charAt(i); + for (int j = strL - 1; j >= 0; j--) { + if (i == length - 1) { + if (j == strL - 1) { + tab[i][j] = str.charAt(j) == c ? 1 : 0; + } else { + tab[i][j] = mod(tab[i][j + 1] + (str.charAt(j) == c ? 1 : 0)); + } + } else { + if (j == strL - 1) { + tab[i][j] = 0; + } else { + tab[i][j] = mod(tab[i][j + 1] + (str.charAt(j) == c ? 1 : 0) * tab[i + 1][j]); + } + } + } + } + NumberFormat nf = NumberFormat.getInstance(); // Get Instance of NumberFormat + nf.setMinimumIntegerDigits(4); // The minimum Digits required is 5 + nf.setMaximumIntegerDigits(4); // The maximum Digits required is 5 + nf.setGroupingUsed(false); + return nf.format(tab[0][0]); //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + JamCase parseCase(List file, int line) { + WelcomeCase cas = new WelcomeCase(); + cas.lineCount = 1; + cas.str = file.get(line); + return cas; + } + + int mod(int i) { + return i % 10000; + } +} + +class WelcomeCase extends JamCase { + String str; +} +" +A21178,"import java.util.*; + +public class B +{ + static int[] a; + static int[][] dp; + static int n, s, p; + + public static void main(String args[]) + { + Scanner scan = new Scanner(System.in); + + int T = scan.nextInt(); + for(int ca=1;ca <= T;ca++) + { + n = scan.nextInt(); + s = scan.nextInt(); + p = scan.nextInt(); + a = new int[n]; + for(int i=0;i < n;i++) + a[i] = scan.nextInt(); + + dp = new int[n][s+1]; + for(int i=0;i < n;i++) + Arrays.fill(dp[i], -1); + + System.out.println(""Case #"" + ca + "": "" + f(0, s)); + } + + } + + + public static int f(int K, int S) + { + if(K == n) return S == 0 ? 0 : -999999; + if(dp[K][S] != -1) return dp[K][S]; + + int rtn = 0; + + boolean[] b = new boolean[4]; //nobeat nosup, nobeat sup, beat nosup, beat sup + + for(int i=0;i <= 10;i++) + for(int j=0;j <= i;j++) + { + if(i+j > a[K]) continue; + int k = a[K] - (i+j); + if(k > j) continue; + + if(i-k > 2) continue; + + //System.out.println(i + "" "" + j + "" "" + k + "" "" + a[K]); + + if(i >= p && i-k == 2) b[3] = true; + if(i >= p && i-k < 2) b[2] = true; + if(i < p && i-k == 2) b[1] = true; + if(i < p && i-k < 2) b[0] = true; + } + + + if(S == 0 && !b[0] && !b[2]) return -999999; + if(S > 0 && b[1]) rtn = Math.max(rtn, f(K+1, S-1)); + if(S > 0 && b[3]) rtn = Math.max(rtn, f(K+1, S-1)+1); + if(b[0]) rtn = Math.max(rtn, f(K+1, S)); + if(b[2]) rtn = Math.max(rtn, f(K+1, S)+1); + + //System.out.println(K + "" "" + S + "" "" + rtn); + return dp[K][S] = rtn; + + + } +}" +A20795," + +import java.util.*; +import java.io.*; +import java.lang.reflect.Array; + +public class Dance { + + public static String filename = ""Input""; + + + public static void main(String[] args) { + + + try { + Scanner filein = new Scanner(new File(filename+"".in"")); + PrintWriter fileout = new PrintWriter(new FileWriter(filename+"".out"")); + int totalCase = filein.nextInt(); + filein.nextLine(); + Hashtable map = new Hashtable(); + //------------------------------ + int[] f1 = {10, 9, 9, 8, 9, 8, 8, 9, 8, 8, 7, 8, 7, 7, 8, 7, 7, 6, 7, 6, 6, 7, 6, 6, 5, 6, 5, 5, 6, 5, 5, 4, 5, 4, 4, 5, 4, 4, 3, 4, 3, 3, 4, 3, 3, 2, 3, 2, 2, 3, 2, 2, 1, 2, 1, 1, 2, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0}; + int[] f2 = {10, 10, 10, 10, 9, 9, 8, 9, 9, 9, 9, 8, 8, 7, 8, 8, 8, 8, 7, 7, 6, 7, 7, 7, 7, 6, 6, 5, 6, 6, 6, 6, 5, 5, 4, 5, 5, 5, 5, 4, 4, 3, 4, 4, 4, 4, 3, 3, 2, 3, 3, 3, 3, 2, 2, 1, 2, 2, 2, 2, 1, 1, 0, 1, 1, 0, 0}; + int[] f3 = {10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 0}; + int[] tt = {30, 29, 29, 28, 28, 27, 26, 27, 26, 26, 25, 25, 24, 23, 24, 23, 23, 22, 22, 21, 20, 21, 20, 20, 19, 19, 18, 17, 18, 17, 17, 16, 16, 15, 14, 15, 14, 14, 13, 13, 12, 11, 12, 11, 11, 10, 10, 9, 8, 9, 8, 8, 7, 7, 6, 5, 6, 5, 5, 4, 4, 3, 2, 3, 2, 1, 0}; + int[] bo = {0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0}; + System.out.println(""Added array""); + + for(int item=1; item<=totalCase; item++) { + + + //int cases = filein.nextInt(); + //filein.nextLine(); + fileout.print(""Case #"" + (item) + "": ""); + System.out.println(""------------------------------------------------------------------------""); + System.out.println(""Case #"" + (item) + "": ""); + System.out.println(""------------------------------------------------------------------------""); + String str = filein.nextLine(); + String[] tokens = str.split(""\\s""); + System.out.println(tokens.length); + int N= Integer.parseInt(tokens[0]); + System.out.println(""N""+N); + int S= Integer.parseInt(tokens[1]); + System.out.println(""S""+S); + int score= Integer.parseInt(tokens[2]); + System.out.println(""score""+score); + if(score==0) + { + System.out.println(""Total Count:P->0--""+N); + fileout.println(N); + continue; + } + int[] NA=new int[N]; + for(int i =0; i< N ; i++) + { + NA[i]=Integer.parseInt(tokens[3+i]); + } + Arrays.sort(NA); + /* + int tem; + for( int i = 0; i < NA.length/2; ++i ) { + tem = NA[i]; + NA[i] = NA[NA.length - i - 1]; + NA[NA.length - i - 1] = tem; + } + */ + + + + int[] ans= new int[N]; + int surprise=0; + int goal=0; + int goaly[][] = new int[N][2]; + int goal0=0; + int goal1=0; + for (int i =0; i=score||f2[j]>=score||f3[j]>=score) + { + System.out.println(""tt[j]-""+tt[j]); + + System.out.println(""f1[j]-""+f1[j]); + System.out.println(""f2[j]-""+f2[j]); + System.out.println(""f3[j]-""+f3[j]); + System.out.println(""bo[j]-""+bo[j]); + System.out.println(""----------------------""); + if (bo[j]==0) + goaly[i][0]=goaly[i][0]+1; + else + goaly[i][1]=goaly[i][1]+1; + } + } + } + if(goaly[i][0]>0) + goal0++; + if(goaly[i][1]>0) + goal1++; + } + + int counter=0; + HashMap mapr = new HashMap(); + for(int i=0; i< N; i++) + { + if(surprise !=S) + { + if(goaly[i][1]>0 && goaly[i][0]==0) + { + counter++; + surprise++; + mapr.put(i,""Dummy""); + } + } + } + + for(int i=0; i< N; i++) + { + + if(surprise !=S) + { + if(goaly[i][1]>0 && goaly[i][0]>0) + { + counter++; + surprise++; + mapr.put(i,""Dummy""); + } + } + } + + for(int i=0; i< N; i++) + { + + if( !mapr.containsKey(i)) + { + if(goaly[i][0]>0 ) + { + counter++; + } + } + } + + + System.out.println(""Total Count""+counter); + fileout.println(counter); + + + } + + filein.close(); + fileout.close(); + } + catch(IOException e) { + System.out.println(""Error loading input or output file""); + } + } +} + +" +A22049,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + + +class Dance { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + // TODO Auto-generated method stub + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int cases = Integer.parseInt(br.readLine()); + for(int i = 0; i=0;j--){ + int score = scores[j]; + int remaining=0; + while(score%3!=0){ + score--; + remaining++; + } + int average= score/3; + int r = remaining; + if(average>=best){ + count++; + continue; + } + if(remaining>0){ + average++; + remaining -- ; + } + if(average>=best){ + count++; + continue; + } + else if(surprising>0 && (remaining >0 || (r==0&&score>1))){ + average++; + surprising--; + } + if(average>=best) + count++; + else + break; + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } + +} +" +A20028,"package uk.ac.cam.rio22.problemB; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; + +public class ProblemB { + + public static void main (String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + PrintStream out = new PrintStream(new FileOutputStream(""outputBLarge.out"")); + int num = Integer.parseInt(br.readLine()); + for(int n=1;n<=num;n++) { + out.print(""Case #"" + (n) + "": ""); + String[] line = br.readLine().split("" ""); + int surprise = Integer.parseInt(line[1]); + int min = 3*Integer.parseInt(line[2]) - 2; + int count = 0; + for(int i=3;i=min) { + count++; + } + else if(surprise>0 & score>=min-2 & score>1) { + surprise--; + count++; + } + } + + out.println(count); + } + + } + +} +" +A21365,"package qualification.B; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) { + int totalCase = 0; + int supriseCaseNo = 0; + int googlerNo = 0; + int p = 0; + FileInputStream is = null; + try { + is = new FileInputStream(args[0]); + Scanner scan = new Scanner(is); + totalCase = scan.nextInt(); + for (int i = 0; i < totalCase; i++) { + googlerNo = scan.nextInt(); + supriseCaseNo = scan.nextInt(); + p = scan.nextInt(); + int[] scores = new int[googlerNo]; + for (int j = 0; j < googlerNo; j++) { + scores[j] = scan.nextInt(); + } + solve(i, googlerNo, supriseCaseNo, p, scores); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } finally { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private static void solve(int caseNo, int googlerNo, int supriseCaseNo, int p, + int[] scores) { + int answer = 0; + int t = supriseCaseNo; + for (int i = 0; i < googlerNo; i++) { + // •½‹Ï’l‚ÌŒvŽZ + int avg = scores[i] / 3; + int mod = scores[i] % 3; + int diff = avg - p; + if (diff <= -3) { + continue; + } else if (diff >= 0) { + answer++; + } else if (diff == -1) { + if (mod == 0) { + if (t > 0 && p > 1) { + t--; + answer++; + } else { + continue; + } + } else { + answer++; + } + } else if (diff == -2) { + if (mod == 0 || mod == 1) { + continue; + } else if (mod == 2) { + if (t > 0) { + t--; + answer++; + } + } + } + } + StringBuilder sb = new StringBuilder(); + sb.append(""Case #""); + sb.append(caseNo+1); + sb.append("": ""); + sb.append(answer); + System.out.println(sb.toString()); + + } +} +" +A21264,"package codejam2012.r0; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + +/** + * @author julian + */ +public class B { + + public static final void main(String[] args) throws IOException { + (new B()).run(); + } + + private int getBestRes(int v) { + return ((v % 3 == 0) ? 0 : 1) + ((int) v / 3); + } + + private int getBestSurRes(int v) { + return ((v % 3 == 2) ? 2 : Math.min(v, 1)) + ((int) (v / 3)); + } + + public void run() throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""B.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""B.out"")); + int t = Integer.parseInt(in.readLine()); + for (int i = 0; i < t; i++) { + StringTokenizer stok = new StringTokenizer(in.readLine()); + int n = Integer.parseInt(stok.nextToken()); + int s = Integer.parseInt(stok.nextToken()); + int p = Integer.parseInt(stok.nextToken()); + int[] total = new int[n]; + for (int k = 0; k < n; k++) { + total[k] = Integer.parseInt(stok.nextToken()); + } + out.write(""Case #"" + (i + 1) + "": "" + solve(n, s, p, total) + ""\n""); + } + in.close(); + out.flush(); + out.close(); + } + + public int solve(int n, int s, int p, int[] t) { + int good = 0; + int soso = 0; + for (int i = 0; i < n; i++) { + if (getBestRes(t[i]) >= p) { + good++; + } else if (getBestSurRes(t[i]) >= p) { + soso++; + } + } + + return good + Math.min(s, soso); + } + +} +" +A22544,"import java.util.Scanner; + +public class DancingWithTheGooglers { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int t=sc.nextInt(); + for(int i=0;i0?1:0); + if(score>=p){ + ans++; + }else if(s>0 && total>=p){ + int x=(total-p)/2; + if(x+2>=p){ + s--; + ans++; + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+ans); + } + } +} +" +A22568,"package googlecodejam2012.qualification.dancinggooglers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; + +public class DancingGooglers { + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { +// System.out.println(hasWithoutSurprise(6, 2)); +// System.out.println(hasWithoutSurprise(5, 2)); +// System.out.println(hasWithoutSurprise(4, 2)); +// System.out.println(hasWithoutSurprise(7, 2)); +// System.out.println(hasWithoutSurprise(8, 2)); +// System.out.println(hasWithoutSurprise(3, 2)); +// System.out.println(hasWithoutSurprise(1, 1)); +// System.out.println(hasWithoutSurprise(0, 1)); +// System.out.println(); +// System.out.println(hasWithSurprise(6, 2)); +// System.out.println(hasWithSurprise(5, 2)); +// System.out.println(hasWithSurprise(4, 2)); +// System.out.println(hasWithSurprise(7, 2)); +// System.out.println(hasWithSurprise(8, 2)); +// System.out.println(hasWithSurprise(3, 2)); +// System.out.println(""Should be false: "" + hasWithSurprise(2, 3)); +// System.out.println(""Should be false: "" + hasWithSurprise(3, 3)); +// System.out.println(""Should be false: "" + hasWithSurprise(4, 3)); +// System.out.println(""Should be true: "" + hasWithSurprise(5, 3)); +// System.out.println(""Should be true: "" + hasWithSurprise(6, 3)); +// System.out.println(""Should be true: "" + hasWithSurprise(7, 3)); +// System.out.println(""Should be false: "" + hasWithSurprise(0, 1)); + String lineSep = System.getProperty(""line.separator""); + BufferedReader br = new BufferedReader( + args.length > 0 ? new FileReader(args[0]) + : new InputStreamReader(System.in)); + try { + Writer out = new BufferedWriter(args.length > 1 ? new FileWriter(args[1]): new OutputStreamWriter(System.out)); + try { + int numLines = Integer.parseInt(br.readLine().trim()); + for (int i = 1; i <= numLines;++i) { + String line = br.readLine(); + out.write(""Case #"" + i + "": ""+count(line) + lineSep); + } + } finally { + out.close(); + } + } finally { + br.close(); + } + } + + private static int count(String line) { + String[] parts = line.split("" ""); + int n = Integer.parseInt(parts[0]); + int s = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + int[] sumScores = new int[parts.length - 3]; + for (int i = parts.length; i -->3;) { + sumScores[i - 3] = Integer.parseInt(parts[i]); + } + return count(n, s, p, sumScores); + } + + private static int count(int n, int s, int p, int[] sumScores) { + int countWithoutSurprise = 0; + int countWithPossibleSurprise = 0; + for (int sumScore : sumScores) { + if(hasWithoutSurprise(sumScore, p)) { + countWithoutSurprise++; + } else if (hasWithSurprise(sumScore, p)) { + countWithPossibleSurprise++; + } + } + return countWithoutSurprise + Math.min(s, countWithPossibleSurprise); + } + + private static boolean hasWithSurprise(int sumScore, int p) { + return sumScore >= p && (sumScore + 4) /3 >= p; + } + + private static boolean hasWithoutSurprise(int sumScore, int p) { + return (sumScore + 2) / 3 >= p; + } +} +" +A21752,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.*; + +public class main { + + main() throws FileNotFoundException { + Scanner sc = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(""result.txt""); + int tests = sc.nextInt(); + for (int t = 1; t <= tests; t++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + Map> map = new TreeMap<>(); + ArrayList scores = new ArrayList<>(); + + for (int m = 0; m < n; m++) { + int g = sc.nextInt(); + scores.add(g); + map.put(g, dec(g)); + } + + int ww = 0; + int w = 0; + int cw = 0; + for (int i = 0; i < n; i++) { + if (isDecomposeThere(map.get(scores.get(i)), p, true) && isDecomposeThere(map.get(scores.get(i)), p, false)) { + ww++; + } else if (isDecomposeThere(map.get(scores.get(i)), p, true)) { + w++; + } else if (isDecomposeThere(map.get(scores.get(i)), p, false)) { + cw++; + } + } + out.printf(""Case #%d: %d\n"", t, (w >= s) ? (s + cw + ww) : (w + ww + cw)); + } + out.flush(); + } + + public static void main(String[] args) throws FileNotFoundException { + main m = new main(); + } + + public boolean isDecomposeThere(ArrayList ds, int p, boolean surprise) { + for (D dec : ds) { + if (dec.a >= p && dec.surprise == surprise) return true; + } + return false; + } + + public ArrayList dec(int n) { + ArrayList list = new ArrayList<>(); + for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= i; j++) { + for (int k = 0; k <= j; k++) { + if (i - j <= 2 && j - k <= 2 && i - k <= 2 && i + j + k == n) { + boolean surprise = (i - j == 2 || j - k == 2 || i - k == 2); + list.add(new D(i, j, k, surprise)); + } + } + } + } + return list; + } + + class D { + int a, b, c; + boolean surprise; + + public D(int a, int b, int c, boolean surprise) { + this.a = a; + this.b = b; + this.c = c; + this.surprise = surprise; + } + + @Override + public String toString() { + return """" + a + "" "" + b + "" "" + c + "" "" + surprise; + } + } + +}" +A22702,"package jpt.codejam; + +import java.io.PrintStream; +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; + +public class Codejam2012 { + static void solve_Qual_B() throws Exception { + Scanner in = new Scanner(System.in); + PrintStream out = System.out; + + int cases = in.nextInt(); + for (int nCase = 1; nCase <= cases; ++nCase) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int res = 0; + for (int i=0; i=29) max2 = -1; + + if (max1 >= p) ++res; + else if (max2 >= p && S > 0) { + ++res; + --S; + } + } + out.printf(""Case #%d: %d\n"", nCase, res); + } + } + + + static void solve_Qual_C() throws Exception { + Scanner in = new Scanner(System.in); + PrintStream out = System.out; + + int[] ten = new int[8]; + ten[0] = 1; + for (int i=1; i ms = new HashSet(); + for (int n=A; n<=B; ++n) { + int d = 1; + for (int aux=10; aux<=n; aux*=10) ++d; + ms.clear(); + for (int k=1; k=m && n!=m && !ms.contains(m)) ++res; + ms.add(m); + } + } + out.printf(""Case #%d: %d\n"", nCase, res/2); + } + } + + public static void main(String[] args) throws Exception { + solve_Qual_B(); + //solve_Qual_C(); + //solve_1A_A(); + //solve_1A_B(); + //solve_1A_C(); + } +} +" +A22969,"package gcj; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + + public static void main(String[] args) { + + String filenamein = ""B-large.in""; + String filenameout = ""out.txt""; + + try + { + FileInputStream fstreamin = new FileInputStream(filenamein); + DataInputStream in = new DataInputStream(fstreamin); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter fstreamout = new FileWriter(filenameout); + BufferedWriter out = new BufferedWriter(fstreamout); + + String strLine = br.readLine(); + int nCases = Integer.parseInt(strLine); + int counter = 1; + while ((strLine = br.readLine()) != null) + { + System.out.println (strLine); + + String solu = Solve(strLine); + + System.out.println (solu); + System.out.println (); + + out.write(""Case #""+ counter++ +"": "" + solu + ""\n""); + } + + in.close(); + out.close(); + } + catch (Exception e) + { + System.err.println(""Error: "" + e.getMessage()); + } + } + + private static String Solve(String strLine) + { + String[] ss = strLine.split("" ""); + + int n = Integer.parseInt(ss[0]); + int s = Integer.parseInt(ss[1]); + int p = Integer.parseInt(ss[2]); + + int sum = 0; + + int valorIntermedio = 3*p; + + if(valorIntermedio == 0) + { + sum = n; + } + else if(valorIntermedio == 3) + { + int count = 0; + for(int i = 0 ; i < n ; i++) + { + int t = Integer.parseInt(ss[i+3]); + if(t>0) count++; + } + sum = count; + } + else + { + for(int i = 0 ; i < n ; i++) + { + int t = Integer.parseInt(ss[i+3]); + + if(t >= valorIntermedio-2) + { + sum++; + } + + else if(s > 0 && t >= valorIntermedio-4) + { + s--; + sum++; + } + } + } + + return String.valueOf(sum); + } + +} +" +A20626,"/* +GCJ2012-Q +*/ + +import java.io.*; +import java.util.*; +import java.math.*; + +public class GCJ2012QB { + static BufferedReader fin; + static PrintWriter fout; + // change numefile + static String file=""qbl""; + static String infile=file+"".in""; + static String outfile=file+"".out""; + // + + // write result to output file + private static void writetestresult(int test, String ret){ + fout.println(""Case #""+test+"": ""+ret); + } + + // open files + private static void openfiles() throws IOException{ + fin = new BufferedReader(new FileReader(infile)); + fout = new PrintWriter(new BufferedWriter(new FileWriter(outfile))); + } + + // close files + private static void closefiles() throws IOException{ + fin.close(); + fout.close(); + } + + // solve test no. ""test"" + private static String solvetest(int test) throws IOException{ + System.out.println("">>>Solving test...""+test); + // Parse input for test no. test + String a=fin.readLine(); + String[] as=a.split("" ""); + int N=Integer.parseInt(as[0]); + int S=Integer.parseInt(as[1]); + int p=Integer.parseInt(as[2]); + int[] t=new int[N]; + for (int i=0; i=0) || (3*pc-2==t[i] && pc-1>=0)) nes[i]=1; + if ((3*pc-2==t[i] && pc-2>=0) || (3*pc-3==t[i] && pc-2>=0) || (3*pc-4==t[i] && pc-2>=0)) sur[i]=1; + } + iret=0; + int surp=0; + for (int j=0; j { + + /** Return at most n items from the beginning of the Iterable. */ + public static ArrayList head(Iterable collection, int n) { + ArrayList head = new ArrayList(); + int count = n; + if (n > 0) + for (T item : collection) { + head.add(item); + if (--count == 0) + break; + } + return head; + } + + /** Return at most n items from the end of the List. */ + public static ArrayList tail(List list, int n) { + ArrayList tail = new ArrayList(); + for (int len = list.size(), i = Math.max(len - n, 0); i < len; i++) + tail.add(list.get(i)); + return tail; + } + +} +" +A21670,"import java.util.Scanner; + +public class problemB { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner cin = new Scanner(System.in); + int t = cin.nextInt(); + int k = 0, n, s, p, i, ans; + int[] a; + while (t > 0) { + t--; + k++; + n = cin.nextInt(); + s = cin.nextInt(); + p = cin.nextInt(); + a = new int[n]; + for (i = 0; i < n; i++) + a[i] = cin.nextInt(); + ans = 0; + for (i = 0; i < n; i++) { + if(a[i]>=p+Math.max(p-1, 0)*2){ + ans++; + }else + if(a[i]>=p+Math.max(p-2, 0)*2 && s>0){ + ans++; + s--; + } + } + System.out.println(""Case #""+k+"": ""+ans); + } + } + +} +" +A20302,"import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class one { + public static void main(String[] args) { + try { + Scanner in = new Scanner(new File(args[0])); + PrintWriter out = new PrintWriter( new FileWriter(args[1])); + int T = in.nextInt(); + for(int i=0;i=3*p-2) + res++; + else if(s>0 && (t[j]==3*p-3 || t[j]==3*p-4) && t[j]>0) + { + res++; + s--; + } + j++; + } + out.println(""Case #""+(i+1)+"": ""+res); + } + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +" +A22590,"package com.dagova.dancingWithTheGooglers; + +public class DancingWithTheGooglersSolver +{ + private int solution; + private int bestScore; + private int surprisedTriplets; + private int numberOfGooglers; + + + public DancingWithTheGooglersSolver() + { + solution = 0; + } + + + private void checkTotalPoints(int googlerTotalPoints) + { + float quotient = googlerTotalPoints / 3f; + + if(quotient >= bestScore) + solution++; + else + { + googlerTotalPoints -= bestScore; + if(googlerTotalPoints >= 0) + { + quotient = googlerTotalPoints / 2f; + if(quotient + 1 >= bestScore) + solution++; + else + { + if(surprisedTriplets > 0 && quotient + 2 >= bestScore) + { + surprisedTriplets--; + solution++; + } + } + } + } + } + + + public int solve(String line) + { + String[] splittedLine = line.split("" ""); + numberOfGooglers = Integer.parseInt(splittedLine[0]); + surprisedTriplets = Integer.parseInt(splittedLine[1]); + bestScore = Integer.parseInt(splittedLine[2]); + + for(int googler = 0; googler < numberOfGooglers; googler++) + { + checkTotalPoints(Integer.parseInt(splittedLine[3+googler])); + } + + return solution; + } +} +" +A20909,"// Google Code Jam Qualification Round 2012 +// Problem B. Dancing With the Googlers + +import java.util.*; +import java.io.*; + +public class DancingWithTheGooglers { + static String inname = ""B-large.in""; // input file name here + static String outname = ""B-large.out""; // output file name here + public static void main(String[] args){ + try{ + Scanner in = new Scanner(new BufferedReader(new FileReader(inname))); + //Scanner in = new Scanner(System.in); + BufferedWriter out = new BufferedWriter(new FileWriter(outname)); + int n, s, p, t[]; + int T = in.nextInt(); + for (int cas = 1; cas <= T; cas++){ + int ans = 0; + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + t = new int[n]; + for (int i = 0; i < n; i++) + t[i] = in.nextInt(); + for (int i = 0; i < n; i++){ + if (t[i]%3 == 0){ + if (t[i]/3 >= p) ans++; + else if (t[i]/3 == p-1 && t[i] > 1 && s > 0){ + ans++; s--; + } + } else { + if (t[i]/3+1 >= p) ans++; + else if (t[i]/3+1 == p-1 && t[i] > 1 && t[i]%3 == 2 && s > 0){ + ans++; s--; + } + } + } + //System.out.print(""Case #"" + cas + "": "" + ans + ""\n""); + out.write(""Case #"" + cas + "": "" + ans + ""\n""); + } + in.close(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A21707,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +public class CopyOfMain { + + public static void main(String[] args) throws FileNotFoundException { + String file = ""B-large""; + Scanner in = new Scanner(new File(file + "".in"")); + PrintWriter out = new PrintWriter(new File(file + "".out"")); + + int T = in.nextInt(); + for(int t=1; t<=T; t++){ + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int[] scores = new int[N]; + int[] bst = new int[N]; + int[] dmax = new int[N]; + + int nextp=0; + int prevp=0; + for(int i=0; i < scores.length; i++){ + int s = scores[i] = in.nextInt(); + if(s%3==0){ + bst[i]=s/3; + dmax[i] = bst[i]>0?1:0; + }else if(s%3 ==1){ + bst[i]=s/3 + 1; + dmax[i] = 0; + }else{ + bst[i]=s/3 + 1; + dmax[i] = 1; + } + + if(bst[i]>=p) + nextp++; + if(bst[i]==p-1&& dmax[i]>0) + prevp++; + } + out.println(""Case #"" + t + "": ""+(nextp+Math.min(S, prevp)));//+Math.min(S, prevp)); + } + + + in.close(); + out.close(); + } +} +" +A20966,"import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.StringTokenizer; + + +public class Code2 { + + + + private BufferedReader reader = null; + PrintStream out = null; + + public static void main(String[] args) throws Exception { + String file = ""B-small-attempt0""; + Code2 code2 = new Code2(); + try { + code2.reader = new BufferedReader(new FileReader(""source/"" + file + "".in"")); + code2.out = new PrintStream(new FileOutputStream(""source/"" + file + "".out"")); + code2.runCases(); + } finally { + code2.reader.close(); + code2.out.close(); + } + } + + private void runCases() throws IOException { + int cases = getInt(); + for (int c = 1; c <= cases; c++) { + out.print(""Case #"" + c + "": ""); + execute(); + out.print(""\n""); + } + } + + private String readNext() throws IOException { + String s = reader.readLine(); + return s; + } + + private int getInt() throws IOException{ + String s= this.readNext(); + return Integer.valueOf(s); + } + + private void execute() throws IOException { + String s = this.readNext(); + Code2DataStructure ds = new Code2DataStructure(); + StringTokenizer st = new StringTokenizer(s,"" ""); + ds.setNoOfGooglers(Integer.parseInt(st.nextToken())); + ds.setSurprisingTrplets(Integer.parseInt(st.nextToken())); + ds.setP(Integer.parseInt(st.nextToken())); + int[] marks = new int[ds.getNoOfGooglers()]; + for (int i = 0; i < ds.getNoOfGooglers(); i++) { + marks[i] = Integer.parseInt(st.nextToken()); + } + ds.setMarks(marks); + System.out.println(""=========================""); + this.processData(ds); + System.out.println(""=========================""); + out.print(ds.getResult()); + + } + + private void processData(Code2DataStructure ds) { + int marks[] = ds.getMarks(); + Arrays.sort(marks); + int nonsurprisingtripletsCount = 0; + int surprisinggtripletsCount = 0; + int requiredst = ds.getSurprisingTrplets(); + for (int i = 0; i < marks.length; i++) { + if(this.isEligibleForMax(marks[i], ds.getP())) { + if((marks[i] >= (3*ds.getP()-2)) && marks[i] >= ds.getP()) { + nonsurprisingtripletsCount++; + } else if((requiredst > 0) && marks[i] >= ds.getP()){ + requiredst--; + surprisinggtripletsCount++; + } + } + } + System.out.println(""nst ""+nonsurprisingtripletsCount+"" st ""+surprisinggtripletsCount+"" rst ""+ds.getSurprisingTrplets()); +// if(surprisinggtripletsCount > ds.getSurprisingTrplets()) { +// surprisinggtripletsCount = ds.getSurprisingTrplets(); +// } + ds.setResult(surprisinggtripletsCount+nonsurprisingtripletsCount); + } + + private boolean isEligibleForMax(int value, int p) { + if(value >= (3*p - 4)) { + return true; + } + return false; + } + +} +" +A20942,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package codejam.B2012; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B2012 { + + public static void main(String[] args) throws FileNotFoundException { + Scanner scanner = new Scanner(new File(""C:/docs/codejam/2012/B-large.in"")); + PrintWriter output = new PrintWriter(new File(""C:/docs/codejam/2012/B-large.out.txt"")); + + int T = scanner.nextInt(); + for (int i = 1; i < T + 1; i++) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + System.out.println(""N = "" + N + "" | S = "" + S + "" | p = "" + p); + + int c = 0; + int mp = 3 * p - 2; + int smp = 3 * p - 4; + for (int j = 0; j < N; j++) { + int tp = scanner.nextInt(); + System.out.print(tp + "" ""); + if (tp >= mp) { + c++; + } else if (tp >= smp && S > 0 && smp >= 0) { + c++; + S--; + } + } + System.out.println(); + System.out.println(""c = "" + c); + System.out.println(""--------------""); + output.println(""Case #"" + i + "": "" + c); + } + + scanner.close(); + output.close(); + } + +} +" +A21225,"import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class QualB +{ + + + public void run()throws IOException + { + Scanner in = new Scanner(new File(""b.in"")); + PrintWriter out = new PrintWriter(""b.out""); + int nt = in.nextInt(); + in.nextLine(); + for(int it = 1;it <= nt; it++) + { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int [] a = new int[n]; + for(int i=0;i= p) + ret++; + else + { + max = a[i] / 3; + if(a[i] != 0) + max++; + if(q == 2) + max++; + if(max >= p && s > 0) + { + ret++; + s--; + } + } + } + + out.println(""Case #"" + it + "": "" + ret); + } + out.close(); + } + + /** + * @param args + */ + public static void main(String[] args)throws IOException + { + new QualB().run(); + } + +} +" +A22615,"import java.io.*; +import java.util.*; +public class Solve { + + public static void main ( String[] args ) throws FileNotFoundException, IOException { + BufferedReader in = new BufferedReader( new FileReader ( args[0] ) ); + BufferedWriter out = new BufferedWriter( new FileWriter ( ""outfile.txt"" ) ); + int cases = Integer.parseInt( in.readLine() ); + String[] tmp; + int number, surprising, minimum, count, allMax, result; + int[] scores; + for ( int i = 1; i <= cases; i++ ) { + tmp = in.readLine().split( "" "" ); + result = 0; + number = Integer.parseInt( tmp[0] ); + surprising = Integer.parseInt( tmp[1] ); + minimum = Integer.parseInt( tmp[2] ); + scores = new int[ number ]; + allMax = minimum * 3; + for ( int j = 0; j < number; j++ ) { + scores[j] = Integer.parseInt( tmp[ j + 3 ] ); + } + for ( int j = number - 1; j >= 0; j-- ) { + if ( scores[j] > allMax - 3 ) { + result ++; + } + else { + if ( scores[j] >= allMax - 4 && minimum -2 >= 0) { + if ( surprising > 0 ) { + result++; + surprising--; + } + } + } + } + out.write( ""Case #"" + i + "": "" + result ); + out.newLine(); + out.flush(); + } + in.close(); + out.close(); + } + public static String replace( String first, String second, char target, char replacement ) { + String ret = """"; + for ( int i = 0; i < first.length(); i++ ) { + if ( first.charAt( i ) == target ) { + ret = ret + replacement; + } + else { + ret = ret + second.charAt( i ); + } + } + return ret; + } + +} +" +A20060," +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + + +public class B { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + + String ss = reader.readLine(); + int n = Integer.parseInt(ss); + + for (int i = 0; i < n; i++) { + Map map = new HashMap(); + ss = reader.readLine(); + + String[] parts = ss.split("" ""); + int N = Integer.parseInt(parts[0]); + int S = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + + int good = 0; + int sur = 0; + int t = (p - 1) + (p - 1) + p; + int y = p - 2 + p - 2 + p; + + if (p == 0) { + t = 0; + y = 0; + } + if (p == 1) { + t = 1; + y = 1; + } + if (p == 2) { + t = 4; + y = 2; + } + for (int j = 3; j < parts.length; j++) { + int x = Integer.parseInt(parts[j]); + if (x >= t) { + good++; + } else if (x >= y) { + sur++; + } + } + int res = good + Math.min(S, sur); + String sss = ""Case #"" + (i + 1) + "": "" + res ; + System.out.println(sss); + + + } + } +} +" +A21624,"import java.util.*; +import java.io.*; + +public class Solution { + FastScanner in; + PrintWriter out; + + public void solve() throws IOException { + int cases = in.nextInt(); + for (int nowCase = 1; nowCase <= cases; nowCase++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int ans = 0; + for (int i = 0; i < N; i++) { + int t = in.nextInt(); + if ((t + 2) / 3 >= p) { + ans++; + } else { + if ((t + 4) / 3 >= p && S > 0 && (t != 0)) { + S --; + ans++; + } + } + } + // + out.print(""Case #""); + out.print(nowCase); + out.print("": ""); + // + out.print(ans); + // + out.println(); + } + } + + public void run() { + try { + in = new FastScanner(new File(""b.in"")); + out = new PrintWriter(new File(""b.out"")); + + //in = new FastScanner(System.in); + //out = new PrintWriter(System.out); + + solve(); + + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + class FastScanner { + BufferedReader br; + StringTokenizer st; + + FastScanner(File f) { + try { + br = new BufferedReader(new FileReader(f)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + FastScanner(InputStream f) { + br = new BufferedReader(new InputStreamReader(f)); + } + + String next() { + while (st == null || !st.hasMoreTokens()) { + try { + st = new StringTokenizer(br.readLine()); + } catch (IOException e) { + e.printStackTrace(); + } + } + return st.nextToken(); + } + + String readLine() { + try { + return br.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return "" ""; + } + + int nextInt() { + return Integer.parseInt(next()); + } + } + + public static void main(String[] arg) { + new Solution().run(); + } +}" +A20143,"import java.io.File; +import java.io.PrintStream; +import java.util.Scanner; + +class B { + static public void main(String[] args) { + try { + PrintStream out = new PrintStream(new File(""b.out"")); + System.setOut(out); + Scanner theIn=new Scanner(new File(""B-large.in"")); + int t=theIn.nextInt(); + int n; + int s; + int p; + + for (int i=1; i<=t; i++) { + System.out.print(""Case #""+i+"": ""); + n=theIn.nextInt(); + s=theIn.nextInt(); + p=theIn.nextInt(); + int numberP=0; + int leftS=s; + + for (int j=1; j<=n; j++) { + int current=theIn.nextInt(); + + if (((current%3==0) && (current/3>=p)) ||((current%3!=0) && (current/3+1>=p)) ) numberP+=1; else { + if (leftS==0) continue; + if (current<2) continue; + if ((current%3==0) && ((current-3)/3+2>=p)) { + numberP+=1; + leftS-=1; + continue; + } + if ((current%3==1) && ((current-4)/3+2>=p)) { + numberP+=1; + leftS-=1; + continue; + } + if ((current%3==2) && ((current-2)/3+2>=p)) { + numberP+=1; + leftS-=1; + continue; + } + } + + } + System.out.println(numberP); + } + + + } catch (Exception e) {} + } +}" +A20879," +import java.io.BufferedReader; +import java.io.FileReader; + +import java.io.BufferedWriter; +import java.io.FileWriter; + +import java.io.IOException; + +public class Task2 +{ + public static void main(String[] args) + { + try + { + readSolveAndWrite(""B-large.in"", ""output_file.txt""); + } + catch(IOException ioException) { System.err.println(ioException); } + } + + protected static void readSolveAndWrite(final String inputPath, final String outputFile) throws IOException + { + BufferedReader in = new BufferedReader(new FileReader(inputPath)); + BufferedWriter out = new BufferedWriter(new FileWriter(outputFile)); + int n = Integer.parseInt(in.readLine()); + for(int i = 0; i < n; i++) + { + final String inputLine = in.readLine(); + final String outputLine = ""Case #"" + (i + 1) + "": "" + solve(inputLine); + + out.write(outputLine); + out.newLine(); + } + + out.flush(); + out.close(); + in.close(); + } + + protected static String solve(final String line) + { + String[] elements = line.split("" ""); + + final int n = Integer.parseInt(elements[0]); + int s = Integer.parseInt(elements[1]); + final int p = Integer.parseInt(elements[2]); + int array[] = new int[n]; + + for(int i = 0; i < n; i++) + array[i] = Integer.parseInt(elements[3 + i]); + + int result = 0; + for(int i = 0; i < n; i++) + { + final int temp = array[i]; + + if(temp < p) + continue; + + int a = temp / 3; + int b = temp % 3; + + if(b == 0) + { + if(a >= p) + result++; + else if((s > 0) && (a + 1 >= p) && (a - 1 >= 0)) + { + s--; + result++; + } + } + else if(b == 1) + { + if((a >= p) || (a + 1 >= p)) + result++; + } + else if(b == 2) + { + if((a >= p) || (a + 1 >= p)) + result++; + else if((s > 0) && (a + 2 >= p)) + { + s--; + result++; + } + } + } + + return ("""" + result); + } + +}" +A20824,"package Aufgabe2; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Main { + + private Scanner scanner; + private PrintWriter writer; + + public Main(InputStream is, OutputStream os) { + scanner = new Scanner(is); + writer = new PrintWriter(os); + } + + public void solve() { + + // Unit Tests: + int tmp; + int tmp1[] = {15,13,11}; + if (calculate(1, 5, tmp1)!=3) return; + int tmp2[] = {23,22,21}; + if (calculate(0, 8, tmp2)!=2) return; + int tmp3[] = {8,0}; + if (calculate(1, 1, tmp3)!=1) return; + int tmp4[] = {29,20,8,18,18,21}; + if (calculate(2, 8, tmp4)!=3) return; + + for (int i=0; i<200; i++) + System.out.println(""""); + + int cases = scanner.nextInt(); + + for (int i = 1; i <= cases; i++) { + writer.print(""Case #""); + writer.print(i + "": ""); + + scanner.nextLine(); + int n = scanner.nextInt(); // number of Googlers + int s = scanner.nextInt(); // number of surprising triplets + int p = scanner.nextInt(); // minimum score + int t[] = new int[n]; + for (int j = 0; j < n; j++) + t[j] = scanner.nextInt(); + + System.out.println(i + "": MinScore="" + p + "", Surprising Triplets="" + s); + int result = calculate(s, p, t); + + writer.println(result); + System.out.println("" -> "" + result); + System.out.println(""-------------""); + } + writer.flush(); + } + + private int calculate(int noSurprisingScores, + int minimumScore, int[] scores) { + int result = 0; + + for (int score : scores) { + int triplet[] = new int[3]; + System.out.print(score + "": ""); + switch (score % 3) { + case 0: + if (score / 3 >= minimumScore) { + result++; + System.out.println((score / 3) + "","" + (score / 3) + "","" + (score / 3)); + } else { + if (noSurprisingScores > 0) + if (score / 3 + 1 >= minimumScore && score / 3 - 1 >= 0) { + result++; + noSurprisingScores--; + System.out.println((score / 3 - 1) + "","" + (score / 3) + "","" + (score / 3 + 1) + "" *""); + } + } + break; + case 1: + if ((score-1)/3 + 1 >= minimumScore) { + result++; + System.out.println((score-1)/3 + "","" + ((score-1)/3) + "","" + ((score-1)/3 + 1)); + } else { + // Surprising Triplet führt nicht zur Erhöhung des max Scores + } + break; + case 2: + if ((score-2)/3 + 1 >= minimumScore) { + result++; + System.out.println((score-2)/3 + "","" + ((score-2)/3 + 1) + "","" + ((score-2)/3 + 1)); + } else { + if (noSurprisingScores > 0) + if ((score - 2) / 3 + 2 >= minimumScore) { + result++; + noSurprisingScores--; + System.out.println((score-2)/3 + "","" + (score-2)/3 + "","" + ((score-2)/3 + 2) + "" *""); + } + } + break; + } + + } + + return result; + } + + /* + * private boolean exceedsMinumumScore(int[] triplet, int minScore) { for + * (int i=0; i<3; i++) if (triplet[i] >= minScore) return true; return + * false; } + */ + + public static void main(String[] args) { + try { + InputStream is = new FileInputStream(""B-small-attempt.in""); + OutputStream os = new FileOutputStream(""B-small-attempt.out""); + Main problem = new Main(is, os); + problem.solve(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + System.out.println(""finished""); + } +} +" +A21270,"import java.io.*; +import java.util.*; + +public class DancingWithTheGooglers +{ + static int surprise, target; + static int [] scores; + static int numGooglers; + + static int [][] matrix; + public static void main(String[] args) throws IOException + { + Scanner scan = new Scanner(new File(""b_large.in"")); + + int numCases = scan.nextInt(); + for (int z = 1; z <= numCases; z++) + { + numGooglers = scan.nextInt(); + surprise = scan.nextInt(); + target = scan.nextInt(); + + scores = new int[numGooglers]; + for (int i = 0; i < numGooglers; i++) + scores[i] = scan.nextInt(); + + matrix = new int[numGooglers][surprise+1]; + for (int [] arr : matrix) + Arrays.fill(arr, -1); + + int max = magic(0, surprise); + + System.out.println(""Case #""+z+"": "" + max); + } + } + + static int magic(int pos, int surpriseLeft) + { + if (surpriseLeft < 0) + return -1000000; + if (pos == numGooglers) + { + if (surpriseLeft != 0) + return -1000000; + else + return 0; + } + + if (matrix[pos][surpriseLeft] >= 0) + return matrix[pos][surpriseLeft]; + + int best = 0; + for (int i = 0; i <= 10; i++) + { + for (int j = Math.max(i-2, 0); j <= Math.min(10,i+2); j++) + { + for (int k = Math.max(i-2, 0); k <= Math.min(10,i+2); k++) + { + if (Math.abs(i-j) > 2 || Math.abs(j-k) > 2 || Math.abs(i-k) > 2) + continue; + if (i + j + k != scores[pos]) + continue; + + int score = 0; + if (i >= target || j >= target || k >= target) + score = 1; + + if (Math.abs(i-j) > 1 || Math.abs(j-k) > 1 || Math.abs(i-k) > 1) + best = Math.max(best, score+magic(pos+1, surpriseLeft-1)); + else + best = Math.max(best, score+magic(pos+1, surpriseLeft)); + } + } + } + matrix[pos][surpriseLeft] = best; + return best; + } +} +" +A20032,"import java.io.*; +import java.util.*; +public class GoogleDancing { + public static void main(String[] args) throws IOException { + BufferedReader read = new BufferedReader(new FileReader(""B-large.in.txt"")); + int T = Integer.parseInt(read.readLine()); + for(int i = 1; i <= T; i++){ + StringTokenizer st = new StringTokenizer(read.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int P = Integer.parseInt(st.nextToken()); + if(P == 0) { + System.out.println(""Case #"" + i + "": "" + N); + continue; + } + int total = 0; + for(int j = 0; j < N; j++) { + int temp = Integer.parseInt(st.nextToken()); + if(temp == 0) + continue; + int q = temp/3 + ((temp%3 == 0)? 0:1); + if(P <= q) + total++; + else if(temp%3 != 1) { + if(P <= q+1 && S > 0) { + total++; + S--; + } + } + } + System.out.println(""Case #"" + i + "": "" + total); + } + + } +} +" +A21799,"import java.util.Scanner; + +public class DWG +{ + public static int[] SuspA = null; + public static int[] nonSuspA = null; + + /** + * @param args + */ + public static void main(String[] args) + { + + Scanner scnr = new Scanner(System.in); + int T = scnr.nextInt(); + for (int t = 1; t <= T; t++) + { + + int N = scnr.nextInt(); + int S = scnr.nextInt(); + int p = scnr.nextInt(); + + SuspA = new int[N]; + nonSuspA = new int[N]; + + int ans = 0; + int suspCount = 0; + + for (int n = 0; n < N; n++) + { + int x = scnr.nextInt(); + calcCombs(x, p, n); + //System.out.printf ( ""a (%d) b (%d) \n"" , SuspA[n], nonSuspA[n]); + + if (nonSuspA[n] > 0) + { + ans++; + } else + { + if (SuspA[n] > 0 && suspCount < S) + { + ans++; + suspCount++; + } + } + } + System.out.println(""Case #"" + t + "": "" + ans); + // System.out.printf(""Case #%d: %d\n"", t, ans); + } + } + + private static void calcCombs(int n, int p, int index) + { + int sum = n; + int minP = p; + int susp = 0; + int nonSusp = 0; + for (int i = 0; i <= 10; i++) + { + for (int j = 0; j <= 10; j++) + { + for (int k = 0; k <= 10; k++) + { + if (i + j + k == sum) + { + if (i >= minP || j >= minP || k >= minP) + { + if (Math.abs(i - j) > 2 || Math.abs(j - k) > 2 || Math.abs(i - k) > 2 ) + { + continue; + } + if (Math.abs(i - j) == 2 || Math.abs(j - k) == 2 || Math.abs(i - k) == 2 ) + { + if (i == j && j == k) + { + susp = susp + 3; + } else + { + susp++; + } + //System.out.printf("" susp (%d)(%d)(%d) \n "", i , j, k); + } else + { + if (i == j && j == k) + { + nonSusp = nonSusp + 3; + } else + { + nonSusp++; + } + nonSusp++; + //System.out.printf("" nonsusp (%d)(%d)(%d) \n "", i , j, k); + } + } + } + } + } + } + //System.out.printf(""susp: %d nonsusp: %d"", susp/3, nonSusp/3); + SuspA[index] = susp / 3; + nonSuspA[index] = nonSusp / 3; + } + +} +" +A22264,"import java.io.*; +import java.util.*; +import static java.lang.System.*; + +public class ProblemB { + + + public class Case { + int numSurprising; + int bestResultThreshold; + ArrayList points = new ArrayList(); + + ArrayList> findTriples(int sum, int maxDiff) { + int floor = sum / 3; + int ceil = (sum + 2) / 3; + + int min = Math.max(ceil - maxDiff, 0); + int max = Math.min(floor + maxDiff, 10); + + ArrayList> ts = new ArrayList>(); + for (int i1 = min; i1 <= max; i1++) { + for (int i2 = min; i2 <= max; i2++) { + loop: + for (int i3 = min; i3 <= max; i3++) { + ArrayList t = new ArrayList(); + t.add(i1); + t.add(i2); + t.add(i3); + + int s = 0; + for (int i : t) s += i; + if (s != sum) continue; + + for (int i : t) { + for (int k : t) { + if (Math.abs(i - k) > maxDiff) continue loop; + } + } + + ts.add(t); + } + } + } + + return ts; + } + + int getMax(ArrayList t) { + Integer max = null; + for (Integer i : t) { + if (max == null || i > max) max = i; + } + return max; + } + + public void solve(int caseIndex) { + + int numBest = 0; + + loop: + for (int p : points) { + { + ArrayList> ts = findTriples(p, 1); + for (ArrayList t : ts) { + if (getMax(t) >= bestResultThreshold) { + numBest++; + continue loop; + } + } + } + + if (numSurprising > 0) { + ArrayList> ts = findTriples(p, 2); + for (ArrayList t : ts) { + if (getMax(t) >= bestResultThreshold) { + numBest++; + numSurprising--; + continue loop; + } + } + } + +// int baseBest = (p + 2) / 3; +// if (baseBest >= bestResultThreshold) { +// numBest++; +// } +// else { +// if (numSurprising > 0) { +// +// } +// } + } + + println(""Case #"" + (caseIndex + 1) + "": ""+numBest); + } + + } + + public void run() throws Exception { + + BufferedReader r = new BufferedReader(new FileReader(""input.txt"")); + int numCases = new InputParser(r.readLine()).readInt(); + + for (int caseIndex = 0; caseIndex < numCases; caseIndex++) { + Case c = new Case(); + + InputParser p = new InputParser(r.readLine()); + + int googlers = p.readInt(); + c.numSurprising = p.readInt(); + c.bestResultThreshold = p.readInt(); + for (int i = 0; i < googlers; i++) { + c.points.add(p.readInt()); + } + + c.solve(caseIndex); + } + + r.close(); + } + + public static void main(String[] args) throws Exception { + fileWriter = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(""output.txt"")))); + new ProblemB().run(); + fileWriter.close(); + } + + public static class InputParser { + String text; + int pos; + + public InputParser(String text) { + this.text = text; + } + + public void skipSpaces() { + while (pos < text.length()) { + if (text.charAt(pos) != ' ') break; + pos++; + } + } + + public String readUntil(char expectedChar) { + StringBuilder b = new StringBuilder(); + while (pos < text.length()) { + char ch = text.charAt(pos); + if (ch == expectedChar) break; + b.append(ch); + pos++; + } + return b.toString(); + } + + public String readToken() { + skipSpaces(); + return readUntil(' '); + } + + public int readInt() { + return Integer.parseInt(readToken()); + } + + public long readLong() { + return Long.parseLong(readToken()); + } + + public char readChar() { + char ch = text.charAt(pos); + pos++; + return ch; + } + + public void readExpectedString(String s) { + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + if (readChar() != ch) throw new RuntimeException(""Expected: ""+ch); + } + } + } + + public static PrintWriter fileWriter; + + public static void print(String text) { + fileWriter.print(text); + System.out.print(text); + } + + public static void println(String text) { + fileWriter.println(text); + System.out.println(text); + } + + public static void addToMultiMapArrayList(Key key, Value value, Map> map) { + ArrayList list = map.get(key); + if (list == null) { + list = new ArrayList(); + map.put(key, list); + } + list.add(value); + } + + public static void addToMultiMapLinkedHashSet(Key key, Value value, Map> map) { + LinkedHashSet list = map.get(key); + if (list == null) { + list = new LinkedHashSet(); + map.put(key, list); + } + list.add(value); + } + + public static ArrayList getMultiMapValues(Map> map) { + ArrayList result = new ArrayList(); + for (Collection list : map.values()) { + result.addAll(list); + } + return result; + } + + +} +" +A20981,"package fixjava; + +/** + * Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method + * in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in + * Java. + */ + +public interface Lambda2 { + public V apply(P param1, Q param2); +} +" +A21027,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +public class b { + + public static void main(String[] args) throws IOException { + BufferedReader bd= new BufferedReader(new InputStreamReader(System.in)); + int li= Integer.parseInt(bd.readLine()); + for (int i = 1; i <=li; i++) { + String[] cadena=bd.readLine().split("" ""); + int n=Integer.parseInt(cadena[0]); + int s=Integer.parseInt(cadena[1]); + int p=Integer.parseInt(cadena[2]); + + int min=p+(2*(p-1)); + int mins=(p+(2*(p-2))<0)?1:(p+(2*(p-2))); + + int[] c = new int[n]; + int res=0; + for (int j = 0; j < n; j++) { + c[j]=Integer.parseInt(cadena[3+j]); + if(c[j]>=min){ + res++; + //System.out.println(c[j]); + } + else if((c[j]>=mins)&&s>0){ + res++; + s--; + //System.out.println(c[j]); + } + + } + System.out.println(""Case #""+i+"": ""+res); + } + } + static boolean saleConP(int t,int p){ + + + return false; + } + static boolean saleConPS(int t,int p){ + + + return false; + } +} + " +A22141,"/************************************************************************* + * Compilation: javac StdOut.java + * Execution: java StdOut + * + * Writes data of various types to standard output. + * + *************************************************************************/ + +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.Locale; + +/** + * Standard output. This class provides methods for writing strings + * and numbers to standard output. + *

+ * For additional documentation, see Section 1.5 of + * Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne. + */ +public final class StdOut { + + // force Unicode UTF-8 encoding; otherwise it's system dependent + private static final String UTF8 = ""UTF-8""; + + // assume language = English, country = US for consistency with StdIn + private static final Locale US_LOCALE = new Locale(""en"", ""US""); + + // send output here + private static PrintWriter out; + + // this is called before invoking any methods + static { + try { + out = new PrintWriter(new OutputStreamWriter(System.out, UTF8), true); + } + catch (UnsupportedEncodingException e) { System.out.println(e); } + } + + // singleton pattern - can't instantiate + private StdOut() { } + + // close the output stream (not required) + /** + * Close standard output. + */ + public static void close() { + out.close(); + } + + /** + * Terminate the current line by printing the line separator string. + */ + public static void println() { + out.println(); + } + + /** + * Print an object to standard output and then terminate the line. + */ + public static void println(Object x) { + out.println(x); + } + + /** + * Print a boolean to standard output and then terminate the line. + */ + public static void println(boolean x) { + out.println(x); + } + + /** + * Print a char to standard output and then terminate the line. + */ + public static void println(char x) { + out.println(x); + } + + /** + * Print a double to standard output and then terminate the line. + */ + public static void println(double x) { + out.println(x); + } + + /** + * Print a float to standard output and then terminate the line. + */ + public static void println(float x) { + out.println(x); + } + + /** + * Print an int to standard output and then terminate the line. + */ + public static void println(int x) { + out.println(x); + } + + /** + * Print a long to standard output and then terminate the line. + */ + public static void println(long x) { + out.println(x); + } + + /** + * Print a short to standard output and then terminate the line. + */ + public static void println(short x) { + out.println(x); + } + + /** + * Print a byte to standard output and then terminate the line. + */ + public static void println(byte x) { + out.println(x); + } + + /** + * Flush standard output. + */ + public static void print() { + out.flush(); + } + + /** + * Print an Object to standard output and flush standard output. + */ + public static void print(Object x) { + out.print(x); + out.flush(); + } + + /** + * Print a boolean to standard output and flush standard output. + */ + public static void print(boolean x) { + out.print(x); + out.flush(); + } + + /** + * Print a char to standard output and flush standard output. + */ + public static void print(char x) { + out.print(x); + out.flush(); + } + + /** + * Print a double to standard output and flush standard output. + */ + public static void print(double x) { + out.print(x); + out.flush(); + } + + /** + * Print a float to standard output and flush standard output. + */ + public static void print(float x) { + out.print(x); + out.flush(); + } + + /** + * Print an int to standard output and flush standard output. + */ + public static void print(int x) { + out.print(x); + out.flush(); + } + + /** + * Print a long to standard output and flush standard output. + */ + public static void print(long x) { + out.print(x); + out.flush(); + } + + /** + * Print a short to standard output and flush standard output. + */ + public static void print(short x) { + out.print(x); + out.flush(); + } + + /** + * Print a byte to standard output and flush standard output. + */ + public static void print(byte x) { + out.print(x); + out.flush(); + } + + /** + * Print a formatted string to standard output using the specified + * format string and arguments, and flush standard output. + */ + public static void printf(String format, Object... args) { + out.printf(US_LOCALE, format, args); + out.flush(); + } + + /** + * Print a formatted string to standard output using the specified + * locale, format string, and arguments, and flush standard output. + */ + public static void printf(Locale locale, String format, Object... args) { + out.printf(locale, format, args); + out.flush(); + } + + // This method is just here to test the class + public static void main(String[] args) { + + // write to stdout + StdOut.println(""Test""); + StdOut.println(17); + StdOut.println(true); + StdOut.printf(""%.6f\n"", 1.0/7.0); + } + +} +" +A20522,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; + +public class B { + final static String CASE_NO = ""Case #""; + final static String SUFFIX = "": ""; + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + int total; + int T; // nuber of test cases + int N; // number of googlers + int S; // number of surprising triplets + int P; + + BufferedReader br = readFile(""B-small.txt""); + + T = Integer.parseInt(br.readLine()); + total = T; + while (T > 0) { + T--; + String line = br.readLine(); + String[] input = line.split("" ""); + int i = 0; + N = Integer.parseInt(input[i++]); + S = Integer.parseInt(input[i++]); + P = Integer.parseInt(input[i++]); + int countP = 0; + + while (N > 0) { + N--; + int t = Integer.parseInt(input[i++]); + int mod3 = t % 3; + int bestResult = 0; + + + // getting best result from triplet + if (mod3 == 0) { + bestResult = t / 3; + } else if (mod3 == 1) + bestResult = ((t + 2) / 3); + else if (mod3 == 2) + bestResult = ((t + 1) / 3); + else { + throw new Exception(""something's wrong with mod3""); + } + + // satisfies P? + if (bestResult >= P) { + countP++; + } else { + // surprising score allowed? + if (S > 0 && t > 0 && mod3 != 1) { + bestResult += 1; + + if (bestResult >= P) { + countP++; + S--; + } + + } + } + + } + System.out.println(CASE_NO + (total - T) + SUFFIX + countP); + // System.out.println(N + "" "" + S + "" "" + P); + + } + + } + + private static BufferedReader readFile(String fileName) + throws FileNotFoundException { + + FileReader fr = new FileReader(fileName); + BufferedReader br = new BufferedReader(fr); + return br; + } + +} +" +A22721,"import java.util.Scanner; + +public class DancingWithTheGooglers { + + public static void main(String[] argv) { + + int lineCounter,numberOfLines,people,currentScore; + int surprises,scoreToBeat,counter,answer; + int possibleScore; + Scanner input = null; + + try {input = new Scanner(System.in);} + catch (Exception e) { System.err.println(""FileNotFoundException: "" + e.getMessage()); } + + numberOfLines = input.nextInt(); + + for (lineCounter = 0; lineCounter < numberOfLines; lineCounter++) { + answer = 0; + input.nextLine(); + people = input.nextInt(); + surprises = input.nextInt(); + scoreToBeat = input.nextInt(); + + for (counter = 0; counter < people; counter++) { + currentScore = input.nextInt(); + possibleScore = scoreNoSurprise(currentScore); + if (possibleScore >= scoreToBeat) + answer++; + else if (surprises > 0) { + possibleScore = scoreSurprise(currentScore); + if (possibleScore >= scoreToBeat) { + answer++; + surprises--; + } + } + } + + System.out.printf(""Case #%d: %d\n"",lineCounter+1,answer); + + } + + } + + public static int scoreNoSurprise(int value) { + if (value < 2) + return value; + if (value == 2) + return 1; + int totalScore = value; + int divergence = totalScore%3; + int baseScore = totalScore/3; + if (divergence == 2) { + return baseScore+1; + } + else if (divergence == 1) { + return baseScore+1; + } + else { // divergence == 0 + return baseScore; + } + } + + public static int scoreSurprise(int value) { + if (value < 3) + return value; + int totalScore = value; + int divergence = totalScore%3; + int baseScore = totalScore/3; + if (divergence == 2) { + return baseScore+2; + } + else if (divergence == 1) { + return baseScore+1; + } + else { // divergence == 0 + return baseScore+1; + } + } + +} +" +A23082,"package com.eevoskos.codejam; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class DancingWithTheGooglers { + + static boolean DEBUG = false; + + class Googler implements Comparable { + List triplets; + + public Googler(List triplets) { + Collections.sort(triplets); + this.triplets = triplets; + } + + List getSuprisingTriplets() { + List surprising = new ArrayList(); + for (Triplet t : triplets) { + if (t.isSurprising()) { + surprising.add(t); + } + } + return surprising; + } + + Triplet bestScoreTriplet() { + Collections.sort(triplets); + return triplets.get(0); + } + + @Override + public int compareTo(Googler another) { + return this.bestScoreTriplet().compareTo(another.bestScoreTriplet()); + } + + List tripletsWithBestScoreAtLeast(int p) { + List list = new ArrayList(); + for (Triplet t : triplets) { + if (t.bestResult() >= p) { + list.add(t); + } + } + return list; + } + + int[] numOftripletsWithBestScoreAtLeast(int p) { + // result[0]: number of triplets + // result[1]: number of the triplets that are surprising + int[] result = new int[2]; + result[0] = 0; + result[1] = 0; + for (Triplet t : triplets) { + if (t.bestResult() >= p) { + result[0]++; + if (t.isSurprising()) { + result[1]++; + } + } + } + return result; + } + } + + class Triplet implements Comparable { + int x, y, z; + + Triplet(int x, int y, int z) { + int[] n = new int[] { x, y, z }; + Arrays.sort(n); + this.x = n[0]; + this.y = n[1]; + this.z = n[2]; + } + + int sum() { + return x + y + z; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) + return false; + + if (!(obj instanceof Triplet)) + return false; + + return x == ((Triplet) obj).x + && y == ((Triplet) obj).y + && z == ((Triplet) obj).z; + } + + boolean isSurprising() { + int[] n = new int[] {x, y, z}; + Arrays.sort(n); + return n[2] - n[0] == 2; + } + + @Override + public String toString() { + String s = x + "" "" + y + "" "" + z; + if (isSurprising()) { + s += "" (*)""; + } + return s; + } + + int bestResult() { + return z; + } + + @Override + public int compareTo(Triplet another) { + if (this.bestResult() > another.bestResult()) { + return 1; + } else if (this.bestResult() < another.bestResult()) { + return -1; + } else { + return 0; + } + } + } + + int solveCase(String input) { + String[] args = input.split("" ""); + + // Number of Googlers + int N = Integer.valueOf(args[0]); + + // Number of surprising triplets + int S = Integer.valueOf(args[1]); + + // Min best score + int p = Integer.valueOf(args[2]); + + // Total points of Googlers + int[] t = new int[args.length - 3]; + for (int i = 0; i < t.length; i++) { + t[i] = Integer.valueOf(args[i + 3]); + } + + if (DEBUG) + printInput(N, S, p, t); + + return calcResult(N, S, p, t); + } + + int calcResult(int N, int S, int p, int[] t) { + int result = 0; + + List googlers = new ArrayList(); + + // For each Googler + for (int i = 0; i < N; i++) { + // Calculate possible combinations of scores + List triplets = getCombinations(t[i]); + googlers.add(new Googler(triplets)); + if (DEBUG) { + System.out.println(""Googler #"" + (i + 1)); + for (Triplet tri : triplets) { + System.out.println(tri); + } + System.out.println(""""); + } + } + + // Sort by best score + Collections.sort(googlers); + + int surprising = 0; + + for (Googler g : googlers) { + List qt = g.tripletsWithBestScoreAtLeast(p); + boolean finishThis = false; + for (Triplet tri : qt) { + if (finishThis) { + continue; + } else if (!tri.isSurprising()) { + result++; + finishThis = true; + continue; + } else { + if (surprising >= S) { + continue; + } else { + surprising++; + result++; + finishThis = true; + continue; + } + } + } + + } + + return result; + } + + List getCombinations(int sum) { + List triplets = new ArrayList(); + for (int x = 0; x <= 10; x++) { + for (int y = 0; y <= 10; y++) { + for (int z = 0; z <= 10; z++) { + Triplet triplet = new Triplet(x, y, z); + if (triplet.sum() == sum) { + if (triplet.z - triplet.x > 2) { + // Impossible case, skip + continue; + } else if(triplets.contains(triplet)) { + // Don't add if duplicate + continue; + } else { + triplets.add(triplet); + } + } else { + // Sum is not proper, skip + continue; + } + } + } + } + return triplets; + } + + static int factorial(int n) { + if (n <= 1) { + return 1; + } else { + return n * factorial(n - 1); + } + } + + static void printInput(int N, int S, int p, int[] t) { + String output = ""\n""; + output += N + "" Googlers, ""; + output += S + "" surprising results. ""; + output += ""How many had best score equal to or greater than "" + p + ""? ""; + output += ""(scores: ""; + for (int i = 0; i < t.length; i++) { + if (i != 0) { + output += "", ""; + } + output += t[i]; + } + output += "")""; + System.out.println(output); + } + + public static void main(String... args) { + DancingWithTheGooglers dancing = new DancingWithTheGooglers(); + + try { + + BufferedReader c = new BufferedReader(new InputStreamReader(System.in)); + + // Number of test cases + int T = Integer.valueOf(c.readLine()); + + System.out.println(); + + // Do, for each test case + for (int i = 0; i < T; i++) { + + // Googlerese string + String input = c.readLine(); + + // Process input + int output = dancing.solveCase(input); + + // Print the translated text + System.out.println(""Case #"" + (i + 1) + "": "" + output); + + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} +" +A21321," +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.Writer; +import java.util.Scanner; + + +public class IOHelper{ + Scanner sc=null; + Writer output=null; + + public IOHelper(String input,String ouptPut){ + try{ + sc=new Scanner(new File(input)); + output=new BufferedWriter(new FileWriter(ouptPut)); + }catch(Exception e){ + e.printStackTrace(); + } + } + public String readLine(){ + String result=null; + result=sc.nextLine(); + while(sc.hasNextLine()&& (result=="" "" ||result==null|| result=="""")){ + result=sc.nextLine(); + } + return result; + } + + public void writeLine(String line){ + try{ + output.write(line); + output.write('\n'); + output.flush(); + }catch(Exception e){ + e.printStackTrace(); + } + + } + public void close(){ + try{ + output.flush(); + output.close(); + sc.close(); + }catch(Exception e){ + e.printStackTrace(); + } + } + +} +" +A22712,"package prob2; + +import java.util.Scanner; + +public class Prob2{ + public static void main(String[] args){ + Scanner scan=new Scanner(System.in); + int n=Integer.parseInt(scan.nextLine()); + for(int i=0;i=p) { + count++; + } else if(specPoss(j)&&maxSpecial(j)>=p) { + needSpec++; + } + } + return count+Math.min(needSpec,s); + } + public static int maxSpecial(int sum){ + return ((sum-2)/3)+2; + } + public static boolean specPoss(int sum){ + return 2<=sum&&sum<=28; + } + public static int maxReg(int sum){ + return (sum+2)/3; + } +}" +A20166,"package qualification; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithTheGooglers { + static int T; + static int[] result; + + public static void main(String[] args) throws IOException { + read(); + write(); + } + + static void read() throws IOException { + File input = new File(""input.txt""); + Scanner scanner = new Scanner(input); + T = scanner.nextInt(); + result = new int[T]; + for (int t=0; t= 3*p-2) { + r++; + } else if ((score >= 3*p-4) && (S > 0) && (p >= 2)) { + r++; + S--; + } + } + result[t] = r; + } + } + + static void write() throws IOException { + File output = new File(""output.txt""); + PrintWriter pw = new PrintWriter(output); + + for (int t=0; t 0 ? p * 3 - 3 : 0; + int thresholdS = p * 3 - 5 > 0 ? p * 3 - 5 : 0; + + for( int i = 3; i < n + 3; i++ ) { + int score = Integer.parseInt( numbers[ i ] ); + + if( p == 0 ) { + results++; + } else if( score > ( thresholdNotS ) ) { + results++; + } else if( s > 0 && score > thresholdS ) { + results++; + s--; + } + } + + System.out.println( ""Case #"" + ( lineNumber + 1 ) + "": "" + results ); + } +} +" +A23080,"package info.stephenn.codejam2012.qualify; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class B { + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + + int cases = sc.nextInt(); + + for(int caseX=1; caseX <= cases; caseX+=1){ + int nGoogles = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + List gTot = new ArrayList(); + for (int i = 0; i < nGoogles; i++){ + gTot.add(sc.nextInt()); + } + int y = doit(gTot, s,p); + System.out.println(""Case #""+caseX+"": ""+y); + } + } + + public static int doit(List gTot, int s, int p){ + Collections.sort(gTot); + + int y=0; + + for (int i=0; i < gTot.size(); i++){ + if (greatestNonSurprising(gTot.get(i)) < p){ + if (s > 0){ + if (greatestSurprising(gTot.get(i)) >= p){ + y +=1; + s -=1; + } + } + } else { + y += ((gTot.size()) - (i)); + break; + } + } + + return y; + } + + public static int greatestSurprising(int gTot){ + int x = gTot / 3; + if ((gTot %3) == 0 && gTot > 2 ) x +=1; + if ((gTot % 3) == 1) x+=1; + else if ((gTot % 3) == 2) x+=2; + return x; + } + + public static int greatestNonSurprising(int gTot){ + int x = gTot/3; + if ((gTot % 3) > 0) x+=1; + if (x > 10){ + //shouldnt happen, . + return 10; + } else{ + return x; + } + } +}" +A20775,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package qualification.Dancing; + +import java.util.*; + +/** + * + * @author farshid + */ +public class Dancing { + + public Dancing() { + } + + public int solve(String problem) { + String[] arr = problem.split("" ""); + + int n = Integer.parseInt(arr[0]); + int s = Integer.parseInt(arr[1]); + int p = Integer.parseInt(arr[2]); + int[] scores = new int[arr.length - 3]; + + for (int i = 3; i < arr.length; i++) { + scores[i - 3] = Integer.parseInt(arr[i]); + } + + LinkedList> combs = + new LinkedList>(); + + for (int i = 0; i < scores.length; i++) { + LinkedList l = this.dancerPossibleCombs(scores[i], p); + combs.add(l); + } + + int max = this.processCombination(combs, s); + + return max; + } + + public void test() { + + } + + private int processCombination(LinkedList> combs, int maxSur) { + + int max = 0; + int currentSur = 0; + + for (int i = 0; i < combs.size(); i++) { + LinkedList current = combs.get(i); + boolean increased = false; + + for (int j = 0; j < current.size(); j++) { + if (!current.get(j).isSurprising()){ + max++; + increased = true; + break; + } + } + + if (!increased && !current.isEmpty() && currentSur < maxSur){ + max++; + currentSur++; + } + } + + return max; + } + + private LinkedList dancerPossibleCombs(int total, int p) { + + LinkedList list = new LinkedList(); + + // Get all possible combs + for (int i = 0; i <= 10; i++) { + + if ((i + 2) >= p && (3 * i) + 4 >= total) { // otherwise no possible/useful combination + + // 8 possible combs + if (3 * i == total && i >= p) { + Combination c = new Combination( + new int[]{i, i, i}, false); + list.add(c); + continue; + } + if ((3 * i + 1) == total && (i + 1) >= p) { + Combination c = new Combination( + new int[]{i, i, i + 1}, false); + list.add(c); + continue; + } + + if ((3 * i + 2) == total) { + if (i + 2 >= p) { + Combination c1 = new Combination( + new int[]{i, i, i + 2}, true); + list.add(c1); + } + if (i + 1 >= p) { + Combination c2 = new Combination( + new int[]{i, i + 1, i + 1}, false); + + list.add(c2); + } + + continue; + } + + if (3 * i + 3 == total && (i + 2) >= p) { + Combination c = new Combination( + new int[]{i, i + 1, i + 2}, true); + list.add(c); + continue; + } + + if (3 * i + 4 == total && (i + 2) >= p) { + Combination c1 = new Combination( + new int[]{i, i + 2, i + 2}, true); + list.add(c1); + } + } + } + + return list; + + } +} +" +A21662,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.StringTokenizer; + + +public class googleDancers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + ArrayList lstInt = new ArrayList(); + boolean error_ni = false; + try{ + FileReader fr=new FileReader(""B-large.in""); + + BufferedReader br = new BufferedReader (fr); + int numCases = Integer.parseInt(br.readLine()); + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""solution.txt""))); + int i; + + + for(i=1; i<=numCases; i++ ){ + String linea = new String(br.readLine()); + StringTokenizer palabraSeparation = new StringTokenizer(linea); + lstInt.clear(); + int N = Integer.parseInt(palabraSeparation.nextToken()); + int S = Integer.parseInt(palabraSeparation.nextToken()); + int p = Integer.parseInt(palabraSeparation.nextToken()); + int solution = 0; + int surprising = 0; + while(palabraSeparation.hasMoreTokens() != false){ + int num_i = Integer.parseInt(palabraSeparation.nextToken()); + lstInt.add(num_i); + /*if (num_i > 30) + error_ni = true;*/ + } + + + + if ((S>=0 && S <= N) && (p>= 0 && p <= 10) && error_ni == false){ + if (p==0){ + solution = lstInt.size(); + + } + else + for (int j=0; j0) solution++; + } + else if (p*3 <= lstInt.get(j) && lstInt.get(j)!=0 ){ + solution++; + } + else if(p*3-2 <= lstInt.get(j) && p>=1 && lstInt.get(j)!=0 ){ + solution++; + } + else if(p*3-4 <= lstInt.get(j) && lstInt.get(j) >= 2 && lstInt.get(j)<=28){ + surprising++; + } + + } + if(S >= surprising) + solution +=surprising; + else if(S < surprising ) + solution +=S; + } + + + //System.out.println(""Case #"" + i+"": ""+solution); + bw.write(""Case #"" + i+"": ""+solution); + bw.newLine(); + + } + + bw.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + + + + + } + +} +" +A22096,"import java.io.*; + +class Programa +{ +static boolean alcanza2(int a,int b) +{ + int j1=0,j2=0,j3=0; + for (int i=0;i<=30;i++) + { + if (i+(i+2)+(i+2)==a) + { + j1=i; + j2=i+2; + j3=i+2; + } + if (i+i+(i+2)==a) + { + j1=i; + j2=i+2; + j3=i; + } + if (i+(i+1)+(i+2)==a) + { + j1=i; + j2=i+2; + j3=i+1; + } + // System.out.println("" ""+a+"" -> ""+j1+"" ""+j2+"" ""+j3); + } + + if (j2>=b) + return true; + else + return false; + +} + static boolean alcanza(int a,int b) +{ + int j1=0,j2=0,j3=0; + for (int i=0;i<=30;i++) + { + if (i+(i+1)+(i+1)==a) + { + j1=i; + j2=i+1; + j3=i+1; + } + if (i+i+i==a) + { + j1=i; + j2=i; + j3=i; + } + if (i+i+(i+1)==a) + { + j1=i; + j2=i+1; + j3=i; + } + } + //System.out.println("" ""+a+"" -> ""+j1+"" ""+j2+"" ""+j3); + + if (j2>=b) + return true; + else + return false; + +} +public static int procesar(String linea) +{ + String vals[]=linea.split("" ""); + int n,s,p; + int usados=0; + int puntajes[]; + n=Integer.parseInt(vals[0]); + s=Integer.parseInt(vals[1]); + p=Integer.parseInt(vals[2]); + puntajes=new int[n]; + for (int i=0;i= P) + count++; + if (x/3 == P-1 && x > 0) + { + if (S > 0) + { + S--; + count++; + } + } + } + if (x % 3 == 1) + { + if (x/3 >= P-1) + count++; + } + if (x % 3 == 2) + { + if (x/3 >= P-1) + count++; + if (x/3 == P-2) + { + if (S > 0) + { + S--; + count++; + } + } + + } + + + + } + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + } +} +" +A21548,"import java.io.*; + +public class ProbB +{ + public static void main (String[] args) throws Exception + { + MyInputReader in = new MyInputReader(new FileInputStream(""B-large.in"")); + PrintWriter pw = new PrintWriter(""output.txt""); + int T = in.nextInt(); + for(int q=0; q0) + continue; + if(3*p<=temp || 3*p-2==temp || 3*p-1==temp) + result++; + else if(count'\n'); + + return sb.toString(); + } + + public String nextWord() throws Exception + { + StringBuffer sb=new StringBuffer(""""); + byte c = read(); + while(c <= ' ') + c = read(); + do + { + sb.append((char)c); + c=read(); + } + while(c>' '); + + return sb.toString(); + } + + public char nextChar() throws Exception + { + byte c=read(); + while(c<=' ') + c= read(); + + return (char)c; + } + + public int nextInt() throws Exception + { + int ret = 0; + byte c = read(); + while(c <= ' ') + c = read(); + boolean neg = c == '-'; + if(neg) + c = read(); + do + { + ret = ret * 10 + c - '0'; + c = read(); + } + while (c > ' '); + + if(neg) + return -ret; + + return ret; + } + + public long nextLong() throws Exception + { + long ret = 0; + byte c = read(); + + while (c <= ' ') + c = read(); + boolean neg = c == '-'; + if(neg) + c = read(); + + do + { + ret = ret * 10 + c - '0'; + c = read(); + } + while (c > ' '); + + if(neg) + return -ret; + + return ret; + } + + private void fillBuffer() throws Exception + { + bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); + if(bytesRead == -1) + buffer[0] = -1; + } + + private byte read() throws Exception + { + if(bufferPointer == bytesRead) + fillBuffer(); + return buffer[bufferPointer++]; + } + } +}" +A20338," +package example2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class dance { + public static void main(String args[]) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int nocases = Integer.parseInt(br.readLine()); + int arr[]; + int ans[] = new int[nocases]; + for (int i = 0; i < nocases; i++) { + String token[] = br.readLine().split("" ""); + int N = Integer.parseInt(token[0]); + int S = Integer.parseInt(token[1]); + int P = Integer.parseInt(token[2]); + arr=new int[N]; + for (int j = 0; j < N; j++) { + arr[j] = Integer.parseInt(token[j + 3]); + } + ans[i]=method(arr, N, P, S); + } + for (int i = 0; i < nocases; i++) { + System.out.println(""Case #"" + (i + 1) + "": "" + ans[i]); + } + } + private static int method(int[] arr, int N, int P, int S) { + int c1 = 0, c2 = 0; + for (int j = 0; j < N; j++) { + if (arr[j] >= P) { + int diff = (int) (arr[j] - P); + if (((2 * P) - diff) <= 2) { + c1++; + } else if ((((2 * P) - diff) <= 4) && (((2 * P) - diff) > 2)) { + c2++; + } + } + } + if (c2 > S) { + c1 = c1 + S; + } else { + c1 = c1 + c2; + } + return c1; + } +} +" +A21660,"package com.google.code; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public abstract class GCJ { + + private BufferedReader input; + private BufferedWriter output; + String inputLine; + String[] brokenUpInputLine; + public static final String FOLDER = ""/tmp/""; + + + protected GCJ() throws IOException { + String subclass = this.getClass().getSimpleName(); + input = new BufferedReader(new FileReader(new File(FOLDER, subclass+"".in""))); + output = new BufferedWriter(new FileWriter(new File(FOLDER, subclass+"".out""))); + } + + public void run() throws NumberFormatException, IOException { + int loop = Integer.valueOf(input.readLine()); + for (int i = 0; i < loop; i++) + answering(i+1); + output.flush(); + } + + protected void write(String s) throws IOException { + System.out.print(s); + output.write(s); + } + protected void writeln(String s) throws IOException { + System.out.println(s); + output.write(s+""\n""); + } + protected void writeln() throws IOException { + System.out.println(); + output.write(""\n""); + } + protected void write(int s) throws IOException { + System.out.print(String.valueOf(s)); + output.write(String.valueOf(s)); + } + protected void writeln(int s) throws IOException { + System.out.println(String.valueOf(s)); + output.write(String.valueOf(s)+""\n""); + } + + protected void readLine() throws IOException { + inputLine = input.readLine(); + brokenUpInputLine = inputLine.split("" ""); + } + + protected String getStringInput(int i) { + return brokenUpInputLine[i]; + } + + protected int getIntInput(int i) { + return Integer.parseInt(brokenUpInputLine[i]); + } + + protected long getLongInput(int i) { + return Long.parseLong(brokenUpInputLine[i]); + } + + protected double getDoubleInput(int i) { + return Double.parseDouble(brokenUpInputLine[i]); + } + + private void answering(int ordinalityOfProblem) throws IOException { + writeOrdinalityOfAnswer(ordinalityOfProblem); + code(ordinalityOfProblem); + } + private void writeOrdinalityOfAnswer(int ordinalityOfProblem) throws IOException { + write(""Case #""+ordinalityOfProblem+"": ""); + } + + protected abstract void code(int count) throws IOException; + +} +" +A22406," + +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.IOException; + + +public class Googlers { + + public static void main(String args[]) throws IOException + { + int totalValid; + int surp, numGooglers, maxNum, calcSurp; + try + { + PrintWriter wt= new PrintWriter(""C:\\Documents and Settings\\windows\\workspace\\test\\src\\file.out.txt""); + Scanner I = new Scanner(new File(""C:\\Documents and Settings\\windows\\workspace\\test\\src\\B-large.in"")); + String num = I.nextLine(); + int numTests = Integer.parseInt(num); + + for(int x=0; x surp) + { totalValid = totalValid + surp; + } + else + { + totalValid = totalValid + calcSurp; + } + //logic to write totalValid to file + String finalResult = ""Case #""+(x+1)+"": ""+totalValid; + + wt.println(finalResult); + finalResult = """"; + } + wt.close(); + I.close(); + } + catch(FileNotFoundException e) + { + e.printStackTrace(); + } + + catch(IOException e) + { + System.out.println(e); + } + } + + + // Replacement algorithm + public static int isGoogler (int num,int max) + { + if (max == 0 && max <= num) + return 1; + else if (num <= 0) + return 0; + else if (num >= ((max * 3)-2 )) + return 1; + else if (num >= ((max * 3)-4 )) + return 2; + else return 0; + } +} + + + + +" +A20211,"package qualification; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.math.BigInteger; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Locale; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; + +public class A { + + static DecimalFormat DF = new DecimalFormat(""0.000000"", new DecimalFormatSymbols(Locale.ENGLISH)); + + private static final int MAX = 1000000; + private static final int MIN = 1 - 1; + private static final int MOD = 1000000009; + + public A(int cc) throws IOException { + final int N = INT(); + int S = INT(); + final int p = INT(); + + int max = 0; + + for (int i = 0; i < N; i++) { + int t = INT(); + int b = t / 3; + int f = p - b; + if( f <= 0 ) { + max++; + continue; + } + + int k = t % 3; + + switch (k) { + case 0: + if (f == 1 && S > 0 && b > 0) { + S--; + max++; + } + break; + case 1: + if (f == 1) { + max++; + } + break; + case 2: + if (f == 1) { + max++; + } else + if (f == 2 && S > 0) { + S--; + max++; + } + break; + + default: + break; + } + } + + println(""Case #"" + cc + "": ""+max); + //System.out.format(""Case #%d: %.09f\n"", cc, total); + } + + public static void run() throws Exception { + String qprefix = ""B""; + init(qprefix+""-large""); + //init(qprefix + ""-small-attempt0""); + //init(""test""); + + int cases = INT(); + for (int cc = 1; cc <= cases; cc++) { + new A(cc); + } + } + + static class Ct extends Thread { + public void run() { + } + } + + static int[][] mapClone(int[][] map) { + int[][] cmap = map.clone(); + for (int i = 0; i < cmap.length; i++) { + cmap[i] = map[i].clone(); + } + return cmap; + } + + // ************************************************************************************* + // *********************************** FRAMEWORK + // ************************************************************************************* + + public static BufferedReader stdin = new BufferedReader( + new InputStreamReader(System.in)); + public static boolean isStandardInput = false; + + public static File input; + public static FileReader inputreader; + public static BufferedReader in; + + public static File output; + public static FileWriter outputwriter; + public static BufferedWriter out; + + public static StringTokenizer st; + + public static void main(String[] args) throws Exception { + doSTDIN(true); + setOutput(""test.out""); + run(); + close(); + } + + public static void init(String problemName) throws Exception { + doSTDIN(false); + setInput(problemName + "".in""); + setOutput(problemName + "".out""); + } + + // **************** PRINT METHODS ********************** + + public static void println() throws IOException { + out.write(""\n""); + System.out.println(); + } + + public static void println(Object obj) throws IOException { + out.write(obj.toString()); + out.write(""\n""); + System.out.println(obj.toString()); + } + + public static void print(Object obj) throws IOException { + out.write(obj.toString()); + System.out.print(obj.toString()); + } + + public static void println(long number) throws IOException { + out.write(Long.toString(number)); + out.write(""\n""); + System.out.println(number); + } + + public static void print(long number) throws IOException { + out.write(Long.toString(number)); + System.out.print(number); + } + + public static void println(char c) throws IOException { + out.write(Character.toString(c)); + out.write(""\n""); + System.out.println(c); + } + + public static void print(char c) throws IOException { + out.write(Character.toString(c)); + System.out.print(c); + } + + public static void println(String line) throws IOException { + out.write(line); + out.write(""\n""); + System.out.println(line); + } + + public static void print(String line) throws IOException { + out.write(line); + System.out.print(line); + } + + // ******************** INPUT DECLARATION ****************** + + public static void doSTDIN(boolean standard) { + isStandardInput = standard; + } + + public static void setInput(String filename) throws IOException { + input = new File(filename); + inputreader = new FileReader(input); + in = new BufferedReader(inputreader); + } + + public static void setOutput(String filename) throws IOException { + output = new File(filename); + outputwriter = new FileWriter(output); + out = new BufferedWriter(outputwriter); + } + + public static void close() throws IOException { + if (in != null) + in.close(); + if (inputreader != null) + inputreader.close(); + + if (out != null) + out.flush(); + if (out != null) + out.close(); + if (outputwriter != null) + outputwriter.close(); + } + + // ************************** INPUT READING ***************** + + static String LINE() throws IOException { + return isStandardInput ? stdin.readLine() : in.readLine(); + } + + static String TOKEN() throws IOException { + while (st == null || !st.hasMoreTokens()) + st = new StringTokenizer(LINE()); + return st.nextToken(); + } + + static int INT() throws IOException { + return Integer.parseInt(TOKEN()); + } + + static long LONG() throws IOException { + return Long.parseLong(TOKEN()); + } + + static double DOUBLE() throws IOException { + return Double.parseDouble(TOKEN()); + } + + static BigInteger BIGINT() throws IOException { + return new BigInteger(TOKEN()); + } + +} + +class AF { + private Object array; + private int oa = 0; + private int ob = 0; + private int as = 10; + private int bs = 10; + + public AF(Object array) { + this.array = array; + } + + public AF(Object array, int oa, int ob) { + this.array = array; + this.oa = oa; + this.ob = ob; + } + + public AF(Object array, int oa, int ob, int as, int bs) { + this.array = array; + this.oa = oa; + this.ob = ob; + this.as = as; + this.bs = bs; + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + for (int a = 0; a < as; a++) { + sb.append(a + oa).append('['); + for (int b = 0; b < bs; b++) { + sb.append(get(a, b)); + if (b != bs - 1) + sb.append(','); + } + sb.append(""]\n""); + } + return sb.toString(); + } + + private String get(int a, int b) { + a += oa; + b += ob; + String s = "" ""; + try { + if (array instanceof int[][]) { + int[][] na = (int[][]) array; + s = Integer.toString(na[a][b]); + } else if (array instanceof byte[][]) { + byte[][] na = (byte[][]) array; + s = Byte.toString(na[a][b]); + } else if (array instanceof Object[][]) { + Object[][] na = (Object[][]) array; + s = na[a][b].toString(); + } + } catch (Exception e) { + } + while (s.length() < 2) { + s = "" "" + s; + } + return s; + } +} + +class AF2 extends JFrame implements ActionListener { + static Object lock = new Object(); + + private JTable jt; + + public AF2(String title, int[][] data) { + super(title); + setSize(150, 150); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent we) { + dispose(); + System.exit(0); + } + }); + jt = new JTable(new ITableModel(data)); + jt.setDefaultRenderer(Integer.class, new CustomTableCellRenderer()); + + // jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + JScrollPane pane = new JScrollPane(jt, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + getContentPane().add(pane); + + JButton button = new JButton(""Continue""); + getContentPane().add(button, BorderLayout.SOUTH); + button.addActionListener(this); + + pack(); + setVisible(true); + } + + public void updateData(int[][] data) { + ((ITableModel) jt.getModel()).updateData(data); + /*synchronized (lock) { + try { + lock.wait(); + } catch (InterruptedException e) { + } + }*/ + return; + } + + public void actionPerformed(ActionEvent arg0) { + synchronized (lock) { + lock.notify(); + } + } +} + +class ITableModel extends AbstractTableModel { + int[][] data; + int[][] old_data; + + public ITableModel(int[][] data) { + if (data != null) + this.data = data; + else + this.data = new int[1][1]; + } + + public void updateData(int[][] p_data) { + if( p_data.length == data.length && p_data[0].length == data[0].length ) { + old_data = data; + } else { + old_data = null; + } + this.data = p_data; + EventQueue.invokeLater(new Runnable() { + public void run() { + fireTableStructureChanged(); + } + }); + } + + public int getColumnCount() { + return data[0].length + 1; + } + + public int getRowCount() { + return data.length; + } + + public String getColumnName(int column) { + return Integer.toString(column - 1); + } + + public Object getValueAt(int rowIndex, int columnIndex) { + if (columnIndex == 0) + return rowIndex; + if( old_data != null && data[rowIndex][columnIndex - 1] != old_data[rowIndex][columnIndex - 1] ) { + return """"+old_data[rowIndex][columnIndex - 1]+"" -> ""+data[rowIndex][columnIndex - 1]; + } + return data[rowIndex][columnIndex - 1]; + } + + public Class getColumnClass(int arg0) { + return getValueAt(0, arg0).getClass(); + } +} + +class CustomTableCellRenderer extends DefaultTableCellRenderer { + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + Component cell = super.getTableCellRendererComponent(table, value, + isSelected, hasFocus, row, column); + if (column == 0) { + cell.setBackground(Color.gray); + } else if (value instanceof Integer) { + Integer amount = (Integer) value; + if (amount.intValue() <= 0) { + cell.setBackground(Color.red); + } else { + cell.setBackground(Color.white); + } + } else { + cell.setBackground(Color.yellow); + } + return cell; + } +} +" +A21691,"import java.io.*; +import java.util.*; + +public class B implements Runnable { + private MyScanner in; + private PrintWriter out; + + private void solve() { + int n = in.nextInt(); + int surprise = in.nextInt(); + int score = in.nextInt(); + int[] total = new int[n]; + for (int i = 0; i < n; ++i) { + total[i] = in.nextInt(); + } + int ans = 0; + for (int i = 0; i < n; ++i) { + if (total[i] >= 3 * score - 2) { + ++ans; + } else if (score > 1 && surprise > 0 && total[i] >= 3 * score - 4) { + ++ans; + --surprise; + } + } + out.println(ans); + } + + @Override + public void run() { + in = new MyScanner(); + try { + out = new PrintWriter(new File(""B-large.out"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + int tests = in.nextInt(); + for (int i = 0; i < tests; ++i) { + out.print(""Case #"" + (i + 1) + "": ""); + solve(); + } + in.close(); + out.close(); + } + + public static void main(String[] args) { + new B().run(); + } + + class MyScanner { + private BufferedReader br; + private StringTokenizer st; + + public MyScanner() { + try { + br = new BufferedReader(new FileReader(""B-large.in"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public void close() { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public boolean hasNext() { + while (st == null || !st.hasMoreTokens()) { + try { + String s = br.readLine(); + if (s == null) { + return false; + } + st = new StringTokenizer(s); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + return st != null && st.hasMoreTokens(); + } + + private String next() { + while (st == null || !st.hasMoreTokens()) { + try { + String s = br.readLine(); + if (s == null) { + return null; + } + st = new StringTokenizer(s); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + return st.nextToken(); + } + + public String nextLine() { + try { + st = null; + return br.readLine(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public int nextInt() { + return Integer.parseInt(next()); + } + + public long nextLong() { + return Long.parseLong(next()); + } + + public double nextDouble() { + return Double.parseDouble(next()); + } + } +}" +A20394,"package codeJamB; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + +public class PgmTemplate { + + /** + * @param args + */ + public static String delims = ""[ ]+""; + public static PrintStream ps; + + public static void main(String[] args) { + + for (String s : args) { + System.out.println(s); + } + + try { + // Open the file that is the first command line parameter + FileInputStream fstream = new FileInputStream(args[0]+"".txt""); + ps = new PrintStream(args[0]+"".out""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + // Read File Line By Line + strLine = br.readLine(); + //System.out.println(strLine); + int numCases = Integer.parseInt(strLine); + // Read File Line By Line + for (int i = 0; i < numCases; i++) { + strLine = br.readLine(); + //System.out.println(i + "" "" + strLine); + doCode(i, strLine); + } + // Close the input stream + in.close(); + } catch (Exception e) {// Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } + + public static void doCode(int Case, String strLine) { + + String[] tokens = strLine.split(delims); + int N = Integer.parseInt(tokens[0]); + int S = Integer.parseInt(tokens[1]); + int P = Integer.parseInt(tokens[2]); + int[] T = new int[N]; + + for (int i=0; i< N; i++) { + T[i] = Integer.parseInt(tokens[3+i]); + } + + int noSurprise = 0; + int withSurprise = 0; + + for (int i=0; i< N; i++) { + if (doWithNoSurprise(P, T[i])) + noSurprise += 1; + else if (doWithSurprise(P, T[i])) + withSurprise += 1; + } + + int TotalCount = noSurprise + Math.min(withSurprise, S); + + System.out.format(""Case #%d: %d\n"", Case + 1, TotalCount); + ps.format(""Case #%d: %d\n"", Case + 1, TotalCount); + + /*System.out.format("" N: %d\n"", N); + System.out.format("" S: %d\n"", S); + System.out.format("" P: %d\n"", P); + for (int i=0; i< N; i++) { + System.out.format("" T[%d]: %d\n"", i, T[i]); + }*/ + + + } + + public static boolean doWithNoSurprise(int P, int T) { + int score1 = T / 3; + int score2 = (T - score1) / 2; + int score3 = T - (score1 + score2); + + //System.out.format (""P: %d T: %d S1: %d S2: %d S3: %d\n"", P, T, score1, score2, score3); + + if (score3 >= P) + return true; + + return false; + + } + + public static boolean doWithSurprise(int P, int T) { + if ((T < 2) || (T>28)) + return false; + int score1 = T / 3; + int score2 = (T - score1) / 2; + int score3 = T - (score1 + score2); + + if ((P - score3) > 1) + return false; + if ((score3 +1) - (score2 -1) > 2) + return false; + if ((score3 +1) - (score1) > 2) + return false; + + //System.out.format (""P: %d T: %d S1: %d S2: %d S3: %d\n"", P, T, score1, score2, score3); + + + return true; + + } + +} + +" +A21267,"import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + + +public class Main +{ + + /** + * @param args + */ +// public static void main(String[] args) +// { +// try +// { +// Map m = new HashMap(); +// start_googlerese(""ejp mysljylc kd kxveddknmc re jsicpdrysi"",""our language is impossible to understand"",m); +// start_googlerese(""rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"",""there are twenty six factorial possibilities"",m); +// start_googlerese(""de kr kd eoya kw aej tysr re ujdr lkgc jv"",""so it is okay if you want to just give up"",m); +// +// m.put('z','q'); +// m.put('q','z'); +// +// int a=0; +// a= a+1; +// +// char letter; +// for (letter='a'; letter <= 'z'; letter++) +// { +// if(m.containsKey(letter)) +// System.out.println(letter+"" ""+m.get(letter)); +// else +// System.out.println(letter+"" ""+""!!!""); +// } +// +// googlerese(m); +// +// } +// catch (IOException e) +// { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } + + + public static void main(String[] args) + { + try + { + dancing(); + //recycled(); + + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void dancing() throws IOException + { + ArrayList input = Tools.getInput(""C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\B-small.in""); + ArrayList output = new ArrayList(); + + int num_cases = Integer.parseInt(input.get(0)[0]); + + for (int i=1;i<=num_cases;i++) + { + int result=0; + + int N=Integer.parseInt(input.get(i)[0]); + int S=Integer.parseInt(input.get(i)[1]); + int p=Integer.parseInt(input.get(i)[2]); + int a,b,c; + for(int j=0;j=p || b>=p || c>=p ) + result++; + else + { + if(S>0 && ( (a==b && a==p-1 && a>0) || (a==c && a==p-1 && a>0) || (b==c && b==p-1 && b>0) ) ) + { + S--; + result++; + } + } + + } + + + StringBuilder sbO = new StringBuilder(); + sbO.append(""Case #""+(i)+"": ""); + sbO.append(result); + output.add(sbO.toString()); + } + + Tools.saveOutputSingle(""C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\B-small.out"", output); + } + + + public static void recycled() throws IOException + { + ArrayList input = Tools.getInput(""C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\C-small.in""); + ArrayList output = new ArrayList(); + + int num_cases = Integer.parseInt(input.get(0)[0]); + + Set done = new HashSet(); + + //!!!!!!!!!!!!!!!!!!! num_cases + for (int i=0;in && m<=upper && !done.contains(m)) + { + System.out.println(n+"" ""+m); + result++; +// done.add(m); + done.add(n); + } + } + } + + + StringBuilder sbO = new StringBuilder(); + sbO.append(""Case #""+(i+1)+"": ""); + sbO.append(result); + output.add(sbO.toString()); + } + + Tools.saveOutputSingle(""C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\C-small.out"", output); + } + + + public static void start_googlerese(String input, String output, Map m) throws IOException + { + if(input.length()!=output.length()) + throw new IOException(); + + for(int i=0;i m) throws IOException + { + ArrayList input = Tools.getInputSingle(""C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\A-small.in""); + ArrayList output = new ArrayList(); + + int num_cases = Integer.parseInt(input.get(0)); + + for (int i=0;i input = Tools.getInput(""D:\\Documents\\Dropbox\\GCJ_JAVA\\1A_2008\\A-large-practice.in""); + ArrayList output = new ArrayList(); + + + int T = Integer.parseInt(input.get(0)[0]); + + for (int i=0;i vectorA = new ArrayList(); + ArrayList vectorB = new ArrayList(); + + for(int j=0;j= p) + goodScoreCaseOneBigger = true; + else + goodScoreCaseOneSmaller = true; + } else { + canMakeTwo = true; + if (c >= p) + goodScoreCaseTwoBigger = true; + else + goodScoreCaseTwoSmaller = true; + } + } + } + } + } + + if (canMakeOne == true) { + + if (goodScoreCaseOneBigger == true) { + for (j=0;j<=S;j++) { + opt[i][j] = Math.max(opt[i][j], opt[i-1][j]+1); + } + } + + if (goodScoreCaseOneSmaller == true) { + for (j=0;j<=S;j++) { + opt[i][j] = Math.max(opt[i][j], opt[i-1][j]); + } + } + + } + + if (canMakeTwo == true) { + + if (goodScoreCaseTwoBigger == true) { + for (j=1;j<=S;j++) { + opt[i][j] = Math.max(opt[i][j], opt[i-1][j-1]+1); + } + } + + if (goodScoreCaseTwoSmaller == true) { + for (j=1;j<=S;j++) { + opt[i][j] = Math.max(opt[i][j], opt[i-1][j-1]); + } + } + + } + + } + + return opt[N][S]; + } + + public static void main(String[] args) throws Exception { + int i,j,k; + + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(""B-large.out""); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + + for (k=1;k<=T;k++) { + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + t = new int[N+1]; + + for (i=1;i<=N;i++) + t[i] = Integer.parseInt(st.nextToken()); + + out.println(""Case #""+k+"": ""+solve()); + + } + + out.close(); + + } + +} +" +A21100,"import java.io.File; +import java.io.PrintWriter; + +import java.util.HashSet; +import java.util.Scanner; + +/** + * User: Sasha + * Date: 09.04.12 + * Time: 19:13 + */ +public class Main { + private Scanner sc; + private PrintWriter wr; + private HashSet set; + + private void prepare() throws Exception { + sc = new Scanner(new File(""C:\\Projects\\B-large.in"")); + File file = new File(""C:\\Projects\\out.txt""); + wr = new PrintWriter(file); +// wr = new PrintWriter(System.out); + } + + private void solve() { + int T = sc.nextInt(); + + for (int i = 0; i < T; ++i) { + set = new HashSet(); + + wr.print(String.format(""Case #%d: "", (i + 1))); + + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int r[] = new int[n]; + for (int j = 0; j < r.length; ++j) + r[j] = sc.nextInt(); + + int res = 0; + + for (int j = 0; j < n; ++j) { + int e = r[j] / 3; + int k = r[j] - e * 3; + + if (e >= p) { + ++res; + } else if (k >= 1 && e + 1 >= p) { + ++res; + } else if (k == 0 && e + 1 >= p && s > 0 && e > 0) { + ++res; + --s; + } + else if (k == 2 && e + 2 >= p && s > 0) { + ++res; + --s; + } + + } + wr.println(res); + } + + wr.flush(); + } + + public static void main(String args[]) throws Exception { + Main main = new Main(); + + main.prepare(); + + main.solve(); + } +} +" +A21555,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class a +{ + public static void main(String[] args) throws IOException + { + BufferedReader in = new BufferedReader(new FileReader(""B-small.in"")); + FileWriter fr = new FileWriter(""small.out""); + + int num = Integer.parseInt(in.readLine()); + + for(int cases = 1 ; cases<=num ; cases++) + { + String []temp = in.readLine().split("" ""); + //for (int i=0;i= ((maxvalue*3)-2)) + { + result++; + } + else if((score >= ((maxvalue*3)-4)) && (availablesurprisingtriplets > 0) && (maxvalue > 1)) + { + result++; + availablesurprisingtriplets--; + } + } + fr.write(""Case #""+cases+"": ""+result+""\n""); + //System.out.println(""Case #""+cases+"": ""+result); + } + fr.close(); + } +} +" +A22943,"package com.jedruch.dancing; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import com.jedruch.utils.Files; +import com.jedruch.utils.Files.LineReader; + +public class Dancing { + + public static void main(String[] args) { + if (args.length == 0) { + System.out.println(""missing file name""); + return; + } + String fileName = args[0]; + Files.readFileByLine(fileName, new LineReader() { + + Dancing gt = new Dancing(); + @Override + public void onNewLine(String line, int lineNumber) { + if ( lineNumber > 1) { + int max = gt.getMaximumGooglers(line); + String output = String.format(""Case #%d: %d"", lineNumber - 1, max); + System.out.println(output); + } + } + }); + } + + public int getMaximumGooglers(String line) { + Object[] params = parseInput(line); + return getMaximumGooglers((int)params[0], (int)params[1], (int[])params[2]); + } + public Object[] parseInput(String line) { + String[] tokens = line.split("" ""); + int arraySize = Integer.valueOf(tokens[0]); + int surprsingS = Integer.valueOf(tokens[1]); + int betScore = Integer.valueOf(tokens[2]); + int[] scores = new int[arraySize]; + + int count = 0; + for (int i = 3; i < tokens.length; i++) { + scores[i - 3] = Integer.valueOf(tokens[i]); + count++; + } + if (arraySize != count) { + throw new IllegalStateException( + ""Given number of scores do not match""); + } + return new Object[] { surprsingS, betScore, scores }; + } + + /** + * + * @param surprisingScores + * - ti ( i = N) + * @param maxBestScore + * - p + * @param results + * @return + */ + public int getMaximumGooglers(int surprisingScores, int maxBestScore, + int[] results) { + List scores = new LinkedList<>(); + for (int s : results) { + scores.add(new Score(s)); + } + makeSurprsingScores(surprisingScores, maxBestScore, scores); + return calculateWithScoreMoreThenGiven(scores, maxBestScore); + } + + public void makeSurprsingScores(int noOfSurprisingScores, int bestScore, + List scores) { + int count = 0; + for (Score s : scores) { + if (count == noOfSurprisingScores) { + break; + } + if (s.getBestScore() >= bestScore) + continue; // ignore this case; + + boolean result = makeSuprisingOnlyIfWorth(s, bestScore); + if (result) { + count++; + } + } + if (count > noOfSurprisingScores) + throw new IllegalStateException( + ""Make more surprsing then exptecated""); + } + + private boolean makeSuprisingOnlyIfWorth(Score s, int bestScore) { + int tmp = s.getTotal(); + s.makeSurprising(); + if (s.getBestScore() >= bestScore) { + return true; + } else { + s.initScores(tmp); // rollback + return false; + } + } + + public int calculateWithScoreMoreThenGiven(List scores, + int maxBestScore) { + int count = 0; + for (Score s : scores) { + if (s.getBestScore() >= maxBestScore) { + count++; + } + } + return count; + } + + public int calculateWithTheBestScore(List scores) { + int max = -1; + int count = 0; + for (Score s : scores) { + if (s.getBestScore() > max) { + count = 1; + max = s.getBestScore(); + } else if (s.getBestScore() == max) { + count++; + } + } + return count; + + } + + public void makeSurprsingScores(int noOfSurprisingScores, List scores) { + int count = 0; + for (Score s : scores) { + if (count == noOfSurprisingScores) { + break; + } + boolean result = s.makeSurprising(); + if (result) { + count++; + } + } + if (count > noOfSurprisingScores) + throw new IllegalStateException( + ""Make more surprsing then exptecated""); + } + +} + +class Score { + private int[] scores = new int[3]; + private int moduloType = -1; + + public Score(int score) { + initScores(score); + } + + void initScores(int total) { + moduloType = total % 3; + int div = total / 3; + Arrays.fill(scores, div); + if (moduloType == 1) { + scores[0] += 1; + } else if (moduloType == 2) { + scores[0] += 1; + scores[1] += 1; + } + } + + void initScores(int first, int second, int third) { + scores[0] = first; + scores[1] = second; + scores[2] = third; + } + + public boolean makeSurprising() { + if (moduloType == -1) { + throw new IllegalStateException(""Can not be -1""); + } + if (moduloType == 1 || getTotal() == 0) + return false; + if (moduloType == 0) { + scores[0] += 1; + scores[2] -= 1; + } else if (moduloType == 2) { + scores[0] += 1; + scores[1] -= 1; + } + return true; + } + + @Override + public String toString() { + return ""Score [scores="" + Arrays.toString(scores) + ""]""; + } + + public boolean isSurprising() { + int first = scores[0]; + int second = scores[1]; + int third = scores[2]; + boolean surprsing = false; + surprsing |= checkSurprising(first, second); + surprsing |= checkSurprising(first, third); + surprsing |= checkSurprising(second, third); + return surprsing; + } + + private boolean checkSurprising(int int1, int int2) { + int diff = Math.abs(int1 - int2); + if (diff > 2) + throw new IllegalStateException(""Some problem with judges""); + return diff == 2; + } + + public int[] getScores() { + return scores; + } + + public int getTotal() { + int sum = 0; + for (int s : scores) { + sum += s; + } + return sum; + } + + public int getBestScore() { + int max = -1; + for (int s : scores) { + max = Math.max(max, s); + } + return max; + } + +} +" +A22760,"package main; + +import java.util.Vector; +import java.io.*; + +public class Googlers { + + /** + * 2012 Qualif B + */ + static int numberOfElementForEachTest = 0; + static int numberOfLinesPerTest = 0; + + public static void main(String[] args) { + Vector elements = new Vector(); + numberOfElementForEachTest = 0; + + Reader.setFile(""input.txt""); + Writer.setFile(""output.txt""); + + String s = Reader.readLine(); + int numberTest = Integer.parseInt(s); + + for (int i=0; i(); + + String s1 = """"; + + s = Reader.readLine(); + s1 = s.substring(0, s.indexOf("" "")); + s=s.substring(s.indexOf("" "")+1); + numberOfElementForEachTest = Integer.parseInt(s1); + + s1 = s.substring(0, s.indexOf("" "")); + s=s.substring(s.indexOf("" "")+1); + int numberOfSurprises = Integer.parseInt(s1); + + s1 = s.substring(0, s.indexOf("" "")); + s=s.substring(s.indexOf("" "")+1); + int bestToReach = Integer.parseInt(s1); + + for (int j=0; j= bestToReach) result++; + else if (bestWithSurprise >= bestToReach && + numberOfSurprises > 0) + { + result ++; + numberOfSurprises --; + } + } + + + Writer.writeln(""Case #"" + (i+1) + "": "" + result); + + } + Writer.close(); + + } + + public static final class Reader + { + static BufferedReader in; + + public static void setFile(String fichier) { + File file = new File(fichier); + try { + in = new BufferedReader(new FileReader(file)); + } catch (FileNotFoundException e) { + } + } + + public static String readLine() { + String line = null; + try { + line = in.readLine(); + } + catch (IOException e) {} + + return line; + } + + public static String readAll() { + String text = """"; + String line = """"; + while (line != null) { + try { + line = in.readLine(); + } + catch (IOException e) { + } + if (line != null) text += line + ""\n""; + } + return text; + } + } + + public static final class Writer + { + static BufferedWriter out; + + public static void setFile(String file) { + try{ + FileWriter fstream = new FileWriter(file); + out = new BufferedWriter(fstream); + } + catch (Exception e){} + } + + public static void write(String ligne) { + try { + out.write(ligne); + } + catch (Exception e){} + } + public static void writeln(String ligne) { + try { + out.write(ligne); + out.write(""\n""); + } + catch (Exception e){} + } + + public static void close() { + try { + out.close(); + } + catch (Exception e){} + } + } + +} +" +A22030,"package codejam2012.qualification; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + static String dir=""/home/casatta/Scaricati/""; +// static String dir=""data/""; + + static String fname=""B-large.in""; +// static String fname=""DancingWithTheGooglers""; + + + public void test(Scanner input, PrintWriter out, Long i) { + int n=input.nextInt(); + int surprising=input.nextInt(); + int p=input.nextInt(); + + int max=p*3; + int notSurprising=max-2; + int isSurprising=max-4; + int count=0; + int current; + + System.out.println(""n="" + n + "" surprising="" + surprising + "" p="" + p ); + System.out.println(""max="" + max + "" notSurprising="" + notSurprising + "" isSurprising="" + isSurprising ); + + + for(int j=0;j=notSurprising) + count++; + else if(current>=isSurprising && surprising>0 && current>=p) { + count++; + surprising--; + } + } + + + + + System.out.println(); + + String result = ""Case #"" + (i+1) + "": "" +count; + out.println(result); + System.out.println(result); + System.out.println(); + } + + + public void run() { + + + try { + String inputPath = dir + fname; + + Scanner input =new Scanner(new File(inputPath)); + FileWriter outFile = new FileWriter(inputPath + "".out""); + PrintWriter out = new PrintWriter(outFile); + try { + Long testCases = input.nextLong(); + input.nextLine(); + + for(Long i=0L ; i < testCases ; i++) + test(input,out,i); + } + finally { + input.close(); + out.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + } + + public static void main(String[] args) { + DancingWithTheGooglers template = new DancingWithTheGooglers(); + template.run(); + } + + +} +" +A20406,"package MyAllgoritmicLib; + +public class CodeGray { + + public static int grayEncode (int n) { + return n ^ (n >> 1); + } + + public static int grayDecode (int g) { + int n = 0; + for (; g > 0; g>>=1) + n ^= g; + return n; + } +} +" +A20296,"package codejam; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.Arrays; + +public class DanceScores { + + public static void main(String[] args) throws Exception { + new DanceScores().init(); + } + + private void init() throws Exception { + + int counter = 1; + BufferedReader br = new BufferedReader(new FileReader( + ""C:\\Users\\i053957\\Downloads\\B-small-attempt0.in"")); + String line = br.readLine(); + while ((line = br.readLine()) != null) { + int belowMin = 0; + String[] values = line.split(""[ ]""); + int[] scores = new int[Integer.parseInt(values[0])]; + int specialCount = Integer.parseInt(values[1]); + int min = Integer.parseInt(values[2]); + for (int i = 3; i < values.length; i++) { + scores[i - 3] = Integer.parseInt(values[i]); + } + + if (min > 1) { + Arrays.sort(scores); + for (int score : scores) { + if ((min * 3 - score) < 3) { + + } else if ((min * 3 - score) < 5) { + if (specialCount > 0) { + specialCount--; + } else { + belowMin++; + } + } else { + belowMin++; + } + } + } else if (min == 1) { + Arrays.sort(scores); + for (int score : scores) { + if (score == 0) { + belowMin++; + } + } + } + + System.out.println(""Case #"" + counter + "": "" + + (scores.length - belowMin)); + counter++; + } + + br.close(); + } +} +" +A21180,"import java.io.*; +import java.util.*; +public class q2Alt{ +public static void main (String[] args) throws IOException + { + BufferedReader input = new BufferedReader (new FileReader (""B-large.txt"")); + PrintWriter output = new PrintWriter (new FileWriter(""test2DoneAlt.out"")); + StringTokenizer st; + + int numOfLine = Integer.parseInt(input.readLine()); + for(int i = 0; i < numOfLine; i++){ + st = new StringTokenizer(input.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int P = Integer.parseInt(st.nextToken()); + int better = 0; + int[] scores = new int [N]; + + for(int j = 0; j < N; j++){ + scores[j] = Integer.parseInt(st.nextToken()); + } + + for(int j = 0; j < N; j++){ + int reduction = scores[j] - P; + if(reduction < 0){} + else if(reduction >= 2*(P - 1)){ + better ++; + } + else if(reduction >= 2*(P-2) && S > 0){ + better ++; + S --; + } + } + + output.println(""Case #"" + (i+1) + "": "" + better); + } + output.close(); + } +} +" +A22400,"import java.util.Scanner; + + +public class qualifier2 { +public static void main(String[] args) +{ + Scanner sc = new Scanner(System.in); + int numcases = sc.nextInt(); + sc.nextLine(); + for(int curcase = 1;curcase <=numcases;curcase++) + { + int numgoog = sc.nextInt(); + int supr = sc.nextInt(); + int cutoff = sc.nextInt(); + int[] scrtot = new int[numgoog]; + for(int i=0;i0)&&(scrtot[i]!=0)) + { + count++; + supr--; + } + } + } + System.out.println(""Case #""+curcase+"": ""+count); + } +} +} +" +A22463,"public abstract class JamCase { + int lineCount; +} +" +A22880,"import java.awt.geom.*; +import java.io.*; +import java.math.*; +import java.util.*; +import java.util.regex.*; +import static java.lang.Math.*; +import static java.lang.System.*; +public class B_large { + + public B_large() throws Exception { + int caseCount = in.nextInt(); + for (int caseNum=1;caseNum<=caseCount;caseNum++) { + out.printf(""Case #%d: "", caseNum); + + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + + int ans = 0; + int reserv = 0; + for (int i=0; i=3*p-2) ans++; + else if (c>=3*p-4&&p-2>=0) reserv++; + } + + out.println(ans+min(s, reserv)); + } + } + + // {{{ + Scanner in = new Scanner(System.in); + public static void main(String[] args) throws Exception { + new B_large(); + } + public static void debug(Object... arr) { + System.err.println(Arrays.deepToString(arr)); + } + // }}} +} +" +A23044,"package problemb; + +import java.io.BufferedReader; +import java.io.FileReader; + +import java.util.ArrayList; +import java.util.List; + +public class ProblemB { + + public static void main(String args[]){ + List inputs = readInput(); + int googlers = 0; + int specialCases = 0; + int bestScore = 0; + List googlerScores = new ArrayList(); + int count = 0; + for(String input : inputs){ + googlerScores = new ArrayList(); + count++; + String[] inputArray = input.split("" ""); + googlers = Integer.parseInt(inputArray[0]); + specialCases = Integer.parseInt(inputArray[1]); + bestScore = Integer.parseInt(inputArray[2]); + + for(int i=3; i<(3+googlers); i++){ + googlerScores.add(Integer.parseInt(inputArray[i])); + } + + output(count, bestResult(googlerScores, specialCases, bestScore)); + + } + } + + + private static int bestResult(List googlerScores, int specialCases, int bestScore){ + int bestResults = 0; + int scoreMinusMax = 0; + int avgScore = 0; + for(Integer googlerScore : googlerScores){ + scoreMinusMax = googlerScore - bestScore; + avgScore = scoreMinusMax / 2; + +// System.out.println(""AVG SCORE: "" + avgScore); +// System.out.println(""BEST SCORE: "" + bestScore); +// System.out.println(""SPECIAL CASES: "" + specialCases); + if(googlerScore == 0 && bestScore > 0) + continue; + if(avgScore >= bestScore || (bestScore - avgScore) < 2){ + bestResults++; + }else if((bestScore - avgScore) == 2 && specialCases > 0){ + specialCases--; + bestResults++; + } + } + + + return bestResults; + } + + private static List readInput(){ + List untranslatedStrings = new ArrayList(); + try{ + BufferedReader in = new BufferedReader(new FileReader(""input.txt"")); + Long numTestCases = Long.parseLong(in.readLine()); + for(int i=0; i=1){ + if(participants[k]>=3*p-2) + results++; + else if(participants[k]>=3*p-4){ + if(S!=0){ + results++; + S--; + } + } + } + } + if(p==0) + results=N; + System.out.println(""Case #""+(i+1)+"": ""+results); + } + } +} +" +A22258,"import java.io.InputStreamReader; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.FileInputStream; +import java.util.StringTokenizer; +import java.io.Writer; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + * @author Nova + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream; + try { + inputStream = new FileInputStream(""B.input.txt""); + } catch (IOException e) { + throw new RuntimeException(e); + } + OutputStream outputStream; + try { + outputStream = new FileOutputStream(""B.output.txt""); + } catch (IOException e) { + throw new RuntimeException(e); + } + InputReader in = new InputReader(inputStream); + OutputWriter out = new OutputWriter(outputStream); + TaskB solver = new TaskB(); + solver.solve(1, in, out); + out.close(); + } +} + +class TaskB { + public void solve(int testNumber, InputReader in, OutputWriter out) { + int numberOfTests = in.nextInt(); + for (int testNum = 1; testNum <= numberOfTests; testNum++) { + out.print(""Case #"" + testNum + "": ""); + int res = 0; + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] a = new int[n]; + for (int i = 0; i < n; i++) a[i] = in.nextInt(); + for (int i = 0; i < n; i++) { + int cc = a[i] / 3; + if (a[i] % 3 != 0) cc++; + if (cc >= p) res++; + else if (s > 0) { + cc = a[i] / 3; + if (a[i] % 3 == 0 && cc > 0) cc++; + if (a[i] % 3 == 1) cc++; + if (a[i] % 3 == 2) cc += 2; + if (cc >= p) { + res++; + s--; + } + } + } + out.println(res); + } + } +} + +class InputReader { + private BufferedReader reader; + private StringTokenizer tokenizer; + + public InputReader(InputStream stream) { + reader = new BufferedReader(new InputStreamReader(stream)); + tokenizer = null; + } + + public String next() { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + try { + tokenizer = new StringTokenizer(reader.readLine()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return tokenizer.nextToken(); + } + + public int nextInt() { + return Integer.parseInt(next()); + } + + } + +class OutputWriter { + private final PrintWriter writer; + + public OutputWriter(OutputStream outputStream) { + writer = new PrintWriter(outputStream); + } + + public OutputWriter(Writer writer) { + this.writer = new PrintWriter(writer); + } + + public void print(Object... objects) { + for (int i = 0; i < objects.length; i++) { + writer.print(objects[i]); + } + } + + public void println(Object... objects) { + print(objects); + writer.println(); + } + + public void close() { + writer.close(); + } +} + +" +A22209,"package com.wonyoung.codejam.qualificationround; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; + +public class DancingWithTheGooglers { + private Integer testCasesT; + private DancingWithTheGooglersData [] data; + + class DancingWithTheGooglersData { + Integer googlersN; + Integer surprisingS; + Integer p; + String[] totalPoints; + + public DancingWithTheGooglersData() { + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append(googlersN.toString()); + sb.append("" "" + surprisingS.toString()); + sb.append("" "" + p.toString()); + int count = 0; + while ( count < googlersN ) { + sb.append("" "" + totalPoints[count].toString()); + count++; + } + + return sb.toString(); + } + } + + public DancingWithTheGooglers(String filename) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(filename)); + String line; + testCasesT = Integer.valueOf(br.readLine()); + data = new DancingWithTheGooglersData[testCasesT]; + + int count = 0; + + while ( count < testCasesT) { + line= br.readLine(); + String [] words = line.split("" ""); + + data[count] = new DancingWithTheGooglersData(); + data[count].googlersN = Integer.valueOf(words[0]); + data[count].surprisingS = Integer.valueOf(words[1]); + data[count].p = Integer.valueOf(words[2]); + data[count].totalPoints = Arrays.copyOfRange(words, 3, 3 + data[count].googlersN); + + count++; + } + br.close(); + } + + public String result(int i) { + return ""Case #""+ (i+1) +"": ""+ greaterOrEqualsThanP(i); + } + + private Integer greaterOrEqualsThanP(int i) { + int result = 0; + int surprisingCards = data[i].surprisingS; + if (data[i].p <= 0) + return data[i].googlersN; + + int baseScore = data[i].p*3 - 3; + for ( String points : data[i].totalPoints) { + Integer n = Integer.valueOf(points); + if (baseScore < n) { + result++; +// System.out.print(""+""); + } + else if (data[i].p < n && baseScore < n+2 && surprisingCards > 0) { + surprisingCards--; + result++; +// System.out.print(""s""); + } + else { +// System.out.print(""-""); + } + } +// System.out.println(); + return result; + } + + public void print(String filename) throws IOException { + BufferedWriter bw = new BufferedWriter(new FileWriter(filename)); + int count = 0; + + while (count < testCasesT) { + bw.write(result(count)); + bw.newLine(); + count++; + } + + bw.close(); + } + + public static void main(String args[]) throws IOException { + DancingWithTheGooglers dwg = new DancingWithTheGooglers(""B-large.in""); + dwg.print(""B-large.out""); + } + +} + +" +A20892,"package com.google.codejam.Qualification2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(new BufferedReader(new FileReader(args[0] + "".in""))); + Writer writer = new BufferedWriter(new FileWriter(args[0] + "".out"")); + + int T = scanner.nextInt(); + + for (int x = 1; x <= T; ++x) { + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + int[] t = new int[N]; + for (int i = 0; i < N; ++i) + t[i] = scanner.nextInt(); + + int y = 0; + + for (int i = 0; i < N; ++i) { + if (t[i] < p) + continue; + + int min = (t[i] - p) / 2; + if (min >= p - 1) { + ++y; + } else if (min == p - 2 && S > 0) { + --S; + ++y; + } + } + + System.out.println(""Case #"" + x + "": "" + y); + writer.write(""Case #"" + x + "": "" + y + ""\n""); + } + + writer.close(); + scanner.close(); + } + +} +" +A20325,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class Main implements Runnable { + final String fileName = ""B-large""; + + void solveCase(int test) throws Exception { + out.print(""Case #"" + test + "": ""); + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int answer = 0; + for (int i = 0; i < n; i++) { + int t = nextInt(); + int c = t / 3 + (t % 3 >= 1 ? 1 : 0); + if (c >= p) + answer++; + else if (s > 0 && t % 3 != 1 && t >= 2 && c < 10 && c + 1 >= p) { + answer++; + s--; + } + } + out.println(answer); + } + + void solution() throws Exception { + int t = nextInt(); + for (int i = 0; i < t; i++) + solveCase(i + 1); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + long nextLong() throws IOException { + return Long.parseLong(next()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + String next() throws IOException { + while (st == null || !st.hasMoreTokens()) { + String l = in.readLine(); + if (l == null) return null; + st = new StringTokenizer(l); + } + return st.nextToken(); + } + + public static void main(String args[]) { + //Locale.setDefault(Locale.UK); + new Thread(new Main()).start(); + } + + public void run() { + try { + in = new BufferedReader(new FileReader(fileName + "".in"")); + //out = new PrintWriter(System.out); + out = new PrintWriter(fileName + "".out""); + solution(); + out.flush(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(202); + } + } + + BufferedReader in; + StringTokenizer st; + PrintWriter out; +}" +A22530,"import java.util.*; + +public class Dancing { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + int T = scan.nextInt(); + for (int i = 0; i < T; i++) { + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + + int count = 0; + for (int j = 0; j < n; j++) { + int m = scan.nextInt(); + + if (m - p < 0) + continue; + + if ((m - p) / 2 >= p - 1) + count++; + else if ((m - p) / 2 >= p - 2 && s > 0) { + count++; + s--; + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + count); + } + } +} +" +A21915,"import java.io.*; +import java.util.*; + +public class ProblemB +{ + public static void main(String[] args) throws Exception + { + final String base = ""B-large""; + BufferedReader reader = new BufferedReader(new FileReader(base+"".in"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(base+"".out"")); + reader.readLine(); + int place = 0; + while (reader.ready()) + { + String[] strs = reader.readLine().split("" ""); + int[] totals = new int[strs.length-3]; + int surprise = Integer.parseInt(strs[1]); + int min = Integer.parseInt(strs[2]); + for (int i=3;i=min && a+2>=c && c>=b) + { + if (b==a+2||c==a+2) + sur=true; + else + { + number++; + continue outer; + } + } + } + } + if (sur && surprise>0) + { + number++; + surprise--; + } + } + return number; + } + + public static int brute(int surprise, int min, int[] totals) + { + int number = 0; + outer: + for (int total : totals) + { + boolean sur = false; + for (int a=1;a<=10;a++) + { + for (int b=1;b<=10;b++) + { + for (int c=1;c<=10;c++) + { + if (a+b+c!=total) + continue; + int maxDiff = Math.max(Math.abs(a-b), Math.max(Math.abs(a-c), Math.abs(b-c))); + int max = Math.max(a, Math.max(b,c)); + if (max>=min) + { + if (maxDiff<2) + { + number++; + continue outer; + } + else if (maxDiff==2) + { + sur=true; + } + } + } + } + } + if (sur && surprise>0) + { + number++; + surprise--; + } + } + return number; + } +} +" +A20063,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + + +public class DancingGooglers { + + private final String inputFile = ""D:\\input.in""; + private final String outputFile = ""D:\\output.out""; + + private static class TestCase{ + int n; + int s; + int p; + int result = 0; + List ti = new ArrayList(); + + public void calculateBest(){ + result = 0; + int max = p * 3; + for (int i: ti){ + if (p <= 0){ + result++; + continue; + } + if (i > 0 && i >= (max - 4)){ + if (i >= max || (max - i) <= 2){ + result++; + }else if((max - i) <= 4 && s > 0){ + result++; s--; + } + } + + } + } + } + List input = new ArrayList(); + public void parseInput(){ + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile))); + int numTestCases = Integer.parseInt(br.readLine()); + for (int i = 0; i < numTestCases; i++){ + String [] lineTokens = br.readLine().split("" ""); + TestCase tc = new TestCase(); + tc.n = Integer.parseInt(lineTokens[0]); + tc.s = Integer.parseInt(lineTokens[1]); + tc.p = Integer.parseInt(lineTokens[2]); + for (int j = 3; j < lineTokens.length; j++){ + tc.ti.add(Integer.parseInt(lineTokens[j])); + } + tc.calculateBest(); + input.add(tc); + } + br.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + public void doOutput(){ + try { + PrintWriter pw = new PrintWriter(new FileOutputStream(outputFile)); + + for (int i = 0; i < input.size(); i++){ + TestCase tc = input.get(i); + pw.println(""Case #"" + (i + 1) + "": "" + tc.result); + } + + pw.flush(); + pw.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public static void main(String [] args){ + DancingGooglers dg = new DancingGooglers(); + dg.parseInput(); + dg.doOutput(); + } +} +" +A22166,"/** + * + */ +package GoogleCodeJam2012; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + +/** + * @author MArunkumar + * + */ +public class DancingWithTheGooglers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""DancingWithTheGooglersInput.txt"")); + FileWriter fw = new FileWriter(""DancingWithTheGooglersOutput.txt""); + int T = Integer.parseInt(br.readLine()); + for(int i=1; i<=T; i++){ + String datas[] = br.readLine().split("" ""); + int N = Integer.parseInt(datas[0]); + int S = Integer.parseInt(datas[1]); + int p = Integer.parseInt(datas[2]); + ArrayList comp = new ArrayList(); + + for(int j=0; j0){ + result++; + S--; + } + } + + fw.write(""Case #""+i+"": ""+result+""\n""); + } + fw.close(); + } + +} + +class Dancer{ + int ts = 0; + int s1 = 0; + int s2 = 0; + int s3 = 0; + boolean pass = false; + boolean passIfSurprised = false; + + public Dancer(int ts){ + this.ts = ts; + } + + void evaluate(int p){ + if(ts%3 == 0){ + s1 = s2 = s3 = ts/3; + }else{ + if(ts%3 == 1){ + s1 = s2 = s3 = ts/3; + s1++; + }else{ + s1 = s2 = s3 = ts/3; + s1++; + s2++; + } + } + if(s1>=p){ + pass = true; + }else{ + setPassIfSurprised(p); + } + } + + void setPassIfSurprised(int p){ + if(s2>0 && s1==s2 &&s1<10){ + s1++; + s2--; + } + if(s1>=p){ + passIfSurprised = true; + } + } +} +" +A20612," +import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; +/** + * + * @author yilianz + */ +public class DancingGoogler{ + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws Exception{ + + // Read file + Scanner inFile = new Scanner(new File(""file.in"")); + PrintWriter outFile = new PrintWriter(new File(""out.file"")); + + int caseN =inFile.nextInt(); + + + // TODO code application logic here + for(int i = 1; i= 3*P-2) { + MaxP++; + } + else if( ti >= 3*P - 4){ + + if (S>0 &&P!=1){ + S--; + MaxP++; + } + } + } + + System.out.println(""Case #""+i+"": ""+MaxP); + outFile.println(""Case #""+i+"": ""+MaxP); + } + + //close the file + inFile.close(); + outFile.close(); + + + + } +} +" +A21753," +import java.util.Scanner; + + +/** + * + * @author Daniel Sheng + */ +public class Dancing +{ + private final static int NUM_JUDGES = 3; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + int lns = Integer.parseInt(in.nextLine()); + + for(int ln = 0; ln < lns; ln++) + { + String[] tokens = in.nextLine().split(""\\s+""); + + int numDancers = Integer.parseInt(tokens[0]), + numSurprising = Integer.parseInt(tokens[1]), + targetBestScore = Integer.parseInt(tokens[2]); + + int result = 0; + + for(int i = 0; i < numDancers; i++) + { + int score = Integer.parseInt(tokens[i + 3]); + if(score >= targetBestScore * NUM_JUDGES - 2) + result++; + else if(score >= targetBestScore * NUM_JUDGES - 4 && numSurprising > 0 && targetBestScore - 2 >= 0) + { + result++; + numSurprising--; + } + } + + System.out.println(""Case #"" + (ln + 1) + "": "" + result); + } + } +} +" +A22606,"public class ProblemB extends FileWrapper { + + private int N[] = null; + private int S[] = null; + private int P[] = null; + private int t[][] = null; + + public ProblemB(String fileName) { + this.processInput(fileName); + this.calculate(); + this.processOutput(OUTPUT); + } + + private int getResult(int caseNum) { + int total = 0; + for (int i=0; i= this.P[caseNum]) { + total++; + }else if (this.t[caseNum][i]/3 == this.P[caseNum] - 1) { + if (this.t[caseNum][i]%3 >= 1) { + total++; + }else if (S[caseNum] > 0 && this.t[caseNum][i]/3 > 0) { + total++; + S[caseNum]--; + } + }else if (this.t[caseNum][i]/3 == this.P[caseNum] - 2 && this.t[caseNum][i]%3 == 2 && this.t[caseNum][i]/3 > 0 && S[caseNum] > 0) { + total++; + S[caseNum]--; + } + } + return total; + } + + @Override + protected void processInput(String fileName) { + try { + this.openReadFile(fileName); + this.caseNum = Integer.parseInt(this.readLine()); + this.output = new String[this.caseNum]; + this.N = new int[this.caseNum]; + this.S = new int[this.caseNum]; + this.P = new int[this.caseNum]; + this.t = new int[this.caseNum][]; + for (int i = 0; i < this.caseNum; i++) { + String elem[] = this.readLine().split("" ""); + this.N[i] = Integer.parseInt(elem[0]); + this.S[i] = Integer.parseInt(elem[1]); + this.P[i] = Integer.parseInt(elem[2]); + this.t[i] = new int[N[i]]; + for (int j=0; j 0) { + new ProblemB(argv[0]); + } else { + new ProblemB(""B-large.in""); + } + } + +}" +A20922,"import java.io.*; +import java.util.*; + +class Main +{ + public static void main(String[] args) throws Exception + { + Main m = new Main(); + m.foo(); + } + + long count = 0; + void foo() throws Exception + { +// BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + Scanner s = new Scanner(System.in); + + int T = s.nextInt(); + int testNum = 1; + while(T-->0) + { + int numGooglers = s.nextInt(); + int numSurprises = s.nextInt(); + int p = s.nextInt(); + + int[] scores = new int[numGooglers]; + for(int k=0; k= p) + { + ret++; + continue; + } + // TODO: Handle a surprise + if(d+1 >= p && numSurprises != 0) + { + ret++; + numSurprises--; + continue; + } + } + else if(r==1) + { + if(d+1 >= p) + { + ret++; + continue; + } + // TODO: Handle a surprise + // I can't. + } + else if(r==2) + { + if(d+1 >= p) + { + ret++; + continue; + } + // TODO: Handle a surprise + if(d+2 >= p && numSurprises != 0) + { + ret++; + numSurprises--; + continue; + } + } + + } + //ret += numSurprises; + //ret -= Math.max(0, numSurp - numSurprises); + + //System.out.printf(""Known surprises: %d, Found surprises: %d\n"", numSurprises, numSurp); + System.out.printf(""Case #%d: %d\n"", testNum, ret); + testNum++; + } + } +}" +A22624,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + + +public class ProblemB { + + public static void main(String[] args) throws FileNotFoundException { + // TODO Auto-generated method stub + Scanner scanner = new Scanner(new File(""/Users/phan/Downloads/B-large.in"")); + PrintWriter pw = new PrintWriter(""/Users/phan/Downloads/outputLarge""); + int test = scanner.nextInt(); + + for (int i = 1; i <= test; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int[] scores = new int[n]; + for (int j = 0; j < n; j++) + scores[j] = scanner.nextInt(); + + Arrays.sort(scores); + + int cnt = 0; + + for (int j = n - 1; j >= 0; j--) { + int[] t = new int[3]; + t[0] = scores[j] / 3; + t[1] = t[0] + (scores[j] % 3) / 2; + t[2] = t[0] + (scores[j] % 3 + 1) / 2; + + //System.out.println(t[0] + "" "" + t[1] + "" "" + t[2]); + + if (t[2] >= p) { + cnt++; + } + else { + if (t[2] == p - 1) { + if ((t[1] > 0) && (t[1] == t[2])) { + if (s > 0) { + cnt++; + s--; + } + else { + break; + } + } + } + } + } + + + pw.println(""Case #"" + String.valueOf(i) + "": "" + String.valueOf(cnt)); + } + + scanner.close(); + pw.close(); + + } + + +} +" +A22450,"package util.graph; + +import java.util.HashSet; +import java.util.PriorityQueue; +import java.util.Set; + +public class DynDjikstra { + public static State FindShortest(Node start, Node target) { + PriorityQueue openSet = new PriorityQueue<>(); + Set closedSet = new HashSet<>(); + openSet.add(start); + while (!openSet.isEmpty()) { + Node current = openSet.poll(); + for (Edge edge : current.edges) { + Node end = edge.target; + if (closedSet.contains(end)) { + continue; + } + State newState = edge.travel(current.last); + //if (end.equals(target)) { + //return newState; + //} + if (openSet.contains(end)) { + if (end.last.compareTo(newState)>0) { + end.last = newState; + } + } else { + openSet.add(end); + end.last = newState; + } + } + closedSet.add(current); + if (closedSet.contains(target)) { + return target.last; + } + } + + return target.last; + } +} +" +A20865,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam.y12.round0; + +import utils.Jam; +import utils.JamCase; + +/** + * + * @author fabien + */ +public class DancingGooglers extends Jam { + + public DancingGooglers(String filename) { + super(filename); + } + + @Override + public JamCase getJamCase(int number) { + return new Line(this, number, lines[number]); + } + + private class Line extends JamCase { + + private String line; + private int s; + private int p; + private int[] scores; + + public Line(Jam parent, int number, String line) { + super(parent, number); + this.line = line; + } + + @Override + public void parse() { + String[] integers = line.split("" ""); + scores = new int[Integer.parseInt(integers[0])]; + s = Integer.parseInt(integers[1]); + p = Integer.parseInt(integers[2]); + int j = 0; + for (int i = 3; i < integers.length; i++) { + scores[j++] = Integer.parseInt(integers[i]); + } + } + + @Override + public void solve() { + int r = 0; + if (p == 0) { + r = scores.length; + } else { + float average = 0; + float pnor = p - 1; + float psus = p - 1.4f; + for (int score : scores) { + if (score > 0) { + average = score / 3.0f; + if (average > pnor) { + r++; + } else if (s > 0 && average >= psus) { + r++; + s--; + } + } + } + } + result = Integer.toString(r); + } + } +} +" +A21910,"package com.utility; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +public class FileReader { + + /* + * Reads data from a given file + */ + public static String readFromFile(String fileName) { + String DataLine = """"; + try { + File inFile = new File(fileName); + BufferedReader br = new BufferedReader(new InputStreamReader( + new FileInputStream(inFile))); + DataLine = br.readLine(); + br.close(); + } catch (FileNotFoundException ex) { + System.out.println(""File Not Found""); + return (null); + } catch (IOException ex) { + System.out.println("" IO Exception""); + return (null); + } + return (DataLine); + + } + + /* + * Reads data from a given file + */ + public static String readOneInputFromFile( + BufferedReader bufferedReader, + int numberOfLines) { + String dataOfLine = """"; + String singleInput = null; + StringBuffer stringBuffer = new StringBuffer(); + try { + for (int i = 0; i < (numberOfLines - 1); i++) { + dataOfLine = bufferedReader.readLine(); + if (dataOfLine != null) { + stringBuffer.append(dataOfLine); + } + } + } catch (IOException ex) { + System.out.println("" IO Exception""); + return (null); + } + + if (stringBuffer != null && stringBuffer.equals("""")) { + singleInput = stringBuffer.toString(); + } + return (singleInput); + + } + + + /* + * Reads data from a given file + */ + public static BufferedReader getBufferedReader(String fileName) { + BufferedReader br = null; + try { + File inFile = new File(fileName); + br = new BufferedReader(new InputStreamReader( + new FileInputStream(inFile))); + } catch (FileNotFoundException ex) { + System.out.println(""File Not Found""); + return (null); + } catch (IOException ex) { + System.out.println("" IO Exception""); + return (null); + } + return (br); + + } + + /* + * Reads data from a given file + */ + public static String readOneLine(BufferedReader bufferedReader) { + String DataLine = """"; + try { + DataLine = bufferedReader.readLine(); + } catch (IOException ex) { + System.out.println("" IO Exception""); + return (null); + } + return (DataLine); + + } + + /* + * Reads data from a given file + */ + public static String[] getSingleInputAsStrArray( + BufferedReader bufferedReader, + int numberOfLines) { + String dataOfLine = """"; + String[] inputStringArray = null; + if (bufferedReader != null && numberOfLines > 0) { + try { + inputStringArray = new String[numberOfLines]; + for (int i = 0; i < (numberOfLines); i++) { + dataOfLine = bufferedReader.readLine(); + if (dataOfLine != null) { + inputStringArray[i] = dataOfLine; + } + } + } catch (IOException ex) { + System.out.println("" IO Exception""); + return (null); + } + } + + return (inputStringArray); + } + + public static String[] extractInputSizeAndConstant( + BufferedReader bufferedReader) { + String[] strings = null; + if (bufferedReader != null) { + + String tempString = FileReader.readOneLine(bufferedReader); + if (tempString != null) { + strings = tempString.split(Constants.SPACE_REG_EXP.getConstant()); + } + } + return strings; + } + + public static void closeBufferedReader(BufferedReader bufferedReader) { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException e) { + System.out.println("" IO Exception""); + } + } + } + + + +} +" +A22158,"import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Scanner; + +public class Solution { + static final boolean DBG = false; + + // x x x s= 3x + // x x x+1 s= 3x +1 + // x x x-1 s= 3x -1 + // x x+1 x+1 s= 3x +2 + // x x-1 x-1 s= 3x-2 + + public static void main(String[] args) { + + AllNormal allNormal = new AllNormal(); + AllSurprising allSurprising = new AllSurprising(); + + Scanner sc = new Scanner(System.in); + long dStart = System.currentTimeMillis(); + StringBuilder sbout = new StringBuilder(); + + int T = sc.nextInt(); + for (int i = 1; i <= T; i++) { + Task one = new Task(sc, allNormal, allSurprising); + int res = one.getSolution(); + sbout.append(""Case #""); + sbout.append(i); + sbout.append("": ""); + sbout.append(res); + sbout.append('\n'); + } + + if (DBG) { + sbout.append(""time :""); + sbout.append(System.currentTimeMillis() - dStart); + } + System.out.print(sbout.toString()); + + } + + static class Task { + int N; // number of people + int S; // Surprising Triplets; + int p; // ? of N with best result >= p + + ArrayList persons = new ArrayList(); + String original = """"; + + public Task(Scanner sc, AllNormal allNormal, AllSurprising allSurprising) { + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + + original = N + "" "" + S + "" "" + p + "", ""; + for (int i = 0; i < N; i++) { + OnePerson one = new OnePerson(sc.nextInt()); + one.setHowItCan(allNormal, allSurprising, p); + persons.add(one); + original += "" "" + one.sum; + } + } + + int getSolution() { + int canNormal = 0; + int canWithSurprising = 0; + for (OnePerson one : persons) { + if (one.canHaveWithNormal) { + canNormal++; + } else { + if (one.canWithSurprising) + canWithSurprising++; + } + } + + return canNormal + Math.min(canWithSurprising, S); + } + } + + static class OnePerson { + int sum = 0; + boolean canHaveWithNormal = false; // can have best >= p without + // surprising rating + + boolean canWithSurprising = false; + + public OnePerson(int sum) { + this.sum = sum; + } + + void setHowItCan(AllNormal allNormal, AllSurprising allSurprising, int p) { + canHaveWithNormal = (allNormal.all.get(this.sum).best >= p); + canWithSurprising = allSurprising.canBeSurprisingWithBestGreater( + this.sum, p); + } + + } + + static class AllNormal { + HashMap all = new HashMap(); + + public AllNormal() { + for (int i = 0; i <= 10; i++) { + addOne(new NormalRating(3 * i, i, i)); + addOne(new NormalRating(3 * i + 1, i + 1, i)); + addOne(new NormalRating(3 * i - 1, i, i - 1)); + addOne(new NormalRating(3 * i + 2, i + 1, i)); + addOne(new NormalRating(3 * i - 2, i, i - 1)); + } + } + + void addOne(NormalRating one) { + if (one.isValid() && !all.containsKey(one.sum)) { + all.put(one.sum, one); + } + } + + void printAll() { + ArrayList vals = new ArrayList(); + vals.addAll(all.values()); + Collections.sort(vals); + for (NormalRating one : vals) { + one.printLn(); + } + } + } + + static class NormalRating implements Comparable { + int sum = 0; + int best = 0; + int min = 0; + + public NormalRating(int sum, int best, int min) { + this.sum = sum; + this.best = best; + this.min = min; + } + + boolean isValid() { + return (sum >= 0) && (best >= 0) && (min >= 0) && (best <= 10); + } + + void printLn() { + System.out.println(""s: "" + sum + "" b: "" + best + "" m: "" + min); + } + + @Override + public int compareTo(NormalRating other) { + return (new Integer(sum)).compareTo(new Integer(other.sum)); + } + + } + + static class AllSurprising { + ArrayList items = new ArrayList(); + + public AllSurprising() { + for (int i = 0; i <= 8; i++) { + addOne(new SurprisingRating(3 * i + 2, i + 2)); + addOne(new SurprisingRating(3 * i + 3, i + 2)); + addOne(new SurprisingRating(3 * i + 4, i + 2)); + + } + } + + void addOne(SurprisingRating one) { + items.add(one); + } + + boolean canBeSurprisingWithBestGreater(int withsum, int p) { + for (SurprisingRating rating : items) { + if (rating.sum == withsum) { + return (rating.best >= p); + } + } + + return false; + } + } + + // x x+2 x = 3x +2 + // x x+2 x+1 = 3x +3 + // x x+2 x+2 = 3x +4 + static class SurprisingRating { + int sum = 0; + int best = 0; + + public SurprisingRating(int sum, int best) { + this.sum = sum; + this.best = best; + } + } +} +" +A21732,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Scanner; +import java.util.StringTokenizer; + +/** + * + * @author bilal + */ +public class Googler { + + static String[] inputBuffer; + static int testCasesCount = 0; + + public Googler(InputStream is) { + Scanner scanner = new Scanner(is); + testCasesCount = scanner.nextInt(); + inputBuffer = new String[testCasesCount]; + int loopCounter = 0; + scanner.nextLine(); + while (scanner.hasNextLine()) { + String nextTestCase = scanner.nextLine(); + inputBuffer[loopCounter] = nextTestCase; + loopCounter++; + if (loopCounter == testCasesCount) { + break; + } + } + } + + public void solve_Googlers(String[] input) { + int solution = 0; + int googlers; + int surprisingCases; + int targetHighestScore; + for (int i = 0; i < input.length; i++) {//iterate over all test cases + System.out.print(""Case #"" + (i + 1) + "": ""); + solution = 0; + StringTokenizer st = new StringTokenizer(input[i]); + googlers = Integer.parseInt(st.nextToken()); + surprisingCases = Integer.parseInt(st.nextToken()); + targetHighestScore = Integer.parseInt(st.nextToken()); + //create Score objects from remaining tokens + LinkedList sortedScores = new LinkedList(); + while (st.hasMoreTokens()) { + sortedScores.add(Integer.parseInt(st.nextToken())); + } + Collections.sort(sortedScores); + //traverse over sorted collection + for (int j = googlers - 1; j >= 0; j--) { + + int totalScore = sortedScores.get(j); + int j1 = (int) Math.ceil(totalScore / 3.0); + int j2 = (int) Math.ceil((totalScore - j1) / 2.0); + int j3 = totalScore - j1 - j2; + //System.out.println("">>>>>""+j1+"" ""+j2+"" ""+j3); + // + if (j1 >= targetHighestScore) {//this googler scored the higheest target score + solution++; + continue; + } + if (surprisingCases <= 0) { + break;//no more surpising cases -> no more solutions + } + //deal with surprising cases + if (j1 == j2 && (j1 + 1) >= targetHighestScore && j2 > 0) { + surprisingCases--; + solution++; + } + } + + System.out.print(solution); + if (i != input.length - 1) { + System.out.println(); + } + //break;//deal with only first case + } + + + } + + public static void main(String[] args) { + Googler goolger = new Googler(System.in); + goolger.solve_Googlers(inputBuffer); + } + + class Scores { + + int totalScore; + int j1, j2, j3; + + public Scores(int totalScore, int j1, int j2, int j3) { + + this.totalScore = totalScore; + this.j1 = j1; + this.j2 = j2; + this.j3 = j3; + } + } +} + +" +A20263,"import java.util.Scanner; + + +public class dancingwiththegooglers { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner in = new Scanner(System.in); + int numOfLines = Integer.parseInt(in.nextLine()); + for(int i = 0;i=(3*p-2)) + result++; + else if(points[i] >= 3*p - 4 && S > 0) + { + if(points[i]>0) + { + result++; + S--; + } + } + } + return result; + } + + private static String readLine(String line) + { + String[] inputs = line.split("" ""); + int S = Integer.parseInt(inputs[1]); + int p = Integer.parseInt(inputs[2]); + int[] points = new int[inputs.length-3]; + for(int i = 0;i googlerScores = new ArrayList<>(); + for (int i = 3; i < googlers + 3; i++) { + googlerScores.add(input[i]); + } + Collections.sort(googlerScores, Collections.reverseOrder()); + + for (int googlerScore : googlerScores) { + if (googlerScore >= minTotal) { + result++; + } else if ((suprisingTriplets > 0) && (googlerScore >= minTotalSuprising)) { + suprisingTriplets--; + result++; + } else { + break; + } + } + + return String.valueOf(result); + } + + }.run(); + } +} +" +A22262," +import java.io.*; +import java.util.*; + +/** + * + * @author Hilos + */ +public class ProblemB { + + public static BufferedWriter bw; + public static BufferedReader br; + + public static void main(String[] args) { + try { + String filename = ""B-large""; + br = new BufferedReader(new FileReader(""E:\\Downloads\\"" + filename + "".in"")); + bw = new BufferedWriter(new FileWriter(""E:\\Downloads\\"" + filename + "".out"")); + + int caseCount = Integer.parseInt(br.readLine()); + + for (int c = 0; c < caseCount; c++) { + String[] lineParts = br.readLine().split("" ""); + + int N = Integer.parseInt(lineParts[0]); + int S = Integer.parseInt(lineParts[1]); + int p = Integer.parseInt(lineParts[2]); + + int[] scores = new int[N]; + + for (int s = 0; s < N; s++) { + scores[s] = Integer.parseInt(lineParts[3 + s]); + } + + SolveCase(c + 1, N, S, p, scores); + } + + + } catch (Exception exc) { + System.out.println(exc.toString()); + } + } + + public static void SolveCase(int caseNumber, int N, int S, int p, int[] scores) throws Exception { + + int aboveOrEqual = 0; + int surprisingLeft = S; + + int scoreCount = scores.length; + for (int s = 0; s < scoreCount; s++) { + int score = scores[s]; + + if(score == 0){ + if(p == 0){ + aboveOrEqual++; + } + }else if (score % 3 == 1) { + if ((score + 2) / 3 >= p) { + aboveOrEqual++; + } + } else if (score % 3 == 0) { + if ((score / 3) >= p) { + aboveOrEqual++; + } else if (surprisingLeft > 0 && (score / 3) + 1 >= p) { + aboveOrEqual++; + surprisingLeft--; + } + } else if (score % 3 == 2) { + if (((score + 1) / 3) >= p) { + aboveOrEqual++; + } else if (surprisingLeft > 0 && ((score + 1) / 3) + 1 >= p) { + aboveOrEqual++; + surprisingLeft--; + } + } + } + + bw.write(""Case #"" + caseNumber + "": "" + aboveOrEqual + ""\n""); + bw.flush(); + } +} +" +A21741,"package com.google.codejam; + +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.regex.Pattern; + +public class CodeJam2 { + private static int N, P, S; + private static int inputNumbers[]; + private static int testCase; + private static FileOutputStream fostream; + private static DataOutputStream out; + + public static void main(String[] args) { + + try { + fostream = new FileOutputStream(""output2.out""); + out = new DataOutputStream(fostream); + Scanner scanner = new Scanner(new File(""B-large.in"")); + String inputNumberline = scanner.nextLine(); + testCase = Integer.parseInt(inputNumberline); + for (int i = 0; i < testCase; i++) { + filterString(scanner.nextLine(), i); + } + out.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + + } + + private static void filterString(String fstring, int caseNumber) { + + final Pattern SPACE = Pattern.compile("" ""); + ArrayList myList = new ArrayList(); + ArrayList baseList = new ArrayList(); + int i = 0; + for (String token : SPACE.split(fstring)) { + try { + if (i == 0) { + inputNumbers = new int[Integer.parseInt(token) + 3]; + inputNumbers[i] = Integer.parseInt(token); + i++; + } else { + inputNumbers[i] = Integer.parseInt(token); + i++; + } + } catch (NumberFormatException ex) { + System.err.println(token + "" is not a number""); + } + } + + P = inputNumbers[2]; + S = inputNumbers[1]; + N = inputNumbers[0]; + + for (int j = 3; j < inputNumbers.length; j++) { + myList.add(inputNumbers[j]); + baseList.add(inputNumbers[j] / 3); + + } + + int mod[] = new int[N]; + int count; + count = 0; + for (int l = 0; l < N; l++) { + mod[l] = myList.get(l) % 3; + switch (mod[l]) { + case 0: + if (baseList.get(l) >= P) + count++; + else { + if (S > 0 && baseList.get(l) > 0 + && baseList.get(l) + 1 >= P) { + count++; + S--; + } + } + break; + case 1: + if (baseList.get(l) >= P || baseList.get(l) + 1 >= P) { + count++; + } else { + if (baseList.get(l) > 0 && baseList.get(l) + 1 >= P) { + count++; + S--; + } + } + break; + case 2: + if (baseList.get(l) + 1 >= P || baseList.get(l) >= P) { + count++; + } else { + if (S > 0 && baseList.get(l) + 2 >= P) { + count++; + S--; + } + } + break; + + } + } + + System.out.println(""Case #"" + (caseNumber + 1) + "": "" + count); + try { + out.writeBytes(""Case #"" + (caseNumber + 1) + "": "" + count + ""\n""); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } + +} + + + +" +A22647,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package dancingwiththegooglers; + +/** + * + * @author James + */ +public class ScoreAnalyzer { + + private int targetBestResultScore; + private int surprisingScores; + private int[] totalScores; + + public ScoreAnalyzer(int[] data) { + surprisingScores = data[1]; + targetBestResultScore = data[2]; + + totalScores = new int[data[0]]; + for (int i = 0; i < data[0]; i++) { + totalScores[i] = data[i+3]; + } + } + + public int getMaxNumOfHighScoringDancers() { + int result = 0; + + int avgTotal = targetBestResultScore * 3; + + if (avgTotal == 0) { + return totalScores.length; // all competitors got at least 0. + } + + for (int i = 0; i < totalScores.length; i++) { + if (totalScores[i] != 0) { + if (totalScores[i] >= (avgTotal-2)) { + // score set is at least + // target-1 target-1 target + result++; + } else if ((totalScores[i] >= (avgTotal-4)) && (surprisingScores > 0)) { + // score is at least + // target-2 target-2 target + // and this result may be a surprising score + result++; + surprisingScores--; // remove a surprising score + } // else it cannot possibly have a sufficiently high max score + } + } + return result; + } + +} +" +A21737,"package prob2; + +import com.bertramtruong.utils.BT; +import com.bertramtruong.utils.DataReader; + +/** + * + * @author Bertram + */ +public class Prob2 { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + DataReader dr = new DataReader(""input.in""); + + try { + int nLines = dr.readInt(); + for (int i = 0; i < nLines; i++) { + //BT.db(""==================== case "", (i + 1), "" =================""); + System.out.print(""Case #"" + (i + 1) + "": ""); + int nGooglers = dr.readInt(); + int nSurprising = dr.readInt(); + int bestRes = dr.readInt(); + + //BT.db(""nGooglers: "", nGooglers); + //BT.db(""nSurprising: "", nSurprising); + //BT.db(""bestRes: "", bestRes); + + int np = 0; + for (int j = 0; j < nGooglers; j++) { + // triplets, take a number divide by 3, + int totalScore = dr.readInt(); + int triplet = totalScore / 3; + if (triplet >= bestRes) { + //BT.db(""bestres: "", triplet); + np++; + } else { + /** + * double remaindar = triplet % 3; // can we do it with + * 1? if (triplet + 1 >= bestRes) { if (remaindar == 0 + * && nSurprising == 0) { } else { nSurprising--; np++; + * } } + * + * if (triplet + 2 >= bestRes) { BT.db(""triplet: "", + * triplet); // can you do it with 1? if (triplet + 1 >= + * bestRes) { // good np++; } else { if (nSurprising > + * 0) { //BT.db(""after: "", triplet + 2); nSurprising--; + * triplet += 2; } } } + * + * if (triplet >= bestRes) { np++; } + */ + int rem = totalScore % 3; + if (triplet + 1 >= bestRes && rem >= 1) { + np++; + } else { + if (totalScore != 0) { + switch (rem) { + case 0: + if (nSurprising > 0 && triplet + 1 >= bestRes) { + triplet++; + nSurprising--; + } + break; + case 1: + triplet++; + break; + case 2: + if (nSurprising > 0 && triplet + 2 >= bestRes) { + triplet += 2; + nSurprising--; + } + break; + } + + if (triplet >= bestRes) { + np++; + } + } + } + } + } + System.out.print(np); + System.out.println(); + } + } catch (Exception x) { + } + } +} +" +A21381,"import java.util.Scanner; + +public class ProblemB { + static Scanner in = new Scanner(System.in); + + public static void main(String[] args) throws Exception{ + int lineCount = Integer.valueOf(in.nextLine()); + int[] lines = new int[lineCount]; + + for(int n = 0; n < lineCount; n++) { + int N = in.nextInt(), + S = in.nextInt(), + p = in.nextInt(); + + int max = 0; + + for (int i = 0; i < N; i++) { + int score= in.nextInt(); + int single = score / 3; + + switch (score % 3) { + case 0: + if (single >= p) { + max++; + } else { + if (S > 0 && score >= 2 && score <= 28 && single + 1 >= p) { + max++; + S--; + } + } + break; + case 1: + if (single + 1 >= p) { + max++; + } + break; + case 2: + if (single +1 >= p) { + max++; + } else { + if (S > 0 && score >= 2 && score <= 28 && single + 2 >= p) { + max++; + S--; + } + } + } + } + + lines[n] = max; + + in.nextLine(); + } + + for(int i = 1; i <= lineCount; i++) { + System.out.println(""Case #"" + i + "": "" + lines[i-1]); + } + } +}" +A21566,"import java.io.*; +import java.util.*; +import java.math.*; + +class B +{ + private static final boolean DEBUG_ON = true; + private static final boolean ECHO_ON = true; + + private static BufferedReader input; + private static BufferedWriter output; + + private static final int INF = Integer.MAX_VALUE / 2; + private static final int MOD = 10007; + + public static void main(String[] args) + { + try + { + input = new BufferedReader(new FileReader(args[0] + "".in"")); + output = new BufferedWriter(new FileWriter(args[0] + "".out"")); + + String line = input.readLine(); + int testcases = getInt(line, 0); + + for (int testcase = 1; testcase <= testcases; testcase++) + { + line = input.readLine(); + int N = getInt(line, 0); + int S = getInt(line, 1); + int P = getInt(line, 2); + + int[] sum = getIntArray(line, 3, 3 + N); + int count = 0; + for (int s : sum) + { + if (s >= (3 * P - 2)) {count++;} + else if (s >= (3 * P - 4) && (1 != P)) {if (S > 0) {S--; count++;}} + } + + String result = ""Case #"" + testcase + "": "" + count; + output(result); + } + + input.close(); + output.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static int getInt(String line, int index) {return Integer.parseInt(getString(line, index));} + public static long getLong(String line, int index) {return Long.parseLong(getString(line, index));} + public static double getDouble(String line, int index) {return Double.parseDouble(getString(line, index));} + public static String getString(String line, int index) + { + line = line.trim(); + while (index > 0) {line = line.substring(line.indexOf(' ') + 1); index--;} + + if ((-1) == line.indexOf(' ')) {return line;} + else {return line.substring(0, line.indexOf(' '));} + } + + public static int[] getIntArray(String line) + { + String[] strings = getStringArray(line); + int[] numbers = new int[strings.length]; + for (int i = 0; i < strings.length; i++) {numbers[i] = Integer.parseInt(strings[i]);} + return numbers; + } + public static long[] getLongArray(String line) + { + String[] strings = getStringArray(line); + long[] numbers = new long[strings.length]; + for (int i = 0; i < strings.length; i++) {numbers[i] = Long.parseLong(strings[i]);} + return numbers; + } + public static double[] getDoubleArray(String line) + { + String[] strings = getStringArray(line); + double[] numbers = new double[strings.length]; + for (int i = 0; i < strings.length; i++) {numbers[i] = Double.parseDouble(strings[i]);} + return numbers; + } + public static String[] getStringArray(String line) {return line.trim().split(""(\\s)+"", 0);} + + public static int[] getIntArray(String line, int begin, int end) + { + String[] strings = getStringArray(line, begin, end); + int[] numbers = new int[end - begin]; + for (int i = begin; i < end; i++) {numbers[i - begin] = Integer.parseInt(strings[i - begin]);} + return numbers; + } + public static long[] getLongArray(String line, int begin, int end) + { + String[] strings = getStringArray(line, begin, end); + long[] numbers = new long[end - begin]; + for (int i = begin; i < end; i++) {numbers[i - begin] = Long.parseLong(strings[i - begin]);} + return numbers; + } + public static double[] getDoubleArray(String line, int begin, int end) + { + String[] strings = getStringArray(line, begin, end); + double[] numbers = new double[end - begin]; + for (int i = begin; i < end; i++) {numbers[i - begin] = Double.parseDouble(strings[i - begin]);} + return numbers; + } + public static String[] getStringArray(String line, int begin, int end) + { + String[] lines = line.trim().split(""(\\s)+"", 0); + String[] results = new String[end - begin]; + for (int i = begin; i < end; i++) {results[i - begin] = lines[i];} + return results; + } + + public static char[][] getCharMatrix(BufferedReader input) throws Exception + { + String line = input.readLine(); + int R = getInt(line, 0); + int C = getInt(line, 1); + char[][] matrix = new char[R][C]; + for (int i = 0; i < R; i++) + { + line = input.readLine(); + for (int j = 0; j < C; j++) {matrix[i][j] = line.charAt(j);} + } + return matrix; + } + public static int[][] getIntMatrix(BufferedReader input) throws Exception + { + String line = input.readLine(); + int R = getInt(line, 0); + int C = getInt(line, 1); + int[][] matrix = new int[R][C]; + for (int i = 0; i < R; i++) + { + line = input.readLine(); + for (int j = 0; j < C; j++) {matrix[i][j] = getInt(line, j);} + } + return matrix; + } + + public static boolean[][] newBooleanMatrix(int R, int C, boolean value) + { + boolean[][] matrix = new boolean[R][C]; + for (int i = 0; i < R; i++) for(int j = 0; j < C; j++) {matrix[i][j] = value;} + return matrix; + } + public static char[][] newCharMatrix(int R, int C, char value) + { + char[][] matrix = new char[R][C]; + for (int i = 0; i < R; i++) for(int j = 0; j < C; j++) {matrix[i][j] = value;} + return matrix; + } + public static int[][] newIntMatrix(int R, int C, int value) + { + int[][] matrix = new int[R][C]; + for (int i = 0; i < R; i++) for(int j = 0; j < C; j++) {matrix[i][j] = value;} + return matrix; + } + public static long[][] newLongMatrix(int R, int C, long value) + { + long[][] matrix = new long[R][C]; + for (int i = 0; i < R; i++) for(int j = 0; j < C; j++) {matrix[i][j] = value;} + return matrix; + } + public static double[][] newDoubleMatrix(int R, int C, double value) + { + double[][] matrix = new double[R][C]; + for (int i = 0; i < R; i++) for(int j = 0; j < C; j++) {matrix[i][j] = value;} + return matrix; + } + + public static void output(String s) throws Exception + { + if (ECHO_ON) {System.out.println(s);} + output.write(s); + output.newLine(); + } + + public static String toKey(boolean[] array) + { + StringBuffer buffer = new StringBuffer(array.length + "",""); + for (int i = 0; i < array.length / 16; i++) + { + char c = 0; + for (int j = 0; j < 16; j++) + { + c <<= 1; if (array[i * 16 + j]) {c += 1;} + } + buffer.append(c + """"); + } + char c = 0; + for (int j = 0; j < (array.length % 16); j++) + { + c <<= 1; if (array[(array.length / 16) * 16 + j]) {c += 1;} + } + buffer.append(c + """"); + return buffer.toString(); + } + public static String toKey(int[] array, int bit) + { + StringBuffer buffer = new StringBuffer(array.length + "",""); + if (bit > 16) + { + for (int i = 0; i < array.length; i++) + { + char c1 = (char)(array[i] >> 16); + char c2 = (char)(array[i] & 0xFFFF); + buffer.append("""" + c1 + c2); + } + } + else + { + int n = 16 / bit; + for (int i = 0; i < array.length / n; i++) + { + char c = 0; + for (int j = 0; j < n; j++) + { + c <<= bit; c += array[i * n + j]; + } + buffer.append(c + """"); + } + char c = 0; + for (int j = 0; j < (array.length % n); j++) + { + c <<= bit; c += array[(array.length / n) * n + j]; + } + buffer.append(c + """"); + } + return buffer.toString(); + } + + public static void debug(String s) + {if (DEBUG_ON) {System.out.println(s);}} + public static void debug(String s0, double l0) + {if (DEBUG_ON) {System.out.println(s0+"" = ""+l0);}} + public static void debug(String s0, double l0, String s1, double l1) + {if (DEBUG_ON) {System.out.println(s0+"" = ""+l0+""; ""+s1+"" = ""+l1);}} + public static void debug(String s0, double l0, String s1, double l1, String s2, double l2) + {if (DEBUG_ON) { System.out.println(s0+"" = ""+l0+""; ""+s1+"" = ""+l1+""; ""+s2+"" = ""+l2);}} + public static void debug(String s0, double l0, String s1, double l1, String s2, double l2, String s3, double l3) + {if (DEBUG_ON) {System.out.println(s0+"" = ""+l0+""; ""+s1+"" = ""+l1+""; ""+s2+"" = ""+l2+""; ""+s3+"" = ""+l3);}} + public static void debug(String s0, double l0, String s1, double l1, String s2, double l2, String s3, double l3, String s4, double l4) + {if (DEBUG_ON) {System.out.println(s0+"" = ""+l0+""; ""+s1+"" = ""+l1+""; ""+s2+"" = ""+l2+""; ""+s3+"" = ""+l3+""; ""+s4+"" = ""+l4);}} + + public static void debug(boolean[] array) {if (DEBUG_ON) {debug(array, "" "");}} + public static void debug(boolean[] array, String separator) + { + if (DEBUG_ON) + { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < array.length - 1; i++) {buffer.append((array[i] == true ? ""1"" : ""0"") + separator);} + buffer.append((array[array.length - 1] == true) ? ""1"" : ""0""); + System.out.println(buffer.toString()); + } + } + public static void debug(boolean[][] array) {if (DEBUG_ON) {debug(array, "" "");}} + public static void debug(boolean[][] array, String separator) + {if (DEBUG_ON) {for (int i = 0; i < array.length; i++) {debug(array[i], separator);}}} + + public static void debug(char[] array) {if (DEBUG_ON) {debug(array, "" "");}} + public static void debug(char[] array, String separator) + { + if (DEBUG_ON) + { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < array.length - 1; i++) {buffer.append(array[i] + separator);} + buffer.append(array[array.length - 1]); + System.out.println(buffer.toString()); + } + } + public static void debug(char[][] array) {if (DEBUG_ON) {debug(array, "" "");}} + public static void debug(char[][] array, String separator) + {if (DEBUG_ON) {for (int i = 0; i < array.length; i++) {debug(array[i], separator);}}} + + public static void debug(int[] array) {if (DEBUG_ON) {debug(array, "" "");}} + public static void debug(int[] array, String separator) + { + if (DEBUG_ON) + { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < array.length - 1; i++) {buffer.append(array[i] + separator);} + buffer.append(array[array.length - 1]); + System.out.println(buffer.toString()); + } + } + public static void debug(int[][] array) {if (DEBUG_ON) {debug(array, "" "");}} + public static void debug(int[][] array, String separator) + {if (DEBUG_ON) {for (int i = 0; i < array.length; i++) {debug(array[i], separator);}}} +} +" +A21163,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + + +public class DancingWithTheGooglers { + + + /** + * @param args + */ + public static void main(String[] args) { + ArrayList input = new ArrayList(); + BufferedReader br = null; + int googlerNumber = 0; + int surpriseNuber = 0; + int p = 0; + int[] points = null; + try { + br = new BufferedReader(new InputStreamReader(System.in)); + int totalLineNumber = Integer.parseInt(br.readLine().trim()); + for(int i = 0;i < totalLineNumber;i++){ + input.add(br.readLine()); + } + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + for(int i = 0;i < input.size();i++){ + String[] infoArray = input.get(i).split("" ""); + googlerNumber = Integer.parseInt(infoArray[0]); + surpriseNuber = Integer.parseInt(infoArray[1]); + p = Integer.parseInt(infoArray[2]); + points = new int[googlerNumber]; + for(int j = 0;j < googlerNumber;j++){ + points[j] = Integer.parseInt(infoArray[3+j]); + } + int notSurprisePointsNumber = 0; + int notSurprisePointsMin = 3 * p - 2; + if(notSurprisePointsMin < 0){ + notSurprisePointsMin = p; + } + int surprisePointsNumber = 0; + int surprisePointsMin = 3 * p - 4; + if(surprisePointsMin < 0){ + surprisePointsMin = p; + } + int result = 0; + if(googlerNumber != surpriseNuber){ + for(int j = 0;j < points.length;j++){ + if(points[j] >= notSurprisePointsMin){ + notSurprisePointsNumber++; + points[j] = -100; + } + } + } + if(surpriseNuber != 0){ + for(int j = 0;j < points.length && surprisePointsNumber < surpriseNuber;j++){ + if(points[j] >= surprisePointsMin){ + surprisePointsNumber++; + points[j] = -100; + } + } + } + result = surprisePointsNumber + notSurprisePointsNumber; + if(p == 0){ + result = googlerNumber; + } + if(result > googlerNumber){ + result = googlerNumber - (result - googlerNumber); + } + int flag = i + 1; + System.out.print(""Case #"" + flag + "": ""); + System.out.println(result); + } + } + +} +" +A20218,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class ProblemB { + public static void main(String[]args) throws FileNotFoundException { + File file = new File(""test.txt""); + Scanner scan = new Scanner(file); + + int cases = Integer.parseInt(scan.nextLine()); + + for(int i=1;i <= cases;i++) { + int dancers = scan.nextInt(); + int surprise = scan.nextInt(); + int minscore = scan.nextInt(); + int winner = 0; + for(int j=0;j= (minscore*3-2)) winner++; + else if(score >= (minscore*3-4) && surprise!=0 && score!=0) { winner++; surprise--; } + else; + } + if (scan.hasNextLine()) scan.nextLine(); + System.out.println(""Case #"" + i + "": "" + winner); + } + + } +} +" +A21682,"import static java.lang.Double.parseDouble; +import static java.lang.Integer.parseInt; +import static java.lang.Long.parseLong; +import static java.lang.System.exit; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.StringTokenizer; + + +public class Dancing { + + static BufferedReader in; + static PrintWriter out; + static StringTokenizer tok; + + static int nextInt() throws IOException { + return parseInt(next()); + } + + static long nextLong() throws IOException { + return parseLong(next()); + } + + static double nextDouble() throws IOException { + return parseDouble(next()); + } + + static String next() throws IOException { + while (tok == null || !tok.hasMoreTokens()) { + tok = new StringTokenizer(in.readLine()); + } + return tok.nextToken(); + } + + static String nextLine() throws IOException { + return in.readLine(); + } + + static char at(String s, int i) { + return s.charAt(i); + } + + public static void main(String[] args) { + try { + in = new BufferedReader(new InputStreamReader(new FileInputStream(""B-large.in""))); + out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(""B-large.out""))); +// in = new BufferedReader(new InputStreamReader(System.in)); +// out = new PrintWriter(new OutputStreamWriter(System.out)); + solve(); + in.close(); + out.close(); + } catch (Throwable e) { + e.printStackTrace(); + exit(1); + } + } + + private static void solve() throws IOException { + int t = nextInt(); + for (int i = 0; i < t; i ++) { + int id = i+1; + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int[] g = new int[n]; + for (int j = 0; j < n; j ++) {g[j] = nextInt();} + if (p == 0) { + out.println(""Case #"" + id + "": "" + n); + continue; + } + if (p == 1) { + int res = 0; + for (int j = 0; j < n; j ++) { + if (g[j] > 0) res ++; + } + out.println(""Case #"" + id + "": "" + res); + continue; + } + int low = p * 3 - 4; + int high = low + 1; + int sup = 0; + int qual = 0; + for (int j = 0; j < n; j ++) { + if (g[j] == 0) continue; + if (g[j] < low) continue; + if (g[j] > high) qual ++; + else sup ++; + } + sup = Math.min(sup, s); + out.println(""Case #"" + id + "": "" + (sup + qual)); + } + } +}" +A23043,"import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; + + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + try { + BufferedReader br = new BufferedReader(new FileReader(""/Users/William/Desktop/B-large.in"")); + String strLine; + + strLine = br.readLine(); + int numOfLine = Integer.parseInt(strLine); + +// ArrayList inputs = new ArrayList(); + for (int i=0;i= gap) { + numSuccess++; + } + else if (average == gap-1){ + switch (score%3) { + case 0: + if ((suprise>0) && (score>0)){ + numSuccess++; + suprise--; + } + break; + case 1: + if (score>1) { + numSuccess++; + } + break; + case 2: + if ((score==2) && (suprise>0)){ + numSuccess++; + suprise--; + } + else { + numSuccess++; + } + break; + } + } + else if (average == gap-2) { + switch (score%3) { + case 0: + case 1: + break; + case 2: + if (suprise>0) { + numSuccess++; + suprise--; + } + break; + } + } + } + + int caseNum = i + 1; + System.out.println(""Case #"" + caseNum + "": "" + numSuccess); + } + } + catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } + +} +" +A22935,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.ArrayList; + +public class B { + + private String nombreInputOutput; + private BufferedReader input; + public int surprising = 0; + + public B(String nombreInputOutput) { + this.nombreInputOutput = nombreInputOutput; + } + + public void run() { + try { + input = new BufferedReader(new FileReader(new File(nombreInputOutput + "".in""))); + PrintWriter output = new PrintWriter(new File(nombreInputOutput + "".out"")); + + int num_cases = Integer.parseInt(input.readLine().trim()); + String Solution; + for (int runs = 1; runs <= num_cases; runs++) { + Solution = new Solution().solve_case(input.readLine().trim()); + String result = ""Case #"" + runs + "": "" + Solution; + output.println(result); + System.out.println(result); + } + output.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public class Solution { + + public String solve_case(String caseline) throws Exception { + String[] inputs = caseline.split(""\\s+""); + int numGooglers = Integer.parseInt(inputs[0]); + surprising = Integer.parseInt(inputs[1]); + int bestResult = Integer.parseInt(inputs[2]); + ArrayList googlers = new ArrayList(); + int inputsTotal = inputs.length; + for (int i = 1; i <= numGooglers; i++) { + googlers.add(Double.parseDouble(inputs[inputsTotal - i])); + } + + int maxNumGooglers = 0; + for (Double g : googlers) { + if (checkGoogler(g, bestResult)) { + maxNumGooglers++; + } + } + String Solution = Integer.toString(maxNumGooglers); + return Solution; + } + + private Boolean checkGoogler(Double result, int bestResult) { + Double resultbythree = result / 3; + if (resultbythree > bestResult-1) { + return true; + } else if (bestResult*3 > 5 && result > bestResult*3-5) { + if (surprising > 0) { + surprising--; + return true; + } else { + return false; + } + } else { + return false; + } + } + } + + public static void main(String[] args) { + B b = new B(""B-large""); + b.run(); + } + +}" +A22138,"/** + * + */ +package asem.core.util; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.math.BigInteger; + +/** + * @author A.Alathwari + * + * InputReader + * + */ +public class InputReader extends BufferedReader { + + /** + * @param in + */ + public InputReader(Reader in) { + super(in); + // TODO Auto-generated constructor stub + } + + /** + * @param in + * @param sz + */ + public InputReader(Reader in, int sz) { + super(in, sz); + // TODO Auto-generated constructor stub + } + + public InputReader(String fileName) throws java.io.FileNotFoundException { + // TODO Auto-generated constructor stub + this(new FileReader(fileName)); + } + + public String readLine(boolean skipEmptyLines) throws IOException { + + String str = this.readLine(); + + if (skipEmptyLines) + while (str.length() == 0) + str = this.readLine(); + + return str; + } + + private String readIntegral() throws IOException { + + int c = this.read(); + + while (c == ' ' || c == '\n' || c == '\t' || c == '\r') + c = this.read(); + + boolean sign = false; + + while (c == '-') { + c = this.read(); + sign = !sign; + } + + StringBuffer buf = new StringBuffer(); + while (Character.isDigit(c)) { + buf.append((char) c); + this.mark(1); + c = this.read(); + } + + this.reset(); + + return (sign) ? ""-"" + buf.toString() : buf.toString(); + } + + private String readFlat() throws IOException { + + int c = this.read(); + + while (c == ' ' || c == '\n' || c == '\t' || c == '\r') + c = this.read(); + + boolean sign = false; + + while (c == '-') { + c = this.read(); + sign = !sign; + } + + StringBuffer buf = new StringBuffer(); + while (Character.isDigit(c) || c == '.') { + buf.append((char) c); + this.mark(1); + c = this.read(); + } + + this.reset(); + + return (sign) ? ""-"" + buf.toString() : buf.toString(); + } + + public int readInt() throws IOException { + return Integer.parseInt(readIntegral()); + } + + public long readLong() throws IOException { + return Long.parseLong(readIntegral()); + } + + public double readDouble() throws IOException { + return Double.parseDouble(readFlat()); + } + + public BigInteger readBigInteger() throws IOException { + + try { + return new BigInteger(readWord()); + } catch (NumberFormatException e) { + throw new java.util.InputMismatchException(); + } + } + + @SuppressWarnings(""deprecation"") + public String readWord() throws IOException { + + int c = this.read(); + + while (Character.isSpace((char)c)) + c = this.read(); + + StringBuffer res = new StringBuffer(); + do { + res.appendCodePoint(c); + c = this.read(); + } while (!Character.isSpace((char)c) && Character.isDefined(c)); + + return res.toString(); + } + + @SuppressWarnings(""deprecation"") + public String readString() throws IOException { + + int c = this.read(); + + while (Character.isSpace((char) c)) + c = this.read(); + + StringBuffer buf = new StringBuffer(); + while (Character.isDefined(c)) { + buf.append((char) c); + this.mark(1); + c = this.read(); + } + + this.reset(); + + return buf.toString(); + } + + @SuppressWarnings(""deprecation"") + public char readCharacter() throws IOException { + + char c = (char) this.read(); + + while (Character.isSpace(c)) + c = (char) this.read(); + + return c; + } +} +" +A20199," import java.io.*; +import java.util.*; + +class d{ + File ffff; + FileReader fr; + BufferedReader br; + + File fout; + FileWriter fw; + BufferedWriter bw; + + public void run(){ + try{ + + ffff=new File(""C:\\Users\\Dimitris\\Documents\\NetBeansProjects\\jam\\src\\B-small-attempt0.in""); + fr=new FileReader(ffff); + br=new BufferedReader(fr); + + fout=new File(""C:\\Users\\Dimitris\\Documents\\NetBeansProjects\\jam\\src\\output.out""); + fw=new FileWriter(fout); + bw=new BufferedWriter(fw); + + + + int ipol; + int diair; + + int loop=new Integer(br.readLine()); + int ii=1; + + for(int j=0;j=t){ + res++; + } + + + else{ + + if(ipol==0){ + if(fail!=f){ + int j1=diair+1; + if(j1>=t){ + res++; + fail++; + continue; + } + } + } + if(ipol==1){ + int j2=diair+1; + if(j2>=t){ + res++; + continue; + } + } + + if(ipol==2){ + int j3=diair+1; + if(j3>=t){ + res++; + continue; + } + + if(fail!=f){ + int j4=diair+2; + if(j4>=t){ + res++; + fail++; + continue; + } + } + } + + if(ipol>2) continue; + + } + + }//for + String r=Integer.toString(res); + bw.write(""Case #""+ii+"": ""+r); + bw.write('\n'); + ii++; + + } + bw.close(); + br.close(); + } + catch(Exception e){ + e.printStackTrace(); + } + + +} //run + + + public static void main(String[]args){ + d dd=new d(); + dd.run(); + + } +} //class +" +A23020,"import java.util.*; +public class ProblemB { + public static void main(String... args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int t=1; t<=T; t++) { + String ans=""""; + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + List list = new ArrayList<>(); + int higher = 0; + int border = 0; + for (int n=0; n= p) higher++; + else if (p-1 != 0 && ave == p-1 && point%3 != 1) border++; + } + if(border >= S){ + System.out.println(""Case #"" +t+ "": "" +(higher+S)); + } else { + System.out.println(""Case #"" +t+ "": "" +(higher+border)); + } + } + } +} +" +A22022,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.Vector; + + +public class problemB { + + Vector lines = new Vector(); + + public static void main(String[] a) { + problemB pb = new problemB(); + + pb.lines = pb.readfile(""C:\\eclipse\\Ashish\\files\\B-large.in""); + int nooftestcases = Integer.parseInt(pb.lines.elementAt(0)); + System.out.println(nooftestcases); + Vector outlines = new Vector(); + //int j=1; + for (int i=1; i<=nooftestcases; i++) { + String[] s = pb.lines.elementAt(i).split("" ""); + int go = Integer.parseInt(s[0]); + int su = Integer.parseInt(s[1]); + int ms = Integer.parseInt(s[2]); + Vector sc = new Vector(); + for (int j=0; j 0)) { + System.out.println(""Yes""); + howmany++; + continue; + } + + if (tc.minscore - sd > 1.5) { + System.out.println(""No""); + continue; + } + + if (remsurp > 0 && sd !=0 ) { + System.out.println(""finally""); + howmany++; + remsurp--; + } else { + System.out.println(""Hard luck""); + } + + } + + + return howmany; + } + + public void writefile(String name, Vector l) { + try{ + // Create file + FileWriter fstream = new FileWriter(name); + BufferedWriter out = new BufferedWriter(fstream); + for (int i=0; i readfile(String fp) { + Vector lines = new Vector(); + try { + FileReader fr = new FileReader(fp); + BufferedReader br = new BufferedReader(fr); + String s; + while((s = br.readLine()) != null) { + //System.out.println(s); + lines.addElement(s); + } + fr.close(); + + } + catch (Exception e) { + System.out.println(e); + } + return lines; + } + +} +" +A22894,"import java.util.*; +import java.io.*; + +public class b { + + public static void main (String[] args){ + + //settingup input and output + Scanner in = null; + PrintWriter out = null; + try{ + in = new Scanner(new File(""blarge.txt"")); + out = new PrintWriter(new FileOutputStream(""blargeout.txt""), true); + }catch(Exception e){ + System.out.println(""file not found""); + } + + // number of cases + int n = in.nextInt(); + in.nextLine(); + + // run through each case + for(int currentCase = 1; currentCase <= n; currentCase++){ + + int result = 0; + int N = in.nextInt(); // number of Googlers + int S = in.nextInt(); // number of surprising triplets + int p = in.nextInt(); // must be >= p to be considered + int t[] = new int[N]; // total point for each Googler + for(int i = 0; i < N; i++){ + t[i] = in.nextInt(); + } + + for(int i = 0; i < N; i++){ + if(t[i] >= (p*3 - 2)) result++; // automatically pass + else if((S > 0) && ((((p*3 - 3) > 0) && (t[i] == (p*3 - 3))) + || (((p*3 - 4) > 0) && (t[i] == (p*3 - 4))))){ + result++; + S--; // consumes a quota of surprising triplet to pass + } + } + + //output answers for each case + out.println(""Case #"" + currentCase + "": "" + result); + } + + // close input and output streams + in.close(); + out.close(); + } +}" +A22852,"package qualification.common; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Created by IntelliJ IDEA. + * User: ofer + * Date: 14/04/12 + * Time: 17:31 + * To change this template use File | Settings | File Templates. + */ +public class OutputWriter { + + public static void writeOutput(String filename,String[] output){ + try { + FileWriter write = new FileWriter( filename , false); + PrintWriter print_line = new PrintWriter( write ); + for (String str: output){ + print_line.println(str); + } + print_line.close(); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } +} +" +A23018,"package tr0llhoehle.cakemix.googleCodejam; + +import java.text.ParseException; +import java.util.ArrayList; + +import tr0llhoehle.cakemix.utility.googleCodeJam.Problem; +import tr0llhoehle.cakemix.utility.googleCodeJam.SupportedTypes; + +public class DWGProblem extends Problem { + + private int numberOfSuprisingTriplets; + private int border; + private int[] dancerSums; + + public DWGProblem() { + this.types = new SupportedTypes[1]; + this.types[0] = SupportedTypes.LIST_INT; + } + + @Override + public void addValue(Object o) throws ParseException { + ArrayList input = (ArrayList) o; + dancerSums = new int[input.get(0)]; + numberOfSuprisingTriplets = input.get(1); + border = input.get(2); + + for (int i = 0; i < dancerSums.length; i++) { + dancerSums[i] = input.get(i + 3); + } + + } + + public int getNumberOfSuprisingTriplets() { + return numberOfSuprisingTriplets; + } + + public int getBorder() { + return border; + } + + public int[] getDancerSums() { + return dancerSums; + } +} +" +A20177,"package codejam; + +import java.util.ArrayList; + +import codejam.fileHandler; + +public class SpeakingInTongues { + + /** + * @param args + */ + public static void main(String[] args) { + fileHandler file = new fileHandler(""input.in"", ""output.in""); + int noOfCase = file.readCase(); + char abcd[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', + 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z' }; + char replacement[] = { 'y', 'n', 'f', 'i', 'c', 'w', 'l', 'b', 'k', + 'u', 'o', 'm', 'x', 's', 'e', 'v', 'z', 'p', 'd', 'r', 'j', + 'g', 't', 'h', 'a', 'q' }; + ArrayList arrayList = new ArrayList(); + for(int i=0;i=0 && !find; a--) { + if(3*a-4>score) + continue; + for(b = a; b>=0 && b >=a-2 && !find; b--) { + for(c = b; c>=0 && c >=b-2 && c >=a-2 && !find; c--) { +// System.out.println(a+"",""+b+"",""+c); + if(a+b+c==score) { + if(a >= threshold) { + if(a-c <= 1){ + count++; + find = true; +// System.out.println(""find!""); + } + else if(a-c == 2){ + sfind = true; +// System.out.println(""suprise!""); + } + } + } + + } + } + } + if(!find && sfind && suprise > 0) + { + count++; + suprise --; + } + } + int maxCount = count; + out.write(maxCount+""\n""); + } + out.flush(); + out.close(); + in.close(); + } +} +" +A22301,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author mohamedmohideenebrahim + */ +public class Codejam { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + try { + Scanner scanner = new Scanner(new File(args[0])); + int testCaseNum = scanner.nextInt(); + scanner.nextLine(); + for (int i = 0; i < testCaseNum; i++) { + System.out.println(""Case #"" + (i + 1) + "": "" + getString(scanner.nextLine())); + } + } catch (FileNotFoundException ex) { + Logger.getLogger(Codejam.class.getName()).log(Level.SEVERE, null, ex); + } + + + + } + + public static int getString(String input) { + String[] inputArray = input.split("" ""); + //System.out.println(input); + int noOfSurprise = Integer.parseInt(inputArray[1]); + int minMark = Integer.parseInt(inputArray[2]); + + int countedSurprise = 0; + int countedMinMark = 0; + + for (int i = 3; i < inputArray.length; i++) { + int mark = Integer.parseInt(inputArray[i]); + int remainder = mark % 3; + int quotient = mark / 3; + + if(remainder == 0) + { + //System.out.println(quotient+"",""+quotient+"",""+quotient); + //System.out.println((quotient-1)+"",""+quotient+"",""+(quotient+1)); + if(quotient >= minMark) + { + countedMinMark++; + //System.out.println(""Matched ""+quotient+"",""+quotient+"",""+quotient); + } + else if(mark > 2 && countedSurprise != noOfSurprise && (quotient+1) >= minMark) + { + //System.out.println(""Matched ""+(quotient-1)+"",""+quotient+"",""+(quotient+1)); + countedMinMark++; + countedSurprise++; + } + //System.out.println(); + } + else if(remainder == 1) + { + //System.out.println(quotient+"",""+quotient+"",""+(quotient+1)); + if(quotient+1 >= minMark) + { + //System.out.println(""Matched ""+quotient+"",""+quotient+"",""+(quotient+1)); + countedMinMark++; + } + //System.out.println(); + } + else if(remainder == 2) + { + //System.out.println((quotient+1)+"",""+quotient+"",""+(quotient+1)); + //System.out.println(quotient+"",""+quotient+"",""+(quotient+2)); + if(quotient+1 >= minMark) + { + //System.out.println(""Matched ""+(quotient+1)+"",""+quotient+"",""+(quotient+1)); + countedMinMark++; + } + else if(mark > 2 && countedSurprise != noOfSurprise && (quotient+2) >= minMark) + { + countedMinMark++; + countedSurprise++; + //System.out.println(""Matched ""+quotient+"",""+quotient+"",""+(quotient+2)); + } + //System.out.println(); + + } + //System.out.println(""Mark "" + mark + "" Quotient "" + quotient + // + "" Counted MinMark "" + countedMinMark + "" counted surprise "" + countedSurprise); + //System.out.println(); + } + return countedMinMark; + + } +} +" +A23087,"package com.codejam2012; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Scanner; + +public class Problem2 { + + public static void main(String[] args) throws Exception{ + Scanner sc = new Scanner(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""output1.txt"")); + + int T = Integer.parseInt(sc.nextLine()); + for (int i=0; i= p || (quo == p-1 && rem !=0)){ + y++; + System.out.println(t[j]+""Default True""); + } + else if (quo < p-2 || (quo == p-2 && rem !=2)){ + System.out.println(t[j]+""Default False""); + } + else if((quo == p-2 && rem == 2&& quo!=0)||(quo == p-1 && rem == 0&& quo!=0)){ + if(S>0){ + y++; + S--; + System.out.println(t[j]+""True""); + } + else{ + System.out.println(t[j]+""False""); + } + } + else if((quo == p-2 && rem == 2&& quo==0 && p==0)||(quo == p-1 && rem == 0&& quo==0 && p==0)){ + y++; + } + } + System.out.println(""Case #""+(i+1)+"": ""+y); + pw.write(""Case #""+(i+1)+"": ""+y+""\n""); + } + pw.flush(); + pw.close(); + sc.close(); + } + + static boolean checkP(){ + + + return true; + } + +} + + +" +A22838,"package com.unitedcoders.examples.codejam; + +import java.io.File; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class DancingWithGooglers { + + public static void main(String[] args) throws Exception { + + Scanner scanner = new Scanner(new File(""/Users/nh/b.in"")); + PrintStream out = new PrintStream(new File(""/Users/nh/b.out"")); + + int testcases = scanner.nextInt(); + scanner.nextLine(); + for (int casenr = 1; casenr <= testcases; casenr++) { + + int googlers = scanner.nextInt(); + int surprises = scanner.nextInt(); + int minScore = scanner.nextInt(); + + ArrayList scores = new ArrayList(); + for(int i=0; i scores){ + + + Collections.sort(scores); + Collections.reverse(scores); + + int save = minScore + 2*(minScore-1); + int min = minScore +2*(minScore-2); + int p = 0; + + + for(int i : scores){ + + if(i>=save){ + p++; + continue; + }else{ + if((i>=min && surprises >0) && (i>0)){ + p++; + surprises--; + } + } + + } + + return p; + + + + } +} +" +A21415,"package Qualification.A.jam2011; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +/* + + 4 + 3 1 5 15 13 11 + 3 0 8 23 22 21 + 2 1 1 8 0 + 6 2 8 29 20 8 18 18 21 + + + */ +public class C { + static int S; + static int p; + static int min; + + public static void main(String[] args) throws IOException { + + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + File f = new File(""output.txt""); + FileWriter fw = new FileWriter(f); + in.nextLine(); + + for (int j = 0; j < T; j++) { + + S = in.nextInt(); + p = in.nextInt(); + min = in.nextInt(); + + String s = in.nextLine(); + // System.out.println(S+""\n""+p+""\n""+min); + s = s.substring(1); + // System.out.println(s); + + fw.write(""Case #"" + (j + 1) + "": "" + passed(s) + ""\n""); + // System.out.println(""Case #"" + (j + 1) + "": "" + passed(s) + ""\n""); + } + + fw.flush(); + fw.close(); + + } + + private static int passed(String s) { + String[] v = s.split("" ""); + // int[] intv=new int[v.length]; + int total = 0; + for (int i = 0; i < v.length; i++) { + // intv[i]=Integer.parseInt(v[i]); + total += calc(Integer.parseInt(v[i])); + } + + return total; + } + + private static int calc(int parseInt) { + int base = parseInt / 3; + switch (parseInt % 3) { + case 0: { + if (base >= min) { + return 1; + } else { + if (p > 0 && base > 0 && base + 1 >= min) { + p--; + return 1; + } + } + + break; + } + case 1: { + if (base >= min || base + 1 >= min) { + return 1; + } else { + if (p > 0 && base > 0 && base + 1 >= min) { + p--; + return 1; + } + } + + break; + } + case 2: { + if (base + 1 >= min || base >= min) { + return 1; + } else { + if (p > 0 && base > 0 && base + 2 >= min) { + p--; + return 1; + } + } + + break; + } + } + + /* + * if(parseInt= min) { return 1; } if (base == min - 1) { if (parseInt % 3 != 0) { + * return 1; } } if (p > 0) { if (base >= min - 2) { if (parseInt % 3 >= + * 0) { p = p - 1; return 1; } + * + * } if (base == min - 1) { if (parseInt % 3 == 0) { p = p - 1; return + * 1; } + * + * } + * + * } + */ + return 0; + } +}" +A20659,"import java.io.*; +import java.util.*; + +public class Main{ + + String inputFile = ""B-large.in""; + PrintStream output; + Scanner fileScanner; + int outputLine = 0; + double start = System.currentTimeMillis(); + + public Main(){ + newCodeJam(); + + fileScanner.nextLine(); + while (fileScanner.hasNextLine()){ + String line = fileScanner.nextLine(); + Scanner scanner = new Scanner(line); + ArrayList scores = new ArrayList(); + + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + while (scanner.hasNext()){ + scores.add(scanner.nextInt()); + } + + println(solve(N, S, p, scores) +""""); + } + + output.close(); + System.out.println(""Finished.""); + System.out.println(""Time Taken: "" + ((System.currentTimeMillis()-start)/1000) + "" seconds.""); + } + + + + + private int solve(int N, int S, int p, ArrayList list){ + + int ans = 0; + Collections.sort(list); + + for (int x=list.size()-1; x>=0; x--){ + int num = list.get(x); + int normalBestResult = normalBestResult(num); + + if (normalBestResult >= p){ + ans++; + }else{ + if (surpriseWillAddOne(num) && S > 0){ + if ((normalBestResult + 1) >= p){ + ans++; + S = S - 1; + } + } + } + } + + return ans; + } + + + private int normalBestResult(int num){ + if (num % 3 == 0){ + return (num / 3); + }else { + return (num / 3) + 1; + } + } + + + private boolean surpriseWillAddOne(int num){ + + if (num < 2 || num > 28){ + return false; + } + + if (num % 3 == 1){ + return false; + }else { + return true; + } + } + + + // CodeJam Utility Methods: + + public void newCodeJam(){ + String outputFile = inputFile.substring(0, inputFile.length()-3) + ""-OUTPUT.out""; + System.out.print(""\f""); + // open input file + try { + fileScanner = new Scanner(new File(inputFile)); + }catch(IOException e) {} + // open output file + try { + output = new PrintStream(new File(outputFile)); + }catch(IOException ex) {} + } + + public void println(String s){ + outputLine++; + output.println(""Case #"" + outputLine + "": "" + s); + } + + public static void main(String[] args){ + new Main(); + } + +}" +A20423,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.math.BigInteger; +import java.util.*; + +public class ProblemBB { + + static class State { + boolean surprising, not; + int max; + + State(boolean S, boolean n, int mx) { + surprising = S; + not = n; + max = mx; + } + } + + private void solve() throws IOException { + int T = nextInt(); + while (T-- > 0) { + int N = nextInt(); + int S = nextInt(); + int P = nextInt(); + int[] a = new int[N]; + State[] St = new State[N]; + for (int i = 0; i < N; i++) + a[i] = nextInt(); + int res = 0; + for (int i = 0; i < a.length; i++) { + St[i] = new State(false, false, -1); + for (int k1 = 0; k1 <= 10; k1++) { + for (int k2 = 0; k2 <= 10; k2++) { + for (int k3 = 0; k3 <= 10; k3++) { + if (k1 + k2 + k3 == a[i]) { + if (notValid(k1, k2, k3)) + continue; + if (surprise(k1, k2, k3)) { + if (k1 >= P || k2 >= P || k3 >= P) { + St[i].surprising = true; + St[i].max = Math.max(St[i].max, + Math.max(k1, Math.max(k2, k3))); + } + } else { + if (k1 >= P || k2 >= P || k3 >= P) { + St[i].not = true; + St[i].max = Math.max(St[i].max, + Math.max(k1, Math.max(k2, k3))); + } + } + } + } + + } + + } + } + + boolean[] V = new boolean[N]; + for (int i = 0; i < St.length && S > 0; i++) { + if (St[i].surprising && !St[i].not) { + res++; + V[i] = true; + S--; + } + } + for (int i = 0; i < St.length && S > 0; i++) { + if (!V[i] && St[i].surprising && St[i].not) { + res++; + V[i] = true; + S--; + } + } + for (int i = 0; i < St.length; i++) { + if (!V[i] && St[i].not) { + res++; + } + } + pf(); + pl(res); + } + } + + private boolean notValid(int k1, int k2, int k3) { + if (Math.abs(k1 - k2) > 2 || Math.abs(k1 - k3) > 2 + || Math.abs(k2 - k3) > 2) + return true; + return false; + } + + private boolean surprise(int k1, int k2, int k3) { + if (Math.abs(k1 - k2) == 2 || Math.abs(k1 - k3) == 2 + || Math.abs(k2 - k3) == 2) + return true; + return false; + } + + public static void main(String[] args) { + new ProblemBB().run(); + } + + BufferedReader reader; + StringTokenizer tokenizer; + PrintWriter writer; + + public void run() { + try { + reader = new BufferedReader(new FileReader(""B.in"")); + // reader = new BufferedReader(new InputStreamReader(System.in)); + tokenizer = null; + // writer = new PrintWriter(System.out); + writer = new PrintWriter(""B.out""); + solve(); + reader.close(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + BigInteger nextBigInteger() throws IOException { + return new BigInteger(nextToken()); + } + + String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + return tokenizer.nextToken(); + } + + void p(Object... objects) { + for (int i = 0; i < objects.length; i++) { + if (i != 0) + writer.print(' '); + writer.flush(); + writer.print(objects[i]); + writer.flush(); + } + } + + void pl(Object... objects) { + p(objects); + writer.flush(); + writer.println(); + writer.flush(); + } + + int cc; + + void pf() { + writer.printf(""Case #%d: "", ++cc); + writer.flush(); + } + +}" +A21162,"import java.util.Scanner; + +public class Dancing { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int caseCount = sc.nextInt(); + for (int i = 1; i <= caseCount; i++) { + int N = sc.nextInt(); + int numSuprise = sc.nextInt(); + int p = sc.nextInt(); + int bestN = 0; + for (int j = 1; j <= N; j++) { + int result = getThree(sc.nextInt(), numSuprise, p); + if (result > 1) { + result = 1; + numSuprise--; + } + bestN += result; + } + + System.out.println(""Case #"" + i + "": "" + bestN); + } + } + + private static int getThree(int total, int numSuprise, int p) { + if (total == 0 && p > 0) { + return 0; + } else if ((total - p) < (p - 2) * 2) { + return 0; + } else if ((total - p) == (p - 2) * 2 || (total - p) == (p * 2 - 3)) { + if (numSuprise <= 0) { + return 0; + } else { + return 2; + } + } else { + int average = total * 10 / 3; + if (average % 10 == 0) { + if (average >= p * 10) { + return 1; + } else { + return 0; + } + } else if (average % 10 == 3) { + if ((average + 7) >= p * 10) { + return 1; + } else { + return 0; + } + } else { + if ((average + 4) >= p * 10) { + return 1; + } else { + return 0; + } + } + } + } +} +" +A20996,"package fixjava; + +import java.util.HashMap; + +public class MapDualKeyToValue extends HashMap, V> { + + private static final long serialVersionUID = 1L; + + public V put(K1 key1, K2 key2, V value) { + return put(Pair.make(key1, key2), value); + }; + + public MultiMapKeyToList getValuesGroupedByKey2() { + MultiMapKeyToList key2ToValues = new MultiMapKeyToList(); + for (java.util.Map.Entry, V> ent : entrySet()) + key2ToValues.put(ent.getKey().getRight(), ent.getValue()); + return key2ToValues; + } + + public MultiMapKeyToList getValuesGroupedByKey1() { + MultiMapKeyToList key1ToValues = new MultiMapKeyToList(); + for (java.util.Map.Entry, V> ent : entrySet()) + key1ToValues.put(ent.getKey().getLeft(), ent.getValue()); + return key1ToValues; + } +} +" +A21816," +package codejam2012.qualification; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +public class ProblemB { + public static void main(String[] args) throws Exception { + System.setIn(new FileInputStream(""B-large.in"")); + System.setOut(new PrintStream(new FileOutputStream(""B-large.out""))); + Scanner in = new Scanner(System.in); + int testCase = in.nextInt(); + + for(int i = 1; i <= testCase; i++) { + int count = 0, count2 = 0; + + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + for(int j = 0; j < n; j++) { + int t = in.nextInt(); + if(t >= 3*p-2) + count++; + else if(3*p-4 >= 0 && t >= 3*p-4) + count2++; + } + count += (count2>s? s: count2); + System.out.printf(""Case #%d: %d%n"", i, count); + } + } +} +" +A20061,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import static java.lang.Math.abs; +import static java.lang.Math.max; + +public class DancingWithGooglers { + + public static void main(String[] args) throws IOException { + new DancingWithGooglers().solveAll(); + } + + BufferedReader reader; + + int T; + + private void solveAll() throws IOException { + reader = new BufferedReader(new InputStreamReader(System.in)); + T = Integer.parseInt(reader.readLine()); + for (int i = 0; i < T; i++) { + solve(i + 1); + } + } + + private void solve(int caseNumber) throws IOException { + String line = reader.readLine(); + String[] strings = line.split("" ""); + int N = Integer.parseInt(strings[0]); + int S = Integer.parseInt(strings[1]); + int P = Integer.parseInt(strings[2]); + int[] scores = new int[N]; + for (int i = 0; i < N; i++) { + scores[i] = Integer.parseInt(strings[3 + i]); + } + + Triplet[] bestTriplets = new Triplet[N]; + Triplet[] bestSurprisingTriplets = new Triplet[N]; + + for (int i = 0; i < N; i++) { + //System.out.println(""Score: "" + scores[i]); + bestTriplets[i] = findBestTriplet(scores[i]); + bestSurprisingTriplets[i] = findBestSurprisingTriplet(scores[i]); + //System.out.println(bestTriplets[i] + "" - "" + ""*"" + bestSurprisingTriplets[i]); + } + + int result = 0; + for (int i = 0; i < N; i++) { + if (bestTriplets[i].scores[0] >= P) { + result++; + } + } + int usedSurprising = 0; + for (int i = 0; i < N; i++) { + if (bestSurprisingTriplets[i].scores[0] >= P + && bestTriplets[i].scores[0] < P + && usedSurprising < S) { + result++; + usedSurprising++; + } + } + + System.out.println(""Case #"" + caseNumber + "": "" + result); + } + + private Triplet findBestTriplet(int score) { + for (int i = 10; i >= 0; i--) { + for (int j = i; j >= max(i - 1, 0); j--) { + for (int k = j; k >= max(j - 1, 0); k--) { + if (i + j + k == score && i - k <= 1) { + return new Triplet(i, j, k); + } + } + } + } + return null; + } + + private Triplet findBestSurprisingTriplet(int score) { + for (int i = 10; i >= 0; i--) { + for (int j = i; j >= max(i - 2, 0); j--) { + for (int k = j; k >= max(j - 2, 0); k--) { + if (i + j + k == score && i - k <= 2) { + return new Triplet(i, j, k); + } + } + } + } + return null; + } + + class Triplet { + int[] scores; + + public Triplet(int s1, int s2, int s3) { + scores = new int[] {s1, s2, s3}; + } + + @Override + public String toString() { + return scores[0] + "" "" + scores[1] + "" "" + scores[2]; + } + } + +} +" +A21489,"package world2012.qualification; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + public static boolean canPass(int[] t, int p) { + if (t[0] < 0 || t[1] < 0 || t[2] < 0) + return false; + return t[0] >= p || t[1] >= p || t[2] >= p; + } + + public static int maxGooglers(int[] scores, int p, int s) { + B b = new B(); + Triple[] ts = new Triple[scores.length]; + for (int i = 0; i < scores.length; i++) { + ts[i] = b.new Triple(scores[i]); + } + + int count = 0; + int surpr = 0; + for (Triple t : ts) { + if (canPass(t.triple, p)) + count++; + else if (canPass(t.sTriple, p)) + surpr++; + } + + return count + Math.min(surpr, s); + } + + static PrintWriter out; + + public static void parseInput() throws Exception { +// String file = ""world2012/qualification/B-large-attempt0.in""; + String file = ""world2012/qualification/B-large.in""; +// String file = ""input.in""; + Scanner scanner = new Scanner(new File(file)); + out = new PrintWriter(new FileWriter((file.replaceAll("".in"", """")))); + + int T = Integer.parseInt(scanner.nextLine()); + + for (int i = 0; i < T; i++) { + String[] in = scanner.nextLine().split(""\\s""); + int N = Integer.parseInt(in[0]); + int S = Integer.parseInt(in[1]); + int P = Integer.parseInt(in[2]); + int[] scores = new int[N]; + for (int j = 0; j < N; j++) { + scores[j] = Integer.parseInt(in[j + 3]); + } + + int r = maxGooglers(scores, P, S); + out.println(""Case #""+(i+1)+"": ""+r+""""); + } + } + + public static void main(String[] args) throws Exception { + parseInput(); + out.close(); + System.out.println(""Done!""); + } + + class Triple { + + int[] triple; + int[] sTriple; + int score; + + public Triple(int score) { + this.score = score; + init(); + } + + private void init() { + if (score % 3 == 2) { + int l = score / 3; + int b = score / 3 + 1; + triple = new int[] {b, b, l}; + sTriple = new int[] {b + 1, b - 1, l}; + } else if (score % 3 == 1) { + int l = score / 3; + int b = score / 3 + 1; + triple = new int[] {b, l, l}; + sTriple = new int[] {b, b, l - 1}; + } else { + int l = score / 3; + triple = new int[] {l, l, l}; + sTriple = new int[] {l + 1, l, l - 1}; + } + } + } + +} +" +A22297,"package cg.y2012.QualQ2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Q2 { + + /** + * @param args + */ + public static void main(String[] args) { + + int[] s = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Map> G = new HashMap>(); + for(int i:s){ + for(int j:s){ + for(int k:s){ + if(Math.abs(i-j)< 2 && Math.abs(k-j)< 2 && Math.abs(i-k)< 2){ + int sum = i+j+k; + List trips = G.get(sum); + if(trips == null){ + trips = new ArrayList(); + } + trips.add(new int[]{i,j,k}); + G.put(sum, trips); + } + } + } + } + Map> ST = new HashMap>(); + for(int i:s){ + for(int j:s){ + for(int k:s){ + if((Math.abs(i-j)== 2 && Math.abs(k-j) < 2 && Math.abs(i-k) < 2) || + (Math.abs(i-j)< 2 && Math.abs(k-j)== 2 && Math.abs(i-k)<2) || + (Math.abs(i-j) < 2 && Math.abs(k-j) < 2 && Math.abs(i-k)== 2)){ + int sum = i+j+k; + List trips = ST.get(sum); + if(trips == null){ + trips = new ArrayList(); + } + trips.add(new int[]{i,j,k}); + ST.put(sum, trips); + } + if((Math.abs(i-j)== 2 && (Math.abs(k-j) == 0 || Math.abs(i-k) == 0)) || + (Math.abs(k-j)== 2 && (Math.abs(k-i) == 0 || Math.abs(i-j) == 0)) || + (Math.abs(k-i)== 2 && (Math.abs(k-j) == 0 || Math.abs(i-j) == 0))){ + int sum = i+j+k; + List trips = ST.get(sum); + if(trips == null){ + trips = new ArrayList(); + } + trips.add(new int[]{i,j,k}); + ST.put(sum, trips); + } + } + } + } + for(Map.Entry> k : G.entrySet()){ + System.out.print(k.getKey()+"" -- ""); + List l = k.getValue(); + for(int[] a : l){ + System.out.print(""{""); + for(int x : a){ + System.out.print("" ""+x+"", ""); + } + System.out.print(""}""); + } + System.out.println(""""); + } + + for(Map.Entry> k : ST.entrySet()){ + System.out.print(k.getKey()+"" -- ""); + List l = k.getValue(); + for(int[] a : l){ + System.out.print(""{""); + for(int x : a){ + System.out.print("" ""+x+"", ""); + } + System.out.print(""}""); + } + System.out.println(""""); + } + BufferedWriter out = null; + try { + String newLine = System.getProperty(""line.separator""); + out = new BufferedWriter(new FileWriter(args[0]+"".output"")); + BufferedReader b = new BufferedReader(new FileReader(args[0])); + int number_of_test_cases = Integer.parseInt(b.readLine().split("" "")[0]); + for( int tc = 0; tc < number_of_test_cases; tc++) { + int[] data = convertToInt(b.readLine()); + int N = data[0]; + int S = data[1]; + int p = data[2]; + + int rScores[] = new int[N]; + int j=0; + for(int i=0;i < rScores.length;i++){ + rScores[i] = -1; + } + + int count = 0; + for(int i=0;i scores = G.get(data[3+i]); + boolean found = false; + if(scores != null){ + for(int[] score : scores){ + if(score[0] >=p ||score[1] >=p || score[2] >=p ){ + count ++; + found = true; + break; + } + } + if(!found){ + rScores[j] =data[3+i]; + j++; + } + } + } + for(int i=0;i < rScores.length && S > 0;i++){ + if(rScores[i] == -1) + break; + List scores = ST.get(rScores[i]); + if(scores != null){ + for(int[] score : scores){ + if(score[0] >=p ||score[1] >=p || score[2] >=p ){ + count ++; + S--; + break; + } + } + } + } + out.write(""Case #""+(tc+1)+"": ""+count+newLine); + + } + } catch (IOException e) { + System.out.println(""Exception : ""+e); + } + finally { + if(out != null){ + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + private static int[] convertToInt(String line){ + String data[] = line.split("" ""); + int[] rtn = new int[data.length]; + for(int i=0;i< data.length ;i++){ + rtn[i]=Integer.parseInt(data[i].trim()); + } + return rtn; + } + +} +" +A21295,"//package com.GoogleCodeJam.y2012.Qualification.DancingWithTheGooglers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class DancingWithTheGooglers { + public static void main(String[] args) { + try { + BufferedReader in = new BufferedReader(new FileReader(new File(""B-large.in""))); + int numCases = Integer.parseInt(in.readLine()); + for (int caseNum = 1; caseNum <= numCases; caseNum++) { + String[] caseInput = in.readLine().split("" ""); + int numFound = getNumOverBar(caseInput); + System.out.println(""Case #""+ caseNum + "": "" + numFound); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public static int getNumOverBar(String[] caseInput) { + int numGooglers = Integer.parseInt(caseInput[0]); + int surprisingRemaining = Integer.parseInt(caseInput[1]); + int minThreshhold = Integer.parseInt(caseInput[2]); + int numFound = 0; + for (int scoreId = 3; scoreId < (numGooglers + 3); scoreId ++) { + int givenScore = Integer.parseInt(caseInput[scoreId]); + int checkedScore = givenScore %3 == 0 ? givenScore : (givenScore + 3 - givenScore %3); + if (checkedScore/3 >= minThreshhold) { + numFound ++; + } else if (givenScore == 0) { + if (minThreshhold == 0) { + numFound++; + } + } else if (surprisingRemaining > 0) { + if (givenScore % 3 == 2) { + if ((givenScore + 4)/3 >= minThreshhold) { + numFound ++; + surprisingRemaining --; + } + } else if (givenScore % 3 == 0) { + if ((givenScore+3) / 3 >= minThreshhold) { + numFound ++; + surprisingRemaining --; + } + } + } + } + return numFound; + + } +} +" +A21035," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.StringTokenizer; + +public class Dance { + private String strLine; + private BufferedReader f; + private PrintWriter out; + private ArrayList hasil; + + public Dance() { + strLine = new String(); + try { + f = new BufferedReader(new FileReader(""b0.in"")); + out = new PrintWriter(new BufferedWriter(new FileWriter(""dance.out""))); + } catch(IOException i) { + } + hasil = new ArrayList(); + } + + public void find(int N, int S, int p, ArrayList save) { + int temp; + int count = 0; + int sTemp = S; + System.out.println(""ha = "" + N + ""|"" + S + ""|"" + p); + for (int i = 0; i < N; i++) { + temp = save.get(i); + if ((temp % 3) == 1) { + if (temp / 3 + 1 >= p) { + System.out.println(""a"" + i); + count++; + } + } else if ((temp % 3) == 2) { + if (sTemp == 0) { + if (temp / 3 + 1 >= p) { + System.out.println(""b"" + i); + count++; + } + } else { + if (temp / 3 + 1 < p) { + sTemp--; + if (temp /3 + 2 >= p && temp /3 + 2 <= 10) { + System.out.println(""c"" + i); + count++; + } else { + sTemp++; + } + } else { + if (temp / 3 - 1 >= 0) { + System.out.println(""d"" + i); + count++; + } + } + } + } else { + if (sTemp > 0) { + if (temp / 3 >= p) { + System.out.println(""f"" + i); + count++; + } else if (temp / 3 + 1 >= p) { + if (temp / 3 - 1 <= 0) { + + } else if (temp / 3 + 1 >= 10) { + + } else { + System.out.println(""e"" + i); + count++; + sTemp--; + } + } + } else { + if (temp / 3 >= p) { + System.out.println(""g"" + i); + count++; + } + } + } + } + hasil.add(count); + } + + public static void main(String[] args) throws IOException { + Dance dance = new Dance(); + int N; + int S; + int T; + int p; + StringTokenizer st; + ArrayList save; + + T = Integer.parseInt(dance.f.readLine()); + System.out.println(""T = "" + T); + if (T > 100 || T < 1) { + System.out.println(""Error""); + } else { + for (int i = 0; i < T; i++) { + if ((dance.strLine = dance.f.readLine()) != null) { + System.out.println(""dance = "" + dance.strLine); + st = new StringTokenizer(dance.strLine); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + save = new ArrayList(); + for (int j = 0; j < N; j++) { + save.add(Integer.parseInt(st.nextToken())); + } + dance.find(N,S,p,save); + } + } +// while ((dance.giver = dance.f.readLine()) != null) { +// if (dance.giver.length() > 100) { +// System.out.println(""Error""); +// isError = true; +// break; +// } else { +// for (int l = 0; l < dance.giver.length(); l++) { +// if (dance.giver.charAt(l) != ' ') +// s = s + dance.member.get(dance.giver.charAt(l)); +// else +// s = s + dance.giver.charAt(l); +// } +// dance.hasil.add(s); +// s = """"; +// } +// } + for (int x = 0; x < dance.hasil.size(); x++) { + dance.out.println(""Case #"" + (x + 1)+ "": "" +dance.hasil.get(x)); + } + dance.out.close(); // close the output file + System.exit(0); + } + } +} +" +A22445,"import java.util.*; + +public class B { + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int cases = s.nextInt(); + for (int i=1; i<=cases; i++) { + int n = s.nextInt(); + int surprising = s.nextInt(); + int p = s.nextInt(); + int number = 0; + for (int j=0; j=p) number++; + else + if ((m+1) >= p) { + surprising--; + if (surprising >=0) number++; + } + } + + if (t==0) + if (t >= p) number++; + + if (remind == 1) { + if ((m+1) >= p) number++; + } + + if (remind == 2) { + if ((m+1) >= p) number++; + else + if ((m+2) >= p) { + surprising--; + if (surprising >=0) number++; + } + } + + } + System.out.println(""Case #"" + i + "": "" + number); + } + } +}" +A22619,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class B { + + public void func(){ + + Scanner in=null; + try { + in = new Scanner(new File(""input.txt"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + int no = in.nextInt(); + for(int i=0;i= min) && flag == 0){ + res++; + intArr[j][3] = 1; + ++flag; + } + --k; + ++v; + } + if(Math.abs((intArr[j][0]-intArr[j][1])) == 2 || Math.abs((intArr[j][1]-intArr[j][2])) == 2 || Math.abs((intArr[j][2]-intArr[j][0])) == 2 ){ + ++ss; + } + } + if((res < ng) && (ss < sp)){ + for(int j=0;j= min || intArr[j][1]>= min) ++res; + ++ss; + }else{ + if(intArr[j][0]-1 >= min || intArr[j][1]+1 >= min){ + intArr[j][0]--; + intArr[j][1]++; + ++res; + ++ss; + } + } + ///continue; + }else if(Math.abs(intArr[j][1]-intArr[j][2]) < 1){ + if(j==ng-1){ + intArr[j][1]--; + intArr[j][2]++; + if(intArr[j][1] >= min || intArr[j][2]>= min) ++res; + ++ss; + }else{ + if(intArr[j][1]-1 >= min || intArr[j][2]+1 >= min){ + intArr[j][1]--; + intArr[j][2]++; + ++res; + ++ss; + } + } + }else if(Math.abs(intArr[j][2]-intArr[j][0]) < 1){ + if(j==ng-1){ + intArr[j][2]--; + intArr[j][0]++; + if(intArr[j][0] >= min || intArr[j][2]>=min) ++res; + ++ss; + }else{ + if(intArr[j][2]-1 >= min || intArr[j][0]+1 >= min){ + intArr[j][2]--; + intArr[j][0]++; + ++res; + ++ss; + } + } + } + if(ss>=sp){ + break; + } + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+res); + } + } + + + public static void main(String[] args) { + B b = new B(); + b.func(); + } + +} +" +A20733," + +public interface TestCaseFactory { + + TestCase getInstance(int number); + +}" +A22684,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.Reader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + + +public class Main +{ + + public static HashMap mapp = new HashMap(); + + public static void main(String[] args) throws Exception + { + PrintWriter writer = new PrintWriter(new FileWriter(""output.txt"")); + BufferedReader input = new BufferedReader(new FileReader(""B-large.in"")); + int size=Integer.parseInt(input.readLine()); + for(int i=0; i google = new ArrayList(); + for(int j=3; j= 2*(p-1) && (testNum-p)>=0) + { + count++; + } + else if((testNum - p) < 2*(p-1) && (testNum-p)>=0) + { + if(S!=0 && (testNum - p) >= 2*(p-2) ) + { + count++; + S--; + } + } + } + writer.println(""Case #""+(i+1)+"": ""+count); + + } + writer.close(); + input.close(); + } + +} +" +A21956,"import java.io.*; +import java.math.*; + +public class Dance { + public void cal(String filename) throws NumberFormatException, IOException + { + BufferedReader in = new BufferedReader(new FileReader(filename)); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""bar.txt""))); + int count = 1; + String s = in.readLine(); + int all = Integer.parseInt(s); + while((s = in.readLine()) != null) + { + int result = 0; + if(count > all) + break; + String[] elements = s.split("" ""); + int dancer_num = Integer.parseInt(elements[0]); + int surprise_num = Integer.parseInt(elements[1]); + int least = Integer.parseInt(elements[2]); + for(int i = 0; i < dancer_num; i++) + { + if( 3 + i >= elements.length) + break; + int data = Integer.parseInt(elements[3 + i]); + if(data <= 30 && data>=0) + { + if(data / 3 >= least) + result = result + 1; + else + { + int second = (data - least) / 2; + int third = data - second - least; + if(Math.abs(least - second) <= 1 &&Math.abs(least - third) <= 1) + { + if(second >= 0 && third >= 0) + result = result + 1; + } + else if(Math.abs(least - second) <= 2 &&Math.abs(least - third) <= 2) + { + if(surprise_num > 0 && second >= 0 && third >= 0) + { + result = result + 1; + surprise_num = surprise_num - 1; + } + } + else + {} + } + } + } + out.println(""Case #"" + count +"": "" + result); + count = count + 1; + } + out.close(); + } + + public static void main(String[] args) throws NumberFormatException, IOException + { + Dance d = new Dance(); + d.cal(""foo2.txt""); + } + +} +" +A23088,"package jam; + +import java.util.Scanner; + +public class Main_B { + static int[] results; + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int tests = Integer.valueOf(scan.nextLine()); + results = new int[tests]; + int c = 0; + while(c < tests) + { + solve(scan.nextLine(), c); + c++; + } + //print results + System.out.println(""Output""); + for (int i = 0; i < results.length; i++) { + System.out.println(""Case #"" + (i+1) + "": "" + results[i]); + } + + } + //N S P {numbers separated by spaces} + public static void solve(String s, int on) + { + String[] parts = s.split("" ""); + //int num = Integer.valueOf(parts[0]); + int surp = Integer.valueOf(parts[1]); + int max = Integer.valueOf(parts[2]); + int high = 3*max - 2; + int high_w_surp = 3*max - 4; + int[] vals = gather(parts); + int num_pep = 0; + + for (int i = 0; i < vals.length; i++) { + if(vals[i] >= Math.max(high, max)) + { + num_pep++; + } + else if(vals[i] >= Math.max(high_w_surp, max) && surp > 0) + { + surp--; + num_pep++; + } + } + results[on] = num_pep; + + } + + public static int[] gather(String[] vals) + { + int[] nums = new int[vals.length-3]; + for (int i = 0; i < nums.length; i++) { + nums[i] = Integer.valueOf(vals[i+3]); + } + return nums; + } +} +" +A20793,"import java.io.BufferedReader; +import java.io.InputStreamReader; + + +public class R0_2_2012 { + + public static void main(String[] args) { + + try { + + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(bf.readLine()); + + for (int i=0; i1 && t<29) surprising = (t-t%3) / 3 + 2; + } else { + regular = (t-t%3)/3 + t%3; + if (t>1 && t<29) surprising = (t-t%3)/3 + 1; + } + + if (regular >= p) + count++; + else if (surprising >= p && S>0) { + count ++; + S--; + } + + } + + System.out.println(""Case #"" + (i+1) + "": "" + count); + + } + + + } catch (Exception e) { + e.printStackTrace(); + } + + + } + +} +" +A21097,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + + +public class DancingWithTheGooglers { + + public static void readInput(String pFileName, List pInputCases) { + File tFile = new File(pFileName); + try { + BufferedReader tBufferedReader = new BufferedReader( + new InputStreamReader(new FileInputStream(tFile)), 4096); + String tLineRead = tBufferedReader.readLine().trim(); + int tCaseSize = Integer.valueOf(tLineRead); + int tLineIndex = 0; + while(tLineIndex < tCaseSize) { + tLineRead = tBufferedReader.readLine().trim(); + pInputCases.add(tLineRead); + tLineIndex++; + } + } catch(FileNotFoundException pException) { + pException.printStackTrace(); + } catch(IOException pException) { + pException.printStackTrace(); + } + } + + public static void main(String[] pArgs) throws Exception { + if(pArgs.length == 0) { + throw new Exception(""no input""); + } + List tInputCases = new ArrayList(); + + readInput(pArgs[0], tInputCases); + for(int tCaseIndex = 0; tCaseIndex < tInputCases.size(); tCaseIndex++) { + String[] tInputs = tInputCases.get(tCaseIndex).split(""[ ]+""); + int tNumberOfGooglers = Integer.valueOf(tInputs[0]); + int tSurprise = Integer.valueOf(tInputs[1]); + int tPoint = Integer.valueOf(tInputs[2]); + //System.out.print(tNumberOfGooglers); + //System.out.print("" ""); + //System.out.print(tSurprise); + //System.out.print("" ""); + //System.out.print(tPoint); + //System.out.println(); + int tNumber = 0; + for(int i = 3; i < tNumberOfGooglers + 3; ++i) { + int tTotal = Integer.valueOf(tInputs[i]); + //System.out.print(tInputs[i]); + //System.out.print("" ""); + int tDifference = tTotal % 3; + int tScore = tTotal / 3; + //System.out.print(tDifference); + //System.out.print("",""); + //System.out.print(tScore); + //System.out.print("" ""); + switch(tDifference) { + case 0: + if(tScore >= tPoint) { + ++tNumber; + } else if((tScore + 1 >= tPoint) && (tScore > 0)) { + if(tSurprise > 0) { + ++tNumber; + --tSurprise; + } + } + break; + case 1: + if(tScore + 1 >= tPoint) { + ++tNumber; + } + break; + case 2: + if(tScore + 1 >= tPoint) { + ++tNumber; + } else if(tScore + 2 >= tPoint) { + if(tSurprise > 0) { + ++tNumber; + --tSurprise; + } + } + break; + } + //System.out.println(""Case #"" + tCaseIndex + "": "" + tNumber); + } + System.out.println(""Case #"" + (tCaseIndex + 1) + "": "" + tNumber); + } + } +} +" +A22401,"import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +public class ClientB { + + public static void main(String args[]) throws Exception { + ClientB client = new ClientB(); + String[] inputLines = client.getInputLines(args[0]); + + int lineCount = Integer.valueOf(inputLines[0]); + + for(int i = 1; i <= lineCount; i++) { + String currentLine = inputLines[i]; + String[] currentCase = currentLine.split("" ""); + + int numOfGooglers = Integer.valueOf(currentCase[0]); + int numOfSuprisingScoreTriplets = Integer.valueOf(currentCase[1]); + int numOfBestResultGtEq = Integer.valueOf(currentCase[2]); + + System.out.println(""Min or better: "" + numOfBestResultGtEq); + System.out.println(""sup: "" + numOfSuprisingScoreTriplets); + + List baseScores = new ArrayList(); + for(int j = 0; j < numOfGooglers; j++) { + baseScores.add(client.fillScores(Integer.valueOf(currentCase[3+j]))); + } + + int[] processedScores = client.categorizeScores(baseScores, numOfBestResultGtEq); + + int sol = processedScores[0] + Math.min(numOfSuprisingScoreTriplets, processedScores[1]); + + System.out.println(""Case #"" + i + "": "" + sol); + System.out.println(); + } + } + + private int[] categorizeScores(List scores, int bar) { + int[] cat = {0, 0, 0}; //Good, bad, no potential (of being counted) + + for(int[] eachScoreSet : scores) { + int maxScore = eachScoreSet[1]; //by def of fillScores alg + + if(maxScore >= bar) { + cat[0]++; + } else if(maxScore+1 == bar) { + int oth = Math.max(eachScoreSet[0], eachScoreSet[2]); + if(oth-1 >= 0 && (maxScore+1) - (oth-1) <= 2) { + cat[1]++; + } else { + cat[2]++; + } + } else { //no hope + cat[2]++; + } + } + + return cat; + } + + private int[] fillScores(int maxValue) { + int[] scores = {0, 0, 0}; + int totScore = 0; + while(++totScore <= maxValue) { + scores[totScore % 3]++; + } + System.out.println(""maxVal:"" + maxValue +"" {""+scores[0]+"",""+scores[1]+"",""+scores[2]+""}""); + return scores; + + } + + private String[] getInputLines(String fileName) throws Exception { + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + List lines = new ArrayList(); + String nextLine; + while((nextLine = reader.readLine()) != null) { + lines.add(nextLine); + } + return lines.toArray(new String[lines.size()]); + } + +} +" +A20092,"package com.codejam2012; + +public class CodeJam2 { + + public static String fileDir = ""P:\\CodeJam2012\\""; + public static String baseFileName = ""B-large""; + public static String inputFileName = fileDir + baseFileName + "".in""; + public static String outputFileName = fileDir + baseFileName + "".out""; + + public static int Tcase; + public static int Ccase = 0; + public static String[] cases; + public static Case singleCase; + + public static void main(String[] args) { + + FileUtils.deleteFile(outputFileName); + String inputString = FileUtils.readFile(inputFileName); + parseInputString(inputString); + for (; Ccase < Tcase;) { + parse(); + } + } + + public static void parseInputString(String inputString) { + + cases = inputString.split(""\n""); + Tcase = Integer.parseInt(cases[0]); + Ccase = 0; + } + + private static void parse() { + + Ccase++; + FileUtils.appendToFile(outputFileName, ""Case #"" + Ccase + "": ""); + singleCase = new Case(cases[Ccase]); + singleCase.execute(); + FileUtils.appendToFile(outputFileName, singleCase.getDataToPrint() + + ""\n""); + + } + + public static class Case { + StringBuilder outputStatement; + private int N, S, P; + private int[] G; + private boolean[][] B; // greater than p , surprising , both + + public Case(String caseString) { + outputStatement = new StringBuilder(); + String[] arr = caseString.split("" ""); + N = Integer.parseInt(arr[0]); + S = Integer.parseInt(arr[1]); + P = Integer.parseInt(arr[2]); + G = new int[N]; + B = new boolean[N][3]; + + for (int i = 0; i < G.length; i++) { + G[i] = Integer.parseInt(arr[i + 3]); + } + java.util.Arrays.sort(G); + } + + public void execute() { + + for (int loop = 0; loop < G.length; loop++) { + checkANumberForSurprisingAndDeleteSurprising(G[loop], loop); + + } + + int finalYeild = 0; + for (int loop = 0; loop < N; loop++) { + // if(S >= 1){ + // if(B[loop][2] == true){ + // S--; + // finalYeild++; + // }else if(B[loop][1] == true){ + // S--; + // }else if(B[loop][0] == true){ + // finalYeild++; + // } + // }else{ + // if(B[loop][0] == true){ + // finalYeild++; + // } + // } + + if (S >= 1) { + if (B[loop][2] == true) { + S--; + finalYeild++; + B[loop][0] = false; + B[loop][1] = false; + B[loop][2] = false; + } + } + + } + + for (int loop =0; loop < G.length; loop++) { + if (S >= 1) { + if (B[loop][1] == true) { + S--; + } else if (B[loop][0] == true) { + finalYeild++; + } + } else { + if (B[loop][0] == true) { + finalYeild++; + } + } + + } + + outputStatement.append(finalYeild); + + } + + private void checkANumberForSurprisingAndDeleteSurprising( + int underprocess, int index) { + + int s[] = { underprocess / 3, underprocess / 3, underprocess / 3 }; + + int seed = -2; + int endseed = 2; + for (int i = seed; i <= endseed; i++) { + s[0] = underprocess / 3 + i; + if (s[0] != Math.abs(s[0])) { + continue; + } + for (int t = seed; t <= endseed; t++) { + s[1] = underprocess / 3 + t; + if (s[1] != Math.abs(s[1])) { + continue; + } + for (int u = seed; u <= endseed; u++) { + s[2] = underprocess / 3 + u; + if (s[2] != Math.abs(s[2])) { + continue; + } + if ((s[0] + s[1] + s[2]) == underprocess) { + if (Math.abs(s[0] - s[1]) > 2 + || Math.abs(s[0] - s[2]) > 2 + || Math.abs(s[2] - s[1]) > 2) { + + } else if (Math.abs(s[0] - s[1]) == 2 + || Math.abs(s[0] - s[2]) == 2 + || Math.abs(s[2] - s[1]) == 2) { + if (s[0] >= P || s[1] >= P || s[2] >= P) { + B[index][2] = true; + } else { + B[index][1] = true; + } + } else if (Math.abs(s[0] - s[1]) < 2 + || Math.abs(s[0] - s[2]) < 2 + || Math.abs(s[2] - s[1]) < 2) { + + if (s[0] >= P || s[1] >= P || s[2] >= P) { + B[index][0] = true; + } + } + } + + } + } + + } + + } + + public String getDataToPrint() { + return outputStatement.toString(); + + } + + } +} +" +A22843,"import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DanclingGooglers { + + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(new File(""input2.in"")); + int numCases = scanner.nextInt(); + + PrintWriter pw = new PrintWriter(new File(""output2.txt"")); + + for (int i = 1; i <= numCases; i++) { + int num = scanner.nextInt(); + int surprisingTriplets = scanner.nextInt(); + int bestScore = scanner.nextInt(); + + int result = 0; + + for (int k = 0; k < num; k++) { + int score = scanner.nextInt(); + if(bestScore == 0){ + result++; + } else if(bestScore>=1 && score >= (3* bestScore - 2)){ + result++; + } else if(bestScore>=2 && score>= (3*bestScore -4) && surprisingTriplets>0){ + result++; + surprisingTriplets--; + } + } + pw.println(""Case #"" + i + "": "" + result); + } + scanner.close(); + pw.close(); + } +} +" +A21585," +import java.util.Scanner; + +public class Dancing_with_the_googlers { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int input = sc.nextInt(); + for (int i = 1; i <= input; i++){ + int googlers = sc.nextInt(); + int surprises = sc.nextInt(); + int min = sc.nextInt(); + int results = 0; + for (int j = 0; j < googlers; j++){ + int googler = sc.nextInt(); + int avg = googler / 3; + int mod = googler % 3; + if (avg >= min || ((avg + 1 == min) && mod > 0)){ + results++; + }else if (surprises > 0 && (avg + 1 == min) && avg != 0){ + results++; + surprises--; + }else if (surprises > 0 && (avg + 2 == min) && mod > 1) { + results++; + surprises--; + } + } + System.out.println(""Case #""+i+"": ""+results); + + } + } +} +" +A21432,"package com.google.jam.eaque.qualif.b; + +import java.io.IOException; + +import com.google.jam.eaque.stub.InputFileManager; +import com.google.jam.eaque.stub.Stub; +import com.google.jam.eaque.stub.Util; + +public class Small extends Stub { + + @Override + public String runTestCase(InputFileManager ifm) + throws NumberFormatException, IOException { + + long[] numbers = Util.stringsToLongs(ifm.readAndSplit()); + long[] quotients = new long[(int) numbers[0]]; + long[] remainders = new long[(int) numbers[0]]; + long s = numbers[1]; + long p = numbers[2]; + long res = 0; + + for (int i = 0; i < remainders.length; i++) { + quotients[i] = numbers[i+3] / 3; + remainders[i] = numbers[i+3] % 3; + + if (quotients[i] >= p) + { + res++; + } + else if (quotients[i] == (p - 1)) + { + if (remainders[i] != 0) + { + res++; + } + else if (quotients[i] != 0 && s > 0) + { + res++; + s--; + } + } + else if (quotients[i] == (p - 2) && s > 0) + { + if (remainders[i] == 2) + { + res++; + s--; + } + } + } + + + + return "" "" + res; + } +} +" +A22000,"package Googlers; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class googlers { + + static void print(int nbCases, int N, int S, int P, int[] T) { + System.out.print(N + "" ""); + System.out.print(S + "" ""); + System.out.print(P); + for (int j = 0; j < N; j++) + { + System.out.print("" "" + T[j]); + } + System.out.println(); + } + + static int maxWinners(int N, int S, int P, int[] T) { + int res = 0; + int used = 0; + if (P == 0) + { + return N; + } + else + { + for (int i = 0; i < N; i++) + { + if (T[i] >= 3 * P - 2) + { + res += 1; + } + else if (T[i] >= 3 * P - 4 && used < S && P >= 2) + { + used += 1; + res += 1; + } + } + } + return res; + } + static void run(int N, int S, int P, int[] T, int turn) { + System.out.println(""Case #"" + turn + "": "" + maxWinners(N, S, P, T)); + } + + /** + * @param args + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException { + Scanner f = new Scanner( + new File( + ""C:\\Users\\Jean-Baptiste\\Desktop\\Info2A\\GoogleJam\\src\\Googlers.in"")); + int nbCases = f.nextInt(); + int[] T = { 0 }; + int N = 1; + int S = 1; + int P = 1; + + for (int i = 0; i < nbCases; i++) + { + N = f.nextInt(); + S = f.nextInt(); + P = f.nextInt(); + T = new int[N]; + for (int j = 0; j < N; j++) + { + T[j] = f.nextInt(); + } + run(N, S, P, T, i + 1); + } + + f.close(); + } + +} +" +A22179,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +public class B { + + PrintWriter out; + + public void read() throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + out = new PrintWriter(new FileWriter(""B-large.out"")); + int n = Integer.parseInt(br.readLine()); + int i = 0; + String line; + while (i < n) { + line = br.readLine(); + solve(i + 1, line); + + i++; + } + + out.close(); + out.flush(); + } + + public void solve(int c, String line) { + + int max = 0; + String[] tokens = line.split("" ""); + out.print(""Case #"" + c + "": ""); + + List t = new ArrayList(); + Integer N = Integer.parseInt(tokens[0]); + Integer S = Integer.parseInt(tokens[1]); + Integer p = Integer.parseInt(tokens[2]); + + + for (int i = 3; i < (N + 3); i++) { + if (Integer.parseInt(tokens[i]) >= p) + t.add(Integer.parseInt(tokens[i])); + } + + for (int x = 0; x < t.size(); x++) { + int sub = t.get(x) - p; + + if (sub >= (2 * p)) { + max = max + 1; + } else { + if (p + (p - 1) > sub) { + if ((p - 1) + (p - 1) > sub) { + if (S > 0) { + if ((p - 2) + p > sub) { + if ((p - 2) + (p - 1) > sub) { + if ((p - 2) + (p - 2) > sub) { + continue; + } else if ((p - 2) + (p - 2) == sub) { + max = max + 1; + S = S - 1; + } + } else if ((p - 2) + (p - 1) == sub) { + max = max + 1; + S = S - 1; + } + } else if ((p - 2) + p == sub) { + max = max + 1; + S = S - 1; + } + } + } else if ((p - 1) + (p - 1) == sub) { + max = max + 1; + } + } else if (p + (p - 1) == sub) { + max = max + 1; + } + } + } + + + out.print(max); + out.println(); + } + + public static void main(String[] args) throws IOException { + new B().read(); + } +} +" +A22920,"import java.util.Scanner; + + +public class DWtG { + + static int T,N,S,P; + static int[] t = new int[1000]; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = Integer.parseInt(sc.nextLine()); + for (int k = 0; k= P) result++; + else + { + if (S > 0 && base > 0 && base+1>=P) + { + result++; + S--; + } + } + break; + } + case 1: + { + if (base >= P || base+1 >= P) result++; + else + { + if (S > 0 && base+1 >=P) + { + result ++; + S--; + } + } + break; + } + case 2: + { + if (base + 1 >= P || base >= P) result ++; + else + { + if (S > 0 && base + 2 >= P) + { + result++; + S--; + } + } + + break; + } + } + } + System.out.println(""Case #"" + (k+1) + "": "" + result); + } + } + +} +" +A21884,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; + + +public class DWG { + public static void main(String[] args) { + Integer caseNum = 0; + /*if(args.length == 0) { + return; + } + caseNum = Integer.parseInt(args[0]);*/ + ArrayList argList = new ArrayList(); + + String line=null; + File inputFile = new File(""DWGData.txt""); + BufferedReader reader; + try { + reader = new BufferedReader(new FileReader(inputFile)); + while ((line=reader.readLine()) != null) { + argList.add(line); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + caseNum = Integer.parseInt(argList.get(0)); + + for(int caseIndex=0; caseIndex < caseNum.intValue(); caseIndex++) { + String input = argList.get(caseIndex+1); + System.out.println(""Case #"" + (caseIndex+1) + "": "" + countGooglers(input)); + } + } + + private static int countGooglers(String input) { + int numOfWiners = 0; + String[] inputData = input.split("" ""); + if(inputData.length >=4) { + int numOfGooglers = Integer.parseInt(inputData[0]); + int numOfSurprise = Integer.parseInt(inputData[1]); + int score = Integer.parseInt(inputData[2]); + + int minWithSurprise = ((score > 2) ? (score-2) : 0)*2 + score; + int minWithoutSurprise = ((score > 1) ? (score-1) : 0)*2 + score; + + if((inputData.length-3) == numOfGooglers) { + int[] scoreOfGooglers = new int[numOfGooglers]; + for(int i=0; i < numOfGooglers; i++) { + scoreOfGooglers[i] = Integer.parseInt(inputData[i+3]); + if(scoreOfGooglers[i] >= minWithoutSurprise) { + numOfWiners++; + }else if(scoreOfGooglers[i] >= minWithSurprise) { + if(numOfSurprise > 0) { + numOfWiners++; + numOfSurprise--; + } + } + } + + } + } + + return numOfWiners; + } +} +" +A21118,"import java.io.*; +import java.util.*; +public class BSmall { + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(new File(""B-Large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B-Large.out""))); + + int T = Integer.parseInt(in.nextLine()); + + for (int i = 0; i < T; i++) { + String[] Line = in.nextLine().split("" ""); + int counter = 0; + int surprising = Integer.parseInt(Line[1]); + int thresh = Integer.parseInt(Line[2]); + + int len = Line.length; + + for (int j = 3; j < len; j++) { + int score = Integer.parseInt(Line[j]); + + if (score == 0) { + if (score >= thresh) { + counter++; + } + Line[j] = null; + continue; + } + + int mod3 = score % 3; + switch (mod3) { + case 2: if ((score/3) + 1>= thresh) { + counter++; + Line[j] = null; + break; + } + case 1: if ((score/3) + 1 >= thresh) { + counter++; + Line[j] = null; + break; + } + case 0: if ((score/3) >= thresh) { + counter++; + Line[j] = null; + break; + } + } + } + for (int l = 3; l < len && surprising > 0; l++) { + if (!(Line[l] == null)) { + int score = Integer.parseInt(Line[l]); + int mod3 = score % 3; + switch (mod3) { + case 2: if ((score/3) + 2 >= thresh) { + counter++; + surprising--; + break; + + } + case 1: if ((score/3) + 1 >= thresh) { + counter++; + surprising--; + break; + } + case 0: if ((score/3) + 1 >= thresh) { + counter++; + surprising--; + break; + } + } + } + } + + out.write(""Case #""+ (i+1) +"": "" + counter); + if (i != T-1) + out.write(""\n""); + //System.out.println(counter); + //System.out.println(Arrays.toString(Line)); + } + + out.close(); + System.exit(0); + } +} +" +A20133,"import java.io.*; +import java.util.*; + +public class ProblemB { + public static void main(String[]args) { + Scanner f = new Scanner(System.in); + int T = f.nextInt(); + + for(int set=0;set=p) { + result++; + } else if((base==p-1 && t[c]%3==2 || base==p-1 && base>0 && t[c]%3==0) && S > 0) { + result++; + S--; + } + } + + System.out.printf(""Case #%d: %d\n"",set+1,result); + } + } +}" +A21763," +public class gcj2012PBS { + + + public static void main(String[] args) { + + + String filenameIn = ""B-large.in""; + String filenameOut = ""B-large.out""; + FileIn fi = new FileIn(filenameIn); + String s = fi.getString(); + String ss[] = s.split(""\n""); + StringBuilder sb = new StringBuilder(); + int z = Integer.valueOf(ss[0]); + + + + for (int i = 1; i <= z; i++) { + String tt[] = ss[i].split("" ""); + int [] score = new int[100]; + int google = Integer.valueOf(tt[0]); + int igai = Integer.valueOf(tt[1]); + int saitei = Integer.valueOf(tt[2]); + int answer = 0; + + for (int x = 0; x < google; x++) { + score[x] = Integer.valueOf(tt[x+3]); + + int a = score[x]; + + if(a < saitei) { + continue; + } + + + + if (saitei * 3 <= a) { + answer++; + continue; + } + + + if (saitei * 3 == a) { + answer++; + continue; + } + + int hhh=0; + int ttt=0; + + for (int t = 0; t <=10; t++) { + if (t * 3 >= a) { + ttt = t; + hhh = t*3; + break; + } + } + + + if (a <= saitei + 1 + saitei + 1 + saitei + 1 && a >= saitei + saitei - 1 + saitei - 1 + ) { + answer++; + continue; + } + + + + int b = hhh - a; + + + if( igai > 0 && a >= saitei + saitei - 2 + saitei - 2) { + igai--; + answer++; + continue; + } + + + + + } + sb.append(""Case #""); + sb.append(i); + sb.append("": ""); + sb.append(answer); + sb.append(""\n""); + + + + + + + } + + + + + + + new FileOut(filenameOut, sb.toString()); + + + } + +} +" +A21040,"package codejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Second { + + public static void main(String[] args) throws FileNotFoundException { + String path = ClassLoader.getSystemClassLoader().getResource(""codejam/"").getPath(); + Second worker = new Second(); + +// worker.scan(new File(path, ""second-s.in""), new File(path, ""second-s.out"")); + worker.scan(new File(path, ""second-x.in""), new File(path, ""second-x.out"")); + } + + private void scan(File input, File output) throws FileNotFoundException { + Scanner in = new Scanner(input); + PrintWriter out = new PrintWriter(output); + + int n = Integer.parseInt(in.nextLine()); + for (int i = 0; i < n; i++) { + out.printf(""Case #%d: %s\n"", i + 1, solve(in.nextLine())); + } + + out.flush(); + out.close(); + in.close(); + } + + public String solve(String line) { + String[] tokens = line.split("" ""); + int n = Integer.parseInt(tokens[0]); + int s = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int[] points = new int[n]; + for (int i = 0; i < points.length; i++) { + points[i] = Integer.parseInt(tokens[3 + i]); + } + + int result = 0; + for (int pc : points) { + int r = solve(pc, p); + if (r == 3 && s > 0) { + result++; + s--; + } else if (r == 1 || r == 2) { + result++; + } + } + return """" + result; + } + + public int solve(int pc, int p) { + if (pc == 0) { + return p == 0 ? 1 : 0; + } + int m = pc / 3; + while ( m < p) m++; + + int k = 0; + do { + k = 3 * m; + if (k == pc || k - 1 == pc) { + return 1; + } + if (k - 2 == pc) { + return 2; + } + if (k - 3 == pc || k - 4 == pc) { + return 3; + } + m++; + } while (k - pc <= 4); + return 0; + } +} +" +A20880," +public class GooglersDance { + + boolean surprising = true; + + public int maxDancers(int n, int s,int p, int[] t) { + + int len = t.length; + int winners = 0; + + for(int i = 0; i < n; i++) { + + if(checkWinner(p,t[i],!surprising)) { + + winners++; + continue; + + } + if(s > 0 && checkWinner(p,t[i],surprising)) { + + winners++; + s--; + + } + + } + + return winners; + + } + + private boolean checkWinner(int p, int t, boolean surprisingWanted) { + + if(!surprisingWanted) { + + if(((t-1) % 3) == 0) { + + int a = (t-1)/3; + if(a >= 0 && a+1 >= p) { + + return true; + + } + else { + + return false; + + } + + } + else if(((t-2) % 3) == 0) { + + int a = (t-2)/3; + if(a >= 0 && a+1 >= p) { + + return true; + + } + else { + + return false; + + } + + } + else { + + int a = t/3; + if(a >= p) { + + return true; + + } + else { + + return false; + + } + + } + + } + else { + + int a = 0; + switch(t % 3) { + + case 0 : + a = t/3 - 1; + break; + case 1 : + a = (t-4)/3; + break; + case 2 : + a = (t-2)/3; + break; + + } + if(a >= 0 && a+2 >= p) { + + return true; + + } + else { + + return false; + + } + + } + + + } + +} +" +A21372," +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + +public class DancingWithGooglers { + + public static int outputLine(String inputLine){ + int count = 0; + String[] inputArray = inputLine.split("" ""); + ArrayList line = new ArrayList(Arrays.asList(inputArray)); + int surprises = Integer.parseInt((String) line.get(1)); + int key = Integer.parseInt((String) line.get(2)); + int minCompare = key + key - 2 + key -2; + if (minCompare < 0) + minCompare =0; + int autoYes = key + key - 1 + key -1; + for (int k = 3; k < line.size(); k++) { + if (Integer.parseInt((String) line.get(k)) == 0 && key ==0) + count++; + else if (Integer.parseInt((String) line.get(k)) <= 0) + count = count; + else if (Integer.parseInt((String) line.get(k)) >= autoYes) { + count++; + } + else if (Integer.parseInt((String) line.get(k)) >= minCompare && surprises > 0) { + count ++; + surprises --; + } + } + return count; + + } + + public static void main (String [] args) { + ArrayList answers = new ArrayList(); + System.out.println(""Insert a number.""); + int i; + Scanner scan = new Scanner(System.in); + i = Integer.parseInt(scan.nextLine()); + for (int j = 0; j< i; j++) { + String inputLine = scan.nextLine(); + answers.add(outputLine(inputLine)); + } + for (int j = 0; j < answers.size(); j++){ + System.out.println(""Case #"" + (j+1) + "": "" + (answers.get(j))); + } + + +/* + String output = """"; + int length = inputArray.get(j).length(); + for (int k = 0; k < length; k++) { + output += convertLetter(inputArray.get(j).substring(k,k+1)); + } + System.out.println (""Case #"" + (j+1) + "": ""+ output); + */ + } + + }" +A22944,"import java.io.*; +import java.util.Arrays; +import java.util.Locale; +import java.util.Scanner; + +public class DancingWithTheGooglers { + // -ea –Xmx256M –Xss64M + int N, S, p; + int[] t; + + private Object solve() throws Exception { + Arrays.sort(t); + int result = 0; + for (int i = t.length - 1; i >= 0; i--) { + int r = t[i]; + int k = r / 3; + if (r % 3 > 0) k++; + if (k >= p) { result++; continue; } + if (S == 0) break; + + if (r > 0 && r % 3 != 1) { + k++; + } + if (k >= p) { result++; S--; } + } + return result; + } + + private void load() throws Exception { + N = nextInt(); + S = nextInt(); + p = nextInt(); + t = nextIntArray(N); + log.print(""N: "" + N + "", S: "" + S + "", p: "" + p + "", t: "" + Arrays.toString(t)); + } + + + private static final String PREFIX = ""B-large""; + private static final String PATH = ""d:/gcjam12/qr/""; + private static final String POSTFIX_IN = "".in""; + private static final String POSTFIX_OUT = "".out""; + private static final PrintStream log = System.out; + + public static void main(String args[]) throws Exception { + Locale.setDefault(Locale.US); + InputStreamReader reader = new InputStreamReader(new BufferedInputStream(new FileInputStream(PATH + PREFIX + POSTFIX_IN))); + PrintStream out = new PrintStream(new FileOutputStream(PATH + PREFIX + POSTFIX_OUT)); + Scanner in = new Scanner(reader); + + long t0 = System.nanoTime(); + int testCount = in.nextInt(); in.nextLine(); + for (int testIndex = 1; testIndex <= testCount; testIndex++) { + log.printf(""Data #%d: "", testIndex); + + DancingWithTheGooglers s = new DancingWithTheGooglers(); + s.in = in; + s.load(); + s.in = null; + log.println(); + + long t1 = System.nanoTime(); + String result = ""Case #"" + testIndex + "": "" + s.solve(); + + out.println(result); + log.println(result); + log.printf(""Time #%d: %.6f sec\n\n"", testIndex, (System.nanoTime() - t1) / 1e9); + } + log.printf(""Total time: %.6f sec"", (System.nanoTime() - t0)/1e9); + + reader.close(); + out.close(); + } + + private Scanner in; + private int nextInt() { return in.nextInt(); } + private long nextLong() { return in.nextLong(); } + private double nextDouble() { return Double.parseDouble(in.next()); } + private String nextLine() { return in.nextLine().trim(); } + private void skipLine() { in.nextLine(); } + private String next() { return in.next().trim(); } + private int[] nextIntArray(int size) { int[] a = new int[size]; for (int i = 0; i < size; i++) a[i] = in.nextInt(); return a; } + private long[] nextLongArray(int size) { long[] a = new long[size]; for (int i = 0; i < size; i++) a[i] = in.nextLong(); return a; } + private double[] nextDoubleArray(int size) { double[] a = new double[size]; for (int i = 0; i < size; i++) a[i] = Double.parseDouble(in.next()); return a; } + private String[] nextLineArray(int size) { String[] a = new String[size]; for (int i = 0; i < size; i++) a[i] = in.nextLine().trim(); return a; } + private String[] nextTokenArray(int size) { String[] a = new String[size]; for (int i = 0; i < size; i++) a[i] = in.next().trim(); return a; } +} +" +A20938,"import java.io.*; +import java.util.*; + +public class dancing { + static String next() { + if (st == null || !st.hasMoreTokens()) + nextLine(); + return st.nextToken(); + } + + static int nextInt() { + return Integer.parseInt(next()); + } + + static void nextLine() { + try { + st = new StringTokenizer(f.readLine()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + static StringTokenizer st; + static PrintWriter out; + static BufferedReader f; + + public static void main(String[] args) throws IOException { + String progName = (dancing.class.getCanonicalName()) + ""2.out""; + f = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(System.out); + out = new PrintWriter(new BufferedWriter(new FileWriter(progName))); + int T = nextInt(); + for (int test = 1; test <= T; test++) { + int N = nextInt(), S = nextInt(), p = nextInt(); + int a = 3 * p - 4, b = 3 * p - 2; + if (p == 1) + a = 1; + int count = 0; + for (int i = 0; i < N; i++) { + int x = nextInt(); + if (x >= b) { + count++; + } else if (x >= a && S > 0) { + S--; + count++; + } + } + out.printf(""Case #%d: %d\n"", test, count); + } + out.close(); + // System.exit(0); + } + +}" +A21346,"import java.util.*; +import java.io.*; + +public class Qual2012 { + + public static void lame() { + try { + FileReader fr = new FileReader(""input.txt""); + BufferedReader reader = new BufferedReader(fr); + PrintWriter writer = new PrintWriter(""output.txt""); + + HashMap dictionary = new HashMap(); + dictionary.put(""a"", ""y""); + dictionary.put(""b"", ""h""); + dictionary.put(""c"", ""e""); + dictionary.put(""d"", ""s""); + dictionary.put(""e"", ""o""); + dictionary.put(""f"", ""c""); + dictionary.put(""g"", ""v""); + dictionary.put(""h"", ""x""); + dictionary.put(""i"", ""d""); + dictionary.put(""j"", ""u""); + dictionary.put(""k"", ""i""); + dictionary.put(""l"", ""g""); + dictionary.put(""m"", ""l""); + dictionary.put(""n"", ""b""); + dictionary.put(""o"", ""k""); + dictionary.put(""p"", ""r""); + dictionary.put(""q"", ""z""); + dictionary.put(""r"", ""t""); + dictionary.put(""s"", ""n""); + dictionary.put(""t"", ""w""); + dictionary.put(""u"", ""j""); + dictionary.put(""v"", ""p""); + dictionary.put(""w"", ""f""); + dictionary.put(""x"", ""m""); + dictionary.put(""y"", ""a""); + dictionary.put(""z"", ""q""); + dictionary.put ("" "", "" ""); + int numCases = Integer.parseInt(reader.readLine()); + + for (int i = 1; i <= numCases; i++) { + String sentence = reader.readLine(); + String newSentence = """"; + for (char c: sentence.toCharArray()) { + char[] temp = new char[1]; + temp[0] = c; + newSentence += dictionary.get(new String(temp)); + } + writer.println(""Case #"" + i + "": "" + newSentence); + } + + writer.close(); + fr.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public static boolean canMatch(int score, int target) { + if (score == 0) + return target <= 0; + if (score == 1 || score == 2) + return target <= 1; + if (score % 3 == 0){ + return score/3 >= target; + } + return ((score/3) + 1 >= target); + } + + public static boolean canMatchSpecial(int score, int target) { + if (score == 0) + return target <= 0; + if (score == 1) + return target <= 1; + if (score == 2) + return target <= 2; + if (score % 3 == 1) + return (score /3 + 1) >= target; + return (score /3 + 2) >= target; + } + + public static void dance() { + try { + FileReader fr = new FileReader(""input.txt""); + BufferedReader reader = new BufferedReader(fr); + PrintWriter writer = new PrintWriter(""output.txt""); + + int numCases = Integer.parseInt(reader.readLine()); + for (int i = 1; i <= numCases; i++) { + StringTokenizer line = new StringTokenizer(reader.readLine(), "" ""); + int numDancers = Integer.parseInt(line.nextToken()); + int numSurprising = Integer.parseInt(line.nextToken()); + int bestScore = Integer.parseInt(line.nextToken()); + List scores = new LinkedList(); + for (int j = 0; j < numDancers; j++) + scores.add(Integer.parseInt(line.nextToken())); + int count = 0; + for (Integer score: scores) { + if (canMatch(score, bestScore)) + count++; + else if (canMatchSpecial(score, bestScore) && numSurprising > 0) { + numSurprising--; + count++; + } + } + writer.println(""Case #"" + i + "": "" + count); + } + + writer.close(); + fr.close(); + + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main (String[] args) { + //lame(); + dance(); + } +}" +A21014,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package gcj.b; + +import java.util.Scanner; + +/** + * + * @author S_Malindi + */ +public class B { + + public static void main(String[] args) { + + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); + + for (int z = 1; z <= T; z++) { + + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + + int t = 0; + int ans = 0; + int mscore = (P * 3); + + for (int i = 1; i <= N; i++) { + + t = in.nextInt(); + + if (t >= (mscore - 2)) { + + ans++; + + } else if (t >= (mscore - 4)) { + if ((S > 0 )&& ( t > 0) ) { + + S--; + ans++; + } + + } + + } + + System.out.format(""Case #%d: %d\n"", z, ans); + + } + + } +} +" +A21454,"package org.ivansopin.jam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + final static String fileName = ""DancingWithTheGooglers2""; + + final static String inExtension = "".in""; + final static String outExtension = "".out""; + final static String source = fileName + inExtension; + final static String destination = fileName + outExtension; + + static BufferedReader bufferedReader; + static BufferedWriter bufferedWriter; + static int counter; + + /* this is problem-specific */ + static int numOfCases; + static int numOfPeople, tmpNumOfPeople; + static int numOfSurp, tmpNumOfSurp; + static int max, tmpMax; + static int[] points, tmpPoints; + + public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException { + bufferedReader = new BufferedReader(new FileReader(new File(source))); + bufferedWriter = new BufferedWriter(new FileWriter(new File(destination))); + + numOfCases = Integer.parseInt(bufferedReader.readLine()); + + Reader reader = new Reader(); + reader.start(); + reader.join(); + + for (int i = 0; i < numOfCases; i++) { + copyData(); + + reader = new Reader(); + reader.start(); + + /********* this is where the real logic starts **********/ + + Comparator comparator = new ScoreComparator(); + ArrayList scores = new ArrayList(); + int curNumOfSurp = 0; + int curNumOfGood = 0; + + for (int j = 0; j < numOfPeople; j++) { + Score score = new Score(points[j], max); + scores.add(score); + //score.display(); + if (score.surprising) + curNumOfSurp++; + if (score.elMax >= max) + curNumOfGood++; + } + + System.out.println(curNumOfSurp + "" surprises initially; "" + numOfSurp + "" expected""); + + if (curNumOfSurp < numOfSurp) { + Collections.sort(scores, comparator); + + int j = 0; + + while (curNumOfSurp < numOfSurp) { + Score score = scores.get(j++); + + if (!score.surprising) { + score.switchSurp(); + curNumOfSurp++; + } + } + + } else if (curNumOfSurp > numOfSurp) { + Collections.sort(scores, comparator); + + int j = scores.size() - 1; + + while (curNumOfSurp > numOfSurp) { + Score score = scores.get(j--); + + if (score.surprising) { + boolean wasGoodScore = score.elMax >= max; + if (score.switchSurp()) + curNumOfSurp--; + boolean isGoodScore = score.elMax >= max; + if (wasGoodScore && !isGoodScore) + curNumOfGood--; + } + } + } + + //for (int j = 0; j < numOfPeople; j++) { + // scores.get(j).display(); + //} + + // at some point, the results should be printed: + bufferedWriter.write(""Case #"" + (i + 1) + "": "" + curNumOfGood + ""\n""); + + + /********** this is where the real logic ends ***********/ + + if (reader.isAlive()) { + reader.join(); + } + } + + bufferedWriter.close(); + bufferedReader.close(); + } + + static class ScoreComparator implements Comparator + { + @Override + public int compare(Score x, Score y) + { + // Assume neither string is null. Real code should + // probably be more robust + if (x.total < y.total) + { + return -1; + } + if (x.total > y.total) + { + return 1; + } + return 0; + } + } + + static class Score { + int type; + boolean surprising = false; + int elMax; + int total; + + Score (int total, int maxWanted) { + this.total = total; + int rem = total % 3; + int maxElement; + + if (rem == 0) { + if (total == 0) { + maxElement = 0; + type = 1; + } else { + maxElement = total / 3; + + if ((maxElement >= maxWanted) || (maxElement + 1 < maxWanted)) { + elMax = maxElement; + type = 1; + } else { + elMax = maxElement + 1; + surprising = true; + type = 5; + } + } + } else if (rem == 1) { + maxElement = total / 3 + 1; + + elMax = maxElement; + type = 2; + } else { + maxElement = total / 3 + 1; + + if ((maxElement >= maxWanted) || (maxElement + 1 < maxWanted)) { + elMax = maxElement; + type = 3; + } else { + elMax = maxElement + 1; + surprising = true; + type = 4; + } + } + } + + boolean switchSurp() { + if (surprising) { + if (type == 5) { + type = 1; + elMax -= 2; + } else if (type == 6) { + type = 2; + } else { + type = 3; + elMax -= 1; + } + + return true; + } else { + if (type == 1) { + if (total != 0) { + type = 5; + elMax += 2; + return true; + } + return false; + } else if (type == 2) { + type = 6; + return true; + } else { + type = 4; + elMax += 1; + return true; + } + } + } + + void display() { + String triple = ""\t[""; + + if (type == 1) { + triple += elMax + "","" + elMax + "","" + elMax; + } else if (type == 2) { + triple += (elMax - 1) + "","" + (elMax - 1) + "","" + (elMax); + } else if (type == 3) { + triple += (elMax - 1) + "","" + (elMax) + "","" + (elMax); + } else if (type == 4) { + triple += (elMax - 2) + "","" + (elMax - 2) + "","" + (elMax); + } else if (type == 5) { + triple += (elMax - 2) + "","" + (elMax - 1) + "","" + (elMax); + } else { + triple += (elMax - 2) + "","" + (elMax) + "","" + (elMax); + } + + System.out.println(triple + ""] = "" + total + "" ("" + surprising + "") (type "" + type + "")""); + } + } + + static void copyData() { + /* this is problem-specific */ + numOfPeople = tmpNumOfPeople; + numOfSurp = tmpNumOfSurp; + max = tmpMax; + points = tmpPoints; + } + + static class Reader extends Thread { + public Reader() { + } + + @Override + public void run() { + int item; + String line; + StringTokenizer tokenizer; + + try { + if (counter < numOfCases) { + /* this is problem-specific */ + line = bufferedReader.readLine(); + tokenizer = new StringTokenizer(line); + + tmpNumOfPeople = Integer.parseInt(tokenizer.nextToken()); + tmpNumOfSurp = Integer.parseInt(tokenizer.nextToken()); + tmpMax = Integer.parseInt(tokenizer.nextToken()); + tmpPoints = new int[tmpNumOfPeople]; + + for (int i = 0; i < tmpNumOfPeople; i++) { + item = Integer.parseInt(tokenizer.nextToken()); + + tmpPoints[i] = item; + } + + counter++; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} +" +A22863,"import java.util.*; +import java.io.*; + +public class DancingWithTheGooglers{ + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + Formatter formatter = new Formatter(System.out); + int T = Integer.parseInt(br.readLine()); + String[] dataStr; + int[] data; + int lineNum=1; + while(T-->0){ + dataStr = br.readLine().split(""\\s""); + data=new int[dataStr.length-3]; + for(int i=0;i=p || (div3==p-1 && dances[i] % 3>=1)) { + best++; + continue; + } + if((div3 == p - 1 && div3>=1) || (div3==p-2 && dances[i]%3==2)){ + maybe++; + continue; + } + } + return best+Math.min(S,maybe); + } +} +" +A22609,"package main; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class TestClass { + + public static void main (String[] args) throws IOException, InterruptedException { + BufferedReader reader = new BufferedReader(new FileReader(""C:\\in.txt"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""C:\\out.txt"")); + MyTest myTest = new MyTest(); + myTest.getTranslation(); + + int caseNum = Integer.parseInt(reader.readLine()); + for(int i=0; i points = new ArrayList(); + + int N = Integer.parseInt(numbers[0]); + int S = Integer.parseInt(numbers[1]); + int p = Integer.parseInt(numbers[2]); + + for(int j=0; j 0, best result is at least avgBase + 1 + if (addPoint > 0) { + bestResult += 1; + } + if (bestResult >= c.p) { + // already larger than p, no surprising needed + c.increment(); + } else { + // use surprising point if possible, 3 conditions + // 1. still has surprising point to use + // 2. addPoint is 0 or 2 (surprising can make a difference) + // 3. total point >= 2 (can't make point 2 apart if the total point is < 2) + if (c.hasS() && addPoint != 1 && c.t[i] >= 2) { + // when addPoint is 0 or 2, best result can be incremented by 1 if is surprising triplet + if (bestResult + 1 >= c.p) { + c.useS(); + c.increment(); + } + } + } + } + } + + // write result + writeFile(cases, ""B-large.out""); + print(""Complete!""); + } + + public static void printf(String format, Object... args) { + System.out.printf(format, args); + } + + public static void print(Object o) { + System.out.println(o); + } + + public static void writeFile(CaseB[] result, String out) { + PrintWriter writer = null; + try { + writer = new PrintWriter(out); + for (int i = 0; i < result.length; i++) { + writer.printf(""Case #%d: %s\n"", i+1, result[i]); + } + writer.flush(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (writer != null) { + writer.close(); + } + } + } + + public static CaseB[] read(String file) { + BufferedReader reader = null; + CaseB[] cases = null; + try { + reader = new BufferedReader(new FileReader(file)); + + // get test case count + int caseCount = Integer.parseInt(reader.readLine()); + cases = new CaseB[caseCount]; + for (int i = 0; i < cases.length; i++) { + Scanner scan = new Scanner(reader.readLine()); + int n = scan.nextInt(); + int s = scan.nextInt(); + int p = scan.nextInt(); + int[] t = new int[n]; + for (int x = 0; x < n; x++) { + t[x] = scan.nextInt(); + } + + cases[i] = new CaseB(s, p, t); + scan.close(); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return cases; + } +} + +class CaseB { + //private int n; // number of Googler + private int s; // number of surprising triplets + int p; // expected best result + int[] t; // total score of each Googler + + private int result; + + public CaseB(int s, int p, int[] t) { + this.s = s; + this.p = p; + this.t = t; + this.result = 0; + } + + public void increment() { + result++; + } + + public boolean hasS() { + return s > 0; + } + + public void useS() { + s--; + } + + public int getResult() { + return result; + } + + public void setResult(int result) { + this.result = result; + } + + @Override + public String toString() { + return """" + result; + } + + public String getInfo() { + String out = t.length + "" "" + s + "" "" + p; + for (int i = 0; i < t.length; i++) { + out += "" "" + t[i]; + } + return out; + } +} +" +A20610,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class problemB { + + static int diff(int a,int b,int c){ + return Math.max(Math.max(Math.abs(a-b), Math.abs(b-c)),Math.abs(c-a)); + } + static int func(int score, int least){ + int val=0,possible=0,surprise=0; + while(least<=30){ + if(least-1>=0 && score-least-least+1>=0){ + val = diff(least,least-1,score-least-least+1); + if(val==0||val==1){possible++;break;} + else if(val==2){surprise++;} + } + if(least-2>=0 && score-least-least+2>=0){ + val = diff(least,least-2,score-least-least+2); + if(val==0||val==1){possible++;break;} + else if(val==2){surprise++;} + } + if(score-least-least>=0){ + val = diff(least,least,score-least-least); + if(val==0||val==1){possible++;break;} + else if(val==2){surprise++;} + } + if(score-least-least-1>=0){ + val = diff(least,least+1,score-least-least-1); + if(val==0||val==1){possible++;break;} + else if(val==2){surprise++;} + } + if(score-least-least-2>=0){ + val = diff(least,least-2,score-least-least-2); + if(val==0||val==1){possible++;break;} + else if(val==2){surprise++;} + } + least++; + } + if(possible==1)return 0; + else if(surprise >= 1)return 1; + else return 3; + } + + public static void main(String args[]) throws IOException{ + //System.out.println(func(29,12)); + BufferedWriter out = new BufferedWriter(new FileWriter(""D:\\B-large.out"")); + Scanner sc = new Scanner(new File(""D:\\B-large.in"")); + int test = sc.nextInt(); + for(int i=0;ifsurprise){ + out.write(""Case #"" + (i+1) + "": "" + String.valueOf(fnormal+fsurprise)); + } + else{ + out.write(""Case #"" + (i+1) + "": "" + String.valueOf(fnormal+surprise)); + } + out.newLine(); + //System.out.println(googlers + "" "" + surprise + "" "" + least + "" "" + score[googlers-1]); + } + out.close(); + } + +} +" +A22881,"package year2012; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.HashSet; +import java.util.Set; + +public class Dancing { + + + static PrintWriter out; + + static int count(int[] scores, int N, int S, int p) { + int result = 0; + for (int i = 0; i < N; ++i) { + if (scores[i] >= p) { + int rest = scores[i] - p; + if (rest/2 > (p - 2)) { + result ++; + } else if (S > 0 && rest/2 == (p - 2)) { + result ++; + S --; + } else { + continue; + } + } + } + return result; + } + + static void deal(String file) throws Exception { + BufferedReader reader = new BufferedReader(new InputStreamReader( + new FileInputStream(file), ""utf8"")); + String line = reader.readLine(); + int T = Integer.parseInt(line); + for (int no = 1; no <= T; no++) { + String[] args = reader.readLine().split(""\\s""); + int N = Integer.parseInt(args[0]); + int S = Integer.parseInt(args[1]); + int p = Integer.parseInt(args[2]); + int scores[] = new int[N]; + for (int i = 0; i < N; ++i) { + scores[i] = Integer.parseInt(args[3 + i]); + } + out.println(""Case #"" + no + "": "" + count(scores, N, S, p)); + } + } + + public static void main(String[] args) throws Exception { + out = new PrintWriter(new File(""result-out.txt"")); + //deal(""B-large.in""); + deal(""B-large.in""); + out.close(); + + } + +} +" +A20076,"import java.util.Scanner; + +/** + * Abdulaziz + * 4/13/12 + * Problem + *

+ * You're watching a show where Googlers (employees of Google) dance, and then each dancer is given a triplet of scores by three judges. Each triplet of scores consists of three integer scores from 0 to 10 inclusive. The judges have very similar standards, so it's surprising if a triplet of scores contains two scores that are 2 apart. No triplet of scores contains scores that are more than 2 apart. + *

+ * For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. + *

+ * The total points for a Googler is the sum of the three scores in that Googler's triplet of scores. The best result for a Googler is the maximum of the three scores in that Googler's triplet of scores. Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? + *

+ * For example, suppose there were 6 Googlers, and they had the following total points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising triplets of scores, and you want to know how many Googlers could have gotten a best result of 8 or better. + *

+ * With those total points, and knowing that two of the triplets were surprising, the triplets of scores could have been: + *

+ * 10 9 10 + * 6 6 8 (*) + * 2 3 3 + * 6 6 6 + * 6 6 6 + * 6 7 8 (*) + * The cases marked with a (*) are the surprising cases. This gives us 3 Googlers who got at least one score of 8 or better. There's no series of triplets of scores that would give us a higher number than 3, so the answer is 3. + * Input + *

+ * The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing integers separated by single spaces. The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. + *

+ * Output + *

+ * For each test case, output one line containing ""Case #x: y"", where x is the case number (starting from 1) and y is the maximum number of Googlers who could have had a best result of greater than or equal to p. + *

+ * Limits + *

+ * 1 ≤ T ≤ 100. + * 0 ≤ S ≤ N. + * 0 ≤ p ≤ 10. + * 0 ≤ ti ≤ 30. + * At least S of the ti values will be between 2 and 28, inclusive. + * Small dataset + *

+ * 1 ≤ N ≤ 3. + * Large dataset + *

+ * 1 ≤ N ≤ 100. + * Sample + *

+ *

+ * Input + *

+ * Output + *

+ * 4 + * 3 1 5 15 13 11 + * 3 0 8 23 22 21 + * 2 1 1 8 0 + * 6 2 8 29 20 8 18 18 21 + * Case #1: 3 + * Case #2: 2 + * Case #3: 1 + * Case #4: 3 + */ +public class Problem2 { + public static void main(String[] args) { + /*4 + 3 1 5 15 13 11 + 3 0 8 23 22 21 + 2 1 1 8 0 + 6 2 8 29 20 8 18 18 21 + Case #1: 3 + Case #2: 2 + Case #3: 1 + Case #4: 3 + */ + String sLines = args[0]; + int lines = Integer.valueOf(sLines); + String[] inputs = new String[lines]; + Scanner in = new Scanner(System.in); + + for (int i = 0; i < Integer.valueOf(sLines); i++) { + inputs[i] = in.nextLine(); + } + + for (int i = 1; i <= inputs.length; i++) { + System.out.println(""Case #"" + i + "": "" + analyze(inputs[i - 1].trim())); + } + + + } + + private static int analyze(String str) { + String[] arg = str.split("" ""); + int googler = Integer.valueOf(arg[0]); + int suprising = Integer.valueOf(arg[1]); + int condition = Integer.valueOf(arg[2]); + int found = 0; + + for (int i = 3; i < googler + 3; i++) { + int sum = Integer.valueOf(arg[i]); + // int del = sum / 3; + + if (condition == 0) { + found++; + continue; + } + + if (condition == 1 && sum >= 1) { + found++; + continue; + } + + if (sum < 2) + continue; + + if (3 * condition - 4 <= sum && sum < 3 * condition - 2) { + + if (suprising == 0) + continue; + + suprising--; + found++; + } else { + if (sum >= 3 * condition - 2) + found++; + } + + } + return found; + } + + +} +" +A21428,"package qualification; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + +public class ProblemB { + + public static int solve(String in){ + int n; + int s; + int p; + + int need = 0; + int count = 0; + String[] segs = in.split(""\\s+""); + n = Integer.parseInt(segs[0]); + s = Integer.parseInt(segs[1]); + p = Integer.parseInt(segs[2]); + + for (int i = 3; i < segs.length; i++){ + int score = Integer.parseInt(segs[i]); + if (score >= 3*p && p >= 0) + count++; + else if (score >= (3*p - 2) && (p >= 1)) + count++; + else if (score >= (3*p - 4) && (p >= 2)) + need++; + } + + if (need <= s) + count += need; + else + count += s; + + return count; + } + + public static void main(String[] args) { + + try{ + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""outputB-large"")); + String line = br.readLine(); + int ans = 0; + int num = Integer.parseInt(line); + + for (int i = 0; i < num; i++){ + line = br.readLine(); + ans = solve(line); + bw.write(""Case #"" + (i+1) + "": "" + ans + ""\n""); + } + + br.close(); + bw.close(); + }catch(Exception e){ + e.printStackTrace(); + } + } + +} +" +A20965," +public class Code2DataStructure { + + private int noOfGooglers; + private int surprisingTrplets; + private int p; + private int[] marks; + private int result; + public int getNoOfGooglers() { + return noOfGooglers; + } + public void setNoOfGooglers(int noOfGooglers) { + this.noOfGooglers = noOfGooglers; + } + public int getSurprisingTrplets() { + return surprisingTrplets; + } + public void setSurprisingTrplets(int surprisingTrplets) { + this.surprisingTrplets = surprisingTrplets; + } + public int getP() { + return p; + } + public void setP(int p) { + this.p = p; + } + public int[] getMarks() { + return marks; + } + public void setMarks(int[] marks) { + this.marks = marks; + } + public int getResult() { + return result; + } + public void setResult(int result) { + this.result = result; + } + + + +} +" +A21750,"public class QualBDancingWithTheGooglers +{ + static boolean debug = false; + + public static void main(String[] args) + { + Utils.openInFile(""B-large.in""); + Utils.openOutFile(""out.txt"", debug); + String input = Utils.readFromFile(); + int lineCount = Integer.parseInt(input); + + //while ((input = Utils.readFromFile()) != null) + for (int line = 1; line <= lineCount; line++) + { + if (debug) System.out.println(); + input = Utils.readFromFile(); + String[] split = input.split("" ""); + int Number = Integer.parseInt(split[0]), + Surprising = Integer.parseInt(split[1]), + points = Integer.parseInt(split[2]); + int[] allPoints = new int[Number]; + for (int j = 0; j < Number; j++) + allPoints[j] = Integer.parseInt(split[j+3]); + String output = """"; + + int mustBeSurprisingCount = 0, count = 0; + + for (int sumP: allPoints) + { + int mod = sumP%3; + int third = sumP/3; + int minP = third, maxP = third, minPSup = third, maxPSup = third; + switch (mod) + { + case 0: minPSup--; maxPSup++; break; + case 1: maxP++; minPSup--; maxPSup++; break; + case 2: + default:maxP++; maxPSup+=2; + } + if (debug) System.out.println(""third=""+third); + if (points <= maxP) + count++; + else if (2 <= sumP && sumP <= 28 && points <= maxPSup) + mustBeSurprisingCount++; + } + + if (debug) + { + System.out.println(""input=""+input); + System.out.println(""count=""+count); + System.out.println(""mustBeSurprisingCount=""+mustBeSurprisingCount); + } + output = ""Case #"" + line + "": ""; + output += (count + Math.min(mustBeSurprisingCount, Surprising)); + Utils.writeToFile(output); + } + Utils.closeInFile(); + Utils.closeOutFile(); + } +} +" +A22246,"package inout; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; + +/** + * + * @author Hasier Rodriguez + */ +public final class Out { + + private Out() { + } + + public static void write(String path, int n, String result) throws FileNotFoundException, IOException { + File f = new File(path); + BufferedWriter br = new BufferedWriter(new FileWriter(f, true)); + String out = ""Case #"" + n + "": "" + result; + br.write(out); + System.out.println(out); + br.newLine(); + br.flush(); + br.close(); + } +} +" +A21002,"package fixjava; + +/** + * Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method + * in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in + * Java. + * + * + final HashSet allNames = new HashSet(); + Lambda, Void> addAllIfNotNull = new Lambda, Void>() { + public Void apply(Set newNames) { + if (allNames != null) + allNames.addAll(newNames); + return null; + } + }; + allNames.add(cell.getName()); + addAllIfNotNull.apply(cell.getValues(""Main_name"")); + addAllIfNotNull.apply(cell.getValues(""Other_name"")); + addAllIfNotNull.apply(cell.getValues(""Tree_node"")); + addAllIfNotNull.apply(cell.getValues(""Lineage_name"")); + * + */ + +public interface Lambda { + public V apply(P param); +} +" +A22715,"import java.util.*; +/** + * Google Code Jam 2012 Qualification Round Problem B: Dancing With the Googlers + * + * @author Wayne Roswell + * @version (4/14/2012 3:20PM EST) + */ +public class Dancing +{ + public static void main(String[] args) + { + Scanner a = new Scanner(System.in); + + String b = a.nextLine(); + int c = Integer.parseInt(b); + + for(int i = 0; i < c; i++) + { + String d = a.nextLine(); + String[] e = d.split("" ""); + int number = Integer.parseInt(e[0]); + int surprises = Integer.parseInt(e[1]); + int score = Integer.parseInt(e[2]); + int[] dancers = new int[number]; + int y = 0; + for(int j = 0; j < number; j++) + { + dancers[j] = Integer.parseInt(e[j + 3]); + } + + for(int j = 0; j < number; j++) + { + int even = dancers[j] / 3; + int[] add = {even, even, even}; + + int diff = dancers[j] - score; + int other = diff / 2; + int mod = diff % 2; + //System.out.println(dancers[j] + "" "" + even + "" "" + diff + "" "" + other + "" "" + score); + /*if(score == other) + { + y++; + } + else + { + if((score + (other * 2)) == dancers[j]) + { + if(Math.abs(score - other) == 1) + { + y++; + } + else if(Math.abs(score - other) == 2 && surprises > 0) + { + surprises--; + y++; + } + } + }*/ + int sum = add[0] + add[1] + add[2]; + if(even >= score) + { + y++; + } + else + { + if(dancers[j] == sum) + { + if(even >= score) + { + y++; + } + else if((score - even) == 1 && surprises > 0 && dancers[j] > 0 && (score - other) < 3 && (other + mod) < 11) + { + surprises--; + y++; + } + } + else + { + if(even >= score) + { + y++; + } + else if((score - even) == 1 && dancers[j] > 0 && (score - other) < 3 && (other + mod) < 11) + { + y++; + } + else if((score - even) == 2 && surprises > 0 && dancers[j] > 0 && (score - other) < 3 && (other + mod) < 11) + { + surprises--; + y++; + } + } + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + y); + } + } +}" +A20459,"package year2012.DancingWiththeGooglers; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +final class DancingWiththeGooglers { + + /** + * @param args + * @throws IOException + */ + static class Triplet { + public boolean ableMax = false; + public boolean ableSurprising = true; + public boolean beMaxMustSurprise = false; + + Triplet(int totalScore, int maxScore) { + int mean = totalScore / 3; + int remainder = totalScore % 3; + if (totalScore == 29 || totalScore == 30) { + ableMax = true; + } + else if (totalScore == 0 || totalScore == 1) + { + ableSurprising = false; + if (maxScore <= totalScore) + { + ableMax = true; + } + else ableMax = false; + } + else if (mean >= maxScore) { + ableMax = true; + } else if (mean == (maxScore - 1)) { + if (remainder == 2 || remainder == 1) + ableMax = true; + if (remainder == 0) + beMaxMustSurprise = true; + } else if (mean == (maxScore - 2)) { + if (remainder == 2) + beMaxMustSurprise = true; + } + } + } + + public static void main(String[] args) throws IOException { + + String file = ""B-large""; + Scanner sc = new Scanner(new FileReader(file + "".in"")); + PrintWriter pw = new PrintWriter(new FileWriter(file + "".out"")); + + int T = sc.nextInt(); + for (int i = 0; i < T; i++) { + + int N = sc.nextInt(); + int S = sc.nextInt(); // surprising + int p = sc.nextInt(); + + int totalBeAlwaysMax = 0; + int totalBeMaxMustSurprising = 0; + int totalNotSurpriseAbleMax = 0; + + int result = 0; + + for (int i1 = 0; i1 < N; i1++) { + Triplet temp = new Triplet(sc.nextInt(), p); + if (temp.ableMax && temp.ableSurprising) + totalBeAlwaysMax++; + if (temp.beMaxMustSurprise == true) + totalBeMaxMustSurprising++; + if (!temp.ableSurprising && temp.ableMax) + { + totalNotSurpriseAbleMax++; + } + + } + + if (S <= totalBeMaxMustSurprising) { + result = totalBeAlwaysMax + S + totalNotSurpriseAbleMax ; + } else { + result = totalBeAlwaysMax + totalBeMaxMustSurprising + totalNotSurpriseAbleMax; + } + + pw.println(""Case #"" + (i + 1) + "": "" + result); + // pw.println(); + + } + pw.flush(); + pw.close(); + sc.close(); + } +} +" +A21087,"/** + * Created by IntelliJ IDEA. + * User: Administrator + * Date: 3/3/12 + * Time: 11:00 AM + * To change this template use File | Settings | File Templates. + */ + +import SRMLib.MathLibrary; +import SRMLib.TestSRMLib; +import com.sun.org.apache.bcel.internal.generic.F2D; + +import java.io.*; +import java.util.*; +import java.util.zip.Inflater; + +public class SRM { + public static void main(String[] args) throws IOException { + //TestSRMLib.run(); + codeJam1.main(); + + return; + } +} +class codeJam1 { + public static void main() throws IOException { + String inputPath = ""E:\\input.txt""; + String outputPath = ""E:\\output.txt""; + BufferedReader input = new BufferedReader(new FileReader(inputPath)); + BufferedWriter output = new BufferedWriter(new FileWriter(outputPath)); + + String line; + line = input.readLine(); + int T = Integer.parseInt(line); + for (int i = 1; i <= T; ++i) { + line = input.readLine(); + String[] words = line.split("" ""); + int N = Integer.parseInt(words[0]); + int S = Integer.parseInt(words[1]); + int p = Integer.parseInt(words[2]); + int n = 0; + int res = 0; + + for (int j = 3; j < words.length; ++j) { + if (p == 0) { + res++; + continue; + } + + int t = Integer.parseInt(words[j]); + if (p == 1) { + if (t > 0) + res++; + continue; + } + if (t >= 3 * p - 2) + res++; + else if (t >= 3 * p - 4) + n++; + } + + res += Math.min(n, S); + output.write(""Case #"" + i + "": "" + res); + output.newLine(); + } + + input.close(); + output.close(); + } +} +" +A22395,"import java.io.*; +import java.util.*; +public class Dancing { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + for(int z=1; z<=t; z++) { + StringTokenizer st = new StringTokenizer(br.readLine(),"" ""); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int ans = 0; + int temp = 0; + int[] a = new int[n]; + for(int i=0; i(3*p-3)) ans++; + if(a[i]==(3*p-3)||a[i]==(3*p-4)) temp++; + } + if(temp>s) temp = s; + if(p==1) temp = 0; + System.out.println(""Case #""+z+"": ""+(ans+temp)); + } + } +} +" +A22162,"import java.util.*; +import java.io.*; +import java.text.*; +import java.math.*; + +public class DancingWithTheGooglers { + public static BufferedReader BR; + + public static String readLine() { + try { + return BR.readLine(); + } catch(Exception E) { + System.err.println(E.toString()); + return null; + } + } + + + // ****** MAIN ****** + + public static void main(String [] args) throws Exception { + BR = new BufferedReader(new InputStreamReader(System.in)); + + int testcases = Integer.parseInt(readLine()); + for (int t = 1; t <= testcases; t++) { + DancingWithTheGooglers instance = new DancingWithTheGooglers(); + instance.solve(t); + } + + } + + // ****** GLOBAL VARIABLES ****** + + + + public DancingWithTheGooglers() { + } + + public boolean solve(int caseNumber) { + StringTokenizer st = new StringTokenizer(readLine()); + int n = Integer.parseInt(st.nextToken()); + int s = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] totals = new int[n]; + for (int i = 0; i < n; ++i) { + totals[i] = Integer.parseInt(st.nextToken()); + } + int result = 0; + for (int i = 0; i < n; ++i) { + if ((totals[i]+2) / 3 >= p) { + ++result; + } else if (s > 0 && totals[i] >= 2 && (totals[i]-2)/3 + 2 >= p) { + ++result; + --s; + } + } + System.out.println(""Case #"" + caseNumber + "": "" + result); + return false; + } + + +} +" +A21908,"package test.qual; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.utility.FileReader; +import com.utility.FileWriterUtility; + +public class SpeakInTongues { + public static void main(String[] args) throws IOException { + BufferedReader inputBufReader = FileReader.getBufferedReader(""sample.txt""); + BufferedReader br = FileReader.getBufferedReader(""A-small-attempt1.in""); + BufferedWriter bw = FileWriterUtility.getBufferedWriter(""output.txt""); + + Map wordMap = getWordMap(inputBufReader); + + wordMap.put('y', 'a'); + wordMap.put('e', 'o'); + wordMap.put('z', 'q'); + + if (wordMap.keySet().size() == 25) { + List alphabets1 = new ArrayList(); + List alphabets2 = new ArrayList(); + for (int i = 0; i < 26; i++) { + alphabets1.add((char) ('a'+i)); + alphabets2.add((char) ('a'+i)); + } + + alphabets1.removeAll(wordMap.keySet()); + alphabets2.removeAll(wordMap.values()); + wordMap.put(alphabets1.get(0), alphabets2.get(0)); + } + + int n = Integer.valueOf(br.readLine()); + + for (int i = 0; i < n; i++) { + String input = br.readLine(); + char[] chars = input.toCharArray(); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(""Case #"" + (i+1) + "": ""); + + for (int j = 0; j < chars.length; j++) { + if (chars[j] == ' ') { + stringBuilder.append(' '); + } + else if (wordMap.get(chars[j]) != null) { + stringBuilder.append(wordMap.get(chars[j])); + } + else { + stringBuilder.append(chars[j]); + } + } + + bw.write(stringBuilder.toString()); + bw.newLine(); + } + bw.close(); + } + + private static Map getWordMap(BufferedReader inputBufReader) + throws IOException { + List input = new ArrayList(); + List output= new ArrayList(); + + for (int i = 0; i < 3; i++) { + String[] strArray = inputBufReader.readLine().split("" ""); + for (int j = 0; j < strArray.length; j++) { + char[] temp = strArray[j].toCharArray(); + for (int k = 0; k < temp.length; k++) { + input.add(temp[k]); + } + } + } + + for (int i = 0; i < 3; i++) { + String[] strArray = inputBufReader.readLine().split("" ""); + for (int j = 0; j < strArray.length; j++) { + char[] temp = strArray[j].toCharArray(); + for (int k = 0; k < temp.length; k++) { + output.add(temp[k]); + } + } + } + + if (input.size() != output.size()) { + throw new RuntimeException(""Invalid word mapping""); + } + + Map wordMapping = new HashMap(); + + for (int i = 0; i < input.size(); i++) { + wordMapping.put(input.get(i), output.get(i)); + } + return wordMapping; + } + + +// List alphabets1 = new ArrayList(); +// List alphabets2 = new ArrayList(); +// for (int i = 0; i < 26; i++) { +// alphabets1.add((char) ('a'+i)); +// alphabets2.add((char) ('a'+i)); +// } +// +// System.out.println(wordMapping.keySet().size()); +// alphabets1.removeAll(wordMapping.keySet()); +// alphabets2.removeAll(wordMapping.values()); +// System.out.println(); +// System.out.println('z' - 'a'); +} +" +A21175,"import java.io.*; +import java.util.*; + +class googledance { + public static void main (String [] args) throws IOException { + + BufferedReader f = new BufferedReader(new FileReader(""googledance.in"")); + + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""googledance.out""))); + + int n = Integer.parseInt(f.readLine()); + + String[] scores = new String[n]; + int[] answers = new int[n]; + + for(int i=0; i 0){ //balance out the deviations as closely as possible + breakdown[j][k]--; + } + else{ + breakdown[j][k]++; //good news, the breakdown is always sorted from inc->dec + } + + } + + } + + /*for(int k=0; k<3; k++){ + System.out.println(breakdown[j][k]); + }*/ + + } + + for(int j=0; j= threshold){ + answers[i]++; + succeeded[j] = true; + + break; + } + } + + } + + for(int j=0; j0){ + + if((breakdown[j][0]+2-breakdown[j][1] > 2) || (breakdown[j][0]+1>10) || (breakdown[j][1]-1<0)) //greater than 2 is an impossible surprise + continue; + + breakdown[j][1]--; + breakdown[j][0]++; + + numsurprises--; + } + + } + + for(int j=0; j= threshold){ + answers[i]++; + succeeded[j] = true; + + break; + } + } + + /*for(int k=0; k<3; k++){ + System.out.println(breakdown[j][k]); + }*/ + + } + + } + + for(int i=0; i input = ReadWriteTextFile.doReadTextFile(""B-large.in""); + ArrayList output = new ArrayList(); + + int n = Integer.parseInt(input.get(0)); + for (int i=1;i<=n;i++) { + System.out.println(""Case#: "" + i + "" ""); + output.add(Integer.toString(FindNumber.start(input.get(i)))); + } + + ReadWriteTextFile.doWriteTextFile(output); + } + +}" +A22470,"package qualifier; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + + +public class B { + public static void main(String args[]) throws IOException { + Scanner in = new Scanner(new File(""B-large.in"")); + PrintStream out = new PrintStream(new File(""B-large.out"")); + int tc = in.nextInt(); + + for(int c=1; c<=tc; c++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int ct = 0; + + int d; + for(int i=0; i= (p*3)-2) { + ct++; + } else if(d >= (p*3)-4 && s > 0) { + s--; + ct++; + } + } + + out.printf(""Case #%d: %d\n"", c, ct); + } + } +} +" +A21575,"import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + + +public class LaDanceGoogler { + + public static void main(String[] args) throws IOException { + Path input = Paths.get(""/Users/mdymczyk/google-codejam/Tongues/src/input.in""); + List lines = Files.readAllLines(input, Charset.forName(""UTF-8"")); + lines.remove(0); + int i = 1; + for(String line : lines) { + StringBuilder sb = new StringBuilder(); + sb.append(""Case #""+i+"": ""); + String[] numbers = line.split("" ""); + int specials = Integer.parseInt(numbers[1]); + int searchedValue = Integer.parseInt(numbers[2]); + int results = 0; + for(int j = 3 ; j < numbers.length ; j++) { + int score = Integer.parseInt(numbers[j]); + for(int s = searchedValue ; s <= 10 ; s++){ + int rest = score-s; + if(rest-2*s == 0 || + (rest-2*s+1 == 0 && score-1 >= 0) || + (rest-2*s+2 == 0 && score-1 >= 0)) { + results++; + break; + } else if(specials > 0 && ((rest-2*s+3 == 0 && score-1 >= 0) || + (rest-2*s+4 == 0 && score-2 >= 0))) { + results++; + specials--; + break; + } + } + } + sb.append(results); + System.out.println(sb); + i++; + } + } + +} +" +A22613,"import java.io.*; +import java.util.*; +import java.math.*; +/** @author Samuel Ahn */ + +public class B { + public static void main(String args[]) throws Exception { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for (int i = 1; i <= T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] array = new int[N]; + for (int j = 0; j < N; j++) { + array[j] = in.nextInt(); + } + Arrays.sort(array); + int sum = 0; + for (int j = 0; j < N; j++) { + int temp = array[j]; + if ((temp == 0)) { + if (temp >= p) { + sum++; + } + } else if ((temp == 1)) { + if (temp >= p) { + sum++; + } + } else { + if (S > 0) { + if (((temp + 4) / 3) >= p) { + sum++; + S--; + } + } else { + if (((temp + 2) / 3) >= p) { + sum++; + } + } + } + } + System.out.printf(""Case #%d: %d\n"", i, sum); + } + } +}" +A20139,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Scanner; + +public class Problem2 { + public static void main(String[] args) throws FileNotFoundException { + + String inputFile = ""B-large.in""; + Scanner inputScanner = new Scanner(new FileInputStream(""d:\\input\\"" + + inputFile)); + PrintStream ps = new PrintStream(new FileOutputStream( + ""d:\\output\\pro2.txt"")); + int totalCaseNum = inputScanner.nextInt(); + inputScanner.nextLine(); + // ----------------------------------------------- + + // ----------------------------------------------- + for (int caseNum = 1; caseNum <= totalCaseNum; caseNum++) { + String line = inputScanner.nextLine(); + String prefix = ""Case #"" + caseNum + "": ""; + StringBuilder output = new StringBuilder(prefix); + // ----------------------------------------------- + + Scanner in = new Scanner(line); + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + int[] T = new int[N]; + + int count = 0; + + if (0 == P) { + count = N; + } else { + int minScore = Math.max(0, (P - 2)) * 2 + P; + int maxScore = Math.max(0, (P - 1) * 3); + for (int i = 0; i < T.length; i++) { + int ti = in.nextInt(); + if (ti > maxScore) { + count++; + continue; + } + if (ti < minScore) { + continue; + } + if (S > 0 && 2 <= ti && ti <= 28) { + count++; + S--; + } + + } + } + output.append(count); + // ----------------------------------------------- + System.out.println(output); + ps.println(output); + } + } +} +" +A20779,"/** + * + */ +package me.adrabi.codejam; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Adrabi Abderrahim, z3vil + * + */ +public class P2 +{ + + private static int SURPRISING = 0; + + public static void main(String[]$) throws NumberFormatException, IOException + { + List dancers = new ArrayList(); + { + BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(""p2""))); + int count = Integer.parseInt(reader.readLine()); + + String line = null; + while((line = reader.readLine()) != null) + { + dancers.add(line); + } + } + + int currentLine = 1; + for(String line : dancers) + { + String elements[] = line.split("" ""); + // 0 - number of dancers + // 1 - Surprise + // 2 - score + final int score = Integer.parseInt(elements[2]); + + int currentScoreAccepted = 0; + + //System.out.print(line+ ""\t\t""); + + for(int index = 3 ; index < elements.length; index++) + { + int surp = Integer.parseInt(elements[1]); + int scorces[] = calcNumber(Integer.parseInt(elements[index]) , surp > 0 && surp > SURPRISING, score); + for(int tmp : scorces) + { + if(tmp >= score) + { + currentScoreAccepted++; + break; + } + } + } + + SURPRISING = 0; + System.out.printf(""Case #%d: %d\n"", currentLine++ , currentScoreAccepted, score); + } + } + + public static int[] calcNumber(int number, boolean isSuprising, int score) + { + + if(number == 0) + { + return new int[]{0, 0, 0}; + } + else + { + int pass = 0; + boolean change = false; + while((pass < 3 || !change) || (pass > -3 && change)) + { + int part1 = -1; + int part2 = -1; + int part3 = -1; + + if(number > 3) + { + part1 = number/2 - (isSuprising? ( number % 2 == 0 ? 2 : 1) : 0); + part2 = part1/2 - pass; + part3 = -1; + + if(part1 + part2 > 20) + { + part2 = 20 - part1; + } + else if((part1 + part2) % 2 == 1) + { + part2--; + } + part1 += part2; + for(int bruteForce = 10; bruteForce > 0; bruteForce--) + { + int tmp = Math.abs((part1/2) - bruteForce); + boolean active = false; + if(part1 + bruteForce == number && (tmp == 1 || tmp == 0 || ( tmp == 2 && (active = isSuprising)))) + { + if(active) + { + SURPRISING++; + } + part3 = bruteForce; + break; + } + } + } + else + { + part1 = part2 = part3 = 0; + change = true; + pass = -4; + } + + if(part3 > -1) + { + int x = part1/2, y = part1/2, z = part3; + + if(number == 1) + { + x = 1; + y = 0; + z = 0; + } + else if(number == 2) + { + x = 1; + y = 1; + z = 0; + } + else if(number == 3) + { + x = 1; + y = 1; + z = 1; + } + + if( (x < score && y < score && z < score) && isSuprising) + { + if(z + 1 <= 10 && z + 1 >= score) + { + if( x - 1 < y && y < z + 1 && Math.abs((x - 1) - y) <= 1 && Math.abs((x-1) - (z+1)) <= 2) + { + SURPRISING++; + //System.out.printf(""(%d, %d, %d)"", x -1 , y, z + 1); + return new int[]{x -1 , y, z + 1}; + } + else if( y - 1 < x && x < z + 1 && Math.abs(x - (y-1)) <= 1 && Math.abs((z+1) - (y-1)) <= 2) + { + SURPRISING++; + //System.out.printf(""(%d, %d, %d)"", x , y - 1, z + 1); + return new int[]{x , y - 1, z + 1}; + } + else + { + //System.out.printf(""(%d, %d, %d)"", x , y, z); + return new int[]{ x , y, z}; + } + } + else if(z + 2 <= 10 && z + 2 >= score && x == y && Math.abs((z + 2) - (y - 1)) == 2) + { + SURPRISING++; + //System.out.printf(""(%d, %d, %d)"", x - 1 , y - 1, z + 2); + return new int[]{x + 1 , y - 1, z + 2}; + } + else + { + //System.out.printf(""(%d, %d, %d)"", x, y, z); + return new int[]{ x , y, z}; + } + } + else + { + //System.out.printf(""(%d, %d, %d)"", x, y, z); + return new int[]{ x , y, z}; + } + } + else + { + if(change) + { + pass--; + } + else + { + pass++; + } + if(pass >= 3) + { + change = true; + pass = -1; + } + } + } + } + return new int[]{ -1 , -1, -1}; + } +} +" +A22241,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class B { + + public String solve(int N, int S, int p, int[] t) { + int cnt = 0; + int p1 = Math.max(3*p-2, p); + int p2 = Math.max(3*p-4, p); + for (int i=0; i= p1) { + cnt ++; + } else if (t[i] >= p2) { + if (S > 0) { + S --; + cnt ++; + } + } + } + return Integer.toString(cnt) + ""\n""; + } + + //////////////////////////////////////// + // read input + //////////////////////////////////////// + public String runInput(BufferedReader br) throws IOException { + String[] items = br.readLine().trim().split(""\\s+""); + int idx = 0; + int N = Integer.parseInt(items[idx++]); + int S = Integer.parseInt(items[idx++]); + int p = Integer.parseInt(items[idx++]); + int[] t = new int[N]; + for (int i=0; i 0) { + if (remainder == 1) { + bestResult = singleScore + 1; + } else if (remainder == 2) { + bestResult = singleScore + 1; + if (bestResult + 1 == minResult && surprisingResults > 0) { + surprisingResults--; + bestResult++; + } + } else if (remainder == 0) { + bestResult = singleScore; + if (bestResult + 1 == minResult && surprisingResults > 0) { + surprisingResults--; + bestResult++; + } + + } + } + if (bestResult >= minResult) dancersWithMinResult++; + } + + write(run+1, String.valueOf(dancersWithMinResult)); + } + } + + // ===================================================================================== + // File Access + // ===================================================================================== + + private String readLine() { + try { + return br.readLine(); + } catch (IOException e) { + throw new IllegalStateException(); + } + } + + private void write(int caseNumber, String result) { + pw.println(""Case #""+caseNumber+"": ""+result); + } + + private void loadFile(String fileName) { + File inFile = new File(this.getClass().getResource(fileName).getFile()); + File outFile = new File(inFile.getAbsolutePath().substring(0, (int)(inFile.getAbsolutePath().length()-2L))+""out""); + outFile.delete(); + try { + outFile.createNewFile(); + br = new BufferedReader(new InputStreamReader(new FileInputStream(inFile))); + pw = new PrintWriter(new FileOutputStream(outFile)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // ===================================================================================== + // Initialisation / cleanup + // ===================================================================================== + + public static void main(String[] args) throws InterruptedException { + System.out.println(""Running...""); + startTime = System.currentTimeMillis(); + + Thread thread = new Thread(new Blarge()); + thread.start(); + + while (thread.isAlive()) { + Thread.sleep(UPDATE_INTERVAL_MILLIS); + updateTime(); + } + + endTime = System.currentTimeMillis(); + System.out.println(""Finished after ""+(endTime-startTime)+"" ms""); + } + + private static void updateTime() { + currTime = System.currentTimeMillis(); + float timePerRun; + if (run > 0) + timePerRun = (currTime-startTime) / run; + else + timePerRun = 0; + float timeLeft = timePerRun * (totalNumberOfRuns - run); + + System.out.println(""Runs passed: "" + run); + System.out.println(""Estimated time left: ""+timeLeft+"" ms""); + + } + + @Override + public void run() { + loadFile(fileName); + solve(); + cleanUp(); + } + + private void cleanUp() { + try { + pw.flush(); + pw.close(); + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}" +A21311,"import java.io.*; +import java.util.*; + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + Kattio io = new Kattio(System.in, new FileOutputStream(""dance.out"")); + int T = io.getInt(); + for (int test = 1; test <= T; test++) { + int N = io.getInt(); + int S = io.getInt(); + int p = io.getInt(); + int res = 0; + for (int i = 0; i < N; i++) { + int t = io.getInt(); + int h = t/3; + boolean surprise = t >= 2 && t <= 28; + if (t % 3 != 0) h++; + if (h >= p) { + res++; + } else if (surprise && h+1 >= p && S > 0 && t%3 != 1) { + res++; + S--; + } + } + io.println(""Case #""+test+"": ""+res); + } + io.close(); + } + + static class Kattio extends PrintWriter { + public Kattio(InputStream i) { + super(new BufferedOutputStream(System.out)); + r = new BufferedReader(new InputStreamReader(i)); + } + public Kattio(InputStream i, OutputStream o) { + super(new BufferedOutputStream(o)); + r = new BufferedReader(new InputStreamReader(i)); + } + + public boolean hasMoreTokens() { + return peekToken() != null; + } + + public int getInt() { + return Integer.parseInt(nextToken()); + } + + public double getDouble() { + return Double.parseDouble(nextToken()); + } + + public long getLong() { + return Long.parseLong(nextToken()); + } + + public String getWord() { + return nextToken(); + } + + private BufferedReader r; + private String line; + private StringTokenizer st; + private String token; + + private String peekToken() { + if (token == null) + try { + while (st == null || !st.hasMoreTokens()) { + line = r.readLine(); + if (line == null) return null; + st = new StringTokenizer(line); + } + token = st.nextToken(); + } catch (IOException e) { } + return token; + } + + private String nextToken() { + String ans = peekToken(); + token = null; + return ans; + } + } +}" +A22060,"import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.util.Scanner; +import java.util.Set; + + +public class ProblemB { + + /** + * @param args + * Ahmed Kammorah + */ +public static void main(String[] args) { + + ProblemB problem=new ProblemB(); + + problem.MainAlgorithm(); + problem.closeFiles(); + } + + ReadFile readFile; + writeOutputFile writeOutputFile; + + public ProblemB() { + + //readFile=new ReadFile(""B-small-attempt0.in""); + //writeOutputFile = new writeOutputFile(""B-small.out""); + + readFile=new ReadFile(""B-large.in""); + writeOutputFile = new writeOutputFile(""B-large.out""); + } + + + + + void MainAlgorithm(){ + + + int N= Integer.parseInt(readFile.readNextLineScan()); + + + int a=0,b=0,c=0; + + for(int i=1; i <=N ; i++){ + int NumGoogler=readFile.readNextIntScan(); + int S=readFile.readNextIntScan(); + + int P=readFile.readNextIntScan(); + int maxG=0; + for(int j=1 ; j <= NumGoogler ; j++){ + int GScore = readFile.readNextIntScan(); + + + a=GScore/3; + b=(GScore-a)/2; + c=GScore-(a+b); + if(a

0 && c >= P && ( (a<=10 && a>=0) && (b<=10 && b>=0) && (c<=10&&c>=0) )){ + //System.out.println(""( ""+c+"" )""+P); + //S--; + }else{ + a=GScore/3; + b=(GScore-a)/2; + c=GScore-(a+b); + } + } + + + + + + //System.out.println(""( ""+a+"" , ""+b+"" , ""+c+"" )""); + if(a >= P || b >= P || c >= P){ + maxG++; + } + + if(Math.abs(a-b)==2 || Math.abs(a-c)==2 || Math.abs(b-c)==2){ + S--; + } + + } + + writeOutputFile.writeLineToOut(""Case #"" + i +"": ""+maxG+""\n""); + + } + + + + } + + + public void closeFiles(){ + readFile.closeFile(); + writeOutputFile.closeOutFile(); + } + + +}// end problem class + + + + + +class writeOutputFile { + + BufferedWriter dataOut; + FileWriter fileOut; + public writeOutputFile(String fileOutput) { + try { + + //File file= new File(getClass().getResourceAsStream(fileOutput).toString()); + fileOut =new FileWriter(fileOutput); + dataOut = new BufferedWriter(fileOut); + + } catch (IOException e) { + System.out.println("" constractor out file ...""); + e.printStackTrace(); + } + + } + + public void writeLineToOut(String line){ + try { + dataOut.write(line); + + + } catch (IOException e) { + System.out.println("" write out file ...""); + e.printStackTrace(); + } + } + + + + public void closeOutFile(){ + + try { + dataOut.close(); + fileOut.close(); + } catch (IOException e) { + System.out.println("" close out file ...""); + e.printStackTrace(); + } + } + + + } + + + + + + +class ReadFile { + + //InputStream fileStream; + //DataInputStream data; + Scanner scanner; + + + public ReadFile(String fileName) { + + scanner = new Scanner(getClass().getResourceAsStream(fileName)); + + } + + + + + public int readNextIntScan(){ + + return scanner.nextInt(); + + } + + public char readNextChar(){ + return (char)scanner.nextByte(); + } + + public String readNextLineScan(){ + return scanner.nextLine(); + } + + + public void closeFile(){ + scanner.close(); + + } + + +} + +" +A20650,"import java.util.Arrays; +import java.util.Scanner; + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner reader = new Scanner(System.in); + int T = reader.nextInt(); + for(int tc = 1 ; tc <= T ; tc++ ) { + int N = reader.nextInt(); + int S = reader.nextInt(); + int p = reader.nextInt(); + int [] arr = new int[N]; + for(int i = 0 ; i < N ; i ++) { + arr[i] = reader.nextInt(); + } + int res = doit(arr, S, p); + System.out.printf(""Case #%d: %d\n"", tc, res); + } + } + + private static int doit(int[] arr, int s, int p) { + int n = arr.length; + Triplet[] ts = new Triplet[n]; + for(int i = 0 ; i < n ; i ++) { + ts[i] = new Triplet(arr[i]); + } + Arrays.sort(ts); + int count = 0; + for(int i = 0 ; i < arr.length; i ++) { + if ( ts[i].max >= p) { + count ++; +// System.out.println(ts[i].total + "" used""); + continue; + } + if( s > 0 && ts[i].surprisingMax >= p) { + s--; + count ++; +// System.out.println(ts[i].total + "" used""); + continue; + } +// System.out.println(ts[i].total + "" "" + s + p); + } + return count; + } +} + +class Triplet implements Comparable { + int total; + int max; + int surprisingMax; + public Triplet(int total) { + this.total = total; + initialize(); + } + private void initialize() { + int avg = total / 3; + int remaining = total % 3; + int a[] = new int[3]; + a[0] = avg; + a[1] = avg; + a[2] = avg; + if(remaining > 0) { + a[0]++; + } + if(remaining > 1) { + a[1]++; + } + this.max = a[0]; + switch(remaining) { + case 0: + case 2: + this.surprisingMax = a[0] + (a[1] > 0 ? 1 : 0); + break; + case 1: + this.surprisingMax = -1; + break; + } +// System.out.println(""total: "" + total + "" max: "" + max + "" remaining: "" + remaining + "" surp max: "" + surprisingMax); + } + @Override + public int compareTo(Triplet o) { + if(o.total != total) { + return o.total - total; + } + if(o.max != max) { + return o.max - max; + } + return o.surprisingMax - surprisingMax; + } +} +" +A20087,"package se.round1.problem2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import se.round1.util.JamUtil; + +public class Problem2 { + + Map trans = new HashMap(); + + public static void main(String[] args) throws IOException{ + new Problem2(); + } + + public Problem2() throws IOException{ + + BufferedReader reader = JamUtil.getReader(""problem2/B-large.in""); + + int currCase = 0; + String s = """"; + boolean first = true; + BufferedWriter writer = JamUtil.getWriter(""problem2/output.txt""); + while((s = reader.readLine()) != null){ + if(first){ + s = reader.readLine(); + first = false; + } + currCase++; + int res = solveLine(s); + String sol = ""Case #""+currCase+"": ""+res+""\n""; + System.out.print(sol); + + writer.write(sol); + } + writer.close(); + } + + + private int solveLine(String line){ + String[] linearr = line.split("" ""); + int dancers = Integer.parseInt(linearr[0]); + int surprice = Integer.parseInt(linearr[1]); + int scoreToReach = Integer.parseInt(linearr[2]); + int success = 0; + for(int i=0;i= scoreToReach){ + success++; + } + else if( surprice > 0 && (maxScore+1) >= scoreToReach && score >= 2 && ( (3*maxScore) -1) <= score){ + success++; + surprice--; + } + } + + return success; + } + + private int canReachScoreWithoutSurprice(int score){ + if(score == 0) + return 0; + if(score == 1) + return 1; + if(score == 2) + return 1; + if(score == 3) + return 1; + + int test = score / 3; + + while( 3*(test)+1 > score){ + test--; + } + + if(test <=0) + return 0; + return test+1; + } + + + +} +" +A20692,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +public class DancingWithTheGooglers { + private DancingWithTheGooglers() { + } + + public void solveInput(final InputStream input, final OutputStream output) + throws IOException { + + final BufferedReader reader = new BufferedReader(new InputStreamReader( + input)); + final BufferedWriter writer = new BufferedWriter( + new OutputStreamWriter(output)); + + final int numTestCase = Integer.valueOf(reader.readLine().trim()); + + System.out.println(""Total Test Cases: "" + numTestCase); + + String line = null; + int caseNo = 1; + while ((line = reader.readLine()) != null) { + final String[] words = line.trim().split("" ""); + final int N = Integer.parseInt(words[0]); + final int S = Integer.parseInt(words[1]); + final int P = Integer.parseInt(words[2]); + final int[] scores = new int[N]; + for (int i = 0; i < N; i++) { + scores[i] = Integer.parseInt(words[3 + i]); + } + int Y = 0; + int nS = S; + + for (int i = 0; i < N; i++) { + final int score = scores[i]; + final int avg = score / 3; + if (avg >= P) { + Y++; + continue; + } + + final int[] triplets = new int[] { avg, avg, avg }; + final int remainder = score % 3; + + if (remainder > 0) { + if ((avg + 1) >= P) { + Y++; + continue; + } else if (avg + remainder >= P && nS > 0) { + Y++; + nS--; + continue; + } + } + if (triplets[1] > 0) { + ++triplets[0]; + --triplets[1]; + if (triplets[0] >= P && nS > 0) { + Y++; + nS--; + continue; + } + } else if (triplets[2] > 0) { + ++triplets[0]; + --triplets[2]; + if (triplets[0] >= P && nS > 0) { + Y++; + nS--; + continue; + } + } + } + + if (caseNo > 1) { + writer.write(""\n""); + } + final String text = ""Case #"" + (caseNo++) + "": "" + (Y); + System.out.println(text); + writer.write(text); + writer.flush(); + } + writer.close(); + reader.close(); + } + + /** + * @param args + */ + public static void main(final String[] args) throws Exception { + final DancingWithTheGooglers dancing = new DancingWithTheGooglers(); + + final File outputFile = new File(""output/B-large.out""); + if (outputFile.exists()) { + outputFile.delete(); + } + final FileOutputStream fos = new FileOutputStream(outputFile); + + dancing.solveInput( + SpeakingInTongues.class.getResourceAsStream(""B-large.in""), fos); + + } +} +" +A21765,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + + + +public class FileOut { + + /** + * コンストラクタ. + * @param filename 書き出すファイル名 + * @param s 書き出す文字列 + */ + public FileOut(String filename, String s) { + File f = new File(filename); + FileWriter fw = null; + try { + fw = new FileWriter(f); + fw.write(s); + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + } + + +}" +A20897,"package CodeJam; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class B { + + /** + * @param args + */ + static Scanner scan = new Scanner(System.in); + static BufferedReader brscan = new BufferedReader(new InputStreamReader(System.in)); + static PrintWriter pw ; + static ArrayList arrTriplet = new ArrayList(1000); + public static void main(String[] args) throws NumberFormatException, IOException { + pw = new PrintWriter(""output-B.txt""); + // TODO Auto-generated method stub + + + + int tc = scan.nextInt(); + + + int googler, surprise, minscore; + for (int x=1; x<=tc; x++) { + arrTriplet.clear(); + googler = scan.nextInt(); + surprise = scan.nextInt(); + minscore = scan.nextInt(); + + for (int n = 0; n=minscore) { + pass++; + } else if (surprise>0){ + if (now.x == now.y && now.y == now.z) { + if (now.x+1>=minscore && now.y>0) { + pass++; + surprise--; + } + } else if (now.x == now.y) { + if (now.x+1>=minscore && now.y>0) { + pass++; + surprise--; + } + } + + } + + } + //debug(); + pw.println(""Case #""+x+"": ""+pass); + } + pw.flush(); + pw.close(); + } + + public static void debug() { + for (int n=0; n { + int x, y, z; + public Triplet(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + @Override + public int compareTo(Triplet o) { + // TODO Auto-generated method stub + if (this.x!=o.x) { + return o.x-this.x; + } + if (this.y!=o.y) { + return o.y-this.y; + } + + if (this.z!=o.z) { + return o.z-this.z; + } + return 0; + } + + public int getMax() { + if (x>=y && x>=z) { + return x; + } + if (y>=x && y>=z) { + return y; + } + return z; + } + + public int getMin() { + if (x<=y && x<=z) { + return x; + } + if (y<=z && y<=x) { + return y; + } + return z; + } + + public String toString() { + return ""[""+x+"",""+y+"",""+z+""]""; + } + +}" +A21182,"/** + * Copyright 2012 Christopher Schmitz. All Rights Reserved. + */ + +package com.isotopeent.codejam.lib.converters; + +import com.isotopeent.codejam.lib.InputConverter; + +public class MultiLineConverter implements InputConverter { + + private InputConverter[] converters; + private int count; + + private Object[] input; + private int lineNumber; + + public MultiLineConverter(InputConverter lineConverter, int count) { + this.converters = new InputConverter[count]; + this.count = count; + for (int i = 0; i < count; i++) { + converters[i] = lineConverter; + } + } + + public MultiLineConverter(InputConverter[] lineConverters) { + this.converters = lineConverters; + this.count = lineConverters.length; + } + + @Override + public boolean readLine(String data) { + if (lineNumber == 0) { + input = new Object[count]; + } + InputConverter converter = converters[lineNumber]; + if (!converter.readLine(data)) { + input[lineNumber++] = converter.generateObject(); + } + + if (lineNumber >= input.length){ + lineNumber = 0; + } + return lineNumber != 0; + } + + @Override + public Object[] generateObject() { + return input; + } + +} +" +A22840,"import java.io.*; +import java.util.*; + +public class DancingWithTheGooglers { + + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static StringTokenizer st; + + public static void main ( String [] args ) throws IOException + { + int T = Integer.parseInt(br.readLine()); + + for(int i = 0;i < T; i++) { + System.out.print(""Case #"" + (i+1) + "": ""); + new DancingWithTheGooglers().cal(); + } + } + + + private void cal() throws IOException + { + int N, S, p; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + + int [] t = new int [N]; + for(int i = 0; st.hasMoreTokens(); i++) + t[i] = Integer.parseInt(st.nextToken()); + + /* + for(int i : t) + System.out.println(i); + */ + + int num = 0; + for(int n : t) { + int q = n / 3; + int r = n % 3; + + // System.out.println(q + "" "" + r); + + + if ( r == 0 && q >= p) { + num++; + } else if ( r == 0 && q != 10 && q != 0 && q + 1 >= p && S > 0 ) { + num++; S--; + } + else if ( r == 1 && q + 1 >= p) { + num++; + } else if ( r == 2 && q + 1 >= p) { + num++; + } else if ( r == 2 && q + 2 >= p && S > 0) { + num++; S--; + } + + } + + System.out.println(num); + + } + +} +" +A20175,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Googlers { + + public static void main(String args[]) throws IOException { + int num = 0; + int N = 0; + int number = 1; + + int S = 0; + int P = 0; + String[] a = new String[103]; + + FileInputStream fstream = new FileInputStream(""d:/B-large.in""); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + String readLine; + readLine = br.readLine(); + + num = Integer.valueOf(readLine); + // System.out.println(num); + + FileWriter fstreamw = new FileWriter(""d:/B-large.out""); + BufferedWriter out = new BufferedWriter(fstreamw); + + while ((readLine = br.readLine()) != null) { + int[] b = new int[100]; + a = new String[103]; + int count = 0; + a = readLine.split("" ""); + N = Integer.valueOf(a[0]); + S = Integer.valueOf(a[1]); + P = Integer.valueOf(a[2]); + for (int i = 0; i < N; i++) { + b[i] = Integer.valueOf(a[i + 3]); + // System.out.println(b[i]); + } + for (int i = 0; i < N; i++) { + if(P==0){ + count++; + }else if((P>0)&&(b[i] - P)>=0){ + + + float temp = b[i] - P - P + 1; + int normal = P - 1; + int surprise = P - 3; + if(temp>=normal){ + count++; + }else if((temp>=surprise)&&(S>0)){ + S--; + count++; + } + } + + } + + out.write(""Case #""); + out.write(String.valueOf(number)); + out.write("": ""); + out.write(String.valueOf(count)); + out.write(""\r\n""); + number++; + + // System.out.println(""count="" + count); + // System.out.println(-1 / 2.0f); + } + + out.close(); + } +} +" +A20265,"import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class B { + + int ref; + + int[] scores = new int[3]; + + int max1=0; + + int max2=0; + + + public B(int ref, int suma) { + super(); + this.ref = ref; + scores[0] = suma/3; + suma-=scores[0]; + scores[1] = suma/2; + scores[2] = suma-scores[1]; + max1 = scores[2]>=ref?1:0; + if (suma>=2 && suma <= 28) + max2 = (scores[2]+1)>=ref?1:0; + else + max2=-1; + //System.out.println(Arrays.toString(scores)); + /*if(ref==scores[0]) + max2--; + if(scores[1]>=ref) + max2++; + if((scores[2]+1)>=ref) + max2++; + int tmpMax = 0; + if(ref==scores[0]) + tmpMax--; + if(scores[1]+1>=ref) + tmpMax++; + if((scores[2])>=ref) + tmpMax++; + if(tmpMax>max2) + max2=tmpMax; + */ + } + + + + public static void main(String[] args) throws Exception{ + Scanner sc = new Scanner(new File(""B-large.in"")); + PrintWriter pw = new PrintWriter(new File(""B-large.out"")); + int cases = sc.nextInt(); + for (int i = 0; i < cases; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int ref = sc.nextInt(); + B[] scores = new B[n]; + boolean[] excep = new boolean[n]; + for (int j = 0; j < n; j++) { + scores[j] = new B(ref,sc.nextInt()); + } + for (int j = 0; j < s; j++) { + int max = -10; + int index = -1; + for (int k = 0; k < excep.length; k++) { + if(excep[k]) + continue; + if(scores[k].max2-scores[k].max1 > max){ + max = scores[k].max2-scores[k].max1; + index = k; + } + } + excep[index]=true; + } + int res=0; + for (int j = 0; j < excep.length; j++) { + if(excep[j]) + res+=scores[j].max2; + else + res+=scores[j].max1; + } + //System.out.println(Arrays.toString(excep)); + pw.println(""Case #""+(int)(i+1)+"": ""+res); + + } + pw.close(); + } + + +} +" +A20685,"import java.io.BufferedReader; +import java.io.FileReader; + + +public class DancingTest { + + public static void main(String[] args) { + int numCase = 0; + int caseIndex = 0; + int[] numGooglers = null; + int[] numSurprises = null; + int[] bestResult = null; + int[][] scores = null; + int maxNumScores = 100; + + try { + FileReader reader = new FileReader(""C:\\Users\\CheeMeng\\Downloads\\B-large.in""); + BufferedReader br = new BufferedReader(reader); + String s = br.readLine(); + numCase = new Integer(s).intValue(); + numGooglers = new int[numCase]; + numSurprises = new int[numCase]; + bestResult = new int[numCase]; + scores = new int[numCase][maxNumScores]; + while((s = br.readLine()) != null) { + String s1[] = s.split("" ""); + numGooglers[caseIndex] = new Integer(s1[0]).intValue(); + numSurprises[caseIndex] = new Integer(s1[1]).intValue(); + bestResult[caseIndex] = new Integer(s1[2]).intValue(); + for (int i = 3; i < s1.length; i++) { + scores[caseIndex][i - 3] = new Integer(s1[i]).intValue(); + } + caseIndex++; + } + reader.close(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + for (int i = 1; i <= numCase; i++) { + System.out.println(""Case #"" + i + "": "" + dancingTest(numGooglers[i - 1], numSurprises[i - 1], bestResult[i - 1], scores[i - 1])); + } + } + + public static int dancingTest(int numGooglers, int numSurprises, int bestResult, int[] scores) { + int count = 0; + int nearMisses = 0; + for (int i = 0; i < numGooglers; i++) { + int best = 0; + if ((scores[i] % 3) == 0) { + // Assume scores are (x, x, x), so best score will be the average + best = scores[i] / 3; + // Specially consider the case where scores are (x - 1, x, x + 1) + if ((best == bestResult - 1) && (best >= 1) && (best <= 9)) { + nearMisses++; + } + } + else if ((scores[i] % 3) == 2) { + // Assume scores are (x - 1, x, x), so best score will be the average + best = (scores[i] + 1) / 3; + // Specially consider the case where scores are (x - 1, x - 1, x + 1) + if ((best == bestResult - 1) && (best >= 1) && (best <= 9)) { + nearMisses++; + } + } + else if ((scores[i] % 3) == 1) { + // Scores will be either (x - 1, x - 1, x) or (x - 2, x, x) + // doesn't matter if any of them is marked surprising + best = (scores[i] + 2) / 3; + } + if (best >= bestResult) { + count++; + } + } + + count = count + Math.min(nearMisses, numSurprises); + return count; + } +} +" +A21591,"import java.util.Scanner; + + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int numTestCases = Integer.valueOf(scanner.nextLine()); + for ( int i =0; i < numTestCases; i++ ) { + String theCase = scanner.nextLine(); + Scanner lineScanner = new Scanner(theCase); + int numGooglers = lineScanner.nextInt(); + int surprises = lineScanner.nextInt(); + int p = lineScanner.nextInt(); + int minNotSuprising = getMinNotSurprising(p); + int minSurprising = getMinSurprising(p); + int count = 0; + for ( int j =0; j < numGooglers; j++ ) { + int totalScore = lineScanner.nextInt(); + if ( totalScore >= minNotSuprising ) { + count++; + } else if (totalScore >= minSurprising && surprises > 0) { + surprises--; + count++; + } + } + StringBuilder builder = new StringBuilder(""Case #""); + builder.append(i+1).append("": ""); + builder.append(count); + System.out.println(builder.toString()); + } + + } + + private static int getMinSurprising(int p) { + return p + (p-2 < 0 ? 0 : p-2)*2; + } + + private static int getMinNotSurprising(int p) { + return p + (p-1 < 0 ? 0 : p-1)*2; + } + +} +" +A20088,"package se.round1.util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +public class JamUtil { + + public static BufferedReader getReader(String path) + { + File file = new File(path); + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + BufferedReader bf = new BufferedReader(new InputStreamReader(fis)); + + return bf; + } + + public static BufferedWriter getWriter(String path) { + try { + return new BufferedWriter(new FileWriter(path)); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} +" +A20635,"import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +public class B { + static int getMaxNumberTodlers(String input){ + String[] inputs=input.split("" ""); + int T=Integer.parseInt(inputs[0]); + int S=Integer.parseInt(inputs[1]); + int p=Integer.parseInt(inputs[2]); + int results[]=new int[T]; + for (int i=0;i=min) + br++; + else if (results[i]>=minSup&&S>0){ + br++; + S--; + } + return br; + } + + public static void main(String[] args) throws NumberFormatException, IOException{ + + FileInputStream fstream = new FileInputStream(""problemB.txt""); + + // Convert our input stream to a + // DataInputStream + DataInputStream in = new DataInputStream(fstream); + FileOutputStream out; // declare a file output object + PrintStream p; // declare a print stream object + out = new FileOutputStream(""problemBout.txt""); + p = new PrintStream( out ); + int n=Integer.parseInt(in.readLine()); + for (int i=0;i lines; + private int numOfIntersections; + + public WiresCase(int order, int numberOfLines, IO io) { + super(order, numberOfLines, io); + } + + @Override + public void initializeVars() { + lines = new ArrayList(); + } + + @Override + public void addLine(String line) { + String[] tmp = line.split("" ""); + Short[] tmp2 = { Short.parseShort(tmp[0]), Short.parseShort(tmp[1]) }; + this.lines.add(tmp2); + } + + @Override + public void printSolution() { + System.err.println(""Case #"" + getOrder() + "": "" + numOfIntersections); + } + + @Override + public CaseSolver process() { + Collections.sort(lines, new Comparator() { + @Override + public int compare(Short[] o1, Short[] o2) { + return o1[0] - o2[0]; + } + }); + //printList(); + + + for (int i = 0; i < lines.size(); i++) { + for (int j = i + 1; j < lines.size(); j++) { + if (lines.get(i)[1] > lines.get(j)[1]) { + numOfIntersections++; + } + } + } + + return this; + } + + private void printList() { + for (Short[] a : lines) { + System.err.println(Arrays.deepToString(a)); + } + } +}" +A20033,"package com.code; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.Writer; + +public class ReadWriteInputFile +{ + public BufferedReader readInputFile(String filePath) + { + try + { + FileInputStream fstream = new FileInputStream(filePath); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + return br; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public Writer writeOutputFile(String filePath) + { + try + { + File file = new File(filePath); + Writer outWriter = new BufferedWriter(new FileWriter(file)); + return outWriter; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + + } + + public void closeObjects(Writer outWriter) + { + try + { + outWriter.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + +} +" +A20415,"package Parser; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; + +public class MyWriter { + Writer out; + + public MyWriter(String fileName) { + // TODO Auto-generated constructor stub + try { + File file = new File(fileName); + FileOutputStream fos; + fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos); + out = new BufferedWriter(osw); + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void writeString(String text) { + try { + out.write(text + '\n'); + } catch (IOException e) { + } + } + + public void close(){ + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} +" +A21246,"package google_code_jam; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Scanner; + +public class Dancing { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(new FileInputStream(""data/dancers_long.txt"")); + Writer out = new OutputStreamWriter(new FileOutputStream(""data/dancers_long_output.txt"")); + try { + // Read the number of tests + int numTests = 0; + int answer = 0; + String testLine; + if (scanner.hasNextLine()) + numTests = Integer.valueOf(scanner.nextLine()); + for (int i=1; i<=numTests; i++) { + if (scanner.hasNextLine()) { + testLine = scanner.nextLine(); + answer = getAnswer(testLine); + out.write(""Case #"" + i + "": "" + answer + ""\n""); + } + } + } + finally { + scanner.close(); + out.close(); + } + } + + private static int getAnswer(String testLine) { + //System.out.println(""The updateCounts was called with "" + testLine); + int numDancers = 0; + int numSurprises = 0; + int scoreToReach = 0; + int sumScores = 0; + String[] parts = testLine.split("" ""); + numDancers = Integer.valueOf(parts[0]); + numSurprises = Integer.valueOf(parts[1]); + scoreToReach = Integer.valueOf(parts[2]); + if (scoreToReach <= 0) { + return numDancers; + } + int answer = 0; + for (int j=0; j 0 && canBeSurprise(sumScores, scoreToReach)) { + answer++; + numSurprises--; + } else { + // Didn't quality, do nothing + } + } + return answer; + } + + private static boolean canBeSurprise(int sumScores, int scoreToReach) { + if (sumScores == 0) + return false; + if (sumScores >= 3 * (scoreToReach - 2) + 2) + return true; + else + return false; + } + + private static boolean canBeNormal(int sumScores, int scoreToReach) { + return sumScores > 3 * (scoreToReach - 1); + } + + + +} +" +A22710,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam.common; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Lance Chen + */ +public class CodeHelper { + + private static String FILE_ROOT = ""D:/workspace/googlecodejam/meta""; + + public static List> loadInputsExcludes(String fileName) { + List> result = new ArrayList>(); + List lines = FileUtil.readLines(FILE_ROOT + fileName); + int index = 0; + for (String line : lines) { + if (index == 0) { + index++; + continue; + } + if (index % 2 == 1) { + index++; + continue; + } + List dataList = new ArrayList(); + String[] dataArray = line.split(""\\s+""); + for (String data : dataArray) { + if (data.trim().length() > 0) { + dataList.add(data); + } + } + result.add(dataList); + index++; + } + return result; + } + + public static List> loadInputs(String fileName) { + List> result = new ArrayList>(); + List lines = FileUtil.readLines(FILE_ROOT + fileName); + for (String line : lines) { + List dataList = new ArrayList(); + String[] dataArray = line.split(""\\s+""); + for (String data : dataArray) { + if (data.trim().length() > 0) { + dataList.add(data); + } + } + result.add(dataList); + } + return result; + } + + public static List loadInputLines(String fileName) { + return FileUtil.readLines(FILE_ROOT + fileName); + } + + public static void writeOutputs(String fileName, List lines) { + FileUtil.writeLines(FILE_ROOT + fileName, lines); + } +} +" +A20417,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + +public class Dancing { + + public static void main(String[] args) throws Exception { + + BufferedReader in = new BufferedReader(new FileReader(""dancing.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""dancing.out"")); + + String lineStr; + int T, N, S, P, ti, result; + + T = Integer.parseInt(in.readLine()); + System.out.println(T + "" test cases""); + + for (int line = 1; line <= T; line++) { + + lineStr = in.readLine(); + String[] fields = lineStr.split("" ""); + N = Integer.parseInt(fields[0]); + S = Integer.parseInt(fields[1]); + P = Integer.parseInt(fields[2]); + + System.out.println(""N="" + N + "" S="" + S + "" P="" + P); + + result = 0; + for (int i = 0; i < N; i++) { + ti = Integer.parseInt(fields[3 + i]); + if (ti > (3 * (P - 1))) { + // Guaranteed to have at least P and without surprise + result++; + } else if (ti >= 2 && ti <= 28 && ti >= (3 * (P - 1) - 1)) { + // Have p but with surprise + if (S > 0) { + result++; + // reduce available surprise + S = S - 1; + } + } + } + + out.println(""Case #"" + line + "": "" + result); + System.out.println(lineStr + "" : "" + result); + } + + in.close(); + out.close(); + } + +} +" +A21356,"package test; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Test { + + public static void main (String[] arg) throws IOException{ + + Scanner sc; + + PrintWriter pWriter = null; + + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(""B.out"")); + pWriter = new PrintWriter(bw); + + sc = new Scanner(new File(""B-large.in"")); + + int T = sc.nextInt(); + //System.out.println(""T = "" +T); + + int max = 30 , min , lim1 , lim2 ; + + for(int i=1; i<=T; i++){ + //Scanner sc2 = new Scanner(sc.nextLine()); + int N = sc.nextInt(), S = sc.nextInt(), P = sc.nextInt(); + //System.out.println(""N = "" +N+ ""S = "" +S+ ""P = "" +P); + + min = P * 3 - 2 ; + lim1 = P * 3 - 3; + lim2 = P * 3 - 4; + int somme = 0; + + for(int j = 0 ; j < N ; j++){ + int t = sc.nextInt(); + if(t >= P){ + if(t <= max && t >= min) somme++; + if(t == lim1 && S > 0) { somme++; S--; } + if(t == lim2 && S > 0) { somme++; S--; } + } + } + + //System.out.println(""Case: #"" +i+ "" ""+somme); + pWriter.println(""Case #"" +i+ "": ""+somme); + } + + /* + int i=0; + + while(sc.hasNext()){ + String l = """", ligne = sc.nextLine(); + + //System.out.println(""in=""+ligne); + + Scanner sc2 = new Scanner(ligne); + sc2.useDelimiter("" ""); + + while(sc2.hasNext()){ + if(!l.equals("""")) + l = sc2.next() +"" ""+l; + else + l = sc2.next(); + } + + //System.out.println(""out=""+l); + if(i != 0) + pWriter.println(""Case #""+i+++"": ""+l); + else i++; + + }*/ + } catch (FileNotFoundException e) { + e.printStackTrace(); + + }finally{ + //System.out.println(""out""); + pWriter.close() ; + } + + } +} +" +A21568,"import java.io.*; +import java.util.StringTokenizer; + +/** + * Created by IntelliJ IDEA. + * User: marcus + * Date: 4/13/12 + * Time: 8:18 PM + * To change this template use File | Settings | File Templates. + */ +public class DancingGooglers { + public static void main(String a[]) throws IOException { + + int T = 0; + FileInputStream fInputstream = null; + try { + fInputstream = new FileInputStream(""B-large.in""); + } catch (FileNotFoundException e) { + //e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + DataInputStream in = new DataInputStream(fInputstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + + FileWriter fstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + + String strT = null; + strT = br.readLine(); + + T = Integer.parseInt(strT); + + + + for(int i = 1; i <= T; i++) { + String testCase = br.readLine(); + StringTokenizer st = new StringTokenizer(testCase, "" ""); + + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + + //System.out.println(""Number of Googlers: "" + N); + //System.out.println(""Number of Surprises: "" + S); + //System.out.println(""Great to have: "" + p); + + int result = 0; + + int [] markSheet = new int[N]; + for(int j = 0; j < N; j++){ + markSheet[j] = Integer.parseInt(st.nextToken()); + } + + for (int k = 0; k < N; k++){ + int minValue = p > 1 ? ((p -1) * 3): p; + //System.out.println(""Min Value : "" + minValue); + + if(markSheet[k] >= p ){ + if(p == 0 && markSheet[k] >= 0){ // m = 0 + result++; + + } else if(markSheet[k] > p && p <= 1){ // m = 1, 2 + + result++; + + }else if(markSheet[k] > ((p -1) * 3)){ + result++; + } else if(S > 0){ + if(markSheet[k] == ((p -1) * 3)){ + result++; + S--; + } else { + int rem = markSheet[k] % 3; + int val = markSheet[k] / 3; + if(rem > 1){ + if((val + 2) >= p){ + result++; + S--; + } + } else { + if((val + 1) >= p){ + result++; + S--; + } + } + } + } + } + } + + System.out.println(""Case #"" + i + "": "" + result); + System.out.println(""S: "" + S); + + out.write(""Case #"" + i + "": "" + result + ""\n""); + } + + in.close(); + out.close(); + } + + +} +" +A22630,"import java.io.*; +import java.util.*; + +public class GoogleCount{ + + public GoogleCount(String line, int i, BufferedWriter out){ + int count=0; + try { +// ArrayList gooda = new ArrayList(); +// TreeSet goods = new TreeSet(); + StringTokenizer token = new StringTokenizer(line); + out.write(""Case #""+Integer.toString(i)+"": ""); + String str = null; + Goods cur; + int countS=0, countG=0; + while (token.hasMoreTokens()){ + str = token.nextToken(); + int totG=Integer.parseInt(str); + + str = token.nextToken(); + int totS=Integer.parseInt(str); + + str = token.nextToken(); + int best=Integer.parseInt(str); + + int curr,temp; + while (token.hasMoreTokens() && count=best){ + if (curr-best>=((best-1)*2)){ + + countG++; + } + else if(curr-best>=((best-2)*2) && countS= p) { + total++; + continue; + } + + if(t % 3 == 0) { + if(curS >= S) { + continue; + } + + if(min+1 >= p && t >= 3) { + curS++; + total++; + } + } else { + if(min+1 >= p) { + total++; + continue; + } + + if(t % 3 == 2) { + if(curS >= S) { + continue; + } + + if(min+2 >= p && t >= 2) { + curS++; + total++; + } + } + } + } + + result.append(CASE).append(i).append("": "").append(total); + if(i != T) { + result.append(N_L); + } + writer.write(result.toString()); + result.setLength(0); + } + writer.flush(); + + } catch(IOException e) { + e.printStackTrace(); + } finally { + sc.close(); + try { + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} +" +A22947,"package com.ozan.jam.qr2012; + +import com.ozan.jam.JamBase; + +import java.io.IOException; +import java.util.Scanner; + +/** + * TODO: Describe type + */ +public class B extends JamBase { + + protected B() throws IOException { + super(""qr2012"", ""B"", ""large""); + } + + public static void main(String[] args) throws IOException { + new B().run(); + } + + @Override + protected String handleTestCase(Scanner in) { + int n = in.nextInt(); + int surprises = in.nextInt(); + int p = in.nextInt(); + + int count = 0; + + for (int i = 0; i < n; i++) { + int score = in.nextInt(); + if ((score + 2) / 3 >= p) { + count++; + } else if (score >= 2 && (score + 4) / 3 >= p && surprises > 0) { + count++; + surprises--; + } + } + + in.nextLine(); + return Integer.toString(count); + } + +} +" +A21492,"import java.util.Arrays; +import java.util.Scanner; + + +public class Q2 { + + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int T = s.nextInt(); + for (int i = 0; i < T; i++) { + int N = s.nextInt(); + int S = s.nextInt(); + int P = s.nextInt(); + int[] scores = new int[N]; + for (int j = 0; j < N; j++) { + scores[j] = s.nextInt(); + } + System.out.println(""Case #"" + (i + 1) + "": "" + numAboveMax(scores, S, P)); + } + } + + private static int numAboveMax(int[] scores, int S, int P) { + int surprises = 0; + int result = 0; + if (P > 1) { + for (int i = scores.length - 1; i >= 0; i--) { + if (scores[i] > (3 * P - 3)) { + result++; + } else if ((scores[i] > (3 * P - 5)) && (surprises < S)) { + result++; + surprises++; + } + } + return result; + } else if (P == 1) { + for (int i = scores.length - 1; i >= 0; i--) { + if (scores[i] > 0) { + result++; + } + } + return result; + } else { + return scores.length; + } + } +} +" +A20104,"package my.codejam; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author ""Dzianis Siarheyeu"" + * + */ +public class TaskB { + + private final static boolean DEBUG_OUTPUT = true; + + static class Combo { + final int[] sequence; + final boolean surprise; + final int sum; + final int min, max; + final boolean usual; + + public Combo(int[] sequence, boolean surprise) { + super(); + this.sequence = sequence; + this.surprise = surprise; + + int sumX = 0; + for (int i = 0; i < sequence.length; i++) { + sumX += sequence[i]; + } + this.sum = sumX; + + this.min = Math + .min(sequence[2], Math.min(sequence[0], sequence[1])); + this.max = Math + .max(sequence[2], Math.max(sequence[0], sequence[1])); + + if (max - min > 2) { + throw new IllegalStateException(""Wrong combo.""); + } + this.usual = max - min <= 1; + } + + public Combo(int b1, int b2, int b3) { + this.sequence = new int[3]; + sequence[0] = b1; + sequence[1] = b2; + sequence[2] = b3; + surprise = Math.abs(b1 - b2) + Math.abs(b2 - b3) == 2 ? true + : false; + + this.sum = b1 + b2 + b3; + this.min = Math.min(b3, Math.min(b1, b2)); + this.max = Math.max(b3, Math.max(b1, b2)); + + if (max - min > 2) { + throw new IllegalStateException(""Wrong combo.""); + } + this.usual = max - min <= 1; + + } + + public boolean isUsual() { + return usual; + } + + public int getMin() { + return min; + } + + public int getMax() { + return max; + } + + public int getSum() { + return sum; + } + + public int[] getSequence() { + return sequence; + } + + public boolean isSurprise() { + return surprise; + } + + @Override + public String toString() { + return ""Combo [max="" + max + "", min="" + min + "", sequence="" + + Arrays.toString(sequence) + "", sum="" + sum + + "", surprise="" + surprise + ""]""; + } + + } + + static class Score { + final int sum; + final Combo usual; + final Combo su; + + public Score(Combo usual, Combo su) { + super(); + this.sum = usual.getSum(); + this.usual = usual; + this.su = su; + + if (usual.isUsual() == false) { + throw new IllegalStateException( + ""Unfortunately usual is unusual... usual="" + usual + + "" su="" + su); + } + } + + public int getSum() { + return sum; + } + + public Combo getUsual() { + return usual; + } + + public Combo getSu() { + return su; + } + + @Override + public String toString() { + return ""Score [\nsu="" + su + "", sum="" + sum + "", \nusual="" + usual + + ""]""; + } + + } + + static class ScoreBase { + + Map base = new HashMap(); + + { + base.put(0, new Score(new Combo(0, 0, 0), null)); + base.put(1, new Score(new Combo(0, 0, 1), null)); + base.put(2, new Score(new Combo(0, 1, 1), new Combo(0, 0, 2))); + base.put(3, new Score(new Combo(1, 1, 1), new Combo(0, 1, 2))); + base.put(4, new Score(new Combo(1, 1, 2), new Combo(0, 2, 2))); + base.put(5, new Score(new Combo(1, 2, 2), new Combo(1, 1, 3))); + base.put(6, new Score(new Combo(2, 2, 2), new Combo(1, 2, 3))); + base.put(7, new Score(new Combo(2, 2, 3), new Combo(1, 3, 3))); + base.put(8, new Score(new Combo(2, 3, 3), new Combo(2, 2, 4))); + base.put(9, new Score(new Combo(3, 3, 3), new Combo(2, 3, 4))); + base.put(10, new Score(new Combo(3, 3, 4), new Combo(2, 4, 4))); + base.put(11, new Score(new Combo(3, 4, 4), new Combo(3, 3, 5))); + base.put(12, new Score(new Combo(4, 4, 4), new Combo(3, 4, 5))); + base.put(13, new Score(new Combo(4, 4, 5), new Combo(3, 5, 5))); + base.put(14, new Score(new Combo(4, 5, 5), new Combo(4, 4, 6))); + base.put(15, new Score(new Combo(5, 5, 5), new Combo(4, 5, 6))); + base.put(16, new Score(new Combo(5, 5, 6), new Combo(4, 6, 6))); + base.put(17, new Score(new Combo(5, 6, 6), new Combo(5, 5, 7))); + base.put(18, new Score(new Combo(6, 6, 6), new Combo(5, 6, 7))); + base.put(19, new Score(new Combo(6, 6, 7), new Combo(5, 7, 7))); + base.put(20, new Score(new Combo(6, 7, 7), new Combo(6, 6, 8))); + base.put(21, new Score(new Combo(7, 7, 7), new Combo(6, 7, 8))); + base.put(22, new Score(new Combo(7, 7, 8), new Combo(6, 8, 8))); + base.put(23, new Score(new Combo(7, 8, 8), new Combo(7, 7, 9))); + base.put(24, new Score(new Combo(8, 8, 8), new Combo(7, 8, 9))); + base.put(25, new Score(new Combo(8, 8, 9), new Combo(7, 9, 9))); + base.put(26, new Score(new Combo(8, 9, 9), new Combo(8, 8, 10))); + base.put(27, new Score(new Combo(9, 9, 9), new Combo(8, 9, 10))); + base.put(28, new Score(new Combo(9, 9, 10), new Combo(8, 10, 10))); + base.put(29, new Score(new Combo(9, 10, 10), null)); + base.put(30, new Score(new Combo(10, 10, 10), null)); + } + + Map getMap() { + return base; + } + + int getMaxPlayers(int N, int S, int P, int[] Ti) { + + // System.out.println(""getMaxPlayers() N="" + N + "" S="" + S + "" P="" + // + P + "" Ti="" + Arrays.toString(Ti)); + + int res = 0; + int surprisedNotUsed = S; + + for (int t : Ti) { + Score cur = base.get(t); + + Combo usual = cur.getUsual(); + if (usual.getMax() >= P) { + res++; + + // System.out.println("""" + usual.getSum() + "" "" + // + Arrays.toString(usual.getSequence())); + continue; + + } else { + if (surprisedNotUsed > 0) { + Combo su = cur.getSu(); + if (su != null && su.getMax() >= P) { + res++; + surprisedNotUsed--; + // System.out.println("""" + su.getSum() + "" "" + // + Arrays.toString(su.getSequence()) + "" *""); + continue; + + } + } + } + + // System.out.println("" t="" + // + t + // + "" "" + // + Arrays.toString(cur.usual.getSequence()) + // + "" "" + // + (cur.su != null ? Arrays.toString(cur.su + // .getSequence()) + // + ""*"" : ""NULL"")); + + } + + // System.out.println(""getMaxPlayers() res="" + res + ""\n""); + + return res; + } + + String getInfo() { + StringBuffer buf = new StringBuffer(); + + for (int i = 0; i < 30; i++) { + Score score = base.get(i); + + buf.append(""\n i="" + i + "" score="" + score + ""\n""); + } + + return buf.toString(); + } + + } + + static void reportError(String text) { + System.out.println(""ERR "" + text); + } + + private static String getOutFileName(String inFileName) { + String outFileName = inFileName.replace("".in"", "".out""); + return outFileName; + } + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + System.out.println(""Hello World!""); + + String filePath = ""/home/dsa/Downloads/B-large.in""; + String filePathOut = getOutFileName(filePath); + + File file = new File(filePath); + File fileOut = new File(filePathOut); + + FileInputStream fis = new FileInputStream(file); + FileOutputStream fos = new FileOutputStream(fileOut); + + if (DEBUG_OUTPUT) { + System.out.println(""----------------------------------------""); + } + + ScoreBase scoreBase = new ScoreBase(); + + // String info = scoreBase.getInfo(); + // System.out.println("" info="" + info); + + MyReader myReader = new MyReader(scoreBase); + int item; + while ((item = fis.read()) > 0) { + char ch = (char) item; + + if (DEBUG_OUTPUT) { + System.out.print(ch); + } + + myReader.feedItem(ch); + } + myReader.endOfInputReached(); + + fis.close(); + + if (DEBUG_OUTPUT) { + System.out.println(""----------------------------------------""); + } + + List output = myReader.getOutput(); + long testCaseCount = 0; + + for (Integer testCase : output) { + testCaseCount++; + + String s1 = ""Case #"" + testCaseCount + "": "" + testCase + ""\n""; + if (DEBUG_OUTPUT) { + System.out.print(s1); + } + fos.write(s1.getBytes()); + } + + fos.flush(); + fos.close(); + + } + + static class MyReader { + + ScoreBase scoreBase = new ScoreBase(); + + public MyReader(ScoreBase scoreBase) { + super(); + this.scoreBase = scoreBase; + } + + enum MyReaderState { + NOT_USED, FIRST_LINE, DATA_LINE, FINISHED; + }; + + MyReaderState curState = MyReaderState.NOT_USED; + StringBuffer curWordContent = new StringBuffer(); + int casesNumber = -1; + List output = new ArrayList(); + List curLine = new ArrayList(); + + void endOfInputReached() { + // if (curLineReverse.size() > 0 || curWordContent.length() > 0) { + // processLine(); + // } + } + + List getOutput() { + return output; + } + + void feedItem(char ch) { + + // if (DEBUG_OUTPUT) { + // System.out.println(""feedItem() ch=\"""" + ch + ""\"""" + // + "" curWordContent="" + curWordContent.toString()); + // } + + if (ch == '\r') + return; + + switch (curState) { + case NOT_USED: + if (ch == '\n') { + throw new IllegalStateException( + ""Input file can't start with empty first line.""); + } + curState = MyReaderState.FIRST_LINE; + curWordContent.append(ch); + break; + + case FIRST_LINE: + if (ch == '\n') { + curState = MyReaderState.DATA_LINE; + casesNumber = Integer.parseInt(curWordContent.toString()); + System.out.println(""First line parsed: casesNumber="" + + casesNumber); + curWordContent.setLength(0); + } else { + curWordContent.append(ch); + } + break; + + case DATA_LINE: + switch (ch) { + + case '\n': + processDataLine(); + break; + + default: + curWordContent.append(ch); + break; + } + break; + + default: + break; + } + } + + private void processDataLine() { + + String curLine = curWordContent.toString(); + String[] curLineParts = curLine.split("" ""); + int[] intParts = new int[curLineParts.length]; + + for (int i = 0; i < curLineParts.length; i++) { + intParts[i] = Integer.parseInt(curLineParts[i]); + } + // System.out.println(""processDataLine() curLine="" + curLine); + + int N = intParts[0]; + int S = intParts[1]; + int P = intParts[2]; + int[] Ti = new int[intParts.length - 3]; + System.arraycopy(intParts, 3, Ti, 0, Ti.length); + + // System.out.println(""processDataLine() N="" + N + "" S="" + S + + // "" P="" + // + P + "" Ti="" + Arrays.toString(Ti)); + + curWordContent.setLength(0); + + int maxPlayers = scoreBase.getMaxPlayers(N, S, P, Ti); + // System.out.println(""processDataLine() maxPlayers="" + + // maxPlayers); + + output.add(maxPlayers); + } + } + +} +" +A20466,"import java.io.IOException; +import java.util.Scanner; + +public class codejam_B_small { + + public static void main(String[] args) throws IOException { + FileUtil.Timer.start(); + + Scanner scanner = new Scanner(System.in); + int numOfTest = scanner.nextInt(); + scanner.nextLine(); + String[] testCases = new String[numOfTest]; + for (int i = 0; i < numOfTest; i++) { + testCases[i] = scanner.nextLine(); + } + + + String[] finalResult = new String[numOfTest]; + for (int i = 0; i < numOfTest; i++) { + String testCase = testCases[i]; + String result = runTestCase(testCase); + finalResult[i] = FileUtil.formatTestResult(i, result); + System.out.println(finalResult[i]); + } + FileUtil.Timer.stop(); + } + + private static String runTestCase(String testCase) { + String[] splits = testCase.split("" ""); + int numOfGoogler = Integer.valueOf(splits[0]); + int numOfSurpring = Integer.valueOf(splits[1]); + int bestResult = Integer.valueOf(splits[2]); + if (numOfGoogler <= 0) { + return ""0""; + } + + // int maxResult = 3 * bestResult; + int count = 0; + // check best result + for (int i = 3; i < splits.length; i++) { + int point = Integer.valueOf(splits[i]); + int avg = point / 3; + int reminder = point % 3; + int diff = bestResult - avg; + if (avg >= bestResult || diff == 0) { + count++; + continue; + } else if (point < bestResult) { + continue; + } + + if (reminder >= 1 && diff <= 1) { + count++; + continue; + } else if (reminder >= 2 && diff == 2 && numOfSurpring > 0) { + numOfSurpring--; + count++; + continue; + } else if (reminder == 0 && diff == 1 && numOfSurpring > 0) { + numOfSurpring--; + count++; + continue; + } + } + return String.valueOf(count); + } + +} +" +A21802,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + + +public class testC { + + public static void main(String args[]){ + + + int arrayInt[]; + String str=""""; + int numbersOfGooglers=0; + int S=0; + int P=0; + int index=0; + int count=0; + int arrResults[]; + try{ + FileReader fr = new FileReader(""2.txt""); + BufferedReader br = new BufferedReader(fr); + int size = Integer.parseInt(br.readLine()); + for(int loop=0;loop0 && ( P+(P-1)+(P+1)==arrResults[i] || P+(P+2)+(P+2)==arrResults[i] || P+(P-2)+(P-2)==arrResults[i] || P+(P-1)+(P-2)==arrResults[i] || P+(P+1)+(P+2)==arrResults[i])) + { + count++; + S--; + break; + } + }else if((P-1<0)){ + if(P*3==arrResults[i] || P+(P+1)+(P+1)==arrResults[i] || P+(P)+(P+1)==arrResults[i] ) + { + count++; + break; + } + else if(S>0 && ( P+(P+2)+(P+2)==arrResults[i] || P+(P+1)+(P+2)==arrResults[i])) + { + count++; + S--; + break; + } + }else if((P-2<0)){ + if(P*3==arrResults[i] || P+(P-1)+(P-1)==arrResults[i] || P+(P+1)+(P+1)==arrResults[i] || P+(P)+(P+1)==arrResults[i] || P+(P)+(P-1)==arrResults[i]) + { + count++; + break; + } + else if(S>0 && ( P+(P-1)+(P+1)==arrResults[i] || P+(P+2)+(P+2)==arrResults[i] || P+(P+1)+(P+2)==arrResults[i])) + { + count++; + S--; + break; + } + } + + + P++; + } +/* + if(arrResults[i]/P<4){ + if(arrResults[i]%P < 2){ + count++; + break; + }else if(arrResults[i]%P == 2 && S>0){ + count++; + S--; + break; + } + } + P++; + */ + + } + System.out.println(""Case #""+(loop+1)+"": ""+count); + /* for(int j=0;j= minSet) + { + answer++; + } else { + minSet -= 2; + if (minSet < 1) + { + minSet = 1; + } + if ((value >= minSet) && (amountOfSurpTrp > 0)) + { + answer++; + amountOfSurpTrp--; + } + } + } + System.out.println("" "" + answer); + } +} +" +A21974,"package com.renoux.gael.codejam.utils; + +import java.io.BufferedReader; +import java.io.Closeable; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + + +public class Input implements Closeable { + + BufferedReader reader; + + private Input(BufferedReader reader) { + this.reader = reader; + } + + public static Input open(File f) { + final BufferedReader r; + try { + r = FileUtils.getReader(f); + } catch (FileNotFoundException e) { + throw new TechnicalException(e); + } + + return new Input(r); + } + + public void close() { + try { + reader.close(); + } catch (IOException e) { + throw new TechnicalException(e); + } + } + + public String readLine() { + try { + return reader.readLine(); + } catch (IOException e) { + throw new TechnicalException(e); + } + } + + +} +" +A20405,"package qualification.taskB; + +import Parser.MyReader; +import Parser.MyWriter; + +public class Main { + + public static void main(String[] args) { + MyReader myReader = new MyReader( + ""/Users/shami13/Downloads/B-small-attempt0.in""); + MyWriter myWriter = new MyWriter( + ""/Users/shami13/Downloads/B-small-attempt0.out""); + + int taskLength = Integer.parseInt(myReader.read()); + for (int i = 1; i <= taskLength; i++) { + String[] taskString = myReader.read().split("" ""); + int T = Integer.parseInt(taskString[0]); + int S = Integer.parseInt(taskString[1]); + int P = Integer.parseInt(taskString[2]); + int[] googlers = new int[T]; + for(int p = 3; p < taskString.length; p++){ + googlers[p-3] = Integer.parseInt(taskString[p]); + } + + Task task = new Task(T,S,P,googlers); + String result = task.execute(); + myWriter.writeString(""Case #"" + i + "": "" + result); + System.out.println(""Case #"" + i + "": "" + result); + } + myWriter.close(); + } +} +" +A20870,"import java.io.* ; +import java.util.Scanner; +public class Main2 { + public static void main(String argsp[]) throws FileNotFoundException{ + + Scanner in = new Scanner(new FileReader(""input.in"")); + PrintWriter out = new PrintWriter(""output.txt""); + int T = 0; + String S1 = in.nextLine() ; + T = Integer.parseInt(S1); + for(int i=0;i1) + checker = 3*p - 4; + else + checker = 0; + int great = 0; + int surprise = 0; + for(int k=0;k=checker) + great++; + if((a[k]==checker || a[k] == checker+1) && p>1) + surprise++; + if(p==1 && a[k] == 0) + great--; + } +// System.out.println(great+ "" "" + surprise); + int answer = 0; + if((S-surprise)<=0) + answer = great+S-surprise; + else + answer = great; + out.println(answer); + } + out.close(); + } +}" +A22928,"package com.vp.iface; + + +public interface Problem{ + + public static int SPEAKGOOGLERESE = 1; + public static int DANCINGWITHGOOGLERS = 2; + + public String solve(String dataset[]); +}" +A21338,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + + +public class DancingWithTheGooglers { + + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(args[0])); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(args[0]+"".out""))); + String l = in.readLine(); + int N = Integer.parseInt(l); + int i=1; + while((l=in.readLine())!= null) + { + int cnt = 0; + out.print(""Case #""+i+++"": ""); + String ll[] = l.split("" ""); + int S = Integer.parseInt(ll[1]); + int p = Integer.parseInt(ll[2]); + //da ll[3]; a ll[ll.length-1]; somme + ArrayList amb = new ArrayList(); + int cntA=0; + for(int z=3;z0) cnt++; + continue; + } + int foo = p+(p-1)+(p-1); + int bar = p+(p-2)+(p-2); + if(sum>=foo) cnt++; + else if(sum>=bar) cntA++; + } + cnt+= Math.min(cntA,S); + out.print(cnt); + if(i<=N) out.println(""""); + } + in.close(); + out.close(); + } +} +" +A22128,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; + + +public class R1Q2 { + public static HashMap wordMap; + + public static void main(String []args) throws NumberFormatException, IOException{ + BufferedReader bf = new BufferedReader(new FileReader(new File(""input""))); + BufferedWriter bw = new BufferedWriter(new FileWriter(new File(""output""))); + int num = Integer.parseInt(bf.readLine()); + for (int i = 1 ; i<=num; i++){ + int maxnum = 0; + String line = bf.readLine(); + String[] argss =line.split("" ""); + int people = Integer.parseInt(argss[0]); + int sup = Integer.parseInt(argss[1]); + int p = Integer.parseInt(argss[2]); + int []points = new int[people]; + int already = 0; + int poss = 0; + for (int j = 0; j < people; j++){ + points[j] = Integer.parseInt(argss[j+3]); + if ((points[j]+2)/3 >= p) already++; + else if ((points[j]+4)/3 >= p && points[j] >=p){ + poss ++; + } + } + maxnum = already + (poss > sup?sup:poss); + bw.write(""Case #""+i+"": ""+maxnum+""\n""); + } + bf.close(); + bw.close(); + } +} +" +A21675,"import java.util.Scanner; + +public class Dance { + + public static void main(String[] args) { + Scanner cin = new Scanner(System.in); + int linenum = cin.nextInt(); + + for(int idx = 1; idx < linenum+1; idx++) + { + System.out.print(""Case #"" + idx + "": ""); + int n = cin.nextInt(); + int s = cin.nextInt(); + int p = cin.nextInt(); + + int ans = 0; + + for(int i=0; i < n; i++) + { + int score = cin.nextInt(); + + if(score == 0) + { + if(p == 0) + ans++; + else + continue; + } + else if(score == p*3 || score == p*3 - 1 ||score == p*3 - 2 || score > p*3) + { + ans++; + } + else if(score == p*3 - 3 || score == p*3 - 4) + { + if(s > 0) + { + s--; + ans++; + } + else + { + continue; + } + } + else + { + continue; + } + } + System.out.println(ans); + } + } + +} +" +A22234,"/** + * User: avokin + * Date: 4/14/12 + */ +public class ProblemB { + private static int solve(int n, int s, int p, int[] t) { + int result = 0; + for (int i = 0; i < n; i++) { + if (t[i] % 3 == 0) { + int a = t[i] / 3; + if (a >= p) { + result++; + } else { + if (a > 0 && a + 1 == p && s > 0) { + s--; + result++; + } + } + } else if (t[i] % 3 == 1) { + int a = t[i] / 3 + 1; + if (a >= p) { + result++; + } + } else { + int a = t[i] / 3 + 1; + if (a >= p) { + result++; + } else { + if (a + 1 == p && s > 0) { + s--; + result++; + } + } + } + } + return result; + } + + public static void main(String[] args) { + String input = ""100\n"" + + ""6 2 8 29 20 8 18 18 21\n"" + + ""77 11 7 17 26 7 17 17 8 19 30 17 19 26 7 17 18 28 4 18 14 3 28 18 18 18 18 18 13 6 17 18 24 15 17 28 26 20 17 18 18 6 17 9 4 19 18 19 17 16 18 18 17 17 17 18 17 3 17 9 18 18 17 22 16 27 18 18 4 17 18 18 18 18 9 0 10 10 30 17\n"" + + ""58 58 9 28 28 17 2 25 12 9 17 16 5 6 6 24 5 28 5 21 12 16 27 14 15 24 16 13 10 3 28 13 14 9 17 21 2 11 16 13 8 17 25 14 6 8 7 8 16 9 10 16 14 2 15 17 19 9 18 23 2\n"" + + ""63 63 1 13 14 12 8 13 20 27 24 17 22 6 14 7 23 12 15 3 19 25 7 16 21 10 20 28 14 26 12 4 2 7 9 9 15 6 22 12 21 22 6 10 11 5 21 17 9 19 18 21 28 12 28 17 19 20 3 11 21 5 15 18 12 25\n"" + + ""91 22 8 4 21 9 0 7 21 21 30 21 23 24 30 21 18 20 21 20 21 17 27 20 20 21 7 20 28 20 17 21 17 2 3 20 10 16 20 1 20 21 21 15 1 23 21 21 21 25 22 21 20 20 3 21 20 21 20 20 21 0 18 20 20 8 14 21 0 30 20 20 21 7 20 21 21 3 4 20 20 1 0 21 11 25 20 2 21 21 21 9 21 20\n"" + + ""54 18 4 21 21 26 1 22 12 14 9 8 9 8 30 17 9 9 27 9 9 8 9 9 9 22 8 9 9 8 9 9 29 5 8 8 29 8 19 8 9 9 15 9 8 8 9 25 3 8 6 9 13 24 0 26 21\n"" + + ""38 11 5 2 14 11 14 18 7 21 23 11 23 1 6 17 3 10 8 3 25 24 8 27 16 11 17 24 19 3 2 25 29 12 14 29 28 18 3 19 17\n"" + + ""59 17 10 26 27 26 4 27 0 27 26 27 27 2 28 26 27 27 15 27 26 26 5 26 27 30 20 23 27 27 26 14 26 27 1 26 27 19 18 26 19 9 26 27 26 0 26 26 27 26 27 27 27 21 26 27 17 27 26 26 26 27\n"" + + ""100 0 3 16 28 2 13 7 2 29 11 22 12 4 1 8 4 28 21 2 9 13 3 1 27 15 17 7 2 26 9 23 24 13 6 7 0 7 26 19 14 24 30 29 25 8 16 26 27 10 12 24 22 2 13 6 7 30 4 9 12 0 5 4 29 25 8 3 18 11 14 20 19 26 15 5 30 14 15 30 0 24 24 5 10 6 28 29 19 14 1 24 1 24 10 29 14 13 13 8 8 29 19\n"" + + ""25 8 3 9 17 8 18 10 6 18 3 22 8 9 4 16 24 14 28 21 15 28 5 7 26 21 6 2\n"" + + ""50 26 6 0 17 29 8 25 1 1 11 17 20 23 18 16 4 20 17 29 30 4 15 23 18 11 15 26 14 28 9 19 11 22 5 12 21 3 1 19 1 30 29 20 8 13 29 16 11 29 3 10 9\n"" + + ""46 18 5 11 7 11 1 11 12 12 17 11 12 21 12 11 11 11 11 12 27 11 9 24 12 11 11 11 12 28 25 29 11 12 12 9 20 12 11 9 11 12 12 11 11 12 11 12 12\n"" + + ""5 1 8 21 1 20 14 4\n"" + + ""65 0 1 17 15 13 6 27 20 29 4 2 21 13 5 3 19 23 29 23 6 17 19 17 30 1 20 16 4 19 5 22 18 13 11 5 20 22 24 10 6 21 6 15 18 10 6 9 25 19 15 13 15 28 24 0 12 21 9 4 12 28 22 29 21 13 25 13\n"" + + ""15 0 10 20 26 8 9 26 26 26 13 27 27 27 18 27 15 26\n"" + + ""8 1 8 27 15 30 17 5 26 26 9\n"" + + ""61 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n"" + + ""100 22 4 25 8 0 27 9 8 6 6 9 8 6 9 8 0 20 9 20 25 8 3 6 8 8 9 17 8 9 5 0 8 21 8 8 8 0 11 0 9 8 1 9 8 9 20 13 8 4 9 8 8 9 4 9 10 22 4 12 17 30 8 8 27 8 9 8 9 9 2 8 12 9 8 0 9 8 13 9 1 15 6 24 23 8 9 9 8 9 9 0 9 8 6 9 9 30 8 6 15 27 8\n"" + + ""62 0 10 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n"" + + ""8 5 7 28 19 17 5 29 10 12 8\n"" + + ""84 84 3 21 28 17 21 24 2 11 23 16 12 25 28 8 12 7 3 18 20 25 18 17 10 20 8 3 3 7 24 27 19 9 5 5 6 5 3 2 7 13 10 7 10 16 25 3 3 23 14 13 8 28 15 22 8 8 27 3 27 10 20 9 22 3 20 12 18 28 5 22 20 10 18 17 11 8 19 21 16 16 10 6 3 2 27\n"" + + ""92 52 10 27 19 5 23 19 29 11 10 12 1 20 28 11 5 17 7 17 5 2 3 27 19 3 0 24 17 21 5 29 11 26 25 26 21 25 7 15 6 11 20 24 27 4 13 3 27 19 10 4 27 11 7 16 27 25 8 11 16 18 29 27 25 21 7 23 14 5 30 18 5 8 22 14 29 12 13 24 13 25 15 10 29 18 2 2 22 19 0 15 1 22 0\n"" + + ""34 18 9 24 24 23 23 29 24 23 23 25 15 24 9 24 14 10 24 3 24 21 23 24 30 23 14 30 7 23 24 23 24 23 9 29 30\n"" + + ""65 31 6 25 16 15 5 26 14 0 12 15 15 17 14 10 14 14 14 4 1 25 14 24 14 14 15 13 16 20 14 15 14 4 9 0 14 8 14 14 15 15 15 4 15 1 14 15 14 14 2 15 15 14 9 14 3 30 15 14 15 15 14 15 16 15 7 26\n"" + + ""19 11 1 26 8 20 19 18 14 14 20 17 7 1 28 9 20 17 2 8 24 27\n"" + + ""31 24 9 22 14 29 0 5 22 26 15 27 1 17 24 5 8 18 30 12 4 30 8 27 10 17 29 25 9 7 16 11 25 7\n"" + + ""33 33 0 3 3 27 26 27 23 18 25 21 12 24 10 22 12 28 19 12 11 11 28 2 27 18 13 4 24 4 4 13 15 3 24 7\n"" + + ""58 28 7 17 27 18 6 18 18 18 18 18 5 29 18 18 18 22 9 17 18 26 17 17 17 18 18 13 18 17 18 17 24 4 5 17 21 17 17 17 17 17 4 18 24 16 10 18 27 6 18 8 13 15 26 18 3 11 9 17 30\n"" + + ""16 12 10 11 15 16 5 5 21 7 5 19 1 21 22 8 26 4 8\n"" + + ""21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"" + + ""70 30 3 11 13 1 3 3 22 24 17 24 29 6 26 24 11 30 5 20 30 7 26 17 16 17 12 5 6 28 12 10 12 28 15 8 19 4 4 30 27 10 6 7 17 20 16 5 25 30 2 15 0 13 29 6 22 13 9 18 1 18 29 13 25 23 17 29 1 4 24 25 18\n"" + + ""49 13 2 13 29 10 8 28 17 2 14 13 9 5 28 18 7 19 30 27 14 27 0 16 9 28 12 6 0 4 8 15 7 7 30 26 14 26 21 1 18 30 16 4 4 18 16 0 27 9 16 20\n"" + + ""42 8 7 18 18 27 17 21 17 17 17 17 17 18 18 25 27 18 19 10 15 18 18 6 13 17 26 30 18 18 18 20 24 18 29 17 8 28 18 18 14 18 17 17 16\n"" + + ""7 6 0 23 27 30 24 3 24 28\n"" + + ""22 0 2 17 1 15 27 16 25 27 30 20 0 9 10 25 25 4 19 28 4 21 29 18 30\n"" + + ""24 0 0 18 4 27 28 14 26 1 26 6 12 23 18 5 9 7 12 27 5 20 30 17 2 24 19\n"" + + ""77 76 1 6 24 25 25 27 24 20 12 26 22 17 21 2 17 16 16 8 27 10 3 15 10 6 15 7 9 19 13 27 5 4 2 16 5 18 22 22 10 13 5 27 9 26 24 23 15 20 5 14 19 16 15 23 0 22 9 23 12 12 9 20 17 3 25 17 27 25 26 12 27 21 14 21 27 28 23 7\n"" + + ""7 1 2 23 2 19 8 15 3 7\n"" + + ""65 0 1 14 7 4 21 29 20 11 8 4 2 22 18 12 21 27 6 13 23 7 30 24 9 22 23 17 25 26 5 26 10 10 25 20 16 15 19 19 21 26 18 0 28 16 21 2 27 28 20 28 28 20 2 27 19 0 17 30 7 23 25 7 30 18 28 8\n"" + + ""67 67 9 6 16 8 15 2 27 17 6 24 21 7 14 8 12 12 7 24 23 21 4 20 16 23 4 6 22 17 21 25 17 20 13 27 27 9 3 9 22 19 10 22 15 14 26 10 17 23 10 9 24 24 7 5 16 19 20 4 20 17 15 12 8 25 18 26 18 21\n"" + + ""87 0 6 24 29 0 4 4 19 30 20 13 28 13 16 17 2 17 1 11 11 14 17 1 16 3 21 9 3 7 29 23 5 27 5 18 24 11 23 28 5 16 27 16 2 19 12 30 0 7 8 12 9 29 26 15 23 0 29 13 11 4 4 16 30 25 7 7 8 11 4 10 4 25 0 28 8 27 18 3 14 0 19 13 10 16 23 8 30 15\n"" + + ""9 0 4 2 23 18 28 5 1 22 20 3\n"" + + ""13 5 0 4 12 6 9 16 24 7 2 22 6 18 1 27\n"" + + ""79 7 2 14 19 14 24 19 1 13 12 0 26 11 22 20 22 22 1 30 8 17 17 10 19 20 18 26 30 5 6 26 15 29 28 11 22 29 0 30 22 23 23 19 17 3 0 24 20 6 23 15 4 27 25 20 21 14 22 10 16 15 25 25 4 0 11 19 14 25 12 8 28 3 24 18 29 10 25 4 5 21\n"" + + ""1 0 4 27\n"" + + ""22 22 0 17 7 8 23 11 12 15 11 20 28 16 9 8 21 9 5 13 20 11 20 16 24\n"" + + ""78 20 4 15 23 3 22 29 29 24 22 19 9 27 16 25 29 1 22 24 0 19 5 2 23 4 14 23 18 10 29 24 6 28 9 8 12 9 27 22 16 10 12 1 7 5 9 7 19 21 26 2 18 3 6 2 0 6 2 25 27 1 5 19 3 24 23 8 22 13 26 14 5 24 25 9 26 26 21 30 17\n"" + + ""81 81 6 23 8 28 2 21 10 25 26 12 20 12 3 26 15 24 5 15 23 14 20 2 17 9 24 17 26 9 26 26 18 13 4 17 18 14 3 19 24 16 18 14 19 8 12 18 6 10 6 13 16 9 24 13 9 6 18 21 23 10 19 26 15 28 19 7 12 11 16 4 13 28 9 5 26 7 16 3 8 23 18 21\n"" + + ""77 11 10 26 26 26 26 27 19 22 29 17 26 27 26 26 26 19 29 22 7 10 26 26 27 26 27 16 2 26 9 30 27 27 27 26 26 14 8 27 2 27 25 26 27 13 26 2 26 26 27 2 29 8 2 2 25 27 12 26 9 27 26 27 26 27 26 27 27 26 27 26 5 14 3 26 27 27 16 15\n"" + + ""68 15 4 26 22 16 2 20 13 22 16 4 6 28 30 10 25 8 11 8 17 14 9 29 12 15 28 12 27 23 7 9 9 18 29 9 28 0 30 1 1 8 19 3 1 29 1 3 16 9 27 19 10 0 20 29 0 18 30 5 1 22 13 9 29 2 8 28 17 28 1\n"" + + ""63 32 7 28 10 29 0 25 28 0 4 13 26 30 17 26 12 7 26 24 20 2 21 12 5 27 21 1 22 24 3 19 2 3 6 5 21 0 25 16 30 30 12 27 26 22 29 0 15 19 10 14 19 19 18 28 29 10 27 27 25 25 21 11 0 13\n"" + + ""98 29 5 7 5 3 3 7 10 14 12 15 5 10 20 19 25 23 1 4 17 11 8 29 29 9 15 20 3 3 20 14 12 20 19 27 3 18 16 20 3 8 25 20 21 7 16 28 11 11 7 10 27 25 30 0 3 13 18 8 15 11 29 12 26 0 25 22 30 4 0 6 23 11 19 1 5 0 10 30 26 27 6 25 12 0 23 7 24 10 17 3 28 24 13 2 24 3 13 1 16\n"" + + ""32 8 8 7 29 1 9 15 8 19 28 22 12 16 5 2 17 21 12 3 23 15 22 4 20 9 15 12 11 2 15 6 2 14 11\n"" + + ""90 19 2 8 10 2 0 2 0 2 10 3 3 3 21 17 2 2 25 3 19 4 2 3 3 30 2 1 3 3 2 12 2 15 2 2 9 29 3 29 3 2 8 18 0 2 8 2 3 2 3 8 3 27 2 8 24 2 2 0 2 30 23 2 24 29 16 30 2 1 3 3 6 29 2 14 19 20 3 3 2 2 4 2 3 5 23 15 3 3 2 2 4\n"" + + ""51 51 10 6 17 2 22 9 12 6 14 16 13 24 27 22 2 24 6 18 4 6 27 27 2 13 25 27 26 6 17 23 9 10 27 8 13 9 22 14 16 26 11 17 5 13 21 18 8 13 6 14 8 14\n"" + + ""21 5 0 27 17 15 29 13 14 3 29 8 4 14 24 30 7 29 5 5 4 20 24 29\n"" + + ""85 8 8 14 30 11 16 17 11 5 21 2 15 5 23 9 17 27 0 24 11 15 7 8 24 8 29 27 9 28 3 2 1 14 14 22 10 2 8 6 28 25 0 26 14 10 1 26 15 24 7 9 1 4 14 6 13 20 29 5 25 11 9 22 19 14 4 8 28 6 18 26 5 19 26 6 28 14 16 26 26 2 30 28 6 13 14 22\n"" + + ""45 45 1 5 26 21 28 5 2 7 12 26 14 7 14 4 14 23 24 18 27 15 2 27 26 13 5 26 16 28 5 21 24 8 10 15 22 8 18 21 2 15 11 11 17 24 26 21\n"" + + ""60 0 10 20 2 27 13 16 10 19 27 16 1 13 24 13 2 8 1 23 1 6 25 9 14 26 27 25 6 1 16 2 7 24 6 28 17 1 25 19 11 12 15 30 25 25 1 22 21 26 9 9 4 22 20 21 0 25 13 5 21 9 28\n"" + + ""91 18 3 30 5 9 6 5 14 6 23 5 5 6 22 30 5 25 6 5 3 6 4 5 20 17 18 5 25 19 5 6 5 6 6 13 6 5 5 16 5 6 15 25 29 6 12 29 5 5 5 24 2 6 6 5 6 22 5 5 8 16 6 5 5 6 5 5 5 7 9 26 5 8 5 10 2 5 5 5 1 6 0 5 0 30 6 22 6 5 30 6 28 30\n"" + + ""24 15 3 7 22 21 7 14 8 8 23 30 13 19 1 30 8 14 26 8 15 0 26 27 0 8 1\n"" + + ""6 6 8 15 20 28 5 21 10\n"" + + ""37 14 5 20 5 1 23 9 30 21 9 14 1 22 15 17 16 27 6 21 10 0 0 27 8 8 17 18 3 18 6 25 12 20 29 18 19 19 9 13\n"" + + ""13 12 9 15 2 15 3 25 0 24 25 10 6 26 25 12\n"" + + ""41 7 2 7 15 14 30 24 27 29 6 5 26 30 25 28 27 1 6 6 14 15 8 19 16 6 7 30 25 30 11 21 0 25 7 7 11 5 3 25 10 1 24 11\n"" + + ""86 4 6 15 14 30 11 30 9 30 20 14 14 14 30 13 19 2 12 14 7 27 15 14 10 14 14 14 28 14 14 14 15 14 19 28 14 14 4 23 7 12 14 15 23 12 14 14 15 4 23 15 19 8 15 15 15 15 14 15 17 10 7 14 14 15 20 24 15 26 15 14 28 15 14 16 3 2 15 14 15 10 14 14 14 14 15 7 14\n"" + + ""77 70 10 6 29 7 18 22 25 27 7 23 24 13 13 21 15 23 14 15 7 15 17 17 0 19 3 21 2 15 1 23 26 13 19 1 4 4 10 12 29 20 13 22 22 29 15 16 15 5 2 10 18 9 21 26 20 4 11 7 25 23 23 27 4 20 19 14 13 22 22 0 27 15 11 15 22 24 25 18\n"" + + ""29 10 1 17 29 6 30 25 8 27 28 9 8 15 15 29 10 2 3 24 1 23 23 10 28 24 9 21 24 21 21 27\n"" + + ""21 8 9 23 24 15 10 22 24 23 23 24 24 23 21 0 17 23 24 24 1 28 9 8\n"" + + ""44 0 7 9 1 24 4 9 2 15 25 30 30 5 3 24 15 26 26 1 7 18 2 6 3 27 8 10 6 2 4 30 10 0 25 16 21 26 23 13 20 19 12 27 24 5 12\n"" + + ""24 0 10 0 13 15 21 10 20 30 2 22 25 30 2 2 25 11 18 10 15 19 26 0 11 13 1\n"" + + ""55 14 8 30 8 15 3 2 16 19 22 8 16 8 26 25 19 28 12 12 1 18 21 12 2 25 3 28 28 15 27 11 2 8 19 18 12 10 29 12 10 27 0 20 26 28 26 17 18 10 28 30 4 17 22 23 30 6\n"" + + ""49 28 2 17 24 17 8 21 18 2 28 29 9 7 24 9 15 2 9 13 30 28 0 23 29 23 9 3 26 1 6 6 5 11 4 20 2 19 5 25 18 29 11 0 9 24 13 8 14 12 22 11\n"" + + ""49 10 3 8 12 20 3 5 12 6 30 5 6 6 5 22 22 6 6 28 15 30 5 5 6 20 3 5 6 5 6 5 8 5 6 21 12 5 5 6 18 5 28 5 20 24 23 26 11 6 6 25\n"" + + ""41 5 10 5 14 7 7 12 13 26 17 27 18 21 0 28 8 12 7 27 10 11 28 12 11 29 19 12 2 28 9 26 9 0 1 14 10 20 19 5 24 9 15 14\n"" + + ""14 0 2 3 3 3 22 3 3 5 30 3 3 0 10 3 3\n"" + + ""44 44 0 21 27 19 3 26 9 24 8 27 8 21 16 18 11 20 11 10 21 8 20 8 5 11 22 20 19 2 10 11 16 11 25 9 8 7 13 21 19 17 7 14 27 10 3\n"" + + ""9 0 9 5 9 1 8 30 2 4 14 30\n"" + + ""93 18 7 17 24 17 18 18 21 18 17 17 17 17 21 18 17 17 17 18 18 17 18 3 18 19 17 17 1 18 28 27 27 9 17 10 10 17 17 17 17 17 18 17 16 12 18 17 18 15 17 15 27 21 13 26 5 24 18 17 24 24 15 14 18 22 17 18 17 17 11 16 1 18 14 18 3 8 9 18 18 25 19 17 16 17 18 3 10 17 6 17 17 18 8 30\n"" + + ""54 16 6 14 14 14 18 15 12 29 10 14 28 15 15 14 25 28 14 23 8 14 15 14 2 15 15 28 14 15 22 14 14 14 20 16 14 18 27 15 18 20 14 15 19 18 13 16 9 1 30 14 15 14 24 15 28\n"" + + ""51 3 2 21 11 10 1 15 10 20 22 8 11 3 29 21 25 24 10 28 23 8 20 3 2 29 7 0 16 24 24 21 9 2 29 16 4 27 4 28 5 9 23 23 2 13 22 25 3 0 15 8 18 5\n"" + + ""66 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"" + + ""7 0 2 5 1 15 3 28 2 6\n"" + + ""8 0 5 29 0 25 15 28 27 28 22\n"" + + ""62 15 5 17 27 13 11 12 14 11 26 11 14 11 16 14 17 11 1 12 11 6 11 24 1 29 15 9 12 10 2 14 12 6 10 22 19 12 6 0 12 11 11 11 12 26 11 11 11 11 28 21 11 11 7 9 6 11 12 1 19 21 30 22 11\n"" + + ""58 28 9 7 24 24 14 24 23 25 24 23 24 24 24 20 23 23 16 23 28 4 23 18 23 24 24 24 30 24 24 23 23 17 24 23 23 16 18 27 29 1 28 24 23 23 10 19 23 24 27 23 23 21 23 23 13 23 23 17 9\n"" + + ""1 0 8 20\n"" + + ""96 47 1 24 22 14 18 4 27 30 1 23 1 1 12 1 3 7 1 5 6 4 22 13 30 4 28 15 29 24 6 16 22 21 25 30 9 17 6 18 1 30 28 30 2 18 27 3 26 19 27 26 11 0 15 15 4 7 8 6 22 18 24 5 21 9 23 0 21 15 25 10 29 28 19 21 24 28 21 10 15 13 27 29 8 7 29 3 3 5 6 22 22 5 25 2 26 0 13\n"" + + ""64 25 5 20 12 11 12 11 12 18 5 12 21 11 27 24 11 26 12 12 12 11 12 10 12 23 18 11 4 27 17 12 11 20 21 2 0 12 12 13 11 11 11 12 24 12 27 10 14 24 17 15 15 11 5 11 26 11 23 11 11 12 12 12 27 11 26\n"" + + ""75 7 9 23 25 19 29 21 23 17 24 24 13 23 1 24 27 24 24 23 23 30 5 23 9 23 14 8 1 14 24 24 10 24 22 23 26 16 24 24 24 27 29 24 24 24 8 24 1 6 23 23 5 23 25 23 23 24 8 24 14 23 7 25 24 1 23 23 21 23 16 10 24 1 23 23 24 24\n"" + + ""75 45 1 3 14 27 14 21 10 24 16 9 16 24 6 22 22 30 3 30 8 15 15 23 30 25 2 23 27 7 28 14 13 19 9 30 23 22 9 12 27 1 8 3 7 9 8 16 23 19 15 13 24 8 8 24 5 2 15 26 18 8 0 12 3 27 15 6 6 8 4 30 11 13 30 8 7 27\n"" + + ""61 47 9 7 25 27 16 8 17 1 18 13 21 23 13 4 9 15 26 3 27 23 24 22 10 0 30 12 18 12 19 27 11 28 3 23 30 17 28 7 26 18 7 21 7 17 13 16 26 8 8 15 4 12 24 16 15 29 14 6 25 10 20 30\n"" + + ""80 54 1 25 29 17 30 5 26 6 23 9 9 16 0 22 3 13 1 5 10 16 3 2 8 3 17 24 23 18 21 22 6 21 10 12 4 24 14 30 22 29 30 5 1 4 2 22 20 6 22 27 12 5 5 29 16 8 30 18 2 3 30 5 2 0 7 15 5 2 28 4 4 28 30 22 13 28 12 16 4 17 5\n"" + + ""76 40 7 25 25 12 18 0 22 4 12 24 1 12 21 16 20 23 23 30 27 6 23 0 1 7 8 28 10 29 5 22 22 2 23 28 14 29 18 0 14 23 13 8 18 28 12 25 14 18 7 16 8 4 25 24 12 6 2 1 7 24 8 19 19 7 24 21 10 9 6 10 4 12 22 3 30 22 10\n"" + + ""15 8 9 23 26 23 23 0 24 24 23 14 23 24 24 23 21 23\n"" + + ""17 1 8 9 21 20 20 20 21 21 20 21 21 20 20 3 8 12 21 20\n"" + + ""11 0 2 10 10 14 4 2 16 22 4 2 18 20\n"" + + ""31 1 7 20 3 6 7 29 6 1 10 15 4 16 25 7 1 7 30 19 15 26 13 24 1 14 19 18 21 2 3 20 5 3\n"" + + ""11 2 6 15 14 17 14 26 14 14 20 15 2 15\n"" + + ""42 0 10 30 10 21 7 0 24 26 19 2 11 21 14 1 28 4 10 16 20 28 2 11 14 5 14 28 6 8 6 28 0 22 13 1 1 9 27 17 22 16 28 29 18\n""; + + String[] lines = input.split(""\n""); + int T = Integer.parseInt(lines[0]); + for (int i = 1; i <= T; i++) { + String line = lines[i]; + String[] items = line.split("" ""); + int n = Integer.parseInt(items[0]); + int s = Integer.parseInt(items[1]); + int p = Integer.parseInt(items[2]); + + int[] t = new int[n]; + for (int j = 0; j < n; j++) { + t[j] = Integer.parseInt(items[3 + j]); + } + + int solution = solve(n, s, p, t); + System.out.println(""Case #"" + i + "": "" + solution); + } + } +} +" +A20639,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class B { + + public static void main(String[] args) { + String line; + String filename1 = ""B-large.in""; + String filename2 = ""B-large.out""; + BufferedReader input; + BufferedWriter output; + int counter = 0; + try { + input = new BufferedReader(new FileReader(filename1)); + output = new BufferedWriter(new FileWriter(filename2)); + while ((line = input.readLine()) != null) { + if (counter == 0) { + } else { + String[] arrayS = line.split(""\\s""); + int N = Integer.parseInt(arrayS[0]); + int surprises = Integer.parseInt(arrayS[1]); + int passingPoint = Integer.parseInt(arrayS[2]); + int reducedPass = passingPoint - 1; + int success = 0; + boolean permazas = false; + for (int i = 3; i < arrayS.length; i++) { + if (reducedPass - 1 < 0) { + reducedPass = 0; + permazas = true; + } + int temp = (Integer.parseInt(arrayS[i]) - passingPoint) - (reducedPass * 2); + // System.out.println(temp); + if (temp < 0 && surprises > 0) { + if (temp + 2 >= 0 && !permazas) { + surprises--; + success++; + } + } + if (temp >= 0) { + success++; + } + } + output.write(""Case #"" + counter + "": "" + success + ""\n""); +// System.out.println(""result:"" + success); + } + counter++; + } + input.close(); + output.close(); + } catch (IOException e1) { + System.exit(1); + } + } +} +" +A22002,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package Codejam2012; + +import java.io.*; + +/** + * + * @author Brian + */ +public class googlers { + + public static void main(String [] args) throws FileNotFoundException, IOException{ + + String data; + String printout=""""; + String [] output; + + int numOfGooglers; + int numOfSurprising; + int leastScore; + int [] scores; + String [] splitData; + + String inputFileName = ""C:/input/googlersIn.txt""; + String outputFileName = ""C:/input/googlersOut.txt""; + + BufferedReader reader = new BufferedReader(new FileReader(inputFileName)); + FileWriter out = new FileWriter(outputFileName); + PrintWriter print = new PrintWriter(out); + + data = reader.readLine(); + int size = Integer.parseInt(data); + output = new String[size]; + data = reader.readLine(); + int k =0; + while(data!=null){ + + splitData = data.split(""\\s""); + numOfGooglers = Integer.parseInt(splitData[0]); + numOfSurprising = Integer.parseInt(splitData[1]); + leastScore = Integer.parseInt(splitData[2]); + scores = new int[numOfGooglers]; + for(int b=3;b= minScore){ + total ++; + } + } + } + else{ + for(int a=0;a=minScore){ + greatCount++; + } + + if(scores[a]>=minScore_alt){ + obvious++; + } + } +// for(int a=0;a=2 && scores[a]=numOfSurprising){ + total = obvious + numOfSurprising; + } + else{ + total = greatCount; + } + + } + + output[k++] = String.valueOf(total); + + data = reader.readLine(); + } + + for(int p=0; p list = new ArrayList(); + for (int ts : totalScores) { + list.add(ts); + } + Collections.sort(list); + for (Integer i : list) { + // Find possible score outcome, check if it contains any number >=minScore + if (containsHighScore(i)) { + runningTotal++; + } + } + + return runningTotal; + } + + private boolean containsHighScore(int totalScore) { + int mod = totalScore % 3; + if (totalScore == 0) { + if (minScore > 0) + return false; + else if (minScore == 0) + return true; + } + if (mod == 0) { + if ((((double)totalScore)/3) >= minScore) { + return true; + } else if ((((double)totalScore)/3+1) >= minScore && numSurprisingScores > 0) { + numSurprisingScores--; + return true; + } + } else if (mod == 1) { + if (Math.ceil(((double)totalScore)/3) >= minScore) { + numPossibleSurprising++; + return true; + } + } else { + if (Math.floor(((double)totalScore)/3) >= minScore || Math.ceil(((double)totalScore)/3) >= minScore) { + numPossibleSurprising++; + return true; + } else if ((Math.ceil(((double)totalScore)/3)+1) >= minScore && numSurprisingScores > 0) { + numSurprisingScores--; + return true; + } + } + numPossibleSurprising++; + return false; + } + + public static Object[] readInput(String[] args) throws IOException { + //String[] str = new String[101]; + ArrayList str = new ArrayList(); + int numStrings = 0; + + // Buffer the input data + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + // Read the data and store in a string array + while (in.ready()) { + str.add(in.readLine()); + numStrings++; + } + in.close(); + + return str.toArray(); + } +} +" +A20595,"package problemB; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class ProblemB { + public static void main(String[] args) throws FileNotFoundException { +// Scanner sc = new Scanner(new File(""B-practice.in"")); +// Scanner sc = new Scanner(new File(""B-small.in"")); + Scanner sc = new Scanner(new File(""B-large.in"")); + int cases = sc.nextInt(); + for (int i = 1; i <= cases; i++) { + // do case things here + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int count = 0; + for (int j = 0; j < n; j++) { + int t = sc.nextInt(); + if (p == 0) { + count++; + continue; + } + if (t == 0) { + continue; + } + if (t == 1) { + if (p == 1) { + count++; + } + continue; + } + if (t == 2) { + if (p == 1) { + count++; + } + if (p == 2) { + if (s > 0) { + s--; + count++; + } + } + continue; + } + if (t/3 >= p) { + count++; + continue; + } + if (t/3 == p - 1 && t % 3 != 0) { + count++; + continue; + } + if (s > 0) { + if (t/3 == p-1) { + count++; + s--; + continue; + } + if (t/3 == p-2 && t%3 == 2) { + count++; + s--; + continue; + } + } + } + System.out.format(""Case #%d: %d\n"", i, count); + } + } +} +" +A20233,"/** + ID: jerryma1 + LANG: JAVA + PROG: B + */ + +import java.io.*; +import java.util.*; + +public class B { + static BufferedReader cin, in; + static StringTokenizer tk; + static PrintWriter out; + static int [] d = {0, 1, 4, 7, 10, 13, 16, 19, 22, 25, 28}; + static int [] m = {100, 100, 2, 5, 8, 11, 14, 17, 20, 23, 26}; + static int [] x = new int[3]; + static boolean surprising = false; + static int maxScore; + public static void main (String [] args) throws IOException { + init(); + int numTests = gInt(); + for (int count = 1; count <= numTests; count ++) { + int numPeople = gInt(), numSurprising = gInt(), min = gInt(); + int ans = 0; + for (int count2 = 0; count2 < numPeople; count2 ++) { + int s = gInt(); + //System.out.printf(""%d %d %d\n"", count, count2, s); + maxScore = -100; + surprising = false; + find(0, 0, s); + if (maxScore >= min) { + ans ++; + continue; + } + maxScore = -100; + surprising = true; + find(0, 0, s); + if (maxScore >= min && numSurprising > 0) { + ans ++; + numSurprising --; + } + } + out.printf(""Case #%d: %d\n"", count, ans); + } + quit(); + } + public static int abs (int a, int b) { + if (a > b) + return a - b; + return b - a; + } + public static void find (int cur, int sum, int score) { + if (cur == 3) { + if (sum == score) { + int maxDiff = abs(x[0], x[1]); + int b = abs(x[1], x[2]), c = abs(x[2],x[0]); + if (b > maxDiff) + maxDiff = b; + if (c > maxDiff) + maxDiff = c; + int m = x[0]; + if (x[1] > m) + m = x[1]; + if (x[2] > m) + m = x[2]; + if (surprising && maxDiff == 2) { + if (m > maxScore) + maxScore = m; + } + else if (!surprising && maxDiff < 2) { + if (m > maxScore) + maxScore = m; + } + } + return; + } + for (int count = 0; count <= 10; count ++) { + x[cur] = count; + find(cur + 1, sum + count, score); + } + } + public static int min (int a, int b) { + if (a < b) + return a; + return b; + } + public static void init () throws IOException { + cin = new BufferedReader(new InputStreamReader(System.in)); + in = new BufferedReader(new FileReader(""B.in"")); + tk = new StringTokenizer(""""); + out = new PrintWriter(new BufferedWriter(new FileWriter(""B.out""))); + } + public static void quit () throws IOException { + System.out.flush(); + out.close(); + System.exit(0); + } + public static String token () throws IOException { + while (!tk.hasMoreTokens()) + tk = new StringTokenizer(in.readLine()); + return tk.nextToken(); + } + public static int gInt () throws IOException { + return Integer.parseInt(token()); + } + public static long gLong () throws IOException { + return Long.parseLong(token()); + } + public static double gDouble () throws IOException { + return Double.parseDouble(token()); + } +} +" +A20471,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + + +public class GCIFileReader { + + public GCIFileReader(File file) throws FileNotFoundException { + mBufferedReader = new BufferedReader(new FileReader(file)); + mFile = file; + } + + public String getLine() { + try { + String s = mBufferedReader.readLine(); + if (s == null) + { + mBufferedReader.close(); + } + return s; + } catch (IOException e) { + return null; + } + } + + public void reset () throws IOException + { + mBufferedReader.close(); + mBufferedReader = new BufferedReader(new FileReader(mFile)); + } + + private BufferedReader mBufferedReader; + private File mFile; + +}" +A20495,"import java.util.*; +public class B { + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + + for (int t = 1; t <= T; ++t) + { + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + + int withoutS = 0; // those that got it without an S + int withS = 0; // those that need an S + for (int n = 0; n < N; ++n) + { + int val = in.nextInt(); + if (val/3 >= P || (val/3 == P-1 && val%3 != 0)) ++withoutS; + else if (!(val/3 == 0 && val%3 <= 1) && ((val/3 == P-1 && val%3 == 0) || (val/3 == P-2 && val%3 == 2))) ++withS; + } + + int ans = withoutS + Math.min(withS, S); + System.out.printf(""Case #%d: %d\n"", t, ans); + } + } +} + +/* + +4 +3 1 5 15 13 11 +3 0 8 23 22 21 +2 1 1 8 0 +6 2 8 29 20 8 18 18 21 + +*/ +" +A23045,"package classes; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class Dancing +{ + public static void main(String[] args) + { + try + { + FileInputStream fstream = new FileInputStream(""/Users/jleibsly2002/B-large.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = br.readLine(); + int N = Integer.parseInt(strLine); + + for(int i = 0; i < N; i++) + { + String[] integers = br.readLine().split("" ""); + int num = Integer.parseInt(integers[0]); + int S = Integer.parseInt(integers[1]); + int p = Integer.parseInt(integers[2]); + int[] scores = new int[num]; + for(int j = 3; j < num+3; j++) + { + scores[j-3] = Integer.parseInt(integers[j]); + } + + int count = 0; + + for(int score : scores) + { + if(score==0) + { + if(p==0) + { + count++; + } + } + else + { + int rem = score%3; + if(rem>0) + { + if(rem == 1) + { + int noSurprise = (score/3)+1; + if(noSurprise>=10) + noSurprise=10; + if(noSurprise>=p) + { + count++; + } + } + else if(rem == 2) + { + int noSurprise = (score/3)+1; + if(noSurprise>=10) + noSurprise=10; + if(noSurprise>=p) + { + count++; + } + else if(S>0) + { + int surprise = noSurprise+1; + if(surprise>=p) + { + count++; + S--; + } + } + } + } + else + { + int noSurprise = score/3; + if(noSurprise>=10) + noSurprise=10; + if(noSurprise>=p) + { + count++; + } + else if(S>0) + { + int surprise = noSurprise+1; + if(surprise>=p) + { + count++; + S--; + } + } + } + } + } + + System.out.println(""Case #"" + (i+1) + "": "" + count); + } + + in.close(); + } + catch (Exception e){ + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A22117,"public class DancingWithGooglers { + public static int[] numbers(int given, boolean check, int p) { + int[] solution = new int[3]; + int []answer= new int[2]; + int num = given / 3; + int mod = given % 3; + + solution[0] = num; + int remain = given - num; + int newN = remain / 2; + solution[1] = newN; + solution[2] = remain - newN; + + if (solution[0] >= p || solution[1] >= p || solution[2] >= p) { + answer[0]=1; + answer[1]=0; + return answer; + } + + if (check) { + answer[1]=1; + if ((mod == 0)&&num!=0) { + solution[0] = num - 1; + solution[1] = num; + solution[2] = num + 1; + + } else if ((mod == 1)&&num!=0) { + solution[0] = num - 1; + solution[1] = num + 1; + solution[2] = num + 1; + } else if (mod == 2) { + solution[0] = num; + solution[1] = num; + solution[2] = num + 2; + } + } + + if (solution[0] >= p || solution[1] >= p || solution[2] >= p) { + answer[0]=1; + + return answer; + } + // System.out.println(solution[0]); + // System.out.println(solution[1]); + // System.out.println(solution[2]); + answer[0]=0; + answer[1]=0; + return answer; + + } + + public static void solve(String fname) { + Read r = new Read(); + r.Read(fname); + String fAnswer=""""; + int numOfTest = r.noOfTestCases; + int[] numOfPlayers = r.N; + int[] numOfSurprising = r.S; + int[] ps = r.p; + int[][] nums = r.all; + + for (int i = 0; i < numOfTest; i++) { + int numOfP = numOfPlayers[i]; + int numOfS = numOfSurprising[i]; + int p = ps[i]; + int[] numsCurr = nums[i]; + int surprised = 0; + + int maxNumber = 0; + for (int j = 0; j < numsCurr.length; j++) { + if (surprised < numOfS) { + int []num ; + num = numbers(numsCurr[j], true, p); + maxNumber = maxNumber + num[0]; + surprised = surprised + num[1]; + } else { + int []num ; + num= numbers(numsCurr[j], false, p); + maxNumber = maxNumber + num[0]; + surprised = surprised + num[1]; + } + } + String ans = ""Case #"" + (i + 1) + "": "" +maxNumber; + + fAnswer=fAnswer+ans+""\n""; + } + System.out.println(fAnswer); + r.write(""out"", fAnswer); + } + + public static void main(String[] args) { + solve(""test""); + } +} +" +A21784,"package B; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws IOException { + Scanner sc; + try { + sc = new Scanner(new File(""B"")); + FileWriter writer = null; + try { + writer = new FileWriter(new File(""output"")); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + int nbLines = Integer.parseInt(sc.nextLine()); + int currentLine = 1; + + int nbGooglers; + int surprising; + int p; + String line =""""; + + int currentGoogler; + + int g; + + int quotient; + int reste; + + int res; + while (currentLine <= nbLines) { + writer.write(""Case #""+currentLine+"": ""); + res=0; + currentGoogler = 1; + line = sc.nextLine(); + Scanner scan = new Scanner(line); + nbGooglers=scan.nextInt(); + surprising = scan.nextInt(); + p=scan.nextInt(); + while (currentGoogler <= nbGooglers) { + g = scan.nextInt(); + quotient = g/3; + reste = g % 3; + System.out.println(g + "" "" +quotient + "" "" + p); + if (g == 0 && p > 0) + ; + else if (quotient >= p) + res++; + else { + if ((quotient == (p - 1)) && (reste >= 1)) + res++; + else if (quotient == (p - 2) && (reste == 2) && (surprising != 0)) { + surprising --; + res++; + } + else if (quotient == (p - 1) && (reste == 0) && (surprising != 0)) { + surprising --; + res++; + } + + } + currentGoogler++; + } + writer.write(res + ""\n""); + currentLine++; + } + writer.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} +" +A22271,"import java.io.*; +import java.util.*; + +public class CodeJamB { + public static void main (String[] args) throws IOException { + int i, j, k; + long startTime = System.currentTimeMillis(); + File inFile = new File(""B-large.in""); // File to read from + File outFile = new File(""B-large.out""); + + BufferedReader reader = new BufferedReader(new FileReader(inFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); + + + String line = null; + line = reader.readLine(); + int cases = Integer.parseInt(line); + int counter = 1; + + while ((line=reader.readLine()) != null) { + int googlers = 0; + int N, S, p; + int sur = 0; + String[] node = line.split("" ""); + N = Integer.parseInt(node[0]); + S = Integer.parseInt(node[1]); + p = Integer.parseInt(node[2]); + if(p <= 1) { + for(i = 3; i < node.length; i++) { + if(Integer.parseInt(node[i]) >= p) + googlers++; + } + } else { + for(i = 3; i < node.length; i++) { + if(Integer.parseInt(node[i]) >= (3*p-2)) { + googlers++; + } else if (Integer.parseInt(node[i]) >= (3*p-4)) { + sur++; + } + } + } + googlers += Math.min(S, sur); + writer.write(""Case #""+counter+"": ""+googlers); + writer.newLine(); + counter++; + } + + writer.close(); + long endTime = System.currentTimeMillis(); + long totalTime = endTime - startTime; + System.out.println(""Total Time: "" + totalTime); + } + } +" +A22797," +package problems; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +/** + * + * @author sergeiw + */ +public class B { + + public static String FILE_SEPARATOR = System.getProperty(""file.separator""); + public static String FILE_INPUT_DIR = System.getProperty(""user.dir"") + FILE_SEPARATOR + ""files"" + FILE_SEPARATOR; + public static String FILE_OUTPUT_DIR = System.getProperty(""user.dir"") + FILE_SEPARATOR + ""files"" + FILE_SEPARATOR; + + public static void main(String[] args) throws FileNotFoundException, IOException { + //String filename = ""B-example.in""; + //String filename = ""B-small-attempt0.in""; + //String filename = ""B-small-attempt1.in""; + //String filename = ""B-small-attempt2.in""; + //String filename = ""B-small-attempt3.in""; + //String filename = ""B-small-attempt4.in""; + //String filename = ""B-small-attempt5.in""; + //String filename = ""B-small-attempt6.in""; + String filename = ""B-large.in""; + File fileOut = new File(FILE_INPUT_DIR + filename.replace("".in"", "".out"")); + FileWriter fw = new FileWriter(fileOut); + File file = new File(FILE_INPUT_DIR + filename); + Scanner scanner = new Scanner(file); + try { + int cases = scanner.nextInt(); + scanner.nextLine(); + int casenum = 1; + + + while (scanner.hasNextLine()) { + + int solution = 0; + + + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + int minScore = (p * 3) - 4; + if (minScore < 0) + minScore = p; + + for (int i = 0; i < N; i++) { + int score = scanner.nextInt(); + + for (int q = p; q >= 0; q--) { + if (score > q*3) { + solution++; + print(String.format(""%d %d %d +"", q, q, q )); + break; + } + if (score >= ((q*3-2)) && score <= (q*3)) { + if (q >= p) + solution++; + + if (score == (q*3)-1) + print(String.format(""%d %d %d"", q, q, q-1 )); + else if (score == (q*3)-2) + print(String.format(""%d %d %d"", q, q-1, q-1 )); + else + print(String.format(""%d %d %d"", q, q, q )); + break; + } + if ( score == ((q*3)-4) || score == ((q*3)-3) ) { + print(String.format(""score: %d q: %d"", score, q)); + if (S-1 >= 0 && q >= p && q > 1) { + S--; + if (score == (q*3)-4) + print(String.format(""%d %d %d (*)"", q, q-2, q-2 )); + else + print(String.format(""%d %d %d (*)"", q, q-1, q-2 )); + solution++; + break; + } + + + } + } + print(String.format(""score: %d, min: %d, sol: %d, S: %d"", score, p, solution, S)); + + /*if (score >= minScore) { + if (score == 0 && minScore == 0) { + solution++; + } else { + if ((score == minScore || score == (minScore + 1))) { + print(String.format(""s: %d min: %d"", score, minScore)); + S--; + if (S >= 0) { + solution++; + } + + } else { + solution++; + } + } + } else { + //print(""LOWER""); + for (int q = p - 1; q >= 2; q--) { + if ( score == ((q*3)-4) || score == ((q*3)-3) ) { + S--; + print(String.format(""LOWER: S: %d"", S)); + break; + * + } + } + + } + print(String.format(""score: %d, min: %d, sol: %d, S: %d"", score, minScore, solution, S)); + */ + + } + //if (S < 0) solution = 0; + + print(String.format(""Case #%d: [%s]"", casenum, solution)); + fw.write(String.format(""Case #%d: %s\n"", casenum, solution)); + casenum++; + print(""""); + + } + } finally { + scanner.close(); + fw.close(); + } + + } + + private static void print(String line) { System.out.println(line); }; + private static void print(int num) { print(String.valueOf(num)); }; + + private static void print(int[] arr) { + for(int i=0;i> parse(String fileName) throws IOException { + Map> retval = new HashMap>(); + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + int testCases = Integer.parseInt(reader.readLine()); + for (int i = 1; i <= testCases; i++) { + String[] tokens = reader.readLine().split(""\\s+""); + + long surprises = Long.parseLong(tokens[1]); + long minScore = Long.parseLong(tokens[2]); + + List totals = new ArrayList(); + for (int j = 3; j < tokens.length; j++) { + totals.add(Long.parseLong(tokens[j])); + + } + retval.put(i, new DancingAlgorithm(i, surprises, minScore, totals)); + } + + return retval; + + } + +} +" +A21851,"import java.util.ArrayList; +import java.util.List; + +import Utils.FileHelper; + + +public class Gcj2012b { + + + + private void solve(String inputPath, String filepath) { + + FileHelper fHelper = new FileHelper(inputPath); + + String[] inputStr= new String[fHelper.getTotalSize()]; + + List rstList = new ArrayList(); + + fHelper.init(inputStr); + + for (String str : inputStr) { + rstList.add(this.caculate(str)); + } + + rstList = format(rstList); + + FileHelper.writeFile(filepath, rstList); + } + + + private String caculate(String str) { + String [] inputList = str.split("" ""); + + int rawCnt = 0; + int supCnt = 0; + + int total = Integer.parseInt(inputList[0]); + int suprise = Integer.parseInt(inputList[1]); + int point = Integer.parseInt(inputList[2]); + + int[]inputs = new int[inputList.length - 3]; + + for(int i = 3; i< inputList.length;++i){ + inputs[i - 3] = Integer.parseInt(inputList[i]); + } + + for(int v : inputs){ + int rst = v / 3; + int remain = v % 3; + + if(remain == 0){ + if(rst >= point) rawCnt ++; + else if(rst >= point - 1 && rst >=1) supCnt ++; + }else if(remain == 2){ + if(rst >= point -1)rawCnt ++; + else if(rst >= point -2 && rst >=1) supCnt ++; + }else if(remain == 1){ + if(rst >= point - 1) rawCnt ++; + } + } + + + return rawCnt + Math.min(suprise, supCnt) +""""; + } + + + public static void main(String[] args) { + + Gcj2012b gcj2012b = new Gcj2012b(); + + String inputPath = ""C:\\Users\\xiaohfan\\Desktop\\B-large.in""; + + String filepath = ""C:\\Users\\xiaohfan\\Desktop\\output.txt""; + + gcj2012b.solve(inputPath, filepath); + + } + + + + + public static List format(List rstList) { + + List outputList = new ArrayList(); + + for(int i = 0; i < rstList.size();++i ){ + outputList.add(""Case #""+ (i+1) +"": ""+rstList.get(i)); + } + + return outputList; + } +} +" +A22645,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; + + + + +public class Texter { + + + + + public static void writeText(String text) { + + String fileName = ""output.txt""; + + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true)); + writer.write(text); + writer.newLine(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + + public static String readFile() { + + String fileName = ""test.txt""; + String LS = System.getProperty(""line.separator""); + StringBuffer fileContent = new StringBuffer(); + + try { + FileReader fr = new FileReader(fileName); + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + + + String line; + while ((line = reader.readLine()) != null) { + fileContent.append(line).append(LS); + } + + } catch (IOException e) { + e.printStackTrace(); + } + + return fileContent.toString(); + } + + + + static FileReader fr; + static BufferedReader reader; + + + + public static void setupReader() { + + + String fileName = ""input.txt""; + + + try { + fr = new FileReader(fileName); + reader = new BufferedReader(new FileReader(fileName)); + + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + + public static String readLine() { + + String fileName = ""test.txt""; + String LS = System.getProperty(""line.separator""); + //StringBuffer fileContent = new StringBuffer(); + + String line = null; + + try { + //FileReader fr = new FileReader(fileName); + // BufferedReader reader = new BufferedReader(new FileReader(fileName)); + + + + line = reader.readLine(); + + } catch (IOException e) { + e.printStackTrace(); + } + + + //Will return null at end of file + return line; + } + + + + + public static ArrayList parseNumberList(String input) { + + + int length = input.length(); + ArrayList numbersArray = new ArrayList(); + + + + int numberCount = 0; + + + //Index to start current number at + int noStart = 0; + + + + //First one shouldn't be a space so start ahead + + for (int i = 1; i < length; i++) { + + + //If character is a space that means a number just ended + + if (input.charAt(i) == ' ') { + + + //Get that number + //Substring from startIndex to endIndex -1 + int number = Integer.parseInt(input.substring(noStart, i)); + + + //Add it to array + numbersArray.add(number); + + //Increment count + numberCount++; + + //Set new number start index to one after the space we just had + noStart = i + 1; + + + + + } + + + //Add last number + if (i == length - 1) { + + + //Get that number + //Substring from startIndex to endIndex -1 + int number = Integer.parseInt(input.substring(noStart, length)); + + + //Add it to array + numbersArray.add(number); + + + } + + + + + } + + + return numbersArray; + + + + + } + + + +} +" +A20096,"import java.util.*; +import java.io.*; + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) throws IOException { + new Dancing().run(); + } + + Integer[] best = new Integer[31]; + int best(int x) { + if (best[x] != null) + return best[x]; + for (int l = 0; l <= Math.min(x, 8); l++) { + for (int m = l; m <= l + 2 && m + l <= x; m++) { + int h = l + 2; + if (l + m + h == x) { + best[x] = h; + } + } + } + if (best[x] == null) + best[x] = -1; + return best[x]; + } + + void run() throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(System.out); + + for (int i = 0; i <= 30; i++) + System.err.println("""" + i + "","" + best(i) + "","" + ((i + 2) / 3)); + + int T = nextInt(); + for (int tt = 0; tt < T; tt++) { + int n = nextInt(), s = nextInt(), p = nextInt(); + + int ans = 0; + ArrayList list = new ArrayList(); + for (int i = 0; i < n; i++) { + int x = nextInt(); + if (x < 2) { + if (x >= p) + ans++; + } else if (x > 28) { + ans++; + } else { + list.add(x); + } + } + + Integer[] arr = new Integer[0]; + arr = list.toArray(arr); + + Arrays.sort(arr); + + int rem = s; + for (int i = 0; i < arr.length; i++) { + int x = arr[i]; + if (best(x) >= p && (x + 2) / 3 < p && rem > 0) { + ans++; + rem--; + } else if ((x + 2) / 3 >= p) { + ans++; + } + } + + System.out.println(""Case #"" + (tt + 1) + "": "" + ans); + } + + out.close(); + } + + BufferedReader br; + StringTokenizer st; + PrintWriter out; + + String next() throws IOException { + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(br.readLine()); + } + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + +} +" +A22688,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class Dancing { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, IOException { + + BufferedReader br= new BufferedReader(new FileReader(""C:\\codejam\\B-large.in"")); + int cases=Integer.parseInt(br.readLine()); + int i=0; + FileWriter wr=new FileWriter(""c:\\codejam\\output.txt""); + for(;cases>0;cases--) + { + StringTokenizer values=new StringTokenizer(br.readLine()); + int n=Integer.parseInt(values.nextToken()); + int s=Integer.parseInt(values.nextToken()); + int p=Integer.parseInt(values.nextToken()); + int c=0; + int bestscore=p*3-2>0?p*3-2:0; + int surprisingscore=p*3-4>1?p*3-4:1; + + while(n>0) + { + int t=Integer.parseInt(values.nextToken()); + if(bestscore<=t) + { + c++; + } + else if(s!=0&&surprisingscore<=t) + { + s--; + c++; + } + n--; + } + i++; + wr.write(""Case #""+i+"": ""+c+""\n""); + } + wr.close(); + + } + +} +" +A20112,"import java.util.*; + +public class Dancing { + private static Scanner s = new Scanner(System.in); + + public static void main(String[] args) { + int T = s.nextInt(); + + for (int t = 0; t < T; t++) { + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + + int[] sums = new int[N]; + boolean[] satisfied = new boolean[N]; + + for (int i = 0; i < N; i++) sums[i] = s.nextInt(); + + for (int i = 0; i < N; i++) { + int low = Math.max(p - 1, 0); + if (p + low * 2 > sums[i]) continue; + satisfied[i] = true; + } + + for (int i = 0; i < N; i++) { + if (S == 0) break; + if (satisfied[i]) continue; + int low = Math.max(p - 2, 0); + if (p + low * 2 > sums[i]) continue; + satisfied[i] = true; + S--; + } + + int max = 0; + for (int i = 0; i < N; i++) + if (satisfied[i]) + max++; + + System.out.printf(""Case #%d: %d\n"", t + 1, max); + } + } +} +" +A21102,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.StreamTokenizer; +import java.util.ArrayList; +import java.util.Collections; + + +public class Dancing { + + public static void main(String[] args) throws Exception { + Dancing object = new Dancing(); + object.solve(object.getClass().getSimpleName().toLowerCase()); + } + + private boolean canHave(int total, int p, boolean surprise) { + int diffMax = 1; + if (surprise) + diffMax = 2; + + for (int t3=p; t3<=10; t3++) + for (int t2diff=0; t2diff<=diffMax; t2diff++) + for (int t1diff=0; t2diff+t1diff<=diffMax; t1diff++) + { + int t2 = t3 - t2diff; + int t1 = t2 - t1diff; + + if (t1 < 0 || t2 < 0) + continue; + + if (t1+t2+t3 == total) + return true; + } + + return false; + } + + private void solve(String filePrefix) throws Exception { + + StreamTokenizer st = new StreamTokenizer(new BufferedReader(new FileReader(filePrefix + "".in""))); + PrintWriter pw = new PrintWriter(new FileWriter(filePrefix + "".out"")); + + st.nextToken(); + int testsCount = (int) st.nval; + + for (int tc=0; tc total = new ArrayList(); + + for (int i=0; i 0 && canHave(total.get(i), p, true)) + { + result++; + s--; + continue; + } + + /* nothing, break */ + break; + } + + pw.write(""Case #"" + (tc+1) + "": "" + result + ""\n""); + } + + pw.flush(); + pw.close(); + + } +} +" +A21440,"package template; + +//standard libraries potentially used: +//Apache commons http://http://commons.apache.org/ +//Google Guava http://code.google.com/p/guava-libraries/ + +import java.util.ArrayList; + + +public class Template { + + public static void main(String[] args) { + + //test(); + //Utils.die(""Done testing""); + + String folder = ""C:\\Users\\Paul Thomson\\Documents\\CodeJam\\DancingWithTheGooglers\\""; + Utils.logfile = folder + ""log.txt""; + String infile = folder + ""large.in""; + String outfile = infile.substring(0, infile.lastIndexOf(""."")) + "".out""; + ArrayList tcList = TestCaseIO.loadFromFile(infile); + //ArrayList tcList = TestCaseIO.mockUp(); + + int numThreads = 1; + if (numThreads == 1) { + TestCaseSolver tcSolver = new TestCaseSolver(tcList, 1); + tcSolver.run(); + } else { + //split into separate lists + ArrayList> tcSubLists = new ArrayList<>(); + for (int i = 0; i < numThreads; i++) { + tcSubLists.add(new ArrayList()); + } + + int i = 0; + for (TestCase tc : tcList) { + tcSubLists.get(i).add(tc); + i++; + if (i == numThreads) { + i = 0; + } + } + + //run each sublist in its own thread + ArrayList threadList = new ArrayList<>(); + int ref = 1; + for (ArrayList tcl : tcSubLists) { + TestCaseSolver tcs = new TestCaseSolver(tcl, ref); + Thread h = new Thread(tcs); + threadList.add(h); + h.start(); + ref++; + } + + //wait for completion + for (Thread h : threadList) { + try { + h.join(); + } catch (InterruptedException ex) { + Utils.die(""InterruptedException waiting for threads""); + } + } + + } + + TestCaseIO.writeSolutions(tcList, outfile); + + double totalTime = 0; + for (TestCase tc : tcList) { + totalTime += tc.getTime(); + } + double avTime = totalTime / (double)tcList.size(); + Utils.sout(""Total compute time "" + String.format(""%.2f"", totalTime) + "" secs.""); + Utils.sout(""Average compute time "" + String.format(""%.2f"", avTime) + "" secs.""); + Utils.sout(""Done.""); + } + + public static void test() { + + } +} +" +A20116,"package GCJ; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class ProblemB { + public static void main(String args[]) throws IOException{ + File file = new File(""I:/res/ACMCS/GCJ/B-large.in""); + File outFile = new File(""I:/res/ACMCS/GCJ/problemB.out.txt""); + FileWriter fw = new FileWriter(outFile); + BufferedWriter bw = new BufferedWriter(fw); + //FileReader fileReader = new FileReader(file); + Scanner in = new Scanner(file); + int cs = in.nextInt(); + int c = 0; + while(cs -- > 0){ + ++ c; + int ans = 0; + int n = in.nextInt(); + int map[] = new int[n]; + int s = in.nextInt(); + int p = in.nextInt(); + for(int i = 0; i < n; ++ i) + map[i] = in.nextInt(); + ans = ProblemB.ans(map, s, p); + bw.write(""Case #""); + bw.write(String.valueOf(c)); + bw.write("": ""); + bw.write(String.valueOf(ans)); + bw.newLine(); + } + bw.close(); + } + + public static int suprise(int triSco){ + int max = (triSco + 4) / 3 + 1; + int min = triSco / 3 -1 > 0 ? triSco / 3 -1 : triSco / 3; + int sco = 0; + for(int i = max; i >= min; -- i){ + sco = triSco - i; + for(int j = (sco + 2) / 2 + 1; j >= (sco) / 2 - 1; -- j){ + int k = sco - j; + if(Math.abs(i - j) <= 2 && Math.abs(i - k) <= 2 && Math.abs(j - k) <= 2 && i >= 0 && j >= 0 && k >= 0) + return Math.max(Math.max(i, j), k); + } + } + return max; + } + + public static int nonSuprise(int triSco){ + int max = (triSco + 2) / 3 + 1; + int min = triSco / 3 - 1; + int sco = 0; + for(int i = max; i >= min; -- i){ + sco = triSco - i; + for(int j = (sco + 1) / 2 + 1; j >= (sco) / 2 - 1; -- j){ + int k = sco - j; + if(Math.abs(i - j) <= 1 && Math.abs(i - k) <= 1 && Math.abs(j - k) <= 1 && i >= 0 && j >= 0 && k >= 0) + return Math.max(Math.max(i, j), k); + } + } + return max; + } + + public static int ans(int map[], int s, int p){ + int max = 0; + for(int i : map){ + if(nonSuprise(i) >= p) + ++ max; + else if(suprise(i) >= p && s > 0){ + ++ max; + -- s; + } + } + return max; + } + +} +" +A20557,"import java.util.Scanner; + + +public class Main { + + static int solve( Scanner in ) { + int N, S, p, ti, sol=0; + double div = 0.0; + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + double req = 0.0; + double min = 0.0; + if(p>0) { + req = (p*3-2)/3.0; + if(p==1) + min = 1.0/3.0; + else + min = (p*3-4)/3.0; + } + while(N-->0) { + ti = in.nextInt(); + if(ti>0) + div = ti/3.0; + else + div = 0.0; + if(div>=req) { + sol++; + }else if( S>0 && div>=min ) { + S--; + sol++; + } + } + return sol; + } + + public static void main ( String args[] ) { + int T; + Scanner in = new Scanner(System.in); + T = in.nextInt(); + int cnt=0; + int sol; + for( cnt=1; cnt<=T; cnt++ ) { + sol = solve( in ); + System.out.printf(""Case #%d: %d\n"", cnt, sol); + } + + } +} +" +A22312,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Scanner; + +public class Main { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + Scanner input = new Scanner(new File(""B-large.in"")); + FileWriter out = new FileWriter(""out.txt""); + + int lineNumber = input.nextInt(); + input.nextLine(); + for (int i = 0; i < lineNumber; i++) { + String solution = ""Case #"" + (i + 1) + "": ""; + int n = input.nextInt(); + int s = input.nextInt(); + int p = input.nextInt(); + int max = 0; + int upperLimit = p * 3 - 2; + int lowerLimit = p * 3 - 4; + for (int j = 0; j < n; j++) { + int sum = input.nextInt(); + if (p == 1 && sum >= 1) { + max++; + } else if (sum >= upperLimit && sum>p) { + max++; + } else if (sum >= lowerLimit && s > 0 && sum>p) { + s--; + max++; + } + } + if(p==0) + max = n; + solution += max; + solution += System.getProperty(""line.separator""); + ; + out.write(solution); + } + + out.close(); + input.close(); + } + +} +" +A22735,"package google2012; + + +import java.io.*; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class DancingGooglers { + + private Map dic = new HashMap<>(); + + protected BufferedReader reader; + protected BufferedWriter writer; + protected Scanner in; + + public static BufferedReader openReader(String inputFile) throws IOException { + FileInputStream fis = new FileInputStream(new File(inputFile).getAbsoluteFile()); + return new BufferedReader( + new InputStreamReader(fis, ""UTF-8"") + ); + } + + public static BufferedWriter openWriter(String outputFile) throws IOException { + File file = new File(outputFile); + + FileOutputStream fos = new FileOutputStream(file.getAbsoluteFile()); + return new BufferedWriter( + new OutputStreamWriter(fos, ""UTF-8"") + ); + } + + public DancingGooglers(String fileName) throws IOException { + init(fileName); + } + + protected void init(String fileName) throws IOException { + String in = fileName; + String out = in.replace("".in"", "".out""); + reader = openReader(in); + this.in = new Scanner(reader); + writer = openWriter(out); + } + + public void close() { + + try { + in.close(); + } catch (Exception e) { + // ignore + } + + try { + if (reader != null) { + reader.close(); + } + } catch (IOException e) { + //ignore + } + try { + if (writer != null) { + writer.close(); + } + } catch (IOException e) { + //ignore + } + } + + + public void write(int caseNumber) throws IOException { + write(""Case #"" + caseNumber + "":""); + } + + public void write(int caseNumber, String val) throws IOException { + write(""Case #"" + caseNumber + "": "" + val); + } + + public void write(String val) throws IOException { + writer.write(val + ""\n""); + writer.flush(); + } + + public void execute() { + try { + + long startProblem = System.currentTimeMillis(); + int T = in.nextInt(); + System.out.println(""Tests:"" + T); + for (int i = 1; i <= T; i++) { + long startCase = System.currentTimeMillis(); + String result = calculate(in.nextInt(), in.nextInt(), in.nextInt()); + System.out.println(""case:"" + i + "" took: "" + (System.currentTimeMillis() - startCase) + "", ms""); + write(i, """" + result); + } + System.out.println(""Took: "" + (System.currentTimeMillis() - startProblem) + "", ms""); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + close(); + } + } + + + private String calculate(int N, int S, int p) { + int count = 0; + for (int i = 0; i < N; i++) { + int t = in.nextInt(); + if (t == 0) { + if (p == 0) { + count++; + } + continue; + } + + int avg = t / 3; + if (avg * 3 == t) { + if (avg >= p) { + count++; + } else if (avg + 1 >= p) { + if (S > 0) { + count++; + S--; + } + } + } else { + if (avg + 1 >= p) { + count++; + } else if (avg + 2 >= p && t != 1) { + if (S > 0) { + count++; + S--; + } + } + } + } + return """" + count; + } + + + public static void main(String[] args) throws Exception { +// String fileName = ""test.in""; +// String fileName = ""B-small-attempt2.in""; + String fileName = ""B-large.in""; + DancingGooglers problem = new DancingGooglers(fileName); + problem.execute(); + } +} +" +A22479,"import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class Main { + + + public static void main(String[] args) { +try{ + int no, i, valuemax, surprise, p, n, j, temp; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + no = Integer.parseInt(br.readLine()); + for (i = 0; i < no; i++) { + int answer = 0; + String str=br.readLine(); + StringTokenizer tok=new StringTokenizer(str,"" ""); + n = Integer.parseInt(tok.nextToken()); + surprise = Integer.parseInt(tok.nextToken()); + p = Integer.parseInt(tok.nextToken()); + for (j = 0; j < n; j++) { + temp = Integer.parseInt(tok.nextToken()); + if (temp == 0) { + if (p != 0) { + continue; + } else { + answer++; + } + continue; + } + if (temp % 3 == 0) { + valuemax = temp / 3; + if (valuemax >= p) { + answer++; + } else if ((valuemax + 1 >= p) && (surprise != 0)) { + answer++; + surprise--; + } + + } + if (temp % 3 == 1) { + valuemax = (temp / 3) + 1; + if (valuemax >= p) { + answer++; + } + } + if (temp % 3 == 2) { + valuemax = (temp / 3) + 1; + if (valuemax >= p) { + answer++; + } else if ((valuemax + 1 >= p) && (surprise != 0)) { + answer++; + surprise--; + } + } + } + System.out.print(""Case #"" + (i + 1) + "": "" + answer); + if ((i + 1) != no) { + System.out.print(""\n""); + } + } + }catch(Exception e){ + System.out.println(e.toString()); + } + } +} +" +A21265,"import java.util.*; +public class problemB +{ + public static void main(String[]args) + { + Scanner scanner = new Scanner(System.in); + int N = scanner.nextInt(); + for(int num=1;num<=N;num++) + { + int cnt = scanner.nextInt(); + int suprise = scanner.nextInt(); + int reach = scanner.nextInt(); + final int not = 2*(reach>=2?(reach-2):0)+reach; + final int sup = 2*(reach>=1?(reach-1):0)+reach; + int res = 0; + int points[] = new int[cnt]; + for(int i=0;ipoint) + { + if(suprise>0) + res++; + suprise--; + continue; + } + res++; + } + System.out.println(""Case #""+num+"": ""+res); + } + } +} +" +A20121,"package atm; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.*; +/** + * + * @author Antonio Lievano + */ +public class Googlers { + public static void main (String[]Args) throws FileNotFoundException { + FileReader reader = new FileReader(""C:\\Users\\Antonio Lievano\\Desktop\\B-large.in""); + Scanner in = new Scanner(reader); + int cases = Integer.parseInt(in.nextLine()); + for (int i = 0; i((p*3)-3)) { + points[j] = -9999999; + answer++; + } + } + for (int k = 0; k((p*3)-5)){ + points[k] = -9999999; + answer++; + counter++; + } + } + System.out.print(answer); + System.out.println(); + } +} +}" +A20332,"package com.dten.cj.qual; + +import static java.lang.Integer.parseInt; +import static java.lang.Math.max; +import static java.lang.Math.min; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.FileUtils; + +public class B { + + public static final int NotSurprising = 0; + public static final int Surprising = 1; + public static final int Impossible = -2; + + private int N; + private int S; + private int p; + private int[] scores; + + public int evaluate(int i, int j, int k) { + int diff = max(i,max(j,k)) - min(i,min(j,k)); + if (diff == 0 || diff == 1 ) + return NotSurprising; + if(diff == 2) + return Surprising; + if(diff > 2) + return Impossible; + return -1; + } + + public int evaluate(int[] triple) { + if (triple.length != 3) + return Impossible; + return evaluate(triple[0], triple[1], triple[2]); + } + + public int processLine(String string) { + String[] split = string.split("" ""); + if (split.length < 4) + return -1; + + N = parseInt(split[0]); + S = parseInt(split[1]); + p = parseInt(split[2]); + scores = new int[split.length - 3]; + for (int i = 0; i < scores.length; i++) { + scores[i] = parseInt(split[i + 3]); + } + N = parseInt(split[0]); + + List possibleCombos = new ArrayList(); + for (int i = 0; i < scores.length; i++) { + possibleCombos.add(possibleScores(scores[i])); + } + + int non = 0; + int surp = 0; + int fail = 0; + + for (int[][] ps : possibleCombos) { + if(hasNonsurprisingTripleAbove(ps)) + non++; + else if (hasSurprisingTripleAbove(ps)) + surp++; + else + fail++; + } + + return non + min(S, surp); + + } + + public boolean hasNonsurprisingTripleAbove(int[][] ps) { + for (int[] triple : ps) { + if (max(triple[0], max(triple[1], triple[2])) >= p + && evaluate(triple) == NotSurprising) { + return true; + } + } + return false; + } + + public boolean hasSurprisingTripleAbove(int[][] ps) { + for (int[] triple : ps) { + if (max(triple[0], max(triple[1], triple[2])) >= p + && evaluate(triple) == Surprising) { + return true; + } + } + return false; + } + + public int[][] possibleScores(int score) { + ArrayList list = new ArrayList(); + for (int i = 0; i <= 10; i++) + for (int j = 0; j <= i; j++) + for (int k = 0; k <= j; k++) + if (k + j + i == score && evaluate(i, j, k) > -1) + list.add(new int[] { k, j, i }); + return list.toArray(new int[list.size()][]); + } + + public String processFile(String fileName) { + StringBuilder sb = new StringBuilder(); + int caseCount = 1; + + try (BufferedReader in = new BufferedReader(new FileReader(fileName))) { + String str = in.readLine(); // Skip first + while ((str = in.readLine()) != null) { + sb.append(""Case #"").append(caseCount++).append("": "") + .append(processLine(str)).append(""\r\n""); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return sb.toString().trim(); + } + + public static void main(String[] args) { + B b = new B(); + String fileName = ""B-large""; + + try { + FileUtils.write(new File(""outputs/qual/"" + fileName + "".out""), + b.processFile(""inputs/qual/"" + fileName + "".in"")); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} +" +A21234,"package codejam; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.google.common.base.Splitter; + +public class ProblemB extends CodeJamRunner { + + + private int nrOfCases; + private int testCaseIndex; + int numberOfGooglers; + int surprisingTriplets; + int personalBestBar; + int maxAbovePersonalBestBar; + + private List totalPoints = new ArrayList(); + + public void process(int lineNr, String line) { + if (lineNr == 1) { + nrOfCases = Integer.valueOf(line); + resetForNextCase(); + } else { + Iterator split = Splitter.on("" "").split(line).iterator(); + numberOfGooglers = Integer.parseInt(split.next()); + surprisingTriplets = Integer.parseInt(split.next()); + personalBestBar = Integer.parseInt(split.next()); + while ( split.hasNext() ) { + totalPoints.add(Integer.parseInt(split.next())); + } + calc(); + write(); + resetForNextCase(); + } + } + + private void write() { + String resultLine = ""Case #"" + testCaseIndex + "": "" + maxAbovePersonalBestBar; + printlnOutput(resultLine); + } + + private void calc() { + int normalAboveCount = 0; + int surpriseAboveCount = 0; + for ( int i : totalPoints ) { + Triplet t = new Triplet( i ); + if ( t.calcMaxNormal() >= personalBestBar ){ + normalAboveCount++; + } + else if ( t.calcMaxSurprise() >= personalBestBar ){ + surpriseAboveCount++; + } + } + int surprisesHappened = Math.min(surpriseAboveCount, surprisingTriplets ); + maxAbovePersonalBestBar = normalAboveCount + surprisesHappened; + } + + private void resetForNextCase() { + testCaseIndex++; + totalPoints.clear(); + } + + public static void main(String args[]) { + ProblemB ao = new ProblemB(); + ao.run(args); + } + +} +" +A20375,"package qualification2012; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.StringTokenizer; + + +public class B { + + private final String f = ""src\\qualification2012\\B-large""; + private BufferedReader in; + private PrintWriter out; + private StringTokenizer token; + + + + private B() throws IOException { + in = new BufferedReader(new FileReader(f+"".in"")); + out = new PrintWriter(f + "".out""); + eat(""""); + + int t = nextInt(); + for (int i = 1; i <= t; i++) { + write(""Case #""+i+"": ""); + solve(); + } + + in.close(); + out.close(); + } + + private void solve() throws IOException { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + + + int scores = 0; + + int[] googlers = new int[n]; + for (int i = 0; i < n; i++) { + googlers[i] = nextInt(); + } + + int possibles = 0; + for (int i = 0; i < googlers.length; i++) { + int g = googlers[i]; + + if (g >= 3*p - 2 && g >= p) { + scores++; + } else if (g >= 3*p - 4 && g >= p) { + possibles++; + } + } + + scores += ((s <= possibles)? s : possibles); + write(scores + ""\n""); + } + + private String nextLine() throws IOException { + return in.readLine(); + } + + private String next() throws IOException { + while (!token.hasMoreTokens()) { + String line = in.readLine(); + if (line == null) { + return null; + } + eat(line); + } + return token.nextToken(); + } + + private int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + private long nextLong() throws IOException { + return Long.parseLong(next()); + } + + private void eat(String s) { + token = new StringTokenizer(s); + } + + private void write(String s) { + System.out.print(s); + out.print(s); + } + + public static void main(String[] args) { + try { + new B(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + +" +A22817,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.StringTokenizer; + + + +public class RQB { + + private static BufferedReader in; + private static PrintWriter out; + private static StringTokenizer input; + + + public static void main(String[] args) throws IOException { + //Initializing ... + + int [] maxa = new int[31];int a =0;int b =1; + for (int i = 1; i <= 30; i++) { + maxa[i]=b;a++;if(a==3){a=0;b++;} + } + int [] maxb = new int[31];a =0;b =2; + for (int i = 2; i <= 30; i++) { + maxb[i]=b;a++;if(a==3){a=0;b++;} + } + new RQB(); + //------------------------------------------------------------------------- + int testCases = nextInt(); + int counter=0; + while (testCases -- > 0){ + counter++; + //Here put the code..:) + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int [] ns = new int[n]; + for (int i = 0; i < ns.length; i++)ns[i]=nextInt(); + Arrays.sort(ns); + int ret = 0; + for (int i = 0; i < ns.length; i++) { + if(maxa[ns[i]]>=p){ret++;continue;} + if(s>0){ + if(ns[i]>=2&&ns[i]<=28){ + if(maxb[ns[i]]>=p){s--;ret++;} + }else{ + if(maxa[ns[i]]>=p)ret++; + } + }else{ + if(maxa[ns[i]]>=p)ret++; + } + } + + writeln(""Case #""+counter+"": ""+ret); + } + //------------------------------------------------------------------------- + //closing up + end(); + //-------------------------------------------------------------------------- + + } + + public RQB() throws IOException { + //Input Output for Console to be used for trying the test samples of the problem + in = new BufferedReader(new InputStreamReader(System.in)); +// out = new PrintWriter(System.out); + //------------------------------------------------------------------------- + //Input Output for File to be used for solving the small and large test files +// in = new BufferedReader(new FileReader(""RQB.in"")); + out = new PrintWriter(""RQB.txt""); + //------------------------------------------------------------------------- + //Initalize Stringtokenizer input + input = new StringTokenizer(in.readLine()); + } + + private static int nextInt() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return Integer.parseInt(input.nextToken()); + } + private static long nextLong() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return Long.parseLong(input.nextToken()); + } + private static double nextDouble() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return Double.parseDouble(input.nextToken()); + } + private static String nextString() throws IOException { + if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); + return input.nextToken(); + } + private static void write(String output){ + out.write(output); + out.flush(); + } + private static void writeln(String output){ + out.write(output+""\n""); + out.flush(); + } + private static void end() throws IOException{ + in.close(); + out.close(); + System.exit(0); + } + +} +" +A22293,"import java.io.*; +public class DancingWithTheGooglers { + + public static void main(String[] args)throws IOException { + BufferedReader bfr = new BufferedReader( + new InputStreamReader(System.in)); + PrintWriter pr = new PrintWriter(System.out); + int n = Integer.parseInt(bfr.readLine()); + for (int i = 1 ;i<=n;i++){ + String input []= bfr.readLine().split("" ""); + int googlers = Integer.parseInt(input[0]); + int surprise = Integer.parseInt(input[1]); + int max = Integer.parseInt(input[2]); + int happens =0; + for (int j =0;j=max||score[1]>=max||score[2]>=max) + happens++; + else if (score[0]==score[2]){ + if(score[0]+1>=max&&score[0]-1>=0) + if (surprise>0){ + happens++; + surprise--; + } + }else if (score[1]==score[2]&&score[0]-1>=0){ + if(score[1]+1>=max) + if (surprise>0){ + happens++; + surprise--; + } + } + + } + pr.printf(""Case #%d: %d\n"", i,happens); + pr.flush(); + } + + } + +} +" +A20717,"package com.codejam.twelve; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class ProbB { + public static void main(String[] args) throws IOException { + FileReader fr = new FileReader( + ""D:\\Dev\\Workspaces\\Android\\codejam\\io\\qualification\\B-large.in""); + FileWriter fw = new FileWriter( + ""D:\\Dev\\Workspaces\\Android\\codejam\\io\\qualification\\B-large.out""); + BufferedReader br = new BufferedReader(fr); + BufferedWriter bw = new BufferedWriter(fw); + + int t = Integer.parseInt(br.readLine()); + + for (int i = 1; i <= t; i++) { + String s = br.readLine(); + bw.append(""Case #"" + i + "": ""); + + String ss[] = s.split("" ""); + int nn[] = new int[ss.length]; + for (int j = 0; j < ss.length; j++) { + nn[j] = Integer.parseInt(ss[j]); + } + + int N = nn[0]; + int S = nn[1]; + int P = nn[2]; + int sa=0; + int na=0; + + for (int j = 0; j < N; j++) { + int trip = nn[3+j]; + int remain = trip-P; + if(remain<0) + continue; + int other = P-(remain/2); + + if(other==2){ + sa++; + } + else if(other<2){ + na++; + } + } + + if(sa>=S) + sa=S; + + bw.append(""""+(na+sa)); + + bw.newLine(); + } + + bw.flush(); + bw.close(); + br.close(); + } +} +" +A21984,"package edu.tamu.dwang089; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.*; + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + // TODO Auto-generated method stub + String string = """"; + + try { + //use buffering, reading one line at a time + //FileReader always assumes default encoding is OK! + BufferedReader input = new BufferedReader(new FileReader(""input.in"")); + try { + String line = null; //not declared within while loop + int num = 0; + + /* + * readLine is a bit quirky : + * it returns the content of a line MINUS the newline. + * it returns null only for the END of the stream. + * it returns an empty String if two newlines appear in a row. + */ + line = input.readLine(); + while (( line = input.readLine()) != null) { + //System.out.println(line); + int result = 0; + String[] strings = line.split("" ""); + int count = Integer.parseInt(strings[0]); + int surprise = Integer.parseInt(strings[1]); + int score = Integer.parseInt(strings[2]); + + List scores = new ArrayList<>(); + for (int i = 3; i < strings.length; i++) { + int value = Integer.parseInt(strings[i]); + scores.add(value); + //System.out.println(value); + } + + for (int i = 0; i < scores.size(); i++) { + int value = scores.get(i); + //System.out.println(value); + if (((value + 2) >= (3 * score)) && (value >= score)) + result++; + else if (((value + 4) >= (3 * score)) && (surprise > 0) && (value >= score)) { + result++; + surprise--; + } + + } + + num++; + System.out.print(""Case #"" + num + "": "" + result); + System.out.println(); + } + + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + } + +} +" +A20100,"package googlecodejam; + +/** + * + * @author ffreakk + */ + +import java.util.Scanner; +import java.lang.Math; +public class Main { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for (int t=1; t<=T; t++){ + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int nSurprises = 0; + int result = 0; + int surpriseScore = 3*p - 4; + int okScore = 3*p - 2; + + int scoreArray[] = new int[N]; + for (int n=0; n= okScore) + result++; + else if (scoreArray[i] >= surpriseScore && scoreArray[i]>0) + nSurprises++; + } + + result += Math.min(nSurprises, S); + System.out.println(""Case #"" +t+ "": "" + result); + } + } + +} +" +A21066,"import java.util.*; +import java.lang.*; +import java.io.*; + +class googler +{ + public static void main(String args[]) + { + try + { + PrintWriter pw=new PrintWriter(""out.txt""); + //creating file reader instance and reading first line + BufferedReader br=new BufferedReader(new FileReader(args[0])); + String line=br.readLine(); + int T=Integer.parseInt(line); //number of test cases T + //------------------------- + for(int i=0;i=p) + //{ + // answer++; + // continue; + //} + int modulo=total%3; + switch(modulo) + { + case 0: + if(x>=p) + { + answer++; + } + else if((x+1)>=p && S>0) + { + answer++; + S--; + } + break; + case 1: + if((x+1)>=p) + answer++; + break; + case 2: + if((x+1)>=p) + { + answer++; + } + else if((x+2)>=p && S>0) + { + answer++; + S--; + } + break; + }//end switch + } + + //System.out.println(""Case #""+(i+1)+"": "" + answer); + + pw.println(""Case #""+(i+1)+"": "" + answer); + /*------------------------**/ + } + br.close(); + pw.close(); + }//end of try + catch(Exception e) + { + System.out.println(""Exception caught: ""+e); + } + } +}" +A22183,"import java.io.*; + +public class Solution { + public static void main(String[] args) throws IOException { + StreamTokenizer in = new StreamTokenizer(new BufferedReader (new FileReader(""input.in""))); + PrintWriter out = new PrintWriter(new File(""output.out"")); + + in.nextToken(); + int t = (int)in.nval; + for (int i = 0; i= p) ? 1 : 0; + else ans += (points[j]/3+1 >= p) ? 1 : 0; + } + for (int j = 0; j0; j++){ + if (points[j]<2 || points[j]>28) continue; + int ost = points[j]%3; + if (ost != 1) { + int current = points[j]/3; + if (ost == 2) current++; + if (current == p-1) { + s--; + ans++; + } + } + } + out.println(ans); + } + out.close(); + } +} +" +A20561," + +import java.io.File; +import java.io.FileReader; +import java.util.Scanner; + +/** + * + * @author Gershom + */ +public class DancingWithGooglers { + + public static void main(String[] args0) { + try { + File f = new File(""example""); + Scanner s = new Scanner(new FileReader(f)); + int num = Integer.parseInt(s.nextLine()); + for (int i = 0; i < num; i++) { + String line = s.nextLine(); + int[] dat = new int[3]; + intList(line, dat); + int numGooglers = dat[0]; + int numSurprising = dat[1]; + int p = dat[2]; + int[] scoresTemp = new int[3 + numGooglers]; + intList(line, scoresTemp); + int[] scores = new int[numGooglers]; + for (int j = 0; j < scores.length; j++) { + scores[j] = scoresTemp[j + 3]; + } + + System.out.println(""Case #"" + (i + 1) + "": "" + + calcNumBest(numSurprising, p, scores)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + static int calcNumBest(int sur, int p, int[] scores) { + int numSurprisingRequired = 0; + int num = 0; + + for (int i = 0; i < scores.length; i++) { + switch (scoreBreakdown(scores[i], p)) { + case 1: + numSurprisingRequired++; + break; + case 2: + num++; + break; + } + } + + return num + Math.min(sur, numSurprisingRequired); + } + + /** + * 0 means target can't be met, 1 means it can be met if it's ""surprising"", + * 2 means it can be met without being surprising. + * @param best + * @return + */ + static int scoreBreakdown(int score, int target) { + //Remaining points assuming target was met + int rem = score - target; + + if (rem < 0) { + return 0; + } + + int otherScores = rem / 2; + + int gap = target - otherScores; + if (gap > 2) { + return 0; + } else if (gap == 2) { + return 1; + } + return 2; + } + + public static void intList(String s, int[] array) { + int index = 0; + String cur = """"; + for (int i = 0; i < s.length() + 1; i++) { + if (i == s.length() || s.charAt(i) == ' ') { + array[index++] = Integer.parseInt(cur); + if (index == array.length) { + break; + } + cur = """"; + } else { + cur += s.charAt(i); + } + } + } +} +" +A20200,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + + +public class Dance { + + /** + * @param args + */ + + static int test(int n, int p, int surp, int [] ds){ + int res=0; + int mean,mod; + + if (p==0) return n; + for(int i=0; i= p + || (mean + 1 >= p && mod >= 1)) {res ++; continue;} + if (((mod==2 && mean +2 >= p) || (mean+1>=p))&& surp > 0) {res ++; surp --; continue;} + } + return res; + } + + public static void main(String[] args) { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int nbtests; + try { + nbtests = new Integer(br.readLine()); + for (int i=0; i dancers; + private int best; + + public Round(Scanner data){ + best = 0; + dancers = new ArrayList(); + num = data.nextInt(); + strange = data.nextInt(); + max = data.nextInt(); + for(int i = 0; i < num; i++){ + dancers.add(data.nextInt()); + } + } + + public int calculate(){ + for(int dancer: dancers){ + if(max * 3 <= dancer){ + best++; + }else if(dancer >= max){ + int score1 = max; + int temp = dancer - max; + int score2 = temp / 2; + if(score1 - score2 == 1){ + best++; + }else if(score1 - score2 == 2 && strange > 0){ + best++; + strange--; + } + } + } + return best; + } +} +" +A21451,"import java.io.*; +import java.util.StringTokenizer; + +public class DancingWithTheGooglers { + static class MyScanner { + BufferedReader br; + StringTokenizer st; + + public MyScanner(String fileName) throws IOException { + br = new BufferedReader(new FileReader(new File(fileName))); + } + + public String nextToken() throws IOException, NullPointerException { + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(br.readLine()); + } + return st.nextToken(); + } + + public String nextString() throws IOException, NullPointerException { + st = null; + return br.readLine(); + } + + public Integer nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + void close() throws IOException { + br.close(); + } + } + + public static void main(String[] args) throws IOException { + final String name = ""B-large""; + MyScanner in = new MyScanner(name + "".in""); + PrintWriter out = new PrintWriter(name + "".txt""); + + int t = in.nextInt(); + for (int i = 1; i <= t; i++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int res = 0; + for (int j = 0; j < n; j++) { + int q = in.nextInt(); + int m = q / 3; + if (q % 3 != 0) { + m++; + } + if (m >= p) { + res++; + } else { + if (s > 0 && q >= p) { + if (q % 3 == 0 || q % 3 == 2) { + m++; + } + if (m >= p) { + s--; + res++; + } + } + } + } + out.println(""Case #"" + i + "": "" + res); + } + + in.close(); + out.close(); + } +} + +" +A20687,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class B { + static BufferedReader br; + static PrintWriter pw; + static StringTokenizer st; + static int k, ch, v = 0; + static int t, n, s, p, tmp; + static String str; + static String[] stray = new String[110]; + static int[] intray = new int[100]; + + String nextToken() throws IOException { + while (st == null || !st.hasMoreTokens()) { + st = new StringTokenizer(br.readLine()); + } + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + char nextChar() throws IOException { + return (char) br.read(); + } + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new FileReader(""input.in"")); + pw = new PrintWriter(""output.out""); + + t = Integer.parseInt(br.readLine()); + + for (int i = 1; i <= t; i++) { + str = br.readLine(); + st = new StringTokenizer(str, "" \t\n\r,.""); + while (st.hasMoreTokens()) { + stray[k] = st.nextToken(); + k++; + } + + n = Integer.parseInt(stray[0]); + s = Integer.parseInt(stray[1]); + p = Integer.parseInt(stray[2]); + + for (int j = 3; j < k; j++) { + intray[j - 3] = Integer.parseInt(stray[j]); + } + + for (int j = 0; j < n; j++) { + if (intray[j] == 0) { + if (p == 0) { + continue; + } else { + ch++; + continue; + } + } + if (intray[j] % 3 == 0) { + tmp = intray[j] / 3; + if (tmp >= p) { + continue; + } else { + if (p - tmp <= 1) { + if (s != 0) { + s--; + continue; + } else { + ch++; + continue; + } + } else { + ch++; + continue; + } + } + } else { + tmp = (int) (intray[j] / 3 + 0.5); + if (intray[j] % 3 == 1) { + if (tmp + 1 >= p) { + continue; + } else { + ch++; + continue; + } + } else { + if (tmp + 1 >= p) { + continue; + } + if (tmp + 2 >= p) { + if (s != 0) { + s--; + continue; + } else { + ch++; + continue; + } + } else { + ch++; + continue; + } + } + } + } + + v++; + pw.println(""Case #"" + v + "": "" + (n - ch)); + + ch = 0; + k = 0; + } + + br.close(); + pw.close(); + } +}" +A22113,"import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + + +public class DancingWithGooglers { + + public static void main(String[] args) throws IOException{ + + String path = ""C:\\Users\\Rapol Tongchenchitt\\Documents\\CodeJam\\""; + String year = ""Qual2012\\""; + + String test = ""input.txt""; String outPath = ""output.txt""; + String a = """"; String A = """"; + String b = ""B-large.in""; String B = ""B-large.out""; + String c = """"; String C = """"; + String d = """"; String D = """"; + + String inName = path+year+b; + String outName = path+year+B; + + Scanner in = new Scanner(new FileInputStream(inName)); + BufferedWriter out = new BufferedWriter(new FileWriter(outName)); + + int caseCount = in.nextInt(); int currentCase = 0; + + while(currentCase++ < caseCount){ + + int dancerCount = in.nextInt(); + int surpriseCount = in.nextInt(); + int minScore = in.nextInt(); + + int goodCount = 0; + int maybeCount = 0; + + for(int i = 0; i < dancerCount; i++){ + int now = in.nextInt(); + int min; + + switch(now%3){ + case 0: + min = now/3; + if(min == 0){ + if (minScore == 0){ + goodCount++; + } + }else if(min >= minScore){ + goodCount++; + }else if(min + 1 == minScore){ + maybeCount++; + } + break; + + case 1: + min = (now/3) + 1; + if(min >= minScore){ + goodCount++; + } + break; + + case 2: + min = (now/3) + 1; + if(min >= minScore){ + goodCount++; + }else if(min + 1 == minScore){ + maybeCount++; + } + break; + + } + } + + goodCount += Math.min(maybeCount, surpriseCount); + + out.write(""Case #"" + currentCase + "": "" + goodCount); + out.newLine(); + } + + out.close(); + + } + +} +" +A22379,"package qualification.p2; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +public class DancingWithTheGooglers +{ + private static void calculate( String testCase, BufferedWriter bw, int n ) throws Exception + { + String[] tcData = testCase.split( "" "" ); + + int N = Integer.parseInt( tcData[0] ); + int S = Integer.parseInt( tcData[1] ); + int P = Integer.parseInt( tcData[2] ); + + int[] sums = new int[N]; + for ( int i = 3; i <= 2+N; i++ ) + sums[i-3] = Integer.parseInt( tcData[i] ); + + int c = 0; + for ( int sum : sums ) + { + if ( sum >= 3*P - 2 && sum >= P ) + c++; + else if ( S > 0 && sum >= 3*P - 4 && sum >= P ) + { + S--; + c++; + } + } + + bw.append( ""Case #""+n+"": ""+c+""\n"" ); + } + + public static void main( String[] args ) throws Exception + { + File inputFile = new File( ""inputfiles/qualification/p2/input.txt"" ); + FileReader fr = new FileReader( inputFile ); + BufferedReader br = new BufferedReader( fr ); + + int numOfTestCases = Integer.parseInt( br.readLine() ); + + File outputFile = new File( ""inputfiles/qualification/p2/output.txt"" ); + outputFile.delete(); + outputFile.createNewFile(); + FileWriter fw = new FileWriter( outputFile ); + BufferedWriter bw = new BufferedWriter( fw ); + + for ( int i = 0; i < numOfTestCases; i++ ) + { + String testCase = br.readLine(); + calculate( testCase, bw, i+1 ); + } + + bw.flush(); + fw.flush(); + + bw.close(); + fw.close(); + } +} +" +A22864,"import java.util.*; +import java.io.*; +import static java.lang.Math.*; + +public class B { + public static void main(String[] args) throws IOException { + /*BufferedReader in = new BufferedReader(new FileReader(""C:/Users/Farnoosh/Desktop/B-small.in"")); + FileWriter fw = new FileWriter(""C:/Users/Farnoosh/Desktop/B-small.out"");*/ + BufferedReader in = new BufferedReader(new FileReader(""C:/Users/Farnoosh/Desktop/B-large.in"")); + FileWriter fw = new FileWriter(""C:/Users/Farnoosh/Desktop/B-large.out""); + + int N = 0; + int S = 0; + int P = 0; + int num1 = 0; + + int Num = new Integer(in.readLine()); + for (int cases = 1; cases <= Num; cases++) + { + int count = 0; + String[] ss = in.readLine().split("" ""); + N = Integer.parseInt(ss[0]); + S = Integer.parseInt(ss[1]); + P = Integer.parseInt(ss[2]); + + for(int i = 0 ; i < N ; i++){ + num1 = Integer.parseInt(ss[i+3]); + + if (P == 0 && num1 == 0){ + count++; + continue; + } + if (num1 < Math.abs(P+2*(P-2))) + { + continue; + } + else if(num1 >= (P+2*(P-1))) + { + count++; + } + else { + if (S > 0){ + count++; + S--; + } + }// end of else + }// end of for + fw.write (""Case #"" + cases + "": "" + count + ""\n""); + } + fw.flush(); + fw.close(); + } + +}" +A20663,"import java.util.*; + +class dance{ + public static void main(String args[]){ + int t,n,s,p; + int i,j; + int score[]; + double average[]; + int sum; + + Scanner sc = new Scanner(System.in); + + t = sc.nextInt(); + + for(i=0;i p-1) sum++; + else if(average[j]!=0 && average[j]-0.5 >p-2){ + if(s>0) sum++; + s--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + sum); + } + } +} +" +A21549,"package qualify; + +import java.util.Scanner; + +public class B { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int i=0;i= 3 * p - 2) { + total++; + } else if (p >= 2 && score >= 3 * p - 4 && s > 0) { + total++; + s--; + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + total); + } + } +} +" +A21359,"// Author: Alejandro Sotelo Arevalo +package qualification; + +import java.io.*; +import java.util.*; + +public class B_DancingWithTheGooglers { + //-------------------------------------------------------------------------------- + private static String ID=""B""; + private static String NAME=""large""; + private static boolean STANDARD_OUTPUT=false; + //-------------------------------------------------------------------------------- + public static void main(String[] args) throws Throwable { + BufferedReader reader=new BufferedReader(new FileReader(new File(""data/""+ID+""-""+NAME+"".in""))); + if (!STANDARD_OUTPUT) System.setOut(new PrintStream(new File(""data/""+ID+""-""+NAME+"".out""))); + for (int c=1,T=Integer.parseInt(reader.readLine()); c<=T; c++) { + String w[]=reader.readLine().trim().split("" +""); + int N=Integer.parseInt(w[0]),S=Integer.parseInt(w[1]),p=Integer.parseInt(w[2]); + int t[]=new int[N]; + for (int i=0; i=2&&t[i]<=28) count++; + } + if (count>>i)&1)==1) { // surprising + if (max-min==2) best=Math.max(best,max); + } + else { + if (max-min<=1) best=Math.max(best,max); + } + } + if (best>=p) count++; + } + result=Math.max(result,count); + } + return result; + } + private static int recursiveApproach1(int N, int S, int p, int[] t) { + return Math.max(0,recursiveApproach1(N,S,p,t,0)); + } + private static int recursiveApproach1(int N, int S, int p, int[] t, int k) { + if (k==N) return S==0?0:-N*2; + int result=-N*2; + if (S>0) { // Surprissing + int best=-1; + for (int u=0; u<=10; u++) for (int v=0; v<=10; v++) for (int w=0; w<=10; w++) if (u+v+w==t[k]) { + int max=Math.max(u,Math.max(v,w)); + int min=Math.min(u,Math.min(v,w)); + if (max-min==2) best=Math.max(best,max); + } + result=Math.max(result,(best>=p?1:0)+recursiveApproach1(N,S-1,p,t,k+1)); + } + { // Not surprissing + int best=-1; + for (int u=0; u<=10; u++) for (int v=0; v<=10; v++) for (int w=0; w<=10; w++) if (u+v+w==t[k]) { + int max=Math.max(u,Math.max(v,w)); + int min=Math.min(u,Math.min(v,w)); + if (max-min<=1) best=Math.max(best,max); + } + result=Math.max(result,(best>=p?1:0)+recursiveApproach1(N,S,p,t,k+1)); + } + return result; + } + private static int recursiveApproach2(int N, int S, int p, int[] t) { + return Math.max(0,recursiveApproach2(N,S,p,t,0)); + } + private static int recursiveApproach2(int N, int S, int p, int[] t, int k) { + if (k==N) return S==0?0:-N*4; + int result=-N*4,sum=t[k]; + if (S>0) { + // Surprissing + int best=(sum>=2&&sum<=28?(sum+4)/3:-1); + if (best!=-1) result=Math.max(result,(best>=p?1:0)+recursiveApproach2(N,S-1,p,t,k+1)); + } + // Not surprissing + int best=(sum+2)/3; + result=Math.max(result,(best>=p?1:0)+recursiveApproach2(N,S,p,t,k+1)); + return result; + } + private static int dynamicProgrammingApproach1(int N, int S, int p, int[] t) { + int table[][]=new int[N+1][S+1]; + for (int k=N; k>=0; k--) for (int s=0; s<=S; s++) { + if (k==N) { + table[k][s]=(s==0?0:-N*4); + } + else { + int result=-N*4,sum=t[k]; + if (s>0) { + // Surprissing + int best=(sum>=2&&sum<=28?(sum+4)/3:-1); + if (best!=-1) result=Math.max(result,(best>=p?1:0)+table[k+1][s-1]); + } + // Not surprissing + int best=(sum+2)/3; + result=Math.max(result,(best>=p?1:0)+table[k+1][s]); + table[k][s]=result; + } + } + return Math.max(0,table[0][S]); + } + private static int dynamicProgrammingApproach2(int N, int S, int p, int[] t) { + int array[]=new int[S+1]; + Arrays.fill(array,-N*4); + array[0]=0; + for (int k=N-1; k>=0; k--) for (int s=S; s>=0; s--) { + int result=-N*4,sum=t[k]; + if (s>0) { + // Surprissing + int best=(sum>=2&&sum<=28?(sum+4)/3:-1); + if (best!=-1) result=Math.max(result,(best>=p?1:0)+array[s-1]); + } + // Not surprissing + int best=(sum+2)/3; + result=Math.max(result,(best>=p?1:0)+array[s]); + array[s]=result; + } + return Math.max(0,array[S]); + } +} +" +A21836,"import java.io.BufferedOutputStream; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Scanner; + +class results { + public int numgooglers,numsurprising,p,counter = 0; + public int[] scores; + HashMap maxifnotsurprising, maxifsurprising; + + results(int numgooglers, int numsurprising, int p,HashMap maxifnotsurprising, HashMap maxifsurprising) { + this.numgooglers = numgooglers; + this.numsurprising = numsurprising; + this.p = p; + scores = new int[numgooglers]; + this.maxifnotsurprising = maxifnotsurprising; + this.maxifsurprising = maxifsurprising; + } + public void addscore(int i) { + scores[counter] = i; + counter++; + } + public int maxgreaterthanp() { + int max = 0; + int remainingsurprising = numsurprising; + for (int i=0;i=p) max++; + else if (remainingsurprising>0 && scores[i] > 1 ) { //If it's surprising, minimum score is 2 + if (maxifsurprising.get(scores[i])>=p) { + max++; + remainingsurprising--; + } + } + } + + + return max; + } + +} + +public class DancingWithGooglers { + + final static String inputfile = ""B-large.in"",outfile = ""output.txt""; + static HashMap maxifnotsurprising,maxifsurprising; + + + public static void main(String[] args) { + maxifnotsurprising = new HashMap(); + maxifsurprising = new HashMap(); + + for(int i=0;i<11;i++) { //Smallest + for (int j=i;j cases = new ArrayList(); + Scanner sc = null; + try { + sc = new Scanner(new File(inputfile)); + } catch (FileNotFoundException e) { + System.err.println(""OHONEZ""); + } + int numtestcases = sc.nextInt(); + for (int i=0;i N=new ArrayList(); + ArrayList S=new ArrayList(); + ArrayList p=new ArrayList(); + ArrayList> t=new ArrayList>(); + ArrayList y=new ArrayList(); + //Leo + File archin=new File(args[0]); + FileReader in=null; + BufferedReader bin=null; + try{ + in=new FileReader(archin); + bin=new BufferedReader(in); + T=Integer.parseInt(bin.readLine()); + for(int i=0;i()); + for(int j=0;j=(3*p.get(i).intValue()-2)){ + y.set(i,y.get(i)+1); + }else{ + if((S.get(i)>0)&&(t.get(i).get(j)>1)&&(t.get(i).get(j)>=(3*p.get(i).intValue()-4))){ + y.set(i,y.get(i)+1); + S.set(i,S.get(i)-1); + } + } + } + } + //Escribo + File archout=new File(""out.txt""); + FileWriter out=null; + BufferedWriter bout=null; + try{ + out=new FileWriter(archout); + bout=new BufferedWriter(out); + for(int i=0;i0){ + bout.newLine(); + } + bout.write(""Case #""+(i+1)+"": ""+y.get(i)); + } + }catch(Exception ex){ + }finally{ + try{ + bout.close(); + }catch(Exception ex){ + } + try{ + out.close(); + }catch(Exception ex){ + } + } + } +} +" +A21929,"package jp.funnything.prototype; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +import jp.funnything.competition.util.CompetitionIO; +import jp.funnything.competition.util.Packer; + +import org.apache.commons.io.FileUtils; + +public class Runner { + public static void main( final String[] args ) throws Exception { + new Runner().run(); + } + + void pack() { + try { + final File dist = new File( ""dist"" ); + + if ( dist.exists() ) { + FileUtils.deleteQuietly( dist ); + } + + final File workspace = new File( dist , ""workspace"" ); + + FileUtils.copyDirectory( new File( ""src/main/java"" ) , workspace ); + FileUtils.copyDirectory( new File( ""../../../../CompetitionUtil/Lib/src/main/java"" ) , workspace ); + + Packer.pack( workspace , new File( dist , ""sources.zip"" ) ); + } catch ( final IOException e ) { + throw new RuntimeException( e ); + } + } + + void run() throws Exception { + final CompetitionIO io = new CompetitionIO(); + + final int t = io.readInt(); + + for ( int index = 0 ; index < t ; index++ ) { + final int[] values = io.readInts(); + + final int n = values[ 0 ]; + final int s = values[ 1 ]; + final int p = values[ 2 ]; + final int[] ts = Arrays.copyOfRange( values , 3 , values.length ); + + if ( n != ts.length ) { + throw new RuntimeException( ""assert"" ); + } + + io.write( index + 1 , solve( s , p , ts ) ); + } + + io.close(); + + pack(); + } + + int solve( final int s , final int p , final int[] ts ) { + int count = 0; + int consumed = 0; + + for ( final int sum : ts ) { + // if not surprising + int max = sum % 3 == 0 ? sum / 3 : sum / 3 + 1; + + if ( max >= p ) { + count++; + continue; + } + + if ( consumed < s && sum > 1 ) { + // if surprising + max = sum % 3 == 2 ? sum / 3 + 2 : sum / 3 + 1; + + if ( max >= p ) { + consumed++; + count++; + } + } + } + + return count; + } +} +" +A21431,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + + +public class CodeJam_B { + public static void main(String[] args){ + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + try{ + String countString = reader.readLine(); + int count = Integer.parseInt(countString); + for(int i=0;i=0;k--){ + int temp = scoreArray[k]; + if(temp >= minAcceptableValue){ + possibleResult++; + continue; + }else if(temp < minAcceptableValue && temp >= minSurprisedAcceptableValue){ + if(usedSurprises < s){ + if(minSurprisedAcceptableValue > 0){ + possibleResult++; + usedSurprises++; + } + }else{ + //out of surprises + } + }else{ + //not possible to get a score here + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+possibleResult); + //System.out.println(""Total Possbile Triplets : ""+possibleResult); + + } + } + catch (IOException ioe){ + System.out.println(""An unexpected error occured.""); + } + } + + + +} +" +A22471,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; + + +public class Dancing { + + public static void main(String[] args) throws Exception { + + BufferedReader fis = new BufferedReader(new FileReader(new File(""input""))); + String numCasesStr = fis.readLine(); + int numCases = Integer.parseInt(numCasesStr); + String val = """"; + int caseNum = 1; + while((val = fis.readLine()) != null) { + String out = calculate(val); + System.out.println(""Case #"" + caseNum + "": "" +out); + caseNum++; + } + + } + + private static String calculate(String val) { + String[] ss = val.split("" ""); + int n = Integer.parseInt(ss[0]); + int s = Integer.parseInt(ss[1]); + int p = Integer.parseInt(ss[2]); + + //The minimum normal scores with atleast one p value + + + + int out = 0; + + for(int i = 3; i < n + 3; i++) { + int score = Integer.parseInt(ss[i]); + + if(p == 0) { + out ++; + continue; + } + + // 28, 29, 30 covers everything + if(score >= 28) { + out++; + continue; + } + + if(score == 0) { + //This is useless at this point + //p==0 is handled above + continue; + } + + //Be greedy use the surprises as we need them + if(3*p-2 <= score) { + out ++; + } else if (s > 0 && score >= 3*p-4) { + out ++; + s--; + } + + } + + return """" + out; + } + +} +" +A21838,"import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; +import java.util.regex.Pattern; + + +public class ProblemB { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try { + Scanner input = new Scanner(new FileReader(""B-large.in"")); + PrintWriter output = new PrintWriter(new FileWriter(""output2.txt"")); + + int numberCases = input.nextInt(); + String data = input.nextLine(); + + for (int i = 0; i < numberCases; i++) { + output.print(""Case #"" + (i + 1) + "": ""); + + data = input.nextLine(); + String[] intS = Pattern.compile("" "").split(data); + int[] numbers = new int[intS.length]; + for (int j = 0; j < intS.length; j++) { + numbers[j] = Integer.parseInt(intS[j]); + } + + int numberGooglers = numbers[0]; + int surprising = numbers[1]; + int p = numbers[2]; + + int count = 0; + //System.out.print(""N ""); + for (int j = 0; j < numberGooglers; j++) { + if (((numbers[j + 3] / 3.0)) > (p - 1)) { + //System.out.print(numbers[j + 3] + "" ""); + count++; + } + } + + //System.out.print(""S ""); + if (surprising > 0) { + for (int j = 0; j < numberGooglers && surprising != 0; j++) { + if ((numbers[j + 3] / 3.0) <= (p - 1) && + (numbers[j + 3] / 3.0) >= (p - 2)) { + if (Math.floor(((numbers[j + 3] - p) / 2.0)) >= (p - 2) && + (numbers[j + 3] - p) >= 0) { + //System.out.print(numbers[j + 3] + "" ""); + count++; + surprising--; + } + } + } + } + //System.out.println(""Counter "" + count); + output.print(count); + output.print(""\n""); + } + output.flush(); + output.close(); + input.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +}" +A22353,"import java.util.Scanner; +import java.util.Arrays; +import java.io.File; + +public class Dancing { + public static void main (String[] args) { + Scanner sc = null; + try { + sc = new Scanner(new File(""input.txt"")); + } catch (Exception e) {} + int N, S, p, result; + int[] t; + String out; + int T = sc.nextInt(); + sc.nextLine(); + for (int i = 1; i <= T; i++) { + result = 0; + N = sc.nextInt(); + S = sc.nextInt(); + p = sc.nextInt(); + t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = -sc.nextInt(); + } + out = ""Case #"" + i + "": ""; + Arrays.sort(t); + for (int j = 0; j < N; j++) { + t[j] = -t[j]; + if ((t[j] == 0) && (p != 0)) { + } else if (t[j] >= 3*p - 2) { + result++; + } else if ((t[j] >= 3*p - 4) && (S > 0)) { + result++; + S--; + } + } + System.out.print(out + result + ((i < T)? ""\n"" : """")); + } + } +}" +A20236,"/* + * Gabriel Shaw + * 4/13/12 + */ +import java.io.File; +import java.io.PrintWriter; +import java.io.IOException; +import java.util.Scanner; +public class DancingWithTheGooglers +{ + public static void main(String[] args) throws IOException + { + File file = new File(""B-large.in""); + PrintWriter outfile = new PrintWriter(""B-large.out""); + Scanner infile = new Scanner(file); + int numberOfCases; + int numberOfGooglers; + int desiredScore; + int numberOfSuprisingCases; + int numberOfGoodScores; + numberOfCases = infile.nextInt(); + infile.nextLine(); + + for(int i=0 ; i= 0) + { + numberOfGoodScores++; + }//end of if(totalScore - desiredScore >= 0) + }//end of if(desiredScore == 1) + if(desiredScore == 0) + { + if(totalScore >= 0) + { + numberOfGoodScores++; + } + } + } + if(!(desiredScore <= 1) && (totalScore - desiredScore - (desiredScore - 1) - (desiredScore - 1)) >= 0) + { + numberOfGoodScores++; + }else + { + if(!(desiredScore <= 1) && (numberOfSuprisingCases > 0) && (totalScore -desiredScore - (desiredScore - 2) - (desiredScore - 2)) >= 0) + { + numberOfGoodScores++; + numberOfSuprisingCases--; + }//end of if((numberOfSuprisingCases > 0) && (totalScore -desiredScore - 2*(desiredScore - 2)) >= 0) + }//end of else + }//end of for(int j=0 ; j= caseNum) + { + line = stdin.readLine(); // returns null if end of input reached + + if (line == null) + { + done = true; + } + else + { + int output = readLine(line); + System.out.println(""Case #"" + caseNum + "": "" + output); + caseNum++; + } + } + } + + private int readLine(String line) + { + int goodCases = 0, keepTrack = 0; + StringTokenizer st = new StringTokenizer(line); + //Get num of Googlers + int googlers = Integer.parseInt(st.nextToken()); + //Get num of Special Cases + int numSpecial = Integer.parseInt(st.nextToken()); + //Get num to be greater than + int num = Integer.parseInt(st.nextToken()); + while (st.hasMoreTokens() && keepTrack < googlers) + { + int temp = Integer.parseInt(st.nextToken()); + if (temp >= (num*3) - 2) + goodCases++; + else if (temp >= (num*3) - 4 && numSpecial > 0 && temp >= num) + { + goodCases++; + numSpecial--; + } + keepTrack++; + } + return goodCases; + } + + + public static void main(String args[]) + { + try + { + new Dancing().run(); + } + catch (IOException ex) + { + ex.printStackTrace(); + } + + } + +} +" +A22550,"package Triple; + +public class Triple +{ + private int X; + private int Y; + private int Z; + + public Triple() + { + this.X = 0; + this.Y = 0; + this.Z = 0; + } + + public Triple(int x, int y, int z) + { + this.X = x; + this.Y = y; + this.Z = z; + } + + public Triple(int total) + { + this.X = total / 3; + this.Y = (total - this.X) / 2; + this.Z = (total - this.X - this.Y); + } + + public Boolean isValid() + { + if (Math.abs(this.X - this.Y) > 2) + { + return false; + } + if (Math.abs(this.X - this.Z) > 2) + { + return false; + } + if (Math.abs(this.Y - this.Z) > 2) + { + return false; + } + + return true; + } + + // A result of ""True"" indicates that a Triple is valid but unusual. ""False"" + // could indicate invalid, or valid but not unusual (it's up to you to + // discriminate) + public Boolean isUnusual() + { + if (!this.isValid()) + { + return false; + } + if (Math.abs(this.X - this.Y) > 1) + { + return true; + } + if (Math.abs(this.X - this.Z) > 1) + { + return true; + } + if (Math.abs(this.Y - this.Z) > 1) + { + return true; + } + + return false; + } + + public Boolean isHigher(int p) + { + Boolean high = false; + if (this.X >= p) + { + high = true; + } + if (this.Y >= p) + { + high = true; + } + if (this.Z >= p) + { + high = true; + } + + return high; + } + + // A false response indicates either the Triple is already higher, or can't + // be made higher without invalidating + public Boolean couldBeHigher(int p) + { + Boolean high = false; + if (this.isHigher(p)) + { + return false; + } + + if ((this.X == p - 1) && (this.X > 0)) + { + high = true; + } + if ((this.Y == p - 1) && (this.Y > 0)) + { + high = true; + } + if ((this.Z == p - 1) && (this.Z > 0)) + { + high = true; + } + + return high; + } + + public void Unusify() + { + int highest = Math.max(this.X, Math.max(this.Y, this.Z)); + int lowest = Math.min(this.X, Math.min(this.Y, this.Z)); + if (this.X == highest) + { + this.X += 1; + if (this.Y == lowest) + { + this.Z -= 1; + } else + { + this.Y -= 1; + } + } else if (this.Y == highest) + { + this.Y += 1; + if (this.X == lowest) + { + this.Z -= 1; + } else + { + this.X -= 1; + } + } else + // this.Z == highest + { + this.Z += 1; + if (this.Y == lowest) + { + this.X -= 1; + } else + { + this.Y -= 1; + } + } + } + + @Override + public String toString() + { + return ""("" + this.X + "", "" + this.Y + "", "" + this.Z + "")"" + (this.isUnusual() ? "" is unusual"" : """") + (this.isValid() ? """" : "" is invalid""); + } + +} +" +A20319,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + public final String INPUT_FILE_NAME = ""b_in""; + public final String OUTPUT_FILE_NAME = ""b_out""; + + int kase = 1; + int N = 0; + int T = 0; + int P = 0; + int SUR = 0; + int ans = 0; + ArrayList sums = new ArrayList(); + ArrayList>> cache = new ArrayList>>(); + int[][] memo; + + public ArrayList> gen(int sum) { + ArrayList> ans = new ArrayList>(); + + for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= 10; j++) { + if (Math.abs(j - i) > 2) + continue; + for (int k = 0; k <= 10; k++) { + if (Math.abs(i - k) > 2) continue; + if (Math.abs(j - k) > 2) continue; + if (i + j + k != sum) continue; + ArrayList v = new ArrayList(); + v.add(i); v.add(j); v.add(k); ans.add(v); + } + } + } + + return ans; + } + + public boolean isSur(ArrayList v) { + int a = v.get(0); int b = v.get(1); int c = v.get(2); + if (Math.abs(a - b) == 2) return true; + if (Math.abs(a - c) == 2) return true; + if (Math.abs(b - c) == 2) return true; + return false; + } + + public boolean isP(ArrayList v) { + int a = v.get(0); int b = v.get(1); int c = v.get(2); + if (a >= P) return true; + if (b >= P) return true; + if (c >= P) return true; + return false; + } +// +// public void solve(int count, int sur, int index) { +// if (index == -1) { +// if (sur == 0) +// ans = Math.max(ans, count); +// return; +// } +// if (sur < 0) +// return; +// ArrayList> v = cache.get(sums.get(index)); +// +// for (int i = 0; i < v.size(); i++) { +// boolean surprize = isSur(v.get(i)); +// if (isP(v.get(i))){ +// if (surprize) +// solve(count + 1, sur - 1, index - 1); +// else +// solve(count + 1, sur, index - 1); +// }else{ +// if (surprize) +// solve(count, sur - 1, index - 1); +// else +// solve(count, sur, index - 1); +// } +// } +// } + + public int solve2(int sur, int index) { + if (index == -1) { + if (sur == 0) + return 0; + return -1; + } + ArrayList> v = cache.get(sums.get(index)); + + int max = 0; + for (int i = 0; i < v.size(); i++) { + boolean surprize = isSur(v.get(i)); + int newsur= sur; + if (surprize) + newsur -= 1; + if (newsur < 0) + continue; + if (isP(v.get(i))) { + if (index == 0 || memo[newsur][index-1] == -1) + max = Math.max(max, solve2(newsur, index - 1) + 1); + else + max = Math.max(max, memo[newsur][index-1]+ 1); + } else { + if (index == 0 || memo[newsur][index-1] == -1) + max = Math.max(max, solve2(newsur, index - 1)); + else + max = Math.max(max, memo[newsur][index-1]); + } + } + memo[sur][index] = max; + return max; + } + + public void run() throws IOException { + Scanner s = new Scanner(new File(INPUT_FILE_NAME)); + // BufferedReader br = new BufferedReader(new + // FileReader(INPUT_FILE_NAME)); + PrintWriter pw = new PrintWriter(new FileWriter(OUTPUT_FILE_NAME)); + // PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); + + for (int i = 0; i <= 30; i++) + cache.add(gen(i)); + + T = s.nextInt(); + while (T-- > 0) { + ans = 0; + sums = new ArrayList(); + memo = new int[101][101]; + for (int i = 0; i < 101; i++) + Arrays.fill(memo[i], -1); + + N = s.nextInt(); + SUR = s.nextInt(); + P = s.nextInt(); + for (int i = 0; i < N; i++) + sums.add(s.nextInt()); + //solve(0, SUR, N - 1); + ans = solve2(SUR, N - 1); + pw.println(""Case #"" + kase + "": "" + ans); + kase++; + } + + pw.close(); + s.close(); + } + + public static void main(String[] args) throws IOException { + (new B()).run(); + } + +} +" +A22051,"package luis.miguel.serrano.utilities; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +import luis.miguel.serrano.settings.GlobalSettings; + +/** + * Data class for processing input and generating output + * @author Luis Miguel Serrano + * + */ +public class DataB { + + private File inputFile; + private File outputFile; + + public DataB(String inputFilePath, String outputFilePath) { + this.inputFile = new File(inputFilePath); + outputFile = new File(outputFilePath); + } + + public DataB(File inputFile) { + this.inputFile = inputFile; + outputFile = new File(GlobalSettings.OUTPUT_FILE_PATH); + } + + /** + * Processes the file passed as argument in the constructor + * @throws FileNotFoundException + */ + public void processFile() throws FileNotFoundException { + if(outputFile.exists()) + outputFile.delete(); + + Scanner scanner = new Scanner(inputFile); + + final int casesNumber = scanner.nextInt(); + scanner.nextLine(); + + for(int i = 0; i!=casesNumber; ++i) + processCase(scanner, i); + + System.out.println(""Done processing file: ""+inputFile); + } + + //Format-specific + private void processCase(Scanner scanner, int caseNumber) { + //System.out.println(""New Case""); + int numberGooglers = scanner.nextInt(); + int numberSurprisingTripletScores = scanner.nextInt(); + int p = scanner.nextInt(); + int[] totalScores = new int[numberGooglers]; + for(int i = 0; i!=numberGooglers; ++i) + totalScores[i] = scanner.nextInt(); + + + int solution; + solution = getSolution(numberGooglers, numberSurprisingTripletScores, p, totalScores); + + //Write solution to file + try { + FileWriter fw = new FileWriter(outputFile, true); + fw.write(""Case #""+(caseNumber+1)+"": ""+solution+""\r\n""); + fw.flush(); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //Problem-specific + private int getSolution(int numberGooglers, int numberSurprisingTripletScores, int p, int[] totalScores){ + int solution = 0; + + int[][] triplets = new int[numberGooglers][3]; + + //Generate Score Triplets + int surprisingTripletsRemaining = numberSurprisingTripletScores; + for(int i = 0; i!= triplets.length; ++i) { + int baseValue = totalScores[i]/3; + int rest = totalScores[i]%3; + + if(rest == 2) + { + int max = baseValue+2; + + //If it is ""worth it"" spending one surprising triplet to make this one count for ""the most"" + if(p == max && surprisingTripletsRemaining != 0) + --surprisingTripletsRemaining; + else { + ++baseValue; + rest -= 3; + } + } + + for(int j = 0; j!=triplets[i].length; ++j){ + if(j == 0) { + triplets[i][j] = baseValue+rest; + } + else { + triplets[i][j] = baseValue; + } + } + + //Integrity Check + int total = 0; + for(int j = 0; j!=triplets[i].length; ++j) + total += triplets[i][j]; + if(total != totalScores[i]) + System.out.println(""Total Scores Mismatch ERROR!""); + } + + + //If there are remaining triplets to spend, try to spend them in cases in which rest was = 0 + for(int i = 0; i!=triplets.length; ++i) + if(surprisingTripletsRemaining != 0){ + if(triplets[i][0] == triplets[i][1] && triplets[i][0] == triplets[i][2] && triplets[i][0] + 1 == p && triplets[i][0] != 0) { + triplets[i][0] += 1; + triplets[i][1] -= 1; + --surprisingTripletsRemaining; + } + } + else + break; + + + +// //Print (DEBUG) +// for(int i = 0; i!=triplets.length; ++i) +// for(int j = 0; j!= triplets[i].length; ++j) +// System.out.println(""triplets[""+i+""][""+j+""] = ""+triplets[i][j]); + + //Find solution + for(int i = 0; i!=triplets.length; ++i){ + for(int j = 0; j!= triplets[i].length; ++j) + { + if(triplets[i][j] >= p){ + ++solution; + break; + } + } + } + + return solution; + } + + + /** + * @param args + */ + public static void main(String[] args) { + + //DataB dataSample = new DataB(GlobalSettings.PROJECT_PATH+""\\input\\input_sample.in"", GlobalSettings.PROJECT_PATH+""\\output\\input_sample.out""); + //DataB dataSmall = new DataB(GlobalSettings.PROJECT_PATH+""\\input\\B-small-attempt0.in"", GlobalSettings.PROJECT_PATH+""\\output\\B-small-attempt0.out""); + DataB dataLarge = new DataB(GlobalSettings.PROJECT_PATH+""\\input\\B-large.in"", GlobalSettings.PROJECT_PATH+""\\output\\B-large.out""); + + try { + //dataSample.processFile(); + //dataSmall.processFile(); + dataLarge.processFile(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + System.out.println(""Finished processing all input!""); + } + +} +" +A22134,"/** + * + */ +package asem.google.codejam; + +//import asem.google.codejam.pract.y2010.qround.ProblemC; + + +/** + * @author A.Alathwari + * + * MainClass + * + */ +public class MainClass { + + public static String INPUT_FILE_PATH = ""input.txt""; + public static String OUTPUT_FILE_PATH = ""output.txt""; + + /** + * + */ + public MainClass() { + // TODO Auto-generated constructor stub + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try { + System.setOut(new java.io.PrintStream( + new java.io.FileOutputStream(MainClass.OUTPUT_FILE_PATH))); + + new Thread(new asem.googe.codejam.qround.ProblemB( + MainClass.INPUT_FILE_PATH, MainClass.OUTPUT_FILE_PATH)).start(); + + } catch (java.io.FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (java.io.IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} +" +A21271,"import java.util.Locale; +import java.util.Scanner; + +public class B { + + void solve(int icase) { + int n = si(); + int s = si(); + int p = si(); + int[] t = new int[31]; + for (int i = 0; i < n; i++) { + t[si()]++; + } + int res = Math.min(p < 2 ? 0 : t[3 * p - 4] + t[3 * p - 3], s); + for (int i = Math.max(3 * p - 2, 0); i <= 30; i++) { + res += t[i]; + } + printf(""Case #%d: %d\n"", icase, res); + } + + public static void main(String[] args) throws Exception { + Locale.setDefault(Locale.US); + new B().repSolve(); + } + + void repSolve() throws Exception { + scanner = new Scanner(System.in); + // scanner = new Scanner(new java.io.File("""")); + int ncase = si(); + sline(); + for (int icase = 1; icase <= ncase; icase++) { + solve(icase); + System.err.println(""[[ "" + icase + "" ]]""); + } + } + + Scanner scanner; + + int si() { + return scanner.nextInt(); + } + + long sl() { + return scanner.nextLong(); + } + + String ss() { + return scanner.next(); + } + + String sline() { + return scanner.nextLine(); + } + + void printf(String format, Object... args) { + System.out.printf(format, args); + } + +} +" +A21278,"import java.util.*; +import java.io.*; +import java.nio.*; +import java.nio.file.*; +import java.nio.charset.*; + +public class danzig +{ + //arrays store each Googler's score info + private static int[] total; + private static int[] max; + private static int[] modulo; + + private static int[] results; + + public static void main(String args[]) + { + //int linesRead=0; + //fileRead(); + Path file = Paths.get(""C:\\Users\\Elena\\Documents\\george\\code jam\\B-large.in""); + Charset cs = Charset.forName(""US-ASCII""); + + try(BufferedReader reader = Files.newBufferedReader(file, cs)){ + //#test cases setup + int T = Integer.valueOf(reader.readLine()); + results = new int[T]; + + //the 'main' loop + for(int i=0; i=0; j--){ + if(n>=S) //do not exceed + break; + if(max[j]=2){ //if remainder 0|2 then can increase + n++; + max[j]++; + } + } + } + /*System.out.println(Arrays.toString(total)); + System.out.println(p+""...""+Arrays.toString(max)); + System.out.println(Arrays.toString(modulo));*/ + + //count number of matches + tally(i,p); + + //System.out.print(""\n""); + } + } catch(IOException x) { + System.out.println(""oops read""); + } + + //System.out.println(Arrays.toString(results)); + fileWrite(); + + } + + public static void tally(int pos, int target){ + int instances=0; + for(int i=0; i=target) + instances++; + } + results[pos]=instances; + } + + public static void fileWrite(){ + Path file = Paths.get(""C:\\Users\\Elena\\Documents\\george\\code jam\\dancing.out""); + Charset cs = Charset.forName(""US-ASCII""); + + try(BufferedWriter writer = Files.newBufferedWriter(file, cs)){ + for(int i=0; i totalScores = new ArrayList(numGooglers); + + for (int i = 0; i < numGooglers; i++) { + totalScores.add(file.nextInt()); + } + + ps.append(""Case #"").print(currentCase); + ps.append("": ""); + + ps.println(getMaxPossibleWithAtLeastScore(totalScores, numSurprises, atLeastScore)); + + currentCase++; + } + } catch (FileNotFoundException e) + { + e.printStackTrace(); + } + } + + private static int getMaxPossibleWithAtLeastScore( + ArrayList totalScores, int numSurprises, int atLeastScore) + { + int maxPossible = 0; + for (int score : totalScores) { + int mean = score / 3; + int remainder = score % 3; + + switch (remainder) { + case 2: + if (mean + 1 >= atLeastScore) { + maxPossible++; + } + else if (numSurprises > 0 && mean + 2 >= atLeastScore) { + numSurprises--; + maxPossible++; + } + break; + case 1: + if (mean + 1 >= atLeastScore) { + maxPossible++; + } + break; + case 0: + if (mean >= atLeastScore) + maxPossible++; + else if (numSurprises > 0 && mean != 0 && mean + 1 >= atLeastScore) { + numSurprises--; + maxPossible++; + } + break; + } + } + + return maxPossible; + } + +} +" +A22931,"public class Googlers { + public static int google(int N, int S, int P, int[] googler) { + int counter = 0; + for (int j = 0; j < googler.length; j++) { + if (googler[j] % 3 == 0 && P >= 0) { + if (googler[j] != 0) { + if (googler[j] / 3 >= P) { + counter++; + } else if (googler[j] / 3 + 1 >= P && S != 0) { + counter++; + S--; + } + } + else if (googler[j] == 0 && P == 0) { + counter++; + } + } else if (googler[j] % 3 == 1) { + if (googler[j] / 3 + 1 >= P) { + counter++; + } + } else if (googler[j] % 3 == 2) { + if (googler[j] / 3 + 1 >= P) { + counter++; + } + else if (googler[j] / 3 + 2 >= P && S != 0) { + counter++; + S--; + } + } + } + return counter; + } +} +" +A21467,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + + +public class Solve1 { + + public static void main(String[] args) { + + FileReader fr; + FileWriter fw; + try { + File fi = new File(""input.txt""); + fr = new FileReader(fi); + BufferedReader br = new BufferedReader(fr); + fw = new FileWriter(""output.txt""); + BufferedWriter bw = new BufferedWriter(fw); + boolean f = true; + int tCount = Integer.MAX_VALUE; + int c = 1; + String line = null; + while((line = br.readLine()) != null && c <= tCount) { + if(f) { + f = false; + tCount = Integer.parseInt(line); + continue; + } + + int ans = getVal(line); + String os = ""Case #"" + c + "": "" + ans; + + + bw.write(os); + bw.newLine(); + c++; + } + bw.flush(); + bw.close(); + br.close(); + } catch (FileNotFoundException eg) { + // TODO Auto-generated catch block + eg.printStackTrace(); + } catch (IOException ed) { + // TODO Auto-generated catch block + ed.printStackTrace(); + } + } + + public static int getVal(String line) { + String[] sa = line.split("" ""); + int[] vals = null; + int s = 0; + int p = 0; + for(int i=0; i< sa.length; i++) { + int v = Integer.parseInt(sa[i].trim()); + if(i == 0) { + vals = new int[v]; + continue; + } + if(i == 1) { + s = v; + continue; + } + if(i == 2) { + p = v; + continue; + } + + vals[i-3] = v; + + } + + + int[] bs = new int[11]; + int[] pc = new int[11]; + + for(int i=0; i= p; i--) { + ans += bs[i]; + } + int ex = 0; + if (p>0) { + if (s > pc[p-1]) + return ans + pc[p-1]; + else + return ans + s; + + } + else + return ans; + + } + + +} + +" +A21759," +import java.io.FileNotFoundException; +import java.util.List; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Amya + */ +public class Dancing { + public static void main(String args[]) throws FileNotFoundException{ + List lines = FileUtil.readFileByLine(""input1""); + int records = Integer.parseInt(lines.get(0)); + int numOfGooglers = 0; + int numOfSurprises = 0; + int bestScore = 0; + String[] nums = null; + int eligiblesWithSurprise = 0; + int eligiblesWithoutSurprise = 0; + int onBorder = 0; + int finalEligibles = 0; + for(int i = 1; i<=records; i++){ + nums = lines.get(i).split("" ""); + numOfGooglers = Integer.parseInt(nums[0]); + numOfSurprises = Integer.parseInt(nums[1]); + bestScore = Integer.parseInt(nums[2]); + for(int j=3 ; j=bestScore){ + if(Integer.parseInt(nums[j])>=(bestScore*3 - 4)){ + eligiblesWithSurprise ++; + } + if(Integer.parseInt(nums[j])>=(bestScore*3 - 2)){ + eligiblesWithoutSurprise ++; + } + } + } + + finalEligibles = eligiblesWithoutSurprise; + + onBorder = eligiblesWithSurprise - eligiblesWithoutSurprise; + if(onBorder > numOfSurprises){ + finalEligibles += numOfSurprises; + }else{ + finalEligibles += onBorder; + } + + if(i == records) + FileUtil.writeOutput(""Case #""+i+"": ""+finalEligibles, true); + else + FileUtil.writeOutput(""Case #""+i+"": ""+finalEligibles, false); + + eligiblesWithSurprise = 0; + eligiblesWithoutSurprise = 0; + } + } +} +" +A22077,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.StringTokenizer; + +public class GoogleDancers{ + + public static void main(String[] args) throws Exception{ + FileReader fr = new FileReader(""C:\\java projects\\learn\\src\\B-small-attempt0.in""); + BufferedReader br = new BufferedReader(fr); + FileWriter fw = new FileWriter(""C:\\java projects\\learn\\src\\BLarge.txt""); + int N = new Integer(br.readLine()); + for (int cases = 1; cases <= N; cases++) { + String str = br.readLine(); + StringTokenizer st = new StringTokenizer(str); + int numberParticipants = Integer.parseInt(st.nextToken()); + int surprise = Integer.parseInt(st.nextToken()); + int goodScore = Integer.parseInt(st.nextToken()); + int a[] = new int[numberParticipants]; + for(int i=0; i< numberParticipants; i++) { + a[i] = Integer.parseInt(st.nextToken()); + } + int count = 0; + int possibility = 0; + int minToGetGoodScore = Math.max(((3 * goodScore) - 2), 1); + System.out.println(""minToGetGoodScore"" + minToGetGoodScore); + int surpriseRange = Math.max(((3* goodScore) - 4), 1); + if (goodScore > 0 ) { + for (int i = 0; i < numberParticipants; i++) { + if (a[i] >= minToGetGoodScore) { + count++; + System.out.println(""Count"" + count); + + + } else if (a[i] >= surpriseRange + && a[i] < minToGetGoodScore) { + possibility++; + } + }System.out.println(""Count"" + count); + count = count + Math.min(possibility, surprise); + System.out.println(""Count"" + count); + } + else + { + count = numberParticipants; + } + fw.write(""Case #"" + cases + "": "" + count + ""\n""); + + } + fw.flush(); + fw.close(); + } +} +" +A20288,"package com.palantir; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class Googlers { + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int numTests = s.nextInt(); + for (int i = 1; i <= numTests; ++i) { + System.out.println(""Case #"" + i + "": "" + solve(s)); + } + } + + private static int solve(Scanner s) { + int numGooglers = s.nextInt(); + int numSurprising = s.nextInt(); + int maxScore = s.nextInt(); + List scores = new ArrayList(); + for (int i = 0; i < numGooglers; ++i) scores.add(s.nextInt()); + int lowestGoodScore = (maxScore * 3) - 2; + int lowestSurpriseScore = (maxScore * 3) - 4; + if (maxScore == 0) { + lowestGoodScore = 0; + lowestSurpriseScore = 0; + } else if (maxScore == 1) { + lowestGoodScore = 1; + lowestSurpriseScore = 1; + } + int goodScores = 0, surpriseScores = 0; + for (int score : scores) { + if (score >= lowestGoodScore) ++goodScores; + else if (score >= lowestSurpriseScore) ++ surpriseScores; + } + if (numSurprising < surpriseScores) surpriseScores = numSurprising; + return goodScores + surpriseScores; + } +} +" +A20046,"package code.jam.quali; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; + +class Line { + int n; + int s; + int p; + ArrayList res; + + public Line(int n, int s, int p, ArrayList res) { + super(); + this.n = n; + this.s = s; + this.p = p; + this.res = res; + } + +} + +public class Dancing { + + private static final String file = ""B-small-attempt0.in""; + private ArrayList lines; + private Integer count; + + public static void main(String[] args) throws Exception { + Dancing g = new Dancing(); + + g.readFile(); + g.calculate(); + + } + + private void calculate() { + + int i = 1; + for (Line line : lines) { + int result = 0; + int sLim = 0; + int nsLim = 0; + if (line.p > 1) { + nsLim = (3 * line.p) - 2; + sLim = (3 * line.p) - 4; + } + else if (line.p == 1) + { + nsLim = 1; + sLim = 1; + } + + Integer tp = null; + Iterator it = line.res.iterator(); + while (it.hasNext()) { + tp = it.next(); + if (tp >= nsLim) { + result++; + it.remove(); + } + } + + it = line.res.iterator(); + while (it.hasNext() && line.s > 0) { + tp = it.next(); + if (tp >= sLim) { + result++; + line.s--; + it.remove(); + } + } + System.out.println(""Case #"" + i + "": "" + result); + i++; + } + } + + private void readFile() { + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(new File( + ""D:/Martin/Downloads/"" + file))); + String sline = null; + sline = br.readLine(); + count = Integer.valueOf(sline.trim()); + lines = new ArrayList(); + while ((sline = br.readLine()) != null) { + String[] sp = sline.split("" ""); + ArrayList r = new ArrayList<>(); + for (int i = 3; i < sp.length; i++) + r.add(Integer.valueOf(sp[i])); + + Line line = new Line(Integer.valueOf(sp[0]), + Integer.valueOf(sp[1]), Integer.valueOf(sp[2]), r); + lines.add(line); + + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + +} +" +A20225,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class Dancers { + + public static void main(String[] args) throws Exception { + BufferedReader reader = new BufferedReader(new FileReader(""input6.txt"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""output1.txt"")); + int cases = Integer.parseInt(reader.readLine()); + + for (int cs = 1; cs <= cases; cs++) { + String line = reader.readLine(); + String[] tokens = line.split("" ""); + + int i = 0; + int n = Integer.parseInt(tokens[i++]); + int surprises = Integer.parseInt(tokens[i++]); + int p = Integer.parseInt(tokens[i++]); + int count = 0; + + while (i < tokens.length) { + int s = Integer.parseInt(tokens[i++]); + if (p == 0) { + count++; + continue; + } + if (p == 1) { + if (s > 0) { + count++; + } + continue; + } + + if (p * 3 - 2 <= s) { + count++; + } else if ((p * 3 - 4 <= s) && surprises > 0) { + count++; + surprises--; + } + } + + writer.write(""Case #"" + cs + "": "" + count + ""\r\n""); + } + + writer.close(); + } +} +" +A21710,"import java.util.Scanner; + + +public class Solution { + public static void main(String[] args){ + Scanner scan = new Scanner(System.in); + int T = scan.nextInt(); + int[] result= new int[T]; + for(int i=0;i=max) + count++; + else{ + if(S>0 && t>=min){ + count++; + S--; + } + + } + } + result[i]=count; + } + for(int i=0;i0) { + writer.append(""\n""); + } + writer.append(""Case #""+(i+1)+"": "" + solve(N,S,P,RES)); + } + writer.flush(); + } + + private static int solve(int n, int s, int p, int[] res) { + int num = 0; + int surLeft = s; + for(int i=0;i0) { + if(p+Math.max(0,p-2)*2<=res[i]) { + surLeft--; + num++; + } + } + } + } + return num; + } +} +" +A21651,"package de.johanneslauber.codejam.model.impl; + +import de.johanneslauber.codejam.model.ICase; + +/** + * + * @author Johannes Lauber - joh.lauber@googlemail.com + * + */ +public class DancingGooglersCase implements ICase { + private final int numberOfAttributes = 1; + private int numberOfGooglers; + private int numberOfTriplets; + private int minLimitOfPoints; + private int[] maxPointsOfGooglers; + + @Override + public void setLine(int lineNumber, String lineValue) { + if (lineNumber == 1) { + String[] splittedLine = lineValue.split("" ""); + numberOfGooglers = Integer.parseInt(splittedLine[0]); + numberOfTriplets = Integer.parseInt(splittedLine[1]); + minLimitOfPoints = Integer.parseInt(splittedLine[2]); + maxPointsOfGooglers = new int[splittedLine.length - 3]; + + for (int i = 3; i < splittedLine.length; i++) { + maxPointsOfGooglers[i - 3] = Integer.parseInt(splittedLine[i]); + } + + } else { + System.out.println(""Linenumber is out of range""); + } + } + + // Setter & Getter + @Override + public int getNumberOfAttributes() { + return numberOfAttributes; + } + + public int getNumberOfGooglers() { + return numberOfGooglers; + } + + public void setNumberOfGooglers(int numberOfGooglers) { + this.numberOfGooglers = numberOfGooglers; + } + + public int getNumberOfTriplets() { + return numberOfTriplets; + } + + public void setNumberOfTriplets(int numberOfTriplets) { + this.numberOfTriplets = numberOfTriplets; + } + + public int getMinLimitOfPoints() { + return minLimitOfPoints; + } + + public void setMinLimitOfPoints(int minLimitOfPoints) { + this.minLimitOfPoints = minLimitOfPoints; + } + + public int[] getMaxPointsOfGooglers() { + return maxPointsOfGooglers; + } + + public void setMaxPointsOfGooglers(int[] maxPointsOfGooglers) { + this.maxPointsOfGooglers = maxPointsOfGooglers; + } + +} +" +A22212,"package gcj.main; + +import gcj.cases.competition.qualification_round_2012.CaseB; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; + +public class Main { + + + public static final void main (String[] args) throws Exception{ +// doTask(""taskTeszt0"", ""/home/dev/Letöltések/0-teszt-practice.in"", ""/home/dev/Letöltések/0-teszt-practice.out"", new Case0()); +// doTask(""taskSmall0"", ""/home/dev/Letöltések/A-small-attempt0.in"", ""/home/dev/Letöltések/A-small-attempt0.out"", new Case0()); + +// doTask(""taskTesztB"", ""/home/dev/Letöltések/B-teszt-practice.in"", ""/home/dev/Letöltések/B-teszt-practice.out"", new CaseB()); +// doTask(""taskSmallB"", ""/home/dev/Letöltések/B-small-attempt0.in"", ""/home/dev/Letöltések/B-small-attempt0.out"", new CaseB()); + doTask(""taskLargeB"", ""/home/dev/Letöltések/B-large.in"", ""/home/dev/Letöltések/B-large.out"", new CaseB()); + +// doTask(""taskTesztC"", ""/home/dev/Letöltések/C-teszt-practice.in"", ""/home/dev/Letöltések/C-teszt-practice.out"", new CaseC()); +// doTask(""taskSmallC"", ""/home/dev/Letöltések/C-small-attempt0.in"", ""/home/dev/Letöltések/C-small-attempt0.out"", new CaseC()); +// doTask(""taskLargeC"", ""/home/dev/Letöltések/C-large.in"", ""/home/dev/Letöltések/C-large.out"", new CaseC()); + + doTask(null, null, null, null); //because i hate the 'never used locally' warning... + } + + + private static final void doTask(String taskID, String inpFilePath, String outFilePath, Case c) throws Exception { + if(taskID == null) return; + BufferedReader br = null; + BufferedWriter bw = null; + String strLine; + int caseNum = 0; + System.out.println(taskID + "" strated...""); + try{ + { + //open files + br = new BufferedReader(new FileReader(new File(inpFilePath))); + bw = new BufferedWriter(new FileWriter(new File(outFilePath))); + } + { + //read caseNum value + if ((strLine = br.readLine()) != null){ + caseNum = Integer.parseInt(strLine); + } + System.out.println(""CaseNum: ""+caseNum); + } + for(int i=0; i charMap; + + public static void main(String[] args) throws Exception { + BufferedReader r = new BufferedReader(new FileReader(fileIn)); + BufferedWriter w = new BufferedWriter(new FileWriter(fileOut)); + String line = r.readLine(); + int T = Integer.parseInt(line); + for (int caseNum = 0; caseNum < T; caseNum++) { + int[] testCase = StringUtil.getIntArray(r.readLine()); + int nGooglers = testCase[0]; + int surprises = testCase[1]; + int pBestResultScore = testCase[2]; + List totalScores = new ArrayList(); + for (int i=0; i totalScores) { + int maxPossibleGooglers = 0; + Collections.sort(totalScores); + Collections.reverse(totalScores); + //int highestNoSurprise = Math.min(3*pBestResultScore+2, 30); + //int highestWithSurprise = Math.min(3*pBestResultScore+4, 30); + int lowestNoSurprise = Math.max(3*pBestResultScore-2, pBestResultScore); + int lowestWithSurprise = Math.max(3*pBestResultScore-4, pBestResultScore); + for (Integer score : totalScores) { + if (score >= lowestNoSurprise /*&& score <= highestNoSurprise*/) { + maxPossibleGooglers++; + } else if (score >= lowestWithSurprise /*&& score <= highestWithSurprise*/ && surprises > 0) { + maxPossibleGooglers++; + surprises--; + } + } + return String.valueOf(maxPossibleGooglers); + } + +} +" +A21319,"import java.io.*; + +public class mains { + public static void main(String[] args) { + BufferedReader input; + BufferedWriter output; + + try { + input = new BufferedReader(new FileReader(""B-large.in"")); + output = new BufferedWriter(new FileWriter(""output.out"")); + + int caseCount = Integer.parseInt(input.readLine()); + + String buf; + String[] values; + int googlerCount; + int sCount; + int minValue; + int score; + int resultCount; + for(int index = 1 ; index <= caseCount; ++index) { + resultCount = 0; + buf = input.readLine(); + values = buf.split("" ""); + googlerCount = Integer.parseInt(values[0]); + sCount = Integer.parseInt(values[1]); + minValue = Integer.parseInt(values[2]); + + for(int i = 0 ; i < googlerCount; ++i) { + score = Integer.parseInt(values[3 + i]); + switch(minValue) { + case 0 : + ++resultCount; + break; + case 1 : + if(score >= 1) + ++resultCount; + break; + default : + score = minValue * 3 - score; + if(score <= 2) { + ++resultCount; + } else if(sCount > 0 && score <= 4) { + ++resultCount; + --sCount; + } + } + } + + if(sCount != 0) { + System.out.println(""Invalid sCount = "" + sCount + "" at "" + index); + } + + output.write(""Case #"" + index + "": "" + resultCount); + output.newLine(); + } + + output.close(); + input.close(); + } catch(Exception e) { + return; + } + } +} +" +A22009," + +public interface Problem { + + void solve(); + + Object getSolution(); + +} +" +A21993,"import java.util.*; +import java.io.*; + +class gcj1{ + public static void main(String[] args) throws IOException{ + BufferedReader inp = new BufferedReader(new FileReader(""inp.txt"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""out.txt"")); + int i = 0; + int[][] regular = new int[31][3]; + int[][] surprising = new int[31][3]; + while(i<=30){ + surprising[i][0]=-1; + surprising[i][1]=-1; + surprising[i][2]=-1; + regular[i][0]=-1; + regular[i][1]=-1; + regular[i][2]=-1; + i++; + } + i=0; + while(i<=30){ + int j = 0; + while(j<=10){ + int k = j; + while(k<=10){ + int m = k; + while(m<=10){ + int sum = j+k+m; + if(sum==i){ + if(Math.abs(m-j)<=1 && Math.abs(j-k)<=1 && Math.abs(m-k)<=1) { + // System.out.println(""For ""+i+"" triplet is : ""+m+"" ""+j+"" ""+k); + regular[i][0] = m; + regular[i][1] = j; + regular[i][2] = k; + } + else { + if((Math.abs(m-j)==2 && Math.abs(j-k)<=2 && Math.abs(k-m)<=2)|| (Math.abs(m-j)<=2 && Math.abs(j-k)==2 && Math.abs(k-m)<=2) || (Math.abs(m-j)<=2 && Math.abs(j-k)<=2 && Math.abs(k-m)==2)){ + // System.out.println(""For ""+i+"" Surprising triplet is : ""+m+"" ""+j+"" ""+k); + surprising[i][0]=m; + surprising[i][1]=j; + surprising[i][2]=k; + } + } + } + m++; + } + k++; + } + j++; + } + // System.out.println(""-----------------------------""); + i++; + } + int test = Integer.parseInt(inp.readLine()); + int p = 1; + while(test>0){ + String data[] = inp.readLine().split("" ""); + int d[] = new int[data.length]; + int pp=0; + while(pp=t || regular[d[i]][1]>=t || regular[d[i]][2]>=t){ + count++; + } + else { + if(s>0) { + if(surprising[d[i]][0]>=t || surprising[d[i]][1]>=t || surprising[d[i]][2]>=t){ + s--; + count++; + } + } + } + i++; + } + i=3; + if (s>0){ + while(i=t || regular[d[i]][1]>=t || regular[d[i]][2]>=t){ + if(surprising[d[i]][0]>=t || surprising[d[i]][1]>=t || surprising[d[i]][2]>=t){ + s--; + } + else { + if(surprising[d[i]][0]!=-1){ + count--; + s--; + } + else { + i++; + continue; + } + } + } + else { + if(surprising[d[i]][0]>=t || surprising[d[i]][1]>=t || surprising[d[i]][2]>=t){ + + } + else { + if(surprising[d[i]][0]!=-1){ + s--; + } + else { + i++; + continue; + } + } + } + i++; + } + } + // if(s>0) out.write(""what the fuck!! \n""); + System.out.println(count); + out.write(""Case #""+p+"": ""+count+""\n""); + p++; + test--; + } + out.close(); + } +} + " +A20774,"package qualification.Dancing; + +public class Combination { + + int[] list; + boolean surprising; + + public Combination(int[] list, boolean surprising){ + this.list = list; + this.surprising = surprising; + } + + public int[] getList(){ + return list; + } + + public boolean isSurprising(){ + return surprising; + } + + @Override + public String toString(){ + String s = """"; + + for (int i = 0; i= p) + pNormal++; + } + else if(n % 3 == 0) { + if((n/3) >= p) + pNormal++; + else if((n/3)+1 >= p) + pSurprising++; + } + else if(n % 3 == 1) { + if((n/3)+1 >= p) + pNormal++; + } + else { + if((n/3)+1 >= p) { + pNormal++; + } + else if((n/3)+2 >= p) { + pSurprising++; + } + } + } + + if(pSurprising > S) + pSurprising = S; + + System.out.println(""Case #""+(c+1)+"": ""+(pNormal+pSurprising)); + } + } +} +" +A20640,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.StringTokenizer; + + +public class DancingWithGooglers { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + // TODO Auto-generated method stub + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st; + int T=Integer.parseInt(br.readLine()); + for(int cn=1;cn<=T;cn++){ + st=new StringTokenizer(br.readLine()); + int N=Integer.parseInt(st.nextToken()); + int S=Integer.parseInt(st.nextToken()); + int P=Integer.parseInt(st.nextToken()); + int t[]=new int[N]; + for(int i=0;i=P) + ctr++; + else if(S>0&&t[i]%3!=1&&a+1>=P&&t[i]>=2&&t[i]<=28){ + ctr++; + S--; + } + } + bw.append(""Case #""+cn+"": ""+ctr+""\n""); + } + bw.flush(); + } + +} +" +A22691,"import java.util.*; +import java.util.regex.*; +import java.text.*; +import java.math.*; +import java.io.*; + +public class DancingWiththeGooglers { + + private final static String FILE_IN = DancingWiththeGooglers.class + .getSimpleName() + "".in""; + private final static String FILE_OUT = DancingWiththeGooglers.class + .getSimpleName() + "".out""; + + public static void main(String[] args) throws Exception { + final Scanner in = new Scanner(new File(FILE_IN)); + final PrintWriter out = new PrintWriter(FILE_OUT); + + final Map> ok = new HashMap>(); + for (int i = 0; i <= 10; ++i) { + add(ok, i, i, i); + if (i < 10) { + add(ok, i, i, i + 1); + add(ok, i, i + 1, i + 1); + } + } + final Map> totalOk = new HashMap>(); + for (int i = 0; i <= 10; ++i) { + for (int j = i; j <= Math.min(10, i + 2); ++j) { + for (int k = j; k <= Math.min(10, i + 2); ++k) { + add(totalOk, i, j, k); + } + } + } + + for (int i = 9; i >= 0; --i) { + ok.get(i).addAll(ok.get(i + 1)); + totalOk.get(i).addAll(totalOk.get(i + 1)); + } + + final int testCnt = in.nextInt(); + for (int caseNum = 1; caseNum <= testCnt; ++caseNum) { + final int n = in.nextInt(); + final int s = in.nextInt(); + final int p = in.nextInt(); + final int[] a = new int[n]; + for (int i = 0; i < n; ++i) { + a[i] = in.nextInt(); + } + Arrays.sort(a); + int result = 0; + int left = s; + for (int score : a) { + if (ok.get(p).contains(score)) { + ++result; + } else if (left > 0 && totalOk.get(p).contains(score)) { + --left; + ++result; + } + } + out.println(String.format(""Case #%d: %d"", caseNum, result)); + } + in.close(); + out.close(); + } + + private final static void add(final Map> col, + final int a, final int b, final int c) { + final int s = a + b + c; + final int max = Math.max(a, Math.max(b, c)); + if (!col.containsKey(max)) { + col.put(max, new HashSet()); + } + col.get(max).add(s); + } +} +" +A22716,"package com.techy.rajeev; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingGame2 { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""techyrajeev.txt"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""myoutput.out"")); + int num=Integer.valueOf(in.readLine().trim()); + int count = 0, l = 1; + while (num > 0) { + int arrtemp[]=toIntArray(in.readLine()); + int N = arrtemp[0]; + int S = arrtemp[1]; + int p=arrtemp[2]; + for(int i=3;i=p){ + count++; + }else{ + if(S>0 && base>0 && base+1>=p){ + count++; + S--; + } + } + }break; + case 1:{ + if(base>=p || base+1>=p){ + count++; + }else{ + if(S>0 && base+1>=p){ + count++; + S--; + } + } + }break; + case 2:{ + if(base+1>=p || base>=p){ + count++; + }else{ + if(S>0 && base+2>=p){ + count++; + S--; + } + } + }break; + } + } + num--; + System.out.println(""Case #""+l+"": ""+count); + bw.write(""Case #""+l+"": ""+count); + bw.newLine(); + count=0; + l++; + } + in.close(); + bw.close(); + } + public static int[] toIntArray(String line){ + String[] p = line.trim().split(""\\s+""); + int[] out = new int[p.length]; + for(int i=0;i=p || B>=p || C>=p) + maxNo++; + else + { + if(S>0 && X!=0) + { + if(A==q) + { + if(B==q || C==q) + { + maxNo++; + S--; + } + } + else + { + if(B==q && C==q) + { + maxNo++; + S--; + } + + } + } + } + + + + } + + + //System.out.println(maxNo); + return maxNo; + } + + + + + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + DancingGooglers dg=new DancingGooglers(); + + FileInputStream fis = new FileInputStream(""c:/small.txt""); + DataInputStream dis = new DataInputStream(fis); + BufferedReader br = new BufferedReader(new InputStreamReader(dis)); + + FileWriter fstream = new FileWriter(""c:/out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + + String str=br.readLine(); + int[] score=new int[100]; + int T=Integer.parseInt(str); + int maxNo=0; + int S=0,p=0; + int caseNo=1; + int N=0; + while( (str = br.readLine()) != null && T>0) + { + if(caseNo>1) + out.newLine(); + + String[] line=str.split("" ""); + + N=Integer.parseInt(line[0]); + S=Integer.parseInt(line[1]); + p=Integer.parseInt(line[2]); + + + for (int i = 3,j=0; i < line.length; i++,j++) { + + score[j]=Integer.parseInt(line[i]); + } + maxNo=dg.maxDancer(N,S, p, score); + + out.write(""Case #""+caseNo+"": ""+maxNo); + + + caseNo++; + T--; + } + + //Close the output stream + out.close(); + + + } + +} +" +A22429,"package com.ignaciobona.codejam.practice.problema; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class Solver { + + public static String PROBLEM_NUMBER=""B""; + + public static String PATH_TO_INPUT_FILE_SMALL=""inputs/""+PROBLEM_NUMBER+""-small-attempt0.in""; + public static String PATH_TO_OUPUT_FILE_SMALL=""outputs/""+PROBLEM_NUMBER+""-small-attempt0.out""; + + + public static String PATH_TO_INPUT_FILE_LARGE=""inputs/""+PROBLEM_NUMBER+""-large.in""; + public static String PATH_TO_OUPUT_FILE_LARGE=""outputs/""+PROBLEM_NUMBER+""-large.out""; + + public static boolean SMALL=false; + + + public static class Problem{ + public int nCase; + public int nGooglers; + public int nSurprising; + public int desiredScore; + public int[]scores; + public StringBuffer outputString; + + + public void solve(){ + + outputString=new StringBuffer(""Case #""+nCase+"": ""); + int nSurprisingLeft=nSurprising; + int nResult=0; + for(int score:scores){ + boolean surprisingFound=false; + boolean normalFound=false; + for(int i=10;i>=0;i--){ + int score1=i; + int score2=i; + int score3=i; + + int aux=score-i; + if(aux>=0){ + if(aux%2==0){ + score2=aux/2; + score3=score2; + }else{ + score2=aux/2; + score3=score2+1; + } + if(score1>=desiredScore||score2>=desiredScore||score3>=desiredScore){ + if( (Math.abs(score1-score2))<2 && (Math.abs(score1-score3)) <2 ){ + //System.out.println(""Posible score for ""+score+"" is (""+score1+"",""+score2+"",""+score3 +"")""); + normalFound=true; + }else if( (Math.abs(score1-score2))<=2 && (Math.abs(score1-score3)) <=2 ){ + //System.out.println(""Posible surprising score for ""+score+"" is (""+score1+"",""+score2+"",""+score3 +"")""); + surprisingFound=true; + } + } + } + + } + if(normalFound){ + nResult++; + }else if(surprisingFound&&nSurprisingLeft>0){ + nSurprisingLeft--; + nResult++; + } + + } + outputString.append(nResult); + + } + } + + //Boring IO handling + public static void main(String[]args){ + try{ + String output=PATH_TO_OUPUT_FILE_LARGE; + if(SMALL){ + output=PATH_TO_OUPUT_FILE_SMALL; + } + File file=new File(output); + file.createNewFile(); + BufferedWriter bw=new BufferedWriter(new FileWriter(file)); + + + String input=PATH_TO_INPUT_FILE_LARGE; + if(SMALL){ + input=PATH_TO_INPUT_FILE_SMALL; + } + FileInputStream fstream = new FileInputStream(input); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + + String strLine; + //Read File Line By Line + int nCases=0; + int nCase=1; + Problem problem=new Problem(); + for (int i=0;(strLine = br.readLine()) != null;i++) { + // Print the content on the console + //System.out.println (strLine); + if(i== 0){ + nCases=Integer.parseInt(strLine); + }else{ + int nParam=(i-1)%1; + switch(nParam){ + case 0: + problem.nCase=nCase; + + + String[]tokens=strLine.split("" ""); + problem.nGooglers=Integer.parseInt(tokens[0]); + problem.nSurprising=Integer.parseInt(tokens[1]); + problem.desiredScore=Integer.parseInt(tokens[2]); + problem.scores=new int[problem.nGooglers]; + for(int j=0,z=3;j map; + + public AChallenge(int number, String line) { + super(number); + text = line; + initTranslationMap(); + setResult(translate()); + } + + private String translate() { + String res=""""; + for(int i=0;i(); + + String input=""ejp mysljylc kd kxveddknmc re jsicpdrysirbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcdde kr kd eoya kw aej tysr re ujdr lkgc jv""; + String output=""our language is impossible to understandthere are twenty six factorial possibilitiesso it is okay if you want to just give up""; + + for(int i=0;i= cutter - 2) { + certainty++; + } else if (scores [i] >= cutter - 4&&cutter - 4>=0) { + dangers++; + } + } +// System.out.println(""m""+max+""c""+cutter+""c""+certainty+""d""+dangers+""s""+surp); + ans = certainty; + ans+= dangers > surp ? surp : dangers; + + System.out.printf(""Case #%d: %d\n"", cas, ans); + } + + } + +} +" +A22872,"package googlejam; + +import java.util.Scanner; + +public class ProblemB { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int numberOfCases = sc.nextInt(); + for (int i = 0; i <= numberOfCases; i++) { + int googlers = sc.nextInt(); + int suprisingTriplets = sc.nextInt(); + int p = sc.nextInt(); + int sum = 0; + for (int j = 0; j < googlers; j++) { + int points = sc.nextInt(); + if (p == 0) { + sum++; + } else if (p == 1) { + if (points >= 1) + sum++; + else + continue; + } else if (points >= p * 3) { + sum++; + } else if ((p * 3 - points) <= 2) { + sum++; + } else if ((p * 3 - points) <= 4 && suprisingTriplets > 0) { + sum++; + suprisingTriplets--; + } + } + System.out.println(String.format(""Case #%d: %d"", i + 1, sum)); + } + } +} +" +A22792,"package Dancing; + +/** + * Created with IntelliJ IDEA. + * User: kevin + * Date: 4/13/12 + * Time: 8:00 PM + * To change this template use File | Settings | File Templates. + */ +public class DanceSet { + public DanceSet(int dancers, int suprises, int minscore,int[] scores){ + this.dancers=dancers; + this.sunrises=suprises; + this.minscore=minscore; + this.scores=scores; + } + public int id; + public int dancers; + public int sunrises; + public int minscore; + public int scores[]; +} +" +A22014,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Vector; + + +public class question2CodeJam { + public int N = 0; + public int S = 0; + public int P = 0; + Vector Scores = new Vector(); + public int scoreValidCount=0; + public int computeAtLeastP(){ + + for(int i=0;i=P){ + scoreValidCount++; + continue; + } + if(minVal == 0 && P == 0){ + scoreValidCount++; + continue; + } else if (minVal==0 && P!= 0){ + continue; + } + if((minVal+1) >= P && S > 0){ + //minVal + 1 would introduce 2 ka gap + scoreValidCount++; + S--; + continue; + } + } + if(currentScore%3==1){ + int minVal = currentScore/3; + if(minVal>=P){ + scoreValidCount++; + continue; + } + if((minVal+1) >= P){ + scoreValidCount++; + continue; + } + } + if(currentScore%3==2){ + int minVal = currentScore/3; + if((minVal+1) >= P){ + scoreValidCount++; + continue; + } + if(((minVal+2) >= P)&&(S>0)){ + S--; + scoreValidCount++; + continue; + } + } + + } + return (int) scoreValidCount; + } + public static void main(String[] args){ + + try{ + File file = new File(args[0]); + + FileWriter fstream = new FileWriter(args[1]); + BufferedWriter out = new BufferedWriter(fstream); + + BufferedReader in = new BufferedReader(new FileReader(file)); + + String line = in.readLine(); + //here line is the number of rounds + int counter=0; + int testCase = Integer.parseInt(line); + + while (counter= mn) r++; + else if(s > 0 && tp >= ms) { r++; s--; } + } + System.out.println(""Case #"" + tc + "": "" + r); + } + } +} + +//n** {{4 3 1 5 15 13 11 3 0 8 23 22 21 2 1 1 8 0 6 2 8 29 20 8 18 18 21}} +" +A22056,"package clasificacion.dancing; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class Dancing +{ + + public static void main(String[] args) + { + FileReader fr = null; + BufferedReader br = null; + FileWriter fw = null; + BufferedWriter bw = null; + + try + { + //fr = new FileReader(""C:/JAVA/Workspaces/CodeJam/googleCodeJam/src/clasificacion/dancing/prueba.in""); + //fr = new FileReader(""C:/JAVA/Workspaces/CodeJam/googleCodeJam/src/clasificacion/dancing/prueba_corta.in""); + fr = new FileReader(""C:/JAVA/Workspaces/CodeJam/googleCodeJam/src/clasificacion/dancing/prueba_larga.in""); + br = new BufferedReader(fr); + fw = new FileWriter(""C:/CODEJAM/clasificacion/dancing.out""); + bw = new BufferedWriter(fw); + + int cantidad = Integer.parseInt(br.readLine()); + for(int i = 0; i< cantidad ; i ++) + { + String linea = br.readLine(); + String[] datos = linea.split("" ""); + int surprise = Integer.parseInt(datos[1]); + int score = Integer.parseInt(datos[2]); + System.out.println("" // surprise: "" + surprise + "" // score "" + score); + int resultado = 0; + for(int j = 3; j < datos.length; j ++) + { + System.out.println(""puntuacion = "" + datos [j]); + int puntuacion = Integer.parseInt(datos[j]); + boolean salir = false; + + for(int a = 0; a <= 10 && !salir; a++) + { + for(int b = 0; b <= 10 && !salir; b++) + { + for(int c = 0; c <=10 && !salir; c++) + { + if( (a + b + c) == puntuacion) + { + if( (Math.abs(a -b) <= 1) && (Math.abs(a - c) <= 1) && (Math.abs(b - c) <= 1) ) + { + if(( a >= score || b >= score || c >= score)) + { + salir = true; + resultado ++; + System.out.println(""a: "" + a + "" / b: "" + b + "" /c: "" + c); + } + } + } + } + } + } + + + for(int a = 0; a <= 10 && !salir; a++) + { + for(int b = 0; b <= 10 && !salir; b++) + { + for(int c = 0; c <=10 && !salir; c++) + { + if( (a + b + c) == puntuacion) + { + if( (Math.abs(a -b) <= 1) && (Math.abs(a - c) <= 1) && (Math.abs(b - c) <= 1) ) + { + if(( a >= score || b >= score || c >= score)) + { + salir = true; + resultado ++; + System.out.println(""a: "" + a + "" / b: "" + b + "" /c: "" + c); + } + } + if(( a >= score || b >= score || c >= score) && surprise > 0 && + (Math.abs(a -b) <= 2) && (Math.abs(a - c) <= 2) && (Math.abs(b - c) <= 2) ) + { + salir = true; + resultado ++; + surprise --; + System.out.println(""a: "" + a + "" / b: "" + b + "" /c: "" + c + ""(*)""); + } + } + } + } + } + } + System.out.println(""Case #"" + (i +1) + "": "" + resultado); + bw.write(""Case #"" + (i + 1) + "": "" + resultado); + bw.newLine(); + } + + } + catch (Exception e) + { + e.printStackTrace(); + } + finally + { + try + { + br.close(); + bw.flush(); + bw.close(); + fr.close(); + fw.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + } + +} +" +A20054,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package google.code.jam.dancing.with.the.googlers; + +import java.io.*; +import java.util.ArrayList; + +/** + * + * @author Lucas + */ +public class Utils { + + public ArrayList parse(String file) { + + BufferedReader in = null; + ArrayList list = new ArrayList(); + int size; + + try { + + in = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(file)))); + size = Integer.parseInt(in.readLine()); + + for (int n = 0; n < size; n++) { + + String[] stringCases = in.readLine().split(""\\s+""); + + ArrayList cases = new ArrayList(); + cases.add(Integer.parseInt(stringCases[0])); + cases.add(Integer.parseInt(stringCases[1])); + cases.add(Integer.parseInt(stringCases[2])); + + for (int m = 0; m < cases.get(0); m++) { + cases.add(Integer.parseInt(stringCases[3 + m])); + } + list.add(cases); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return list; + } + + public void write(ArrayList output, String file) { + + BufferedWriter out = null; + + try { + + out = new BufferedWriter(new FileWriter(file)); + + for (int n = 0; n < output.size() - 1; n++) { + out.write(""Case #"" + (n + 1) + "": "" + output.get(n)); + out.newLine(); + } + out.write(""Case #"" + output.size() + "": "" + output.get(output.size() - 1)); + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (out != null) { + out.flush(); + out.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } +} +" +A20594,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Scanner; + + +public class GooglerDancerMain { + + public static void main(String[] args) { + + + + try { + Scanner s=new Scanner(new BufferedReader(new FileReader(""B-large.in""))); + ArrayList list=new ArrayList(); + int i=0; + int totalCases=Integer.parseInt(s.nextLine()); + while(s.hasNextLine()){ + list.add(new GooglerDancer(++i,s.nextLine())); + } + + for (GooglerDancer googlerDancer : list) { + googlerDancer.process(); + } + + } catch (FileNotFoundException e) { + System.out.println(""file not found""); + } + + + } +} +" +A21394,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class Problem2 { + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""B-small.txt"")); + PrintWriter out = new PrintWriter(new File(""B-out.txt"")); + int testCases = Integer.parseInt(in.readLine().trim()); + for (int i = 0; i < testCases; i++) { + String line = in.readLine(); + StringTokenizer tokenizer = new StringTokenizer(line); + int numDancers = Integer.parseInt(tokenizer.nextToken()); + int S = Integer.parseInt(tokenizer.nextToken()); + int p = Integer.parseInt(tokenizer.nextToken()); + int result = 0; + for (int j = 0; j < numDancers; j++) { + int score = Integer.parseInt(tokenizer.nextToken()); + int subScore1 = -1; + int subScore2 = -1; + boolean isValid2 = true; + if (score % 3 == 0) { + subScore1 = score / 3; + if (score - 3 < 0) { + isValid2 = false; + } + subScore2 = ((score - 3) / 3) + 2; + } + if (score % 3 == 1) { + if (score - 4 < 0) { + isValid2 = false; + } + subScore1 = ((score - 1) / 3) + 1; + subScore2 = ((score - 4) / 3) + 2; + } + if (score % 3 == 2) { + if (score - 2 < 0) { + isValid2 = false; + } + subScore1 = ((score - 2) / 3) + 1; + subScore2 = ((score - 2) / 3) + 2; + } + if(subScore2 > 10){ + isValid2 = false; + } + if (subScore1 >= p) { + result++; + } else if (isValid2) { + if (subScore2 < p) { + continue; + } else { + if (S != 0) { + result++; + S--; + } + } + } + } + out.println(""Case #"" + (i + 1) + "": "" + result); + } + out.close(); + } +} +" +A20874,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + +public class DancingWithTheGooglers { + + public static int max(int N, int S, int p, int[] T) { + int max = 0; + for (int i = 0; i < T.length; i++) { + int a = T[i] / 3; + if (T[i] == 0) { + if (0 >= p) + max++; + } + else if (T[i] == 1) { + if (1 >= p) + max++; + } + else if (T[i] == 2) { + if (1 >= p) + max++; + else if (2 >= p && S > 0) { + max++; + S--; + } + } + else if (T[i] % 3 == 0) { + if (a >= p) + max++; + else if (a + 1 >= p && S > 0) { + max++; + S--; + } + } + else if (T[i] % 3 == 1) { + if (a + 1 >= p) + max++; + } + else { // T[i] % 3 == 2 + if (a + 1 >= p) + max++; + else if (a + 2 >= p && S > 0) { + max++; + S--; + } + } + } + return max; + } + + public static void solve(String file) throws Exception { + + BufferedReader f = new BufferedReader(new FileReader(file + "".in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file + "".out""))); + + int T = Integer.parseInt(f.readLine()); + for (int i = 0; i < T; i++) { + String[] s = f.readLine().split("" ""); + int N = Integer.parseInt(s[0]); + int S = Integer.parseInt(s[1]); + int p = Integer.parseInt(s[2]); + int[] totals = new int[N]; + for (int j = 0; j < N; j++) + totals[j] = Integer.parseInt(s[j + 3]); + int max = max(N, S, p, totals); + System.out.println(""Case #"" + (i+1) +"": "" + max); + out.println(""Case #"" + (i+1) +"": "" + max); + } + out.close(); + } + + public static void main(String[] args) throws Exception { + + //String file = ""B-test""; + //String file = ""B-small-attempt1""; + String file = ""B-large""; + + solve(file); + } +} +" +A21460,"import java.io.*; + +public class Dancing{ + public static void main(String args []){ + try{ + FileInputStream fstream = new FileInputStream(""Blarge.in""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter ostream = new FileWriter(""danceOut.txt""); + BufferedWriter out = new BufferedWriter(ostream); + + String str = br.readLine(); + int num = Integer.parseInt(str.replaceAll(""\\s"","""")); + + String [] cases = new String[num]; + String temp; + int k = 0; + + while((temp = br.readLine()) != null && k < num){ + cases[k] = temp; + ++k; + } + + for(int i=1; i<= num; i++){ + String scores = cases[i-1].trim(); + int n = calcScores(scores); + + out.write(""Case #"" + i + "": "" + n); + out.write(""\n""); + out.flush(); + } + out.close(); + } + catch(Exception e){} + } + public static int calcScores(String input){ + String [] nums = input.split("" ""); + int N = Integer.parseInt(nums[0].replaceAll(""\\s"","""")); + int s = Integer.parseInt(nums[1].replaceAll(""\\s"","""")); + int p = Integer.parseInt(nums[2].replaceAll(""\\s"","""")); + + int scores[] = new int[N]; + int max = 0; + int sLeft = s; + + for (int i=0; i< N; i++) + scores[i] = Integer.parseInt(nums[3+i].replaceAll(""\\s"","""")); + + for(int i=0; i < N; i++){ + int x = scores[i]; + if(findMax(x) >= p) + ++max; + else{ + if(sLeft > 0 && findSurprise(x) >= p){ + ++max; + --sLeft; + } + } + } + return max; + } + + // Three cases: mod 1, mod 2 or mod 0 + public static int findMax(int x){ + if(x % 3 == 0) + return x/3; + else + return (x/3) + 1; + } + + public static int findSurprise(int x){ + if(x % 3 == 2) + return (x/3) + 2; + else if(x != 0) + return (x/3) + 1; + else + return 0; + } +} +" +A20927,"package main; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + + + public static void main(String[] args) throws NumberFormatException, IOException { + InputStreamReader isr = new InputStreamReader(System.in); + BufferedReader reader = new BufferedReader(isr); + + StringBuilder output = new StringBuilder(); + + int T = Integer.parseInt(reader.readLine()); + for (int i=1; i<=T; i++) { + output.append(""Case #"").append(i).append("": ""); + String line = reader.readLine(); + String[] tokens = line.split("" ""); + + int sol = 0; + + int N = Integer.parseInt(tokens[0]); + int S = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + + int max = 3 * p; + for (int j=3; j= max-2) { + sol++; + } else if (t_i >= max-4 && max - 4>=0) { + if (S > 0) { + sol++; + } + S--; + } + } + + output.append(sol).append(""\n""); + } + System.out.println(output.toString()); + } +} +" +A20300,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +public class CodeJam2 +{ + + private class Data + { + private int num; + private int surprise; + private int threshold; + private Integer[] values; + + public Data(int num, int surprise, int threshold, Integer[] values) + { + this.num = num; + this.surprise = surprise; + this.threshold = threshold; + this.values = values; + } + + public int getNum() + { + return num; + } + + public int getSurprise() + { + return surprise; + } + + public int getThreshold() + { + return threshold; + } + + public Integer[] getValues() + { + return values; + } + + public String toString() + { + return num + "" "" + surprise + "" "" + threshold + "" "" + values.length; + } + } + + private List getInputValue() + { + List inpVal = new ArrayList(); + + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + try + { + final String tc_ = stdin.readLine(); + Integer testCase = Integer.parseInt(tc_); + + while (testCase-- > 0) + { + // System.err.println(""tc#"" + testCase); + final String[] input = stdin.readLine().split("" ""); + int num = Integer.parseInt(input[0]); + Integer[] values = new Integer[num]; + + for (int i = 3; i < input.length; ++i) + values[i - 3] = Integer.parseInt(input[i]); + + Data data = new Data(num, Integer.parseInt(input[1]), Integer.parseInt(input[2]), values); + + inpVal.add(data); + + } + + return inpVal; + } + catch (IOException e) + { + e.printStackTrace(); + } + + return null; + } + + private static int getMaxWOSurprise(int a) + { + if (a % 3 == 0) + return a / 3; + else + return (a / 3) + 1; + } + + private static int getMaxWithSurprise(int a) + { + if (a == 0) + return -1; + else if ((a % 3) == 0) + return (a / 3) + 1; + else if (a % 3 == 1) + return -1; + else + return (a / 3) + 2; + } + + private static Integer[] sort(Integer[] arr) + { + for (int i = 0; i < arr.length - 1; ++i) + for (int j = i + 1; j < arr.length; ++j) + if (arr[i] < arr[j]) + { + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + return arr; + } + + public static void main(String[] args) + { + CodeJam2 cj = new CodeJam2(); + List inp = cj.getInputValue(); + // System.err.println(inp); + + // System.err.println(getMaxWithSurprise(15)); + + int count = 1; + + // operating for each tc + for (Data data : inp) + { + int surprise = data.getSurprise(); + int threshold = data.getThreshold(); + int answer = 0; + + Integer[] scores = sort(data.getValues()); + + for (Integer score : scores) + { + // System.err.println(score + "" "" + getMaxWithSurprise(score) + + // "" "" + getMaxWOSurprise(score)); + + if (getMaxWOSurprise(score) >= threshold) + answer++; + else if (surprise > 0 && getMaxWithSurprise(score) >= threshold) + { + answer++; + surprise--; + } + } + + System.out.println(""Case #"" + count++ + "": "" + answer); + } + + // System.err.println(cj.generateCombination(24, 40)); + } +} +" +A20532,"public class B +{ + public static void main(String []args) + { + int j,c,i,T, N, S, P,maior,menor,soma; + java.util.Scanner sc = new java.util.Scanner(System.in); + T = sc.nextInt(); + for (i = 0; i < T; i++) + { + c = 0; + N = sc.nextInt(); + S = sc.nextInt(); + P = sc.nextInt(); + for (j = 0; j < N; j++) + { + soma = sc.nextInt(); + maior = (int)Math.ceil(soma/3.0); + menor = (int)Math.floor(soma/3.0); + if (maior>= P) + c++; + else if (S>0 && ( + (maior - menor == 0 && maior + 1 >= P && menor>0) || + (maior - menor == 1 && maior + 1 >= P && 2*menor + maior + 1 <= soma)) + ) + { + c++; + S--; + } + } + System.out.println(""Case #""+(i+1)+"": ""+c); + } + } +} +" +A22164,"package com.mohit.codejam; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +public class DancingGooglers { + + public static void main(String[] args) { + try { + int noOfTests = 0; + int noGooglers = 0; + int surprises = 0; + int expScore = 0; + int totalScore = 0; + int withoutSurprise = 0; + int withSurprise = 0; + + int judgesScore[] = new int[3]; + int temp = 0; + + FileInputStream fis = new FileInputStream(""input.txt""); + DataInputStream din = new DataInputStream(fis); + BufferedReader br = new BufferedReader(new InputStreamReader(din)); + + FileWriter fstream = new FileWriter(""out.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + String strLine; + strLine = br.readLine(); + if (strLine == null || strLine == """") + return; + + strLine = strLine.trim(); + noOfTests = Integer.parseInt(strLine); + + int testNumber = 1; + + while (noOfTests > 0) { + strLine = br.readLine(); + if (strLine == null || strLine == """" || strLine == ""\n"") + break; + strLine = strLine.trim().toLowerCase(); + + String[] records = strLine.split("" ""); + noGooglers = Integer.parseInt(records[0]); + surprises = Integer.parseInt(records[1]); + expScore = Integer.parseInt(records[2]); + + withoutSurprise = 0; + withSurprise = 0; + + // loop to get the scores of Googlers + for (int i = 0; i < noGooglers; i++) { + // logic to find score such that difference between them is + // not more than 1 + totalScore = Integer.parseInt(records[2 + i + 1]); + judgesScore[0] = totalScore / 3; + judgesScore[1] = (totalScore - judgesScore[0]) / 2; + judgesScore[2] = totalScore - judgesScore[0] + - judgesScore[1]; + + // sort the judges score + for (int k = 0; k < 3; k++) { + for (int l = k + 1; l < 3; l++) { + if (judgesScore[k] > judgesScore[l]) { + temp = judgesScore[k]; + judgesScore[k] = judgesScore[l]; + judgesScore[l] = temp; + } + } + } + if (judgesScore[2] >= expScore) + withoutSurprise++; + else if (judgesScore[2] == (expScore - 1) + && (totalScore - judgesScore[2] > 0) + && (judgesScore[1] == judgesScore[2])) + withSurprise++; + + } + if (withSurprise > surprises) + withSurprise = surprises; + + out.write(""Case #"" + testNumber + "": "" + + (withoutSurprise + withSurprise) + ""\n""); + testNumber++; + } + br.close(); + out.close(); + } catch (IOException e) { + System.out.print(e.getMessage()); + } + } + +} +" +A22130," +import java.io.File; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + public static void main(String args[]) throws Exception { + final String PATH = ""/home/goalboy/software installation/codejam-commandline-1.0-beta4/source/""; + final String FILE = ""B-large-0""; + Scanner in = new Scanner(new File(PATH + FILE + "".in"")); + PrintWriter out = new PrintWriter(PATH + FILE + "".out""); + + int test = in.nextInt(); + for (int t = 1; t <= test; t++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int totals[] = new int[N]; + int bests[] = new int[N]; + boolean addables[] = new boolean[N]; + for (int i = 0; i < N; i++) { + totals[i] = in.nextInt(); + } + Arrays.sort(totals); + for (int i = 0; i < N; i++) { + if (totals[i] % 3 == 0) { + bests[i] = totals[i] / 3; + addables[i] = (bests[i] > 0); + } else if (totals[i] % 3 == 1) { + bests[i] = totals[i] / 3 + 1; + addables[i] = false; + } else { + bests[i] = totals[i] / 3 + 1; + addables[i] = (bests[i] > 0); + } + } + int result = 0; + for (int i = N - 1; i >= 0; i--) { + if (bests[i] >= p) { + result++; + } else if (addables[i] && bests[i] + 1 >= p && S > 0) { + result++; + S--; + } + } + out.println(""Case #"" + t + "": "" + result); + } + + out.close(); + } +} +" +A22540,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam.prparation; + +import java.io.*; +import java.util.*; + +/** + * + * @author HP + */ +public class DancingWithGooglers{ + + /** + * @param args the command line arguments + */ + + static int getLargest(ListL ,boolean[]S) + { + int max=0,o = 0; + for(int i=0;imax && !S[i]) + { + max = L.get(i); + o=i; + } + } + return o; + } + + + public static void main(String[] args) throws FileNotFoundException, IOException + { + + + int TestCases; + + File f = new File(""Dancing.in""); + Scanner scan = new Scanner(f); + TestCases = scan.nextInt(); + + int[] Googlers = new int[TestCases]; + int[] Surprises = new int[TestCases]; + int[] P = new int[TestCases]; + int[] Results = new int[TestCases]; + List> Final = new ArrayList>(); + + int i=0; + while(itmp = new ArrayList(); + Googlers[i] = scan.nextInt(); + Surprises[i] = scan.nextInt(); + P[i] = scan.nextInt(); + for(int j =0;jmod = new ArrayList(); + List> temp = new ArrayList>(); + for(int g=0;gL =new ArrayList(); + int total = Final.get(a).get(g); + int A,B,C; + if(P[a]!=0) + mod.add(total%P[a]); + if(total%3==0) + { + A = total/3; + B=A; + C=A; + } + else + { + if((total+1)%3==0) + { + A = total/3; + B = A+1; + C = A+1; + } + else + { + A = total/3; + B = A; + C = A+1; + } + } + if(A>=P[a]||B>=P[a]||C>=P[a]) + checks[g]=true; + L.add(A); + L.add(B); + L.add(C); + temp.add(L); + //------------------------------------ + } + int surp=0; + while(surp=P[a]||temp.get(m).get(1)>=P[a]||temp.get(m).get(2)>=P[a]) + Results[a]++; + } + } + + + + + + + FileWriter fstreamm = new FileWriter(""Dancing.out""); + BufferedWriter out = new BufferedWriter(fstreamm); + for(int t=0;t 0) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int[] total = new int[n]; + + int clear = (p - 1) * 2 + p; + int specialClear = (p - 2) * 2 + p; + + int score = 0; + + for (int i = 0; i < total.length; i++) { + int j = sc.nextInt(); + if (j < p) { + continue; + } + if (j >= clear) { + score++; + } else if (j >= specialClear && s > 0) { + score++; + s--; + } + } + + System.out.printf(""Case #%d: %d\n"", nbr++, score); + } + } +} +" +A20227,"import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int ti = 0; ti < t; ti++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int result = 0; + List list = new ArrayList(); + for (int i = 0; i < n; i++) + list.add(sc.nextInt()); + Collections.sort(list); + + int ns = n - s; + + for (int k = 0; k <= ns; k++) { + int tr = 0; + int j = 0; + for (; j < k; j++) { + int tmp; + if (list.get(j) <= 1) + tmp = list.get(j); + else + tmp = (list.get(j) - 1) / 3 + 1; + if (tmp >= p) + break; + } + tr += k - j; + for (j = list.size() - (ns - k); j < list.size(); j++) { + int tmp; + if (list.get(j) <= 1) + tmp = list.get(j); + else + tmp = (list.get(j) - 1) / 3 + 1; + if (tmp >= p) + break; + } + tr += list.size() - j; + for (j = k; j < list.size() - (ns - k); j++) { + int tmp; + if (list.get(j) <= 1) + tmp = -100; + else + tmp = (list.get(j) - 2) / 3 + 2; + if (tmp >= p) + break; + } + tr += list.size() - (ns - k) - j; + result = Math.max(result, tr); + } + System.out.printf(""Case #%d: %d%n"", ti + 1, result); + } + } +} +" +A21968,"package com.renoux.gael.codejam.utils; + +import java.util.ArrayList; +import java.util.List; + + + +/** + * Pour tests unitaires + * + * @author renouxg + */ +public final class ListUtils { + + public static List parseInts(List strings) { + ArrayList list = new ArrayList(); + for (String s : strings) { + list.add(Integer.valueOf(s)); + } + return list; + } + +} +" +A22919,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + int T = -1; + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + System.out.println(""Input""); + try { + T = Integer.valueOf(br.readLine()).intValue(); + } catch (NumberFormatException e) { + System.out.println(""Plz input the Numbers.""); + e.printStackTrace(); + } catch (IOException e) { + System.out.println(""Application will be terminated.""); + e.printStackTrace(); + } + + if (T < 1 || T > 100) { + System.out.println(""Input value should be larger than 0, also smaller than 100.""); + return ; + } + + ArrayList info = new ArrayList(); + + String s = null; + + int fromIndex = 0, toIndex = -1; + + for (int i = 0; i < T; i++) { + Info temp = new Info(); + try { + s = br.readLine(); +// System.out.println(""s : "" + s); + toIndex = s.indexOf("" "", fromIndex); + + temp.N = Integer.parseInt(s.substring(fromIndex, toIndex)); + if (temp.N < 1 || temp.N > 101) { + System.out.println(""N value should be larger than 0, also smaller than 101.""); + return ; + } + temp.points = new int[temp.N]; + + fromIndex = toIndex + 1; + toIndex = s.indexOf("" "", fromIndex); + temp.S = Integer.parseInt(s.substring(fromIndex, toIndex)); + if (temp.S < 0 || temp.S > temp.N) { + System.out.println(""S value should be larger than -1, also smaller than N.""); + return ; + } + + fromIndex = toIndex + 1; + toIndex = s.indexOf("" "", fromIndex); + temp.P = Integer.parseInt(s.substring(fromIndex, toIndex)); + if (temp.P < 0 || temp.P > 10) { + System.out.println(""P value should be larger than -1, also smaller than 11.""); + return ; + } + + for (int j = 0; j < temp.N; j++) { + fromIndex = toIndex + 1; + toIndex = s.indexOf("" "", fromIndex); + + if (toIndex == -1) + temp.points[j] = Integer.parseInt(s.substring(fromIndex)); + else + temp.points[j] = Integer.parseInt(s.substring(fromIndex, toIndex)); + + if (temp.points[j] < 0 || temp.points[j] > 30) { + System.out.println(""points value should be larger than -1, also smaller than 31.""); + return ; + } + } +// int swap; +// for (int j = 0; j + 1 < temp.N; j++) { +// if (temp.points[j] > temp.points[j+1]) { +// swap = temp.points[j + 1]; +// temp.points[j + 1] = temp.points[j]; +// temp.points[j] = swap; +// } +// } + + fromIndex = 0; + + } catch (IOException e) { + System.out.println(""Application will be terminated.""); + e.printStackTrace(); + } +// System.out.println(""temp.N : "" + String.valueOf(temp.N)); +// System.out.println(""temp.S : "" + String.valueOf(temp.S)); +// System.out.println(""temp.P : "" + String.valueOf(temp.P)); +// for (int j = 0; j < temp.N; j++) { +// System.out.println(""temp.points["" + String.valueOf(j) + ""] : "" + String.valueOf(temp.points[j])); +// } + + info.add(temp); + } + System.out.println(""Output""); + for (int i = 0; i < info.size(); i++) { + System.out.print(""Case #"" + String.valueOf(i + 1) + "": ""); + System.out.println(String.valueOf(overPersonCheck(info.get(i)))); + } + } + + private static int overPersonCheck(Info info) { + int count = 0; + int surprisingNum = info.S; + + for (int i = 0; i < info.N; i++) { + if (info.P == 0) { + count++; + continue ; + } else if (info.points[i] == 0) { + continue ; + } + + if (info.points[i] >= info.P * 3) { + count++; + } else if (info.points[i] >= info.P * 3 - 2) { + count++; + } else if (info.points[i] >= info.P * 3 - 4 && surprisingNum > 0) { + count++; + surprisingNum--; + } + } + + return count; + } + +} + +class Info { + int N; + int S; + int P; + int[] points; +} +" +A20856,"package codejam.qualification; + +import java.io.File; +import java.io.IOException; +import java.util.Scanner; + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) throws IOException { + String file = ""input2big""; + Scanner in = new Scanner(new File(file)); + int tot = Integer.parseInt(in.nextLine()); +// System.out.println(tot); + for(int i=0;i 0) output++; + } + break; + default: + int temp = 0; + for(int j=0; j= 3*p-2) + output++; + else + if(t >= 3*p-4) + temp++; + } + if(temp <= S) + output += temp; + else + output += S; + } + + System.out.println(""Case #""+(i+1)+"": ""+output); + } + + } + +} +" +A22377,"package com.google.codejam; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +public class DancingWithGooglers { + public static void main(String argsp[]) throws NumberFormatException, IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(""/Users/ashwinjain/Desktop/SmsLogger/InterviewStreet/src/com/google/codejam/in2b.txt""))); + int cases = Integer.parseInt(br.readLine()); + + for(int x=0;x=minScore){ + ans++; + s[i]=-1; + } + if(s[i]>=minScore){ + tempans++; + } + } + + ans = ans+Math.min(suprises, tempans); + System.out.println(""Case #""+(x+1)+"": ""+ans); + } + + } +} +" +A22950," +package codejam2; + +import java.io.*; +import java.util.Hashtable; +import java.util.logging.Level; +import java.util.logging.Logger; + +class FileReader +{ + int T; + FileInputStream fstream; + DataInputStream in; + BufferedReader br; + FileReader() + { + try + { + fstream = new FileInputStream(""B-large.in""); + in = new DataInputStream(fstream); + br = new BufferedReader(new InputStreamReader(in)); + initializeT(); + } + catch (Exception e) + { + System.err.println(""Error: "" + e.getMessage()); + } + } + private void initializeT() + { + String strLine; + try + { + strLine = br.readLine(); + T=Integer.parseInt(strLine); + } + catch (IOException ex) + { + Logger.getLogger(FileReader.class.getName()).log(Level.SEVERE, null, ex); + } + + } + public int getT() + { + return T; + } + public String getNextLine() + { + String temp=null; + try + { + temp=br.readLine(); + } + catch (IOException ex) + { + Logger.getLogger(FileReader.class.getName()).log(Level.SEVERE, null, ex); + } + return temp; + } +} + + + +public class CodeJam2 +{ + + public int findGooglers(int N,int S,int p,int[] scores) + { + int count=0; + for(int i=0;i0) + { + if(temp<=4) + { + if(scores[i]!=0) + { + ++count; + --S; + } + + } + } + + } + } + return count; + } + + public static void main(String[] args) + { + FileReader fr=new FileReader(); + CodeJam2 cj=new CodeJam2(); + FileWriter fstream; + try + { + fstream = new FileWriter(""output1.out""); + BufferedWriter out = new BufferedWriter(fstream); + int T=fr.getT(); + for(int i=0;i x) continue; + int remaining = x-p; + if( (remaining/2) >= (p-1) ) { + pass++; + } else if ( ( (remaining/2) == (p-2) ) && (S > 0) ) { + pass++; + S--; + } + } + + output.write(""Case #"" + i + "": "" + pass + ""\n""); + } + + in.close(); + output.flush(); + output.close(); + + } + +} +" +A21400,"import java.util.Scanner; + +public class problemB { + + private static final StringBuilder output = new StringBuilder(); + + private static int i = 1; + + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + int tests = s.nextInt(); + s.nextLine(); + for (int i = 0; i < tests; i++) { + addLine(String.valueOf(getMaxDancers(s.nextLine()))); + } + System.out.println(showLine()); + + } + + private static int getMaxDancers(String line) { + String[] values = line.split("" ""); + int surprising = Integer.parseInt(values[1]); + int score = Integer.parseInt(values[2]); + int minScore = score * 3 - 2; + int minSurp = minScore - 2; + int numOfDancers = 0; + for(int i = 3; i < values.length; i++){ + int sumOfPoints = Integer.parseInt(values[i]); + if(sumOfPoints >= minScore){ + numOfDancers++; + } + else if(sumOfPoints > 1 && sumOfPoints >= minSurp && surprising > 0){ + numOfDancers++; + surprising--; + } + } + return numOfDancers; + } + + private static void addLine(String s){ + output.append(""Case #""); + output.append(i); + output.append("": ""); + output.append(s); + output.append(""\n""); + i++; + } + + + public static String showLine(){ + return output.toString(); + } +} +" +A20095,"import java.util.*; +import java.io.*; +import java.math.*; + +public class Main { + public static void main(String[] args) { + InputStream inputStream = System.in; + OutputStream outputStream = System.out; + try { + inputStream = new FileInputStream(""a.in""); + outputStream = new FileOutputStream(""a.out""); + } catch (FileNotFoundException e) { + System.err.println(""File not found""); + return; + } + InputReader in = new InputReader(inputStream); + PrintWriter out = new PrintWriter(outputStream); + Solver solver = new Solver(); + solver.solve(in, out); + out.close(); + } +} + +class Solver { + public void solve(InputReader in, PrintWriter out) { + int t = in.nextInt(); + for (int i = 0; i < t; i++) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int ans = 0; + for (int j = 0; j < n; j++) { + int a = in.nextInt(); + if (a == 0) { + if (p == 0) + ans++; + continue; + } + if ((a + 2) / 3 >= p) { + ans++; + continue; + } + if (s > 0) + if (a % 3 != 1 && ((a + 2) / 3 + 1 >= p)) { + ans++; + s--; + } + } + out.print(""Case #""); + out.print(i + 1); + out.print("": ""); + out.println(ans); + } + } +} + +class InputReader { + private BufferedReader reader; + private StringTokenizer tokenizer; + + public InputReader(InputStream stream) { + reader = new BufferedReader(new InputStreamReader(stream)); + tokenizer = null; + } + + public String next() { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + try { + tokenizer = new StringTokenizer(reader.readLine()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return tokenizer.nextToken(); + } + + public long nextLong() { + return Long.parseLong(next()); + } + + public int nextInt() { + return Integer.parseInt(next()); + } + + public double nextDouble() { + return Double.parseDouble(next()); + } +} +" +A22806,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Madu + */ + +import java.io.*; + +public class Ex2 { + + public static void main(String[] args) { + + try{ + + FileInputStream fstream = new FileInputStream(""C:/Users/Madu/Documents/NetBeansProjects/CodeJamR1Ex1/input/A-small-attempt0.in""); + FileOutputStream fout = new FileOutputStream (""C:/Users/Madu/Documents/NetBeansProjects/CodeJamR1Ex1/output/out.txt""); + PrintStream printStream = new PrintStream(fout); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String inputIlne; + br.readLine(); + //printStream.println (""Output""); + //Read File Line By Line + int lineNum = 1; + while ((inputIlne = br.readLine()) != null) { + // Print the content on the console + + //########## + + String[] marks = inputIlne.split("" ""); + + + + int peopleCount = Integer.parseInt(marks[0].toString()); + int s = Integer.parseInt(marks[1].toString()); + int p = Integer.parseInt(marks[2].toString()); + + int ans = 0; + + + + for (int i = 3; i < marks.length; i++) { + + System.out.println(marks[i]); + int total = Integer.parseInt(marks[i].toString()); + + int value = total/3; + int reminder = total%3; + + if(total==0){ + if(p==0){ans++;} + + continue;} + + if(reminder==0){ + + if(value>=p){ans++;} + else if(value+1>=p){ + + if(s>=1){ans++; s--; + } + + } + + } + + else if(reminder==1){ + + if(value>=p){ans++;} + else if(value+1>=p){ans++;} + + } + + else if(reminder==2){ + + if(value>=p){ans++;} + else if(value+1>=p){ans++;} + else if(value+2>=p){ + + if(s>=1){ans++; s--;} + } + + } + + } + + + + printStream.print (""Case #""+lineNum+"": ""+ans);lineNum++; + + //########### + printStream.println(""""); + } + //Close the input stream + in.close(); + + + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.toString()); + } + + } + + + +// public static void main(String[] args) { +// +// String test = ""2 1 1 8 0""; +// int peopleCount = Integer.parseInt(test.substring(0, 1)); +// int s = Integer.parseInt(test.substring(2, 3)); +// int p = Integer.parseInt(test.substring(4, 5)); +// +// int ans = 0; +// +// //System.out.println(p); +// +// String[] marks = (test.substring(6)).split("" ""); +// +// +// +// for (int i = 0; i < marks.length; i++) { +// +// System.out.println(marks[i]); +// int total = Integer.parseInt(marks[i].toString()); +// +// int value = total/3; +// int reminder = total%3; +// +// if(total==0){continue;} +// +// if(reminder==0){ +// +// if(value>=p){ans++;} +// else if(value+1>=p){ +// +// if(s>=1){ans++; s--; +// } +// +// } +// +// } +// +// else if(reminder==1){ +// +// if(value>=p){ans++;} +// else if(value+1>=p){ans++;} +// +// } +// +// else if(reminder==2){ +// +// if(value>=p){ans++;} +// else if(value+1>=p){ans++;} +// else if(value+2>=p){ +// +// if(s>=1){ans++; s--;} +// } +// +// } +// +// } +// +// +// +// System.out.println(""Answer :""+ans); +// +// } + +} +" +A21171,"package qualifyingRound; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class DancingWithGooglers { + public static void main (String [] args) throws FileNotFoundException + { + Scanner in = new Scanner (new File (""input.txt"")); + int numLines = Integer.parseInt(in.nextLine()); + int caseNum = 1; + for (int j = 0; j < numLines; j++) + { + System.out.print(""Case #"" + caseNum + "": ""); + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int noSup = 0; + int sup = 0; + for (int i = 0; i < n; i++) + { + int total = in.nextInt(); + int maxNoSup = maxNoSup(total); + int maxSup = maxSup(total); +// System.out.println(total + "" "" + maxNoSup + "" "" + maxSup); + if (maxNoSup >= p) + noSup++; + else if (maxSup >= p) + sup++; + } + int temp = s - sup; + if (temp <= 0) + System.out.println((noSup + s)); + else + System.out.println((noSup + (sup))); + caseNum++; + } + } + private static int maxNoSup(int totalScore) + { + int i = totalScore % 3; + switch (i) + { + case 0: return totalScore/3; + case 1: return totalScore/3 + 1; + default: return totalScore/3 + 1; + } + } + private static int maxSup(int totalScore) + { + if (totalScore == 0) + return 0; + int i = totalScore % 3; + switch (i) + { + case 0: return totalScore/3 + 1; + case 1: return totalScore/3 + 1; + default: return totalScore/3 + 2; + } + } +} +" +A21820,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + + +public class Dancing { + + public static String dancing(int N, int S, int p, int number[]) { + int result = 0; + int CntS = S; + int score; + + for (int i = 0; i < N; i++){ + score = number[i]; + if ( 3*p - 2 <= score ) + result ++; + else if ( score < 3*p - 4 ) + continue; + else if ( p - 2 >= 0 && CntS > 0){ + result ++; + CntS --; + } + } + + return """" + result; + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + int T = 0; + String str = """"; + + File input = new File(args[0]); + FileReader fileReader; + BufferedReader br; + + File output = new File(""output_Dancing.txt""); + BufferedWriter bw; + + StringTokenizer tokenizer; + + try { + bw = new BufferedWriter(new FileWriter(output)); + + fileReader = new FileReader(input); + br = new BufferedReader(fileReader); + str = br.readLine(); + + T = Integer.parseInt(str); + + for (int i = 0; i < T; i++) { + int N; + int S; + int p; + int number[]; + + str = br.readLine(); + tokenizer = new StringTokenizer(str); + N = Integer.parseInt(tokenizer.nextToken()); + S = Integer.parseInt(tokenizer.nextToken()); + p = Integer.parseInt(tokenizer.nextToken()); + number = new int[N]; + for (int j = 0; j < N; j++){ + number[j] = Integer.parseInt(tokenizer.nextToken()); + } + + bw.write(String.format(""Case #%d: %s\n"", i+1, dancing(N, S, p, number))); + } + + br.close(); + fileReader.close(); + + bw.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} +" +A21576,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.common; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author jim + */ +public class FileLoader { + + public FileLoader() { + + } + + public ArrayList loadFile(String fileName) throws IOException { + FileReader fr = new FileReader(fileName); + BufferedReader br = new BufferedReader(fr); + String in; + ArrayList lines = new ArrayList(); + while ((in = br.readLine()) != null) { + lines.add(in); + } + return lines; + } + +} +" +A20830,"package code.google.com; + +import java.util.Scanner; + +public class problemB { + + public static void main(String[] Args) { + Scanner sc = new Scanner(System.in); + int tests = sc.nextInt(); + int n, s, p; + + sc.nextLine(); + + for (int i = 1; i <= tests; i++) { + int t; + int count = 0; + int uCount = 0; + n = sc.nextInt(); + s = sc.nextInt(); + p = sc.nextInt(); + + for (int j = 1; j <= n; j++) { + t = sc.nextInt(); + if (suprise(t) >= p && unsuprise(t) >= p) + count++; + else if (suprise(t) >= p) + count++; + else if (unsuprise(t) >= p) + uCount++; + } + + if (s < uCount) + uCount = s; + + System.out.println(""Case #"" + i + "": "" + (count + uCount)); + sc.nextLine(); + + } + + } + + public static int max(int a, int b, int c) { + int max = Integer.MIN_VALUE; + + if (a > max) + max = a; + if (b > max) + max = b; + if (c > max) + max = c; + + return max; + } + + public static int suprise(int t) { + + int dim; + + dim = t / 3; + + if (t == 0) + return 0; + if (t == 30) + return 30; + + if (dim > 0) { + int p; + + p = (dim + 1) + (dim + 1) + (dim); + if (p == t) + return max((dim + 1), (dim + 1), (dim)); + p = (dim + 1) + (dim) + (dim); + if (p == t) + return max((dim + 1), (dim), (dim)); + p = (dim) + (dim) + (dim); + if (p == t) + return max((dim), (dim), (dim)); + p = (dim - 1) + (dim) + (dim); + if (p == t) + return max((dim - 1), (dim), (dim)); + p = (dim - 1) + (dim - 1) + (dim); + if (p == t) + return max((dim - 1), (dim - 1), (dim)); + + } else + return 1; + + return -1; + } + + public static int unsuprise(int t) { + int dim; + int p; + + dim = t / 3; + + if (t == 0) + return 0; + if (t == 30) + return 30; + + if (dim > 1 && dim < 9) { + + p = (dim + 2) + (dim + 1) + (dim); + if (p == t) + return max((dim + 2), (dim + 1), (dim)); + p = (dim + 2) + (dim + 2) + (dim); + if (p == t) + return max((dim + 2), (dim + 2), (dim)); + p = (dim + 2) + (dim) + (dim); + if (p == t) + return max((dim + 2), (dim), (dim)); + p = (dim - 2) + (dim - 1) + (dim); + if (p == t) + return max((dim - 2), (dim - 1), (dim)); + p = (dim - 2) + (dim) + (dim); + if (p == t) + return max((dim - 2), (dim), (dim)); + p = (dim - 2) + (dim - 2) + (dim); + if (p == t) + return max((dim - 2), (dim - 2), (dim)); + p = (dim - 1) + (dim + 1) + (dim); + if (p == t) + return max((dim - 1), (dim + 1), (dim)); + + } + + if (dim <= 1) { + + p = (dim + 2) + (dim) + (dim); + if (p == t) + return max((dim + 2), (dim), (dim)); + p = (dim + 2) + (dim + 2) + (dim); + if (p == t) + return max((dim + 2), (dim + 2), (dim)); + p = (dim + 2) + (dim + 1) + (dim); + if (p == t) + return max((dim + 2), (dim + 1), (dim)); + + if (dim == 1) { + p = (dim - 1) + (dim + 1) + (dim); + if (p == t) + return max((dim - 1), (dim + 1), (dim)); + } + + } + + if (dim >= 9) { + + p = (dim - 2) + (dim - 2) + (dim); + if (p == t) + return max((dim - 2), (dim - 2), (dim)); + p = (dim - 2) + (dim) + (dim); + if (p == t) + return max((dim - 2), (dim), (dim)); + p = (dim - 2) + (dim - 1) + (dim); + if (p == t) + return max((dim - 2), (dim - 1), (dim)); + + if (dim == 9) { + p = (dim - 1) + (dim + 1) + (dim); + if (p == t) + return max((dim - 1), (dim + 1), (dim)); + } + + } + + return -1; + } +} +" +A22287,"import java.util.*; +import java.io.*; + +public class dancers { + public static int test(int[] n){ + int counter = 0; + int counter2 = 0; + for(int i = 3; i < n[0] + 3; i++){ + if(n[i] >= (n[2]*3 - 2)){ + counter++; + } else if((n[i] < n[2]*3 - 2) && (n[i] >= n[2]*3 - 4)){ + if((n[2]*3-4 < 0) && n[i] == 0){ + continue; + } + counter2++; + } + } + + if(counter2 <= n[1]){ + counter += counter2; + } else{ + counter += + n[1]; + } + + return counter; + } + public static void main(String[] args) throws IOException{ + Scanner reader = new Scanner(new File(""dancers.in"")); + PrintWriter out = new PrintWriter(new File(""dancers.out"")); + + int n = reader.nextInt(); + int[][] set = new int[n][103]; + for(int i = 0; i < n; i++){ + set[i][0] = reader.nextInt(); + for(int j = 1; j < set[i][0] + 3; j++){ + set[i][j] = reader.nextInt(); + } + } + int[] res = new int[n]; + for(int i = 0; i < n; i++){ + res[i] = test(set[i]); + out.println(""Case #"" + (i+1) + "": "" + res[i]); + } + + out.close(); + System.exit(0); + } +}" +A21059,"package code.jam.y2012.quali; + +import java.io.*; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +public class ProblemB { + + private static String PATH = ""F:\\dev\\projects\\code-jam-2012\\src\\code\\jam\\y2012\\quali""; + File inputFile = new File(PATH, ""B-large.in""); + File outputFile = new File(PATH, ""B-large.out""); + BufferedReader in; + PrintWriter out; + StringTokenizer st = new StringTokenizer(""""); + + public static void main(String[] args) throws Exception { + new ProblemB().solve(); + } + + void solve() throws Exception { + in = new BufferedReader(new FileReader(inputFile)); + out = new PrintWriter(outputFile); + + for (int testCase = 1, testCount = nextInt(); testCase <= testCount; testCase++) { + solve(testCase); + } + + out.close(); + } + + void solve(int testCase) throws IOException { + final int googlers = nextInt(); + final int surprises = nextInt(); + final int atLeastRate = nextInt(); + int googlersPass = 0; + int surprisesUsed = 0; + for (int i = 0; i < googlers; i++) { + final double minSafeAverage = (atLeastRate * 3 - 2) / 3d; + final double minSurpriseAverage = (atLeastRate * 3 - 4) / 3d; + final int googlerTotal = nextInt(); + if (atLeastRate==0 && googlerTotal==0) { + googlersPass++; + continue; + } + if (googlerTotal==0) { + continue; + } + final double googlerAverage = googlerTotal / 3d; + if (googlerAverage>=minSafeAverage) { + //System.out.println(""pass: "" + googlerTotal + "" "" + googlerAverage); + googlersPass++; + continue; + } + if (googlerAverage>=minSurpriseAverage && surprises>surprisesUsed) { + //System.out.println(""PASS: "" + googlerTotal + "" "" + googlerAverage); + googlersPass++; + surprisesUsed++; + continue; + } + } + print(""Case #"" + testCase + "": "" + googlersPass); + } + + private void print(String text) { + out.println(text); + System.out.println(text); + } + + + /** + * helpers + */ + String nextToken() throws IOException { + while (!st.hasMoreTokens()) { + st = new StringTokenizer(in.readLine()); + } + return st.nextToken(); + } + + int nextChar() throws IOException { + return in.read(); + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + String nextLine() throws IOException { + st = new StringTokenizer(""""); + return in.readLine(); + } + + boolean EOF() throws IOException { + while (!st.hasMoreTokens()) { + String s = in.readLine(); + if (s == null) { + return true; + } + st = new StringTokenizer(s); + } + return false; + } + +} +" +A21302,"import java.util.Scanner; + + +public class B { + + static Scanner in = new Scanner(System.in); + + int solve() { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int yesLimit = p + 2 * Math.max(0, p-1); + int maybeLimit = p + 2 * Math.max(0, p-2); + + int yes = 0; + int maybe = 0; + + for (int i=0; i= yesLimit) { + ++yes; + } else if (totalPoints >= maybeLimit) { + ++maybe; + } + } + + return yes + Math.min(S, maybe); + } + + + public static void main(String[] args) { + int T = in.nextInt(); + for (int i=1; i<=T; ++i) { + int ans = new B().solve(); + System.out.println(""Case #"" + i + "": "" + ans); + } + + } + +} +" +A20653,"import java.util.List; + + +public class QB { + public static void main( String args[]) + { + LeerArchivo leer = new LeerArchivo(); + leer.abrirArchivo(""B-large.txt""); + + EscribirArchivo escribir = new EscribirArchivo(); + escribir.abrirArchivo(""respuesta.txt""); + + List lineasArchivo = leer.leer(); + + int numeroDeCasos = Integer.parseInt(lineasArchivo.get(0)); + int contadorLineas =1; + for(int contador=0; contador <= numeroDeCasos-1; contador++) + { + String linea[] = lineasArchivo.get(contadorLineas).split("" ""); + int N = Integer.parseInt(linea[0]); + int S = Integer.parseInt(linea[1]); + int P = Integer.parseInt(linea[2]); + int puntajeGooglers[] = new int[linea.length-2]; + int contadorPuntajes = 0; + for(int i = 3; i<= linea.length-1; i++) + { + puntajeGooglers[contadorPuntajes] = Integer.parseInt(linea[i]); + contadorPuntajes++; + } + + int resultado = solve(N,S,P,puntajeGooglers); + + escribir.escribirLinea(""Case #""+(contador+1)+"": ""+resultado); + + contadorLineas++; + + } + escribir.cerrarArchivo(); + } + + public static int solve(int N, int S, int P, int puntajeGooglers[]) + { + int success = 0; + for(int googler = 0; googler<=N-1; googler++) + { + int puntaje = puntajeGooglers[googler]; + for(int i = 0; i<=puntaje; i++) + { + if(i+i+i==puntaje) + { + if(i>=P && i<=10) + { + System.out.println(i+"" - ""+i+"" - ""+i); + success++; + break; + } + } + if(i+i+i+1==puntaje && i+1<=10) + { + + if(i+1>=P) + { + System.out.println(i+"" - ""+i+"" - ""+(i+1)); + success++; + break; + } + } + if(i+i+i-1==puntaje && i-1<=10) + { + + if(i>=P) + { + System.out.println(i+"" - ""+i+"" - ""+(i-1)); + success++; + break; + } + } + + if(i+i+i+2==puntaje && S>0) + { + if(i+2>=P && i+2<=10) + { + System.out.println(i+"" - ""+i+"" - ""+(i+2)); + S--; + success++; + break; + } + } + if(i+i+i-2==puntaje && S>0) + { + if(i>=P && i<=10) + { + System.out.println(i+"" - ""+i+"" - ""+(i-2)); + S--; + success++; + break; + } + + } + + if(i+i+i-3==puntaje && S>0) + { + if(i>=P && i<=10) + { + System.out.println((i-2)+"" - ""+(i-1)+"" - ""+i); + S--; + success++; + break; + } + } + } + + + + +// if(googlerCumple(puntaje,S,P)) +// success++; + + } + return success; + } + + public static Boolean googlerCumple(int puntaje, int S, int P) + { + for(int i = 0; i<=puntaje; i++) + { + if(i+i+i==puntaje) + { + if(i>=P && i<=10) + { + System.out.println(i+"" - ""+i+"" - ""+i); + return true; + } + } + if(i+i+i+1==puntaje && i+1<=10) + { + + if(i+1>=P) + { + System.out.println(i+"" - ""+i+"" - ""+(i+1)); + return true; + } + } + if(i+i+i-1==puntaje && i-1<=10) + { + + if(i>=P) + { + System.out.println(i+"" - ""+i+"" - ""+(i-1)); + return true; + } + } + + if(i+i+i+2==puntaje && S>0) + { + if(i+2>=P && i+2<=10) + { + System.out.println(i+"" - ""+i+"" - ""+(i+2)); + S--; + return true; + } + } + if(i+i+i-2==puntaje && S>0) + { + if(i>=P && i<=10) + { + System.out.println(i+"" - ""+i+"" - ""+(i-2)); + S--; + return true; + } + + } + + if(i+i+i-3==puntaje && S>0) + { + if(i>=P && i<=10) + { + System.out.println((i-2)+"" - ""+(i-1)+"" - ""+i); + S--; + return true; + } + } + } + return false; + } + +} +" +A20555,"package codejam2012.qualification.b; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class Main { + + Logger log = LoggerFactory.getLogger(Main.class); + + private Scanner in; + private PrintWriter out; + private Memory memory = new Memory(); + + public Main(InputStream in, OutputStream out) { + this.in = new Scanner(in); + this.out = new PrintWriter(out); + } + + public void run() throws Exception { + memory.init(); + int T = in.nextInt(); + log.debug(""T: "" + T); + + for (int t = 1; t <= T; ++t) { + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + + List totals = new ArrayList(); + + for (int n = 1; n <= N; ++n) { + totals.add(in.nextInt()); + } + + log.debug(""N: "" + N + "" S: "" + S + "" P: "" + P + "" totals: "" + totals); + + Round round = new Round(totals, memory); + int result = round.run(S, P); + log.debug(""result: "" + result); + + out.println(String.format(""Case #%d: %d"", t, result)); + } + + out.flush(); + } + + public static void main(String[] args) throws Exception { + String path = ""src/main/resources/"" + args[0]; + try (FileInputStream in = new FileInputStream(path + "".in""); FileOutputStream out = new FileOutputStream(path + "".out"")) { + Main main = new Main(in, out); + main.run(); + } + } +} +" +A20985,"package fixjava; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; +import java.util.Map.Entry; + +public class CountedSet implements Set { + + HashMap map = new HashMap(); + private static final Integer ONE = new Integer(1); + + public CountedSet(Iterable collection) { + for (T t : collection) + add(t); + } + + @Override + public boolean add(T item) { + Integer count = map.get(item); + if (count == null) { + map.put(item, ONE); + return true; + } else { + map.put(item, count + 1); + return false; + } + } + + /** New method to fetch count, not in normal Sets. Returns null if key is not in set. */ + public Integer get(String key) { + return map.get(key); + } + + /** New method to fetch count, not in normal Sets. Returns zero if key is not in set. */ + public int getCount(String key) { + Integer count = map.get(key); + return count == null ? 0 : count; + } + + /** Extra method to iterate over entries consisting of both items and counts */ + public Iterator> iteratorWithCounts() { + return map.entrySet().iterator(); + } + + /** Extra method to iterate over entries consisting of both items and counts */ + public Iterable> iteratableWithCounts() { + return map.entrySet(); + } + + /** Convert into sorted list of pairs */ + public ArrayList> toListSortedByCount(boolean ascending) { + ArrayList> list = Pair.mapToList(map); + Pair.sortPairsByRight(list, ascending); + return list; + } + + // ----- boilerplate stuff: ----- + + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (T item : collection) { + add(item); + changed = true; + } + return changed; + } + + @Override + public void clear() { + map.clear(); + } + + @Override + public boolean contains(Object item) { + return map.containsKey(item); + } + + @Override + public boolean containsAll(Collection collection) { + boolean containsAll = true; + for (Object item : collection) { + if (!contains(item)) { + containsAll = false; + break; + } + } + return containsAll; + } + + @Override + public boolean isEmpty() { + return map.isEmpty(); + } + + /** Just iterates over keys, not counts */ + @Override + public Iterator iterator() { + return map.keySet().iterator(); + } + + @Override + public boolean remove(Object item) { + return map.remove(item) != null; + } + + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object item : collection) { + if (remove(item)) { + changed = true; + break; + } + } + return changed; + } + + @Override + public boolean retainAll(Collection arg0) { + throw new RuntimeException(""Not implemented""); + } + + @Override + public int size() { + return map.size(); + } + + /** Just returns keys in array, not counts */ + @Override + public Object[] toArray() { + return map.keySet().toArray(); + } + + /** Just returns keys in array, not counts */ + @Override + public U[] toArray(U[] arr) { + return map.keySet().toArray(arr); + } +} +" +A20851," + + +public interface Solver { + + public String solve(); +} +" +A20753,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package actual; + +import codejam.*; +import java.io.*; +import java.util.Scanner; +/** + * + * @author atm + */ +public class PB { + public static void main(String[] args) throws Exception { + int Cases; + int N, P, S; + String words[]; + + FileInputStream fstreamIN = new FileInputStream(""F:\\codejam\\input\\B-small-attempt1.in""); + FileOutputStream fstreamOUT = new FileOutputStream(""F:\\codejam\\output\\B-small-attempt1.out""); + + Scanner in=new Scanner(fstreamIN); + PrintWriter out=new PrintWriter(fstreamOUT); + + Cases=in.nextInt(); + + for(int i=0;i=0){ + ans++; + } + } else if(P==1){ + if(num>0) + ans++; + }else if(num>=(3*P - 2)) + ans++; + else if(num>=(3*P - 4) && tempS!=0) + { + ans++; tempS--; + } + } + out.printf(""Case #%d: %d\n"",i+1,ans); + } + out.close(); + } +} +" +A22907,"import java.util.Scanner; + + +public class Start { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner in=new Scanner(System.in); + int cases=in.nextInt(); + + for (int x=1;x<=cases;x++){ + int c=0; + int num=in.nextInt(); + int surp=in.nextInt(); + int best=in.nextInt(); + // int[] dancer=new int[num]; + for (int y=0;y=best)c++; + else if (point+1>=best &&rest>=1)c++; + else if (point+2>=best&&surp>0&&rest==2){ + c++; + surp--; + } + else if (point+1>=best && surp>0 && point>0){ + c++; + surp--; + } + } + System.out.println(""Case #""+x+"": ""+c); + } + + } + +} +" +A20224," +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author sony + */ + +public class DancingGooglers { + public static void main(String[] args) throws FileNotFoundException, IOException + { + BufferedReader br=new BufferedReader(new FileReader(args[0])); + + int Testcases=Integer.parseInt(br.readLine()); + for(int i=0;i=p)||(reminder==1&"ient+1==p)||(reminder==2&"ient+1==p)) + count++; + else if(S>0&&sum>=p){ + + if((reminder==0&"ient+1==p)||(reminder==2&"ient+2==p)) + { + S--; + count++; + } + + } + + + } + + System.out.print(""Case #""+(i+1)+"": ""+count+""\n""); + + + + } + + } + +} + +" +A22289,"import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + Scanner s = new Scanner(System.in); + OutputBuilder output = new OutputBuilder(); + int tests = s.nextInt(); + s.nextLine(); + for (int i = 0; i < tests; i++) { + output.addLine(String.valueOf(getMaxDancers(s.nextLine()))); + } + System.out.println(output.toString()); + } + + private static int getMaxDancers(String line) { + String[] parameters = line.split("" ""); + int surprising = Integer.parseInt(parameters[1]); + int minScore = Integer.parseInt(parameters[2]); + int minNorm = minScore * 3 - 2; + int minSurp = minNorm - 2; + + int dancers = 0; + for(int i = 3; i < parameters.length; i++){ + int sum = Integer.parseInt(parameters[i]); + if(sum >= minNorm || (sum > 1 && sum >= minSurp && surprising-- > 0)){ + dancers++; + } + } + return dancers; + } + + private static class OutputBuilder{ + + private final StringBuilder output = new StringBuilder(); + + private int i = 1; + + void addLine(String s){ + this.output.append(""Case #""); + this.output.append(this.i); + this.output.append("": ""); + this.output.append(s); + this.output.append(""\n""); + this.i++; + } + + @Override + public String toString(){ + return this.output.toString(); + } + } + +} +" +A21290,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class Dancing { + + + public static void main(String[] args) throws IOException + { + File file = new File(""B-large.in""); + Scanner scanner; + BufferedWriter out = new BufferedWriter(new FileWriter(""outfile"")); + + try + { + scanner = new Scanner(file); + int testCases = scanner.nextInt(); + scanner.nextLine(); + + for(int numTest=0; numTest=P) + count++; + else + { + if((avg+1>=P)&&(S>0)) + { + count++; + S--; + } + } + } + if(mod==1) + { + if(avg+1>=P) + count++; + } + if(mod==2) + { + if(avg+1>=P) + count++; + else + { + if((avg+2>=P)&&(S>0)) + { + count++; + S--; + } + } + } + } + } + out.write(""Case #""+(numTest+1)+"": ""+ count +""\n""); + } + + out.close(); + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + + } +} +" +A20912,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class DancingWithGooglers { + + public static void main(String[] args) { + + try { + + BufferedReader br = new BufferedReader(new FileReader(""input.txt"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""output.txt"")); + + int K, N, S, p, i, j; + + K = Integer.parseInt(br.readLine()); + for (i = 0; i < K; i++) { + + String[] line = br.readLine().split("" ""); + N = Integer.parseInt(line[0]); + S = Integer.parseInt(line[1]); + p = Integer.parseInt(line[2]); + + int[] data = new int[line.length - 3]; + for (j = 0; j < data.length; j++) { + data[j] = Integer.parseInt(line[j + 3]); + // System.out.print(data[j] + "" ""); + } + // System.out.println(); + + int counter = 0; + for (j = 0; j < data.length; j++) { + + int a, b, c; + + int res; + a = (int) Math.floor((double) data[j] / 3); + res = data[j] - a; + b = (int) Math.floor((double) res / 2); + res = res - b; + c = res; + + if (a >= p || b >= p || c >= p) { + counter++; + } else if ((a + b + c) != 0 && (a + b + c) != 1) { + int temp = (p - a) + (p - b) + (p - c); + + if (temp == 3 && S > 0) { + + counter++; + S--; + } else if (temp == 4 && S > 0) { + counter++; + S--; + + } + } + + } + bw.write(""Case #"" + (i+1) + "": "" + counter); + bw.newLine(); + + } + br.close(); + bw.close(); + + } catch (IOException io) { + } + + } + +} +" +A21804,"package com.google.codejam.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class CodeJamInputFile extends File { + + /** + * + */ + private static final long serialVersionUID = 8294095294390757204L; + private BufferedReader reader; + private int cases; + + public CodeJamInputFile(String pathname) { + super(pathname); + + try { + this.setReader(); + } catch (FileNotFoundException e) { + } + try { + this.setCases(Integer.valueOf(this.getReader().readLine())); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void setReader() throws FileNotFoundException { + reader = new BufferedReader(new FileReader(this)); + + } + + public BufferedReader getReader() { + return reader; + } + + public void setCases(int cases) { + this.cases = cases; + } + + public int getCases() { + return cases; + } + + public void close() { + try { + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public String getLine() { + String line = """"; + try { + line = reader.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return line; + } + +} +" +A21475,"package dancing; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Dance { + public static void main(String[] args) throws Exception + { + new Dance().run(); + } + + void run() throws Exception + { + Scanner sc = new Scanner(new FileReader(""2.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""2.out"")); + + int ntest = sc.nextInt(); + sc.nextLine(); + + for(int test=1;test<=ntest;++test) + { + String s = sc.nextLine(); + String[] ss = s.split("" ""); + int res = 0; + int min = 0; + if(Integer.parseInt(ss[2])==0) + min = 0; + else if(Integer.parseInt(ss[2])==1) { + min = 1; + } + else{ + min = (Integer.parseInt(ss[2]))*3-4; + } + int bound = (Integer.parseInt(ss[2]))*3-2; + int count = Integer.parseInt(ss[1]); + for(int i=3;i=bound) + res++; + else if(Integer.parseInt(ss[i])>=min&&count>0){ + res++; + count--; + } + } + pw.print(""Case #"" + test + "": ""+res); + pw.println(); + } + pw.close(); + sc.close(); + } + +} +" +A20501," + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.Writer; + +public class Googledance { + public static void main (String[] args) { + FileReader fr = null; + BufferedReader br = null; + Writer out = null; + Writer debug = null; + try { + fr = new FileReader(args[0]); + br = new BufferedReader(fr); + out = new OutputStreamWriter(new FileOutputStream(""googledance-result.txt"")); + debug = new OutputStreamWriter(new FileOutputStream(""googledance-debug.txt"")); + String numOfLine = br.readLine(); + int line = 0; + if (numOfLine != null) { + line = Integer.valueOf(numOfLine); + } else { + return; + } + + String lineData; + String[] danceArray; + + for (int i = 1; i <= line; i++) { + String resultLine = """"; + lineData = br.readLine(); + danceArray = lineData.split("" ""); + int numOfGoogler = Integer.valueOf(danceArray[0]); + int numOfSurprise = Integer.valueOf(danceArray[1]); + int minSingleScore = Integer.valueOf(danceArray[2]); + + int googlerTotalScore = 0; + int okCounter = 0; + int surpriseCounter = 0; + int kOk = 0, lOk = 0, mOk = 0; + boolean okNumber = false; + boolean surpriseNumber = false; + for (int j = 3; j < 3 + numOfGoogler; j++) { + okNumber = false; + surpriseNumber = false; + kOk = 0; lOk = 0; mOk = 0; + googlerTotalScore = Integer.valueOf(danceArray[j]); + if (minSingleScore >=2) { + for (int k = minSingleScore - 2; k <= 30; k++) { + if (okNumber && !surpriseNumber) { + break; + } + for (int l = minSingleScore - 2; l <= 30; l++) { + if (okNumber && !surpriseNumber) { + break; + } + for (int m = minSingleScore - 2; m <= 30; m++) { + if ((k + l + m) == googlerTotalScore) { + if (k >= minSingleScore || l >= minSingleScore || m >= minSingleScore) { + if ((Math.abs(k - l) < 2) && (Math.abs(l - m) < 2) && (Math.abs(k - m) < 2)) { + okNumber = true; + kOk = k; + lOk = l; + mOk = m; + surpriseNumber = false; + break; + } else if ((Math.abs(k - l) <= 2) && (Math.abs(l - m) <= 2) && (Math.abs(k - m) <= 2)) { + okNumber = true; + kOk = k; + lOk = l; + mOk = m; + surpriseNumber = true; + } + } + } + } + } + } + + debug.write(""break out at: "" + kOk + "" "" + lOk + "" "" + mOk + "" ok: "" + okNumber + "" surprise: "" + surpriseNumber + ""\n""); + + if (okNumber) { + okCounter++; + } + + if (surpriseNumber) { + surpriseCounter++; + } + } else if (minSingleScore == 1) { + for (int k = minSingleScore - 1; k <= 30; k++) { + if (okNumber && !surpriseNumber) { + break; + } + for (int l= minSingleScore - 1; l <= 30; l++) { + if (okNumber && !surpriseNumber) { + break; + } + for (int m = minSingleScore - 1; m <= 30; m++) { + if ((k + l + m) == googlerTotalScore) { + if (k >= minSingleScore || l >= minSingleScore || m >= minSingleScore) { + if ((Math.abs(k - l) < 2) && (Math.abs(l - m) < 2) && (Math.abs(k - m) < 2)) { + okNumber = true; + kOk = k; + lOk = l; + mOk = m; + surpriseNumber = false; + break; + } else if ((Math.abs(k - l) <= 2) && (Math.abs(l - m) <= 2) && (Math.abs(k - m) <= 2)) { + okNumber = true; + kOk = k; + lOk = l; + mOk = m; + surpriseNumber = true; + } + } + } + } + } + } + + debug.write(""break out at: "" + kOk + "" "" + lOk + "" "" + mOk + "" ok: "" + okNumber + "" surprise: "" + surpriseNumber + ""\n""); + + if (okNumber) { + okCounter++; + } + + if (surpriseNumber) { + surpriseCounter++; + } + } else if (minSingleScore == 0) { + for (int k = minSingleScore; k <= 30; k++) { + if (okNumber && !surpriseNumber) { + break; + } + for (int l= minSingleScore; l <= 30; l++) { + if (okNumber && !surpriseNumber) { + break; + } + for (int m = minSingleScore; m <= 30; m++) { + if ((k + l + m) == googlerTotalScore) { + if (k >= minSingleScore || l >= minSingleScore || m >= minSingleScore) { + if ((Math.abs(k - l) < 2) && (Math.abs(l - m) < 2) && (Math.abs(k - m) < 2)) { + okNumber = true; + kOk = k; + lOk = l; + mOk = m; + surpriseNumber = false; + break; + } else if ((Math.abs(k - l) <= 2) && (Math.abs(l - m) <= 2) && (Math.abs(k - m) <= 2)) { + okNumber = true; + kOk = k; + lOk = l; + mOk = m; + surpriseNumber = true; + } + } + } + } + } + } + + debug.write(""break out at: "" + kOk + "" "" + lOk + "" "" + mOk + "" ok: "" + okNumber + "" surprise: "" + surpriseNumber + ""\n""); + debug.write(""\n""); + + if (okNumber) { + okCounter++; + } + + if (surpriseNumber) { + surpriseCounter++; + } + } + } + + if (surpriseCounter > numOfSurprise) { + okCounter = okCounter - (surpriseCounter - numOfSurprise); + } + + resultLine = ""Case #"" + i + "": "" + okCounter; + + debug.write(""\n""); + out.write(resultLine); + if (i != line) { + out.write(""\n""); + } + System.out.println(resultLine); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + br.close(); + fr.close(); + out.close(); + debug.close(); + } catch(Exception e) {} + } + } +} +" +A22509,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.StringTokenizer; + + +public class dancing { + public static void main(String[] args) { + // TODO Auto-generated method stub + String input=""""; + StringTokenizer strtok; + + int googlers, surprises, p, count=0; + + int line = 0; + int totalscore, base, residual; + try { + BufferedReader inputStream = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter writer = new BufferedWriter(new FileWriter(""output.txt"")); + + line = Integer.parseInt(inputStream.readLine()); + for(int i=0; i< line; i++){ + input = inputStream.readLine(); + strtok = new StringTokenizer(input,"" ""); + + googlers = Integer.parseInt(strtok.nextToken()); + surprises = Integer.parseInt(strtok.nextToken()); + p = Integer.parseInt(strtok.nextToken()); + for(int j=0 ; j< googlers; j++){ + totalscore = Integer.parseInt(strtok.nextToken()); + base = totalscore/3; + residual = totalscore % 3; + + triplet normal,surprise; + + if(residual==0){ + //normal + normal = new triplet(base,base,base); + //surprising + surprise = new triplet(base-1,base,base+1); + + if(normal.score()>=p) + count++; + else if(surprise.status!=""invalid"" && surprise.score()>=p && surprises > 0){ + count++; + surprises--; + } + } + else if(residual==1){ + //normal + normal = new triplet(base,base,base+1); + //surprising but not helpful + //new triplet(base-1,base+1,base+1); + if(normal.score()>=p) + count++; + } + else if(residual==2){ + //normal + normal = new triplet(base,base+1,base+1); + //surprising + surprise = new triplet(base,base,base+2); + if(normal.score()>=p) + count++; + else if(surprise.status!=""invalid"" && surprise.score()>=p && surprises > 0){ + count++; + surprises--; + } + } + }//for each googler + + //System.out.println(""Case #""+(i+1)+"": ""+count); + + if(i!=line-1) + writer.write(""Case #""+(i+1)+"": ""+count+""\r\n""); + else + writer.write(""Case #""+(i+1)+"": ""+count); + count = 0; + + + + }//read new line + writer.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + }//main +} + + + + + + + + + + + + +" +A22726,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + + +public class gcjq1 { + + public static void main(String[] args) { + + try{ + FileInputStream ifstream = new FileInputStream(""files/B-large.in""); + DataInputStream in = new DataInputStream(ifstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileOutputStream ofstream = new FileOutputStream(""files/output""); + DataOutputStream out = new DataOutputStream(ofstream); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); + + int numCases = Integer.parseInt(br.readLine()); + + for(int i=0; i= n){ + c++; + } + else { + n = p+(2*(p-2)); + if(t[i] >= n && t[i] > 0 && s>0){ + c++; + s--; + } + } + } + + return Integer.toString(c); + } +} + +" +A21282,"import java.io.*; + +public class Task2 { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File(""t.txt""))); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""out.txt""))); + int num = Integer.parseInt(reader.readLine().trim()); + for (int i = 0; i < num; i++) { + String orig = reader.readLine(); + writer.write(""Case #"" + (i+1) + "": ""); + String[] strs = orig.split("" +""); + int n = Integer.parseInt(strs[0]); + int g = Integer.parseInt(strs[1]); + int p = Integer.parseInt(strs[2]); + int res = 0; + for(int j = 3; j < strs.length; j++){ + int k = Integer.parseInt(strs[j]); + if(k / 3 > p-1 || (k /3 == p-1 && k % 3 != 0)){ + res++; + } else { + if (g > 0 && ((k-p >= 0) && ((k-p)/ 2 >= p - 2 || ((k-p) / 2 == p - 1 && (k-p) % 2 != 0)))) { + g--; + res++; + } + } + } + writer.write("""" + res); + if(i < num-1){ + writer.write('\n'); + } + } + writer.close(); + reader.close(); + } +} +" +A22389,"package contest; +import java.io.BufferedReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Input { + BufferedReader in; + + public Input(BufferedReader in) { + this.in = in; + } + + // + + public String readStr() { + return readStr(in); + } + + public int readInt() { + return readInt(in); + } + + public int[] readIntArr() { + return readIntArr(in, "" ""); + } + + public List readIntList() { + return readIntList(in, "" ""); + } + + public List readStrList() { + return readStrList(in, "" ""); + } + + // + + public String readStr(BufferedReader in) { + try { + return in.readLine(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public int readInt(BufferedReader in) { + return Integer.parseInt(readStr(in)); + } + + public int[] readIntArr(BufferedReader in) { + return readIntArr(in, "" ""); + } + + public int[] readIntArr(BufferedReader in, String delimiter) { + String[] tokens = readStr(in).split(delimiter); + int[] ints = new int[tokens.length]; + for (int i = 0; i < tokens.length; i++) { + ints[i] = Integer.parseInt(tokens[i]); + } + return ints; + } + + public List readIntList(BufferedReader in) { + return readIntList(in, "" ""); + } + + public List readIntList(BufferedReader in, String delimiter) { + String[] tokens = readStr(in).split(delimiter); + List ints = new ArrayList(tokens.length); + for (int i = 0; i < tokens.length; i++) { + ints.add(Integer.parseInt(tokens[i])); + } + return ints; + } + + public List readStrList(BufferedReader in, String delimiter) { + return Arrays.asList(readStr(in).split(delimiter)); + } +} +" +A22520,"package codejam; + +import java.io.File; +import java.io.PrintStream; +import java.util.Scanner; + +public class QualificationB { + public static void main(String[] args){ + try{ + Scanner sc=new Scanner(new File(""B.in"")); + PrintStream ps=new PrintStream(""B.out""); + int t=sc.nextInt(); + for(int i=0;i(p-1)*3)count++; + else if(x>1&&x>(p-1)*3-2&&s>0){ + count++; + s--; + } + } + ps.println(""Case #""+(i+1)+"": ""+count); + } + }catch(Exception e){ + e.printStackTrace(); + } + } +} +" +A20694,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DancingWiththeGooglers { + public static void main(String[] args) { + try { + FileWriter w = new FileWriter(new File(""E:\\output.out"")); + BufferedReader r = new BufferedReader(new FileReader(new File(""E:\\B-large.in""))); + int numbeOfCases = Integer.parseInt(r.readLine()); + for(int t = 0; t < numbeOfCases; t++) { + String[] nums = r.readLine().split("" ""); + int s = Integer.parseInt(nums[1]); + int p = Integer.parseInt(nums[2]); + + int mid = Math.max(0, 3 * p - 2); + int min = Math.max(0, 3 * p - 4); + int number = 0; + for(int i = 3; i < nums.length; i++) { + int score = Integer.parseInt(nums[i]); + if(p <= score) { + if(score >= mid) + number++; + else if (score >= min && s > 0) { + s--; + number++; + } + } + } + + w.write(""Case #"" + (t + 1) + "": "" + (number)); + //System.out.println(""Case #"" + (t + 1) + "": "" + (number)); + if(t < numbeOfCases - 1) + w.write(""\n""); + //System.out.println(t); + } + w.close(); + r.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} +" +A21503,"/** + * + * @author amit + */ +import java.io.*; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; +//import java.util.Arrays; +//import java.math.BigInteger; + +public class GCJ { + + BufferedReader rin; + BufferedWriter wout; + int numCases; + + + public String getNextInput() { + try { + String line = rin.readLine(); + String[] aVars = line.split("" ""); + long count = 0; + long N = Long.parseLong(aVars[0]); + long S = Long.parseLong(aVars[1]); + long P = Long.parseLong(aVars[2]); + ArrayList gc = new ArrayList(); + for (int i=0; i=0; i--) { + long t1 = gc.get(i); + //System.out.println(""\nnum: "" + t1); + long t2 = (long) Math.ceil((double)t1/3.0); + if (t1 ==1 && P==2) break; + if (t1 ==0 && P>0) break; + if (P<= t2) { + count ++; + //System.out.println(""\nadded without S""); + } + else if (S>0 && P<=t2+1) { + count ++; + S--; + //System.out.println(""\nadded with S""); + } + else break; + } + /* + long t = Long.parseLong(aVars[i+3]); + System.out.println(""\nscore"" + t); + if ((t%3)==2) { + System.out.println(""mod2""); + if (P <= t/3+1) { + count ++; + } + } + else if ((t%3)==1) { + System.out.println(""mod1""); + S--; + if (P <= t/3 +1) { + count++; + } + } + else { + gc.add(t); + System.out.println(""mod3""); + } + } + Collections.sort(gc); + if (!(gc.isEmpty())) { + for (int i=gc.size()-1; i>=0; i--) { + //System.out.println(""\ni: "" + i); + long t1 = gc.get(i); + if (P<=t1/3) { + count ++; + } + else if (P<=t1/3+1) { + count ++; + S--; + } + else if (S>0) { + System.out.println(""\nError!""); + } + else break; + } + }*/ + return Long.toString(count); + } catch (IOException e) { + System.out.println(""File Error! Could not read line from file""); + } + return null; + } + + public void writeNextOutput(String s) { + try { + wout.write(s); + wout.write(""\n""); + } catch (IOException e) { + System.out.println(""Error! Could not write to the file!""); + } + } + + public GCJ(String s1, String s2) { + try { + rin = new BufferedReader( + new FileReader(s1)); + wout = new BufferedWriter(new FileWriter(s2)); + numCases = Integer.parseInt(rin.readLine()); + + for(int i=1; i <= numCases; i++){ + System.out.println(""case#"" + i); + String sout = getNextInput(); + sout = ""Case #"" + Integer.toString(i) + "":"" + "" "" + sout; + writeNextOutput(sout); + //System.out.println(""case#"" + i); + } + rin.close(); + wout.close(); + } catch (IOException e) { + System.out.println(""File error""); + System.exit(0); + } + } + + public static void main(String[] args) {/* + if (args.length!=2) { + System.out.println(""Enter input file!""); + System.exit(0); + }*/ + GCJ a = new GCJ(""infile.txt"", ""out.txt""); + } +} +" +A21113,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package google; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Arber + */ +public class Google { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Path input_path = new File(""Input.in"").toPath(); + try { + List input_list = Files.readAllLines(input_path,Charset.forName(""UTF-8"")); + int begin = 0; + while(begin a1 = new ArrayList(); + for(int i = n; i<=m; i++) + { + for(int j = 1; j<(""""+n).length();j++) + { + int rec = recycled(""""+i, j); + if(rec>=n &&rec<=m && rec != i) + { + if(rec=3*p-2) + rez++; + else if((t[i]>=3*p-4&&s>0&&p>1)) + { + s--; + rez++; + } + } + return rez; + } +} +" +A22275,"import java.io.*; + +public class code3 { + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + FileWriter fos = new FileWriter(""outfile"",false); + BufferedWriter bw = new BufferedWriter(fos); + int T=Integer.parseInt(br.readLine()), j=1, N , s, p, ti, i , ans ,cancellable;String str[]; + for(;T>0;T--,j++) + { + str=(br.readLine()).split("" "").clone(); + N= Integer.parseInt(str[0]); + s= Integer.parseInt(str[1]); + p= Integer.parseInt(str[2]); + i=0; + ans=0; + cancellable=0; + while(i=p) + ans++; + } + else{ + if(ti == 3*p-4 || ti==3*p-3) + { + if(s!=0) + {s--;ans++;cancellable++;} + + } + else if(ti >= 3*p-2) + { + ans++; + } + } + } + if(s>N-cancellable) + ans=ans-s; + bw.write(""Case #""+j+"": ""+ans+""\n""); + } + bw.close(); + } +}" +A22810,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.StringTokenizer; + + +public class ProblemB { + public static void main(String [] args) throws NumberFormatException, IOException + { + BufferedReader r = new BufferedReader( new FileReader(""C:\\Users\\ÐÐÐ\\Downloads\\B-small-attempt1.in"")); + ArrayList s = new TestCaseReader().read(r); + s = new ProblemB().remap(s); + OutputPrinter p = new OutputPrinter(); + for (String str : s) + p.print(str); + p.m_writer.flush(); + p.m_writer.close(); + + } + + private ArrayList remap(ArrayList s) { + ArrayList remapped = new ArrayList(); + for (String str : s) + { + + StringTokenizer tk = new StringTokenizer(str, "" ""); + + int n_googlers = Integer.parseInt(tk.nextToken()); + int n_surprises = Integer.parseInt(tk.nextToken()); + int target_score = Integer.parseInt(tk.nextToken()); + int total = 0; + + for (int i = 0 ; i < n_googlers ; i ++ ) + { + int score = Integer.parseInt(tk.nextToken()); + int score_div = score % 3; + int score_avg = score /3; + + if (score < target_score) + continue; + + if (score_avg >= target_score&& score_div == 0) + total++; + else + if (score_div > 0 && score_avg >= target_score -1 ) + { + total++; + } + else + if (n_surprises > 0) + { + int avg_rest_of_score = (score - target_score)/2; + if (score_avg >= target_score -2 && (target_score - avg_rest_of_score) <= 2) + { + total ++; + n_surprises --; + } + } + + } + remapped.add("""" +total); + } + return remapped; + } +} +" +A21817,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package dancing; +import java.io.*; +import java.util.*; + +/** + * + * @author Ewka + */ +public class Dancing { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + FileReader fr=null; + PrintWriter fw=null; + BufferedReader br; + int noOfLines=0; + int noOfGooglers=0; + int noOfSurprising=0; + int noOfOut=0; + int p=0; + int noOfUsedSurp=0; + + String[] temp; + + try + { + fw = new PrintWriter (""outputDancingPro.txt""); + } + catch(Exception e) + { + System.out.print(""nie udalo sie""); + } + + try + { + fr = new FileReader(""B-large.txt""); + } + catch(FileNotFoundException e) + { + System.out.println(e.getMessage()); + } + br = new BufferedReader(fr); + String s; + try{ + s=br.readLine(); + noOfLines = Integer.parseInt(s); + for (int i=0;i=0;j--) + { + if (p==0) + { + noOfOut=noOfGooglers; + break; + } + else if (Scores[j] == 0) + continue; + if (Scores[j]/3 >= p) + { + noOfOut++; + } + else if (Scores[j] >= (p+(p-2)+(p-2))) + { + if ((p+(p-1)+(p-1) == Scores[j]) || (p+(p)+(p-1) == Scores[j])) + { + noOfOut++; + } + else if (noOfUsedSurp < noOfSurprising) + { + if ((p+(p-2)+(p-2) == Scores[j]) || (p+(p-2)+(p-1) == Scores[j])) + { + noOfOut++; + noOfUsedSurp++; + } + } + } + else + { + break; + } + } + System.out.println(noOfOut); + fw.print(noOfOut); + fw.println(); + + } + fr.close(); + fw.close(); + } + catch(Exception e) + { + + } + + } +} +" +A20018,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; + + +public class R1P2 { + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""large2.out"")); + String inLine; + int t = Integer.parseInt(in.readLine()); + int counter = 0; + while((inLine = in.readLine()) != null){ + counter++; + int n, s, p; + String[] toks = inLine.split("" ""); + n = Integer.parseInt(toks[0]); + s = Integer.parseInt(toks[1]); + p = Integer.parseInt(toks[2]); + //System.out.println(n+ "" "" + s + "" "" + p); + int j1 = p; + int j2 = p - 1; + int j3 = p - 2; + if(j2 < 0) j2 = 0; + if(j3 < 0) j3 = 0; + int nTotal = j1 + j2 + j2; + int sTotal = j1 + j3 + j3; + //System.out.println(nTotal + "" "" + sTotal); + int pos = 0; + for(int i=3; i=nTotal) pos++; + else if(score >= sTotal && s > 0){ + pos++; + s--; + } + } + System.out.println(""Case #"" + counter + "": "" + pos); + bw.write(""Case #"" + counter + "": "" + pos); + bw.newLine(); + + } + in.close(); + bw.close(); + } + +} +" +A20487,"import java.io.*; + +/** + * Created by IntelliJ IDEA. + * User: YC14RP1 + * Date: 4/14/12 + * Time: 12:29 AM + * To change this template use File | Settings | File Templates. + */ +public class Test2 { + + public static void main(String[] args) throws FileNotFoundException { + String path = ""C:\\Users\\YC14rp1\\Downloads\\B-large.in""; + try{ + // Open the file that is the first + // command line parameter + FileInputStream fstream = new FileInputStream(path); + // Get the object of DataInputStream + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine; + //Read File Line By Line + strLine = br.readLine(); + int n = Integer.valueOf(strLine); + for (int i=1;i<=n;i++) { + strLine = br.readLine(); + String[] split = strLine.split("" ""); + int k = Integer.valueOf(split[0]); + int s = Integer.valueOf(split[1]); + int m = Integer.valueOf(split[2]); + int res = 0; + int res2 = 0; + for (int j=3;j<=2+k;j++) { + int score = Integer.valueOf(split[j]); + int c_m = score % 3; + if (score>3*m-3) { + res++; + } else { + if ((score-1>3*m-6) && (res2=2)) { + //System.out.println(score-1); + //System.out.println(3*m-6); + res2++; + } + } + } + // Print the content on the console + res = res + res2; + System.out.println(""Case #"" + i + "": "" + res); + } + //Close the input stream + in.close(); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + +} +" +A22416,"import java.io.*; +import java.util.*; + +public class Googlers{ + + public static int t; + public int T; + public int S; + public int P; + public int [] ti; + public int y = 0; + public int [] v = new int[3]; + public int check = 0; + public int checkS = 0; + + public static void main(String[] args){ + + String [] parse = new String[100000]; + int counter = 0; + int i; + + File inFile = new File(""B-large.in""); + File outFile = new File(""B-large.txt""); + + + + try{ + + BufferedReader in = new BufferedReader(new FileReader(inFile)); + PrintWriter out = new PrintWriter(new FileWriter(outFile)); + + int t = Integer.parseInt(in.readLine()); + + Googlers [] testCase = new Googlers[t]; + + for(i=0;i5){ + testCase[i].v[0] = total / 3; + testCase[i].v[0] = testCase[i].v[0] + 1; + testCase[i].v[1] = testCase[i].v[0]; + testCase[i].v[2] = total - testCase[i].v[1] - testCase[i].v[0]; + }else{ + testCase[i].v[0] = total / 3; + testCase[i].v[1] = testCase[i].v[0]; + testCase[i].v[2] = total - testCase[i].v[1] - testCase[i].v[0]; + } + + if(testCase[i].v[0] >= testCase[i].P || testCase[i].v[1] >= testCase[i].P || testCase[i].v[2] >= testCase[i].P){ + testCase[i].y = testCase[i].y + 1; + }else{ + if(testCase[i].S != 0){ + if(testCase[i].checkS < testCase[i].S){ + testCase[i].v[0] = testCase[i].P; + testCase[i].v[1] = testCase[i].P - 2; + testCase[i].v[2] = total - testCase[i].v[1] - testCase[i].v[0]; + + if(testCase[i].v[0] < total){ + if((testCase[i].v[0] >= 0 || testCase[i].v[1] >= 0 || testCase[i].v[2] >= 0) && (testCase[i].v[0] <= 10 || testCase[i].v[1] <= 10 || testCase[i].v[2] <= 0)){ + if(testCase[i].v[0] > testCase[i].v[2]){ + if(testCase[i].v[0] - testCase[i].v[2]<=2){ + testCase[i].y = testCase[i].y + 1; + testCase[i].checkS = testCase[i].checkS + 1; + } + }else{ + if(testCase[i].v[2] - testCase[i].v[0]<=2){ + testCase[i].y = testCase[i].y + 1; + testCase[i].checkS = testCase[i].checkS + 1; + } + } + } + } + } + } + + } + } + + out.println(""Case #"" + (i+1) + "": "" + testCase[i].y); + } + + in.close(); + out.close(); + }catch(IOException e){ + e.printStackTrace(); + } + + } + + public static void calTriplets(int a){ + + int total = a; + + int fraction = getFraction(total); + + if(fraction>5){ + + int v1 = total / 3; + + v1 = v1 + 1; + + int v2 = v1; + + int v3 = total - v1 - v2; + + }else{ + + int v1 = total / 3; + + int v2 = v1; + + int v3 = total - v1 - v2; + + } + + } + + public static int getFraction(int value){ + + double a = (double) value / 3; + + String b = Double.toString(a); + + int c = b.indexOf("".""); + + Character d = new Character(b.charAt(c+1)); + + String e = d.toString(); + + int f = Integer.parseInt(e); + + //System.out.println(f); + + return f; + } + +}" +A22101,"import java.io.*; +public class codejam2 +{ + public static void main(String args[]) throws FileNotFoundException, IOException + { + String address=""g:\\cj2.txt""; + BufferedReader br = new BufferedReader(new FileReader(address)); + int test_case=Integer.parseInt(br.readLine()); + int iindex,jindex,N,S,p; + int ul,ll; + int select; + String str,temp[]; + for(iindex=0;iindex=ul) + select++; + else if(Integer.parseInt(temp[jindex])>=ll) + { + if(S>0) + { + S--; + select++; + } + } + + } + System.out.print(""Case #""+(iindex+1)+"": ""); + System.out.println(select); + } + + } + +} +" +A20604,"package codejam; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Problem2 { + + private static int [] MAX_NO_SURPRISE; + private static int [] MAX_WITH_SURPRISE; + + public static void main(String[] args) throws IOException { + + MAX_NO_SURPRISE = calcArray(1); + MAX_WITH_SURPRISE = calcArray(2); + + Scanner scanner = new Scanner(new File(args[0])); + int cases = scanner.nextInt(); + PrintWriter printWriter = new PrintWriter(new File(args[1])); + for (int i = 0; i < cases; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int t[] = new int[n]; + for (int k = 0; k < n; k++) { + t[k] = scanner.nextInt(); + } + printWriter.write(""Case #"" + (i + 1) + "": "" + solve(n,s,p,t) + ""\n""); + } + printWriter.close(); + scanner.close(); + } + + private static int[] calcArray(int d) { + int t[] = new int[31]; + for (int i = 0; i <= 30; i++) { + int max = 0; + for (int a1=0;a1<=10;a1++) { + for (int a2=0;a2<=10;a2++) { + for (int a3=0;a3<=10;a3++) { + if (a1+a2+a3 == i && Math.abs(a1-a2) <= d && Math.abs(a2-a3) <= d + && Math.abs(a1-a3) <= d) { + if (a1 > max) { max = a1; } + if (a2 > max) { max = a2; } + if (a3 > max) { max = a3; } + } + } + } + } + t[i] = max; + } + return t; + } + + private static int solve(int n, int s, int p, int[] t) { + int r[][] = new int[n + 1][s + 1]; + for (int i = 0; i <= s; i++) { + r[0][i] = 0; + } + for (int i = 1; i <= n; i++) { + r[i][0] = ((MAX_NO_SURPRISE[t[i - 1]] >= p) ? 1 : 0) + r[i - 1][0]; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= s; j++) { + r[i][j] = Math.max( + r[i - 1][j] + ((MAX_NO_SURPRISE[t[i - 1]] >= p) ? 1 : 0), + r[i - 1][j - 1] + ((MAX_WITH_SURPRISE[t[i - 1]] >= p) ? 1 : 0)); + } + } + return r[n][s]; + } +} +" +A21009,"package codejam; + +public class DirConsts { + public static final String // + INPUT_DIR = ""/home/luke/Downloads"", // + OUTPUT_DIR = ""/home/luke/Downloads/CodeJam""; +} +" +A23058,"package codejam; + +import java.io.*; +import java.util.Scanner; + + +public final class ReadWriteTextFile { + + + + /** Constructor. */ + ReadWriteTextFile(){ + try { + out =new BufferedWriter(new FileWriter(""output.in"")); + + + scanner = new Scanner(new FileInputStream(""input.in"")); + + + } catch (FileNotFoundException ex) { + }catch (IOException ex) { + + } + + + } + + /** Write fixed content to the given file. */ + void writeNextLine(int text) { + try { + out.write(""Case #""+lineNumber +"": ""+text+""\r\n""); + + System.out.println(""Case #""+lineNumber +"": ""+text); + + } catch (IOException ex) { + + } + + lineNumber++; + } + + String readLine() { + + + String output = scanner.nextLine(); + + return output; + + } + int readIntLine(){ + + String output = scanner.nextLine(); + return Integer.decode(output).intValue(); + } + int readInt(){ + + return scanner.nextInt(); + } + + public void close() + { + try { + out.close(); + } catch (IOException ex) { + } + scanner.close(); + } + // PRIVATE + private int lineNumber = 1; + private BufferedWriter out = null; + private Scanner scanner = null; + +}" +A22213,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class DancingWithTheGooglers { + + static final String input_path = ""data/input.b.txt""; + + private static int solve(int N, int S, int p, int[] t) { + int ans = 0; + int candidate = 0; + + for (int i = 0; i < N; i++) { + int point = t[i]; + int base = point / 3; + int residule = point % 3; + if (base >= p) { + ans += 1; + continue; + } + + if (base == p - 1) { + if (residule > 0) + ans += 1; + else if (base > 0) + candidate += 1; + continue; + } + + if (base == p - 2 && residule == 2) + candidate += 1; + } + + if (S >= candidate) + ans += candidate; + else + ans += S; +// System.out.println(String.format(""%d\t%d"", ans, candidate)); + return ans; + } + + /** + * Good luck, Wash :) + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(input_path)); + String intext = in.readLine(); + int T = Integer.parseInt(intext); + for (int caseIter = 0; caseIter < T; caseIter ++) { + intext = in.readLine(); + System.out.print(String.format(""Case #%d: "", caseIter + 1)); + + String[] parts = intext.split("" ""); + int N = Integer.parseInt(parts[0]); + int S = Integer.parseInt(parts[1]); + int p = Integer.parseInt(parts[2]); + int[] t = new int[N]; + for (int i = 0; i < N; i ++) + t[i] = Integer.parseInt(parts[3 + i]); + + System.out.println(solve(N,S,p,t)); + } + in.close(); + } + +} +" +A22305,"import java.io.*; +import java.util.InputMismatchException; + +/** + * Created with IntelliJ IDEA. + * User: IIoTeP9HuY + * Date: 14.04.12 + * Time: 5:25 + * To change this template use File | Settings | File Templates. + */ + +public class Solver { + + static int getTripleType(int a, int b, int c) { + if (a < 0 || b < 0 || c < 0) + return 0; + if (a > 10 || b > 10 || c > 10) + return 0; + if (Math.abs(a - b) > 2 || Math.abs(a - c) > 2 || Math.abs(b - c) > 2) + return 0; + if (Math.abs(a - b) == 2 || Math.abs(a - c) == 2 || Math.abs(b - c) == 2) + return 2; + return 1; + } + + public static void main(String[] args) throws IOException { + InputReader in = new InputReader(new FileInputStream(""input.txt"")); + OutputWriter out = new OutputWriter(new FileOutputStream(""output.txt"")); + int testCases = in.readInt(); + for(int t = 1; t <= testCases; t++) { + int N = in.readInt(); + int S = in.readInt(); + int p = in.readInt(); + int[] score = new int[N]; + int bestResultNumber = 0; + for(int i = 0; i < N; i++) { + score[i] = in.readInt(); + boolean canWithSurprise = false; + boolean canWithoutSurprise = false; + for(int firstScore = 0; firstScore <= score[i]; firstScore++) { + for(int secondScore = 0; secondScore + firstScore <= score[i]; secondScore++) { + int thirdScore = score[i] - firstScore - secondScore; + int tripleType = getTripleType(firstScore, secondScore, thirdScore); + if (tripleType == 0) + continue; + if (firstScore < p && secondScore < p && thirdScore < p) + continue; + if (tripleType == 2 && S <= 0) + continue; + + if (tripleType == 1) + canWithoutSurprise = true; + else + canWithSurprise = true; + } + } + if (canWithoutSurprise) + bestResultNumber++; + else + if (canWithSurprise && S > 0) { + bestResultNumber++; + S--; + } + } + out.print(""Case #"" + t + "": "" + bestResultNumber + ""\n""); + } + out.close(); + } +} + +class InputReader { + + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + public int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public static boolean isSpaceChar(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + +} + +class OutputWriter { + private final PrintWriter writer; + + public OutputWriter(OutputStream outputStream) { + writer = new PrintWriter(outputStream); + } + + public OutputWriter(Writer writer) { + this.writer = new PrintWriter(writer); + } + + public void print(Object...objects) { + for (int i = 0; i < objects.length; i++) { + if (i != 0) + writer.print(' '); + writer.print(objects[i]); + } + } + + public void printLine(Object...objects) { + print(objects); + writer.println(); + } + + public void close() { + writer.close(); + } + +} + +" +A20253,"import java.io.*; + +public class MySolution { + public MySolution() { + + } + + public static void main(String[] a) throws IOException { + sumfile(""B-large.in""); + } + + static void sumfile(String filename) throws IOException { + int tests=0; + int N=0; + int S=0; + int p=0; + int ti=0; + int count=0; + Reader r = new BufferedReader(new FileReader(filename)); + StreamTokenizer stok = new StreamTokenizer(r); + stok.parseNumbers(); + stok.nextToken(); + if (stok.ttype == StreamTokenizer.TT_NUMBER) { + tests=(int)stok.nval; + } + for(int i=0;i=p*3-2){ + count++; + } + else if(ti>=p*3-4&&S>0&&p*3-4>=0){ + count++; + S--; + } + } + System.out.println(""Case #""+(i+1)+"": ""+count); + count=0; + } + } +} +" +A21877,"package com.priyanka; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +public class ProblemB { + + public static void main(String[] args) throws IOException { + BufferedReader inputfile = new BufferedReader(new InputStreamReader(new FileInputStream(""input.txt""))); + FileOutputStream outresult = new FileOutputStream(""output.txt""); + int testcases = Integer.parseInt(inputfile.readLine()); + for(int i=0; i< testcases; i++) { + String[] temp = inputfile.readLine().split("" ""); + int surprises = Integer.parseInt(temp[1]); + int best = Integer.parseInt(temp[2]); + int t = best - 2; + if(t< 0) { t = 0; } + int var1 = best + 2*t; + t = best - 1; + if(t< 0) { t = 0; } + int min_score_normal = best + 2*t; + int count = 0; + for(int j=3; j= min_score_normal) { + count++; + } else if(score >= var1 && surprises > 0) { + surprises--; + count++; + } + } + outresult.write((""Case #"" + (i+1) + "": "" + count + ""\n"").getBytes()); + } + } +} +" +A21025,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class triplets { + + + + + public static void main(String[] args) throws IOException { + BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); //copy test data into standard input + int num=Integer.parseInt(reader.readLine()); + for(int i=1;i<=num;i++){ + StringTokenizer st=new StringTokenizer(reader.readLine()); + System.out.print(""Case #""+i+"": ""); + int n=Integer.parseInt(st.nextToken()); + int s=Integer.parseInt(st.nextToken()); + int p=Integer.parseInt(st.nextToken()); + int over=0;//number automatically over + int surp=0; //number over if surprising + for(int j=0;j=p){ + over++; + }else if(share+1>=p){ + surp++; + } + }else if(score%3==1){ + if(share+1>=p){ + over++; + } + }else if(score%3==2){ + if(share+1>=p){ + over++; + }else if(share+2>=p){ + surp++; + } + } + } + if(surp>s){ + over+=s; + }else{ + over+=surp; + } + System.out.println(over); + } + + } + +} +" +A20504,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.Scanner; + + +public class Dancing { + + public static void main(String[] args) throws IOException + { + String text = """"; + String fileName = ""/users/bestja/desktop/abc.txt""; + File textFile = new File(fileName); + Scanner in = new Scanner(textFile); + + int testCases = in.nextInt(); + in.nextLine(); + + for (int i = 1; i <= testCases; i++) + { + int count = in.nextInt(); + int surprises = in.nextInt(); + int targetScore = in.nextInt(); + + int[] dancers = new int[count]; + + int winners = 0; + + for (int n = 0; n < count; n++) + { + dancers[n] = in.nextInt(); + } + + for (int n = 0; n < count; n++) + { + if (dancers[n] > targetScore*3-3 && dancers[n] >= targetScore) + winners++; + else if (dancers[n] > targetScore*3-5 && surprises > 0 && dancers[n] >= targetScore) + { + winners++; + surprises--; + } + } + + text += ""Case #"" + i + "": "" + winners + ""\n""; + } + + Writer output = null; + File file = new File(""/users/bestja/desktop/def.txt""); + output = new BufferedWriter(new FileWriter(file)); + output.write(text); + output.close(); + } + + + +} +" +A20349,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +class DancingWithTheGooglers { + + /** + * @param args + * @throws IOException + * @throws NumberFormatException + */ + public static void main(String[] args) throws NumberFormatException, + IOException { + // TODO Auto-generated method stub + + FileInputStream fstream = new FileInputStream(""C:\\input.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + int cases = Integer.parseInt(br.readLine()); + String mainOutput = """"; + + for (int c = 0; c < cases; c++) { + + String str = br.readLine(); + //mainOutput = mainOutput + str + ""\n""; + StringTokenizer stringTokenizer = new StringTokenizer(str); + + int n = Integer.parseInt(stringTokenizer.nextToken()); + int s = Integer.parseInt(stringTokenizer.nextToken()); + int p = Integer.parseInt(stringTokenizer.nextToken()); + int count = 0; + int equal = 0; + int surpriseElement = 0; + int nonSurpriseElement = 0; + + int surpriseElements[] = new int[n]; + int nonSurpriseElements[] = new int[n]; + int i; + for (i = 0; i < n; i++) { + + int x = Integer.parseInt(stringTokenizer.nextToken()); + + int j1 = 0, j2 = 0, j3 = 0; + boolean surpriseFlag = false; + + int k = 0; + while (k < x) { + j1 = p + k; + j2 = (x - j1) / 2; + j3 = x - (j1 + j2); + + if (j1 == j3 && j1 == j2 && j2 == j3 && p == j3) { + equal++; + } + if (j1 > 10 || j2 > 10 || j3 > 10 || j1 < 0 || j2 < 0 + || j3 < 0) + break; + + if (checkForSurprise(j1, j2, j3)) { + // System.out.println(s); + surpriseFlag = true; + surpriseElements[i] = 1; + break; + } + k++; + } + + //Non Surprised Element + j1 = x / 3; + j2 = (x - j1) / 2; + j3 = x - j1 - j2; + + if (j1 >= p || j2 >= p || j3 >= p) { + nonSurpriseElements[i] = 1; + } + } + for(int d = 0;d0) + if(surpriseElements[d] == 1 && nonSurpriseElements[d] == 0){ + nonSurpriseElements[d] = 1; + s--; + } + } + for(int d = 0;d=surprize) + surprizeFlag=true; + + System.out.print(data[j]+""=""+Arrays.toString(triplets[j])+"" ""); + if(isHigh(triplets[j],high)) + countHigh++; + } + System.out.println(countHigh+""""); + writer.write(countHigh+""\r\n""); + } + writer.close(); + fr.close(); + + } + + private static boolean isHigh(int[] is,int h) { + if(is[0]>=h || is[1]>=h || is[2]>=h) + return true; + return false; + } + + static boolean isSurprize(int[] a ){ + if(Math.abs(a[0]-a[1])>1) + return true; + + if(Math.abs(a[0]-a[2])>1) + return true; + + if(Math.abs(a[1]-a[2])>1) + return true; + + return false; + + } + + + private static int[] getTriplets(int x,boolean surprizeFlag,int high){ + + if(x==0) + return new int[]{0,0,0}; + //int x=20; + int a,b,c; + a=x/3; + int t=3*a-x; + if(t%2==0){ + //adjusting for highest + if( (a>=high || (a-t/2) >=high) || + ((a-t/2)+1) totalPoints = new LinkedList(); + for(int i =0;i= p+(2*(p-1))) { + result++; + } else if ( totalPoint >= p+(2*(p-2)) && totalPoint < p+(2*(p-1)) && usedS < S) { + usedS++; + result++; + } + } + j++; + System.out.println(""Case #""+ j +"": ""+result); + } + } + + } + +} +" +A21795,"import java.io.*; +import java.util.*; + +class GooglersDance { + public static void main(String[] args) + throws Exception { + new GooglersDance().start(); + } + + void start() + throws Exception { + InputStreamReader is = + new InputStreamReader( + new FileInputStream(""Input"")); + BufferedReader br = new BufferedReader(is); + OutputStreamWriter os = + new OutputStreamWriter( + new FileOutputStream(""Output"")); + BufferedWriter bw = new BufferedWriter(os); + String line; + int[] inputs; + int test = 1; + line = br.readLine(); + while ((line = br.readLine()) != null) { + String[] inp = line.split("" ""); + inputs = new int[inp.length]; + int i = 0; + for (String s : inp) { + inputs[i++] = Integer.parseInt(s); + } + int surp = inputs[1]; + int t = inputs[2]; + Arrays.sort(inputs, 3, inputs.length); + System.out.print(""Case #"" + test + "": ""); + String toWrite = ""Case #"" + test++ + "": ""; + bw.write(toWrite, 0, toWrite.length()); + for (i = 3; i < inputs.length; i++) { + //System.out.print(inputs[i] + "" ""); + } + int result = 0; + for (i = inputs.length - 1; i > 2; i--) { + int tot = inputs[i]; + if (tot >= (t * 3)) { + result++; + continue; + } + if (tot <= t) { + break; + } + tot -= t; + int val = t - (tot / 2); + //System.out.print("" val = "" + val + "" ""); + if (val == 1) { + result++; + continue; + } + else if (val == 2) { + if (--surp >= 0) { + result ++; + continue; + } + else { + break; + } + } + else { + break; + } + } + System.out.println(result); + String res = Integer.toString(result); + bw.write(res, 0, res.length()); + bw.newLine(); + } + br.close(); + bw.close(); + } +}" +A22922,"import java.io.BufferedWriter; +import java.io.FileWriter; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Scanner; + +public class GCJ3 { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] hold = new int[n]; + for (int i = 0; i < n; i++) { + hold[i] = 0; + int a = sc.nextInt(); + int b = sc.nextInt(); + int k = (int) Math.log10(a); + HashSet checked = new HashSet(); + for (int j = a; j <= b; j++) { + if(checked.contains(j)) + continue; + HashSet set = new HashSet(); + set.add(j); + int curr = j; + for (int l = 0; l <= k; l++) { + int firstDig = curr / (int) Math.pow(10, k); + int mod = curr % (int) Math.pow(10, k); + curr = mod * 10 + firstDig; + if ((int) Math.log10(curr) == k) { + if (a<=curr && curr <=b) { + set.add(curr); + } + } + } + if (set.size() > 1){ + Iterator p = set.iterator(); + for(int m = 0;m= no3 - 2) + { + count++; + } + else if(no==no3-3 || no==no3-4) + { + if(sur>0) + { + count++; + } + sur--; + } + + } + String s1=""Case #""+ start++ +"": ""+count+""\n""; + System.out.println(s1); + byte b1[]=s1.getBytes(); + fos.write(b1); + + + } + + } + + } catch (Exception ex) { + System.err.println(""FileStreamsTest: "" + ex); + } + } +} +" +A22168,"package com.mademoisellegeek.googlecodejam; + +import com.mademoisellegeek.googlecodejam.y2012.qualround.DancingWithTheGooglers; +import com.mademoisellegeek.googlecodejam.y2012.qualround.SpeakingInTongues; + +public class GoogleCodeJam { + + public static void main(String[] args) { + new Thread(new DancingWithTheGooglers()).start(); + } +} +" +A21849,"import java.util.*; +import java.io.*; + +public class Q2 { + + static int m1(String st) { + Scanner sc=new Scanner(st); + int nG=sc.nextInt(); + int nS=sc.nextInt(); + int p=sc.nextInt(); + int count=0; + int[] maxG=new int[nG]; + for (int i=0; i=p) + if (Math.abs(x-y)<2 && Math.abs(x-z)<2 && Math.abs(y-z)<2) + m[i]=Math.max(m[i], Math.max(x, Math.max(y, z))); + else + mS[i]=Math.max(mS[i], Math.max(x, Math.max(y, z))); + + for (int a:m) + if (a>-1) + count++; + for (int i=0; i-1) + if (nS>0 && m[i]==-1) + { + count++; + nS--; + } + return count; + } + public static void main(String[] args) throws IOException { + File inFile=new File(""B-large.in""); + File outFile=new File(""B-large.out""); + BufferedReader br=new BufferedReader(new FileReader(inFile)); + PrintWriter out=new PrintWriter(new FileWriter(outFile)); + StringBuilder sb=new StringBuilder(); + int ntc=Integer.parseInt(br.readLine()); + for (int tc=1; tc<=ntc; tc++) + { + String s=br.readLine(); + sb.append(""Case #""+tc+"": ""+m1(s)+""\n""); + } + out.write(sb.toString()); + br.close(); + out.close(); + } +} +" +A22012,"import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + + +public class B { + static int[][] memo; + static int[] nums; + static int p; + public static void main(String[] args)throws IOException + { + Scanner br=new Scanner(new File(""B-large.in"")); + PrintWriter out=new PrintWriter(new File(""b.out"")); + int cases=br.nextInt(); + for(int c=1;c<=cases;c++) + { + int n=br.nextInt(),s=br.nextInt(); + p=br.nextInt(); + nums=new int[n]; + for(int i=0;i=nums.length) + return 0; + if(memo[index][s]!=-1) + return memo[index][s]; + int best=0; + for(int i=0;i<=10;i++) + { + int max=i; + for(int j=0;j<=10;j++) + { + if(Math.abs(i-j)>2) + continue; + max=Math.max(i,j); + thisone: + for(int k=0;k<=10;k++) + { + int ret=0; + if(Math.abs(i-k)>2||Math.abs(j-k)>2) + continue; + max=Math.max(max,k); + int count=0; + if(Math.abs(i-k)==2) + count++; + if(Math.abs(i-j)==2) + count++; + if(Math.abs(j-k)==2) + count++; + if(i+j+k==nums[index]) + { + boolean surp=(count>=1); + if(surp&&s>0) + { + if(max>=p) + ret++; + ret+=go(index+1,s-1); + } + else if(!surp) + { + if(max>=p) + ret++; + ret+=go(index+1,s); + } + best=Math.max(best,ret); + } + else if(i+j+k>nums[index]) + break thisone; + } + } + } + return memo[index][s]=best; + } +} +" +A20500,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Scanner; +import java.util.StringTokenizer; + +public class habala { + public static void main(String[] args) throws Exception { + + + String s2; + + + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(""input.in""))); + PrintWriter out = new PrintWriter(""output.out""); + + int testCases = Integer.parseInt(in.readLine()); + + for (int i = 1; i <= testCases; i++) { + String s = in.readLine(); + + int Googlers, surprizes ,p; + int winers = 0; + StringTokenizer st = new StringTokenizer (s); + s2 = """"; + + s2 = st.nextToken(); + Googlers = Integer.parseInt(s2); + surprizes = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + + int minn = (3*p-2) < p ? p : (3*p-2) ; + int mins = (3*p-4) < p? p : (3*p-4) ; + + for(int j = 1 ; j <= Googlers ; j++) + { + + int scoure = Integer.parseInt(st.nextToken()); + if (scoure >= minn ) + winers++; + else if(scoure >= mins && surprizes > 0){ + winers++; + surprizes--; + } + + + } + + out.println(""Case #""+i+"": ""+winers); + + } + out.close(); + in.close(); + } +}" +A21904,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.*; + +public class Main +{ + public static void main(String[] args) + throws Exception + { + BufferedReader in = new BufferedReader(new FileReader(args[0])); + FileWriter out = new FileWriter(args[1]); + int T = Integer.parseInt(in.readLine()); + + for (int t = 1; t <= T; t++) + { + String data[] = in.readLine().split(""\\ ""); + int N = Integer.parseInt(data[0]); + int S = Integer.parseInt(data[1]); + int p = Integer.parseInt(data[2]); + int[] totalPoints = new int[N]; + for (int i = 0; i < N; i++) + totalPoints[i] = Integer.parseInt(data[i + 3]); + + int unconditionalSucc = 0; + int failed = 0; + + int upperLimit; + int lowerLimit; + + if (p >= 2) + { + upperLimit = 3 * p - 3; + lowerLimit = 3 * p - 4; + } + else if (p == 1) + { + upperLimit = 0; + lowerLimit = 1; + } + else + { + upperLimit = -1; + lowerLimit = -1; + } + + for (int i = 0; i < totalPoints.length; i++) + { + if (totalPoints[i] > upperLimit) + unconditionalSucc++; + else if (totalPoints[i] < lowerLimit) + failed++; + } + + int uncertain = N - failed - unconditionalSucc; + + out.write(""Case #"" + t + "": "" + (Math.min(uncertain, S) + unconditionalSucc) + ""\n""); + } + + in.close(); + out.close(); + } +} +" +A20458,"import java.io.*; +import java.util.*; + +public class Q2 +{ + private static int max (int a, int b, int c) + { + return Math.max (a, Math.max (b, c)); + } + + public static void main (String[] args) throws IOException + { + BufferedReader reader = new BufferedReader (new FileReader (""input-q2.txt"")); + PrintWriter writer = new PrintWriter (""output-q2.txt""); + String line = reader.readLine(); + int nb = Integer.parseInt (line); + for (int i = 0; i < nb; i++) + { + line = reader.readLine(); + String[] tokens = line.split ("" ""); + int[] googlers = new int[Integer.parseInt (tokens[0])]; + int s = Integer.parseInt (tokens[1]); + int p = Integer.parseInt (tokens[2]); + for (int j = 0; j < googlers.length; j++) + { + googlers[j] = Integer.parseInt (tokens[3 + j]); + } + + System.out.printf (""\ns : %d, p : %d, googlers : %s\n"", s, p, Arrays.toString (googlers)); + + // For each googler + int counter = 0; + for (int j = 0; j < googlers.length; j++) + { + System.out.print (""Googler "" + googlers[j] + "" :""); + int a = 0, b = 0, c = 0; + + if ((googlers[j] - 2) % 3 == 0) + { + a = b = (googlers[j] - 2) / 3; + c = (googlers[j] - 2) / 3 + 2; + + if (max (a, b + 1, c - 1) >= p || c <= 1 || max (a, b, c) < p) + { + System.out.printf ("" (%d %d %d)\n"", a, b + 1, c - 1); + if (max (a, b + 1, c - 1) >= p) + { + counter++; + } + continue; + } + else if (s > 0) + { + s--; + if (max (a, b, c) >= p) + { + counter++; + } + System.out.printf ("" (%d %d %d) *\n"", a, b, c); + continue; + } + else + { + System.out.println (""ERROR""); + } + } + + if ((googlers[j] - 1) % 3 == 0) + { + a = b = (googlers[j] - 1) / 3; + c = (googlers[j] - 1) / 3 + 1; + + if (max (a, b, c) >= p) + { + counter++; + } + System.out.printf ("" (%d %d %d)\n"", a, b, c); + continue; + } + + if (googlers[j] % 3 == 0) + { + a = b = c = googlers[j] / 3; + + if (max (a, b, c) >= p || b <= 1 || max (a, b - 1, c + 1) < p || s == 0) + { + System.out.printf ("" (%d %d %d)\n"", a, b, c); + if (max (a, b, c) >= p) + { + counter++; + } + continue; + } + else if (s > 0) + { + s--; + if (max (a, b - 1, c + 1) >= p) + { + counter++; + } + System.out.printf ("" (%d %d %d) *\n"", a, b - 1, c + 1); + continue; + } + else + { + System.out.println (""ERROR""); + } + } + } + System.out.println (""Counter : "" + counter); + writer.println (""Case #"" + (i + 1) + "": "" + counter); + } + writer.close(); + reader.close(); + } +}" +A22634,"package tw.csc.gcj; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +public class Main { + + /** + * @param args + */ + + public static String str1 = ""abcdefghijklmnopqrstuvwxyz""; + public static String str2 = ""ynficwlbkuomxsevzpdrjgthaq""; + public static void main(String[] args) { + + try { + goB(); + } catch (Exception e) { + + } + } + + public static void goB() throws NumberFormatException, IOException{ + File fin = new File(""B-large.in""); + File fout = new File(""B-large.out""); + BufferedReader br = new BufferedReader(new FileReader(fin)); + FileOutputStream fos = new FileOutputStream(fout); + int c = Integer.parseInt(br.readLine()); + String op = """"; + for (int i = 0 ; i < c ;i ++ ){ + op+=""Case #""+ (i+1)+"": ""; + String[] strin = br.readLine().split(""[ ]""); + int n = Integer.parseInt(strin[0]); + ArrayList arr = new ArrayList(); + for (int k = 3 ; k< n+3 ; k++){ + arr.add(Integer.parseInt(strin[k])); + } + op += testB(n, Integer.parseInt(strin[1]), Integer.parseInt(strin[2]), arr) + ""\n""; + + } + fos.write(op.getBytes()); + fos.close(); + } + + public static String testB(int n , int s, int p, ArrayList arrt ){ + if (p == 0) + return """" + n; + if (p == 1){ + int c = 0; + for (Integer t : arrt){ + if (t > 0) + c++; + } + return """"+c; + } + int c = 0; + int cs = 0; + for (Integer t : arrt){ + if (t >= p*3-2) + c++; + else if (t >= p*3-4) + cs++; + } + if (cs >= s) + c += s; + else + c += cs; + return """" +c; + } + + public static void goC() throws NumberFormatException, IOException { + File fin = new File(""C-large.in""); + File fout = new File(""C-large.out""); + BufferedReader br = new BufferedReader(new FileReader(fin)); + FileOutputStream fos = new FileOutputStream(fout); + int c = Integer.parseInt(br.readLine()); + String op = """"; + for (int i = 0 ; i < c ;i ++ ){ + op+=""Case #""+ (i+1)+"": ""; + String[] strin = br.readLine().split(""[ ]""); + op += test(Integer.parseInt(strin[0]), Integer.parseInt(strin[1])) + ""\n""; + + } + fos.write(op.getBytes()); + fos.close(); + } + + public static String test(int a , int b){ + String ret = """"; + HashSet set = new HashSet(); + for (int n = a ; n <=b ; n++){ + String strn = String.valueOf(n); + for (int i = 1 ; i < strn.length() ; i ++){ + String strtest = strn.substring(strn.length() - i, strn.length() ) + strn.substring(0 , strn.length() -i); + int m = Integer.parseInt(strtest); + if (m > n && m <= b){ + set.add(strn+String.valueOf(m)); + } + } + + } + + return ret + set.size(); + } + + public static void goA() throws NumberFormatException, IOException { + HashMap map = new HashMap(); + + for (int i = 0 ; i < str1.length() ; i ++){ + map.put(str2.charAt(i), str1.charAt(i)); + } + File fin = new File(""A-small-attempt1.in""); + File fout = new File(""A-small-attempt1.out""); + BufferedReader br = new BufferedReader(new FileReader(fin)); + FileOutputStream fos = new FileOutputStream(fout); + int c = Integer.parseInt(br.readLine()); + String op = """"; + for (int i = 0 ; i < c ;i ++ ){ + op+=""Case #""+ (i+1)+"": ""; + String strin = br.readLine(); + String strout = """"; + for (int k = 0 ;k < strin.length() ;k ++){ + if (strin.charAt(k) == ' '){ + strout+="" ""; + } + else{ + strout+= map.get(strin.charAt(k)); + } + } + op+=strout+""\n""; + } + + + fos.write(op.getBytes()); + fos.close(); + }; +} +" +A21886,"import static java.lang.Integer.parseInt; +import static java.lang.Long.parseLong; +import static java.lang.Math.max; +import static java.lang.Math.min; +import static java.util.Arrays.fill; + +import java.io.*; +import java.math.BigInteger; +import java.util.StringTokenizer; + +public class B { + + static BufferedReader in; + static PrintWriter out; + static StringTokenizer tok; + + static void solveTest() throws Exception { + int N = nextInt(); + int S = nextInt(); + int p = nextInt(); + + int res = 0; + for(int i = 0;i< N;i++){ + int t = nextInt(); + int sho = t / 3; + int rem = t % 3; + + if(t == 30 || t == 0){ + if(sho >= p) res++; + continue; + } + else if( t == 29){ + if(sho + 1 >= p) res++; + continue; + } + + if( rem == 1){ + if(sho + 1 >= p) res++; + } + else + { + int border; + if(rem == 0) border = sho; + else border = sho + 1; + + if(border >= p) res++; + else if( border + 1 == p){ + if(S > 0){ + S--; + res++; + } + } + } + } + + out.printf(""%d\n"", res); + } + + static void solve() throws Exception { + int tests = nextInt(); + for (int test = 1; test <= tests; test++) { + out.print(""Case #"" + test + "": ""); + solveTest(); + } + } + + public static void main(String[] args) throws Exception { + in = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); + solve(); + in.close(); + out.close(); + } + + static String next() throws IOException { + while (tok == null || !tok.hasMoreTokens()) { + tok = new StringTokenizer(in.readLine(),"" \r\n\t\f""); + } + return tok.nextToken(); + } + + static char nextChar() throws IOException { + String token = next(); + if (token.length() != 1) { + throw new IllegalArgumentException(""String \"""" + token + ""\"" is not a single character""); + } + return token.charAt(0); + } + + static int nextInt() throws IOException { + return parseInt(next()); + } + + static long nextLong() throws IOException { + return parseLong(next()); + } + + static BigInteger nextBigInt() throws IOException { + return new BigInteger(next()); + } +}" +A20341,"import java.io.*; +import java.util.*; + +public class Dancing { + + public static void main(String [] args) throws Exception{ + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(in.readLine()); + + for(int i = 0; i < T; i++){ + StringTokenizer st = new StringTokenizer(in.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int[] scores = new int[N]; + for(int j = 0; j < N; j++){ + scores[j] = Integer.parseInt(st.nextToken()); + } + + int ans = 0; + for(int j = 0; j < N; j++){ + if(p==0){ + ans++; + continue; + } + + if(scores[j]==0) continue; + + if(scores[j]/3>=p){ + ans++; + } else if(scores[j]/3==p-1&&scores[j]%3>0){ + ans++; + } else if(scores[j]/3==p-1&&scores[j]%3==0 && S>0){ + ans++; + S--; + } else if(scores[j]/3==p-2&&scores[j]%3==2 && S>0){ + ans++; + S--; + } + } + System.out.println(""Case #"" + (i+1) + "": "" + ans); + } + } + +}" +A22338,"import java.io.*; +import java.util.*; + +class Dancing +{ + public static void main(String[] args) throws IOException + { + Scanner s = new Scanner(new File(args[0])); + + int numTests = s.nextInt(); + + for (int i = 1; i <= numTests; i++) + { + // Get rid of prepending newline. + s.nextLine(); + + int count = 0; + + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + + for (int j = 0; j < N; j++) + { + int t = s.nextInt(); + int a = t / 3 + ((t % 3 == 0) ? 0 : 1); + + if (a >= p) + { + count++; + } + else if (a == p-1 && S > 0 && t > 1 && t % 3 != 1) + { + count++; + S--; + } + } + + System.out.println(""Case #"" + i + "": "" + count); + } + } +} +" +A20710,"import java.util.*; +import java.io.*; + +public class ProblemB { + final long MOD = 1000003; + final int MAX_LEN = 500000; + + long pow(long x, long y) { + if (y == 0) return 1; + long res = pow(x, y/2); + res = (res * res) % MOD; + if (y % 2 == 1) res = (res * x) % MOD; + return res; + } + + long inv(long x) { + return pow(x, MOD-2); + } + + long[] fact, invfact; + + void precalc() { + fact = new long[MAX_LEN + 1]; + fact[0] = 1; + for (int i=1; i<=MAX_LEN; i++) + fact[i] = (i * fact[i-1]) % MOD; + invfact = new long[MAX_LEN + 1]; + invfact[0] = 1; + for (int i=1; i<=MAX_LEN; i++) + invfact[i] = (inv(i) * invfact[i-1]) % MOD; + } + + long comb(int N, int M) { + long res = fact[N]; + res = (res * invfact[M]) % MOD; + res = (res * invfact[N-M]) % MOD; + return res; + } + + class Testcase { + long ans; + + public Testcase() { + } + + public Testcase(int seed) { + Random rnd = new Random(seed); + } + + String s; + + int N; + int S; +// int T; + int P; +// ArrayList ti = new ArrayList(); + int [] ti = new int[0]; + public void loadInput(Scanner sc) { +// s = sc.next(); + N = sc.nextInt(); + S = sc.nextInt(); + P = sc.nextInt(); + ti = new int[N]; + for(int i=0;i=c1){ + n1++; + } else if(tai=c2) { + n2++; + } + } + if(P==1) { + ans =n1; + return; + } + n2 = Math.min(S, n2); + ans = n1+ n2; +// ans = F[26][runs][0]; + } + + public void printSelf(PrintWriter pw) { + pw.println(ans); + } + + public boolean sameAnswers(Testcase other) { + return false; + } + } + + final String AFTER_CASE = "" ""; + + public void go() throws Exception { + precalc(); + + Scanner sc = new Scanner(new FileReader(""src\\input.txt"")); + PrintWriter pw = new PrintWriter(new FileWriter(""src\\output.txt"")); + + int caseCnt = sc.nextInt(); + + for (int caseNum = 0; caseNum < caseCnt; caseNum++) { + System.out.println(""solving case "" + caseNum); + + Testcase tc = new Testcase(); + + tc.loadInput(sc); + tc.solveFast(); + + pw.print(""Case #"" + (caseNum + 1) + "":""); + pw.print(AFTER_CASE); + + tc.printSelf(pw); + } + + pw.flush(); + pw.close(); + sc.close(); + } + + public void stresstest() { + int it = 0; + Random rnd = new Random(); + while (true) { + it++; + if (it % 1000 == 0) + System.out.println(it + "" iterations""); + + int seed = rnd.nextInt(); + + Testcase tc1 = new Testcase(seed); + tc1.solveFast(); + + Testcase tc2 = new Testcase(seed); + tc2.solveSlow(); + + if (!tc1.sameAnswers(tc2)) { + System.out.println(""ERROR: it failed""); + System.exit(0); + } + } + } + + public static void main(String[] args) throws Exception { + new ProblemB().go(); + } +} +" +A21361,"import java.io.*; +import java.math.*; +import java.util.*; + +public class CodeJam { + + void runCase(int caseNum) throws IOException { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + int ret = 0; + Map nonSurprise = new HashMap(); + Map surprise = new HashMap(); + + for (int i = 0; i <= 10; ++i) { + for (int j = i; j <= Math.min(10, i + 2); ++j) { + for (int k = Math.max(j, p); k <= Math.min(10, i + 2); ++k) { + int sum = i + j + k; + if (k - i == 2) + surprise.put(sum, true); + else + nonSurprise.put(sum, true); + } + } + } + + for (int i = 0; i < n; ++i) { + int t = nextInt(); + if (nonSurprise.containsKey(t)) { + ++ret; + } else if (s > 0 && surprise.containsKey(t)){ + ++ret; + --s; + } + } + + System.out.print(new StringBuilder().append(""Case #"").append(caseNum).append("": "").append(ret).toString()); + + System.out.println(); + } + + + public static void main(String[] args) throws IOException { + System.setIn(new FileInputStream(new File( + ""input.txt""))); + PrintStream ps = new PrintStream(new File( + ""output.txt"")); + System.setOut(ps); + new CodeJam().runit(); + ps.flush(); + ps.close(); + return; + } + + BufferedReader in; + private StringTokenizer st; + PrintWriter out; + + String next() throws IOException { + while (!st.hasMoreTokens()) { + String line = in.readLine(); + if (line == null) { + return null; + } + st = new StringTokenizer(line); + } + return st.nextToken(); + } + + int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + long nextLong() throws IOException { + return Long.parseLong(next()); + } + + + + void runit() throws IOException { + in = new BufferedReader(new InputStreamReader(System.in)); + out = new PrintWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""""); + + int N = nextInt(); + for (int i = 0; i < N; i++) { + runCase(i + 1); + } + + out.flush(); + } + +} +" +A22683,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * Google code jam. + * Qualification Round 2012. + * Problem B. Dancing With the Googlers + * + * Usage: <app> <input >output + * + * @author sombrabr@gmail.com + * + */ +public class QualB { + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + + int cases = new Integer(in.readLine()); + + run(in, cases); + } + + static void run(BufferedReader in, int cases) throws IOException { + for(int i=0; i=minimumScore) { + googlers++; + } else if(t>=tripletScore && surprisings 0) + return map[i][S] - 1; + if (i == t.length) { + map[i][S] = 1; + return 0; + } + if (S == 0) { + map[i][S] = couldScoreP(t[i], false, p) + solveRec(t, i+1, 0, p) + 1; + return map[i][S] - 1; + } + else { + map[i][S] = Math.max(couldScoreP(t[i], false, p) + solveRec(t, i+1, S, p), couldScoreP(t[i], true, p) + solveRec(t, i+1, S-1, p)) + 1; + return map[i][S] - 1; + } + } + + private int couldScoreP(int i, boolean suprised, int p) { + if (i < p) + return 0; + int a = (i-p)/2; + if (a < p-2 || a < p-1 && !suprised) + return 0; + return 1; + } + +} +" +A20599,"import java.util.*; +import java.io.*; + +class B1small +{ + public static void main(String[] args) throws Exception + { + FileInputStream fis = new FileInputStream(""B-large.in""); + Scanner scan = new Scanner(fis); + FileWriter fw = new FileWriter(""output.txt""); + int T = scan.nextInt(); + for(int i=1;i<=T;i++) + { + int count=0; + int sur =0; + int N = scan.nextInt();//number of dancers + int S = scan.nextInt();//number of surprises + int P = scan.nextInt();//best result + for(int j=0;j=P) + { + count++; + continue; + } + } + else + { + if(t/3>=P) + { + count++; + continue; + } + } + if(t%3==2 && sur=P) + { + sur++; + count++; + continue; + } + } + else if(t%3 == 0 && sur=P) + { + sur++; + count++; + continue; + } + } + } + fw.write(""Case #"" +i +"": ""+ count +""\n""); + } + fw.close(); + } +}" +A22888,"package b; + +import java.util.Arrays; +import java.util.Scanner; + +public class B { + + public B() { + Scanner s = new Scanner (System.in); + + int t = s.nextInt(); + + + for(int i =0; i < t; i++) + { + int n = s.nextInt(); + int ss = s.nextInt(); + int p = s.nextInt(); + + int[] vals = new int[n]; + + for(int j = 0; j < n; j ++) + vals[j]=s.nextInt(); + + Arrays.sort(vals); + + int num=0, numLeft = ss; + for(int j=vals.length-1; j >=0;j--) + { + //System.out.println(vals[j]); + if(numLeft==0 || vals[j]>=29 || vals[j]<2 || (vals[j]+2)/3>=p) + { + //System.out.println(""here ""+(vals[j]+2)/3); + if((vals[j]+2)/3>=p) + { + num++; + } + } + else + { + if((vals[j]+4)/3>=p) + { + numLeft--; + num++; + } + } + } + + System.out.println(""Case #""+(i+1)+"": ""+num); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + new B(); + + } + +} +" +A21051," +import java.io.*; +import java.util.StringTokenizer; + +public class Solution { + public static void main(String args[]){ + try{ + FileInputStream fin=new FileInputStream(""C:\\Program lang\\Google Code Jam\\input00.txt""); + DataInputStream datain=new DataInputStream(fin); + BufferedReader br=new BufferedReader(new InputStreamReader(datain)); + int T=Integer.parseInt(br.readLine()); + for(int j=0;j=p){ + out++; + } + else if((num+3)/3==p && S>0 && num>=3) { + S--; + out++; + } + + } + else if(num%3==1){ + if((num+2)/3>=p) out++; + } + else{ + if((num+1)/3>=p && num>=2) out++; + else if((num+4)/3>=p && S>0 && num>=2) { + out++; + S--; + } + } + } + System.out.println(""Case #""+(j+1)+"": ""+out); + + } + + }catch(Exception e){ + System.out.println(e); + } + } + +}" +A21117,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; + + +public class B { + public static void main(String[] args) throws NumberFormatException, IOException { + // Use scanner! Good for reading in bigints too. + // Arrays.fill for initialising arrays + // Look up cumulative frequency tables (only for dynamic querying with new numbers coming in) + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""in.in""))); + PrintStream writer = new PrintStream(new FileOutputStream(""out.out"")); + int cases = Integer.parseInt(reader.readLine()); + for (int i = 1; i <= cases; i++) { + String[] tokens = reader.readLine().split("" ""); + int googlers = Integer.parseInt(tokens[0]); + int surprising = Integer.parseInt(tokens[1]); + int target = Integer.parseInt(tokens[2]); + int maxReached = 0; + for (int j = 3; j < googlers + 3; j++) { + int total = Integer.parseInt(tokens[j]); + if ((total / 3 + Math.min(total % 3, 1) >= target) || ((total / 3 + Math.max(total % 3, 1) >= target) && + (surprising-- > 0) && ((total >= 1) || (total % 3 != 0)))) { + maxReached++; + } + } + writer.printf(""Case #%d: %d\n"", i, maxReached); + } + } +} +" +A23004,"import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class addy { + public static int counter = 0; + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + int lines = Integer.parseInt(sc.nextLine()); + + for (int count = 0; count < lines; count++) { + String inputLine = sc.nextLine(); + String input[] = inputLine.split("" ""); + int noOfDancers = Integer.parseInt(input[0]); + int noOfSurprise = Integer.parseInt(input[1]); + int minScore = Integer.parseInt(input[2]); + List dancerScore = new ArrayList(); + + for (int i = 0; i < noOfDancers; i++) { + // System.out.println(""dancer ""+i+""score:""+Integer.parseInt(input[3+i])); + dancerScore.add(Integer.parseInt(input[3 + i])); + } + int counting = 0; + for (int dancer : dancerScore) { + counter = 0; + int temp = dancer % 3; + int no = dancer / 3; + if(dancer 0) { + counting++; + + } else if (minScore - no == 0) { + counting++; + + } else if (minScore - no == 2 && temp == 2) { + if (noOfSurprise > 0) { + counting++; + noOfSurprise--; + + } + } else if (minScore - no < 0) { + counting++; + + } else if (minScore - no == 1 && temp == 0) { + if (noOfSurprise > 0) { + counting++; + + noOfSurprise--; + } + } + } + counter = counting; + System.out.println(""Case #"" + (count + 1) + "": "" + counter); + } + + } + +} +" +A20748," +public class Triplet { + private int total; + public Triplet(int totalScore){ + total = totalScore; + } + + int getTotal() { + return total; + } + + boolean isSuprisable() { + if (total < 2 || total > 28) { + return false; + } else { + return true; + } + } + int getBest(boolean suprising) { + int extra = total%3; + int mean = total/3; + int result = -1; + + switch (extra) { + case 0: + if (suprising) { + if (mean >= 1 && mean <= 9) { + result = (mean+1); // m-1, m, m+1 + } else { + result = -1; + } + } else { + result = mean; // m, m, m + } + break; + case 1: + if (suprising) { + if (mean >= 1 && mean <= 9) { + result = mean+1; // m-1, m+1, m+1 + } else { + result = -1; + } + } else { + result = mean+1; // m, m, m+1 + } + break; + case 2: + if (suprising) { + if (mean >= 0 && mean <= 8) { + result = mean + 2; // m, m, m+2 + } else { + result = -1; + } + } else { + result = mean + 1; // m, m+1, m+1 + } + default: + break; + } + + return result; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + total; + return result; + } +} +" +A22062,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + + + File file = new File(""data/B-large.in""); + + + try { + + Scanner scanner = new Scanner(file); + + int numOfLines = scanner.nextInt(); + + scanner.nextLine(); + + + + + for (int i = 0; i < numOfLines; i++) { + + int NumOfGooglers = 0; + int NumOfSurprisingTriplet = 0; + int BestResultTreshold = 0; + + int NumOfGooglersMeetingTreshold = 0; + + // Read number of Googlers + NumOfGooglers = scanner.nextInt(); + //System.out.println(NumOfGooglers); + + NumOfSurprisingTriplet = scanner.nextInt(); + + BestResultTreshold = scanner.nextInt(); + + + int result[]; + for (int j = 0; j < NumOfGooglers; j++) { + + int currResult = scanner.nextInt(); + + if (currResult < (BestResultTreshold/3)) { + // No way, don't bother + continue; + } + + result = getPossibleCombinations(currResult); +// System.out.println(""Max Not Surprising: "" + result[0]); +// System.out.println(""Max Surprising: "" + result[1]); + + + if (result[0] >= BestResultTreshold) { + NumOfGooglersMeetingTreshold++; + } else if (result[1] >= BestResultTreshold && NumOfSurprisingTriplet > 0) { + NumOfGooglersMeetingTreshold++; + NumOfSurprisingTriplet--; + } + + + } + + + System.out.println(""Case #"" + (i+1) + "": "" + NumOfGooglersMeetingTreshold); + + } + + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + + +/* + int result[] = getPossibleCombinations(5); + System.out.println(""Max Not Surprising: "" + result[0]); + System.out.println(""Max Surprising: "" + result[1]);*/ + + + } + + public static int[] getPossibleCombinations(int totalScore) { + + + int indivMax = (int) Math.ceil( Math.min( ((double)totalScore/3.0) , 9)) ; + indivMax = indivMax + 1; + + int i = indivMax; + int indivMin = i - 3; + + + int maxValueNotSurprising = 0; + int maxValueSurprising = 0; + + + // First start with indivMax + for (; i >= indivMin; i--) { + + + int currMin = Math.max(i-2, 0); + for (int j = i; j >= currMin; j--) { + + + for (int k = j; k >= currMin; k--) { + + + if (i+j+k == totalScore) { +// System.out.print(""Found: "" + i + "" "" + j + "" "" + k); + + if (i-k == 2) { + if (i > maxValueSurprising) maxValueSurprising = i; +// System.out.print("" (*)""); + } else { + if (i > maxValueNotSurprising) maxValueNotSurprising = i; + } + +// System.out.println(); + } + + } + + } + } + + int[] output = {maxValueNotSurprising, maxValueSurprising}; + return output; + + } + +} +" +A20513,"package com.googlerese.file; + +public class GooglersBean { + + private int numGooglers; + + private int surprising; + + private int result; + + private int[] scores = new int[100]; + + public int getNumGooglers() { + return numGooglers; + } + + public int getSurprising() { + return surprising; + } + + public int getResult() { + return result; + } + + public int[] getScores() { + return scores; + } + + public void setNumGooglers( int numGooglers ) { + this.numGooglers = numGooglers; + } + + public void setSurprising( int surprising ) { + this.surprising = surprising; + } + + public void setResult( int result ) { + this.result = result; + } + + public void setScores( int[] scores ) { + this.scores = scores; + } + + public void addScore( int index, int score ) { + scores[index] = score; + } + +} +" +A21721,"package qualification_round; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class A_sl_Dansing { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + try { + Scanner inp = new Scanner(new FileInputStream(""A_s_input.txt"")); + int i=0,j=0,k=0,tc=0; + int T = inp.nextInt(); + inp.nextLine(); + for(tc=0;tc= P){ + result++; + } + else if(arr1[i]+1 == P && arr1[i] != 0 && S>0){ + S--; + result++; + } + } + else if(arr2[i] == 1 && arr1[i]+1 >= P){ + result++; + } + else if(arr2[i] == 2){ + if(arr1[i]+1 >= P){ + result++; + } + else if(arr1[i]+2 == P && S>0){ + result++; + S--; + } + } + } + + k=tc+1; + System.out.println(""Case #"" + k +"": ""+result); + + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + +} +" +A20365,"import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +public class Solution2 { + + private static int maxScoreWithSurprise(int media) { + if (media == 0) + return 0; + + Double realAverrage = new Double((double) media / 3); + Double m = Math.ceil(realAverrage); + int mediaDeNota = m.intValue(); + + int notaMaxima = 0; + if (realAverrage == realAverrage.longValue()) { + notaMaxima = media - (mediaDeNota * 2); + notaMaxima++; + } else { + notaMaxima = media - ((mediaDeNota - 1) * 2); + } + + return Math.max(mediaDeNota, notaMaxima); + } + + private static int maxScore(int media) { + if (media == 0) + return 0; + + Double m = Math.ceil(new Double((double) media / 3)); + int mediaDeNota = m.intValue(); + int notaMaxima = media - (mediaDeNota * 2); + + return Math.max(mediaDeNota, notaMaxima); + } + + public static String parser(String input) { + String[] lines = input.split(""\n""); + StringBuilder sb = new StringBuilder(); + + for (int index = 1; index < lines.length; index++) { + String[] current = lines[index].split("" ""); + + int numberSurprise = Integer.parseInt(current[1]); + int minimalAverrage = Integer.parseInt(current[2]); + int normalSum = 0; + int withSurpriseSum = 0; + + for (int j = 3; j < current.length; j++) { + int num = Integer.parseInt(current[j]); + boolean normal = maxScore(num) >= minimalAverrage; + + if (normal) + normalSum++; + else if (maxScoreWithSurprise(num) >= minimalAverrage) + withSurpriseSum++; + } + + int result = withSurpriseSum + normalSum; + result = (result <= normalSum + numberSurprise) ? result + : normalSum + numberSurprise; + + sb.append(""Case #""); + sb.append(index); + sb.append("": ""); + sb.append(result); + if (index != lines.length - 1) + sb.append(""\n""); + } + + return sb.toString(); + } + + public static String parseOfFile(File file) throws Exception { + FileInputStream fstream = new FileInputStream(file); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + StringBuffer sb = new StringBuffer(); + + String strLine; + while ((strLine = br.readLine()) != null) { + sb.append(strLine.trim()); + sb.append(""\n""); + } + + return parser(sb.toString()); + } + + public static void main(String[] args) throws Exception { +// System.out.println(maxScoreWithSurprise(21)); + System.out.println(parseOfFile(new File(""C:\\cide\\teste.txt""))); + } + +} +" +A22769,"package com.menzus.gcj._2012.qualification.b; + +import com.menzus.gcj.common.Processor; + +public class BMain { + + private static String SMALL_FILE_NAME = ""src/main/resources/com/menzus/gcj/_2012/qualification/b/B-small-attempt0.in.txt""; + + public static void main(String[] args) throws Exception { + Processor smallFileProcessor = new BProcessorFactory(SMALL_FILE_NAME).createProcessor(); + smallFileProcessor.process(); + + System.out.println(""done.""); + } +} +" +A20881,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + + +public class Main { + + public static void main(String args[]) throws NumberFormatException, IOException { + + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""out.txt"")); + GooglersDance a = new GooglersDance(); + + String inString = """"; + int t = Integer.parseInt(in.readLine()); + + for(int i = 0; i < t; i++) { + + inString = in.readLine(); + String[] word = inString.split("" ""); + int n = Integer.parseInt(word[0]); + int s = Integer.parseInt(word[1]); + int p = Integer.parseInt(word[2]); + int dancers[] = new int[n]; + for(int j = 3; j < word.length; j++) { + + dancers[j-3] = Integer.parseInt(word[j]); + + } + out.println(""Case #"" + (i+1) + "": "" + a.maxDancers(n,s,p,dancers)); + + } + in.close(); + out.close(); + + } + + private static void printArray(String[] a) { + + for(int i = 0; i < a.length; i++) { + + System.out.print(a[i] + "" ""); + + } + System.out.print(""\n""); + + } + +} +" +A20152,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Usuario + */ +import java.io.*; +import java.util.*; +public class DanceWithGooglers { + public static void main (String[] args) + { + BufferedReader br = null; + PrintStream ps = null; + + try + { + int t; + int n; + int s; + int p; + + int count; + int countsurprisingoblig; + int countimp; + + ArrayList scores; + + String line; + StringTokenizer st; + + br = new BufferedReader (new FileReader(""B.in"")); + ps = new PrintStream (new FileOutputStream (""B-samll1.out"")); + + line = br.readLine (); + t = Integer.parseInt (line); + + for (int testCase = 0; testCase < t; testCase++) + { + count = 0; + countsurprisingoblig = 0; + countimp = 0; + + line = br.readLine (); + st = new StringTokenizer (line); + + n = Integer.parseInt (st.nextToken ()); + s = Integer.parseInt (st.nextToken ()); + p = Integer.parseInt (st.nextToken ()); + + scores = new ArrayList (); + + for (int scoreInputIndex = 0; scoreInputIndex < n; scoreInputIndex++) + { + scores.add (Integer.parseInt (st.nextToken ())); + } + + for (int score : scores) + { + int diff = (int) Math.abs (score - (3*p)); + + if ((score < (3 * p)) && ((diff == 3 || diff == 4)) && (score != 0) && (p > 0)) + { + countsurprisingoblig++; + } + else if (((score < (3 * p)) && (diff > 4)) || ((score == 0) && (p > 0))) + { + countimp++; + } + } + + count = scores.size () - countimp - countsurprisingoblig; + + if (countsurprisingoblig > s) + { + count += s; + } + else + { + count += countsurprisingoblig; + } + +// System.out.println (count); +// System.out.println (n + "" "" + s + "" "" + p + "" "" + scores.toString ()); +// System.out.println (""Case #"" + (testCase + 1) + "": "" + s); + System.out.println(""Case #"" + (testCase + 1) + "": "" + count); + ps.println (""Case #"" + (testCase + 1) + "": "" + count); + } + + +// ps.println (""test1 test1 test1""); + +// System.out.println (""Hola Mundo!!!""); + } + catch (IOException ioe) + { + ioe.printStackTrace (); + } + catch (NumberFormatException nfe) + { + nfe.printStackTrace (); + } + finally + { + if (ps != null) + { + ps.close (); + } + if (br != null) + { + try + { + br.close (); + } + catch (IOException ioe) + { + ioe.printStackTrace (); + } + } + } + } +} +" +A22443," + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; + +public class Problem2 { + public static void main(String arg[]) + { + + try{ + FileInputStream fstream = new FileInputStream(""textfile.txt""); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + FileWriter foutstream = new FileWriter(""D:\\Problem2output.txt""); + BufferedWriter out = new BufferedWriter(foutstream); + + + String strLine,copyStrLine=""""; + int caseCount = -1; + strLine = br.readLine(); + caseCount = Integer.parseInt(strLine); + + for(int j=0; j < caseCount; j++) + //System.out.println (strLine); + { + strLine = br.readLine(); + String[] splitStrings = strLine.split("" ""); + int countGooglers = Integer.parseInt(splitStrings[0]); + int surprisingSet = Integer.parseInt(splitStrings[1]); + int pValue = Integer.parseInt(splitStrings[2]); + int pMaxCount = 0; + + for(int i = 0 ; i < countGooglers; i++ ) + { + int score = Integer.parseInt(splitStrings[3+i]); + int n = score / 3; + if(pValue > score){ + continue; + } + if(score % 3 == 0){ + if(n >= pValue){ + pMaxCount++; + } + if(n == pValue - 1){ + if(surprisingSet > 0){ + pMaxCount++; + surprisingSet--; + } + } + } + else if(score % 3 == 1){ + if(n >= pValue - 1){ + pMaxCount++; + } + } + else{ + if(n >= pValue - 1){ + pMaxCount++; + } + if(n == pValue - 2){ + if(surprisingSet > 0){ + pMaxCount++; + surprisingSet--; + } + } + } + } + System.out.println(""Case #"" + (j + 1) + "": "" + pMaxCount + ""\n""); + out.write(""Case #"" + (j + 1) + "": "" + pMaxCount + ""\n""); + + } + out.close(); + } + catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + + } + } + +} +" +A20778,"package problemB; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.StringTokenizer; + + + +public class DancingwithTheGooglers { + public static void main(String[] args) throws IOException { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + FileWriter fw = new FileWriter(""B-large.out""); + /*BufferedReader in = new BufferedReader(new FileReader(""A-large-practice.in"")); + FileWriter fw = new FileWriter(""A-large-practice.out"");*/ + int T = new Integer(in.readLine()); + for (int cases = 1; cases <= T; cases++){ + StringTokenizer st=new StringTokenizer(in.readLine()); + int numG = new Integer(st.nextToken()); + int numTriplets = new Integer(st.nextToken()); + int leastP = new Integer(st.nextToken()); + Integer[] A = new Integer[numG]; + for (int i = 0; i < A.length; i++){ + A[i] = new Integer(st.nextToken()); + } + Arrays.sort(A, Collections.reverseOrder()); + int result = 0; + for (int i = 0; i < A.length; i++){ + if (A[i] >= 2){ + if (A[i] > (leastP * 3 - 3)){ + result++; + } + else{ + if ((A[i] > (leastP *3 - 5)) && numTriplets > 0){ + result++; + numTriplets--; + } + } + } + else{ + if (A[i] >= leastP){ + result++; + } + } + } + + if (cases != T) {fw.write(""Case #"" + cases + "": ""+ result + ""\n""); } + else{fw.write(""Case #"" + cases + "": ""+ result);} + } + fw.flush(); + fw.close(); + } +} +" +A22029,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.*; + +public class Dance { + public static void main(String args[]){ + + Dance t=new Dance(); + Scanner sc; + int N; + int S; + int P; + int T; + List A; + int div; + int rem; + int goo; + int count = 0; + try{ + sc = new Scanner(new FileReader(""test.txt"")); + T = sc.nextInt(); + //in = new BufferedReader(new FileReader(""test.txt"")); + PrintWriter pw = new PrintWriter(new FileWriter(""Ans.txt"")); + + while(T>0) + { + goo = 0; + N = sc.nextInt(); + S = sc.nextInt(); + P = sc.nextInt(); + A = new ArrayList(); + for(int i=0; i=P){ + div = (Integer)A.get(j)/3; + rem = (Integer)A.get(j) - (div*3); + //System.out.println(div + "" "" + rem); + if(div>=P) + { + goo++; + } + else + { + if((P-div) == 1) + { + if(rem > 0) goo++; + else if(S>0){ + goo++; S--; + } + } + else if((P-div) == 2 && rem == 2 && S>0){ + goo++; S--; + } + + }} + } + //System.out.println(goo); + pw.println(""Case #""+ ++count +"": ""+ goo); + pw.flush(); + + T--; + } + pw.close(); + }catch(Exception e){} + + } +} +" +A20303," +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Scanner; +import java.util.Set; + + +public class Dancing { + + public static void main (String[] args){ + + String output = """"; + try { + System.out.println(""start : "" + new java.util.Date().toString()); + FileOutputStream fo = null; + FileInputStream fi = null; + fi = new FileInputStream(""F:\\adarsh\\codejam10\\codejam12\\src\\B-large.in""); + BufferedReader reader = new BufferedReader(new InputStreamReader(fi)); + Scanner sc = new Scanner(reader); + int testCases = sc.nextInt(); + System.out.println(""test cases : "" + testCases); + + fo = new FileOutputStream(""F:\\adarsh\\codejam10\\codejam12\\src\\B-large.out""); + PrintStream ps = new PrintStream(fo); + sc.nextLine(); + + for (int i = 1; i <= testCases; i++) { + output = """"; + int j = 0; + String data = sc.nextLine(); + System.out.println(""data : "" + data); + String[] dataarray = data.split("" ""); + int noofgooglers = Integer.parseInt(dataarray[j++]); + int[] totallist = new int[noofgooglers]; + int noofsurprises = Integer.parseInt(dataarray[j++]); + int highestval = Integer.parseInt(dataarray[j++]); + int k = 0; + for(; j < dataarray.length ; j++) + { + totallist[k++]= Integer.parseInt(dataarray[j]); + } + Arrays.sort(totallist); + int out = performWork(noofsurprises , highestval , totallist ); + sout(""out"" , """"+out); + ps.println(""Case #""+i+"": "" + out); + } + ps.close(); + fo.close(); + System.out.println(""end : "" + new java.util.Date().toString()); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private static int performWork(int noofsurprises , int p , int[] totallist) + { + int output = 0; + int surprisesfound = 0; + for(int i = 0 ; i < totallist.length ; i++) + { + //int total = Integer.parseInt((String)totallist.get(i)); + int total = totallist[i]; + sout(""total"" , """"+total); + + + if(surprisesfound < noofsurprises) + { + int num1 = (int)Math.ceil((double)total/3); + if(num1 > 10 ) num1 = 10; + sout(""num1"" , """" + num1); + int num2= num1; + int num3 = total - num1 - num2; + + if((num1 != 0) && !(Math.abs(num2-num3) == 2)) + { + num1--; + num2++; + } + + if(num1 >= p || num2 >= p || num3 >= p) + { + surprisesfound++; + output++; + } + sout(""output"" , """"+output); + sout(""set : "", """"+num1+"" ""+num2+"" ""+num3); + } + else + { + int num1 = (int)Math.round((double)total/3); + if(num1 > 10 ) num1 = 10; + sout(""num1"" , """" + num1); + int num2= num1; + int num3 = total - num1 - num2; + if(num1 >= p || num3 >= p) + { + output++; + } + sout(""output"" , """"+output); + sout(""set : "", """"+num1+"" ""+num2+"" ""+num3); + } + + } + sout(""output"" , """"+output); + return output; + } + + private static void sout(String str1 , String str2) + { + System.out.println(str1 + "" : "" + str2); + } + } + + + + + +" +A21323,"package gcj_qr_b; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Scanner; + +/** + * + * @author amahdy + */ +public class GCJ_QR_B { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, IOException { + new GCJ_QR_B().start(); + } + + private void start() throws FileNotFoundException, IOException { + + Scanner in = new Scanner( + new FileReader(""/home/amahdy/b-large.in"")); + int x = in.nextInt(); + in.nextLine(); + + for (int i = 0; i < x; ) { + + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] t = new int[N]; + for(int j=0; j=p) { + max++; + }else if(min+1==p && S>0) { + S--; + max++; + } + break; + case 1: + if(min<10 && min+1>=p) { + max++; + } + break; + case 2: + if(min<10 && min+1>=p) { + max++; + }else if(min<9 && min+2==p && S>0) { + S--; + max++; + } + break; + } + } + System.out.println(""Case #"" + ++i + "": "" + max); + } + } +} +" +A22024,"import java.io.File; +import java.io.PrintWriter; +import java.util.Scanner; + +public class Solution { + static int getGroup(int t, int p) { + if (t >= 2) { + if ((t + 1) / 3 + 1 < p) return 0; + if ((t + 2) / 3 < p) return 1; + return 2; + } else if ((t + 2) / 3 >= p) return 3; + return 4; + } + + public static void main(String[] args) throws Exception { + Scanner in = new Scanner(new File(""B-large.in"")); + PrintWriter out = new PrintWriter(new File(""out.txt"")); + int T = in.nextInt(); + for (int tc = 1; tc <= T; tc++) { + out.print(""Case #"" + tc + "": ""); + int n = in.nextInt(), s = in.nextInt(), p = in.nextInt(); + int cnt[] = new int[5]; + for (int i = 0; i < n; i++) { + int t = in.nextInt(); + cnt[getGroup(t, p)]++; + } + int ans = cnt[3] + cnt[2] + Math.min(cnt[1], s); + out.println(ans); + } + out.close(); + } + +} +" +A20797," +import java.io.*; + +public class gcj + { + + public static void main(String[] args) throws IOException + { + + String fileName = ""B-large.in""; + FileReader reader = new FileReader(fileName); + LineNumberReader lnreader = new LineNumberReader(reader); + FileWriter writer = new FileWriter(""output-B-large.txt""); + PrintWriter out = new PrintWriter(writer); + + String line = """"; + line = lnreader.readLine(); + int no_of_googlers = 0; + int surprise; + int min_score; + int total_score; + int rem_score; + int count; + int kase = 0; + String[] strings = line.split("" ""); + int no_test_cases = Integer.parseInt(strings[0]); + + while ((line = lnreader.readLine()) != null){ + strings = line.split("" ""); + kase++; + count = 0; + no_of_googlers = Integer.parseInt(strings[0]); + surprise = Integer.parseInt(strings[1]); + min_score = Integer.parseInt(strings[2]); + for (int i = 0;i -1){ + if (((min_score*2 - rem_score) < 3) ){ + count++; + } else { + if ((min_score*2 - rem_score == 3) || (min_score*2 - rem_score == 4)){ + if (surprise != 0) { + count ++; + surprise--; + } + } + } + } + } + out.println(""Case #"" + (lnreader. + getLineNumber()-1) + "": "" + count); + } + out.close(); + + } + + } + +" +A22841,"package gcj.gcj2012.qualif; + +import gcj.SolverBase; + +import java.io.BufferedReader; +import java.io.PrintStream; + +public class ProblemB extends SolverBase { + + public ProblemB() { + super(""Dancing With the Googlers""); + } + + public static void main(String[] args) throws Exception { + SolverBase problem = new ProblemB(); + // problem.verbose = true; + problem.solve(System.in, System.out); + } + + @Override + public void solveSingle(BufferedReader reader, PrintStream out) throws Exception { + int[] line = readSingleLineIntArray(reader); + int N = line[0]; + int S = line [1]; + int p = line [2]; + + int x = 0; + for(int i=3;i<3+N;i++){ + int sum = line [i]; + + if( sum < p ){ + // no way... + continue; + } + + if( sum >= ((p-1)+(p-1)+p) ){ + // No surprise needed + x ++; + }else if( S>0 && sum >= ((p-2)+(p-2)+p) ){ + // Consuming 1 surprise + x ++; + S --; + } + } + + out.println( x ); + } +} +" +A21569,"package com.codejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class ProblemB { + + public static void main(String[] args) throws FileNotFoundException { + + Scanner sc = new Scanner(new File(""B-large.in"")); + int T = sc.nextInt(); + sc.nextLine(); + + for (int i = 0; i < T; i++) { + int N = sc.nextInt(); + int S = sc.nextInt(); + int p = sc.nextInt(); + + int[] t = new int[N]; + for (int j = 0; j < N; j++) { + t[j] = sc.nextInt(); + } + + System.out.println(""Case #"" + (i + 1) + "": "" + solve(N, S, p, t)); + + } + + } + + private static int solve(int N, int S, int p, int[] t) { + + int countA = 0, countB1 = 0, countB2 = 0, countC1 = 0, countC2 = 0, count = 0; + for (int i = 0; i < N; i++) { + int r = t[i] % 3, d = t[i] / 3; + switch (r) { + case 1: + if (d + 1 >= p) { + countA++; + } + break; + case 0: + if (d == 0) { + if (d >= p) { + countB1++; + } + } else if (d >= 10) { + if (d >= p) { + countB1++; + } + } else if (d >= p) { + countB1++; + } else if (d + 1 == p && d > 0) { + countB2++; + } + break; + case 2: + if (d >= 9) { + if (d + 1 >= p) { + countC1++; + } + } else if (d + 1 >= p) { + countC1++; + } else if (d + 2 == p) { + countC2++; + } + break; + default: + break; + } + } + + count = countA + countB1 + countC1 + Math.min(countB2 + countC2, S); + return count; + } + +} +" +A22325,"import java.util.*; + +import static java.lang.Math.*; + +public class B { + public static void main(String[] args){ + + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int a = 1; a <= T;a++){ //caso de prueba + in.nextLine(); + int N = in.nextInt(); + int S = in.nextInt(); + int pInt = in.nextInt(); + double p = (double) pInt; + int scores[] = new int[N]; + int scoresaux[] = new int[N]; + int result = 0; + for(int b = 0; b < N;b++) + scoresaux[b] = in.nextInt(); + Arrays.sort(scoresaux); + for(int b = 0, c=N-1; b < N;b++, c--) + scores[b] = scoresaux[c]; + for ( int b = 0; b < N;b++ ) + { + double score = (double)scores[b]; + double aux = score/3; + if(score/3 > (p-1.0) ) //Tiene mayor nota seguro + result++; + else + if( score/3 <= 0.0 || score/3 < (p -1.5) ) + break; + else + { + if (S>0) { result++; S--;} + else break; + } + } + System.out.format(""Case #%d: %d\n"", a, result); + } + } +} +" +A21665,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.lang.reflect.Array; +import java.math.BigInteger; +import java.util.ArrayList; +public class Problem extends Template { + public static void main(String[] args) throws Exception { + _iFILE = ""sample""; + _oFILE = ""output""; + +// Base ProblemA = new Base(new int[] {0, 1}) { +// String lhs = "" abcdefghijklmnopqrstuvwxyz""; +// String rhs = "" yhesocvxduiglbkrztnwjpfmaq""; +// +// @Override +// protected String implementation(String[][] params) { +// String trans = """"; +// String input = ArrayUtil.join(params[0], "" ""); +// for (int i = 0; i < input.length(); i++) { +// trans += rhs.charAt(lhs.indexOf(input.charAt(i))); +// } +// +// return trans; +// } +// }; + Base ProblemB = new Base(new int[] {0, 1}) { + @Override + protected String implementation(String[][] params) { + int count = 0; + + int n = new Integer(params[0][0]).intValue(); + int s = new Integer(params[0][1]).intValue(); + int p = new Integer(params[0][2]).intValue(); + + boolean[][] match = new boolean[n][2]; + + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = new Integer(params[0][3 + i]).intValue(); + + //Assuming x <= y <= z + boolean s_match = false; + boolean n_match = false; + + for (int x = 0; x <= 10; x++) { + { + int z = x + 2; + int y = t[i] - x - z; + + if(x <= y && y <= z && z >= p) { + //System.out.println(""\t("" + x + "","" + y + "","" + z + "") "" + p); + s_match = true; + } + } + { + int z = x + 1; + int y = t[i] - x - z; + + if(x <= y && y <= z && z >= p) { + //System.out.println(""\t("" + x + "","" + y + "","" + z + "") "" + p); + n_match = true; + } + } + { + int z = x; + int y = t[i] - x - z; + + if(x <= y && y <= z && z >= p) { + //System.out.println(""\t("" + x + "","" + y + "","" + z + "") "" + p); + n_match = true; + } + } + } + match[i][0] = s_match; + match[i][1] = n_match; + + /*System.out.print(t[i]); + if(s_match) System.out.print("" *""); + if(n_match) System.out.print("" +""); + System.out.println();*/ + + if(n_match) + count++; + else if(s > 0 && s_match) { + s--; + count++; + } + } + return Integer.toString(count); + } + }; +// Base ProblemC = new Base(new int[] {0, 1}) { +// @Override +// protected String implementation(String[][] params) { +// int count = 0; +// try { +// int len = params[0][0].length(); +// Integer[] p = ArrayUtil.convert(params[0], Integer.class); +// for (int n = p[0]; n <= p[1]; n++) { +// int m = n; +// while(true) { +// m = (int) ((m%10)*Math.pow(10, len - 1)) + m/10; +// if(n < m && m <= p[1]) count++; +// +// if(n == m) break; +// } +// } +// }catch (Exception e) { +// e.printStackTrace(); +// System.exit(0); +// } +// +// return Integer.toString(count); +// } +// }; +// Base ProblemD = new Base(new int[] {1, 0}) { +// @Override +// protected String implementation(String[][] params) { +// int r = new Integer(params[0][0]).intValue(); +// int c = new Integer(params[0][1]).intValue(); +// int d = new Integer(params[0][2]).intValue(); +// +// +// +// +// return """"; +// } +// }; + + ProblemB.run(); + } +} + +class Template { + public static String _oFILE; + public static String _iFILE; + + public static abstract class Base { + static { System.out.println(""--- GOOGLE CODE JAM 2012 ---------------------------------------""); } + + private int[] inputType; + private String columnSeperator = "" ""; + private Template.Base.iCollection input; + abstract protected String implementation(String[][] params) throws Exception; + + public Base(int[] inputType) throws Exception { + this.inputType = inputType; + if (new File(_iFILE).exists()) { + input = new Template.Base.iCollection(); + + String strLine; + BufferedReader buffReader = new BufferedReader(new FileReader(_iFILE)); + while ((strLine = buffReader.readLine()) != null) + input.add(strLine.split(columnSeperator)); + buffReader.close(); + + input.index(); + }else { throw new Exception(""Input File Missing""); } + } + + public void run() throws Exception { + int inputSize = new Integer(input.get(0)[0]).intValue(); + BufferedWriter buffWriter = new BufferedWriter(new FileWriter(new File(_oFILE))); + for (int i = 1; i <= inputSize; i++) { + String result = implementation(Template.ArrayUtil.convert(input.item(i))); + printResult(input.item(i), result); + + buffWriter.write(""Case #"" + i + "": "" + result + ""\n""); + buffWriter.flush(); + } + buffWriter.close(); + + System.out.println(""----------------------------------------- GOOGLE INPUT TYPES ---""); + System.out.println(""{0,n} : EACH CASE WITH n (n > 0) ROWS""); + System.out.println(""{1,0} : EACH CASE WITH DYNAMIC (DEFINED @ FIRST ROW) SET OF ROWS""); + System.out.println(""--------------------------------------------- Subodh Gairola ---""); + } + + private void printResult(ArrayList params, String result) { + for (int i = 0; i < params.size(); i++) { + for (int j = 0; j < params.get(i).length; j++) { + System.out.print(params.get(i)[j] + "" ""); + } + System.out.println(); + } + System.out.println(""\t\t|"" + result + ""|""); + } + class iCollection extends ArrayList { + private static final long serialVersionUID = 1L; + int[][] _index; + + public void index() { + _index = new int[new Integer(this.get(0)[0]).intValue() + 1][2]; + _index[0][0] = inputType[0]; + _index[0][1] = inputType[1]; + for (int i = 1; i < _index.length; i++) { + if (_index[0][0] == 0) { + int len = inputType[1]; + + _index[i][0] = 1 + (i - 1) * len; + _index[i][1] = len; + } else if (_index[0][0] == 1) { + int lastPos = _index[i - 1][0]; + int lastLen = _index[i - 1][1]; + + _index[i][0] = lastPos + lastLen; + _index[i][1] = new Integer(this.get(_index[i][0])[0]).intValue() + 1; + } + } + } + public Template.Base.iCollection item(int index) { + int pos = _index[index][0]; + int len = _index[index][1]; + Template.Base.iCollection params = new Template.Base.iCollection(); + for (int i = pos; i < pos + len; i++) { + params.add(this.get(i)); + } + return params; + } + } + } + public static class Generator { + public int[] a; + public BigInteger numLeft; + public BigInteger total; + public void reset() { + for (int i = 0; i < a.length; i++) { + a[i] = i; + } + numLeft = new BigInteger(total.toString()); + } + public BigInteger getNumLeft() { + return numLeft; + } + public BigInteger getTotal() { + return total; + } + public boolean hasMore() { + return numLeft.compareTo(BigInteger.ZERO) == 1; + } + public static BigInteger getFactorial(int n) { + BigInteger fact = BigInteger.ONE; + for (int i = n; i > 1; i--) { + fact = fact.multiply(new BigInteger(Integer.toString(i))); + } + return fact; + } + public static class Permutation extends Template.Generator { + public Permutation(int n) { + if (n < 1) { + throw new IllegalArgumentException(""Minimum 1""); + } + a = new int[n]; + total = Template.Generator.getFactorial(n); + reset(); + } + public int[] getNext() { + if (numLeft.equals(total)) { + numLeft = numLeft.subtract(BigInteger.ONE); + return a; + } + int temp; + int j = a.length - 2; + while (a[j] > a[j + 1]) { + j--; + } + int k = a.length - 1; + while (a[j] > a[k]) { + k--; + } + temp = a[k]; + a[k] = a[j]; + a[j] = temp; + int r = a.length - 1; + int s = j + 1; + while (r > s) { + temp = a[s]; + a[s] = a[r]; + a[r] = temp; + r--; + s++; + } + numLeft = numLeft.subtract(BigInteger.ONE); + return a; + } + } + public static class Combination extends Template.Generator { + private int n; + private int r; + + public Combination(int n, int r) { + if (r > n) { + throw new IllegalArgumentException(); + } + if (n < 1) { + throw new IllegalArgumentException(); + } + this.n = n; + this.r = r; + a = new int[r]; + BigInteger nFact = Template.Generator.getFactorial(n); + BigInteger rFact = Template.Generator.getFactorial(r); + BigInteger nminusrFact = Template.Generator.getFactorial(n - r); + total = nFact.divide(rFact.multiply(nminusrFact)); + reset(); + } + public int[] getNext() { + if (numLeft.equals(total)) { + numLeft = numLeft.subtract(BigInteger.ONE); + return a; + } + int i = r - 1; + while (a[i] == n - r + i) { + i--; + } + a[i] = a[i] + 1; + for (int j = i + 1; j < r; j++) { + a[j] = a[i] + j - i; + } + numLeft = numLeft.subtract(BigInteger.ONE); + return a; + } + } + } + public static class ArrayUtil { + @SuppressWarnings(""unchecked"") + public static T[][] permutations(T[] array) { + Template.Generator.Permutation x = new Template.Generator.Permutation(array.length); + ArrayList permutations = new ArrayList(); + while (x.hasMore()) { + int[] indices = x.getNext(); + T[] permutation = (T[]) Array.newInstance(array[0].getClass(), indices.length); + for (int i = 0; i < indices.length; i++) { + permutation[i] = array[indices[i]]; + } + permutations.add(permutation); + } + return convert(permutations); + } + @SuppressWarnings(""unchecked"") + public static T[][] combinations(T[] array, int n) { + Template.Generator.Combination x = new Template.Generator.Combination(array.length, n); + ArrayList combinations = new ArrayList(); + while (x.hasMore()) { + int[] indices = x.getNext(); + T[] combination = (T[]) Array.newInstance(array[0].getClass(), indices.length); + for (int i = 0; i < indices.length; i++) { + combination[i] = array[indices[i]]; + } + combinations.add(combination); + } + return convert(combinations); + } + @SuppressWarnings(""unchecked"") + public static T[] convert(String[] array, Class cl) throws Exception { + T[] n = (T[]) Array.newInstance(cl, array.length); + for (int i = 0; i < array.length; i++) { + n[i] = cl.getConstructor(String.class).newInstance(array[i]); + }; + return n; + } + public static String[] convert(T[] array) throws Exception { + String[] n = new String[array.length]; + for (int i = 0; i < array.length; i++) { + n[i] = array[i].toString(); + } + return n; + } + @SuppressWarnings(""unchecked"") + public static T[] convert(ArrayList arrayList) { + if (arrayList.size() == 0) { + return null; + } + T[] array = (T[]) Array.newInstance(arrayList.get(0).getClass(), arrayList.size()); + for (int i = 0; i < array.length; i++) { + array[i] = arrayList.get(i); + } + return array; + } + public static String join(T[] array, String seperator) { + String string = """"; + for (int i = 0; i < array.length; i++) { + string += array[i].toString(); + if (i < array.length - 1) { + string += seperator; + } + } + return string; + } + public static T[] remove(T[] array, int index) { + ArrayList arrayList = new ArrayList(); + for (int i = 0; i < array.length; i++) { + if (i != index) { + arrayList.add(array[i]); + } + } + return convert(arrayList); + } + public static T[] unique(T[] array) { + ArrayList arrayList = new ArrayList(); + for (int i = 0; i < array.length; i++) { + if (!arrayList.contains(array[i])) { + arrayList.add(array[i]); + } + } + return convert(arrayList); + } + } +} +" +A21210,"import java.util.Scanner; + +public class Main extends AbstractCodeJam { + + @Override + protected Problem readProblem(Scanner scan) { + ProblemSample pb = new ProblemSample(); + // PARAMETRES A LIRE !!! + pb.setGooglers(scan.nextInt()); + pb.setSurprises(scan.nextInt()); + pb.setNote(scan.nextInt()); + for (int i = 0; i < pb.getGooglers(); i++) { + pb.getSums().add(scan.nextInt()); + } + scan.nextLine(); + return pb; + } + + /** + * @param args + */ + public static void main(String[] args) { + new Main().solveProblems(System.in, System.out); + } + +} +" +A20713,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + + +class GoogleCodeJam2 { + static BufferedReader br ; + static PrintWriter pw; + static String line; + static HashSet hs; + + public static void main (String [] args) throws IOException { + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(""C:\\Code\\google\\in.txt"")))); + pw = new PrintWriter(new File(""C:\\Code\\google\\out.out"")); + start(); +// +// do { +// present = func(present, start); +// if (present != null) { +// for (int i : present) +// { +// System.out.print(i+"",""); +// } +// } +// System.out.println(); +// }while (present!= null); + + +// Integer input[] = {1,2,3,8,9}; +// System.out.println(convert(input)); +// for (int i: convert(12389)) { +// System.out.print(i+"",""); +// } + + pw.flush(); + pw.close(); + br.close(); + } + catch (NumberFormatException t) { + //throw t; + } + } + + static void start() throws IOException { + int n=0; + int n1=0; + int s=0; + int p=0; + String firstLine = br.readLine().trim(); + n = Integer.parseInt(firstLine.trim()); + + for( int i=0; i1) { + if (t>limit) { + finalSum++; + } else if (t == limit || t==limit-1) { + if (sDone=1) { + finalSum++; + } + } + else if (p<=0) { + finalSum++; + } +// else if (p==2) { +// if (t==1||t==0){ +// +// } else if (t==2 || t==3) { +// if (sDone 10){ + status = ""invalid""; + } + else{ + if(judgec - judgea==2){ + status = ""surprising""; + } + else if((judgec - judgea)==1 || (judgec - judgea)==0){ + status = ""not surprising""; + } + else{ + status = ""invalid""; + } + } + } + public int score(){ + return Math.max(Math.max(judgea,judgeb),judgec); + } + public String toString(){ + if(status.matches(""invalid"")){ + return ""invalid""; + } + return ""("" + judgea+ "","" + judgeb + "","" + judgec +"")""; + } + + + +} +" +A20399,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + + +public class google2 { + + + public static String translate(String l, int index){ + String[] strarray=l.split("" ""); + int N = Integer.valueOf(strarray[0]); + int S = Integer.valueOf(strarray[1]); + int p = Integer.valueOf(strarray[2]); + int right=0; + int realS=0; + int resultnb=0; + if (p>=2){ + for (int i = 3; i < strarray.length; i++){ + int tmp = Integer.valueOf(strarray[i]); + if (tmp>=(3*p-2)){ + right +=1; + } else if (tmp>=(3*p-4)){ + realS+=1; + } + } + resultnb = (right+Math.min(realS, S)); + } else { + for (int i = 3; i < strarray.length; i++){ + int tmp = Integer.valueOf(strarray[i]); + if (tmp>=p){ + resultnb +=1; + } + } + } + + String result = ""Case #""+(index+1)+"": ""+resultnb; + return result; + } + + public static void main(String[] args) throws IOException { + + BufferedReader inputStream = null; + PrintWriter outputStream = null; + + try { + inputStream = new BufferedReader(new FileReader(""input.txt"")); + outputStream = new PrintWriter(new FileWriter(""output.out"")); + + //inputStream.readLine(); + int nbLines = Integer.valueOf(inputStream.readLine()); + //outputStream.println(""Output""); + for (int i = 0 ; i< nbLines-1;i++){ + String l; + l = inputStream.readLine(); + outputStream.println(translate(l,i)); + } + String l= inputStream.readLine(); + outputStream.print(translate(l,nbLines-1)); + } finally { + if (inputStream != null) { + inputStream.close(); + } + if (outputStream != null) { + outputStream.close(); + } + } + } +} +" +A23089,"import java.util.*; +import java.io.*; +public class B { + public B(Scanner in, PrintWriter out) { + int T = in.nextInt(); + in.nextLine(); + for (int t=0; t= P) { + ans+=vals[a+b+c]; + vals[a+b+c]=0; + } else if (a >= P) { + int tmp = Math.min(vals[a+b+c], S); + S -= tmp; + ans += tmp; + vals[a+b+c] -= tmp; + } + } + out.printf(""Case #%d: %d\n"",t+1,ans); + } + out.close(); + } + public static void main(String[] args) throws FileNotFoundException { + new B(new Scanner(new File(""b.in"")),new PrintWriter(new File(""b.out""))); + } +} +" +A21571,"package me.mevrad.codejam; + +import java.util.ArrayList; + +public class DataTemplate { + + public int numberOfGooglers; + public int surprisingScores; + int p; + public ArrayList scores; + + public DataTemplate(){ + scores = new ArrayList(); + } +} +" +A21104,"import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; + + +public class Countscores { + + public static int processLine(String data) { + int result = 0; + String[] info = data.split("" ""); +// for (int i = 0; i < info.length; i++) { +// System.out.print(info[i] + "" ""); +// } +// System.out.println(); + + int N = Integer.parseInt(info[0]); + if (info.length < 3 + N) { + System.err.println(""insufficient arguments!""); + return -1; + } + int surprises = Integer.parseInt(info[1]); + int surprisecount = 0; + int threshold = 3 * Integer.parseInt(info[2]); + + for (int i = 0; i < N; i++) { + int totalscore = Integer.parseInt(info[3 + i]); + if (totalscore >= threshold - 2) { + result++; + } else if (totalscore > Math.max(threshold - 5, 0) + && surprisecount < surprises) { + result++; + surprisecount++; + } + } + + return result; + } + + public static void countScores(String input) { + try { + BufferedReader br = new BufferedReader(new FileReader(input)); + int cases = Integer.parseInt(br.readLine()); + int idx = 0; + while (idx < cases) { + idx++; + System.out.println(""Case #"" + idx + "": "" + processLine(br.readLine())); + } + br.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + String input = ""C:/Users/hattori/Downloads/B-large.in""; + countScores(input); + } + +} +" +A20506,"import java.io.*; +import java.util.*; +class Q2 +{ + public static void main(String str[])throws IOException + { +// FileReader fr=new FileReader(""B-small-attempt0.in""); + FileReader fr=new FileReader(""B-large.in""); + BufferedReader br=new BufferedReader(fr); + FileWriter fw=new FileWriter(""output.txt""); + BufferedWriter bw=new BufferedWriter(fw); + PrintWriter pw=new PrintWriter(bw); + int T=Integer.parseInt(br.readLine()); + for(int i=1;i<=T;i++) + { + String s=br.readLine(); + StringTokenizer st=new StringTokenizer(s); + int N=Integer.parseInt(st.nextToken()); + int S=Integer.parseInt(st.nextToken()); + int p=Integer.parseInt(st.nextToken()); + int Arr[][]=new int[N][4]; + for(int j=0;j=p) + Arr[j][1]=1; + else + Arr[j][1]=0; + } + else + { + Arr[j][2]=n+1; + if(n+1>=p) + Arr[j][1]=1; + else + Arr[j][1]=0; + } + } + for(int j=0;j=p && (Arr[j][2]+1)<=Arr[j][3]) + { + S--; + Arr[j][1]=1; + } + } + int sum=0; + for(int j=0;j=highest){ + resultCount++; + } + + }else if(number%3==1){ + + be.first= number/3; + be.second = number/3; + be.third = (number/3)+1; + if(be.third>=highest){ + resultCount++; + + } + + }else if(number%3==2){ + if((number/3)==9){ + be.first=number/3; + be.second=be.first+1; + be.third=be.first+1; + if(be.second>=highest){ + resultCount++; + + } + }else if(pendingtriplets==0){ + be.first=number/3; + be.second=be.first+1; + be.third=be.first+1; + if(be.second>=highest){ + resultCount++; + + } + } + else{ + be.first=number/3; + be.second=(number/3)+2; + be.third=number/3; + + if(be.second>=highest){ + resultCount++; + surpriseCount++; + pendingtriplets--; + } + } + } + list.add(be); + + + + + } + //System.out.println(""triplets :""+triplets+"", surprise ""+surpriseCount); + + if(triplets>surpriseCount){ + for(int cc=0;ccsurpriseCount){ + //System.out.println(""triplets :""+triplets+"", surprise ""+surpriseCount); + Bean be1 = (Bean)list.get(cc); + // System.out.println(be1.first+"",""+be1.second+"",""+be1.third); + if(((be1.first==be1.second)&&(be1.second==be1.third))&&be1.first!=10&&be1.first!=0){ + + if((be1.first+1)>=highest){ + + be1.first=be1.first-1; + + be1.third =be1.third+1; + if(!(be1.second>=highest)) + resultCount++; + surpriseCount++; + + }else if((be1.first-1)>=highest){ + be1.first=be1.first-1; + be1.third =be1.third+1; + if(!(be1.second>=highest)) + resultCount++; + surpriseCount++; + + } + } + + // list.add(cc,be1); + } + } + } + System.out.println(""Case #""+(s+1)+"": ""+resultCount); + } + } +} +class Bean{ + int first; + int second; + int third; +}" +A22362,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class QB { + + static final String TASK_ID = ""qb""; + static BufferedReader reader; + static PrintWriter writer; + + public static void main(String[] args) { + try { + long now = System.currentTimeMillis(); + reader = new BufferedReader(new FileReader(TASK_ID + "".in"")); + writer = new PrintWriter(TASK_ID + "".out""); + + int numTests = Integer.parseInt(reader.readLine()); + + for (int testId = 0; testId < numTests; testId++) { + Solver solver = new Solver(testId); + solver.readInput(); + solver.run(); + solver.printOutput(); + } + + reader.close(); + writer.close(); + System.out.println(System.currentTimeMillis() - now + ""ms""); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + static class Solver { + + private int testId; + private int N, S, p; + private int[] t; + private int result; + + public Solver(int testId) { + this.testId = testId; + } + + public void run() { + int normalOK = 3*p-2; + int surprisingOK = 3*p-4; + //if p=0, all dancers will pass + //if p=1, normalOK=1, only zero will fail, so set surprisingOK so that no one will pass + if (p==1) surprisingOK=99; + + for (int i=0; i=normalOK) { + result++; + } else if (S>0 && t[i]>=surprisingOK) { + S--; //one less surprise to use + result++; + } + } + } + + private void readInput() { + try { + String line = reader.readLine(); + StringTokenizer st = new StringTokenizer(line); + N = Integer.parseInt(st.nextToken()); + S = Integer.parseInt(st.nextToken()); + p = Integer.parseInt(st.nextToken()); + t = new int[N]; + for (int i=0; i= 3*p) + n++; + else if (pi >= 3*p -1) + n++; + else if (pi >= 3*p -2) + n++; + else if (pi >= 3*p - 4 && (3*p - 4)>=0 && S > 0){ + S--; + n++; + } + } + ps.format(""%d\n"", n); + + } + + public static void main(String[] args) throws IOException { + if (args.length < 1){ + System.err.println(""not suffucient args""); + System.exit(-1); + } + BufferedReader in = openRead(args[0]); + PrintStream ps = new PrintStream(new File(args[1])); + // read size + int T = 0; + String TStr = in.readLine(); + T = Integer.parseInt(TStr); + if ( T < 1 || T > 100) + System.exit(-1); + + + // read contents + String line; + for (int i = 0; i < T && (line = in.readLine())!= null; i++){ + processLine( line, i+1, ps); + } + + + + + + + System.out.println(""Done!""); + + } + +} +" +A21578,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package uk.co.epii.codejam.common; + +/** + * + * @author jim + */ +public interface Processor { + + public String processLine(String line); + +} +" +A21167,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class DancingWiththeGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + new DancingWiththeGooglers().fun(); + } + + private void fun() + { + String file = ""D:/CodeJam/inputB.in""; + try { + scan = new Scanner(new File(file)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + int cases = scan.nextInt(); + + for(int i = 1; i <= cases ; i++) + { + int noOfGooglers = findTheResult(); + System.out.println(""Case #""+i+"": ""+noOfGooglers); + } + } + + private int findTheResult() + { + int googlers = scan.nextInt(); + int surprising = scan.nextInt(); + int minScore = scan.nextInt(); + int minValue = getMinValue(minScore); + int criticValue1 = minValue; + int criticValue2 = criticValue1 + 1; + int count = 0; + int criticalCount = 0; + for(int i = 0; i< googlers; i++) + { + int score = scan.nextInt(); + if(minValue == 0) + { + count++; + continue; + } + else if(minValue == 1) + { + if(score >= minValue) + count++; + continue; + } + if(score >= minValue) + { + if(score == criticValue1 || score == criticValue2) + { + if(criticalCount < surprising) + { + count++; + criticalCount++; + } + } + else + count++; + } + } + return count; + } + + private int getMinValue(int minScore) + { + int value = 0; + if(minScore > 2) + { + value = minScore - 2; + value = minScore + value*2; + } + else + value = minScore; + + return value; + } + + Scanner scan = null; +} +" +A22878,"package com.google.codejam.googlers; + +/** + * Class to hold the result of given test case. + * @author Sushant Deshpande + */ +public class TestResult { + + /** + * variable to represent testOutput. + */ + private int testOutput; + + + /** + * Constructor to create TestResult with testOutput. + * @param testOutput String + */ + public TestResult(final int testOutput) { + this.testOutput = testOutput; + } + + /** + * Getter method for test output. + * @return String + */ + public final int getTestOutput() { + return testOutput; + } + +}" +A21435,"package com.google.jam.eaque.stub; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +import com.google.jam.eaque.qualif.b.Small; + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + + if (args.length != 2) { + System.out.println(""args length : "" + args.length); + System.exit(0); + } + + Stub body = new Small(); + body.setOutputFileName(args[1]); + + try { + InputFileManager ifm = new InputFileManager(args[0]); + BufferedWriter bw = new BufferedWriter(new FileWriter( + body.getOutputFileName())); + + long nbTestCases = ifm.readLong(); + + for (long i = 0; i < nbTestCases; i++) { + bw.write(""Case #"" + (i + 1) + "":"" + body.runTestCase(ifm)); + bw.newLine(); + } + + ifm.close(); + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} +" +A20114,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Googlers { + + /** + * @param args + */ + public static void main(String[] args) { + Scanner scanner = null; + int caseNumber = 0; + Googlers a = new Googlers(); + + try { + scanner = new Scanner(new FileInputStream(args[0])); + while (scanner.hasNextLine()) { + + if (caseNumber == 0) { + scanner.nextLine(); + } else { + String pairs = scanner.nextLine(); + String[] numbers = pairs.split("" ""); + + System.out.println(""Case #"" + caseNumber + "": "" + + a.resolve(numbers)); + } + caseNumber++; + } + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } finally { + scanner.close(); + } + + } + + private Integer resolve(String[] data) { + + int googlersNumber = Integer.parseInt(data[0]); + int surprices = Integer.parseInt(data[1]); + int p = Integer.parseInt(data[2]); + int total = 0; + + ArrayList googlers = new ArrayList(); + for (int i = 0; i < googlersNumber; i++) { + googlers.add(Integer.parseInt(data[3 + i])); + } + + // create the triadas + + ArrayList scores = createTriada(googlers); + + if (surprices > 0) { + // Count number surpricing + Integer totalSuprising = countNumberSurprising(scores); + + if (totalSuprising == surprices) { + // Count p + total = countP(p, scores); + + } else { + // Create missing surprises + scores = createMissingSurprices(surprices - totalSuprising, p, + scores, false); + + Integer totalSuprisingB = countNumberSurprising(scores); + + if (totalSuprisingB != surprices) { + scores = createMissingSurprices(surprices - totalSuprising, + p, scores, true); + } + + // check p + total = countP(p, scores); + } + } else { + total = countP(p, scores); + } + + return total; + } + + private ArrayList createTriada(ArrayList g) { + + ArrayList scores = new ArrayList(); + + for (Integer number : g) { + Integer[] score = new Integer[3]; + + for (int i = 3; i > 0; i--) { + + float resultPrecise = number / i; + int resultInteger = number / i; + int calification = 0; + if (resultPrecise > resultInteger) { + calification = resultInteger + 1; + } else { + calification = resultInteger; + } + score[i - 1] = calification; + number = number - calification; + } + + scores.add(score); + } + + return scores; + } + + private Boolean checkSurprising(Integer[] scores) { + + Boolean found = false; + + int a = scores[0] - scores[1]; + int b = scores[0] - scores[2]; + int c = scores[1] - scores[2]; + + if (a == 2 || b == 2 || c == 2) { + found = true; + } + + return found; + } + + private int countNumberSurprising(ArrayList c) { + + Boolean found = false; + int surpriseN = 0; + + for (Integer[] integers : c) { + + if (checkSurprising(integers)) { + surpriseN++; + } + } + + return surpriseN; + + } + + private ArrayList createMissingSurprices(int missing, int p, + ArrayList s, Boolean forced) { + + for (int i = 0; i < s.size(); i++) { + + if (missing > 0) { + + if (!checkP(p, s.get(i)) || forced) { + + if (s.get(i)[1] > 0) { + + if ((s.get(i)[0] < p && s.get(i)[0] + 1 >= p) || forced) { + + Integer[] newTripleta = (Integer[])s.get(i).clone(); + newTripleta[0] = newTripleta[0]+1; + newTripleta[1] = newTripleta[1]-1; + + if (validTripleta(newTripleta)) { + s.set(i, newTripleta); + missing--; + } + } + } + + } + } + } + return s; + } + + private Boolean validTripleta(Integer[] scores) { + Boolean found = true; + + int a = scores[0] - scores[1]; + int b = scores[0] - scores[2]; + int c = scores[1] - scores[2]; + + if (a > 2 || b > 2 || c > 2) { + found = false; + } + return found; + } + + private Boolean checkP(int p, Integer[] scores) { + + Boolean found = false; + + for (Integer integer : scores) { + if (integer >= p) { + found = true; + break; + } + } + + return found; + } + + private Integer countP(int p, ArrayList scores) { + + Integer total = 0; + + for (Integer[] integer : scores) { + for (Integer integer2 : integer) { + if (integer2 >= p) { + total++; + break; + } + } + } + + return total; + } + +} +" +A22910,"import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; + + +public class Dance { + + static int getMaxGooglers(int N,int S, int p, int[] t) { + int count=0; + int surpriseCount=0; + + int avg=p*3; + for(int i=0;i=avg) + count++; + + else */ + if(t[i]>=p) { + if(t[i]>=avg-2) + + count++; + + else if(surpriseCount=avg-4) { + count++; + surpriseCount++; + } + } + } + } + return count; + } + public static void main(String args[]) { + try { + BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(""c:\\gcj\\B\\B-large.in""))); + String line=br.readLine(); + PrintStream ps=new PrintStream(""c:\\gcj\\B\\B-large.out""); + + int n=Integer.parseInt(line); + for(int i=1;i<=n;i++) { + + line=br.readLine(); + String[] nums=line.split("" ""); + int N=Integer.parseInt(nums[0]); + int S=Integer.parseInt(nums[1]); + int P=Integer.parseInt(nums[2]); + int t[]=new int[N]; + for(int j=0;j mCache = new HashSet(); + + public Dance(int[] totalScores, int maxSurprise, int p) { + mTotalScores = totalScores; + mMaxSurprise = maxSurprise; + mP = p; + recurse(0, 0, 0); + } + + public int getAnswer() { + return mAnswer; + } + + private void recurse(int index, int surprises, int qualified) { + String idx = index + ""_"" + surprises + ""_"" + qualified; + if (mCache.contains(idx)) { + return; + } + else { + mCache.add(idx); + } + if (surprises > mMaxSurprise) return; + if (index >= mTotalScores.length) { + if (qualified > mAnswer) { + mAnswer = qualified; + } + return; + } + + Pair[] pos = scoreVariations(mTotalScores[index]); + for (int i = 0; i < pos.length; i++) { + int localSurprises = surprises; + int localQualified = qualified; + if (pos[i].surprise) localSurprises++; + if (pos[i].max >= mP) localQualified++; + recurse(index + 1, localSurprises, localQualified); + } + } + + // Get possible score variations + public static Pair[] scoreVariations(int score) { + HashSet set = new HashSet(); + + int fStart = score / 3; + int fEnd = Math.min(10, fStart + 3); + + for (int i = fStart; i <= fEnd; i++) { + int sStart = i; + int sEnd = Math.min(10, i + 2); + for (int j = sStart; j <= sEnd; j++) { + int k = score - i - j; + + if (Math.abs(i - k) > 2 || Math.abs(j - k) > 2 || k > 10 || k < 0) { + // Invalid case + continue; + } + + boolean surprise = Math.abs(i - k) == 2 || Math.abs(j - k) == 2 || Math.abs(i - j) == 2; + int max = Math.max(i, Math.max(j, k)); + set.add(new Pair(max, surprise)); + } + } + + return set.toArray(new Pair[0]); + } + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int num = in.nextInt(); + + for (int i = 0; i < num; i++) { + int num2 = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] scores = new int[num2]; + for (int j = 0; j < num2; j++) { + scores[j] = in.nextInt(); + } + Dance d = new Dance(scores, s, p); + System.out.println(""Case #"" + (i + 1) + "": "" + d.getAnswer()); + } + } + +} +" +A21622,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package test2; + +/** + * + * @author Student + */ +public class Score { + + private int i; + private int j; + private int k; + private boolean surp; + + public Score(int i, int j, int k,boolean surp) { + this.i = i; + this.j = j; + this.k = k; + this.surp = surp; + } + + public boolean isValid(){ + return (i<=10&&j<=10&&k<=10)&&(i>=0&&j>=0&&k>=0); + } + + public boolean isSurprising(){ + return surp; + } + + public boolean isbetter(int x){ + return i>=x||j>=x||k>=x; + } + + public String toString(){ + return ""(""+i+"",""+j+"",""+k+"")""; + } +} +" +A20782,"package codejam; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StreamTokenizer; + +public class DancingWithTheGooglers { + + private StreamTokenizer in; + private PrintWriter out; + + public static void main (String[] args) throws IOException { + new DancingWithTheGooglers().soilve(); + } + + int nextInt () throws IOException { + in.nextToken(); + return (int)in.nval; + } + + void soilve () throws IOException { + in = new StreamTokenizer(new BufferedReader(new FileReader(""./src/codejam/input.txt""))); + out = new PrintWriter(new FileWriter(""./src/codejam/output.txt"")); + + int t = nextInt(); + for (int i = 0; i < t; i++) { + int n = nextInt(); + int s = nextInt(); + int p = nextInt(); + + int max = 0; + + for (int j = 0; j= p) { + max++; + } else if (((a / 3) + 1 == p) && (s > 0)) { + max++; + s--; + + } + } else if (a % 3 == 2) { + if ((a + 1) / 3 >= p) { + max++; + } else if ((((a + 1) / 3) + 1 == p) && (s > 0)) { + max++; + s--; + } + } else if (a % 3 == 1) { + if ((a + 2) / 3 >= p) { + max++; + } + } + } + + out.println(""Case #"" + (i + 1) + "": "" + max); + } + + out.flush(); + } + +} +" +A22196,"import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; +import static java.lang.Math.abs; + +public class B { + + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(new FileReader(""input.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""output"")); + + int T = in.nextInt(); + + int n, s, p; + for (int i = 1; i <= T; i++) { + // read input + n = in.nextInt(); s = in.nextInt(); p = in.nextInt(); + int[] googlers = new int[n]; + for (int j = 0; j < n; j++) + googlers[j] = in.nextInt(); + + // solve + int ans = solve(n, s, p, googlers); + bw.write(""Case #"" + i + "": "" + ans); + bw.newLine(); + } + + bw.close(); + System.out.println(""end""); + } + + private static int solve(int n, int s, int p, int[] googlers) throws IOException { + boolean[] surp = new boolean[n]; + boolean[] reach = new boolean[n]; + boolean[] both = new boolean[n]; + + for (int T = 0; T < n; T++) + for (int i = 0; i <= 10; i++) + for (int j = i; j <= i+2 && j <= 10; j++) + for (int k = j; k <= j+2 && j <= 10; k++) + if (i+j+k == googlers[T] && check(i, j, k)) + { + boolean a = isSurprising(i, j, k), b = reached(i, j, k, p); + if(!surp[T]) surp[T] = a && !b; + if(!reach[T]) reach[T] = b && !a; + if(!both[T]) both[T] = a && b; + } + + int max = findMax(n, s, p, surp, reach, both); + + return max; + } + + private static int findMax(int n, int s, int p, boolean[] surp, boolean[] reach, boolean[] both) { + + int max = 0; + for(int i = 0; i < n; i++) + if(both[i] || reach[i])max++; + + int ss = 0; + for(int i = 0; i < n; i++) + if(surp[i] || both[i]) ss++; + + if(ss == s) + return max; + else // ss > s + { + for(int i = 0; i < n; i++) + if(surp[i] || (both[i] && reach[i])) ss--; + + if(ss <= s) + return max; + else + return max-(ss-s); + + } + } + + private static boolean reached(int i, int j, int k, int p) { + return Math.max(i, Math.max(j, k)) >= p; + } + + private static boolean isSurprising(int i, int j, int k) { + return abs(i - j) == 2 || abs(j - k) == 2 || abs(i - k) == 2; + } + + private static boolean check(int i, int j, int k) { + return abs(i - j) <= 2 && abs(j - k) <= 2 && abs(i - k) <= 2; + } +} +" +A20068," +package codejam; + +import java.io.*; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +public class B { + static String str = ""C:\\carl\\fbl.txt""; + static String text = """"; + + static int N, S, P,T; + static int[][] list; + + + public static void main(String[] args) { + + try { + int caser = 1; + int count = 0; + File file = new File(str); + BufferedReader br = new BufferedReader(new FileReader(file)); + PrintWriter outer = new PrintWriter(new FileWriter(""C:\\carl\\fblout.txt"")); + + + while((text = br.readLine()) != null) { + StringTokenizer st = new StringTokenizer(text); + + if(count == 0) { + T = Integer.parseInt(st.nextToken()); + System.out.println(T); + count++; + } else { + /* each subsequent line */ + N = Integer.parseInt(st.nextToken()); + list = new int[N][3]; + S = Integer.parseInt(st.nextToken()); + P = Integer.parseInt(st.nextToken()); + //System.out.println(N + "" :: "" + S + "" :: "" + P); + int c = 0; + while(st.hasMoreTokens()) { + float temp = Float.parseFloat(st.nextToken()); + //double a = temp/3.0; + list[c][0] = Math.round(temp/3.0f); + list[c][1] = Math.round(temp/3.0f); + list[c][2] = (int)(temp - (2 * Math.round(temp/3.0f))); + //System.out.println(temp + "" :: "" + list[c][0] + "" "" + list[c][1] + "" "" + list[c][2]); + c++; + } + + + /* calculations */ + int counter = 0; + for(int[] i : list) { + + if(i[0] >= P || i[1] >= P || i[2] >= P) { + counter++; + } else { + if(S > 0 ) { + double a = (i[0]+i[1]+i[2]) - P; + //System.out.println(""a : "" + a); + double b = a/2.0; + + if((P - b) <= 2 && a > 0) { + //System.out.println(""special "" + S + "" : "" + (P - b) + "" :: pass""); + counter++; + S--; + } else { + //System.out.println(""special "" + S + "" : "" + (P - b) + "" :: fail""); + } + + } + } + + + } + //System.out.println(""""); + outer.println(""Case #"" + count + "": "" + counter); + + count++; + + //caser++; + } + + + } + outer.close(); + + } catch(IOException ex) { + System.out.println(""Error with IO you foooool""); + } catch(Exception ex) { + System.out.println(""Generic Error. Noob.""); + ex.printStackTrace(); + } + } + +} +" +A20137,"import java.io.*; +import java.util.Scanner; + +class dancing +{ + public static void main(String Args[]) throws Exception + { + Scanner s=new Scanner(new FileReader(""inputBl.in"")); + BufferedWriter b=new BufferedWriter(new FileWriter(""outputBl.txt"")); + int T,S,N,p,total,score,max; + T=s.nextInt(); + for(int I=0;I=p) + { + total++; + } + else if(max==p-1&&S>0&&score!=0) + { + S--; + total++; + } + break; + + + case 1:max=score/3+1; + if(max>=p) + { + total++; + } + break; + + + case 2:max=score/3+1; + if(max>=p) + { + total++; + } + else if(max==p-1&&S>0) + { + S--; + total++; + } + break; + } + } + b.write(""Case #""+(I+1)+"": ""+total); + if(I!=T-1) + b.write(""\n""); + + } + s.close(); + b.close(); + } +} + +" +A20359,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package gcj2012.qualification_round; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author langlv + */ +public class Dancing { + + public static void main(String[] args) throws Exception { +// Scanner sc = new Scanner(System.in); +// PrintWriter pw = new PrintWriter(System.out); + Scanner sc = new Scanner(new FileReader(""C:\\B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""C:\\B-large.out"")); + try { + int ntest = Integer.parseInt(sc.nextLine()); + + for (int test = 1; test <= ntest; ++test) { + int res = 0; + + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + + int si = 0; + for (int i = 0; i < n; i++) { + int t = sc.nextInt(); + if (p == 0) { + res++; + } else { + if (t > 0) { + if ((t / 3) == p - 2 && (t % 3) == 2 && si < s) { + si++; + res++; + } + if ((t / 3) == (p - 1) && (t % 3) == 0 && si < s) { + si++; + res++; + } + if (t / 3 >= p || ((t / 3) == (p - 1) && (t % 3) >= 1)) { + res++; + } + } + } + } + + pw.print(""Case #"" + test + "": ""); + pw.print(res); + pw.println(); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + e.printStackTrace(); + } finally { + pw.close(); + sc.close(); + } + } +} +" +A20565,"package b; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +public class Dancing { + List ss = new ArrayList<>(); + int n; + int min; + int sp; + int cnt = 0; + + public Dancing(int min, int sp, int[] sc) { + this.min = min; + this.n = sc.length; + this.sp = sp; + for(int s : sc) { + ss.add(s); + } + } + + public static void main(String[] args) throws IOException { +// System.out.println(new Dancing(5, 1, new int[] {15, 13, 11}).solve()); +// System.out.println(new Dancing(8, 0, new int[] {23, 22, 21}).solve()); +// System.out.println(new Dancing(1, 1, new int[] {8, 0}).solve()); +// System.out.println(new Dancing(8, 2, new int[] {29, 20, 8, 18, 18, 21}).solve()); + + BufferedReader br = new BufferedReader(new FileReader(""src/b/B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""src/b/out"")); + + int row = Integer.parseInt(br.readLine()); + System.out.println(""ROW : "" + row); + + for(int i=0; i it = ss.iterator(); it.hasNext();) { + int s = it.next(); + int rest = s - min; + if (rest < 0) continue; + if (rest /2 >= Math.max(min-1,0)) { + cnt++; + it.remove(); + } + } + + Collections.sort(ss, new Comparator() { + public int compare(Integer o1, Integer o2) { + return o2- o1; + } + }); + + for(Iterator it = ss.iterator(); it.hasNext();) { + int s = it.next(); + int rest = s - min; + if (rest < 0) continue; + if (rest / 2 >= Math.max(min-2, 0) && sp > 0) { + cnt++; + sp--; + it.remove(); + } + } + + return cnt; + } +} +" +A21525,"import java.util.*; +import java.io.*; + +public class B { + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(args[0])); + in.readLine(); + + String[] segments; + int[] scores; + int numCase = 0; + while (in.ready()) { + segments = in.readLine().split("" ""); + scores = new int[segments.length - 3]; + for (int i = 0; i < scores.length; ++i) { + scores[i] = Integer.parseInt(segments[i + 3]); + } + solve(++numCase, Integer.parseInt(segments[1]), Integer.parseInt(segments[2]), scores); + } + } + + private static void solve(int caseNum, int s, int p, int[] scores) { + int max = 0; + + if (p == 0) { + max = scores.length; + } else if (p == 1) { + for (int i = 0; i < scores.length; ++i) { + if (scores[i] >= 1) { + ++max; + } + } + } else { + int limit1 = (p - 2) * 3 + 2; + int limit2 = limit1 + 1; + + int needS = 0; + + int score; + for (int i = 0; i < scores.length; ++i) { + score = scores[i]; + if (score < limit1) { + continue; + } + + if (score <= limit2) { + ++ needS; + continue; + } + + ++max; + } + + max += Math.min(needS, s); + } + + System.out.printf(""Case #%d: %d\n"", caseNum, max); + } +}" +A22089,"package test; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.io.FileWriter; +import java.io.IOException; +import java.math.*; + +public class case2 { + + public static void main(String[] args){ + try { + FileReader is_reader= new FileReader(""C:\\Users\\Paul\\Downloads\\B-large.in""); + BufferedReader reader = new BufferedReader(is_reader); + FileWriter out_writer = new FileWriter(""c:\\output.txt""); + int T = common.readInt(reader); + int result; + String sResult = """"; + + for (int i=0;i=L1) + result++; + else if (input[j+3]=L2&&S>0){ + result++; + S--; + } + } + sResult+=""Case #"" + (i+1)+"": ""+result+""\n""; + + } + System.out.print(sResult); + out_writer.write(sResult); + out_writer.flush(); + } + catch (Exception e){ + + + } + + } +} +" +A22978,"import java.util.HashMap; +import java.util.Map; + +public class ProblemB { + public static void main(String argv[]) + { + IOSystem ioSystem = new IOSystem(""problem/B-large""); +//// IOSystem ioSystem = new IOSystem(""problem/A-small-attempt2""); +// IOSystem ioSystem = new IOSystem(""problem/test""); + + ioSystem.nextLong(); + while(ioSystem.hasNext()) + { + int N = ioSystem.nextInt(); + int S = ioSystem.nextInt(); + int P = ioSystem.nextInt(); + + int koeru = 0; + int supKoeru = 0; + + for(int i=0;i= P) + { + koeru++; + } + else if(t/3 + 1>= P) + { + supKoeru++; + } + } + else if(t%3 == 2) + { + if(t/3 + 1>= P) + { + koeru++; + } + else if(t/3 + 2>= P) + { + supKoeru++; + } + } + else + { + if(t/3 + 1 >= P) + { + koeru++; + } + } + } + + System.out.println(N+"",""+S+"",""+P+"",""+koeru+"",""+supKoeru); + + if(supKoeru > S) + { + koeru += S; + } + else + { + koeru += supKoeru; + } + + + ioSystem.appendAnswer(koeru); + } + + ioSystem.output(); + } +} + + +" +A22728,"package qualr2012.problemB; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collections; +import java.util.LinkedList; +import java.util.TreeSet; +import java.util.logging.Logger; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.ArrayUtils; +import org.springframework.util.Assert; + +public class DancingWithGooglers { + + static Logger log = Logger.getLogger(DancingWithGooglers.class.getName()); + final static String inputFileName = ""B-large.in""; + final static String outputFileName = ""B-large.out""; + + public static void main(String[] args) throws IOException { + String pkgName = DancingWithGooglers.class.getPackage().getName().replaceAll(""\\."", ""/""); + String inputFile = ""src/main/java/"" + pkgName + ""/"" + inputFileName; + String outputFile = ""target/"" + pkgName + ""/"" + outputFileName; + FileUtils.forceMkdir(new File(""target/"" + pkgName)); + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + PrintWriter writer = new PrintWriter(outputFile); + int numCase = Integer.parseInt(reader.readLine()); + + int i, j; + String[] str; + + int[] maxNoSurprise = new int [31]; + int[] maxSurprise = new int [31]; + + for (i = 0; i < 31; ++i) { + maxNoSurprise[i] = (int)Math.ceil(i/3.0); + maxSurprise[i] = (int)Math.ceil(i/3.0 + 0.5); + } + maxSurprise[0] = 0; + + for(int _case = 1; _case <= numCase; ++_case) { + LinkedList t_LL = new LinkedList(); + Integer[] t = null; + str = reader.readLine().split("" ""); + + + int N, S, p; + N = Integer.parseInt(str[0]); + S = Integer.parseInt(str[1]); + p = Integer.parseInt(str[2]); + + for (i = 3; i < str.length; ++i) { + t_LL.add(Integer.parseInt(str[i])); + } + Collections.sort(t_LL); + + t = t_LL.toArray(new Integer[0]); + + Assert.isTrue(t.length == N); + + // move i to the first no-surprise triplet which has max score >= p + for (i = 0; i < t.length; ++i) { + if (maxNoSurprise[t[i]] >= p) { break; } + } + + // for each available S, use it to maximize the number of Googlers to the left of i + for (; i >= 1 && S > 0 && maxSurprise[t[i-1]] >= p; i--, S--) { + + } + + int answer = t.length - i; + log.info(answer+""""); + + writer.println(""Case #"" + _case + "": "" + answer); + } + + reader.close(); + writer.close(); + } + +} +" +A22886,"import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.Map; + + +public class Jam { + + private static String in = ""in""; + + public static void main(String[] args) throws FileNotFoundException, InterruptedException { + parse(args); + Parser parser = new Parser(in); + + //Map tasks = new HashMap(); + + while (parser.hasNext()) { + Case c = parser.nextCase(); + //Thread task = new Thread(c); + //task.start(); + //tasks.put(task, c); + c.run(); + System.out.println(c); + } + + /*for (Thread task : tasks.keySet()) { + Case c = tasks.get(task); + task.join(); + System.out.println(c); + }*/ + } + + private static void parse(String[] args) { + if (args.length > 0) + in = args[0]; + } + +}" +A21635,"public class CodeJamUtils { + /** + * Makes sure that the line separator written by BufferedWriter is a single + * newline character + */ + public static void initLineEndings() { + System.setProperty(""line.separator"", ""\n""); + } +} +" +A21510,"import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class GoogleDancers { + + public static void main(String args[]) throws IOException{ + Scanner scan = new Scanner(System.in); + PrintWriter print = new PrintWriter(new FileWriter(""GoogleDancers.out"")); + Integer cases = Integer.parseInt(scan.nextLine()); + for(int i=0; i= threshHoldScore){ + numAccepted++; + }else if(topScore+1 >= threshHoldScore && surprises > 0){ + numAccepted++; + surprises--; + } + + } + + if(totalScore%3==1){ + topScore++; + if(topScore >= threshHoldScore){ + numAccepted++; + } + } + + if(totalScore %3 == 2){ + topScore++; + if(topScore >= threshHoldScore){ + numAccepted++; + }else if(topScore+1 >= threshHoldScore && surprises > 0){ + numAccepted++; + surprises--; + } + } + } + print.println(""Case #"" + (i+1) + "": "" + numAccepted ); + System.out.println(""Case #"" + (i+1) + "": "" + numAccepted); + print.flush(); + //print.close(); + } + print.close(); + } +} +" +A20461,"import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Arrays; + + +public class Dancing { + + + public static void main(String[] args) throws IOException { + RandomAccessFile in = new RandomAccessFile(new File(""B-large.in""), ""r""); + RandomAccessFile out = new RandomAccessFile(new File(""DanceOut.out""),""rw""); + int num = Integer.parseInt(in.readLine()); + for (int j = 1; j <= num; j++){ + int count = 0; + String[] numbers = in.readLine().split("" ""); + int gs = Integer.parseInt(numbers[0]); + int special = Integer.parseInt(numbers[1]); + int over = Integer.parseInt(numbers[2]); + int[] arr = new int[gs]; + for (int i = 3; i < numbers.length; i++) { + arr[i-3] = Integer.parseInt(numbers[i]); + } + Arrays.sort(arr); + for (int i = 0; i < gs; i++) { + int base = arr[i]/3; + switch(arr[i] % 3) { + case 0: + if (special > 0 && base > 0 && (base+1) >= over) { + count++; + special--; + } + else if(base >= over) { + count++; + } + + break; + case 1: + if(base >= over || (base+1) >= over) { + count++; + } + break; + + case 2: + if (special > 0 && (base + 2) >= over) { + count++; + special--; + } + else if ((base + 1) >= over || base >= over) count++; + + break; + } + } + out.writeBytes(""Case #"" + j + "": "" + count + ""\n""); + } + } + +} +" +A21300,"/** + * Written By Kylin + * Last modified: 2012-4-15 + * State: Pending + */ +package me.kylin.gcj.c2012Q; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class DancingWithTheGooglers { + + String file; + + Scanner sc; + + PrintWriter pr; + + int caseNO; + + boolean showDebug; + + void out(Object str) { + str = ""Case #"" + caseNO + "": "" + str; + System.out.println(str); + if (pr != null) + pr.println(str); + } + + void outNoPre(Object str) { + System.out.println(str); + if (pr != null) + pr.println(str); + } + + void debug(Object str) { + if (showDebug) + System.out.printf(""DEBUG - Case #%d: %s\n"", caseNO, str); + } + + void work() { + if (file != null) { + try { + sc = new Scanner(new FileInputStream(new File(file + "".in""))); + pr = new PrintWriter(new File(file + "".out"")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.exit(1); + } + } else { + sc = new Scanner(System.in); + } + int tc = sc.nextInt(); + sc.nextLine(); + for (caseNO = 1; caseNO <= tc; caseNO++) { + solveACase(); + if (pr != null) + pr.flush(); + } + if (pr != null) + pr.close(); + } + + static String generateFilename(String x, int scale, int t) { + String fn = x.toUpperCase(); + if (scale == 0) + return ""sample""; + if (scale == 1) + fn += ""-small""; + if (scale == 2) + fn += ""-large""; + if (t < 0) + return fn + ""-practice""; + if (t > 0) { + if (scale == 1) + fn += ""-attempt"" + (t - 1); + return fn; + } + return fn; + } + + public static void main(String[] args) { + DancingWithTheGooglers cls = new DancingWithTheGooglers(); + String base = ""data/2012Q/""; + cls.file = base + generateFilename(""B"", 2, 1); + cls.showDebug = true; + cls.work(); + } + + void solveACase() { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int max = 0; + int n_least = 3 * p - 2; + int s_least = n_least - 2; + for (int i = 0; i < n; i++) { + int t = sc.nextInt(); + if (t >= n_least) { + max += 1; + } + else if (p >= 2 && t >= s_least && s > 0){ + max += 1; + s -= 1; + } + } + out(max); + } +} +" +A22152,"package codejam2012; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Hashtable; +import java.util.Scanner; + +public class DancingWithGooglers { + + public static void main(String[] args) throws Exception { + + Scanner scanner = new Scanner(new BufferedReader(new FileReader( + ""A-large-practice.in.txt""))); + Output out = new Output(""B.out""); + + int T = scanner.nextInt(); + + for (int t = 1; t <= T; t++) { + + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + + int[] scores = new int[N]; + + for (int i = 0; i < N; i++) { + scores[i] = scanner.nextInt(); + } + + Arrays.sort(scores); + + int count = 0; + int num_s = 0; + + int[] roundUp = { 0, 2, 1 }; + int[] makeUp = { 1, 0, 1 }; + int[] makeDown = { 1, 1, 0 }; + + for (int i = scores.length - 1; i >= 0; i--) { + + int score = scores[i]; + int mod = score % 3; + + int hi = (score + roundUp[mod]) / 3; + int low = score / 3 - makeDown[mod]; + + if (hi >= p) { + count++; + } else if (num_s < S && (hi + makeUp[mod]) >= p && low >= 0) { + count++; + num_s++; + } else { + //break; + } + } + + out.format(""Case #%d: %d\n"", t, count); + } + + scanner.close(); + out.close(); + } + + static class Output { + + PrintWriter pw; + + public Output(String filename) throws IOException { + pw = new PrintWriter(new BufferedWriter(new FileWriter(filename))); + } + + public void print(String s) { + pw.print(s); + System.out.print(s); + } + + public void println(String s) { + pw.println(s); + System.out.println(s); + } + + public void format(String format, Object... args) { + pw.format(format, args); + System.out.format(format, args); + } + + public void close() { + pw.close(); + } + } + +} +" +A20803,"package be.mokarea.gcj.common; + +import java.io.FileWriter; +import java.io.PrintWriter; +import java.io.Writer; + + +public abstract class GoogleCodeJamBase { + protected abstract Transformation createTransformation(TestCaseReader testCaseReader, PrintWriter outputWriter) throws Exception; + protected abstract String getOutputFileName() throws Exception; + protected abstract TestCaseReader getTestCaseReader() throws Exception; + + public void execute() { + try { + PrintWriter outputWriter = null; + try { + outputWriter = new PrintWriter(new FileWriter(getOutputFileName())); + Transformation transformation = createTransformation(getTestCaseReader(),outputWriter); + transformation.transformAll(); + outputWriter.flush(); + } finally { + closeQuietly(outputWriter); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + private void closeQuietly(Writer outputWriter) { + if (outputWriter != null) { + try { + outputWriter.close(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } +} +" +A20867,"import java.util.ArrayList; +import java.util.Scanner; + +public class B { + + public static void output(int T, int count) { + System.out.print(String.format(""Case #%d: "", T)); + System.out.print(count); + System.out.println(); + } + + public static int getScores(int total, int p) { + int first = p; + int second = p; + int third = p; + + if (first + second + third > total) { + second--; + } else { + return 0; + } + + if (first + second + third > total) { + third--; + } else { + return 0; + } + + if (first + second + third > total) { + second--; + } else { + return 0; + } + + if (first + second + third > total) { + third--; + } else { + return 1; + } + + if (first + second + third > total) { + return -1; + } else { + return 1; + } + + } + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + in.nextLine(); + + for (int i=0; i t = new ArrayList(); + + for (int j=0; j= p) { + t.add(tmp); + } + } + + for (int j=0; j 0) { + count++; + S--; + } + } + + output(i + 1, count); + } + } +} +" +A20280,"package common; + +public interface ISolver { + + String solve(String problem); + + void addCase(String problem, String answer); + +} +" +A20545,"package dancingwiththegooglers; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * + * @author Masilo + */ +public class DancingWithTheGooglers { + + public static void main(String[] args) { + Scanner inputStream = null; + PrintWriter outputStream = null; + + try{ + inputStream = new Scanner(new FileInputStream(""input.txt"")); + outputStream = new PrintWriter(new FileOutputStream(""output.txt"")); + + int t = Integer.parseInt(inputStream.nextLine()); + String outputLine = """"; + String[] inputNumbers = null; + int number = 0, mod = 0, p = 0; + int numberOfBestResults = 0, NumberOfSurprisingResults = 0; + + for (int i = 1; i<=t;i++){ + inputNumbers = inputStream.nextLine().split("" ""); + NumberOfSurprisingResults = Integer.parseInt(inputNumbers[1]); + numberOfBestResults = 0; + outputLine = ""Case #""+i+"": ""; + + for (int j = 3;j= p){ + numberOfBestResults++; + continue; + } + + if (mod==1 && number+1==p){ + numberOfBestResults++; + continue; + } + else if(mod==2 && NumberOfSurprisingResults==0 && number+1==p){ + numberOfBestResults++; + continue; + } + + if (NumberOfSurprisingResults > 0 && (number>=1 || mod >0)){ + if (number+mod == p || number+1==p){ + numberOfBestResults++; + NumberOfSurprisingResults--; + continue; + } + } + + } + + outputLine += """"+numberOfBestResults; + outputStream.println(outputLine); + } + + outputStream.close(); + inputStream.close(); + + } + catch(Exception e){ + System.out.println(""file input.txt was not found""); + } + } +} +" +A23070,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.StringTokenizer; + + +public class dancers { + + /** + * @param args + */ + public static void main(String[] args) throws IOException + { + // TODO Auto-generated method stub + BufferedReader br = new BufferedReader(new FileReader(""problem.in"")); + int t = Integer.parseInt(br.readLine()); + for (int i = 1; i <= t; i++) + { + String line = br.readLine(); + StringTokenizer st = new StringTokenizer(line, "" ""); + int len = Integer.parseInt(st.nextToken()); + int surp = Integer.parseInt(st.nextToken()); + int want = Integer.parseInt(st.nextToken()); + int count = 0; + int[] vals = new int[len]; + for (int j = 0; j < len; j++) + { + vals[j] = Integer.parseInt(st.nextToken()); + } + for (int k: vals) + { + k -= want; + if (k <0) + continue; + else + { + if (k >= 2 * want - 2) + { + count++; + } + else if (k >= 2 * want - 4) + { + if (surp == 0) + continue; + else + { + surp--; + count++; + } + } + } + } + System.out.println(""Case #"" + i + "": "" + count); + + } + } + +} +" +A21080,"package test; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +public class DancingWithTheGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + + PrintWriter out = null; + BufferedReader in = null; + String test; + + try { + + out = new PrintWriter(args[1]); + in = new BufferedReader(new FileReader(args[0]), 1024); + + // number of test cases + in.readLine(); + + for (int i=1; (test=in.readLine())!=null; i++) { + String parameters[] = test.split("" ""); + int googlers = 0; + int surprising = 0; + int totalSurprising = Integer.parseInt(parameters[1]); + int minScore = Integer.parseInt(parameters[2]); + int minTotal = minScore * 3; + for (int j=3; j=minTotal-2) { + googlers++; + } + else if (score>=minTotal-4&&surprising= p) { + y[i]++; + } else if (((tp[j] + 4) / 3) >= p & s > 0&tp[j]>=2) { + y[i]++; + s--; + } + } + + } + for (int i = 0; i < t; i++) { + System.out.println(""Case #""+(i+1)+"": ""+y[i]); + } + + } +} +" +A21151,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +/** + * GoogleDancers Class + * + * @author ndiwan + * + */ +public class GoogleDancers { + + /** + * Main method for calculating best results of Google dancers + * + * @param args + */ + public static void main(String[] args) { + + int testCases; + int googlers; + int surprising; + int cutOff; + int[] marks; + int bestResult = 0; + + BufferedWriter bw = null; + Scanner scan = null; + + try { + + bw = new BufferedWriter(new FileWriter(""Output.txt"")); + scan = new Scanner(new File(""Input.txt"")); + + testCases = scan.nextInt(); + + for (int i = 1; i <= testCases; i++) { + + googlers = scan.nextInt(); + surprising = scan.nextInt(); + cutOff = scan.nextInt(); + bestResult = 0; + + marks = new int[googlers]; + + // storing marks for googlers + for (int j = 0; j < googlers; j++) { + marks[j] = scan.nextInt(); + } + + // processing marks in triplets + for (int k = 0; k < marks.length; k++) { + + int div = marks[k] / 3; + int rem = marks[k] % 3; + + if (div != 0) { + if (div >= cutOff) { + ++bestResult; + } else { + if (cutOff - div == 1) { + if (rem >= 1) { + ++bestResult; + } else if (surprising > 0) { + ++bestResult; + --surprising; + } + } + if (cutOff - div == 2 && rem > 1 && surprising > 0) { + ++bestResult; + --surprising; + } + } + } + else { + if (cutOff == 0 || rem >= cutOff){ + ++bestResult; + } + else if (rem >= cutOff && surprising > 0) { + ++bestResult; + --surprising; + } + } + } + + bw.write(""Case #"" + i + "": "" + bestResult + ""\n""); + } + + } catch (Exception e) { + System.out.println(""Exception "" + e); + e.printStackTrace(); + + } finally { + scan.close(); + try { + bw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +}" +A20151," +public class Triplet { + + private int fFirst; + private int fSecond; + private int fThird; + + public Triplet( int aFirst, int aSecond, int aThird ) { + fFirst = aFirst; + fSecond = aSecond; + fThird = aThird; + } + + public boolean isSurprising() { + if( Math.abs( fFirst - fSecond ) >= 2 ) { + return true; + } + if( Math.abs( fFirst - fThird ) >= 2 ) { + return true; + } + if( Math.abs( fSecond - fThird ) >= 2 ) { + return true; + } + return false; + } + + public int getBestResult() { + return Math.max( Math.max( fFirst, fSecond), fThird ); + } + + +} +" +A20902,"/** + * + */ +package com.sathish.codejam; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +/** + * @author satselva + * + */ +public class Dancers +{ + + public void processInput(String fileName) throws IOException + { + FileInputStream fis = new FileInputStream(fileName); + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + + PrintWriter pw = new PrintWriter(new File(""C:/downloads/output_problem_large_2.txt"")); + String input = br.readLine(); + int testCases = Integer.valueOf(input); + + + for(int i=1; i<=testCases; i++) + { + input = br.readLine(); + String[] samples = input.split("" ""); + int googlers = Integer.valueOf(samples[0]); + int surprising = Integer.valueOf(samples[1]); + int pointsReq = Integer.valueOf(samples[2]); + + int surpriseCnt = 0; + int normalCnt = 0; + int surpriseThreshold = (pointsReq - 1) * 3; + + for(int j=3; j surpriseThreshold) + { + normalCnt++; + } + else if(totalScores > 0 && totalScores >= (surpriseThreshold - 1)) + { + surpriseCnt++; + } + } + int ans = normalCnt + Math.min(surpriseCnt, surprising); + pw.println(String.format(""Case #%d: %d"", i, ans)); + } + pw.flush(); + pw.close(); + } + + + public static void main(String[] args) throws IOException + { + Dancers dancers = new Dancers(); + dancers.processInput(""C:/downloads/B-large.in""); + } + +} +" +A20698,"import java.util.*; +public class googlers { + public static void main(String[] args){ + int t; + Scanner s = new Scanner(System.in); + t=s.nextInt(); + for(int k=0;k3*p-3) count++; + else{ + if(S>0) { + count++; + S--; + } + } + } + System.out.println(""Case #""+(k+1)+"": ""+count); + } + } +} +" +A22597," +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws FileNotFoundException { + Scanner in = new Scanner(new File(B.class.getSimpleName() + "".in"")); + PrintWriter out = new PrintWriter(new File(B.class.getSimpleName() + "".out"")); + int T = in.nextInt(); + for (int i = 0; i < T; i++) { + String s = ""Case #"" + (i + 1) + "": "" + new B().solve(in); + out.println(s); + System.out.println(s); + } + out.close(); + } + + private String solve(Scanner in) { + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = in.nextInt(); + } + int k = 0; + int rem = s; + int res = 0; + for (int i = 0; i < n; i++) { + if (t[i] >= 2) k++; + int mx = (t[i] + 2) / 3; + if (mx >= p) { + res++; + } else if (rem > 0 && t[i] >= 2) { + mx = (t[i] + 4) / 3; + if (mx >= p) { + res++; + rem--; + } + } + } + if (k < s) throw new RuntimeException(""!!!""); + return """" + res; + } +}" +A21136,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + + +public class Main { + private static Map mapa; + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(Thread.currentThread().getContextClassLoader().getResourceAsStream(""B-large.in"")); + BufferedWriter bw = new BufferedWriter(new FileWriter(""C:\\Users\\Erich\\Desktop\\B-large.out"")); + int qtd = sc.nextInt(); + for(int j=0;j=limite){ + total++; + }else{ + switch(tripla%3){ + + case 1: + if(divisao+1>=limite){ + total++; + } + break; + case 2: + if(divisao+1>=limite){ + total++; + }else{ + if(surprising>0 && divisao+2>=limite){ + surprising--;total++; + } + } + break; + case 0: + if(divisao+1>=limite && surprising>0 && tripla>0){ + surprising--;total++; + } + break; + } + } + } + String saida = ""Case #""+(j+1)+"": ""+total+""\n""; + bw.write(saida); + } + bw.flush(); + bw.close(); + } + +} +" +A20206,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.HashMap; +import java.util.Scanner; + +//javac B.java && java B x.in x.out +public class B { + public static void main(String[] args) throws FileNotFoundException { + InputStream in = System.in; + if(args.length>0) + in = new FileInputStream(args[0]); + PrintStream out = System.out; + if(args.length>1) + out = new PrintStream(args[1]); + + Solver s = new Solver(new Scanner(in),out); + //Multiple case input + s.cases(); + //Single case input + //s.go(); + } +} + +class Solver { + Scanner in; + PrintStream out; + public Solver(Scanner scanner, PrintStream printStream) { + in = scanner; + out = printStream; + } + + public void cases() { + int numCases = in.nextInt(); + in.nextLine(); + for(int i=0;i=tN) + ans++; + else if(S>0 && t[i]>=tS) { + ans++; + S--; + } + } + + out.println(ans); + } +}" +A22853,"package qualification.common; + +import java.io.*; + +/** + * Created by IntelliJ IDEA. + * User: ofer + * Date: 14/04/12 + * Time: 17:21 + * To change this template use File | Settings | File Templates. + */ +public class InputReader { + + public static String[] getInputLines(String filename){ + String[] input = null; + File file = new File(filename); + try { + FileReader fr = new FileReader(file); + BufferedReader br = new BufferedReader(fr); + String line = br.readLine(); + int size = Integer.parseInt(line); + input = new String[size + 1]; + input[0] = line; + for (int i=0 ; i output ) { + FileWriter fstream = null; + BufferedWriter out = null; + try { + // Create file + fstream = new FileWriter( fileName ); + out = new BufferedWriter( fstream ); + int size = output.size(); + for ( int i = 1; i <= size; i++ ) { + final String outputStr = + new StringBuffer( ""Case #"" ).append( i ).append( "": "" ).append( output.get( i ) ).toString(); + out.write( outputStr ); + if ( i != size ) { + out.newLine(); + } + } + + } catch ( Exception e ) {//Catch exception if any + System.err.println( ""Error: "" + e.getMessage() ); + } finally { + //Close the output stream + + try { + if ( out != null ) { + out.close(); + } + if ( fstream != null ) { + fstream.close(); + } + } catch ( IOException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } +} +" +A22641,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + + +public class DancingGooglers { + public static void main(String[] args) throws IOException { + BufferedReader fInput = new BufferedReader(new FileReader(""res/inputB.in"")); + PrintWriter fOutput = new PrintWriter(new BufferedWriter(new FileWriter( + ""res/outputB.out""))); + new DancingGooglers().run(fInput, fOutput); + fOutput.close(); + } + + private void run(BufferedReader fInput, PrintWriter fOutput) throws IOException { + int T = Integer.parseInt(fInput.readLine()); + for (int i=0; i= p) { + count++; + continue; + } + + if (S == 0 || t<2 || t%3==1) continue; + + max = t%3==0? base+1 : base+2; + if (max >= p) { + count++; + S--; + } + } + + fOutput.println(""Case #"" + (i+1) + "": "" + count); + } + } +}" +A20598,"import java.util.Collection; +import java.util.ArrayList; +import java.util.Arrays; +import java.lang.Integer; +import java.io.*; +import java.util.Scanner; + +public class DancingWithTheGooglers{ + + private long inversions = 0; + + public static void main(String[] args) throws FileNotFoundException{ + String filename = args[0]; + DancingWithTheGooglers countInversions = new DancingWithTheGooglers(); + countInversions.readArray(filename); +// list = countInversions.sortAndCount(list); +// System.out.println(list); +// System.out.println(countInversions.inversions); + } + + private void readArray( String filename ) throws FileNotFoundException{ + ArrayList list = new ArrayList(); + File fFile = new File(filename); + Scanner scanner = new Scanner(new FileReader(fFile)); + try { + BufferedWriter out = new BufferedWriter(new FileWriter(""outfilename"")); + int k = Integer.valueOf(scanner.nextLine()); + for (int j=1; j<=k; ++j){ + String szoveg = scanner.nextLine(); + Object[] szamok =szoveg.split(""[^0-9]""); + ArrayList szamlista = new ArrayList(Arrays.asList(szamok)); + for (int i=0; i=(3*p-2)){ + szamlista.remove(i); + i--; + o++; + }else if(u= 0; K--) + { + if(vector[K] >= X && vector[K]>=P) + { + total++; + continue; + } + + if (vector[K] >= Y && S > 0 && vector[K] >= P) + { + total++; + S--; + continue; + } + if (vector[K] >= Z && S > 0 && vector[K] >= P) + { + total++; + S--; + continue; + } + + } + VectorString[u]=VectorString[u]+total; + chingon+=VectorString[u]+""\r\n""; + if(leer.hasNextLine()) + {u++;} + } + System.out.print(chingon); + escribir.print(chingon); + /*for(i=0; i= (3*p - 2)){ + result ++; + continue; + } + else if(slot < s){ + slot ++; + result ++; + } + } + + pw.println(""Case #"" + (i + 1) + "": "" + result); + } + pw.close(); + } + +} +" +A20150,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Collection; + + +public class Main { + + public static void main( String[] args ) { + + try { + BufferedReader reader = new BufferedReader( new FileReader( ""C:\\file.in"") ); + ArrayList results = new ArrayList(); + reader.readLine(); + String line = reader.readLine(); + int j = 0; + while( line != null ) { + j++; + ArrayList> tripletCollections = new ArrayList>(); + String[] parameters = line.split( "" "" ); + int nrOfPlayers = Integer.valueOf( parameters[0] ); + int nrOfSurprises = Integer.valueOf( parameters[1] ); + int treshold = Integer.valueOf( parameters[2] ); + System.out.println(""Iteration nr."" + String.valueOf( j )); + System.out.println(""Generating triplets for "" + String.valueOf( nrOfPlayers )); + for( int i = 3; i < parameters.length; i++ ) { + tripletCollections.add( generateTriplets( Integer.valueOf( parameters[i]) ) ); + } + System.out.println(""Selecting triplets""); + Triplet[] selectedTriplet = new Triplet[nrOfPlayers]; + int surprising = 0; + for( int i = 0; i < tripletCollections.size(); i++ ) { + Collection triplets = tripletCollections.get( i ); + if( getAboveNotSurprising( triplets, treshold ) != null ) { + selectedTriplet[i] = getAboveNotSurprising( triplets, treshold ); + } + else if( getAboveAndSurprising( triplets, treshold ) != null ) { + selectedTriplet[i] = getAboveAndSurprising( triplets, treshold ); + surprising++; + } + else if( getBelowNotSurprising( triplets, treshold ) != null ) { + selectedTriplet[i] = getBelowNotSurprising( triplets, treshold ); + } + else { + selectedTriplet[i] = getBelowAndSurprising( triplets, treshold ); + surprising++; + } + } + System.out.println(""Improving triplets""); + if( nrOfPlayers == 1 ) { + System.out.println( ""only one player""); + } + if( surprising != nrOfSurprises ) { + if( surprising < nrOfSurprises ) { + System.out.println(""More surprises than expected""); + int i = 0; + while( ( i < nrOfPlayers ) && ( surprising != nrOfSurprises ) ) { + Collection triplets = tripletCollections.get( i ); + if( !selectedTriplet[i].isSurprising() ) { + if( getAboveAndSurprising( triplets, treshold ) != null ) { + selectedTriplet[i] = getAboveAndSurprising( triplets, treshold ); + surprising++; + } + } + i++; + } + i=0; + while( ( i < nrOfPlayers ) && ( surprising != nrOfSurprises ) ) { + Collection triplets = tripletCollections.get( i ); + if( !selectedTriplet[i].isSurprising() ) { + if( getBelowAndSurprising( triplets, treshold ) != null ) { + selectedTriplet[i] = getBelowAndSurprising( triplets, treshold ); + surprising++; + } + } + i++; + } + } + else { + int i=0; + while( ( i < nrOfPlayers ) && ( surprising != nrOfSurprises ) ) { + Collection triplets = tripletCollections.get( i ); + if( selectedTriplet[i].isSurprising() ) { + if( getBelowNotSurprising( triplets, treshold ) != null ) { + selectedTriplet[i] = getBelowNotSurprising( triplets, treshold ); + surprising--; + } + } + i++; + } + + } + } + int result = 0; + for( Triplet triplet : selectedTriplet ) { + if( triplet.getBestResult() >= treshold ) { + result++; + } + } + results.add(result); + line = reader.readLine(); + } + System.out.println(""Writing output""); + BufferedWriter writer = new BufferedWriter( new FileWriter( ""C:\\output.txt"") ); + for( int i = 0; i < results.size(); i++ ) { + writer.write( ""Case #"" + String.valueOf( i+1 ) + "": "" + String.valueOf( results.get( i ) ) ); + writer.newLine(); + } + writer.close(); + } + catch( Exception e ) { + + } + + + } + + private static Collection generateTriplets( int aSum ) { + ArrayList result = new ArrayList(); + int temp; + if( aSum % 3 == 0 ) { + result.add( new Triplet( aSum/3, aSum/3, aSum/3 ) ); + } + if( (aSum - 1) % 3 == 0 && (aSum - 1) >= 0 ) { + temp = ( aSum - 1 ) / 3; + if( temp + 1 <= 10 ) { + result.add( new Triplet( temp, temp, temp + 1 ) ); + } + } + if( (aSum - 2) % 3 == 0 && (aSum - 2) >= 0) { + temp = ( aSum - 2 ) / 3; + if( temp + 2 <= 10 ) { + result.add( new Triplet( temp, temp, temp + 2 ) ); + } + if( temp + 1 <= 10 ) { + result.add( new Triplet( temp, temp + 1, temp + 1 ) ); + } + } + if( (aSum - 3) % 3 == 0 && (aSum - 3) >= 0) { + temp = ( aSum - 3 ) / 3; + if( temp + 2 <= 10 ) { + result.add( new Triplet( temp, temp + 1, temp + 2 ) ); + } + } + if( (aSum - 4) % 3 == 0 && (aSum - 4) >= 0) { + temp = ( aSum - 4 ) / 3; + if( temp + 2 <= 10 ) { + result.add( new Triplet( temp, temp + 2, temp + 2 ) ); + } + } + return result; + } + + private static Triplet getAboveNotSurprising( Collection aCollection, int aTreshold ) { + for (Triplet triplet : aCollection ) { + if( ( triplet.getBestResult() >= aTreshold ) && !triplet.isSurprising() ) { + return triplet; + } + + } + return null; + } + + private static Triplet getBelowNotSurprising( Collection aCollection, int aTreshold ) { + for (Triplet triplet : aCollection ) { + if( ( triplet.getBestResult() < aTreshold ) && !triplet.isSurprising() ) { + return triplet; + } + + } + return null; + } + + private static Triplet getAboveAndSurprising( Collection aCollection, int aTreshold ) { + for( Triplet triplet : aCollection ) { + if( ( triplet.getBestResult() >= aTreshold ) && triplet.isSurprising() ) { + return triplet; + } + } + return null; + } + + private static Triplet getBelowAndSurprising( Collection aCollection, int aTreshold ) { + for( Triplet triplet : aCollection ) { + if( ( triplet.getBestResult() < aTreshold ) && triplet.isSurprising() ) { + return triplet; + } + } + return null; + } + +} +" +A21344,"import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner s = new Scanner(System.in); +// Scanner s = null; +// try { +// s = new Scanner(new FileInputStream(""s.in"")); +// } catch (FileNotFoundException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } + int lines = s.nextInt(); + for (int i = 1 ; i <= lines ;i++){ + int[] stat = new int[3]; + + int N = s.nextInt(); + int S = s.nextInt(); + int p = s.nextInt(); + int[] b = new int[]{ + 3*p-4,3*p-2,3*p+2,3*p+4 + }; + + for (int j = 0;j < N;j++){ + int a = s.nextInt(); + if (p == 0){ + stat[1] ++; + }else if ( p == 1){ + if (a > 0){ + stat[1] ++; + } + }else if ( p== 10){ + if (a >=28){ + stat[1]++; + }else if (a== 27 &&a == 26){ + stat[2]++; + } + }else{ + if (a >=b[1]){ + stat[1]++; + }else if (a >=b[0]){ + stat[0]++; + } + } + } + int r = stat[1] + Math.min(S, stat[0]+stat[2]); + System.out.printf(""Case #%d: %d\n"",i,r); + } + } + +} +" +A20171,"import java.io.*; +import java.util.StringTokenizer; +import java.lang.Math; + +public class qualifycodejamB{ + + public static int surprisePVal(int score){ + if(score < 4){ + if(score == 0){ + return 0; + }else if(score == 1){ + return 1; + }else{ + return 2; + } + } + + double dscore = (double) score; + + if((dscore % 3) == 1){ + return (int)Math.ceil(dscore/3); + } + else{ + return ((int)Math.ceil(dscore/3) + 1); + } + + } + + public static int bestVal(int score){ + if(score < 4){ + if(score == 0){ + return 0; + }else{ + return 1; + } + } + double dscore = (double)score; + return (int)Math.ceil(dscore/3); + } + + public static int process_score(int cscore, int ttl_surp, int surp, int pval){ + int returnval = 0; + int currentp = bestVal(cscore); + + + if(currentp >= pval){ + return 1; + } + + int bestp = surprisePVal(cscore); + + if (bestp >= pval && ttl_surp > surp){ + return 3; + } + + return returnval; + } + + public static void main(String[] args){ + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String x = null; + String linein = null; + int totalcases = 0; + int ttl_scores = 0; + int ttl_surprises = 0; + int surprise_count = 0; + int pval = 0; + int pcount = 0; + int currentscore = 0; + int scorecount = 0; + int counter = 1; + int process_return = 0; + + try{ + x = br.readLine(); + totalcases = Integer.parseInt(x); + + while( (linein = br.readLine()) != null){ + surprise_count = 0; + pcount = 0; + scorecount = 0; + + StringTokenizer st = new StringTokenizer(linein); + ttl_scores = Integer.parseInt(st.nextToken()); + ttl_surprises = Integer.parseInt(st.nextToken()); + pval = Integer.parseInt(st.nextToken()); + + while(scorecount < ttl_scores){ + currentscore = Integer.parseInt(st.nextToken()); + process_return = process_score(currentscore,ttl_surprises,surprise_count,pval); + if ((process_return & 1) == 1){ + pcount++; + } + if (process_return == 3){ + surprise_count++; + } + + scorecount++; + } + + System.out.print(""Case #"" + (counter) + "": ""+ pcount); + //System.out.println("" debug: return val: ""+process_return+""; used surprises: "" + surprise_count + ""/""+ttl_surprises); + System.out.println(); + + counter++; + } + + } + catch (IOException e) { + e.printStackTrace(); + } + + } + +}" +A21605,"import java.util.*; + +class Dancing +{ + + public static void main(String[] args) + { + int[] dancers = new int[100]; + int N; + int surprising; + int target; + int i; + int result; + int optimal; + int n; + int T; + int t; + Scanner myInput = new Scanner(System.in); + T = myInput.nextInt(); + for (t=1; t<=T; t++) + { + result=0; + N = myInput.nextInt(); + surprising = myInput.nextInt(); + target = myInput.nextInt(); + for (i=0; i=0; i--) + { + optimal = 0; + n=dancers[i]; + //System.out.println(n); + if (surprising>0) + { + if (n%3==0) + { + optimal=n/3; + if (((optimal-1>=0)&&(optimal=target)) + { + optimal++; + surprising--; + } + } + else + if (n%3==1) + { + optimal=(n/3)+1; + } + else + if (n%3==2) + { + optimal=(n/3)+1; + if ((optimal=target)) + { + optimal++; + surprising--; + } + } + + if (optimal>=target) result++; + + } + else + { + if (n%3==0) optimal=n/3; + else + optimal = (n/3)+1; + if (optimal>=target) result++; + } + } + System.out.println(""Case #""+t+"": ""+result); + } + } + +} +" +A21666,"import java.io.*; +import java.util.*; +public class dancing { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(""dancing.in"")); + PrintWriter out = new PrintWriter(new File(""dancing.out"")); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int cases = Integer.parseInt(st.nextToken()); + int answer; + + for (int i = 0; i < cases; i++){ + answer = 0; + StringTokenizer data = new StringTokenizer(br.readLine()); + int[] googlers = new int[Integer.parseInt(data.nextToken())]; + int surprising = Integer.parseInt(data.nextToken()); + int threshold = Integer.parseInt(data.nextToken()); + for (int a = 0; a < googlers.length; a++){ + googlers[a] = Integer.parseInt(data.nextToken()); + } + Arrays.sort(googlers); + for (int z = googlers.length-1; z >= 0; z--){ + if (googlers[z] == 0 && (threshold * 3) > 0){ + } else if (googlers[z] >= ((threshold * 3) - 2)){ + answer++; + } else if (surprising > 0 && ((googlers[z] <= ((threshold * 3) - 2)) && (googlers[z] >= ((threshold * 3) - 4)))){ + surprising--; + answer++; + } + } + out.println(""Case #"" + (i + 1) + "": "" + answer); + } + out.close(); + } +}" +A20210,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package gcj.base; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.regex.Pattern; + +/** + * + * @author jalves + */ +public class Console { + + static final String defaultDelimiters = ""\\s+""; + static final int intRadix = 10; + + private BufferedReader in = null; + private PrintWriter out = null; + + private String delimiters = defaultDelimiters; + private Pattern splitter = null; + private String line = null; + private String[] tokens = null; + private int tokenIdx = 0; + + public Console(String inputName, String outputName, boolean overwrite) { + File f; + InputStreamReader isr; + OutputStreamWriter osw; + + if ((inputName == null) || inputName.equals(""-"")) { + isr = new InputStreamReader(System.in/*, charset*/); + } else { + f = new File(inputName); + if (f.canRead()) { + try { + isr = new FileReader(f); + } catch (FileNotFoundException ex) { + throw new IllegalArgumentException(""Error accessing input file '"" + inputName + ""': Exiting..."", ex); + } + } else { + throw new IllegalArgumentException(""Error accessing input file '"" + inputName + ""': Exiting...""); + } + } + + if ((outputName == null) || outputName.equals(""-"")) { + osw = new OutputStreamWriter(System.out/*, charset*/); + } else { + f = new File(outputName); + try { + if (f.createNewFile()) { + // new file was created + osw = new FileWriter(f); + } else { + // file already exists + if (overwrite && f.canWrite()) { + osw = new FileWriter(f); + } else { + throw new IllegalArgumentException(""Output file '"" + outputName + ""' already exists: Exiting...""); + } + } + + } catch (IOException e) { + throw new IllegalArgumentException(""Error accessing output file '"" + outputName + ""': Exiting..."", e); + } + } + in = new BufferedReader( isr ); + out = new PrintWriter( osw , true); + delimiters = defaultDelimiters; + splitter = Pattern.compile(delimiters); + } + + /************************************************* + * Read from input + *************************************************/ + + protected String readLine() throws IOException { + line = in.readLine(); + tokenIdx = 0; + tokens = null; + return line; + } + + public boolean newLine() throws IOException { + if (readLine() != null) { + return true; + } else { + return false; + } + } + + public void changeDelimiters(String newDelims) { + if (newDelims == null) { + delimiters = defaultDelimiters; + } else { + delimiters = newDelims; + } + splitter = Pattern.compile(delimiters); + } + + private String[] getTokens() throws IOException { + if (line == null) { + if ( ! newLine()) { + return null; + } + } + + tokens = splitter.split(line); + + return tokens; + } + + public String[] getStrings() throws IOException { + return getTokens(); + } + + private long toLong(String s) { + return Long.parseLong(s, intRadix); + } + + public long[] getLongs() throws IOException { + long[] result = null; + if (getTokens() != null) { + result = new long[tokens.length]; + for (int i = 0; i < tokens.length; i++) { + result[i] = toLong(tokens[i]); + } + } + return result; + } + + private double toDouble(String s) { + return Double.parseDouble(s); + } + + public double[] getDoubles() throws IOException { + double[] result = null; + if (getTokens() != null) { + result = new double[tokens.length]; + for (int i = 0; i < tokens.length; i++) { + result[i] = toDouble(tokens[i]); + } + } + return result; + } + + public String getString() throws IOException { + if (tokens == null) { + getTokens(); // no check to wether it returns null + } + if (tokenIdx >= tokens.length) { + newLine(); // no check to wether it returns false + getTokens(); // no check to wether it returns null + } + + return tokens[tokenIdx++]; + } + + public long getLong() throws IOException { + if (tokens == null) { + getTokens(); // no check to wether it returns null + } + if (tokenIdx >= tokens.length) { + newLine(); // no check to wether it returns false + getTokens(); // no check to wether it returns null + } + + return toLong(tokens[tokenIdx++]); + } + + public double getDouble() throws IOException { + if (tokens == null) { + getTokens(); // no check to wether it returns null + } + if (tokenIdx >= tokens.length) { + newLine(); // no check to wether it returns false + getTokens(); // no check to wether it returns null + } + + return toDouble(tokens[tokenIdx++]); + } + + public void cleanup() { + try { + in.close(); + } catch (IOException ex) { + // do nothing + } + out.close(); + } + + /************************************************* + * Write to output + *************************************************/ + public void print(String s) { + out.print(s); + } + + public void println(String s) { + out.println(s); + } + + /************************************************* + * Log to console + *************************************************/ + private SimpleDateFormat sdf = new SimpleDateFormat(""yyyy-MM-dd HH:mm:ss.SSS""); + private Date now = new Date(); + public void logt(String s) { + now.setTime(System.currentTimeMillis()); + System.err.println(sdf.format(now) + "": "" + s); + System.err.flush(); + } + + public void log(String s) { + System.err.print(s); + System.err.flush(); + } + +} +" +A20960,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map.Entry; + +import javax.swing.JFileChooser; + + +public class Solver { + + public static int[][] getPossibleTriplets(int score){ + int s_3 = score/3; + switch (score % 3){ + case 0: + if ((score / 3) > 9){ + return new int[][]{new int[]{0,s_3,s_3,s_3,s_3}}; + } + else { + return new int[][]{new int[]{0,s_3,s_3,s_3,s_3}, new int[]{2,s_3+1,s_3-1,s_3,s_3+1}}; + } + case 1: + return new int[][]{new int[]{1,s_3+1,s_3,s_3,s_3+1}, new int[]{2,s_3+1,s_3-1,s_3+1,s_3+1}}; + case 2: + return new int[][]{new int[]{1,s_3+1,s_3,s_3+1,s_3+1},new int[]{2,s_3+2,s_3,s_3,s_3+2}}; + } + return null; + } + + /** + * return 0 if the score can be obtained with the maximum judge >= p without surprise, + * 1 if it can be obtained with surprise + * -1 if it can't be obtained + * @param score + * @param p + * @return + */ + public static int isPossible(int score, int p){ + int s_3 = score/3; + switch (score % 3){ + case 0: + if (s_3 == 10){ + //only possibility 10 10 10 + return s_3 >= p ? 0 : -1; + } + else if (s_3 == 0){ + //only possibility 0 0 0 + return p == 0 ? 0 : -1; + } + else { + return s_3 >= p ? 0 : (s_3 +1 >= p ? 1 : -1); + } + case 1: + if (s_3 == 0){ + //only possibility 0 0 1 + return p <=1 ? 0 : -1; + } + return s_3+1 >= p ? 0 : -1; + case 2: + if (s_3 == 0){ + //only possibilities 0 1 1 and 0 0 2 + return p <= 1 ? 0 : (p == 2 ? 1 : -1); + } + return s_3+1 >= p ? 0 : (s_3+2 >=p ? 1 : -1); + } + return -1; + } + + + /** + * @param args + */ + public static void main(String[] args) { + JFileChooser chooser = new JFileChooser("".""); + int ans = chooser.showOpenDialog(null); + if (ans == JFileChooser.APPROVE_OPTION){ + File input = chooser.getSelectedFile(); + JFileChooser chooser2 = new JFileChooser(input.getParentFile()); + ans = chooser2.showSaveDialog(null); + if (ans == JFileChooser.APPROVE_OPTION){ + File output = chooser2.getSelectedFile(); + + try { + BufferedReader reader = new BufferedReader(new FileReader(input)); + PrintWriter writer = new PrintWriter(new FileWriter(output)); + String line = reader.readLine(); + int numCase = Integer.parseInt(line); + for (int caseNum = 0 ; caseNum < numCase ; caseNum++){ + line = reader.readLine(); + String[] tokens = line.split("" ""); + int numScores = Integer.parseInt(tokens[0]); + int numSurprise = Integer.parseInt(tokens[1]); + int p = Integer.parseInt(tokens[2]); + int numPossibleWithoutSurprise = 0; + int numPossibleWithSurprise = 0; + int[] scores = new int[numScores]; + for (int t = 3 ; t < tokens.length ; t++){ + scores[t-3] = Integer.parseInt(tokens[t]); + int r = isPossible(scores[t-3], p); + if (r == 0){ + numPossibleWithoutSurprise++; + } + else if (r == 1){ + numPossibleWithSurprise++; + } + } + if (caseNum > 0){ + writer.println(); + } + writer.print(""Case #""+(caseNum+1)+"": ""+(numPossibleWithoutSurprise+Math.min(numPossibleWithSurprise, numSurprise))); + } + writer.flush(); + writer.close(); + reader.close(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + } + +} +" +A21122,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package leider.ken; + +import java.io.*; +import java.util.*; +import java.util.concurrent.*; + +/** + * + * @author ken + */ +public class CommandLine { + + public static void main(String args[]) throws Exception { + Parser parser = new DancingParser(); + + ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + //ExecutorService executor = Executors.newFixedThreadPool(1); + + for (String file : args) { + Map> tests = parser.parse(file); + + Map results = new ConcurrentSkipListMap(); + List> futures = executor.invokeAll(createCommands(results, tests)); + + for (Future future : futures) { + if (future.get() == null) { + System.err.println(""Failed on test of "" + file); + break; + } + } + + final String outputFile = changeExtension(file, "".out""); + PrintStream out = new PrintStream(new FileOutputStream(outputFile)); + for (Map.Entry entry : results.entrySet()) { + out.println(entry.getValue()); + System.out.println(tests.get(entry.getKey()) + "" ===> "" + entry.getValue()); + } + + + System.out.println(""Results in "" + outputFile); + } + + executor.shutdown(); + } + + public static Collection> createCommands(Map results, Map> tests) { + List> retval = new ArrayList>(); + + for (Map.Entry> entry : tests.entrySet()) { + retval.add(new CommandLine.Command(entry.getKey(), entry.getValue(), results)); + } + + return retval; + } + + private static class Command implements Callable { + private final int testID; + private final Callable test; + private final Map results; + + private Command(int testID, Callable test, Map results) { + this.testID = testID; + this.test = test; + this.results = results; + + } + public String call() throws Exception { + try { + final String retval = test.call(); + results.put(testID, retval); + return retval; + } catch (Exception e) { + System.err.println(""Exception during test case "" + testID); + e.printStackTrace(); + } + + return null; + } + } + + static String changeExtension(String originalName, String newExtension) { + int lastDot = originalName.lastIndexOf("".""); + if (lastDot != -1) { + return originalName.substring(0, lastDot) + newExtension; + } else { + return originalName + newExtension; + } + } +} +" +A22291,"package com.wordofday.service.job; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GoogleDance { + + public static void main(String[] args){ + GoogleDance dancer = new GoogleDance(); + try{ + FileInputStream in = new FileInputStream(args[0]); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String strLine = null; + int count = 0; + while ((strLine = br.readLine()) != null) { + if(count>0){ + //skip first line + if(count>1){ + System.out.print(""\nCase #""+count+"": ""+dancer.output(strLine)); + }else{ + System.out.print(""Case #""+count+"": ""+dancer.output(strLine)); + } + } + count++; + + } + //Close the input stream + in.close(); + }catch(Exception e){ + e.printStackTrace(); + } + + } + + private int output(String strLine) { + int output = 0; + String[] parts = strLine.split("" ""); + int totalItems = Integer.parseInt(parts[0]); + int surprises = Integer.parseInt(parts[1]); + int threshold = Integer.parseInt(parts[2]); + List scores = new ArrayList(); + for(int i=3;i>>> outputList = new ArrayList>>>(); + for(Integer score:scores){ + Map>> scoreMap = new HashMap>>(); + List outputResult = new ArrayList(); + //try dividing by 3 and look for +-1 + int benchMark = score/3; + int firstScore = benchMark ; + int secondScore = benchMark; + int thirdScore = benchMark; + for(int a=-2;a<2;a++){ + firstScore = benchMark+a; + + for(int b=-2;b<=2;b++){ + secondScore = benchMark +b; + for(int c=-2;c<=2;c++){ + thirdScore = benchMark +c; + validateScore(threshold, score, scoreMap, outputResult, firstScore, + secondScore, thirdScore); + outputResult= new ArrayList(); + } + } + } + outputList.add(scoreMap); + + } + + int totalItemsWithSurprises = 0; + for(int m=0;m>> scoreMap = outputList.get(m); + if(scoreMap.get(""surprise"")!=null){ + List> surpriseList = scoreMap.get(""surprise""); + if(surpriseList.size()>0){ + //if this isnt a needed surprise, remove it + if( scoreMap.get(""normal"") != null + && scoreMap.get(""normal"").size() > 0 && + (isValidThresHold( scoreMap.get(""normal""), threshold) || ( + !isValidThresHold(scoreMap.get(""normal""), threshold) && !isValidThresHold( + scoreMap.get(""surprise""), threshold)))){ + scoreMap.remove(""surprise""); + }else{ + if(totalItemsWithSurprises>=surprises){ + scoreMap.remove(""surprise""); + }else{ + totalItemsWithSurprises++; + } + } + } + } + } + + int diff = totalItemsWithSurprises-surprises; + + if(totalItemsWithSurprises>surprises){/* + while (diff > 0) { + // diff are the extra items that have surprises more than needed + // clear the surprises from those if they already have a normal + // solution + + for (int m = 0; m < outputList.size(); m++) { + Map>> scoreMap = outputList + .get(m); + if (scoreMap.get(""surprise"") != null) { + if (surprises == 0 + || (diff > 0 + && scoreMap.get(""surprise"").size() > 1 + && scoreMap.get(""normal"") != null + && scoreMap.get(""normal"").size() > 0 && (isValidThresHold( + scoreMap.get(""normal""), threshold) || ( + !isValidThresHold( + scoreMap.get(""normal""), threshold) && !isValidThresHold( + scoreMap.get(""surprise""), threshold))))) { + scoreMap.remove(""surprise""); + diff--; + } + } + } + } + */} + + + totalItemsWithSurprises=0; + for (int m = 0; m < outputList.size(); m++) { + Map>> scoreMap = outputList.get(m); + + List> surpriseList = scoreMap.get(""surprise""); + List> normalList = scoreMap.get(""normal""); + + if(isValidThresHold(surpriseList,threshold) + ||isValidThresHold(normalList,threshold)){ + output++; + } + } + return output; + } + + private boolean isValidThresHold(List> normalList, + int threshold) { + boolean valid = false; + if(normalList!=null){ + for(List data:normalList){ + for(Integer item:data){ + if(item>=threshold){ + valid = true; + break; + } + } + } + } + return valid; + } + + private void validateScore(int threshold, Integer score, + Map>> scoreMap, + List outputResult, int firstScore, int secondScore, + int thirdScore) { + if(isValid(firstScore,secondScore,thirdScore, score,threshold)){ + outputResult.add(firstScore); + outputResult.add(secondScore); + outputResult.add(thirdScore); + + if((firstScore-secondScore)==2 + || (firstScore-secondScore)==-2 + || (secondScore-thirdScore)==2 + || (secondScore-thirdScore)==-2 + || (firstScore-thirdScore)==2 + || (firstScore-thirdScore)==-2 + ){ + List> surpriseList = scoreMap.get(""surprise""); + if(surpriseList==null){ + surpriseList = new ArrayList>(); + } + surpriseList.add(outputResult); + scoreMap.put(""surprise"", surpriseList); + }else{ + List> normalList = scoreMap.get(""normal""); + if(normalList==null){ + normalList = new ArrayList>(); + } + normalList.add(outputResult); + scoreMap.put(""normal"", normalList); + } + } + } + + private boolean isValid(int firstScore, int secondScore, int thirdScore, + Integer score, int threshold) { + if(firstScore>=0 && firstScore<=10 + && secondScore>=0 && secondScore<=10 + && thirdScore>=0 && thirdScore<=10 + && (firstScore+secondScore+thirdScore)==score.intValue() + //&& (firstScore>=threshold || secondScore>=threshold || thirdScore>=threshold) + && !( + (firstScore-secondScore)>2 + || (firstScore-secondScore)<-2 + || (secondScore-thirdScore)>2 + || (secondScore-thirdScore)<-2 + || (firstScore-thirdScore)>2 + || (firstScore-thirdScore)<-2 + ) + ){ + return true; + } + return false; + } + + + +} +" +A20573,"package CaseSolvers; + +import Controller.IO; + +public abstract class CaseSolver { + + private int order; + + public CaseSolver(int order, int numberOfLines, IO io) { + this.order = order; + initializeVars(); + addAllLines(io, numberOfLines); + } + + public abstract void addLine(String line); + + public abstract void initializeVars(); + + public abstract void printSolution(); + + public abstract CaseSolver process(); + + public void addAllLines(IO io, int numberOfLines) { + for (int i = 0; i < numberOfLines; i++) { + addLine(io.readLine()); + } + } + + public int getOrder() { + return order; + } + +} +" +A21312,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +public class googler { + public static void main(String[] args) throws Exception { + int n; + int res; + int threshold; + int cheat; + int goo; + int test; + int div; + int rem; + String[] temp; + BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter write = new BufferedWriter(new OutputStreamWriter(System.out)); + + n = Integer.parseInt(read.readLine()); + + for (int j=1; j<=n; j++) { + temp = read.readLine().split("" ""); + res = 0; + goo = Integer.parseInt(temp[0]); + cheat = Integer.parseInt(temp[1]); + threshold = Integer.parseInt(temp[2]); + + for (int i=0; i= threshold) { + res++; + + } + else if (threshold - div == 1) { + if (rem > 0){ + res++; + + } + else if (cheat > 0 && div > 0) { + cheat--; + res++; + + } + } + else if ((threshold - div == 2) && rem == 2 && cheat > 0) { + cheat--; + res++; + + } + } + + write.write(String.format(""Case #%d: %d\n"", j, res)); + + } + write.flush(); + } +} + + + " +A22007," + +import java.io.*; +import java.util.Scanner; + +public class B { + + /** + * @param args + */ + public static void main(String[] args) throws IOException { + Scanner s = new Scanner(new FileReader(new File(""B-large.in""))); + PrintWriter out = new PrintWriter(new File(""B.out"")); + StringBuilder resultat =new StringBuilder(""""); + + int T = s.nextInt(); + + for (int i = 0; i < T; i++) { + + int r=0; + + int N = s.nextInt(); + int S = s.nextInt(); + int P = s.nextInt(); + + int sr = S; + + int[] ti = new int[N]; + for (int j = 0; j < N; j++) { + ti[j] = s.nextInt(); + + if(ti[j]==0 && P>0) + continue; + + if(ti[j]>=P*3-2) + r++; + else if(ti[j]>=P*3-4 && sr>0) + { + r++; + sr--; + } + } + + if(i!=0) + resultat.append(""\n""); + resultat.append(""Case #""+(i+1)+"": ""+r); + + + + } + + + + out.print(resultat); + out.close(); + } +} +" +A22803,"/** + * + */ +package hu.hke.gcj; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +/** + * @author katalma + * + */ +public class DancingWithTheGooglers { + + static DancingWithTheGooglers dwtg = new DancingWithTheGooglers() ; + /** + * @param args + */ + public static void main(String[] args) { + + readAndCalculate(args[0], args[1]); + } + + private static void readAndCalculate(String inputF, String outputF) { + BufferedReader input = null; + BufferedWriter output = null; + try { + String line = null; + input = new BufferedReader(new FileReader(inputF)); + output = new BufferedWriter(new FileWriter(outputF)); + boolean first = true; + int expectedRows = 0; + int actualRows = -1; + while ((( line = input.readLine()) != null) && (actualRows < expectedRows)) { + System.out.print(actualRows+1); + System.out.println(""----------------------------------------------------""); + if (first) { + first = false; + expectedRows = Integer.parseInt(line); + } else { + output.write(""Case #"" +(actualRows+1)+"": ""+ dwtg.maximumBestResults(line)); + if (actualRows +1 < expectedRows) { + output.write(""\n""); + } + } + actualRows++; + } + + input.close(); + output.close(); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + } + + } + + private String maximumBestResults(String line) { + // TODO Auto-generated method stub + System.out.println(line); + B actLine = new B(line); + return actLine.pGooglers(); + } + + class B { + int googlerN; + int suprs; + int p; + Googler[] googlers; + int pGooglers; + + private B() {}; + + B(String line) { + String[] tmp = line.split("" ""); + googlerN = Integer.parseInt(tmp[0]); + suprs = Integer.parseInt(tmp[1]); + p = Integer.parseInt(tmp[2]); + googlers = new Googler[googlerN<= tmp.length-3? googlerN : tmp.length-3]; + for (int i = 0; i < googlers.length; i++) { + googlers[i] = new Googler(Integer.parseInt(tmp[i+3])); + } + pGooglers = 0; + } + + public String pGooglers() { + // TODO Auto-generated method stub + System.out.println(""Limit: ""+p+"" Suprise: ""+suprs); + pGooglers = 0; + int actSuprs = 0; + for (int i = 0; i < googlers.length; i++) { + if (googlers[i].possibleP(p)) { + System.out.println(""Possible: "" +googlers[i]); + pGooglers++; + } else if (actSuprs< suprs) { + System.out.println(""with suprise?""); + if (googlers[i].possiblePS(p)) { + System.out.println(""Possible with suprise: "" +googlers[i]); + pGooglers++; + actSuprs++; + } + } + } + return Integer.toString(pGooglers); + } + + } + + class Googler { + int totalCounts; + int div; + int mod; + + Googler(int i) { + totalCounts = i; + div = i/3; + mod = i%3; + } + + public boolean possibleP(int p) { + if (div>=p) { + return true; + } + if ((mod<2 ) &&(div+mod>=p)) { + return true; + } + if ((mod==2 ) && (div+1>=p)&& (totalCounts>1)) { + return true; + } + return false; + } + public boolean possiblePS(int p) { + if (div>=p) { + return true; + } + if (div+mod>=p) { + return true; + } + if ((mod==0 ) && (div+1>=p) && (totalCounts>1)) { + return true; + } + return false; + } + public String toString() { + return ""googgler: ""+totalCounts+""::""+div+""::""+mod; + } + } +} +" +A22717,"import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + + +public class Googlers { + + static public int min(int a, int b){ + return a < b ? a : b; + } + + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + File f = new File( ""B-large.in"" ); + FileWriter out=new FileWriter(""output.txt""); + + Scanner in = new Scanner(new FileReader(f)); + + if(f.exists()){ + int T; + int N, S, p; + int[] t = new int[100]; + + T = in.nextInt(); + + for(int i = 1; i <= T; i++){ + + N = in.nextInt(); + S = in.nextInt(); + p = in.nextInt(); + + int sup = 0; + int litige = 0; + + for(int j = 0; j < N ; j++) + t[j] = in.nextInt(); + + for(int j = 0; j < N ; j++){ + if(t[j] >= 3*p-2) + sup++; + else + if(t[j] >= 3*p-4 && 3*p-4 >= 0) + litige++; + + + } + out.write(""Case #"" + i +"": "" + (sup+ min(S, litige))+ ""\n""); + + + } + } + + in.close(); + out.close(); + + + } +} +" +A21469,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + + +public class ProbB { + public static int solve(int N, int S, int p, int[] scores) { + int count = 0; + for(int i = 0; i 0) { + count++; S--; + } + } + } + } + return count; + } + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""B-large.out"")); + String line = in.readLine(); + int T = Integer.parseInt(line); + for(int i=1; i<=T; i++) { + line = in.readLine(); + String[] comp = line.split(""\\s+""); + int N = Integer.parseInt(comp[0]); + int S = Integer.parseInt(comp[1]); + int p = Integer.parseInt(comp[2]); + int[] scores = new int[N]; + for(int j = 0; j= p)cnt++; + else if(y+1 <= x && y+1 == p)updateable++; + }else if(rem == 1){ + if(y+1 >= p)cnt++; + }else{//rem == 2 + if(y+1 >= p)cnt++; + else if(y+2 == p)updateable++; + } + } + cnt += Math.min(S,updateable); + out.println(cnt); + System.out.println(cnt); + } + out.close(); + } +}" +A20955,"import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class Main { + + + public static void main(String[] args) throws IOException { + + BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); + int tc=Integer.parseInt(br.readLine()); + for(int j=0;j=p) + { + cnt++; + continue; + } + if(s>0) + { + if((GT[i]+1)==p) + { + GT[i]=GT[i]+1; + cnt++; + s--; + + } + } + + + + + } + + + } + + for(int i=0;i=p) + cnt++; + + + } + + + } + + for(int i=0;i=p) + { + cnt++; + continue; + } + else if(s>0) + { + GT[i] = GT[i] + 1; + if(GT[i]>=p) + { + s--; + cnt++; + } + + } + + } + + + } + + int x=j+1; + System.out.println(""Case #""+x+"": ""+cnt); + + } + } + + +} + +" +A21531,"import java.io.File; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class Googlerese { + + static Scanner in; + static PrintWriter out; + + public static void fillDictionary(Map dic){ + dic.put(new Character('a'), new Character('y')); + dic.put(new Character('b'), new Character('n')); + dic.put(new Character('c'), new Character('f')); + dic.put(new Character('d'), new Character('i')); + dic.put(new Character('e'), new Character('c')); + dic.put(new Character('f'), new Character('w')); + dic.put(new Character('g'), new Character('l')); + dic.put(new Character('h'), new Character('b')); + dic.put(new Character('i'), new Character('k')); + dic.put(new Character('j'), new Character('u')); + dic.put(new Character('k'), new Character('o')); + dic.put(new Character('l'), new Character('m')); + dic.put(new Character('m'), new Character('x')); + dic.put(new Character('n'), new Character('s')); + dic.put(new Character('o'), new Character('e')); + dic.put(new Character('p'), new Character('r')); + dic.put(new Character('q'), new Character('z')); + dic.put(new Character('r'), new Character('p')); + dic.put(new Character('s'), new Character('d')); + dic.put(new Character('t'), new Character('r')); + dic.put(new Character('u'), new Character('j')); + dic.put(new Character('v'), new Character('g')); + dic.put(new Character('w'), new Character('t')); + dic.put(new Character('x'), new Character('h')); + dic.put(new Character('y'), new Character('a')); + dic.put(new Character('z'), new Character('q')); + } + + public static String translate(String originalWord, Map dic){ + String translatedWord=""""; + for(int i = 0; i < originalWord.length(); i++){ + translatedWord += dic.get(originalWord.charAt(i)); + } + + return translatedWord; + } + + public static void main(String[] args) throws Exception { + in = new Scanner(new File(""A-small.txt"")); + out = new PrintWriter(new File(""output.txt"")); + + Map dic = new HashMap(); + fillDictionary(dic); + //Read file + String Y = null; + String[] originalWords; + int T = in.nextInt(); + //for each case do + for (int i = 0; i < T; i++){ + //get first O and first B buttons + Y = in.nextLine(); + originalWords = Y.split("" ""); + System.out.print(""Case "" + i + "":""); + for(int j = 0; j < originalWords.length; j++){ + System.out.print( translate(originalWords[j],dic)) + } + + } + + out.print(Y); + //printf(""Case #%d: %s%n"", cas, ans); + + out.close(); + } +}" +A21656," +public class Scores { + private int N; // Number of Googlers + private int S; // Number of surprising triplets of scores + private int p; // Score at least + private int[] t; // total point of Googlers + + public Scores(String str) { + String[] tmpArr = str.split("" ""); + N = Integer.parseInt(tmpArr[0]); + S = Integer.parseInt(tmpArr[1]); + p = Integer.parseInt(tmpArr[2]); + + t = new int[N]; + for (int i=0; i= minTNormal) { + maxNumber++ ; + } else if (t[i] >= minTSurprising) { + surpNumber++ ; + } + } + + if (S < surpNumber) { + surpNumber = S ; + } + + return maxNumber+surpNumber; + } + +} +" +A22814,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + + +public class QuestionB { + + public static void doPuzzle() { + + try { + + File questionfile = new File(""B.in""); + BufferedReader questionreader = new BufferedReader(new FileReader(questionfile)); + + File answerfile = new File(""B.out""); + PrintWriter answerwriter = new PrintWriter(new BufferedWriter(new FileWriter(answerfile))); + + String[] params = null; + String question = questionreader.readLine(); + int T = Integer.parseInt(question); + + int[][] table = makeTable(); + + for (int i = 0; i < T; i++) { + question = questionreader.readLine(); + params = question.split("" ""); + int N = Integer.parseInt(params[0]); + int S = Integer.parseInt(params[1]); + int p = Integer.parseInt(params[2]); + int[] t = new int[N]; + for (int j = 0; j < N; j++) t[j] = Integer.parseInt(params[3+j]); + answerwriter.println(""Case #"" + (i+1) + "": "" + analyze(table, N, S, p, t)); + } + + answerwriter.close(); + questionreader.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + private static int[][] makeTable() { + int[][] scoreTable = new int[31][11]; + for (int i = 0; i < 31; i++) { + if (i == 0) { + for (int j = 0; j < 1; j++) scoreTable[i][j] = 2; + for (int j = 1; j < 11; j++) scoreTable[i][j] = 0; + continue; + } + if (i == 1) { + for (int j = 0; j < 2; j++) scoreTable[i][j] = 2; + for (int j = 2; j < 11; j++) scoreTable[i][j] = 0; + continue; + } + if (i >= 28) { + for (int j = 0; j < 11; j++) scoreTable[i][j] = 2; + continue; + } + int shou = i / 3; + int amari = i % 3; + switch (amari) { + case 0: + for (int j = 0; j < shou+1; j++) scoreTable[i][j] = 2; + scoreTable[i][shou+1] = 1; + for (int j = shou+2; j < 11; j++) scoreTable[i][j] = 0; + break; + case 1: + for (int j = 0; j < shou+2; j++) scoreTable[i][j] = 2; + for (int j = shou+2; j < 11; j++) scoreTable[i][j] = 0; + break; + case 2: + for (int j = 0; j < shou+2; j++) scoreTable[i][j] = 2; + scoreTable[i][shou+2] = 1; + for (int j = shou+3; j < 11; j++) scoreTable[i][j] = 0; + break; + } + + } + + return scoreTable; + } + + private static int analyze(int[][] table, int N, int S, int p, int[] t) { + int[] count = new int[3]; + for (int i = 0; i < t.length; i++) { + count[table[t[i]][p]]++; + } + int border = (count[1] < S) ? count[1] : S; + + return count[2] + border; + } +} + +" +A21719," +public class DancingGooglers { + static String test = ""4\n3 1 5 15 13 11\n3 0 8 23 22 21\n2 1 1 8 0\n6 2 8 29 20 8 18 18 21""; + static String val = ""100\n6 2 8 29 20 8 18 18 21\n68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n54 30 6 1 12 14 26 21 28 3 12 16 11 7 10 11 13 8 3 15 19 1 26 0 20 11 8 6 29 10 14 23 27 2 16 2 0 0 23 2 27 18 17 4 25 20 5 5 25 16 7 27 23 0 4 27 4\n73 30 2 18 3 2 10 3 2 3 3 15 21 3 2 2 3 27 2 2 3 6 1 16 21 2 8 17 3 8 29 14 2 2 20 13 2 30 21 3 2 2 2 14 28 2 30 3 18 21 1 2 2 14 20 7 3 2 17 2 14 2 25 2 2 21 3 21 3 3 3 0 2 2 23 3\n52 15 5 21 29 12 13 12 11 11 12 25 28 0 12 30 23 11 27 12 11 11 16 12 12 11 4 17 11 11 19 12 12 19 0 20 24 12 4 24 11 5 5 12 6 12 11 12 1 12 11 24 12 11 7\n95 45 4 1 11 18 8 10 26 24 12 14 7 21 9 18 11 3 21 3 0 4 1 4 10 24 3 9 1 9 3 9 13 24 13 11 26 29 14 16 12 22 12 14 18 15 8 18 9 16 14 24 17 19 17 25 4 5 23 19 11 29 17 12 3 20 15 8 21 26 27 3 22 6 29 15 10 14 5 28 27 6 12 3 8 5 13 23 10 15 1 12 8 4 18 22 5 11\n65 25 10 30 25 19 27 18 26 22 19 6 27 28 27 26 25 27 3 21 19 9 15 26 27 18 27 26 28 22 26 24 17 1 27 26 25 27 26 0 27 23 20 26 21 11 10 26 26 26 26 23 11 27 29 27 26 26 27 27 11 26 25 27 26 17 27 6\n17 17 3 27 6 25 13 13 3 8 8 4 2 11 16 5 20 11 12 13\n76 76 1 13 9 23 28 7 7 24 20 17 10 3 9 16 11 20 20 17 20 24 19 20 11 10 16 16 5 28 17 17 6 12 26 22 26 11 4 12 5 4 28 4 11 17 22 10 23 4 27 28 18 18 22 11 4 2 14 6 12 7 26 15 19 11 12 12 11 14 28 15 26 7 25 20 23 11 19\n44 11 10 21 19 4 10 11 7 30 25 11 29 26 15 11 3 15 19 11 5 14 21 25 9 22 1 16 10 13 16 10 13 8 7 18 0 9 17 2 1 4 17 14 23 22 26\n67 30 4 18 8 8 18 25 7 9 8 8 30 9 8 26 8 18 9 8 22 8 5 8 9 8 5 11 8 9 26 16 9 8 9 23 9 5 8 19 8 17 2 10 9 8 9 4 8 0 9 1 8 26 2 8 9 9 21 9 8 11 8 9 17 9 9 17 9 0\n21 21 2 16 27 20 25 8 10 22 16 18 7 25 9 5 23 15 23 24 20 13 12 4\n5 2 9 19 24 6 24 23\n15 7 0 29 0 10 12 25 25 27 0 9 20 0 7 15 25 16\n57 16 9 23 24 9 23 13 30 23 24 23 23 24 23 7 6 24 24 27 19 24 24 23 19 24 23 24 1 24 23 24 29 12 24 23 2 0 19 23 10 23 24 1 16 6 22 24 23 3 23 24 16 10 24 24 24 23 24 24\n89 78 6 22 27 9 15 28 13 26 28 21 4 11 3 10 25 16 16 15 2 18 2 22 19 21 16 24 7 3 5 12 4 12 12 17 20 21 30 4 17 22 3 13 18 10 10 4 1 29 7 24 2 11 25 13 29 28 16 24 12 5 8 6 20 10 24 13 18 30 12 21 4 20 0 13 2 6 11 25 10 13 23 22 27 17 16 9 30 28 9 7\n19 3 5 11 11 12 11 25 12 12 8 11 12 12 12 12 17 11 12 11 5 1\n90 22 3 8 7 19 6 5 5 6 5 5 1 5 26 5 16 20 6 17 4 5 5 28 24 15 26 6 5 1 6 5 30 9 1 20 20 5 5 5 6 5 5 5 6 5 6 10 5 6 22 22 5 5 5 27 6 18 0 5 6 6 9 5 6 0 10 6 6 6 6 12 6 5 17 3 19 13 0 5 6 6 5 16 6 24 5 9 6 5 5 6 12\n48 48 5 16 10 25 11 5 6 24 10 3 12 4 14 22 15 4 23 18 7 10 6 23 10 15 23 7 16 8 12 23 8 24 23 28 3 11 3 14 5 25 13 11 20 26 14 5 2 10 6\n36 31 1 0 29 26 9 22 15 27 15 3 19 5 26 15 7 7 1 26 24 0 3 15 21 10 2 2 26 17 26 26 29 15 15 8 7 23 21\n18 18 3 24 25 12 5 3 27 26 28 4 14 10 3 3 5 17 19 14 18\n84 50 2 15 23 21 17 28 10 2 5 25 14 6 0 20 21 21 16 18 6 11 15 23 26 20 7 7 29 3 13 26 12 3 28 0 3 9 7 25 17 27 16 15 25 5 18 28 27 11 4 25 26 2 24 13 26 26 25 19 12 17 21 10 15 23 20 22 0 12 29 8 5 2 24 0 15 12 14 3 12 5 7 7 6 27 0\n55 8 0 1 19 8 0 5 23 14 2 0 19 29 18 19 14 13 6 30 23 24 24 29 10 19 7 19 2 7 8 27 25 28 8 8 14 19 22 30 7 21 6 25 22 11 5 25 11 30 26 21 30 29 18 16 0 9\n11 2 4 9 28 27 8 8 8 9 26 8 9 8\n73 38 6 14 16 11 30 15 20 22 10 8 20 1 2 24 20 4 21 28 9 27 6 20 12 17 0 19 6 21 19 28 17 3 29 6 7 21 11 2 22 20 17 20 3 16 14 26 29 28 5 1 11 10 24 21 9 17 1 22 30 14 17 17 13 20 29 3 8 5 9 16 30 7 10 8\n1 0 9 15\n50 27 7 23 9 12 7 19 30 28 27 1 10 13 6 26 10 29 1 30 7 27 19 13 23 16 13 15 29 2 20 4 23 23 10 28 28 9 23 26 17 15 1 24 15 4 17 0 14 7 24 11 11\n7 3 3 5 5 14 1 21 5 6\n68 15 9 15 0 26 9 25 6 9 27 3 3 26 15 4 19 27 25 28 21 4 21 5 0 14 6 28 17 16 30 30 29 19 1 20 23 22 0 10 11 26 29 29 6 29 11 4 15 21 3 29 9 19 8 10 15 24 12 24 8 11 0 6 5 6 8 9 23 27 9\n62 22 6 1 16 3 17 1 15 13 11 11 11 6 17 26 1 24 0 13 15 11 3 22 11 18 28 22 19 12 22 26 10 10 11 2 15 6 12 30 5 25 14 26 9 7 8 9 8 29 17 24 3 0 0 28 28 6 9 10 11 25 4 19 23\n3 3 1 18 25 14\n84 61 6 9 4 26 8 4 14 24 3 20 3 16 23 13 28 13 21 11 28 21 18 26 8 30 11 1 6 8 6 21 28 4 18 18 4 16 27 30 22 10 15 23 11 18 10 21 11 24 30 27 10 8 2 13 28 26 27 10 1 14 22 5 5 7 18 18 3 4 5 19 20 28 6 21 25 17 16 24 27 17 0 21 10 4 22\n20 2 6 22 14 14 24 14 15 2 15 14 25 5 21 0 5 15 15 17 23 14 25\n77 27 5 14 15 11 10 11 12 12 12 29 22 11 11 19 12 24 12 12 13 17 2 18 26 14 12 12 10 11 25 29 28 12 11 12 12 11 25 3 12 11 11 11 29 11 12 19 12 27 6 4 16 21 11 6 12 12 11 9 11 19 11 12 11 2 16 15 12 8 20 7 12 11 11 11 11 27 12 11\n38 0 9 28 9 22 7 7 22 28 3 7 16 14 29 13 7 14 25 24 26 27 9 12 3 27 22 24 22 28 20 21 24 16 30 16 13 25 11 9 18\n28 0 9 3 10 4 23 28 23 1 24 23 15 23 24 18 23 6 20 24 21 24 24 28 10 18 30 22 23 24 21\n11 7 5 5 30 30 11 27 20 19 18 24 4 19\n67 26 8 23 16 22 4 28 15 27 20 26 2 6 17 29 25 0 14 16 20 14 29 30 2 15 1 16 15 1 9 7 2 0 7 8 8 28 29 6 22 3 21 23 0 22 22 25 15 29 26 13 26 21 22 19 30 18 17 23 12 23 20 20 0 7 9 14 18 19\n4 2 3 17 0 19 13\n14 6 5 8 12 17 11 26 12 11 20 12 12 29 11 12 0\n44 14 9 5 23 2 10 24 17 23 24 24 6 23 24 24 23 12 23 12 2 24 24 24 23 21 23 23 16 24 24 24 2 23 23 24 8 23 24 23 23 24 24 4 21 17 30\n66 47 9 9 8 28 25 4 13 22 25 22 24 7 20 22 18 2 5 12 26 25 20 27 20 1 2 27 17 26 16 25 2 11 0 1 24 1 18 9 14 4 4 16 18 12 25 15 15 17 10 11 6 14 0 8 29 14 2 28 28 12 10 19 8 30 22 13 17\n41 34 2 18 13 11 11 5 0 7 2 28 21 29 3 25 9 4 20 9 0 26 15 9 22 6 14 29 13 14 2 22 23 27 26 12 9 26 9 22 10 30 9 21\n66 31 9 14 23 13 24 20 19 27 23 24 24 23 10 24 24 6 23 24 24 23 24 24 0 24 26 23 23 23 5 2 23 4 23 24 23 24 23 25 21 9 24 21 23 23 23 23 8 23 23 24 23 24 0 24 23 23 12 5 23 25 9 22 17 14 30 8 26\n65 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n37 0 10 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n49 0 5 9 4 7 9 15 24 16 13 13 30 8 16 14 7 9 7 27 7 19 15 30 5 27 1 28 13 23 28 3 1 4 2 0 18 18 29 15 10 20 12 29 17 7 7 8 11 3 9 27\n75 75 8 27 24 28 25 25 21 24 12 20 9 17 10 11 21 16 27 26 8 10 13 25 21 2 2 10 6 22 20 26 26 5 3 14 15 4 28 2 5 8 8 15 9 14 20 21 28 6 17 9 9 2 2 20 10 22 28 19 16 3 17 20 7 22 21 26 3 4 20 28 11 9 6 22 20 3\n59 59 0 24 19 10 8 3 15 9 14 22 16 10 9 28 18 2 13 21 16 26 2 28 27 26 7 16 5 28 4 4 21 2 4 19 6 9 21 19 5 28 7 26 20 23 12 25 3 18 24 13 24 10 10 24 24 20 4 24 13 18\n17 3 10 13 27 16 27 26 5 8 27 26 19 27 26 0 27 3 11 26\n87 8 4 0 14 8 18 14 15 8 4 9 26 11 7 9 11 8 13 9 8 8 9 9 9 8 30 4 20 9 20 9 8 1 18 5 9 8 8 8 9 9 16 8 8 23 9 9 9 8 3 13 17 18 8 8 18 9 9 7 6 21 9 9 7 11 22 8 9 8 30 8 16 8 8 19 9 27 30 0 7 15 25 9 19 8 9 9 9 8\n46 19 6 15 15 11 14 14 15 14 20 2 13 23 30 14 20 15 14 15 14 15 15 6 15 14 22 1 22 5 14 14 15 17 3 16 13 7 27 15 11 27 11 14 6 15 14 28 15\n53 53 0 13 7 4 6 6 4 21 8 16 21 28 27 18 2 19 17 14 26 5 17 5 23 8 23 2 14 6 15 27 14 8 28 24 15 26 26 21 10 26 27 25 14 25 23 28 5 28 2 22 18 19 20 26\n45 18 2 26 2 10 5 3 15 29 8 12 12 2 2 19 3 3 3 2 23 5 15 11 26 4 13 9 3 2 2 30 19 2 3 15 2 30 3 1 14 2 2 3 16 2 3 3\n71 35 3 6 5 18 6 6 5 5 26 14 0 7 18 6 3 5 6 18 5 28 24 5 5 6 6 19 6 14 5 5 6 7 17 6 6 10 15 17 5 6 9 11 17 6 5 5 12 5 18 0 1 6 17 22 6 6 6 6 5 23 11 6 6 5 6 5 9 18 5 17 6 27\n92 57 5 0 22 16 29 7 6 25 29 18 6 15 23 17 18 27 7 11 28 4 0 22 18 27 7 15 27 27 21 5 5 12 28 28 1 2 9 2 13 25 23 15 30 29 24 1 20 19 5 26 3 18 29 0 10 7 22 4 13 14 5 9 18 25 25 12 10 27 29 5 23 29 30 5 25 27 18 29 25 27 3 29 28 15 4 25 11 25 1 0 20 25 2\n90 36 7 18 19 19 22 7 0 18 1 17 15 28 18 18 18 6 17 18 2 10 3 15 18 17 25 20 18 17 17 19 18 17 18 18 18 2 10 4 17 11 18 9 18 18 17 26 18 3 14 18 17 19 7 17 29 18 24 1 18 26 18 1 18 20 18 18 3 18 30 18 17 17 10 17 28 17 18 18 4 14 18 18 18 18 10 18 9 21 3 6 17\n81 0 9 21 15 17 3 29 19 1 6 7 17 28 26 1 14 14 18 19 21 10 26 25 3 14 20 1 7 24 18 24 18 9 23 8 3 19 17 2 25 18 2 25 18 2 4 25 5 16 26 20 7 30 10 14 19 14 21 6 12 1 27 12 24 9 13 10 8 3 9 21 25 12 9 25 8 0 7 19 9 0 25 19\n25 6 6 7 27 14 5 2 30 18 30 27 4 24 16 24 0 30 17 12 4 28 4 5 19 1 9 30\n5 4 1 0 22 12 2 20\n17 0 7 23 14 3 1 13 8 22 22 2 4 18 11 21 18 24 21 25\n38 7 4 8 8 22 9 21 9 16 8 20 18 12 9 2 7 8 8 19 8 9 9 8 8 8 9 9 22 9 9 25 22 8 11 9 8 9 18 8 9\n34 5 6 22 15 15 16 21 15 14 15 4 15 14 15 15 17 22 15 7 15 15 5 15 14 14 23 30 4 6 15 10 14 20 14 0 15\n60 0 5 15 13 6 22 9 6 17 27 16 3 29 25 25 23 15 10 8 20 2 6 17 30 6 10 6 28 6 12 24 12 18 3 18 23 20 2 13 30 9 6 15 27 4 5 5 30 16 22 13 22 6 22 12 3 27 14 27 18 11 10\n63 40 0 13 23 4 13 16 22 20 16 27 11 14 29 9 25 5 15 27 13 23 22 15 28 12 0 5 17 9 16 23 12 23 9 3 25 29 10 22 6 12 10 30 15 27 2 9 15 8 28 21 22 3 12 25 15 26 14 20 30 0 27 21 9 3\n20 0 9 9 24 25 8 4 11 20 29 21 6 27 0 7 22 24 16 7 6 21 26\n23 0 10 29 19 22 18 11 27 22 18 22 7 2 12 11 25 8 21 4 11 13 9 13 3 19\n10 0 10 21 0 24 22 1 12 13 29 6 30\n5 5 7 24 20 11 20 13\n79 4 4 16 20 16 1 18 14 4 4 17 22 28 21 9 11 26 13 30 13 1 27 21 8 28 2 25 17 0 13 18 0 2 12 27 30 24 11 21 21 0 23 30 5 14 17 24 8 4 9 30 10 20 26 8 12 22 3 12 7 26 27 28 16 30 2 19 15 1 0 15 18 21 13 13 30 10 30 13 26 27\n74 21 5 11 12 11 11 6 12 26 12 12 12 25 4 15 30 23 12 14 11 1 26 12 11 5 12 11 12 11 11 11 12 9 12 14 12 12 13 23 9 22 19 28 12 12 11 12 6 15 3 11 10 16 12 12 12 8 12 11 12 16 18 11 6 24 12 14 11 7 11 11 12 11 1 8 25\n52 25 8 25 11 0 13 24 20 13 18 30 10 28 5 28 22 29 7 6 27 22 12 19 9 11 29 13 6 11 5 28 14 20 3 8 7 0 3 19 6 18 20 19 22 7 1 19 14 27 28 8 29 19 28\n88 21 9 28 10 26 19 30 23 2 29 21 4 4 16 8 20 9 12 3 19 16 10 19 28 0 22 17 19 11 11 5 17 28 25 3 5 23 25 24 24 21 15 13 17 23 9 6 15 30 14 26 3 27 12 29 28 28 0 15 6 14 7 14 12 8 10 2 24 21 26 14 0 18 21 7 13 2 29 18 16 3 26 3 21 20 9 23 18 29 9\n31 1 10 27 26 27 30 27 21 11 26 1 15 26 26 11 15 27 24 26 27 24 22 27 27 27 0 26 26 2 26 27 27 27\n71 28 6 0 8 6 2 20 29 14 27 6 27 22 10 10 8 17 11 24 9 12 10 20 0 29 8 5 15 17 25 21 16 6 3 3 27 15 4 23 13 16 19 3 15 13 17 2 18 9 14 9 20 12 7 27 20 5 25 17 11 17 30 1 18 8 16 0 20 3 3 8 8 27\n71 71 10 28 4 10 28 16 2 22 25 21 10 21 25 21 3 9 5 9 14 24 18 13 28 19 15 19 12 20 28 2 27 24 4 11 26 22 15 28 14 19 26 13 5 27 5 26 17 6 2 26 26 18 25 5 10 25 14 9 24 7 13 13 4 22 11 9 8 15 4 3 25 18\n63 0 3 7 4 7 0 15 26 7 26 4 21 28 11 2 6 22 8 24 22 18 3 3 8 10 28 20 2 6 26 19 15 28 9 8 20 24 0 21 22 6 26 22 27 27 13 3 14 28 29 9 8 27 18 4 26 9 18 26 14 21 0 25 28 6\n25 4 7 23 3 24 28 30 26 4 12 14 15 27 29 1 30 1 30 14 29 24 1 0 27 22 0 16\n100 49 6 3 21 17 12 25 26 8 30 9 10 15 19 7 28 3 0 16 4 17 26 19 16 27 15 10 20 9 1 29 10 27 30 23 28 28 11 18 27 5 17 22 29 6 12 1 10 29 8 13 9 8 23 21 5 24 12 16 14 15 2 10 0 3 19 27 23 20 3 30 30 18 12 5 1 19 13 20 16 10 1 26 8 20 29 28 28 23 8 14 16 23 1 12 2 22 5 14 25 29 26\n43 17 6 29 30 11 0 2 0 15 22 26 3 10 12 4 24 18 12 25 7 17 6 22 21 4 29 28 20 29 25 27 30 11 24 20 5 20 14 6 6 24 5 19 29 10\n99 76 3 4 27 13 17 15 4 13 0 20 24 9 17 9 25 24 27 9 7 8 24 6 12 28 1 28 9 17 14 13 6 20 7 29 6 7 15 4 10 21 18 14 5 2 1 23 27 1 8 30 9 14 20 12 20 20 29 6 29 22 25 21 24 20 12 15 0 3 0 17 7 15 8 8 9 21 26 7 26 11 5 9 21 19 16 30 10 5 9 2 23 27 19 5 5 15 16 22 14 29\n39 10 5 11 4 11 16 12 28 11 10 18 20 3 5 12 22 12 13 16 14 11 9 20 25 22 11 24 10 19 1 12 11 28 14 11 20 2 11 11 1 11\n96 32 6 14 8 4 15 14 24 29 14 15 15 14 14 15 14 14 7 15 14 14 4 5 23 13 14 0 29 2 3 21 30 14 1 14 15 15 14 24 15 16 14 15 14 13 14 15 14 24 20 10 15 14 14 15 8 15 15 14 14 15 14 17 21 11 1 25 16 8 3 15 29 14 15 15 26 14 15 15 14 17 28 15 15 15 14 14 15 10 19 18 23 18 10 15 15 14 19\n39 7 2 1 16 3 22 17 6 3 29 4 5 1 25 2 17 8 6 25 7 22 29 3 19 27 29 17 3 6 1 21 11 25 1 21 3 24 26 22 10 29\n89 18 3 21 27 5 7 13 18 8 10 13 19 0 8 30 30 23 21 16 21 7 5 14 24 23 6 30 25 11 22 28 29 21 10 11 2 11 5 20 17 15 19 1 30 23 25 16 0 7 15 18 11 10 16 22 30 12 11 21 0 9 26 8 24 15 5 21 10 7 22 5 14 12 27 13 2 21 12 29 2 12 15 19 7 21 6 30 26 9 18 5\n94 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n80 5 4 17 18 2 8 9 9 18 29 0 9 9 2 4 9 9 8 20 18 10 12 22 30 8 12 8 22 9 27 17 8 8 8 9 9 9 9 9 9 24 8 8 8 4 8 3 9 14 12 25 0 15 9 29 8 28 8 8 2 12 19 15 30 20 8 8 27 9 28 8 19 9 8 13 20 9 18 8 16 8 4\n69 22 0 0 13 29 3 24 18 5 28 20 8 22 21 27 6 29 15 3 20 12 15 23 16 0 26 14 23 20 29 27 27 10 15 30 1 7 12 7 28 27 24 1 6 23 3 14 7 13 2 17 6 4 27 4 22 29 7 14 16 13 2 26 3 3 9 28 10 8 1 23\n3 1 8 4 1 23\n73 30 5 12 11 23 12 11 8 12 16 12 11 23 12 7 12 19 12 1 11 11 12 11 11 4 12 22 4 7 11 12 11 27 11 11 14 26 15 11 18 2 12 12 11 12 12 12 26 12 12 11 11 11 6 21 16 17 8 25 1 11 10 23 2 14 21 11 7 11 6 12 16 12 11 19\n52 22 9 24 8 17 23 11 23 23 24 24 24 23 8 3 24 23 24 23 24 24 25 13 5 23 24 20 24 3 24 24 23 21 20 23 17 24 21 17 28 9 23 23 19 24 23 23 11 23 24 24 23 24 24\n97 97 3 21 20 27 9 18 21 23 13 9 3 23 4 17 4 27 19 4 20 17 26 20 13 22 22 5 17 27 7 23 27 7 17 26 8 14 24 25 7 9 21 26 19 15 21 19 19 24 26 5 23 21 6 18 18 24 22 3 28 15 25 14 2 14 19 24 7 13 22 6 13 6 22 28 7 3 23 12 18 5 27 16 15 24 24 27 26 27 13 18 20 16 6 8 23 11 22 12\n89 25 3 26 25 5 22 5 5 0 6 2 5 6 6 21 12 10 5 11 20 2 5 5 17 5 6 7 6 6 6 6 16 15 5 5 6 20 6 5 8 13 6 5 5 18 6 4 6 6 6 5 27 19 6 0 5 5 5 22 5 30 11 5 23 7 7 6 5 3 26 6 8 20 2 6 5 6 5 25 4 21 7 19 7 6 6 5 6 5 16 22\n82 0 10 28 10 23 18 25 23 9 2 16 15 0 14 9 0 4 27 21 20 13 12 23 24 11 5 8 2 24 18 28 6 16 11 17 17 27 28 9 21 30 13 30 17 24 12 6 9 26 27 30 29 0 22 6 23 5 8 10 8 8 24 17 23 8 25 28 27 8 24 8 5 26 13 12 5 26 9 30 6 28 2 15 1\n76 0 6 3 4 4 2 29 22 4 28 26 0 21 23 3 9 24 1 2 20 8 10 20 23 26 25 9 28 30 17 2 28 20 13 23 26 23 14 15 15 30 13 10 22 22 20 7 10 24 23 20 22 21 17 15 26 14 2 26 27 10 5 29 1 2 5 25 2 12 16 26 16 12 0 25 21 9 10\n60 10 4 19 8 30 9 25 8 0 19 8 16 22 9 29 9 8 9 7 8 22 9 18 7 14 9 8 8 5 8 18 9 9 23 1 8 8 27 18 17 30 4 13 8 8 8 21 27 13 21 28 0 4 9 8 23 16 1 22 9 8 10\n91 3 3 7 6 1 5 14 2 5 6 23 19 5 6 13 23 14 14 5 1 5 24 12 5 5 18 5 6 6 28 6 6 6 5 5 5 7 5 27 6 22 21 13 5 6 28 6 5 6 6 7 30 2 22 6 6 6 23 2 6 5 6 12 6 5 6 5 4 7 13 4 21 11 18 17 3 10 20 7 15 26 5 6 23 6 6 12 4 6 5 10 26 6\n22 9 1 4 4 2 1 23 15 13 0 1 0 23 17 4 23 24 10 29 14 24 14 2 3\n6 0 10 19 25 15 12 21 10\n22 13 8 16 24 8 0 21 22 29 24 18 14 29 29 3 0 11 16 28 19 7 7 0 26\n""; + /** + * @param args + */ + public static void main(String[] args) { + String[][] cases = CaseReader.getCases(val, 1); + for (int i = 0;i < cases.length;i++) + { + parseCase(i + 1, cases[i][0]); + } + } + + static void parseCase(int caseNum, String caseString) { + String[] args = caseString.split("" ""); + int googleCount = Integer.parseInt(args[0]); + int surprises = Integer.parseInt(args[1]); + int lowest = Integer.parseInt(args[2]); + int[] googleScores = new int[googleCount]; + for (int i = 0;i < googleCount;i++) + { + googleScores[i] = Integer.parseInt(args[i + 3]); + } + int countAbove = getCasesWhereAbove(lowest, surprises, googleScores); + System.out.println(""Case #"" + caseNum + "": "" + countAbove); + } + + static int getCasesWhereAbove(int minimum, int surpriseCount, int[] scores) { + int count = 0, currentSurprises = 0; + for (int i = 0;i < scores.length;i++) { + if ((scores[i] + 2) / 3 >= minimum) { // This one naturally works, so it's fine. + count++; + } else if (scores[i] >= minimum && (scores[i] + 4) / 3 >= minimum && currentSurprises < surpriseCount) { + count++; + currentSurprises++; + } + } + return count; + } + +} +" +A20479," +package B; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Scanner; + +public class B { + + public static void main(String[] args) throws IOException { + PrintStream out = new PrintStream(new File(""/output.txt"")); + Scanner in = new Scanner(new File(""/B-large.in"")); + int testCase = Integer.parseInt(in.next()); + for (int n = 0; n < testCase; n++) { + int count = 0; + int googlers = Integer.parseInt(in.next()); + int surprising = Integer.parseInt(in.next()); + int wantScores = Integer.parseInt(in.next()); + for (int g = 0; g < googlers; g++) { + int scores = Integer.parseInt(in.next()); + if (scores - (wantScores * 3) >= -2) { + count++; + } else if ((surprising > 0) && (((scores - (wantScores * 3) == -4)&&scores>=2) || ((scores - (wantScores * 3) == -3)&&scores>=3))) { + surprising--; + count++; + } + } + out.println(""Case #"" + (n + 1) + "": "" + count); + System.out.println(""Case #"" + (n + 1) + "": "" + count); + } + in.close(); + out.close(); + } +} +" +A21320,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class GCJ2012QA +{ + + public static void main(String[] args) throws Exception + { + Scanner sc = new Scanner(new FileReader(""A-input.txt"")); + PrintWriter pw = new PrintWriter(new FileWriter(""A-output.txt"")); + + final int CASE_COUNT = sc.nextInt(); + for(int caseNum = 1; caseNum<= CASE_COUNT; caseNum++){ + pw.print(""Case #"" + caseNum + "": ""); + //HERE WE SOLVE STUFF + int ans = 0; + + int N = sc.nextInt(); + int S = sc.nextInt(); + int sp = sc.nextInt(); + for(int i =0; i= sp){ + ans++; + } else if( kk > 0 && (base + 1) >= sp && (base - 1) >= 0){ + ans++; + } else if(S>0) { + if(kk == 0 && (base+2) >= sp && (base - 1) >= 0){ + ans++; + S--; + } + if(kk == 1 && (base+2) >= sp && (base - 1) >= 0){ + ans++; + S--; + } + if(kk == 2 && (base+2) >= sp){ + ans++; + S--; + } + } + + } + + //PUT ANSWER HERE + pw.println(ans); + } + + pw.flush(); + pw.close(); + sc.close(); + } + + +} +" +A21998,"import java.util.*; +import java.io.*; +class GooglerDancing2{ +static int S,p,count=0; +static int[] g=new int[1000]; +static int[] v=new int[1000]; +static PrintWriter pw ; +public static void main(String[] args){ + + try { +File file = new File(""B-large.in""); + FileReader fr = new FileReader(file); +BufferedReader br = new BufferedReader(fr); +File file1 = new File(""Bout42.in""); +FileWriter fw = new FileWriter(file1); +pw= new PrintWriter(fw); +int T= Integer.valueOf(br.readLine()); +Scanner cin=new Scanner(System.in); +int i,j,k; + +//System.out.println(""enter no. of test cases""); +int n=1; + while(n<=T) + { +// int ok=cin.nextInt(); + int N=0; +count=0; + + +String G=br.readLine(); j=0;i=0;k=1; +int m=1; +String r=""""; +if(G==null)break; + +int l; +for(l=0;l0) + { + for(i=10;i>=0;i--) + for(j=10;j>=0;j--) + for(k=10;k>=0;k--) + { + if(t==(i+j+k)) + if(any(i,j,k)>0 && (max(i,j,k)>=p)) + { + //count++; + v[l]=1; + S--;//pw.println(""penallty ""+"" ""+i+"" ""+j+"" ""+k+"" ""+t); + return 1; + } + } + } +return 0; +} +static int any1(int i,int j,int k) +{ +if(mod(i-j)==0 && mod(j-k)==0 && mod(i-k)==0) +return 1; +if(mod(i-j)==1 && mod(j-k)==1 && mod(i-k)==0) +return 1; +if(mod(i-j)==1 && mod(j-k)==0 && mod(i-k)==1) +return 1; +if(mod(i-j)==0 && mod(j-k)==1 && mod(i-k)==1) +return 1; +return 0; +} +static int any(int i,int j,int k) +{ +if(mod(i-j)==2 && mod(j-k)==2 && mod(i-k)==0) +return 1; +if(mod(i-j)==0 && mod(j-k)==2 && mod(i-k)==2) +return 1; +if(mod(i-j)==2 && mod(j-k)==0 && mod(i-k)==2) +return 1; +if(mod(i-j)==2 && mod(j-k)==1 && mod(i-k)==1) +return 1; +if(mod(i-j)==1 && mod(j-k)==2 && mod(i-k)==1) +return 1; +if(mod(i-j)==1 && mod(j-k)==1 && mod(i-k)==2) +return 1; +return 0; +} +static int max(int i,int j,int k) +{ +if(i>j && i>k)return i; +if(j>k)return j; +return k; +} +static int mod(int n) +{ +if(n<0) +return n*-1; +return n; +} +static int diff(int i,int j,int k) +{ +if(any1(i,j,k)>0) +{ +if(max(i,j,k)>=p) +{ +//count++; +return 1; +} +} + + +return 0; +} +static int pos(int t,int l) +{ +int i,j,k; +for(i=10;i>=0;i--) +for(j=10;j>=0;j--) +for(k=10;k>=0;k--) +{ +if(t==(i+j+k)) +if(diff(i,j,k)==1) +{ +v[l]=-1; +//pw.println("" ""+i+"" ""+j+"" ""+k+"" ""+t); +return 1; +} +} + +return pena(t,l); + +//return 0; +} + + +}//class + +" +A21103," +package gcj; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.Scanner; + +/** + * + * @author Mervin.Lavin + */ +public class Gcj +{ + + public static void main + (String[] args) + throws Exception + { + doProb2( ""B-large.in"", ""output.txt"" ); + } + + private static void doProb2 + ( String inputFileName, String outputFileName ) + throws Exception + { + File inputFile = new File( inputFileName ); + Scanner scanner = null; + scanner = new Scanner( inputFile ); + File outputFile = new File( outputFileName ); + BufferedWriter output = new BufferedWriter( new FileWriter( outputFile ) ); + + int contestants, surpriseScores, minBestScore; + int totalScore, aveScore, passedContestants; + int testCases = scanner.nextInt(); + for ( int caseNum = 1; caseNum <= testCases; caseNum++ ) + { + contestants = scanner.nextInt(); + surpriseScores = scanner.nextInt(); + minBestScore = scanner.nextInt(); + passedContestants = 0; + for ( int contestant = 0; contestant < contestants; contestant++ ) + { + totalScore = scanner.nextInt(); + aveScore = totalScore / 3; + switch ( totalScore % 3 ) + { + case 0: + if ( aveScore >= minBestScore ) + { + passedContestants++; + } + else if ( ( surpriseScores > 0 ) + && ( ( aveScore + 1 ) >= minBestScore ) + && ( ( aveScore + 1 ) <= totalScore )) + { + passedContestants++; + surpriseScores--; + } + break; + case 1: + if ( ( aveScore + 1 ) >= minBestScore ) + { + passedContestants++; + } + break; + case 2: + if ( ( aveScore + 1 ) >= minBestScore ) + { + passedContestants++; + } + else if ( ( surpriseScores > 0 ) + && ( ( aveScore + 2 ) >= minBestScore ) + && ( ( aveScore + 2 ) <= totalScore ) ) + { + passedContestants++; + surpriseScores--; + } + break; + } + } + output.append( ""Case #"" + caseNum + "": "" + passedContestants ); + output.newLine(); + } + scanner.close(); + output.close(); + } +} +" +A21374,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.math.BigInteger; +import java.util.*; + +public class B { + + static class State { + boolean surprising, not; + int max; + + State(boolean S, boolean n, int mx) { + surprising = S; + not = n; + max = mx; + } + } + + private void solve() throws IOException { + int T = nextInt(); + while (T-- > 0) { + int N = nextInt(); + int S = nextInt(); + int P = nextInt(); + int[] a = new int[N]; + State[] St = new State[N]; + for (int i = 0; i < N; i++) + a[i] = nextInt(); + int res = 0; + for (int i = 0; i < a.length; i++) { + St[i] = new State(false, false, -1); + for (int k1 = 0; k1 <= 10; k1++) { + for (int k2 = 0; k2 <= 10; k2++) { + for (int k3 = 0; k3 <= 10; k3++) { + if (k1 + k2 + k3 == a[i]) { + if (notValid(k1, k2, k3)) + continue; + if (surprise(k1, k2, k3)) { + if (k1 >= P || k2 >= P || k3 >= P) { + St[i].surprising = true; + St[i].max = Math.max(St[i].max, Math.max(k1, Math.max(k2, k3))); + } + } else { + if (k1 >= P || k2 >= P || k3 >= P) { + St[i].not = true; + St[i].max = Math.max(St[i].max, Math.max(k1, Math.max(k2, k3))); + } + } + } + } + + } + + } + } + + boolean[] V = new boolean[N]; + for (int i = 0; i < St.length && S > 0; i++) { + if (St[i].surprising && !St[i].not) { + res++; + V[i] = true; + S--; + } + } + for (int i = 0; i < St.length && S > 0; i++) { + if (!V[i] && St[i].surprising && St[i].not) { + res++; + V[i] = true; + S--; + } + } + for (int i = 0; i < St.length; i++) { + if (!V[i] && St[i].not) { + res++; + } + } + pf(); + pl(res); + } + } + + private boolean notValid(int k1, int k2, int k3) { + if (Math.abs(k1 - k2) > 2 || Math.abs(k1 - k3) > 2 + || Math.abs(k2 - k3) > 2) + return true; + return false; + } + + private boolean surprise(int k1, int k2, int k3) { + if (Math.abs(k1 - k2) == 2 || Math.abs(k1 - k3) == 2 + || Math.abs(k2 - k3) == 2) + return true; + return false; + } + + public static void main(String[] args) { + new B().run(); + } + + BufferedReader reader; + StringTokenizer tokenizer; + PrintWriter writer; + + public void run() { + try { + reader = new BufferedReader(new FileReader(""B_.in"")); +// reader = new BufferedReader(new InputStreamReader(System.in)); + tokenizer = null; +// writer = new PrintWriter(System.out); + writer = new PrintWriter(""B.out""); + solve(); + reader.close(); + writer.close(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + + int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws IOException { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws IOException { + return Double.parseDouble(nextToken()); + } + + BigInteger nextBigInteger() throws IOException { + return new BigInteger(nextToken()); + } + + String nextToken() throws IOException { + while (tokenizer == null || !tokenizer.hasMoreTokens()) { + tokenizer = new StringTokenizer(reader.readLine()); + } + return tokenizer.nextToken(); + } + + void p(Object... objects) { + for (int i = 0; i < objects.length; i++) { + if (i != 0) + writer.print(' '); + writer.flush(); + writer.print(objects[i]); + writer.flush(); + } + } + + void pl(Object... objects) { + p(objects); + writer.flush(); + writer.println(); + writer.flush(); + } + + int cc; + + void pf() { + writer.printf(""Case #%d: "", ++cc); + writer.flush(); + } + +} +" +A21412," +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +public class Googlers { + + public static void main(String[] args) throws Exception { + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B-large.out""))); + + int T = Integer.parseInt(in.readLine()); + + + for (int q = 1; q <= T; q++) { + + StringTokenizer st = new StringTokenizer(in.readLine()); + int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int P = Integer.parseInt(st.nextToken()); + int SurCount = 0; + int[] sum = new int[N]; + int res = 0; + for (int i = 0; i < sum.length; i++) { + sum[i] = Integer.parseInt(st.nextToken()); + if (sum[i] >= 2 && (sum[i] + 1) % 3 == 0 && (sum[i] + 1) / 3 >= P) { + res++; + } else if (sum[i] >= 1 && (sum[i] + 2) % 3 == 0 && (sum[i] + 2) / 3 >= P) { + res++; + } else if (sum[i] % 3 == 0) { + if (sum[i] / 3 >= P) { + res++; + } else if (sum[i] >= 3 && SurCount < S && (sum[i] + 3) / 3 >= P) { + res++; + SurCount++; + } + + } else if (sum[i] >= 2 && (sum[i] + 4) % 3 == 0 && SurCount < S && (sum[i] + 4) / 3 >= P) { + res++; + SurCount++; + } + // System.out.println(i + "" : "" + res + "" : "" + SurCount); + + + + } + out.write(""Case #"" + q + "": "" + res + ""\n""); + // System.out.println(""BE""); + + } + out.close(); + } +} +" +A21872,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Dancing { + + public static PrintWriter pw; + + public static void main(String[] args) throws FileNotFoundException { + + //Scanner in = new Scanner (System.in); + try{ + File f = new File(""\\\\filesrv/stufiles$/matt.tough/out.txt""); + f.createNewFile(); + pw = new PrintWriter(f); + }catch(Exception e){ + + } + Scanner in = new Scanner(new File(""\\\\filesrv/stufiles$/matt.tough/B-large.in"")); + String line = in.nextLine(); + int cases = Integer.parseInt(line); + for (int t=0; t < cases; t++){ + line = in.nextLine(); + Scanner thisLine = new Scanner (line); + int dancers = thisLine.nextInt(); + int surprises = thisLine.nextInt(); + int p = thisLine.nextInt(); + int p3 = p*3; + int count =0; + int totalScores[] = new int[dancers]; + for (int index = 0; index < dancers; index++){ + totalScores[index] = thisLine.nextInt(); + } + for ( int i = 0; i < dancers; i++){ + if(p ==0){ + count++; + continue; + }else if(p ==1){ + if (totalScores[i]>0) + count++; + continue; + + } + + if (totalScores[i]>= p3-2){ + count++; + } + else if(totalScores[i]>= p3-4){ + if (surprises>0){ + surprises--; + count++; + } + } + + } + pw.printf(""Case #%d: %d\n"", t+1, count); + } + pw.flush(); + } + +} +" +A21089,"package com.google.codejam; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class Main { + + /** + * @param args + * @throws FileNotFoundException + */ + + static Scanner in; + static BufferedWriter writer; + public static void main(String[] args) throws IOException { + + in = new Scanner(new File(""src/B-large.in"")); + writer = new BufferedWriter(new FileWriter(new File(""src/b.out""))); + + int T = in.nextInt(); + + for (int i = 1; i <= T; i++) { + int N = in.nextInt(); + int S = in.nextInt(); + int P = in.nextInt(); + int[] t = new int[N]; + + for (int j = 0; j < N; j++) { + t[j] = in.nextInt(); + } + solveCase(i, N, S, P, t); + } + + writer.close(); + + } + + public static int solveCase(int TEST_CASE, int N, int S, int P, int[] t) throws IOException { + int ans = 0; + int minSc = 3*P-2; + int minScSup = (P==1)?1:3*P-4; + int validCom = 0; + int validSup = 0; + for (int i = 0; i < t.length; i++) { + if(t[i]>=minSc) + validCom++; + else if (t[i]=minScSup) { + validSup++; + } + } + if(validSup<=S) ans = validCom + validSup; + else { + ans = validCom + S; + } + writer.write(""Case #"" + TEST_CASE + "": "" + ans); + writer.newLine(); + return 0; + } + +} +" +A23069,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class B { + public static void main(String[] args) throws FileNotFoundException { + Scanner scanner = new Scanner(new File(""B-large.in"")); + PrintWriter printer = new PrintWriter(new File(""a.out"")); + int t = scanner.nextInt(); + for (int i = 0; i < t; i++) { + int n = scanner.nextInt(); + int s = scanner.nextInt(); + int p = scanner.nextInt(); + int ans = 0; + for (int j = 0; j < n; j++) { + int tmp = scanner.nextInt(); + if (tmp >= p + 2 * Math.max(p - 1, 0)) { + ans++; + } else if (s > 0 && tmp >= p + 2 * Math.max(p - 2, 0)) { + ans++; + s--; + } + } + printer.println(""Case #"" + (i + 1) + "": "" + ans); + } + printer.flush(); + printer.close(); + } +} +" +A20944,"package org.moriraaca.codejam.dancingwithgooglers; + +import java.io.InputStream; + +import org.moriraaca.codejam.GeneralDataParser; + +public class DancingWithTheGooglersDataParser extends GeneralDataParser { + + public DancingWithTheGooglersDataParser(InputStream input) { + super(input); + } + + @Override + protected void doParse() { + for (int i = 0; i < testCases.length; i++) { + DancingWithTheGooglersTestCase tc = new DancingWithTheGooglersTestCase(); + tc.scores = new int[scanner.nextInt()]; + tc.S = scanner.nextInt(); + tc.p = scanner.nextInt(); + for (int j = 0; j < tc.scores.length; j++) { + tc.scores[j] = scanner.nextInt(); + } + + testCases[i] = tc; + } + } + +} +" +A22848,"import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Dancing { + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(new FileReader(""dancing.in"")); + PrintWriter out = new PrintWriter(new FileWriter(""DancingAlarge.out"")); + + int numCases = sc.nextInt(); + int count = 0; + + for (int i = 0; i < numCases; i++) { + int numGooglers = sc.nextInt(); + int numSurprising = sc.nextInt(); + int p = sc.nextInt(); + count = 0; + + for (int j = 0; j < numGooglers; j++) { + int thisGoogler = sc.nextInt(); + if (thisGoogler == 0 && p != 0) { + continue; + } + else if (thisGoogler >= 3 * p - 2) { + count++; + } + else if (numSurprising > 0 && thisGoogler >= (3 * p - 4)) { + count++; + numSurprising--; + } + } + out.println(""Case #"" + (i + 1) + "": "" + count); + } + out.close(); + } +} +" +A21218,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class Dancing { + + /** + * @param args + */ + + static int t =0; + //static ArrayList> table = new ArrayList>(); + + public static void inputF() throws FileNotFoundException{ + + File inputFile = new File(""B-large.in""); + Scanner in = new Scanner(inputFile); + File outputFile = new File(""B-large.out""); + PrintWriter out = new PrintWriter(outputFile); + String result=""""; + String input =""""; + + int n,s,p=0; + int[] list; + + t = in.nextInt(); + //System.out.println(n); + input = in.nextLine(); + for (int i=1; i<=t; i++) { + n = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + + list = new int[n]; + for (int j=0; jp-2) & (list[i]>=p)) { + result++; + } else if ((medium==p-2) & (s>0)) { + result++; + s--; + } + } + return result; + } + + + + public static void main(String[] args) throws FileNotFoundException { + inputF(); + + } + +} +" +A22828,"package mgg.problems; + +import mgg.utils.FileUtil; + +/** + * @author manolo + * @date 14/04/12 + */ +public class ProblemD { + + public final static String EXAMPLE_IN = ""D-example.in""; + public final static String EXAMPLE_OUT = ""D-example.out""; + + public final static String D_SMALL_IN = ""D-small-practice.in""; + public final static String D_SMALL_OUT = ""D-small-practice.out""; + + public final static String D_LARGE_IN= ""D-large-practice.in""; + public final static String D_LARGE_OUT = ""D-large-practice.out""; + + public final static String delim = "" ""; + + public static String solve(FileUtil util) { + + //TODO + + return null; + } + +} +" +A22382,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DancingWithTheGooglers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + + int testCaseNumber; + + String input; + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + input = in.readLine(); + + testCaseNumber = Integer.parseInt(input.trim()); + + int[] totalScoreArray = new int[testCaseNumber]; + + for(int i=0; i=minNos){ + score++; + } + else if(surprisingNum>0 && dataArray[j]>=minS){ + score++; + surprisingNum--; + } + } + System.out.println(score); + totalScoreArray[i] = score; + } + + + in.close(); + + FileWriter fstream = new FileWriter(""B-large.out""); + BufferedWriter out = new BufferedWriter(fstream); + + for(int i=1; i<=testCaseNumber;i++){ + String outLine = ""Case #""+i+"": ""+totalScoreArray[i-1]+""\n""; + out.write(outLine); + } + out.close(); + System.out.println(""File created successfully.""); + + } + +} + +" +A21882,"import static java.lang.Math.*; +import static java.util.Arrays.*; +import static java.util.Collections.reverse; +import static java.lang.Integer.*; +import static java.lang.Long.parseLong; +import java.util.*; +import java.awt.geom.*; +import java.io.*; + +//// Apache Jakarta Common Lang : http://commons.apache.org/lang/ +//import org.apache.commons.lang.builder.*; + +// java -Xmx1024m -Xss5m +@SuppressWarnings(""unchecked"") +public class B { +// private static final String IMPOSSIBLE = ""IMPOSSIBLE""; + private static final String NO = ""IMPOSSIBLE""; + public static final long MAX = Long.MAX_VALUE; + public static final int INF = 1000000000; + public static final int MOD = 9901; + public static final int UNDEF = -3; + + static int[] best = new int[31]; + static int[] bestSurprise = new int[31]; + static { + fill(best,-1); + fill(bestSurprise,-1); + for (int a1 = 0; a1 <= 10; ++a1) { + for (int a2 = a1; a2 <= 10 && a2<=a1+2; ++a2) { + for (int a3 = a2; a3 <= 10 && a3<=a1+2; ++a3) { + if (a3-a1==2) { + bestSurprise[a1+a2+a3] = Math.max(bestSurprise[a1+a2+a3], a3); + } else { + best[a1+a2+a3] = Math.max(best[a1+a2+a3], a3); + } + } + } + } + } + + /* + * each dancer is given a triplet of scores by three judges + * Each triplet of scores consists of three integer scores = [0..10] + * + * C(3,2) max diff<=2, surprising if max diff=2 + * it's surprising if a triplet of scores contains two scores that are 2 apart. + * No triplet of scores contains scores that are more than 2 apart. + * + * The best result is the maximum of the three scores in that Googler's triplet of scores. + * + * Given the total points for each Googler, as well as the number of surprising triplets of scores, + * what is the maximum number of Googlers that could have had a best result of at least p? + +N, the number of Googlers, +S, the number of surprising triplets of scores + +Limits +1 ≤ T ≤ 100. +0 ≤ S ≤ N. +0 ≤ p ≤ 10. +0 ≤ ti ≤ 30. +At least S of the ti values will be between 2 and 28, inclusive. + +Small dataset +1 ≤ N ≤ 3. + +Large dataset +1 ≤ N ≤ 100. + */ + /* + * iter 10^3 possibility to record sum -> max best result + * + * greedy : use surprise only when it has benefit (cross >=p boundary) + */ + private void run(int caseNumber) throws Exception { + /* + * + */ + int n = INT(); + int s = INT(); + int p = INT(); + int[] tot = new int[n]; + for (int i = 0; i < tot.length; i++) { + tot[i] = INT(); + } + + + /// reading input done + if(caseNumbercaseEnd) { + System.out.println(""### skip case ""+caseNumber); + return; + } + + + /// start solving problem + int ret = 0; + for (int i = 0; i < tot.length; i++) { + if (best[tot[i]]>=p) { + ret++; + } else if(s>0 && bestSurprise[tot[i]]>=p) { + ret++; + s--; + } + } + + out.printf(""Case #%d: %s\n"", caseNumber, ret); + } + + static boolean printInput=false; +// static boolean printInput=true; // print input case + + static boolean redirectStdoutToFile=false; +// static boolean redirectStdoutToFile=true; // redirect all STDOUT to ""output.txt"" + + + static boolean writeToFile=true; +// static boolean writeToFile=false; + +// static String testFilename=null; +// static String testFilename=""B-test.in""; +// static String testFilename=""B-small-attempt0.in""; +// static String testFilename=""B-small-attempt1.in""; +// static String testFilename=""B-small.in""; +// static String testFilename=""B-small-practice.in""; + static String testFilename=""B-large.in""; +// static String testFilename=""B-large-practice.in""; + + static String resultFilename=testFilename+""-res.txt""; + + static BufferedReader in; + static StringTokenizer inTok = new StringTokenizer(""""); + +// static Scanner in; + static PrintWriter out; + + //control the cases to run : [caseStart..csaeEnd] + static int caseStart=1; +// static int caseStart=1; + static int caseEnd=Integer.MAX_VALUE; +// static int caseEnd=caseStart+0; + + public static void main(String[] args) throws Exception { + long start = System.currentTimeMillis(); + +// myTest(); + + // $0 inputFile caseStart caseEnd + if(args.length>0) { + testFilename = args[0]; + } + if(args.length>1) { + caseStart=parseInt(args[0]); + } + if(args.length>2) { + caseEnd=parseInt(args[1]); + } + + // redirect sys out + if(redirectStdoutToFile) { + String filename = ""output.txt""; + System.out.println(""NOTE: redirect stdout to file ""+filename); + FileOutputStream fos = new FileOutputStream(filename); + PrintStream ps = new PrintStream(fos,true); + System.setOut(ps); + } + + if(testFilename==null) { + myTest(); + } else { +// in = new BufferedReader(new InputStreamReader(System.in)); + in = new BufferedReader(new FileReader(testFilename)); + int NN=INT(); +// in = new Scanner(System.in); +// in = new Scanner(new File(testFilename)); +// int NN=in.nextInt(); + out = writeToFile ? new PrintWriter(new FileWriter(resultFilename),true) + : new PrintWriter(System.out, true); + for (int i = 1; i <= NN; i++) { +// out.printf(""Case #%d: "", i); + if (printInput) System.out.println(""\n### Case ""+i); + new B().run(i); + } + in.close(); + + if(writeToFile) { + out.close(); + } + } + + System.out.println(""\nTime taken: ""+((System.currentTimeMillis()-start)/1000.0)+"" sec""); + + if(writeToFile) { + File ans=new File(testFilename+""-ans.txt""); + if(ans.exists()&&ans.length()>0) { + boolean same=sameFileContent(ans,new File(resultFilename)); + if(same) { + System.out.println(""Answer correct :)""); + } else { + System.out.println(""ERROR : Answer not matched""); + } + } + } + } + + private static boolean sameFileContent(File ansFile, File resFile) throws IOException { + System.out.println(); + BufferedReader ans = new BufferedReader(new FileReader(ansFile)); + BufferedReader res = new BufferedReader(new FileReader(resFile)); + boolean ok=true; + List wrong = new ArrayList(); + int ln=1; + while(true) { + String sAns=ans.readLine(); + String sRes=res.readLine(); + if(sAns==null) { + if(sRes!=null) { + System.out.println(""### result has more lines than answer""); + do { + System.out.println(sRes); + } while ((sRes=res.readLine())!=null); + System.out.println(); + ok=false; + } + break; + } + if(sRes==null) { + if(sAns!=null && !sAns.isEmpty()) { + System.out.println(""### answer has more lines than result""); + do { + System.out.println(sAns); + } while ((sAns=ans.readLine())!=null); + System.out.println(); + ok=false; + } + break; + } +// if(!sAns.equals(sRes)) { + if(!sAns.trim().equals(sRes.trim())) { + System.out.println(""### line ""+ln+"" not match:""); + System.out.println(""ans = ""+sAns); + System.out.println(""res = ""+sRes); + System.out.println(); + ok=false; + wrong.add(ln); + } + ln++; + } + if(!ok) { + System.out.println(""wrong : ""+wrong.size()+"" lines, lines start from 1: ""+wrong); + System.out.println(""total : ""+ln+"" lines""); + } + ans.close(); + res.close(); + return ok; + } + + private static void myTest() throws Exception { +// int num=-1000; + int num=1000; + for (int i = 1; i <= num; ++i) { +// System.out.println(i+"" : ""+new B().small(Rn.i(0,50))); +// for (int j = 1; j <= i; ++j) { +// System.out.println(i+"",""+j+"" : ""+i); +// } + } + } + + static String LINE() throws IOException { + String s=in.readLine(); + if (printInput) System.out.println(s); + return s; + } + static String STR() throws IOException { + while (!inTok.hasMoreTokens()) { + String line = LINE(); + if (line == null) { + return null; + } + inTok = new StringTokenizer(line); + } + return inTok.nextToken(); + } + + static int INT() throws IOException { return Integer.parseInt(STR()); } + static long LONG() throws IOException { return Long.parseLong(STR()); } + static double DOUBLE() throws IOException { return Double.parseDouble(STR()); } + + static int INT(String s) { return Integer.parseInt(s); } + static double DOUBLE(String s) { return Double.parseDouble(s); } + static long LONG(String s) { return Long.parseLong(s); } +} +" +A21317,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.Scanner; + +/** + * + * @author Saul Hidalgo + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + try { + Scanner sc = new Scanner(new File(""test2.txt"")); + PrintStream ps = new PrintStream(new File(""output2.txt"")); + + int T = sc.nextInt(); + for ( int t = 1 ; t <= T ; t++ ){ + int n = sc.nextInt(), s = sc.nextInt(), p = sc.nextInt(); + + int[] l = new int[n]; + for ( int i = 0 ; i < n ; i++ ){ + l[i] = sc.nextInt() - p ; + } + + int a = 0 , b = 0; + + for ( int i = 0 ; i < n ; i++ ){ + if ( l[i] == -1 && p > 0 ){ + }else if ( l[i] >= 2*( p - 1 ) ){ + ++a; + }else if ( l[i] >= 2*( p - 2 ) ){ + ++b; + } + } + ps.println(""Case #"" + t + "": "" + ( a + b - Math.max(0, b - s ) )); + } + + } + catch (FileNotFoundException ex) { + // =( + } + } +} +" +A23040,"package com.abuhijleh.googlejam; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class GoogleJam { + static final String code = ""yhesocvxduiglbkrztnwjpfmaq""; + + public static void main(String[] args) { + File input = new File(""inputFile""); + String[] result; + Scanner scan; + try { + scan = new Scanner(input); + result = new String[scan.nextInt()]; + scan.nextLine(); + for (int i = 0; i < result.length; i++) { + int N, S, P; + int[] val; + N = scan.nextInt(); + S = scan.nextInt(); + P = scan.nextInt(); + val = new int[N]; + for (int j = 0; j < val.length; j++) + val[j] = scan.nextInt(); + scan.nextLine(); + result[i] = ""Case #"" + (i + 1) + "": "" + solve(S, P, val); + } + System.out.println(""Output""); + for (int i = 0; i < result.length; i++) + System.out.println(result[i]); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private static int solve(int s, int p, int[] val) { + int count = 0; + for (int i = 0; i < val.length; i++) { + if ((val[i] - p) >= 0) + if (((val[i] - p) / 2) < (p - 1)) { + if (s > 0 && (((val[i] - p) / 2)+2) >= p) { + s--; + count++; + } + } else + count++; + } + return count; + } +} +" +A20077,"import java.util.Arrays; +import java.util.Scanner; + + +public class dancingWithTheGooglers { + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int nCases = in.nextInt(); + for (int c = 0; c < nCases; c++) { + int n = in.nextInt(); + int s = in.nextInt(); + int min = in.nextInt(); + //System.out.printf(""%d is the best result we're looking for\n"", min); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = in.nextInt(); + } + Arrays.sort(t); + int unsurprisingMinTotal = min + 2*(min-1 < 0 ? 0 : min-1); + int surprisingMinTotal = min + 2*(min-2 < 0 ? 0 : min-2); + int count = 0; + int surprisesLeft = s; + while (surprisesLeft >= 0) { + if (t[t.length-1-count] >= unsurprisingMinTotal) { + //System.out.printf(""%d is unsurprising\n"", t[t.length-1-count]); + count++; + } else if(t[t.length-1-count] >= surprisingMinTotal && surprisesLeft > 0) { + //System.out.printf(""%d is surprising\n"", t[t.length-1-count]); + surprisesLeft--; + count++; + } else { + //System.out.printf(""%d is rejected\n"", t[t.length-1-count]); + surprisesLeft = -1; + } + + if (count >= t.length) { + break; + } + } + System.out.printf(""Case #%d: %d\n"", c+1, count); + } + } +} +" +A22433,"import java.io.*; +import java.util.*; + +public class B_Qual { + static int n, s, score; + static int inf = 1 << 25; + static int[][] dp = new int[128][128]; + static int[] points=new int[128]; + public static int go(int index, int surprise) { + if(surprise>s)return -inf; + if (index == n) { + if (surprise == s) + return 0; + return -inf; + } + if (dp[index][surprise] != -1) + return dp[index][surprise]; + int res = 0; + for (int i = 0; i <= 10; i++) { + for (int j = -1; j <= 1; j++) { + for (int k = -1; k <= 1; k++) { + int a = i, b = i + j, c = i + k; + int max = Math.max(Math.max(a, b), c); + if (a+b+c==points[index]&&ValidTriple(a,b,c)&&!surp(a,b,c)) { + if (max >= score) + res = Math.max(res, 1 + go(index + 1, surprise)); + else + res = Math.max(res, go(index + 1, surprise)); + } + } + } + } + for (int i = 0; i <= 10; i++) { + for (int j = -2; j <= 2; j ++) { + for (int k = -2; k <= 2; k ++) { + int a = i, b = i + j, c = i + k; + int max = Math.max(Math.max(a, b), c); + if (a+b+c==points[index]&&ValidTriple(a,b,c)&&surp(a,b,c)) { + if (max >= score) + res = Math.max(res, 1 + go(index + 1, surprise + 1)); + else + res = Math.max(res, go(index + 1, surprise + 1)); + } + } + } + } + return dp[index][surprise] = res; + } + + private static boolean surp(int a, int b, int c) { + int[] x={a,b,c}; + for (int i = 0; i < x.length; i++) { + for (int j = 0; j < x.length; j++) { + if(x[i]-x[j]==2)return true; + } + } + return false; + } + + private static boolean ValidTriple(int a, int b, int c) { + int[] x={a,b,c}; + Arrays.sort(x); + for (int i = 0; i < x.length; i++) { + if(!valid(x[i])) + return false; + } + for (int i = 0; i < x.length; i++) { + for (int j = i+1; j < x.length; j++) { + if(x[j]-x[i]>2) + return false; + } + } + return true; + } + + private static boolean valid(int a) { + return a >= 0 && a <= 10; + } + + public static void main(String[] args) throws IOException { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for (int tt = 1; tt <= T; tt++) { + for (int[] x : dp) + Arrays.fill(x, -1); + n = in.nextInt(); + s = in.nextInt(); + score = in.nextInt(); + for(int i=0;i= p) { + total++; + } else if (scores[j]/3 == p-1) { + if (scores[j]%3 >= 1) { + total++; + } else { + if (s > 0) { + s--; + total++; + } + } + + } else if (scores[j]/3 == p-2) { + if (scores[j]%3 >= 2) { + if (s > 0) { + s--; + total++; + } + } + } + } + + out.write(total + "" \n""); + } + out.close(); + + } + +} +" +A22623,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class Dancing +{ + public static void main(String[] args) throws FileNotFoundException + { + Scanner sc = new Scanner(new File(""inputs/dancing.in"")); + + int cases = sc.nextInt(); + + for (int i = 1; i <= cases; i++) + { + int googs = sc.nextInt(); + int surprises = sc.nextInt(); + int min = sc.nextInt(); + + int num = 0; + + for (int j = 0; j < googs; j++) + { + int curr = sc.nextInt(); + + int remain = curr - min; + + if (remain < 0) + { + continue; + } + else if (remain / 2 >= (min - 1)) + { + num++; + } + else if (surprises > 0 && (remain / 2 == (min - 2))) + { + num++; + surprises--; + } + } + + System.out.printf(""Case #%s: %s\n"", i, num); + } + } +} +" +A20776,"import java.io.FileReader; +import java.io.BufferedReader; +import java.io.FileWriter; +import java.io.BufferedWriter; + +public class DancingGooglers { + + /** + * @param args + */ + public static void main(String[] args) { + try{ + //read file + FileReader filein = new FileReader(args[0]); + BufferedReader in = new BufferedReader(filein); + //write file + FileWriter fileout = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fileout); + //process data + int numcases = Integer.valueOf(in.readLine()).intValue(); + for(int i=0; i max) max = googlers[j][1]; + if(googlers[j][1] < min) min = googlers[j][1]; + googlers[j][2] = Integer.valueOf(casedata[3+j])-googlers[j][0]-googlers[j][1]; + if(googlers[j][2] > max) max = googlers[j][2]; + if(googlers[j][2] < min) min = googlers[j][2]; + googlers[j][0] = max; + googlers[j][1] = Integer.valueOf(casedata[3+j]) - max -min; + googlers[j][2] = min; + googlers[j][3] = max - min; + if(max - min > 1) surprises++; + } + while(surprises < totalsurprises){ + int test = 0; + for(int j=0; j 0 ){ + surprises++; + googlers[j][0]++; + googlers[j][1]--; + googlers[j][3] = 2; + test = 1; + break; + } + } + if(test == 0) break; + } + int result = 0; + for(int j=0; j= bestresult){ + result++; + } + } + out.write(""Case #"" + (i+1) + "": "" + result + ""\n""); + } + //Close the output stream + out.close(); + //Close the input stream + in.close(); + }catch (Exception e){//Catch exception if any + System.err.println(""Error: "" + e.getMessage()); + } + } +} +" +A21101," +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Scanner; + +public class DancingGooglers { + public static void main(String[] args) throws FileNotFoundException { + int T; + //Scanner sc = new Scanner(System.in); + Scanner sc = new Scanner(new File(""input.in"")); + T=sc.nextInt(); + + for( int i=0;i=0;j--) { + if(ti[j]/3>=p) { + count++; + } + else if(ti[j]==0) { + break; + } + else{ + float temp = ((float) ti[j])/3; + if(p-temp<.9) { + count++; + } + else if(p-temp==1 || p-temp<1.4) { + if(S>0) { + count++; + S--; + } + } + } + } + System.out.println(""Case #""+(i+1)+"": ""+count); + } + + } +} +" +A21263,"/** + * + */ +package codejam2012.qualification; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * @author Jaffar Ramay + * + */ +public class DancingWithTheGooglers { + + public static int[] giveBreakDown(int number, int maxScore, boolean getSurprising){ + + int[] array = null; + outer: for (int i = 0; i <= 10; i++) { + for (int j = 0; j <= 10; j++) { + for (int k = 0; k <= 10; k++) { + if(number==(i+j+k)){ + + if((i-j>2 || i-k>2 || j-i>2 || j-k>2 || k-i>2 || k-j>2)){ + continue; + }else if(i>=maxScore || j>=maxScore || k>=maxScore){ + if((i-j==2 || i-k==2 || j-i==2 || j-k==2 || k-i==2 || k-j==2)){ + if(getSurprising){ + array = new int[3]; + array[0] = i; + array[1] = j; + array[2] = k; + break outer; + } + }else if(!getSurprising){ + array = new int[3]; + array[0] = i; + array[1] = j; + array[2] = k; + break outer; + + } + } + } + + + } + } + + } + return array; + + } + + public static void solve() throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File(""/Users/jaffar_ramay/Workspaces/eclipseWorkspace/Revision/src/codejam2012/qualification/DancingWithTheGooglers.in""))); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(""/Users/jaffar_ramay/Workspaces/eclipseWorkspace/Revision/src/codejam2012/qualification/DancingWithTheGooglers.out""))); + StringBuffer output; + String line = null; + while((line=reader.readLine())!=null){ + int testCases = Integer.parseInt(line); + for (int i = 1; i <= testCases; i++) { + String[] testCase = reader.readLine().split("" ""); + int NumberOfGooglers = Integer.parseInt(testCase[0]); + int SurprisingTripplets = Integer.parseInt(testCase[1]); + int BestResultP = Integer.parseInt(testCase[2]); + int gotAtleastBestScore = 0; + for (int j = 0; j < NumberOfGooglers; j++) { + int scoreByJudges = Integer.parseInt(testCase[j+3]); + int[] array = null; + + array = giveBreakDown(scoreByJudges,BestResultP,false); + if(array==null){ + if(SurprisingTripplets>0){ + array = giveBreakDown(scoreByJudges,BestResultP,true); + if(array!=null) + SurprisingTripplets--; + } + } + if(array==null){ + array = giveBreakDown(scoreByJudges,-1,false); + } + if(array==null){ + if(SurprisingTripplets>0){ + array = giveBreakDown(scoreByJudges,-1,true); + if(array!=null) + SurprisingTripplets--; + } + } + if(array[0]>=BestResultP||array[1]>=BestResultP||array[2]>=BestResultP){ + gotAtleastBestScore++; + } + } + + writer.write(""Case #""+i+"": ""+gotAtleastBestScore); + if(i= (p*3)-2) + c++; + else if((g[i] >= (p*3)-4) && s > 0 && g[i]!=0) + { + c++; + s--; + } +// gd[i] = ((double)g[i])/3; + } + +// java.util.Arrays.sort(gd); +//// java.util.Arrays.sort(g); +// +// for(int i = n-1;i>=0;i--) +// { +// if((gd[i] > p) || ((double)p - gd[i] < 1)) +// { +// c++; +// } +// else if((s > 0) && (((double)p-gd[i]) <=1.333333333333334) && gd[i] != 0) +// { +// c++; +// s--; +// } +// else +// break; +// } + + System.out.println(""Case #""+(a+1)+"": "" + c); + } + + } + +} +" +A22122,"import java.util.Scanner; + +public class B { + + private static Scanner in = new Scanner(System.in); + + private static void solve(int no) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + + int ans = 0; + for (int i = 0; i < N; i++) { + int sum = in.nextInt(); + int avr = sum / 3; + int rem = sum % 3; + switch (rem) { + case 0: + if (avr >= p) { + ans++; + } else if (S > 0 && avr > 0 && avr + 1 >= p) { + ans++; + S--; + } + break; + case 1: + if (avr + 1 >= p) { + ans++; + } + break; + case 2: + if (avr + 1 >= p) { + ans++; + } else if (S > 0 && avr + 2 >= p) { + ans++; + S--; + } + break; + } + } + System.out.printf(""Case #%d: %d%n"", no, ans); + } + + public static void main(String[] args) { + int T = in.nextInt(); + for (int i = 0; i < T; i++) { + solve(i + 1); + } + } + +} +" +A21067,"package com.googlecode.codejam.contest.gcj2012.round_q; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.concurrent.Callable; + +import com.googlecode.codejam.model.JamCaseResolver; +import com.googlecode.codejam.model.JamCaseResolverFactory; +import com.googlecode.codejam.model.JamResolver; + +public class B extends JamCaseResolver { + + private final int s; // surprising + private final int p; // score limit + + private final int[] scores; + + public B(final int caseNumber, final Iterator lineIterator) { + super(caseNumber); + int[] input = this.parseInt(lineIterator.next().split("" "")); + s = input[1]; + p = input[2]; + scores = Arrays.copyOfRange(input, 3, input.length); + } + + @Override + protected String resolve() { + int surprisingUsed = s; + int result = 0; + for (int score : scores) { + if(score < 2) { + if(score >= p) + result++; + continue; + } + double avg = Math.ceil(score / 3.0); + + if(avg >= p) { + result++; + } else if (surprisingUsed > 0 && avg + 1 >= p && (score - 1) % 3 != 0) { + result++; + surprisingUsed--; + } + } + return String.valueOf(result); + } + + public static void main(String[] args) throws Exception { + final JamCaseResolverFactory factory = new JamCaseResolverFactory() { + @Override + public Callable newJamCaseResolver(int caseNumber, Iterator lineIterator) { + return new B(caseNumber, lineIterator); + } + }; + final JamResolver jamResolver = new JamResolver(factory, ""gcj2012/round_q"", ""B-large.in""); + jamResolver.resolve(); + } + +} +" +A20155,"import java.util.*; +import java.io.*; + +public class CodeJam { + public static void main(String[] args) { + try { + //recycleLarge(1000000, 2000000); + // read + FileInputStream instream = new FileInputStream(""A-small.in""); + DataInputStream in = new DataInputStream(instream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + // write + FileOutputStream outstream = new FileOutputStream(""A-small.out""); + DataOutputStream out = new DataOutputStream(outstream); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); + + // reading file information + int testcases = Integer.parseInt(br.readLine()); + for (int i = 0; i < testcases; i++) { + // ------------------------------------------------------------------------------------------------------------- + String line = br.readLine(); + String[] items = line.split("" ""); + int N = Integer.parseInt(items[0]); + int S = Integer.parseInt(items[1]); + int p = Integer.parseInt(items[2]); + long howManyP = 0; + if (p == 0) { + howManyP = N; + } else { + for(int j=3; j 0) { + howManyP++; + } + } else { + int relaxedScore = (3 * p) - 2; + int minimumScore = (3 * p) - 4; + if (score >= relaxedScore) howManyP++; + else if (score >= minimumScore && S > 0) { + howManyP++; S--; + } + } + } + } + + + // ------------------------------------------------------------------------------------------------------------- + bw.write(""Case #"" + (i + 1) + "": "" + howManyP + ""\r\n""); + } + + // close input file + in.close(); + // close output file + bw.flush(); + out.close(); + } catch (Exception e) { + System.err.println(""Error: "" + e.getMessage()); + } + } + + + private static void printArray(Object[] array) { + for (Object ch : array) + System.out.print(ch); + } + + +} + +" +A20540,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.*; +public class B { + public static void main(String[] args) throws Exception { + Scanner sc = new Scanner(new File(""B.in"")); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(""B.out""))); + int C = sc.nextInt(); + for(int i=1;i<=C;i++){ + int N = sc.nextInt(); + int S = sc.nextInt(); + int B = sc.nextInt(); + boolean[] pass = new boolean[N]; + boolean[] wierd = new boolean[N]; + troll:for(int a=0;a10||c<0)continue; + for(int d=b-2;d<=b+2;d++){ + + if(d>10||d<0)continue; + if(b+c+d!=P)continue; + int small = Math.min(Math.min(b,c),d); + int big = Math.max(Math.max(b,c),d); + // System.out.println(b+"" ""+c+"" ""+d); + if(big>=B){ + if(big-small==2){ + + // System.out.println(b+"" ""+c+"" ""+d); + wierd[a]=true; + } + else if(big-small<2){ + pass[a]=true; + // System.out.println(b+"" ""+c+"" ""+d); + continue troll; + } + } + } + } + } + } + // System.out.println(Arrays.toString(pass)); + // System.out.println(Arrays.toString(wierd)); + int ans = 0; + int used = 0; + for(int a=0;a scores = new ArrayList(); + + for (int i = 1; i <= total; i++) { + int result = 0; + + totGooglers = in.nextInt(); + totStriplets = in.nextInt(); + totPoints = in.nextInt(); + + for (int j = 0; j < totGooglers; j++) { + int [] tot = new int[2]; + pointsGooglers = in.nextInt(); + int auxPointsGooglers = pointsGooglers; + int aux = 0; + + for (int k = 0; k < 3; k++) { + if(auxPointsGooglers%3==0){ + auxPointsGooglers = auxPointsGooglers/3; + break; + }else if(auxPointsGooglers>0){ + aux++; + auxPointsGooglers--; + } + } + + tot = new int[]{auxPointsGooglers, auxPointsGooglers, auxPointsGooglers}; + + if(aux==2){ + tot[0]++; + tot[1]++; + }else if(aux==1){ + tot[0]++; + } + + scores.add(tot); + } + + int auxTotStriplets = totStriplets; + int auxResult = 0; + for (int[] js : scores) { + + for (int k : js) { + if(k>=totPoints){ + auxResult++; + } + } + + if(auxResult==0){ + if(auxTotStriplets>0){ + if(((js[1]-1)>=0 || (js[2]-1)>=0)){ + if((js[0]+1)>=totPoints){ + if(js[2]>js[1] || js[2]==js[0]){ + js[2]--; + auxTotStriplets--; + js[0]++; + }else if(js[1]>js[2]){ + js[1]--; + auxTotStriplets--; + js[0]++; + } + } + } + } + } + + auxResult = 0; + + } + + for (int[] js : scores) { + for (int k : js) { + if(k>=totPoints){ + result++; + break; + } + } + } + + scores.clear(); + + System.out.format(""Case #%d: %s\n"", i, result); + } + } +} +" +A21465,"package codejam.dancing; + +import codejam.is.TestRunner; + +/** + * Created with IntelliJ IDEA. + * User: ofer + * Date: 4/14/12 + * Time: 4:54 AM + * To change this template use File | Settings | File Templates. + */ +public class Main { + private static final String path = ""C:\\Users\\his\\Desktop\\codejam\\files\\""; + private static final String filePrefix = ""test""; + + private static final String inputFile = path + filePrefix + "".in""; + private static final String outputFile = path + filePrefix + "".out""; + + + public static void main(String[] args){ + + + TestRunner testRunner = new TestRunner(); + testRunner.runTests(inputFile, outputFile, DancingTest.class); + + } +} +" +A22248,"import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; + + +public class Prob1B { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new FileReader(""B-large.in"")); + PrintWriter pw = new PrintWriter(new FileWriter(""output.txt"")); + int t = Integer.parseInt(br.readLine()); + for(int x = 1; x <= t; x++) { + String[] strs = br.readLine().split("" ""); + int n = Integer.parseInt(strs[0]); + int s = Integer.parseInt(strs[1]); + int p = Integer.parseInt(strs[2]); + int[] scores = new int[n]; + for(int i = 0; i < scores.length; i++) { + scores[i] = Integer.parseInt(strs[3 + i]); + } + + int minNormalScore = Math.max(3 * p - 2, p); + int surprisingMinScore = Math.max(3 * p - 4, p); + int res = 0; + for(int i = 0; i < scores.length; i++) { + if(scores[i] >= minNormalScore) { + res++; + } else if(scores[i] >= surprisingMinScore && s > 0) { + s--; + res++; + } + } + + pw.println(""Case #"" + x + "": "" + res); + } + + br.close(); + pw.close(); + } +} +" +A23049,"import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Scanner; + +public class B { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // TODO Auto-generated method stub + Scanner scan = new Scanner(new File(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""B.out"")); + int t = scan.nextInt(); + for (int i = 1; i <= t; i++) { + int N = scan.nextInt(); + int S = scan.nextInt(); + int p = scan.nextInt(); + int surpMin = p*3 - 4; + int normMin = p*3 - 2; + int ans = 0; + for(int j = 0; j < N; j++){ + int sum = scan.nextInt(); + if(p==0){ + ans++; + } + else if(sum >= normMin){ + ans++; + } + else if((sum >= surpMin) && (p != 1 || sum > 0) && S > 0){ + ans++; + S--; + } + } + out.write(""Case #"" + i + "": ""+ ans + ""\n""); + } + out.close(); + } +} +" +A20572,"package CaseSolvers; + +import Controller.IO; + +public class GooglereseCase extends CaseSolver { + + static Character[] opa; + static { + opa = new Character[26]; + opa['a' - 97] = 'y'; + opa['b' - 97] = 'h'; + opa['c' - 97] = 'e'; + opa['d' - 97] = 's'; + opa['e' - 97] = 'o'; + opa['f' - 97] = 'c'; + opa['g' - 97] = 'v'; + opa['h' - 97] = 'x'; + opa['i' - 97] = 'd'; + opa['j' - 97] = 'u'; + opa['k' - 97] = 'i'; + opa['l' - 97] = 'g'; + opa['m' - 97] = 'l'; + opa['n' - 97] = 'b'; + opa['o' - 97] = 'k'; + opa['p' - 97] = 'r'; + opa['q' - 97] = 'z'; + opa['r' - 97] = 't'; + opa['s' - 97] = 'n'; + opa['t' - 97] = 'w'; + opa['u' - 97] = 'j'; + opa['v' - 97] = 'p'; + opa['w' - 97] = 'f'; + opa['x' - 97] = 'm'; + opa['y' - 97] = 'a'; + opa['z' - 97] = 'q'; + } + + StringBuilder line; + + public GooglereseCase(int order, int numberOfLines, IO io) { + super(order, numberOfLines, io); + } + + @Override + public void addLine(String line) { + this.line = new StringBuilder(line); + } + + @Override + public void printSolution() { + System.err.println(""Case #"" + getOrder() + "": "" + line); + } + + @Override + public CaseSolver process() { + for (int i = 0; i < line.length(); i++) { + char temp = line.charAt(i); + if (temp != ' ') + line.setCharAt(i, opa[temp - 97]); + } + return this; + } + + @Override + public void initializeVars() { + // TODO Auto-generated method stub + + } + +} +" +A22564,"import java.util.Scanner; + + +public class B_Dancing { + + static boolean enoughNonSurprising(int p, int score) { + return score >= 3*p-2; + } + static boolean enoughSurprising(int p, int score) { + return score >= 3*p-4; + } + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + boolean firstline = true; + for (int cas = 1; cas <= T; cas++) { + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int enoughNS = 0; + int enoughS = 0; + for (int i = 0; i < N; i++) { + int score = in.nextInt(); + if (enoughNonSurprising(p,score)) + enoughNS++; + else if (p > 1 && enoughS < S && enoughSurprising(p,score)) + enoughS++; + } + if (firstline) + firstline = false; + else + System.out.println(); + System.out.print(""Case #""+cas+"": ""+(enoughNS+enoughS)); + } + } + +} +" +A21527,"package Testc; + + +import java.util.Scanner; + +public class CodeB { + public static void main(String[] args) { + int numT=0; + Scanner kb=new Scanner(System.in); + numT=kb.nextInt(); + for(int i=0;i=0;k--){ + int max=0; + for(int l=0;l<=k;l++){ + if(scores[l]>=scores[k]&&scores[l]>=scores[max]) + max=l; + } + int temp=scores[max]; + scores[max]=scores[k]; + scores[k]=temp; + } + + + int indexscore=0; + int count = 0; + int lastscore = scores.length-1; + int count2=0; + if(surprising>0){ + for(int v=0;v count2) + result = count; + else + result=count2; + + System.out.println(""Case #""+(i+1)+"":""+"" ""+count); + } + + + + + } + + + public static boolean cal_surprise(int sum, int p) { + int a = 0; + int b = 0; + int c = 0; + for (a = 0; a <= 10; a++) { + for (b = 0; b <= 10; b++) { + for (c = 0; c <= 10; c++) { + if (a + b + c == sum && (Math.abs(a - b) == 2) && Math.abs(b - c) <= 2 && Math.abs(a - c) <= 2) { + //System.out.println(""sum:""+sum+"" a=""+a+"" b=""+b+"" c=""+c); + if (a >= p || b >= p || c >= p) return true; + else return false; + } + } + } + } + return false; + + } + + public static boolean cal_(int sum, int p) { + int a = 0; + int b = 0; + int c = 0; + for (a = 0; a <= 10; a++) { + for (b = 0; b <= 10; b++) { + for(c = 0; c <= 10; c++) { + if (a + b + c == sum && (Math.abs(a - b) <= 1) && Math.abs(b - c) <= 1 && Math.abs(a - c) <= 1) { + //System.out.println(""sum:""+sum+"" a=""+a+"" b=""+b+"" c=""+c); + if (a >= p || b >= p || c >= p) return true; + else return false; + } + + } + } + } + return false; + } +} + +" +A20702,"import java.io.*; +import java.util.StringTokenizer; + +/** + * @author Ivan Romanov + */ +public class B { + + private String solve(int n) throws IOException { + int s = nextInt(); + int p = nextInt(); + int[] t = new int[n]; + for (int i = 0; i < n; i++) { + t[i] = nextInt(); + } + int cool = 0; + for (int x : t) { + int rem3 = x % 3; + int max = x / 3; + if (rem3 > 0) { + max++; + } + // no surprise + if (max >= p) { + cool++; + } else if (s > 0) { + // try surprise + if (rem3 == 0 && x > 0) { + max++; + } else if (rem3 == 2) { + max++; + } + if (max >= p) { + cool++; + s--; + } + } + } + return """" + cool; + } + + private BufferedReader reader; + + private StringTokenizer tt = new StringTokenizer(""""); + + private String nextToken() throws IOException { + while (!tt.hasMoreTokens()) { + tt = new StringTokenizer(reader.readLine()); + } + return tt.nextToken(); + } + + private int nextInt() throws IOException { + return Integer.parseInt(nextToken()); + } + + private void run() throws IOException { + String problem = ""B-large""; + reader = new BufferedReader(new FileReader(problem + "".in"")); + PrintWriter writer = new PrintWriter(new File(problem + "".out"")); + try { + int cases = nextInt(); + int tc = 1; + while (tc <= cases) { + writer.print(""Case #"" + tc + "": ""); + int n = nextInt(); + writer.println(solve(n)); + tc++; + } + } finally { + reader.close(); + writer.close(); + } + } + + public static void main(String[] args) { + try { + new B().run(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +}" +A20509,"import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class ProbB { + static int[][] SurprisingCombinations = {{0,0,2},{0,1,2},{0,2,2}}; + static int[][] notSurprisingCombinations = {{0,0,0},{0,0,1},{0,1,1}}; + public static void main(String[] args) { + PrintWriter out; + try { + out = new PrintWriter(new FileWriter(""d:\\codejam2012\\outputfile.txt"")); + Scanner scanner = new Scanner(new File(""d:\\codejam2012\\B-large.in"")); + + + int cases = scanner.nextInt(); + scanner.nextLine(); + + for (int i = 1; i <= cases; i++) { + int n = scanner.nextInt(), s = scanner.nextInt(), p = scanner.nextInt(); + int[] dancers = new int[n]; + for (int j = 0; j < dancers.length; j++) { + dancers[j] = scanner.nextInt(); + } + int sol = solve(dancers, n, s, p); + out.println(""Case #""+i+"": "" +sol); + } + + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + private static int solve(int[] dancers, int n, int s, int p) { + int ret = 0; + + for (int i = 0; i < dancers.length; i++) { + if(isDoneWithCombinations(notSurprisingCombinations,dancers[i], p)){ + //here not surprising sequence and can get atleast p + ret++; + }else if(isDoneWithCombinations(SurprisingCombinations,dancers[i], p) && s > 0){ + //here surprising sequence and can get atleast p + ret++; + s--; + } + } + return ret; + } + private static boolean isDoneWithCombinations(int[][] combinations, int seq, int p) { + boolean sol = false; + for (int i = 0; i < combinations.length; i++) { + int sub = 0; + for (int j = 0; j < combinations[i].length; j++) { + sub += combinations[i][j]; + } + if((seq - sub) >= 0 && (seq - sub)% 3 == 0 && ((seq - sub) / 3) + combinations[i][2] >= p){ + sol = true; + } + } + return sol; + } + +} +" +A20654,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + + +public class DancingWithGooglers { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + // BufferedInputStream in = new BufferedInputStream(new FileInputStream(""input.txt"")); + BufferedReader in = new BufferedReader(new FileReader(""B-large.in"")); + BufferedWriter out = new BufferedWriter(new FileWriter(""output.txt"")); + int t = Integer.parseInt(in.readLine()); + int cnt = 0; + while(t>0){ + t--; cnt++; + int ans = 0; + String s1 = in.readLine(); + String[] ss = s1.split("" ""); + int n = Integer.parseInt(ss[0]); + int s = Integer.parseInt(ss[1]); + int p = Integer.parseInt(ss[2]); + int [] x = new int[n]; + for(int i=0; i=p){ + ans++; + continue; + }else if(p-min==1 && extra>0){ + ans++; + continue; + }else if((s>0 && extra==0 && p-min==1 && min != 0) || (s>0 && extra==2 && p-min==2 && min !=0)){ + ans++; + s--; + continue; + } + } + out.write(""Case #""+ cnt +"": "" + ans+""\n""); + } + in.close(); + out.close(); + } + +} +" +A20893,"import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Scanner; + +public class ProblemB { + public static void main(String[] args) throws Exception { + + Scanner in = new Scanner( + // System.in + // new FileInputStream(""b-small.in"") + new FileInputStream(""b-large.in"")); + PrintStream out = new PrintStream( + // System.out + // new FileOutputStream(""b-small.out"") + new FileOutputStream(""b-large.out"")); + int T = in.nextInt(); + in.nextLine(); + + for (int i = 1; i <= T; i++) { + int res = 0; + int N = in.nextInt(); + int S = in.nextInt(); + int p = in.nextInt(); + int[] ts = new int[N]; + for (int j = 0; j < N; j++) + ts[j] = in.nextInt(); + in.nextLine(); + Arrays.sort(ts); + + int nscore = Math.max(p * 3 - 2, p); + int sscore = Math.max(p * 3 - 4, p); + + for (int j = N; --j >= 0;) { + if (ts[j] >= nscore) + res++; + else if (ts[j] >= sscore && S-- > 0) + res++; + else + break; + } + out.println(""Case #"" + i + "": "" + res); + } + } +} +" +A21048,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + + +public class Main { + static final String inputFilename = ""B-large.in""; + + static class DataSet { + public int bestScore, + specialScoreCount; + public int[] scores; + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(""<$DataSet:"") + .append(bestScore).append("", "") + .append(specialScoreCount).append("", ""); + if (null != scores) { + sb.append(""[""); + for (int i=0, n=scores.length; i"").toString(); + } + + public static DataSet parse(String input) { + if (null == input) return null; + + DataSet result = new DataSet(); + int begin = 0; + int end = input.indexOf(' '); + + int scoresCount = Integer.parseInt(input.substring(begin, end)); + begin = end + 1; + end = input.indexOf(' ', begin); + + result.specialScoreCount = Integer.parseInt(input.substring(begin, end)); + begin = end + 1; + end = input.indexOf(' ', begin); + + result.bestScore = Integer.parseInt(input.substring(begin, end)); + result.scores = new int[scoresCount]; + for (int i=0; i dataSets = new ArrayList(); + for (int i=0; i= set.bestScore) { + if (diff >= -1) + setResult++; + else if (diff >= -2 && usedSurprises < set.specialScoreCount) { + setResult++; + usedSurprises++; + } + } + } + writeLine(out, formatCase(i+1, setResult)); + } + closeWriter(out); + } + +} +" +A21141,"import java.io.File; +import java.util.*; + +public class ProblemB { + + public static void main(String[] args) throws Exception { + + Scanner sc = new Scanner(new File(""C:\\B-small-attempt0.in"")); + //Scanner sc = new Scanner(System.in); + int cases = Integer.parseInt(sc.nextLine().trim()); + for (int i = 0; i < cases; i++) { + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int[] val = new int[n]; + + for (int j = 0; j < n; j++) { + val[j] = sc.nextInt(); + } + System.out.println(""Case #"" + (i + 1) + "": "" + solve(s, p, val)); + } + } + + private static int solve(int s, int p, int[] val) { + + int ret = 0; + + for (int v : val) { + int x1 = 0; + + if (v < 2) { + x1 = v; + } else if (v > 28) { + x1 = 10; + } else if (v % 3 == 1) { + x1 = (v + 2) / 3; + } else if (v % 3 == 0) { + x1 = v / 3; + if ((x1 == p - 1) && (s > 0)) { + s--; + x1++; + } + } else { + x1 = (v + 1) / 3; + if ((x1 == p - 1) && (s > 0)) { + s--; + x1++; + } + } + if (x1 >= p) + ret++; + } + return ret; + } +} +" +A20988,"package fixjava; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Iterator; + +/** + * Iterator that iterates over the lines of the file and then closes it after the last line has been read. + * + * e.g. + * + * + * + * for (String line : new FileLineIterator(""in.txt"")) + * System.out.println(line); + * + * for (NumberedLine nl : new FileLineIterator(""in.txt"").withLineNumbers()) + * System.out.println(nl.getLineNum() + "" "" + nl.getLine()); + * + * + */ +public class FileLineIterator implements Iterable, Iterator { + + private BufferedReader reader; + String nextLine = null; + boolean nextLineAlreadyFetched = false; + private int lineNum = -1; + + // ------------------------------------------------------------------------------------------ + + /** + * Construct an iterator that iterates over the lines of the file and then closes it after the last line has been read. + * + * e.g. for (String line : new FileLineIterator(""in.txt"")) System.out.println(line); + * + * @throws IllegalArgumentException + * on any I/O exception, so you can use this directly in foreach loops. + */ + public FileLineIterator(String filename) { + this(new File(filename)); + } + + /** + * Construct an iterator that iterates over the lines of the file and then closes it after the last line has been read. + * + * e.g. for (String line : new FileLineIterator(file)) System.out.println(line); + * + * @throws IllegalArgumentException + * on any I/O exception, so you can use this directly in foreach loops. + */ + public FileLineIterator(File file) { + try { + reader = new BufferedReader(new FileReader(file), 1024 * 1024); + } catch (FileNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public Iterator iterator() { + return this; + } + + // ------------------------------------------------------------------------------------------ + + private String getNextLine(boolean consume) { + if (!nextLineAlreadyFetched) { + try { + nextLine = reader.readLine(); + lineNum++; + nextLineAlreadyFetched = true; + if (nextLine == null) + // Close reader after last line has been read + reader.close(); + } catch (IOException e) { + if (reader != null) + try { + reader.close(); + } catch (Exception e2) { + } + throw new IllegalArgumentException(e); + } + } + String retVal = nextLine; + if (consume) { + nextLine = null; + nextLineAlreadyFetched = false; + } + return retVal; + } + + /** Return the current zero-indexed line number -- only returns the correct line number after a call to hasNext() or next() */ + public int getLineNum() { + return lineNum; + } + + @Override + public boolean hasNext() { + return getNextLine(false) != null; + } + + @Override + public String next() { + return getNextLine(true); + } + + @Override + public void remove() { + getNextLine(true); + } + + // ------------------------------------------------------------------------------------------ + + public class NumberedLine { + String line; + int lineNum; + + public NumberedLine(String line, int lineNum) { + this.line = line; + this.lineNum = lineNum; + } + + public String getLine() { + return line; + } + + public int getLineNum() { + return lineNum; + } + } + + /** Return an Iterable that includes the line number with each line */ + public Iterable withLineNumbers() { + final FileLineIterator fileLineIter = this; + return new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + @Override + public void remove() { + fileLineIter.remove(); + } + + @Override + public NumberedLine next() { + String line = fileLineIter.next(); + int lineNum = fileLineIter.getLineNum(); + return new NumberedLine(line, lineNum); + } + + @Override + public boolean hasNext() { + return fileLineIter.hasNext(); + } + }; + } + }; + } +} +" +A20198,"package qualification.problemB; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class ProblemB { + + static int num; + static String[] lines; + + static String dir = ""./src/qualification/problemB""; + static String inTxt = dir + ""/B-large.in""; + static String outTxt = dir + ""/B-large.out""; +// static String inTxt = dir + ""/ex_probb.txt""; +// static String outTxt = dir + ""/ex_probb_ans.txt""; + + public static void main(String[] args) { + input(inTxt); + String[] ansStrs = new String[num]; + for (int i = 0; i < lines.length; i++) { + String[] strs = lines[i].split(""\\s""); + int[] nums = new int[strs.length]; + for (int j = 0; j < strs.length; j++) { + nums[j] = Integer.valueOf(strs[j]); + } + int ans = solve(nums[0], nums[1], nums[2], Arrays.copyOfRange(nums, 3, nums.length)); + ansStrs[i] = String.valueOf(ans); + } + output(outTxt, ansStrs); + } + + static void input(String fname) { + try { + BufferedReader br = new BufferedReader( + new InputStreamReader( + new FileInputStream(fname))); + String line = br.readLine(); + num = Integer.valueOf(line); + System.out.println(num); + lines = new String[num]; + for (int i = 0; i < num; i++) { + lines[i] = br.readLine(); + System.out.println(lines[i]); + } + br.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + static void output(String fname, String[] output) { + File outFile = new File(fname); + try { + FileWriter fw = new FileWriter(outFile); + for (int i = 0; i < num && i < output.length; i++) { + String out = ""Case #""+(i+1)+ "": "" + output[i] + '\n'; + System.out.print(out); + fw.write(out); + fw.flush(); + } + fw.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static int solve(int num, int sup, int better, int[] scores) { + int count = 0; + for (int i = 0; i < num; i++) { + int score = scores[i] - better; + if (2 * better <= score) { + count++; + } else if (1 <= better && 2 * (better - 1) <= score) { + count++; + } else if (2 <= better && 0 < sup && 2 * (better - 2) <= score) { + count++; + sup--; + } + } + return count; + } +} +" +A22001,"import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + + +public class GoogleDance { + + public static void main(String[] args) { + File inputFile = new File(""input.txt""); + Scanner s; + + try { + s = new Scanner(inputFile); + int lineCount = s.nextInt(); + s.nextLine(); + + int googlers, surprising, target, max; + int score; + + for(int i = 1; i <= lineCount; i++) { + max = 0; + googlers = s.nextInt(); + surprising = s.nextInt(); + target = s.nextInt(); + + for(int j = 0; j < googlers; j++) { + score = s.nextInt(); + + if(score == 0 && target == 0) max++; + else if(score <= target) continue; + else if(score / 3 >= target) max++; + else { + score -= target; + if(score/2 >= target) + max++; + else if(Math.abs(score/2 - target) < 2) + max++; + else if(surprising > 0 && Math.abs(score/2 - target) < 3) { + max++; + surprising--; + } + } + } + + System.out.println(""Case #""+i+"": ""+max); + } + + s.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } +} +" +A21923,"/** + * + */ +package code.google.codejam; + +import java.util.Arrays; + +/** + * @author sunilkumarp + * + */ +public class Dancing extends Template { + + int N = 0; + + int S = 0; + + int P = 0; + + int[] scores = null; + + int minscoreReqForP = 0; + + /* (non-Javadoc) + * @see code.google.codejam.Template#doSolveProblem() + */ + @Override + protected Object doSolveProblem() throws Exception { + int cannotGetPButCanGetS = 0; + + + int count = 0; + int canGetP = 0; + + int i = 0; + for (; i < N; ++i) { + int score = scores[i]; + if (score >= minscoreReqForP) { + canGetP = N - i; + break; + } + if (score > 1) { + cannotGetPButCanGetS++; + } + } + + + + if (canGetP > 0) { + int canGetPWithoutSAndWithS = 0; + int canGetPWithS = 0; //signifies can't get P without S + int canGetPWithoutS = 0; // signifies can't get P with S // Doesn't matter as doesn't affect 'S' + //int cantGetPWithoutS = 0; + for (int j = N -1; j >= N-canGetP; --j) { + int score = scores[j]; + if (score > 1) { + int mod = score % 3; + switch (mod) { + case 0: + if (score/3 < P) { + canGetPWithS++; + } else { + canGetPWithoutSAndWithS++; + } + break; + case 1: + canGetPWithoutSAndWithS++; + break; + case 2: + if (score/3 + 1 < P) { + if (score/3 + 2 < P) { + // Not possible + throw new IllegalStateException(""must be something wrong""); + } else { + canGetPWithS++; + } + } else { + canGetPWithoutSAndWithS++; + } + break; + } + } else { + canGetPWithoutS++; + } + } + + if (canGetPWithS <= S) { + count = canGetP; + } else { + count = canGetP - (canGetPWithS - S); + count = count >= 0 ? count : 0; + } + } + + + + return count; + } + + /* (non-Javadoc) + * @see code.google.codejam.Template#printInput() + */ + @Override + protected void printInput() throws Exception { + System.out.println(""N-"" + N); + System.out.println(""S-"" + S); + System.out.println(""P-"" + P); + System.out.println(""Scores-"" + Arrays.toString(scores)); + } + + /* (non-Javadoc) + * @see code.google.codejam.Template#initializeTestCase() + */ + @Override + protected void initializeTestCase() throws Exception { + readLine(); + N = readNextInteger(); + S = readNextInteger(); + P = readNextInteger(); + minscoreReqForP = P == 1 ? 1 : (P == 0 ? 0 : 3 * P - 4); + scores = new int[N]; + for (int i = 0; i < N; ++i) { + scores[i] = readNextInteger(); + } + Arrays.sort(scores); + } + +} +" +A22053,"import java.util.Scanner; + +public class DancingWithTheGooglers { + public static void main(String[] args) { + + bestResultForScores(); + + new DancingWithTheGooglers().go(); + } + + public static int[] bestUnsurprisingResultForScore = new int[31]; + public static int[] bestSurprisingResultForScore = new int[31]; + public static int[] upgradeBySurprise = new int[31]; + + private static void bestResultForScores() { + for (int a = 0; a <= 10; a++) + for (int b = 0; b <= 10; b++) + for (int c = 0; c <= 10; c++) { + int bestResult = Math.max(a, Math.max(b, c)); + int worstResult = Math.min(a, Math.min(b, c)); + int spread = bestResult - worstResult; + + int totalScore = a + b + c; + + switch (spread) { + case 0: + case 1: + if (bestResult > bestUnsurprisingResultForScore[totalScore]) + bestUnsurprisingResultForScore[totalScore] = bestResult; + break; + case 2: + if (bestResult > bestSurprisingResultForScore[totalScore]) + bestSurprisingResultForScore[totalScore] = bestResult; + } + } + + for(int i = 0; i < 31; i++) { + upgradeBySurprise[i] = Math.max(0, (bestSurprisingResultForScore[i] - bestUnsurprisingResultForScore[i])); + } + } + + private void go() { + Scanner sc = new Scanner(System.in); + + int numTestCases = Integer.parseInt(sc.nextLine()); + + for (int caseNum = 1; caseNum <= numTestCases; caseNum++) { + System.out.print(""Case #"" + caseNum + "": ""); + + int numGooglers = sc.nextInt(); + int numSurprisingTriplets = sc.nextInt(); + int p = sc.nextInt(); + + int[] totalPoints = new int[numGooglers]; + for (int i = 0; i < numGooglers; i++) { + totalPoints[i] = sc.nextInt(); + } + + int[] bestPossibleScores = new int[31]; + for (int i = 0; i < numGooglers; i++) { + bestPossibleScores[bestUnsurprisingResultForScore[totalPoints[i]]]++; + } + + int sum = 0; + for (int i = p; i < 31; i++) { + sum += bestPossibleScores[i]; + } + + for(int totalScore : totalPoints) { + if(bestUnsurprisingResultForScore[totalScore] == p-1 && bestSurprisingResultForScore[totalScore] == p && numSurprisingTriplets > 0) { + numSurprisingTriplets--; + sum++; + } + } + + System.out.println(sum); + } + } +} +" +A22283,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package googlers; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +/** + * + * @author Floran + */ +public class Googlers { + + int nbCase; + static String inName; + static String outName; + public final char h=(char) 104; + + public static void solve() throws IOException{ + PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(outName))); + //Scanner in=new Scanner(""A-small-practice.txt""); + BufferedReader in=new BufferedReader(new FileReader(inName)); + String ligne=in.readLine(); + // nb de cas + System.out.println(ligne); + int nbCase=Integer.parseInt(ligne); + //compte + int count=0; + for(int i=1;i<=nbCase;i++){ + int ns=0;//nb suprise + count=0; + String[] parametre=in.readLine().split("" ""); + System.out.println(""lenght""+parametre.length); + int nb=Integer.parseInt(parametre[0]);//nb de participant + System.out.println(""nb""+nb); + int suprise=Integer.parseInt(parametre[1]);//nb de triplet surprise + System.out.println(""sup""+suprise); + int min=Integer.parseInt(parametre[2]);//un quote du triplet doit être >=min + for(int m=3;m=min) + if(tab[0]>=min) + count++; + } + else{ + //if(tab[0][2]>=min) + if(tab[0]>=min) + count++; + //else if(tab[0][2]>=min &&ns<=suprise){ + else if(tab[1]>=min && ns= P) { + w++; + continue; + } + + if (a == P-1 && r > 0) { + w++; + continue; + } + + if (S == 0) + continue; + + int extra; + if (r == 0 && a > 0) + extra = 1; + else + extra = r; + if (a + extra >= P) { + w++; + S--; + } + } + out.println(w); + } + } + + static String read() { + try { return in.readLine(); } catch (IOException e) { return null; } + } + public static void main(String[] args) throws IOException { +// in = new BufferedReader(new InputStreamReader(System.in)); +// out = new PrintWriter(new BufferedOutputStream(System.out)); + String file = ""B-large""; + in = new BufferedReader( new FileReader(file + "".in"") ); + out = new PrintWriter( new FileOutputStream(file + ""_"" + System.currentTimeMillis() + "".out"") ); + solve(); out.flush(); + } + static BufferedReader in; static PrintWriter out; +} +" +A21631,"import java.io.*; +import java.util.Scanner; + +/** + * Created by IntelliJ IDEA. + * User: tanin + * Date: 4/14/12 + * Time: 9:22 AM + * To change this template use File | Settings | File Templates. + */ +public class Dancing { + + + public static void main(String[] args) throws Exception { + + String filename = ""dancing""; + String outFilename = filename + ""_out""; + + FileInputStream fis = new FileInputStream(new File(filename)); + Scanner input = new Scanner(new BufferedInputStream(fis)); + + FileOutputStream fOut = new FileOutputStream(new File(outFilename)); + BufferedOutputStream bOut = new BufferedOutputStream(fOut); + DataOutputStream out = new DataOutputStream(bOut); + + int numCases = input.nextInt(); + input.nextLine(); + + for (int caseNumber=0;caseNumber= p) { + count++; + } else { + + int maxSurprised = -1; + + if ((g[i]%3) == 0 && ((g[i] / 3) - 1) >= 0) maxSurprised = (g[i] / 3) + 1; + else if ((g[i]%3) == 1) maxSurprised = (g[i] / 3) + 1; + else if ((g[i]%3) == 2) maxSurprised = (g[i] / 3) + 2; + + if (maxSurprised >= p && s > 0) { + count++; + s--; + } + } + } + + return count; + } +} +" +A20138," +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.Scanner; + +/** + * + * @author violetlily + */ +public class Jam2012Q_B_S { + + private final String ipath = ""B-large.in""; + private final String opath = ""B-large.ou""; + + public void Handle() throws FileNotFoundException { + + PrintStream out = new PrintStream( + new BufferedOutputStream( + new FileOutputStream(opath))); + System.setOut(out); + + Scanner sc = new Scanner(new FileInputStream(new File(ipath))); + int m = sc.nextInt(); + int ii = 1; + while (m > 0) { + + int n = sc.nextInt(); + int s = sc.nextInt(); + int p = sc.nextInt(); + int c = 0; + while(n > 0){ + int t = sc.nextInt(); + if(t%3 == 0){ + if(t/3 >= p && t/3!= 0){ + c ++; + }else if(t/3 +1 >= p && s > 0 && t/3!= 0){ + c ++; + s--; + }else if(t == 0 && t/3 >= p){ + c ++; + } + } + else if(t%3 == 1){ + if(t/3 + 1 >=p ){ + c++; + } + }else{ + if(t/3 +1 >= p){ + c++; + }else if(t/3 + 2 >=p && s > 0){ + c++; + s--; + } + } + n--; + } + + System.out.println(""Case #"" + ii + "": "" + c ); + ii++; + m--; + } + out.close(); + } + + + public static void main(String args[]) throws Exception { + Jam2012Q_B_S t = new Jam2012Q_B_S(); + t.Handle(); + } +} +" +A20045,"import java.io.*; +import java.util.*; + +class B +{ + public static void main(String args[]) throws FileNotFoundException + { + Scanner in = new Scanner(new File(args[0])); + + int t; + + t = Integer.parseInt(in.nextLine()); + + for (int i=0; i0) + { + m++; + s--; + } + else if ( x == 1) + { + if (r==0 && d>0 && s>0) + { + m++; + s--; + } + else if (r > 0) + m++; + } + } + if (m > n) + m=n; + } + System.out.println(""Case #"" + (i+1) + "": "" + m); + } + + } +} +" +A21907,"package com.utility; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +public class FileWriterUtility { + + public static File getFile(String outputFileLoc) { + File outputFile = null; + if (outputFileLoc != null) { + outputFile = new File(outputFileLoc); + if (!outputFile.exists()) { + try { + outputFile.createNewFile(); + } catch (IOException e) { + System.out.println(""Error :"" + e.getMessage()); + } + } + } + return outputFile; + } + + public static File getNewFile(String outputFileLoc) { + File outputFile = null; + if (outputFileLoc != null) { + outputFile = new File(outputFileLoc); + if (!outputFile.exists()) { + try { + outputFile.delete(); + outputFile.createNewFile(); + } catch (IOException e) { + System.out.println(""Error :"" + e.getMessage()); + } + } + } + return outputFile; + } + + public static BufferedWriter getBufferedWriter(File outputFile) { + BufferedWriter bufferedWriter = null; + if (outputFile != null) { + FileWriter fileWriter; + try { + fileWriter = new FileWriter(outputFile); + bufferedWriter = new BufferedWriter(fileWriter); + } catch (IOException e) { + System.out.println(""Error :"" + e.getMessage()); + } + } + return bufferedWriter; + } + + public static BufferedWriter getBufferedWriter(String fileName) { + BufferedWriter bufferedWriter = null; + if (fileName != null) { + File file = new File(fileName); + bufferedWriter = getBufferedWriter(file); + } + return bufferedWriter; + } + + public static void write(BufferedWriter bufferedWriter, String outputString) { + if (bufferedWriter != null && outputString != null) { + try { + bufferedWriter.write(outputString); + } catch (IOException e) { + System.out.println(""Error :"" + e.getMessage()); + } + } + } + + public static void writeNewLine(BufferedWriter bufferedWriter) { + if (bufferedWriter != null) { + try { + bufferedWriter.write(""\n""); + } catch (IOException e) { + System.out.println(""Error :"" + e.getMessage()); + } + } + } + + public static void closeBufferedWriter(BufferedWriter bufferedWriter) { + if (bufferedWriter != null) { + try { + bufferedWriter.close(); + } catch (IOException e) { + System.out.println(""Error :"" + e.getMessage()); + } + } + } + +} +" +A21920,"package googler; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class Main { + + public static void main(String[] args) throws IOException { + + + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(""B-large.in"")))); + + br.readLine(); + String temp; + int nsurprise=0; + int best; + int googlers; + int usedmin; + int answer; + int casenumber=1; + + FileWriter fstream = new FileWriter(""output.txt""); + BufferedWriter out = new BufferedWriter(fstream); + + while((temp=br.readLine())!=null) + { + String arr[] = temp.split("" ""); + usedmin=0; + answer=0; + googlers = Integer.parseInt(arr[0]); + nsurprise = Integer.parseInt(arr[1]); + best = Integer.parseInt(arr[2]); + +// System.out.println(""best: "" + best); +// System.out.println(""arrlength: "" + arr.length); + + for(int j=arr.length-1;j>=3;j--) + { + int totalscore = Integer.parseInt(arr[j]); + + if(totalscore/3>=best) + { + answer++; + } + else if(totalscore!=0) + { + int eachscore = totalscore/3; + int thirdscore = totalscore - eachscore*2; + + if(thirdscore>=best && (thirdscore-eachscore)==2 && usedmin=best && (thirdscore-eachscore)==1) + { + answer++; + } + + else if(thirdscore==eachscore && usedmin=best) + { + answer++; + usedmin++; + } + } + else if(thirdscore-eachscore==2) + { + eachscore = eachscore+1; + thirdscore = thirdscore-2; + + if(eachscore>=best) + { + answer++; + } + } + } + + } + out.write(""Case #"" + casenumber + "": "" + answer); + //System.out.println(""Case #"" + casenumber + "": "" + answer); + out.newLine(); + casenumber++; + } + + out.close(); + } + +} +" +A23061,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package googlecodejam; + +/** + * + * @author Bhanu + */ + +import java.util.*; + +public class DancingGooglers { + +public static void main(String arg[]) throws Exception +{ + + int s1[] = {0,1,2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}; + int h1[] = {0,1,1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10}; + int s2[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28}; + int h2[] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10,10}; + + /*TreeSet st = new TreeSet(); + st.add(0); + int low = 0; + int high = 1; + for(;high <= 10;) + { + st.add(high + 2 * low); + + // System.out.println(""Adding "" + low +"" :""+ low + "": "" + high); + st.add(2* high + low); + //System.out.println(""Adding "" + low +"" :""+ high + "": "" + high); + + st.add(3 *high ); + //System.out.println(""Adding "" + high +"" :""+ high + "": "" + high); + + low = high; + high++; + + + } + + System.out.println(st); +*/ + + /*TreeSet st1 = new TreeSet(); + + for(int i = 2 ;i <= 10; i++) + { + st1.add(i + (i -2) + (i -2)); + System.out.println(""Adding "" + (i - 2) + "" "" + (i - 2) + "" "" + i); + + st1.add(i + (i -1) + (i -2)); + System.out.println(""Adding "" + (i - 2) + "" "" + (i - 1) + "" "" + i); + + st1.add(i + (i ) + (i -2)); + System.out.println(""Adding "" + (i - 2) + "" "" + (i ) + "" "" + i); + + } + System.out.println(st1); + System.out.println(st1.size()); + * + */ + + + java.io.BufferedReader bin = new java.io.BufferedReader(new java.io.InputStreamReader (System.in)); + int T = Integer.parseInt( bin.readLine() ); + for(int i = 1; i <= T ; i++) + { + String[] split = bin.readLine().split("" ""); + int N = Integer.parseInt(split[0]); + int S = Integer.parseInt(split[1]); + int p = Integer.parseInt(split[2]); + + int tot[] = new int[N]; + + for(int k = 3; k < split.length;k++) + { + tot[k - 3] = Integer.parseInt(split[k]); + } + + Arrays.sort(tot); + int count = 0; + + for(int k = N -1 ; k >= 0 ; k--) + { + int t = tot[k]; + boolean n1 = false; + boolean n2 = false; + if(h1[t] >= p) n1 = true; + + if( t >= 2 && t <= 28) + { + if( S > 0 && h2[t-2] >= p) n2 = true; + } + + if(n1 == false && n2 == false){ + + } + else if(n1 == false && n2 == true) + { + count++; + S--; + } + else if(n1 == true && n2 == false) + { + count++; + } + else if(n1 == true && n2 == true) + { + count++; + + } + } + + System.out.println(""Case #"" + i + "": "" + count); + } + +} + +} +" +A21572,"import java.util.*; +import java.io.*; + +public class B { + + private static int googlers(String s) { + StringTokenizer st = new StringTokenizer(s); + final int N = Integer.parseInt(st.nextToken()); + int S = Integer.parseInt(st.nextToken()); + int p = Integer.parseInt(st.nextToken()); + int score[] = new int[N]; + int r = 0; + for(int i = 0; i < N; i++) { + int z = score[i] = Integer.parseInt(st.nextToken()); + int a = z / 3; + int bn, bs; + switch(z % 3) { + case 0: + bn = a; + bs = a == 0 ? a : a + 1; + break; + case 1: + bn = a + 1; + bs = a + 1; + break; + //case 2: + default: + bn = a + 1; + bs = a + 2; + break; + } + if(bn >= p) + r++; + else if(bs >= p && S > 0) { + r++; + S--; + } + } + return r; + } + + public static void main(String args[]) throws Exception { + //String fileName = ""B.in""; + //String fileName = ""B-small-attempt0.in""; + String fileName = ""B-large.in""; + BufferedReader in = new BufferedReader(new FileReader(fileName)); + PrintStream out = new PrintStream(fileName.substring(0, fileName.lastIndexOf('.')) + "".out""); + int T = Integer.parseInt(in.readLine()); + for(int i = 1; i <= T; i++) { + out.print(""Case #"" + i + "": ""); + String s = in.readLine(); + out.println(googlers(s)); + } + out.close(); + in.close(); + } +}" +A21392,"package de.hg.codejam.tasks.io; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +public abstract class Writer { + + public static String generateOutputPath(String inputPath) { + return inputPath.substring(0, inputPath.lastIndexOf('.') + 1) + ""out""; + } + + public static void print(String[] output) { + for (String s : output) + System.out.println(s); + } + + public static void write(String[] output) { + for (int i = 0; i < output.length; i++) + System.out.println(getCase(i + 1, output[i])); + } + + public static void write(String[] output, String path) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(path, + false))) { + for (int i = 0; i < output.length; i++) { + writer.append(getCase(i + 1, output[i])); + writer.newLine(); + writer.flush(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + + private static String getCase(int number, String caseString) { + return ""Case #"" + (number) + "": "" + caseString; + } + +} +" +A21982,"import java.util.Scanner; + +public class B { + + /** + * @param args + */ + public static void main(String[] args) { + + Scanner in = new Scanner(System.in); + + int T = in.nextInt(); + + in.nextLine(); + + for (int i = 1; i <= T; i++) { + + int numDancers = in.nextInt(); + int numSurprisingTriplets = in.nextInt(); + int p = in.nextInt(); + int triplet, div, mod; + int res = 0; + + for (int j = 0; j < numDancers; j++) { + triplet = in.nextInt(); + + div = triplet / 3; + mod = triplet % 3; + + if (triplet != 0) { + if (div >= p) + res++; + else { + if (mod != 0) { + div++; + if (div >= p) + res++; + else { + mod--; + if (mod != 0) { + div++; + if (div >= p && numSurprisingTriplets > 0) { + res++; + numSurprisingTriplets--; + } + } + } + } else { + div++; + if (div >= p && numSurprisingTriplets > 0) { + res++; + numSurprisingTriplets--; + } + } + } + + } + else + if (p == 0) + res++; + } + System.out.println(""Case #"" + i + "": "" + res); + } + } + +} +" +A22343,"import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.Scanner; + +public class ProblemB { + + public static void main(String[] args) throws FileNotFoundException { + + String test = ""4\n"" + ""3 1 5 15 13 11\n"" + ""3 0 8 23 22 21\n"" + ""2 1 1 8 0\n"" + + ""6 2 8 29 20 8 18 18 21\n""; + + Scanner sc = new Scanner(new File(""B-large.in"")); + int teller = 0; + int numLines = 0; + String out = """"; + String finalOut = """"; + boolean print = false; + + int N = 0;// googlers + int S = 0;// suprising tripplet + int P = 0; // min score + + int A = 0; + String[] split; + + while (true) { + String line = sc.nextLine(); + if (teller == 0) { + numLines = Integer.valueOf(line); + } else { + print = true; + split = line.split("" ""); + N = Integer.valueOf(split[0]); + S = Integer.valueOf(split[1]); + P = Integer.valueOf(split[2]); + + for (int i = 3; i < split.length; i++) { + int score = Integer.valueOf(split[i]); + + if (P < 1) { + A++; + } else if (S > 0 && score > 0) { + if (score >= (P + P + P - 2)) { + A++; + } else if (score >= (P + P + P - 4)) { + A++; + S--; + } + } else if (score > 0) { + if (score >= (P + P + P - 2)) { + A++; + } + } + + } + } + + if (print) { + + if (teller == numLines) { + System.out.println(""Case #"" + teller + "": "" + A); + finalOut += ""Case #"" + teller + "": "" + A; + break; + } else { + System.out.println(""Case #"" + teller + "": "" + A); + finalOut += ""Case #"" + teller + "": "" + A + ""\n""; + } + A = 0; + + } + teller++; + } + + PrintWriter writer = new PrintWriter(new File(""out.txt"")); + + writer.print(finalOut); + writer.close(); + + } + +} +" +A21826,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package jam2012; +import jam.util.Utilities; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author sam + */ +public class DancingGooglers { + + private int T;//number of testcases + private int N;//number of googlers + private int S;//number of surprising triplets of scores + private int p;//best result for each case + private int[] scores; + private int ti;//score for each googler + private Scanner input; + private static Utilities utility=new Utilities(); + //method to calculate maximum number of googlers + + public void openFile() { + Scanner cin = new Scanner(System.in); + System.out.println(""Enter File Path containing test data: ""); + String filePath = cin.nextLine(); + try { + input = new Scanner(new File(filePath)); + } catch (FileNotFoundException ex) { + System.err.println(""Error opening file!""); + System.exit(1); + Logger.getLogger(DancingGooglers.class.getName()).log(Level.SEVERE, null, ex); + } + } +//small input + + public void readFile() throws Exception { + + if (input.hasNext()) { + //read number of test cases + T = input.nextInt(); + //enforce T limit + + //move to first case + int test_count = 0; + input.nextLine(); + //for each test case read N, S, p, and N values to array ti and call output method + while (input.hasNext() && (test_count <= T)) { + test_count++; + N = input.nextInt(); + //proceed for this input + S = input.nextInt(); + p = input.nextInt(); + scores = new int[N]; + //populate scores + for (int i = 0; i < N; i++) { + scores[i] = input.nextInt(); + } + Arrays.sort(scores); + //call output method + output(test_count, S, p, scores); + } + + } + } + + public void closeFile() { + input.close(); + } + + public void output(int test_case, int surprises, int best_result, int[] scores) throws Exception { + String output=""""; + if (p > 1) { + int q = p * 3 - 2; + int s = p * 3 - 4; + int count = 0; + int pt = N - 1; + + for (int i = N - 1; i >= 0; i--) { + if (scores[i] >= q) { + count++; + pt--; + } + } + while (pt >= 0 && scores[pt] >= s && S > 0) { + count++; + pt--; + S--; + } + output=""Case #"" + test_case + "": "" + count; + System.out.println(""Case #"" + test_case + "": "" + count); + // Utilities.writeToFile(""googld.in"",""Case #"" + test_case + "": "" + count); + } else if (p == 1) { + int j = 0; + for (j = 0; j < N; j++) { + if (scores[j] > 0) { + break; + } + + } + output=""Case #"" + test_case + "": "" + (N - j); + System.out.println(""Case #"" + test_case + "": "" + (N - j)); + //Utilities.writeToFile(""googled.in"",""Case #"" + test_case + "": "" + (N - j)); + } else if (p == 0) { + output=""Case #"" + test_case + "": "" + N; + System.out.println(""Case #"" + test_case + "": "" + N); + + } + Utilities.writeToFile(""googld.in"",output); + } + + public static void main(String[] str) throws Exception { + DancingGooglers dG = new DancingGooglers(); + dG.openFile(); + dG.readFile(); + dG.closeFile(); + } +} +" +A20499,"import java.util.*; + +public class B +{ + public static void main(String[] args) + { + Scanner in = new Scanner(System.in); + int T = in.nextInt(); + for(int c = 1; c <= T; c++){ + int n = in.nextInt(); + int s = in.nextInt(); + int p = in.nextInt(); + + int high = 0; + int low = 0; + + int ans; + + if(p < 2){ + int count = 0; + for(int i = 0; i < n; i++){ + int t = in.nextInt(); + if(t > 0) count++; + } + if(p == 0) + ans = n; + else + ans = count; + } + else{ + for(int i = 0; i < n; i++){ + int t = in.nextInt(); + if(t >= 3*p - 2) + high++; + else if(t >= 3*p - 4) + low++; + } + + ans = ans = high + ((s < low)? s : low); + } + System.out.println(""Case #"" + c + "": "" + ans); + + } + + } + +}" +A20995,"package fixjava; + +/** + * Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method + * in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in + * Java. + */ + +public interface Lambda3 { + public V apply(P param1, Q param2, R param3); +} +" +A21640,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + + +public class CodeJamTextInputReader { + private final BufferedReader reader; + private final int numberOfTestCases; + private int lastReadTestCase = 0; + + public CodeJamTextInputReader(File inputFile) throws IOException, InvalidInputException { + reader = new BufferedReader(new FileReader(inputFile)); + + numberOfTestCases = readInNumberOfTestCases(); + } + + private int readInNumberOfTestCases() throws IOException, InvalidInputException { + String firstLine = reader.readLine(); + try { + return Integer.parseInt(firstLine); + } + catch (NumberFormatException e) { + throw new InvalidInputException(""Expected first line to be number of test cases"", e); + } + } + + public boolean hasNextTestCase() { + return numberOfTestCases != lastReadTestCase; + } + + public String readNextLine() throws IOException { + ++lastReadTestCase; + + return reader.readLine(); + } + + public int getLastReadTestCaseNumber() { + return lastReadTestCase; + } + + public void close() throws IOException { + this.reader.close(); + } +} +" +A22758,"/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package codejam2012; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Scanner; + +/** + * + * @author Luis Sergio Curay + */ +public class b_2 { + + public b_2() { + Scanner in= new Scanner(System.in); + int t= in.nextInt(); + HashMap>> comb= new HashMap>>(); + for (int i = 0; i <= 30; i++) { + ArrayList> curr= new ArrayList>(); + for (int j = 0; j <= 10; j++) + for (int k = 0; k <= 10; k++) + for (int l = 0; l <= 10; l++) + if((j+k+l) == i) { + ArrayList tmp= new ArrayList(); + int arr[]= new int[]{j,k,l}; + Arrays.sort(arr); + for (int m = 0; m < arr.length; m++) { + tmp.add(arr[m]); + } + curr.add(tmp); + } + comb.put(i, curr); + } + for (int i = 0; i < t; i++) { + int n= in.nextInt(); + int s= in.nextInt(); + int p= in.nextInt(); + int res= 0; + for (int j = 0; j < n; j++) { + int c= in.nextInt(); + int rank= 0; + ArrayList> curr= comb.get(c); + for (ArrayList combs : curr) { + if(combs.get(0).equals(combs.get(1)) && combs.get(0).equals(combs.get(2))) { + if(combs.get(0) >= p) { + rank=6;break;//res++;break; + } + } else if(combs.get(0).equals(combs.get(1))) { + if(combs.get(2) >= p && (combs.get(2) - combs.get(1)) == 1) { + if(rank < 5) rank= 5;//res++;break; + } else if(combs.get(2) >= p && (combs.get(2) - combs.get(1)) == 2 && s > 0) { + if(rank < 4) rank= 4;//res++;s--;break; + } + } else if(combs.get(1).equals(combs.get(2))) { + if(combs.get(1) >= p && (combs.get(1) - combs.get(0)) == 1) { + if(rank < 3) rank= 3;//res++;break; + } else if(combs.get(1) >= p && (combs.get(1) - combs.get(0)) == 2 && s > 0) { + if(rank < 2) rank= 2;//res++;s--;break; + } + } else { + if(combs.get(2) >= p) + if((combs.get(2) - combs.get(1)) == 1 && (combs.get(1) - combs.get(0)) == 1 && s > 0) { + if(rank < 1) rank= 1;//res++;s--;break; + } + } + } + if(rank == 6 || rank ==5 || rank == 3) + res++; + else if( rank > 0){ + res++;s--; + } + } + System.out.println(""Case #"" + (i + 1) + "": "" + res); + } + } + + public void print(ArrayList t) { + for (Integer integer : t) { + System.out.print(integer + "" ""); + } + System.out.println(); + } +}" +A21250," +import java.io.*; + +public class B { + + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + int T; + T = Integer.parseInt(reader.readLine()); + for (int i = 1; i <= T; i++) { + String[] input = reader.readLine().split("" ""); + int result = 0; + int N = Integer.parseInt(input[0]); + int S = Integer.parseInt(input[1]); + int p = Integer.parseInt(input[2]); + for (int j = 3; j < input.length; j++) { + int score = Integer.parseInt(input[j]); + int temp = score/3; + if(score % 3 ==0){ + if(temp>=p){ + ++result; + } else if (temp+1>=p && S>0 && temp>=1){ + ++result; + --S; + } + } else if(score % 3 ==1){ + if (temp+1>=p){ + ++result; + } + } else { + if (temp+1>=p){ + ++result; + } else if(temp+2>=p && S>0){ + ++result; + --S; + } + } + } + if (i < T) { + System.out.println(""Case #"" + i + "": "" + result); + } else { + System.out.print(""Case #"" + i + "": "" + result); + } + } + } +}" +A22119," +public class Problem { + + public int googlers; + public int surprisingTriplets; + public int bestResult; + public int[] totals; + + public Problem(int googlers, int suprisingTriplets, int bestResult, int[] totals) { + super(); + this.googlers = googlers; + this.surprisingTriplets = suprisingTriplets; + this.bestResult = bestResult; + this.totals = totals; + } + + public int solve() { + + boolean[] bestTotals = new boolean[totals.length]; + + for (int i = 0; i < bestTotals.length; i++) { + bestTotals[i] = tryFindingAnswer(totals[i], false); + } + + // Try to find surprising results + int i = 0; + int surprising = surprisingTriplets; + while (i < bestTotals.length && surprising > 0) { + + if (!bestTotals[i]) { + bestTotals[i] = tryFindingAnswer(totals[i], true); + + if (bestTotals[i]) { + surprising--; + } + } + + i++; + } + + int finalResult = 0; + for (boolean b : bestTotals) { + if (b) { + finalResult++; + } + } + + return finalResult; + } + + private boolean tryFindingAnswer(int total, boolean isSurprising) { + + if (total == 0) { + return (bestResult == 0); + } + + total -= bestResult; + if (total >= 20) { + return true; + } + + int lowLimit = bestResult - 1; + int highLimit = bestResult + 1; + + if (isSurprising) { + lowLimit--; + highLimit++; + } + + if (lowLimit < 0) { + lowLimit = 0; + } + + if (highLimit > 10) { + highLimit = 10; + } + + if (highLimit * 2 < total) { + return true; + } + + for (int i = lowLimit; i <= highLimit; i++) { + int tempOtherValue = total - i; + + if (tempOtherValue >= lowLimit && tempOtherValue <= highLimit) { + return true; + } + } + + return false; + } +} +" +A22363," +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Scanner; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +/** + * + * @author JY + */ +public class ProblemB { + + private static int testNum; + private static int[][] scores; + + public static void main(String[] args) { + input(); + int[] result = calc(); + output(testNum, result); + } + + private static void input() { + Scanner in = null; + in = new Scanner(System.in); + testNum = Integer.parseInt(in.nextLine()); + scores = new int[testNum][]; + for (int i = 0; i < testNum; i++) { + String line = in.nextLine(); + String[] nums = line.split("" ""); + int n = Integer.parseInt(nums[0]); + scores[i] = new int[n + 3]; + for (int j = 0; j < n + 3; j++) { + scores[i][j] = Integer.parseInt(nums[j]); + } + } + } + + private static int[] calc() { + int[] res = new int[testNum]; + for (int i = 0; i < testNum; i++) { + int result = 0; + int[] scoreLine = scores[i]; + int n = scoreLine[0]; + int s = scoreLine[1]; + int p = scoreLine[2]; + for (int j = 0; j < n; j++) { + int currentScore = scoreLine[j + 3]; + if ((currentScore + 2) >= 3 * p) { + result++; + } else if (s > 0 && (currentScore + 4) >= 3 * p && (currentScore + 4) / 3 >= 2) { + result++; + s--; + } + } + res[i] = result; + } + return res; + } + + private static void output(int testNum, int[] res) { + for (int i = 0; i < testNum; i++) { + System.out.printf(""Case #%d: %s\n"", i + 1, res[i]); + } + } + + private static void prt(int[] c) { + for (int i = 0; i < c.length; i++) { + System.out.print(c[i] + "" ""); + } + System.out.println(""""); + } +} +" +A20700,"import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.PrintWriter; +import java.util.Scanner; + + +public class googler { + + + public static void main(String args[]) throws FileNotFoundException + { + + Scanner in=new Scanner(new FileReader(""input.in"")); + PrintWriter pw=new PrintWriter(""ans.txt""); + + + int cases=in.nextInt(); + in.nextLine(); + for(int counter=1;counter<=cases;counter++) + { + int n=in.nextInt(); + int s=in.nextInt(); + int p=in.nextInt(); + + System.out.println(n+"" ""+s+"" ""+p); + int req; + if(p==0) + { + pw.println(""Case #""+(counter)+"": ""+n); + in.nextLine(); + continue; + } + else + req=p*3-2; + + int min=req-2>0?req-2:1; + + int answer=0; + + for(int j=0;j=req) + { + answer++; + continue; + } + else if(score>=min&&s>0) + { + answer++; + s--; + } + } + + pw.println(""Case #""+(counter)+"": ""+answer); + } + pw.close(); + } +} +" +A22610,"package main; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + + +public class MyTest { + public int getNumOfGoogler(int S, int p, List points) { + if(p == 0) { + return points.size(); + } + int ret = 0; + for(int point : points) { + if(point >= 3 * p - 2) { + ret++; + } else if(point >= 3 * p - 4 && S > 0 && p > 1) { + S--; + ret++; + } + } + return ret; + } + + + Map map = new HashMap(); + + public String getTranslation(String gs) { + String ret = """"; + for(int i=0; i bases) { + for(int i=bases.get(0); ; i++) { + boolean breakOut = false; + for(int base : bases) { + if(!isNumHappy(i, base)) { + breakOut = true; + break; + } + } + if(!breakOut) { + return i; + } + } + } + + public boolean isNumHappy(int num, int base) { + int sum = 0; + List previous = new ArrayList(); + while(sum != 1) { + sum = 0; + String numStr = toString(num, base); + if(previous.contains(numStr)) { + return false; + } + previous.add(numStr); + for(int i=0; i sum) { + return false; + } + } + return true; + } + + private String getBinaryNum(int i, int length) { + String ret = Integer.toBinaryString(i); + if(ret.length() < length) { + return new String(new char[length - ret.length()]).replace(""\0"", ""0"") + ret; + } + return ret; + } + + public class Chick { + Chick(int b, int t, int x, int v) { + T = t; + B = b; + X = x; + V = v; + arrive = (B - X) / (double)V <= T; + } + + public int T; + public int B; + public int X; + public int V; + public boolean arrive; + } + + public int getSwapNum(List chicken, int K) { + int ret = 0; + for(int i=chicken.size()-1; i>=0; i--) { + if(K == 0) { + break; + } + if(!chicken.get(i).arrive) { + ret += K; + } else { + K--; + } + } + if(K != 0) { + return -1; + } + return ret; + } + + public class Directory { + Directory(String n) { + name = n; + dirs = new ArrayList(); + } + + Directory getChild(String name) { + for(Directory dir : dirs) { + if(dir.name.equals(name)) { + return dir; + } + } + return null; + } + + public String name; + public List dirs; + } + + public int getNumOfMkdir(Directory root, List> newDirs) { + int ret = 0; + Directory curr, pre; + for(List newDir : newDirs) { + curr = root; + for(String folder : newDir) { + pre = curr; + curr = curr.getChild(folder); + if(curr == null) { + ret++; + pre.dirs.add(new Directory(folder)); + curr = pre.getChild(folder); + } + } + } + return ret; + } + + public List getDirNames(String dir) { + List ret = new ArrayList(Arrays.asList(dir.split(""/""))); + ret.remove(0); + return ret; + } + + public String rotate(int K, char[][] position) { + char[][] rotated = new char[position.length][position.length]; + for(int i=0; i=0; i--) { + if(rotated[i][j] != '.') { + rotated[tmp][j] = rotated[i][j]; + tmp--; + } + } + for(; tmp>=0; tmp--) { + rotated[tmp][j] = '.'; + } + } + + boolean r = checkColor('R', K, rotated); + boolean b = checkColor('B', K, rotated); + + if(r && b) { + return ""Both""; + } else if(r) { + return ""Red""; + } else if(b) { + return ""Blue""; + } else { + return ""Neither""; + } + } + + private boolean checkColor(char color, int K, char[][] rotated) { + int num = 0; + for(int i=0; i=rotated.length || j+k >= rotated.length) { + break; + } + if(rotated[i+k][j+k] == color) { + num++; + if(num == K) { + return true; + } + } else { + break; + } + } + num = 0; + } + } + + num = 0; + for(int i=0; i=rotated.length || j-k < 0) { + break; + } + if(rotated[i+k][j-k] == color) { + num++; + if(num == K) { + return true; + } + } else { + break; + } + } + num = 0; + } + } + + return false; + } + + public class WalkWay implements Comparable{ + WalkWay(int b, int e, int w) { + B = b; + E = e; + W = w; + } + + public int B; + public int E; + public int W; + + @Override + public int compareTo(WalkWay o) { + if(W == o.W) { + return 0; + } + return W < o.W ? -1 : 1; + } + } + + public Double getMinTimeForWalkWay(int X, int S, int R, Double t, List walkWays) { + int walkWayNum = walkWays.size(); + int tmp = 0; + for(int i=0; i= walkWayNum) { + walkWays.add(new WalkWay(i, X, 0)); + break; + } + if(i < walkWays.get(tmp).B) { + walkWays.add(new WalkWay(i, walkWays.get(tmp).B, 0)); + i = walkWays.get(tmp).E - 1; + tmp++; + } else if(i == walkWays.get(tmp).B) { + i = walkWays.get(tmp).E - 1; + tmp++; + } + } + Collections.sort(walkWays); + + Double ret = new Double(0); + for(WalkWay walkWay : walkWays) { + if(t > 0) { + Double ideaT = (new Double(walkWay.E) - walkWay.B) / (walkWay.W + R); + if(t >= ideaT) { + t -= ideaT; + ret += ideaT; + } else { + Double pass = t * (walkWay.W + R); + ret += t + (new Double(walkWay.E) - pass - walkWay.B) / (walkWay.W + S); + t = new Double(-1); + } + } else { + ret += (new Double(walkWay.E) - walkWay.B) / (walkWay.W + S); + } + } + + return ret; + } + + public String getPerfertHarmony(Long L, Long H, List frequencise) { + boolean flag = true; + for(long i=L; i<=H; i++) { + flag = true; + for(Long frequency : frequencise) { + if(i % frequency != 0 && frequency % i != 0) { + flag = false; + break; + } + } + if(flag) { + return """" + i; + } + } + return ""NO""; + } + + public Long getRocketTime(Long L, Long t, Long N, List distance) { + Long sum = new Long(0); + List singleDis = new ArrayList(); + for(Long dis : distance) { + sum += dis; + } + Long nRound = N / distance.size(); + Long nRemain = N % distance.size(); + Long time = nRound * sum; + for(int i=0; i= time || L == 0) { + return time; + } + + Long pass = t/2; + Long passRound = pass / sum; + Long passRemain = pass % sum; + Long passRoundRemain = nRound - passRound; + + if(t != 0) { + for(int i=0; i 0) { + passRemain -= distance.get(i); + } else { + singleDis.add(distance.get(i)); + } + } + if(passRemain != 0) { + singleDis.add(-passRemain); + } + passRoundRemain--; + } + + Collections.sort(distance); + Collections.sort(singleDis); + + Long minus = new Long(0); + int singleDisIndex = singleDis.size()-1; + for(int i=distance.size()-1; i>=0; i--) { + while(singleDisIndex >= 0 && singleDis.get(singleDisIndex) >= distance.get(i)) { + minus += singleDis.get(singleDisIndex); + singleDisIndex--; + L--; + } + if(L <= passRoundRemain) { + minus += L * distance.get(i); + break; + } else { + minus += passRoundRemain * distance.get(i); + L -= passRoundRemain; + } + } + + return time - minus; + } + + public char[][] tiles; + public boolean test() { + for(int i=0; i= tiles.length || j+1 >= tiles[i+1].length || tiles[i][j+1] != '#' || tiles[i+1][j] != '#' || tiles[i+1][j+1] != '#') { + return false; + } + tiles[i][j] = '/'; + tiles[i+1][j] = '\\'; + tiles[i][j+1] = '\\'; + tiles[i+1][j+1] = '/'; + } + } + } + return true; + } + + public String test1(List words, String seq) { + int maxScore = -1; + String maxString = """"; + + for(String word : words) { + int score = -1; + StringBuilder wildCard = new StringBuilder(new String(new char[word.length()]).replace(""\0"", ""_"")); + List words2 = new ArrayList(words); + int words2Size = words.size(); + + for(int i=0; i maxScore) { + maxScore = score; + maxString = word; + } + } + return maxString; + } + + private boolean killerWordWildCard(String word, String wildCard, Character notIn) { + if(!wildCardMatch(word, wildCard)) { + return false; + } else if(notIn != null) { + int begin = -1; + while(true) { + if(begin+1 >= word.length()) { + break; + } + begin = word.indexOf(notIn, begin + 1); + if(begin == -1) { + break; + } + if(wildCard.charAt(begin) != notIn) { + return false; + } + } + // wildCard.indexOf(notIn); + } + return true; + } + + private boolean wildCardMatch(String str1, String str2) { + if(str1.length() != str2.length()) { + return false; + } + for(int i=0; i max(Comparable... numbers) { + Comparable max = numbers[0]; + + for(Comparable number : numbers) { + if(number.compareTo(max) > 0) { + max = number; + } + } + return max; + } + + @SuppressWarnings(""unchecked"") + public static Comparable min(Comparable... numbers) { + Comparable min = numbers[0]; + + for(Comparable number : numbers) { + if(number.compareTo(min) < 0) { + min = number; + } + } + return min; + } + + private int lcm(int a, int b) { + return a * b / gcd(a, b); + } + + private int gcd(int a, int b) { + while(a != b) { + if(a > b) { + a -= b; + } else { + b -= a; + } + } + return a; + } + + private double sqrt(double n) { + double d = n/2.0; + double lst = 0.0; + while(lst != d) { + lst = d; + d = (d+n/d)/2.0; + } + return d; + } + + private void dfs(int row, int column, String path) { + HashSet ret = new HashSet(); + HashSet dic = new HashSet(); + boolean[][] used = new boolean[5][5]; + char[][] boggle ={ + {'l', 'i', 'b', 'c', 'd'}, + {'x', 'n', 's', 'c', 'd'}, + {'e', 'd', 'b', 't', 'd'}, + {'l', 'a', 'b', 'c', 'd'}, + {'l', 'i', 's', 't', 'd'}}; + if(!checkRange(row) || !checkRange(column) || used[row][column]) { + return; + } + path += boggle[row][column]; + used[row][column] = true; + if(dic.contains(path) && !ret.contains(path)) { + ret.add(path); + System.out.println(path); + used[row][column] = false; + return; + } + + dfs(row+1, column, path); + dfs(row-1, column, path); + dfs(row, column+1, path); + dfs(row, column-1, path); + used[row][column] = false; + } + + private boolean checkRange(int i) { + return i < 5 && i >= 0; + } +}" +A22519,"import java.io.File; +import java.util.Scanner; + + +public class Dance { + + public static void main(String[] args) throws Throwable { + Scanner scan = new Scanner(new File(""dance.in"")); + int t = Integer.parseInt(scan.nextLine()); + for (int i = 1; i <= t; i++) { + String line = scan.nextLine(); + Scanner token = new Scanner(line); + int n = token.nextInt(); + int s = token.nextInt(); + int p = token.nextInt(); + int counter = 0; + for (int j = 0; j < n; j++) { + int score = token.nextInt(); + int scoreEach = score / 3; + int remainder = score % 3; + + if (scoreEach >= p) { + counter++; + } else if (scoreEach + 1 == p && remainder >= 1) { + counter++; + } else if (scoreEach + 2 >= p && remainder == 2 && s > 0) { + s--; + counter++; + } else if (scoreEach + 1 == p && remainder == 0 && s > 0 && score > 0) { + s--; + counter++; + } + } + System.out.printf(""Case #%d: %d\n"", i, counter); + } + } + +} +" +A23029,"import java.io.*; +import java.util.*; + + +public class DancingWithTheGooglers { + + public static void main (String[] args) throws IOException { + Scanner in = new Scanner(new File(""B-small.txt"")); + + int cases; + cases = in.nextInt(); + + int google, s, p; + int count; + + int temp; + + for (int n = 0; n < cases; n++) { + google = in.nextInt(); + s = in.nextInt(); + p = in.nextInt(); + count = 0; + + for (int i = 0; i < google; i++) { + temp = in.nextInt(); + + if (p == 0) { + count ++; + } else if (p == 1 && temp == 0) { + continue; + } else if (temp/3 >= p) { + count ++; + } else if (temp/3 == p - 1 && temp%3 >= 1) { + count ++; + } else if (temp/3 == p - 1 && temp%3 == 0){ + if (s != 0) { + count ++; + s--; + } + } else if (temp/3 == p - 2 && temp%3 == 2) { + if (s != 0) { + count ++; + s--; + } + } + } + + System.out.println(""Case #"" + (n+1) + "": "" + count); + } + + } +}" +A22834,"import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.Scanner; + + + + +public class Dancing { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + File f = new File(""D://B-large.in""); + Scanner sc; + try { + sc = new Scanner(f); + int n = sc.nextInt(); + //System.out.println(n); + for (int i = 0;i=p) + num++; + else if (val/3 == p-1 && val/3 >= 0){ + if (val % 3 ==0){ + if (val/3-1 >= 0) + snum++; + } + else + num++; + } + else if (val/3 == p-2 && val/3 >= 0){ + if (val % 3 ==2) + snum++; + } + } + num = num + (snum>s?s:snum); + System.out.println(""Case #""+(i+1)+"": ""+num); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + + } + +} +" +A20929,"package br.com; + +public class Tripla { + + int pontuacaoMaxima; + + public Tripla(int pontuacaoMaxima) { + this.pontuacaoMaxima = pontuacaoMaxima; + } + + public int maximaPontuacao() { + int menor = pontuacaoMaxima / 3; + if (menor * 3 < pontuacaoMaxima) { + return menor + 1; + } + return menor; + } + + public int maximaPontuacaoEspecial() { + if (pontuacaoMaxima == 0) { + return 0; + } + if (pontuacaoMaxima % 3 == 1) { + return (pontuacaoMaxima / 3) + 1; + } + + else { + return (pontuacaoMaxima / 3) + 2; + } + } +} +" +A21994,"import java.io.*; +class Main +{ +public static int dance(int ll,int spp,int maxx,int g[]) +{ + +int c=0; +int l=ll; +long result[][]=new long[l][4]; +int max=maxx; +//int g[]={15,13,11}; +int s=0; +int i=0; +int sum=0; +int flag=0; +int t=2; +int presp=spp; +int special=0; +int sp=0; +int sol=0;int maxsol=0;int row=0; +int sum2=0; +boolean yes=true; +for(int loop=0;loop=max || j>=max ||k>=max) +{ +maxsol++; +//System.out.println(i+ "" ""+j+"" ""+k); +c++; +flag=0; +} +} + +} +} +i++; + + +/*if(special==presp) +{ +t=1; +special=0; +}*/ +} +result[row][0]=sum2; +result[row][1]=sol; +result[row][3]=sp; +result[row][2]=maxsol; +row++; +flag=0; +sol=0; +maxsol=0; +sp=0; +} +//System.out.println(""ans :""+c); +//System.out.println(""special :""+special); +int ans=0; +sort(result,l); +for(int rr=0;rr0) +{ +presp=rr+presp; +break; +} +} +//System.out.println(""presp =""+presp); +for(int rr=0;rr0 ) +{ +if(rr>(presp-1)) +{ +if(result[rr][3]>=result[rr][2]) +{ +yes=false; +} +} + +if(yes) +ans++; + +yes=true; +} +/* +for(int cc=0;cc<4;cc++) +{ +//System.out.print(result[rr][cc]+"" | ""); +} +System.out.println();*/ +} +//System.out.println(""ans right:""+ans); +return ans; + +} +public static void sort(long a[][],int l) +{ +long cell1=0,cell2=0,cell3=0,cell4=0; +for(int i=0;ia[j][2]) +{ +cell1=a[i][0]; +cell2=a[i][1]; +cell3=a[i][2]; +cell4=a[i][3]; + +a[i][0]=a[j][0]; +a[i][1]=a[j][1]; +a[i][2]=a[j][2]; +a[i][3]=a[j][3]; + +a[j][0]=cell1; +a[j][1]=cell2; +a[j][2]=cell3; +a[j][3]=cell4; + +} + +} +} +} +public static void main(String ar[]) throws IOException +{ +FileReader in=new FileReader(""hello.txt""); +FileWriter ot=new FileWriter(""check.txt"",true); + +BufferedReader ds=new BufferedReader(in); +BufferedWriter out=new BufferedWriter(ot); + +//System.out.println(""check332wefsd""); +int loop=Integer.parseInt(ds.readLine()); +String i[]=new String[loop]; +int ll,maxx,sp; +int rs[]; +int ans; +for(int ii=1;ii<=loop;ii++) +{ +i=ds.readLine().split("" ""); +ll=Integer.parseInt(i[0]); +sp=Integer.parseInt(i[1]); +maxx=Integer.parseInt(i[2]); +rs=new int[ll]; +for(int j=3;j maxDist || diff2 > maxDist || diff3 > maxDist) || (arr[0] < minimumPositive && arr[1] < minimumPositive && arr[2] < minimumPositive)) { + return false; + } else { + return true; + } + + } + + + private void calculatePossibleScores(final int total, final int maxcheat, final int minimumPositive) { + Runnable r = new Runnable() { + public void run() { + int[] working = new int[3]; + + boolean withCheat = false; + + for(int i = 0; i <= 10; i++) { + working[0] = i; + + for(int j = 0; j <= 10; j++) { + working[1] = j; + + for(int k = 0; k <= 10; k++) { + working[2] = k; + + if(working[0] + working[1] + working[2] != total) { + continue; + } + + if(testArray(working, total, 1, minimumPositive)) { + //System.out.println(Arrays.toString(working) + "" "" + maxcheat + "" "" + total + "" "" + minimumPositive); + possibleNoCheat.incrementAndGet(); + jobsWorking.decrementAndGet(); + return; + } else if (!withCheat) { + if(testArray(working, total, 2, minimumPositive)) { + withCheat = true; + } + } + } + } + } + + if(withCheat) { + possibleWithCheatOnly.incrementAndGet(); + } + + jobsWorking.decrementAndGet(); + } + }; + + service.execute(r); + } + + public void doEverything(String file) throws Exception { + String[] lines = readFile(file); + + int casen = 1; + + for(String line : lines) { + reset(); + //System.out.println(""\n\n\n""); + String[] sints = line.split(""\\s+""); + int[] ints = new int[sints.length]; + + for(int i = 0; i < sints.length; i++) { + ints[i] = Integer.parseInt(sints[i]); + } + + int numGooglers = ints[0]; + int start = 3; + int maxcheat = ints[1]; + int minPositive = ints[2]; + +// System.out.println(numGooglers + "" "" + maxcheat + "" "" + minPositive); + + for(int i = start; i < ints.length; i++) { +// System.out.println(""Testing: "" + ints[i]); + jobsWorking.incrementAndGet(); + + calculatePossibleScores(ints[i], maxcheat, minPositive); +// System.out.println(); + } + + while(jobsWorking.get() > 0) { + Thread.sleep(100); + } + + System.out.println(""Case #"" + casen + "": "" + (possibleNoCheat.get() + (possibleWithCheatOnly.get() > maxcheat ? maxcheat : possibleWithCheatOnly.get()))); + casen++; + } + + service.shutdown(); + } + + public static void main(String[] args) throws Throwable { + new Dancing().doEverything(""C:/Users/Eddie/Desktop/google_input.txt""); + + } + + private static String[] readFile(String file) throws IOException { + Scanner scanner = new Scanner(new File(file)); + + String numLines = scanner.nextLine(); + + int nl = Integer.parseInt(numLines); + + String[] lines = new String[nl]; + int i = 0; + + while(scanner.hasNextLine() && i < nl) { + lines[i] = scanner.nextLine(); + ++i; + } + + return lines; + } +} +" +A22453,"package util.graph; + +public abstract class Edge implements Cloneable{ + public abstract State travel(State current); + public Node target; + public void connect(Node start, Node end) { + try { + Edge clone = (Edge) this.clone(); + start.edges.add(clone); + clone.target=end; + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } + + public void biConnect(Node n1, Node n2) { + connect(n1,n2); + connect(n2,n1); + } +} +" +A22302,"import java.io.*; +import java.util.*; + +public class B { + + public static void main(String[] args) throws IOException { + //variable initialization + String inFile = args[0]; + String outFile = inFile.split(""\\."")[0] + "".out""; + + //file reading... + BufferedReader reader = new BufferedReader(new FileReader(inFile)); + PrintWriter writer = new PrintWriter(new FileWriter(outFile)); + + //get input data + int T = Integer.valueOf(reader.readLine()); + for (int i = 0; i < T; i++) { + String[] str_nums = reader.readLine().split("" ""); + int[] nums = new int[str_nums.length]; + int n = 0; + for (String str : str_nums) { + nums[n++] = Integer.valueOf(str); + } + + int N = nums[0]; + int S = nums[1]; + int p = nums[2]; + int res = 0; + + for (n = 0; n < N; n++) { + int total = nums[n+3]; + int k = total / 3; + int k2 = total % 3; + if (k >= p) res++; + else if (p-k == 1 && k2 > 0) res++; + else if (S > 0) + if (k2 >= p-k || (k2 == 0 && k != 0 && p-k == 1)) { + S--; + res++; + // System.out.println(""Surpraise: ("" + k + "","" + k + "","" + (k+k2) + "") p="" + p); + } + + } + String result = ""Case #"" + (i+1) + "": "" + res; + writer.println(result); + // char[] line = readerReal.readLine().toCharArray(); + // for (char c : line) { + // if (dict.containsKey(c)) { + // writer.write(dict.get(c)); + // } else { + // writer.write(c); + // } + // } + // writer.write('\n'); + + // System.out.println(Arrays.toString(nums)); + // System.out.println(result); + + } + reader.close(); + writer.close(); + } +} +" +A20535,"package codejam.morl99.b; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Scanner; + +import codejam.morl99.a.ProblemA; + +public class ProblemB { + public void solveSet(PrintWriter pw, BufferedReader reader) throws IOException { + + String firstLine = reader.readLine(); + Scanner scanner = new Scanner(firstLine); + scanner.useDelimiter("" ""); + int T = scanner.nextInt(); + + for (int i = 1; i <= T; i++) { + scanner = new Scanner(reader.readLine()); + scanner.useDelimiter("" ""); + int N = scanner.nextInt(); + int S = scanner.nextInt(); + int p = scanner.nextInt(); + int[] t = new int[N]; + for (int googler = 0; googler < N; googler++) { + t[googler] = scanner.nextInt(); + } + System.out.println(""-- N: "" + N + "" S: "" + S + "" p>=""+p +"" t:""+ Arrays.toString(t) ) ; + int solution = solveLine(N,S,p,t); + pw.printf(""Case #%d: %d"",i,solution); + pw.println(); + } + + } + + public int solveLine(int N, int S, int p, int[] t) { + int casesAbove = 0; + for (int i = 0; i < N; i++) { + if (isRegularScoreAbove(t[i], p)) { + casesAbove++; + continue; + } + + //Whenever a regular score is not above the limit, but the best surprising distribution is + //we take the greedy approach and assume this was a surprising score. What better than a score above + //could we hope for? + if (S > 0 && isSurprisingScoreAbove(t[i], p)) { + S--; + casesAbove++; + } + } + return casesAbove; + } + + public boolean isRegularScoreAbove(int ti, int p) { + //This is the formular for the best score that can be achieved, if no score can be + //apart more than 1 from any other score + int best = ti/3 + Math.min(ti%3,1); + System.out.println(""Best regular score for "" + ti + "" is "" + best); + return best >= p; + } + + public boolean isSurprisingScoreAbove(int ti, int p) { + //integer division, which is exactly what we want! + int b = ((ti-1) / 3); + int best = b + 1 + (ti-b*3+1)/3; + //Special case, that we are near zero... + best = Math.min(ti,best); + System.out.println(""Best surprising score for "" + ti + "" is "" + best); + return best >= p; + } + + public static void main(String[] args) throws IOException { + ProblemB p = new ProblemB(); + + OutputStream output = new FileOutputStream(""res/B.out"", false); + PrintWriter pw = new PrintWriter(output); + BufferedReader reader = new BufferedReader(new FileReader(""res/B-large.in"")); + p.solveSet(pw, reader); + pw.close(); + reader.close(); + + + } +} +" +A22160,"/************************************************************************* + * Compilation: javac In.java + * Execution: java In + * + * Reads in data of various types from: stdin, file, URL. + * + * % java In + * + * Remarks + * ------- + * - isEmpty() returns true if there is no more input or + * it is all whitespace. This might lead to surprising behavior + * when used with readChar() + * + *************************************************************************/ + + +import java.net.URLConnection; +import java.net.URL; +import java.net.Socket; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.util.Scanner; +import java.util.Locale; + + +/** + * Input. This class provides methods for reading strings + * and numbers from standard input, file input, URL, and socket. + *

+ * The Locale used is: language = English, country = US. This is consistent + * with the formatting conventions with Java floating-point literals, + * command-line arguments (via Double.parseDouble()) + * and standard output (via System.out.print()). It ensures that + * standard input works the number formatting used in the textbook. + *

+ * For additional documentation, see Section 3.1 of + * Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne. + */ +public final class In { + private Scanner scanner; + + // assume Unicode UTF-8 encoding + //private String charsetName = ""UTF-8""; + + private String charsetName = ""ISO-8859-1""; + + // assume language = English, country = US for consistency with System.out. + private Locale usLocale = new Locale(""en"", ""US""); + + /** + * Create an input stream for standard input. + */ + public In() { + scanner = new Scanner(new BufferedInputStream(System.in), charsetName); + scanner.useLocale(usLocale); + } + + /** + * Create an input stream from a socket. + */ + public In(Socket socket) { + try { + InputStream is = socket.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + socket); + } + } + + /** + * Create an input stream from a URL. + */ + public In(URL url) { + try { + URLConnection site = url.openConnection(); + InputStream is = site.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + url); + } + } + + /** + * Create an input stream from a file. + */ + public In(File file) { + + try { + scanner = new Scanner(file, charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + file); + } + } + + + /** + * Create an input stream from a filename or web page name. + */ + public In(String s) { + + try { + // first try to read file from local file system + File file = new File(s); + if (file.exists()) { + scanner = new Scanner(file, charsetName); + scanner.useLocale(usLocale); + return; + } + + // next try for files included in jar + URL url = getClass().getResource(s); + + // or URL from web + if (url == null) { url = new URL(s); } + + URLConnection site = url.openConnection(); + InputStream is = site.getInputStream(); + scanner = new Scanner(new BufferedInputStream(is), charsetName); + scanner.useLocale(usLocale); + } + catch (IOException ioe) { + System.err.println(""Could not open "" + s); + } + } + + /** + * Does the input stream exist? + */ + public boolean exists() { + return scanner != null; + } + + /** + * Is the input stream empty? + */ + public boolean isEmpty() { + return !scanner.hasNext(); + } + + /** + * Does the input stream have a next line? + */ + public boolean hasNextLine() { + return scanner.hasNextLine(); + } + + /** + * Read and return the next line. + */ + public String readLine() { + String line = null; + try { line = scanner.nextLine(); } + catch (Exception e) { } + return line; + } + + /** + * Read and return the next character. + */ + public char readChar() { + // (?s) for DOTALL mode so . matches any character, including a line termination character + // 1 says look only one character ahead + // consider precompiling the pattern + String s = scanner.findWithinHorizon(""(?s)."", 1); + return s.charAt(0); + } + + + + // return rest of input as string + /** + * Read and return the remainder of the input as a string. + */ + public String readAll() { + if (!scanner.hasNextLine()) { return null; } + + // reference: http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html + return scanner.useDelimiter(""\\A"").next(); + } + + + + /** + * Return the next string from the input stream. + */ + public String readString() { + return scanner.next(); + } + + /** + * Return the next int from the input stream. + */ + public int readInt() { + return scanner.nextInt(); + } + + /** + * Return the next double from the input stream. + */ + public double readDouble() { + return scanner.nextDouble(); + } + + /** + * Return the next float from the input stream. + */ + public double readFloat() { + return scanner.nextFloat(); + } + + /** + * Return the next long from the input stream. + */ + public long readLong() { + return scanner.nextLong(); + } + + /** + * Return the next byte from the input stream. + */ + public byte readByte() { + return scanner.nextByte(); + } + + + /** + * Return the next boolean from the input stream, allowing ""true"" or ""1"" + * for true and ""false"" or ""0"" for false. + */ + public boolean readBoolean() { + String s = readString(); + if (s.equalsIgnoreCase(""true"")) return true; + if (s.equalsIgnoreCase(""false"")) return false; + if (s.equals(""1"")) return true; + if (s.equals(""0"")) return false; + throw new java.util.InputMismatchException(); + } + + + /** + * Close the input stream. + */ + public void close() { scanner.close(); } + + + + /** + * Test client. + */ + public static void main(String[] args) { + In in; + String urlName = ""http://www.cs.princeton.edu/IntroCS/stdlib/InTest.txt""; + + // read from a URL + System.out.println(""readAll() from URL "" + urlName); + System.out.println(""---------------------------------------------------------------------------""); + try { + in = new In(urlName); + System.out.println(in.readAll()); + } + catch (Exception e) { } + System.out.println(); + + // read one line at a time from URL + System.out.println(""readLine() from URL "" + urlName); + System.out.println(""---------------------------------------------------------------------------""); + try { + in = new In(urlName); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (Exception e) { } + System.out.println(); + + // read one string at a time from URL + System.out.println(""readString() from URL "" + urlName); + System.out.println(""---------------------------------------------------------------------------""); + try { + in = new In(urlName); + while (!in.isEmpty()) { + String s = in.readString(); + System.out.println(s); + } + } + catch (Exception e) { } + System.out.println(); + + + // read one line at a time from file in current directory + System.out.println(""readLine() from current directory""); + System.out.println(""---------------------------------------------------------------------------""); + try { + in = new In(""./InTest.txt""); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (Exception e) { } + System.out.println(); + + + // read one line at a time from file using relative path + System.out.println(""readLine() from relative path""); + System.out.println(""---------------------------------------------------------------------------""); + try { + in = new In(""../stdlib/InTest.txt""); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (Exception e) { } + System.out.println(); + + // read one char at a time + System.out.println(""readChar() from file""); + System.out.println(""---------------------------------------------------------------------------""); + try { + in = new In(""InTest.txt""); + while (!in.isEmpty()) { + char c = in.readChar(); + System.out.print(c); + } + } + catch (Exception e) { } + System.out.println(); + System.out.println(); + + // read one line at a time from absolute OS X / Linux path + System.out.println(""readLine() from absolute OS X / Linux path""); + System.out.println(""---------------------------------------------------------------------------""); + in = new In(""/n/fs/csweb/introcs/stdlib/InTest.txt""); + try { + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + } + catch (Exception e) { } + System.out.println(); + + + // read one line at a time from absolute Windows path + System.out.println(""readLine() from absolute Windows path""); + System.out.println(""---------------------------------------------------------------------------""); + try { + in = new In(""G:\\www\\introcs\\stdlib\\InTest.txt""); + while (!in.isEmpty()) { + String s = in.readLine(); + System.out.println(s); + } + System.out.println(); + } + catch (Exception e) { } + System.out.println(); + + } + +} +" +A20602,"import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class DancingWithTheGooglers { + public static File input; + public static FileReader inputreader; + public static BufferedReader in; + + public static File output; + public static FileWriter outputwriter; + public static BufferedWriter out; + + public static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + public static StringTokenizer st; + + public static void main(String[] args) { + try { + + String name = ""input-2""; + setInput(name); + setOutput(name + "".out""); + + int cases = getInt(); + + for(int caseNr = 1; caseNr <= cases; caseNr++) { + int N = getInt(), S = getInt(), p = getInt(); + + int[] scoreArr = new int[N]; + + for(int i=0; i 10) return 0+getMaximumOfIndexRecursive(index-1, surprisingLeft, scoreArr, scoreGoal, 0); + + thisGoal = (tempGoal > 0) ? tempGoal : scoreGoal; + + + double _a = (double) ((scoreArr[index] - thisGoal) / 2.0); + double _b = _a; + + int a = (int) Math.floor(_a); + int b = (int) Math.ceil(_b); + + a = Math.max(a, 0); + b = Math.max(b, 0); + + int diff = Math.max(Math.max(Math.abs(a-b), Math.abs(a-thisGoal)), Math.abs(b-thisGoal)); + + boolean scoreOk = (a >= 0 && a <= 10 && b >= 0 && b <= 10 && (a + b + thisGoal == scoreArr[index])) ? true : false; + + //System.out.println(""Hmm.. case: "" + scoreArr[index] + "". Values: "" + thisGoal + "", "" + a + "", "" + b + "". (_a och _b)"" + _a + "", "" + _b); + + if (scoreOk && diff < 2) { + //System.out.println(""YES""); + return 1+getMaximumOfIndexRecursive(index-1, surprisingLeft, scoreArr, scoreGoal, 0); + } else if (scoreOk && diff == 2 && surprisingLeft > 0) { + //System.out.println(""YES""); + return 1+getMaximumOfIndexRecursive(index-1, surprisingLeft-1, scoreArr, scoreGoal, 0); + } else if (tempGoal == 0) { + //System.out.println(""NO""); + return 0+getMaximumOfIndexRecursive(index, surprisingLeft, scoreArr, scoreGoal, scoreGoal+1); + } else { + //System.out.println(""NO""); + return 0+getMaximumOfIndexRecursive(index, surprisingLeft, scoreArr, scoreGoal, tempGoal+1); + } + } + + // -------------------- I/O stuff ------------------------- + public static void setInput(String filename) throws IOException { + input = new File(filename); + inputreader = new FileReader(input); + in = new BufferedReader(inputreader); + } + + public static void setOutput(String filename) throws IOException { + output = new File(filename); + outputwriter = new FileWriter(output); + out = new BufferedWriter(outputwriter); + } + + + static void print(String s) throws IOException { + System.out.print(s); + out.write(s); + } + + static String readLine() throws IOException { + //return stdin.readLine(); + return in.readLine(); + } + + static String getToken() throws IOException { + while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(readLine()); + + return st.nextToken(); + } + + static int getInt() throws IOException { + return Integer.parseInt(getToken()); + } + + static String getChar() throws IOException { + return getToken(); + } + + static String getLine() throws IOException { + return readLine(); + } +} +" +A22510,"import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class B { + public static void main (String[] args) + { + Scanner scan = new Scanner(System.in); + int c = scan.nextInt(); + int n, s, p; + for (int i = 1; i <= c; i++) + { + n = scan.nextInt(); + s = scan.nextInt(); + p = scan.nextInt(); + ArrayList ti = new ArrayList(); + for (int j = 0; j < n; j++) + ti.add(new Integer(scan.nextInt())); + Collections.sort(ti); + int count = 0; + for (int j = ti.size()-1; j >= 0; j--) + { + int t = ti.get(j).intValue(); + if ((t+2)/3 >= p) + count++; + else if ((3*p - 4) <= t && s > 0 && t > 3) + { + count++; + s--; + } + } + System.out.println(""Case #"" + i + "": "" + count); + } + } +} +" +A20762,"package com.elbr.codejam2012.qualification.B; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URL; + +public class Dancing { + private static boolean debug = false; + + private static String findP; + + private static int p = 0; + + private static int s = 0; + + private static boolean checkDiff(String prefix, boolean checkNoSurprise) { + prefix = prefix.trim(); + + if (prefix.length() == 0) { + return true; + } + + String[] params = prefix.split(""\\s""); + int max = -1; + int min = -1; + + for (String s : params) { + int i = Integer.parseInt(s); + if (min == -1) { + min = i; + } + + if (max == -1) { + max = i; + } + + max = Math.max(max, i); + min = Math.min(min, i); + } + + if ((max > 10) || (min > 10)) { + return false; + } + + if (((max - min) > 2) || (max < p)) { + return false; + } + + if ((max - min) < 2) { + return true; + } + + if (checkNoSurprise) { + return false; + } + + if (s == 0) { + return false; + } + + s--; + + return true; + } + + public static int count(String input, String countString) { + return input.trim().split(""\\Q"" + countString + ""\\E"", -1).length - 1; + } + + public static void main(String[] in) throws IOException { + // String fileName = ""sample2.in""; + String fileName = ""B-large.in""; + URL file = Dancing.class.getResource(fileName); + String path = file.getFile(); + BufferedReader reader = new BufferedReader(new FileReader(path)); + + File fileOut = new File(fileName + "".out""); + fileOut.createNewFile(); + BufferedWriter writer = new BufferedWriter(new FileWriter(fileOut)); + + int numOfCases = Integer.parseInt(reader.readLine()); + + for (int t = 0; t < numOfCases; t++) { + String line = reader.readLine(); + + String outputLine = ""Case #"" + (t + 1) + "": "" + result(line); + if (true || debug) { + System.out.println(outputLine); + } + writer.write(outputLine + System.getProperty(""line.separator"")); + } + + reader.close(); + writer.close(); + } + + public static void partition(int n, boolean checkNoSurprise) { + findP = null; + + partition(n, n, """", checkNoSurprise); + } + + public static void partition(int n, int max, String prefix, + boolean checkNoSurprise) { + if (findP != null) { + return; + } + + if (n == 0) { + if ((count(prefix, "" "") == 2)) { + if (debug) { + System.out.println(""Check votes: "" + prefix); + } + + if (checkDiff(prefix, checkNoSurprise)) { + findP = prefix; + } + } + return; + } + + for (int i = Math.min(max, n); i >= 1; i--) { + String np = prefix + "" "" + i; + if (count(prefix, "" "") <= 2) { + partition(n - i, i, np, checkNoSurprise); + } + } + } + + private static int result(String line) { + String[] params = line.split(""\\s""); + int n = Integer.parseInt(params[0]); + s = Integer.parseInt(params[1]); + p = Integer.parseInt(params[2]); + + System.out.println(line + "": "" + s + "", "" + p); + + int[] m = new int[n]; + + int a = 0; + for (int i = 0; i < n; i++) { + m[i] = Integer.parseInt(params[3 + i]); + + if (debug) { + System.out.println(m[i] + "" => ""); + } + + if ((m[i] == 0) && (p == 0)) { + findP = ""0 0 0""; + if (debug) { + System.out.println(""not surprise => "" + findP); + } + a++; + } else { + partition(m[i], true); + + if (findP != null) { + a++; + if (debug) { + System.out.println(""not surprise => "" + findP); + } + } else { + if (debug) { + System.out.println(""---""); + } + partition(m[i], false); + if (findP != null) { + a++; + if (debug) { + System.out.println(""surprise => "" + findP); + } + } + } + } + } + + return a; + } +} +"