@@ -0,0 +1,1644 @@
+import java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0A// Brute-force solution, runs in O(n%5E3) time, and has O(n) storage complexity%0Apublic class Solution %7B%0A  static class Result %7B%0A    int topics;%0A    int teams;%0A    Result(int topics, int teams) %7B%0A      this.topics = topics;%0A      this.teams = teams;%0A    %7D%0A  %7D%0A%0A  private static int mergeAndCountTopics(String a, String b) %7B%0A    int cnt = 0;%0A    for (int i = 0; i %3C a.length(); i++) %7B%0A      if (a.charAt(i) == '1' %7C%7C b.charAt(i) == '1') %7B%0A        cnt++;%0A      %7D%0A    %7D%0A    return cnt;%0A  %7D%0A%0A  private static Result findMaxTopics(String%5B%5D topic) %7B%0A    if (topic == null %7C%7C topic.length == 0) return new Result(0, 0);%0A    HashMap%3CString, Integer%3E agg = new HashMap%3CString, Integer%3E();%0A    for (int i = 0; i %3C topic.length; i++) %7B%0A      for (int j = i + 1; j %3C topic.length; j++) %7B%0A        agg.put(i + %22-%22 + j, mergeAndCountTopics(topic%5Bi%5D, topic%5Bj%5D));%0A      %7D%0A    %7D%0A%0A    int maxTopic = 0;%0A    for (String key : agg.keySet()) %7B%0A      maxTopic = Math.max(maxTopic, agg.get(key));%0A    %7D%0A%0A    int maxTeams = 0;%0A    for (String key : agg.keySet()) %7B%0A      if (agg.get(key) == maxTopic) %7B%0A        maxTeams++;%0A      %7D%0A    %7D%0A%0A    return new Result(maxTopic, maxTeams);%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    Scanner in = new Scanner(System.in);%0A    int n = in.nextInt();%0A    int m = in.nextInt();%0A    String topic%5B%5D = new String%5Bn%5D;%0A    for (int topic_i = 0; topic_i %3C n; topic_i++) %7B%0A      topic%5Btopic_i%5D = in.next();%0A    %7D%0A%0A    Result res = findMaxTopics(topic);%0A    System.out.println(res.topics);%0A    System.out.println(res.teams);%0A  %7D%0A%7D%0A

add solution for acm-icpc