anonymous No title
Java
public class Alt_Check  {

    private static File altsYmlFile;
    private static FileConfiguration altsYml;
    private static Main plugin;

    public static void put(Player p) {
        String playername = p.getName();
        String uuid = p.getUniqueId().toString();
        String hostname = p.getAddress().getHostName();
        String hostaddress = p.getAddress().getAddress().getHostAddress();

        put(playername, uuid, hostname, hostaddress);
    }

    public static void put(String playername, String uuid, String hostname, String hostaddress) {

        altsYml.set(uuid + ".mcid", playername);

        List<String> hostaddresses = new ArrayList<String>();

        if (altsYml.isSet(uuid + ".ip.hostnames")) {

            hostaddresses = altsYml.getStringList(uuid + ".ip.hostnames");

            if (!hostaddresses.contains(hostname)) {

                hostaddresses.add(hostname);

                altsYml.set(uuid + ".ip.hostnames", hostaddresses);

            }

        } else {

            hostaddresses.add(hostname);

            altsYml.set(uuid + ".ip.hostnames", hostaddresses);

        }

        if (altsYml.isSet(uuid + ".ip.hostaddresses")) {

            hostaddresses = altsYml.getStringList(uuid + ".ip.hostaddresses");

            if (!hostaddresses.contains(hostaddress)) {

                hostaddresses.add(hostaddress);

                altsYml.set(uuid + ".ip.hostaddresses", hostaddresses);

            }

        } else {

            hostaddresses.add(hostaddress);

            altsYml.set(uuid + ".ip.hostaddresses", hostaddresses);

        }
    }

    public static boolean hasPut(Player p) {

        return altsYml.isSet(p.getUniqueId().toString());
    }

    public static List<String> getAltsByHostAddress(String hostaddress) {
        List<String> mcids = new ArrayList<String>();
        for (String uuid : altsYml.getKeys(false)) {
            if (altsYml.isSet(uuid + ".ip.hostaddresses")) {
                if (altsYml.getStringList(uuid + ".ip.hostaddresses").contains(hostaddress)) {
                    mcids.add(altsYml.getString(uuid + ".mcid"));
                }
            }
        }
        return mcids;
    }

    public static List<String> getAltsByHostName(String hostname) {

        List<String> mcids = new ArrayList<String>();

        for (String uuid : altsYml.getKeys(false)) {

            if (altsYml.isSet(uuid + ".ip.hostnames")) {

                if (altsYml.getStringList(uuid + ".ip.hostnames").contains(hostname)) {

                    mcids.add(altsYml.getString(uuid + ".mcid"));
                }
            }
        }

        return mcids;
    }

    public static List<String> getAltsByMCID(String mcid) {

        List<String> mcids = new ArrayList<String>();

        for (String uuid : altsYml.getKeys(false)) {

            if (altsYml.isSet(uuid + ".mcid") && altsYml.getString(uuid + ".mcid").equalsIgnoreCase(mcid)) {

                mcid = altsYml.getString(uuid + ".mcid");

                List<String> hostnames = getHostNamesByMCID(mcid);

                for (String hostname : hostnames) {

                    List<String> alts = getAltsByHostName(hostname);

                    for (String alt : alts) {

                        if (!mcids.contains(alt)) {

                            mcids.add(alt);
                        }
                    }
                }

                List<String> addresses = getAddressesByMCID(mcid);

                for (String address : addresses) {

                    List<String> alts = getAltsByHostAddress(address);

                    for (String alt : alts) {

                        if (!mcids.contains(alt)) {

                            mcids.add(alt);
                        }
                    }
                }
            }
        }
        return mcids;
    }

    public static List<String> getAddressesByMCID(String mcid) {

        for (String uuid : altsYml.getKeys(false)) {

            if (altsYml.isSet(uuid + ".mcid") && altsYml.getString(uuid + ".mcid").equalsIgnoreCase(mcid)) {

                return altsYml.getStringList(uuid + ".ip.addresses");

            }
        }
        return null;
    }

    public static List<String> getHostNamesByMCID(String mcid) {

        for (String uuid : altsYml.getKeys(false)) {

            if (altsYml.isSet(uuid + ".mcid") && altsYml.getString(uuid + ".mcid").equalsIgnoreCase(mcid)) {

                return altsYml.getStringList(uuid + ".ip.hostnames");
            }
        }

        return null;
    }

    public static String getUUIDByMCID(String mcid) {
        for (String uuid : altsYml.getKeys(false)) {
            if (altsYml.isSet(uuid + ".mcid") && altsYml.getString(uuid + ".mcid").equalsIgnoreCase(mcid)) {
                return uuid;
            }
        }
        return null;
    }

    public static String getMCIDbyUUID(String uuid) {

        return altsYml.getString(uuid + ".mcid");
    }

    public static void init() {

        plugin = Main.getInstance();

        altsYmlFile = new File(plugin.getDataFolder(), "alts.yml");

        if (!altsYmlFile.exists()) {

            plugin.saveResource("alts.yml", false);

        }
        altsYml = YamlConfiguration.loadConfiguration(altsYmlFile);
    }

    public static File getAltsYmlFile() {

        return altsYmlFile;
    }

    public static FileConfiguration getAltsYml() {

        return altsYml;
    }

    public static void save() {

        try {

            altsYml.save(altsYmlFile);

        } catch (IOException e) {

            e.printStackTrace();
        }
    }

}

anonymous No title
Java
public class Alts_Main implements CommandExecutor {

    public Alts_Main(){

    }


    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        if (args.length == 0) {

            sender.sendMessage(Main.prefix + "§c引数(player)を入力してください。");

        } else {


            OfflinePlayer op = Bukkit.getOfflinePlayer(args[0]);

            if (op != null && (op.hasPlayedBefore() || op.isOnline())) {

                List<String> alts_ = Alt_Check.getAltsByMCID(args[0]);
                List<String> addresses_ = Alt_Check.getAddressesByMCID(args[0]);
                List<String> hostnames_ = Alt_Check.getHostNamesByMCID(args[0]);

                BanList addressBans = getServer().getBanList(BanList.Type.IP);
                BanList nameBans = getServer().getBanList(BanList.Type.NAME);

                List<String> alts = new ArrayList<String>();
                List<String> addresses = new ArrayList<String>();
                List<String> hostnames = new ArrayList<String>();

                for (String alt : alts_) {

                    if (nameBans.isBanned(alt)) {

                        alts.add("§8- §c" + alt);

                    } else {

                        alts.add("§8- §a" + alt);
                    }
                }

                for (String address : addresses_) {

                    if (nameBans.isBanned(address)) {

                        addresses.add("§8- §c" + address);

                    } else {

                        addresses.add("§8- §a" + address);
                    }
                }

                for (String hostname : hostnames_) {

                    if (nameBans.isBanned(hostname)) {

                        hostnames.add("§8- §c" + hostname);

                    } else {

                        hostnames.add("§8- §a" + hostname);
                    }
                }
                sender.sendMessage("§3§l---------- §b§l" + args[0] + " §3§l----------");

                sender.sendMessage("§fAccount:");

                for (String alt : alts) {
                    sender.sendMessage(alt);
                }

                sender.sendMessage("§fIP:");

                for (String address : addresses) {
                    sender.sendMessage(address);
                }

                for (String hostname : hostnames) {
                    sender.sendMessage(hostname);
                }


                sender.sendMessage("§3§l-----------------------------------");

            } else {

                sender.sendMessage( Main.prefix + "§e" + args[0] + " §cはログインしたことがありません。");
            }
        }
        return true;
    }
}
anonymous No title
Java
final int count2 = 900;

                                        BukkitRunnable bukkitRunnable = new BukkitRunnable() {

                                            int anInt = count2;

                                            public void run() {

                                                if (anInt == 0) {

                                                    for (Player target : Bukkit.getOnlinePlayers()) {

                                                        Inventory inventory = target.getInventory();

                                                        if (inventory.contains(Material.GOLDEN_APPLE) && inventory.contains(Material.BED) && inventory.contains(Material.LAVA_BUCKET)) {

                                                            String name = target.getName();

                                                            Main.Clear.add(name);

                                                            FireworkEffect effect1 = FireworkEffect.builder().with(FireworkEffect.Type.BURST).withColor(Color.ORANGE)
                                                                    .withFade(Color.WHITE).build();

                                                            FireworkEffect effect2 = FireworkEffect.builder().with(FireworkEffect.Type.BURST).withColor(Color.ORANGE)
                                                                    .withFade(Color.WHITE).build();

                                                            Random rnd = new Random();

                                                            target.sendMessage( Main.prefix + "§fあなたは, §eミッション §fを §6クリア済み §fのため, §bゲームクリア §fです。§6おめでとうございます。");

                                                            target.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 1000000, 0,true, false), true);

                                                            BukkitRunnable runnable = new BukkitRunnable() {

                                                                int i3 = 0;

                                                                @Override
                                                                public void run() {

                                                                    Location location = target.getLocation();

                                                                    if (i3 <= 15) {

                                                                        if (i3 < 15) {

                                                                            Firework firework = location.getWorld().spawn(target.getLocation().clone()
                                                                                    .add(rnd.nextInt(6) - 3, rnd.nextInt(3), rnd.nextInt(6) - 3), Firework.class);
                                                                            FireworkMeta fireworkMeta = firework.getFireworkMeta();
                                                                            fireworkMeta.addEffect(effect1);
                                                                            fireworkMeta.setPower(1);
                                                                            firework.setFireworkMeta(fireworkMeta);

                                                                        } else {

                                                                            Firework firework = location.getWorld().spawn(target.getLocation().clone(), Firework.class);
                                                                            FireworkMeta fireworkMeta = firework.getFireworkMeta();
                                                                            fireworkMeta.addEffect(effect2);
                                                                            fireworkMeta.setPower(1);
                                                                            firework.setFireworkMeta(fireworkMeta);
                                                                        }


                                                                        i3++;

                                                                        return;

                                                                    }

                                                                    cancel();

                                                                }
                                                            };

                                                            runnable.runTaskTimer(Main.getPlugin(), 5, 5);


                                                        } else {

                                                            target.sendMessage( Main.prefix + "§fあなたは, §eミッション §fをクリア §cしていない §fため, §4ゲームオーバー §fです。§6お疲れ様でした。");

                                                        }

                                                        target.playSound(target.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
                                                        target.playSound(target.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1, 1);

                                                        target.sendTitle("§b終了", "§c1ダメージ§fでも受けたら§4Ban§fされる§cサバイバルゲーム", 5,20,5);

                                                    }

                                                    Bukkit.broadcastMessage("§b終了");
                                                    Bukkit.broadcastMessage("§c1ダメージ§fでも受けたら§4Ban§fされる§cサバイバルゲーム");

                                                    cancel();

                                                    return;
                                                }


                                                if (anInt <= count2 && anInt>=11) {

                                                    String msg = "§f終了まで残り §b§l" + anInt + "秒§f... ";

                                                    for (Player target : Bukkit.getOnlinePlayers()) {

                                                        TextComponent textComponent = new TextComponent();

                                                        textComponent.setText(msg);

                                                        target.spigot().sendMessage(ChatMessageType.ACTION_BAR, textComponent);


                                                    }

                                                } else if (anInt <= 10 && anInt >= 6) {

                                                    String msg = "§f終了まで残り §e§l" + anInt + "秒§f... ";

                                                    for (Player target : Bukkit.getOnlinePlayers()) {

                                                        target.playSound(target.getLocation(), Sound.BLOCK_NOTE_SNARE, 1, 1);

                                                        TextComponent textComponent = new TextComponent();

                                                        textComponent.setText(msg);

                                                        target.spigot().sendMessage(ChatMessageType.ACTION_BAR, textComponent);


                                                    }

                                                } else if (anInt <= 5 && anInt >= 4) {

                                                    String msg = "§f終了まで残り §c§l" + anInt + "秒§f... ";

                                                    for (Player target : Bukkit.getOnlinePlayers()) {

                                                        target.playSound(target.getLocation(), Sound.BLOCK_NOTE_BASS, 1, 1);


                                                        TextComponent textComponent = new TextComponent();

                                                        textComponent.setText(msg);

                                                        target.spigot().sendMessage(ChatMessageType.ACTION_BAR, textComponent);


                                                    }

                                                } else if (anInt <= 3) {

                                                    String msg = "終了まで残り §c§l" + anInt + "秒§f... ";

                                                    for (Player target : Bukkit.getOnlinePlayers()) {

                                                        target.playSound(target.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 1);


                                                        TextComponent textComponent = new TextComponent();

                                                        textComponent.setText(msg);

                                                        target.spigot().sendMessage(ChatMessageType.ACTION_BAR, textComponent);

                                                        target.sendTitle("§c" + anInt,  "§c1ダメージ§fでも受けたら§4Ban§fされる§cサバイバルゲーム", 5,20,5);


                                                    }
                                                }

                                                anInt--;

                                            }

                                        };
                                        
                                        bukkitRunnable.runTaskTimer(Main.getPlugin(), 0L, 20L);
anonymous No title
Java

//潜水艦撃沈ゲーム
import java.util.Scanner;

class SubmarineGame {
    public static Attack atk = new Attack();
    public int Y, X;
    static Sea[][] sea = new Sea[5][5];

    public static void main(String[] args) {
        // FuneData fd =new FuneData();
        // SeaData sd =new SeaData();
        System.out.println("潜水艦撃沈ゲーム開始!!");
        Scanner stdIn = new Scanner(System.in);
        System.out.print("先攻→ 0 後攻→ 1 を入力:");
        int ForS = stdIn.nextInt();
        if (ForS == 0) {
            int atkx = 0;
            int atky = 0;
            while (true) {
                System.out.println("あなたのターンです。");
                // choose();
                System.out.println("(" + "," + ")" + "を攻撃");
                System.out.print("結果(命中→ 0 波高し→ 1 ハズレ→ 2 命中・撃沈→ 3):");
                int result = stdIn.nextInt();
                if (result == 0) {
                    System.out.println("0の機能は未実装");
                    atk.Hit(atky, atkx);
                }
                if (result == 1) {
                    System.out.println("1の機能は未実装");
                    atk.Namitakashi(atky, atkx);
                }
                if (result == 2) {
                    System.out.println("2の機能は未実装");
                    atk.Miss(atky, atkx);
                }
                if (result == 3) { // 命中(0)と統合できそう
                    System.out.println("3の機能は未実装");
                    atk.Sink(atky, atkx);
                }

                System.out.println("あいてのターンです。");
                System.out.print("攻撃されたy座標を入力:");
                int attackedY = stdIn.nextInt();
                System.out.print("攻撃されたx座標を入力:");
                int attackedX = stdIn.nextInt();
                //System.out.println("結果は" + "  " + "でした。");
                System.out.println("結果は" + Attacked(attackedY, attackedX) + "でした。");
            }
        }

        if (ForS == 1) {
            while (true) {
                System.out.println("あいてのターンです。");
                System.out.print("攻撃されたy座標を入力:");
                int attackedY = stdIn.nextInt();
                System.out.print("攻撃されたx座標を入力:");
                int attackedX = stdIn.nextInt();
                Attacked(attackedY, attackedX);
                //System.out.println("結果は" + "  " + "でした。");
                System.out.println("結果は" + Attacked(attackedY, attackedX) + "でした。");

                System.out.println("あなたのターンです。");
                System.out.println("(" + "," + ")" + "を攻撃");
                System.out.print("結果(命中→ 0 波高し→ 1 ハズレ→ 2 命中・撃沈→ 3):");
                int result = stdIn.nextInt();
                if (result == 0) {
                    System.out.println("0の機能は未実装");
                    atk.Hit(attackedY, attackedX);
                }
                if (result == 1) {
                    System.out.println("1の機能は未実装");
                    atk.Namitakashi(attackedY, attackedX);
                }
                if (result == 2) {
                    System.out.println("2の機能は未実装");
                    atk.Miss(attackedY, attackedX);
                }
                if (result == 3) { // 命中(0)と統合できそう
                    System.out.println("3の機能は未実装");
                    atk.Sink(attackedY, attackedX);
                }
            }
        }
    }

    public static String Attacked(int y, int x) { // 敵陣から攻撃
        String str = " ";
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                sea[i][j] = new Sea(0, 0, 0, 0);
            }
        }
        if (namitaka(y, x) == true | sea[y][x].mikata == 1) {
            if (sea[y][x].mikata == 1) {
                atk.enHit(y, x);
            } else {
                str = atk.enNamitakashi(y, x);
            }
        } else {
            str = atk.enMiss(y, x);
        }
        return str;
    }

    public static boolean namitaka(int y, int x) {
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (sea[y + i][x + j].mikata == 1) {
                    return true;
                }
            }
        }
        return false;
    }
}
class Sea{
  int mikata;  //味方がいるかいないか いる→1 いない→0
  int teki;   //敵がいるかいないか  いる→1 いない→0
  int hp0;    //HPが0の潜水艦がいるかいないか いる→1 いない→0
  int chance;  //敵がいる可能性 数字が大きいほどいる可能性が高い

  Sea(int mikata,int teki,int hp0,int chance){
    this.mikata = mikata;
    this.teki = teki;
    this.hp0 = hp0;
    this.chance = chance;
    
  }

  Sea(){
      this.mikata = 0;
      this.teki = 0;
      this.hp0 = 0;
      this.chance = 0;
  }
  public String toString(){
    String str;
    str = ("海の状況 "+ this.mikata +","+ this.teki +","+ this.hp0 +","+ this.chance);

    return str;
  }

}

public class SeaData{
 SeaData(){
    //インスタンス作成
    Sea[][] sea = new Sea[5][5];
    //初期化
    for(int i=0; i<5; i++){
      for(int j=0; j<5; j++){
        sea[i][j] = new Sea(0,0,0,0);
      }
    }
    //出力
    for(int i=0; i<5; i++){
      for(int j=0; j<5; j++){
        System.out.println("sea["+i+"]"+"["+j+"]"+sea[i][j]);
      }
    }

 }
}
class Attack {
  int bX=0;
  int bY=0;   //攻撃したとこ・されたとこ。bはbombの略。
  Sea[][] sea = new Sea[5][5];
  String str;
  Attack(){
      for(int i = 0;i < 5;i++){
          for(int j = 0;j < 5;j++){
              sea[i][j] = new Sea();
          }
      }
  }
//自陣から攻撃
  public void Hit(int bY,int bX) { //命中

    if(sea[bY][bX].teki == 0) {
      sea[bY][bX].teki = 1;
    }
    /* 敵艦のHP-1
       HPが0になったらSink */
  }

  public void Namitakashi(int bY,int bX) { //波高し

    for(int i = -1; i <= 1; i++) {
      for(int j = -1; j <= 1; j++) {
        sea[bY+i][bX+j].chance++;
      }
    sea[bY][bX].chance = 0;
    }
  }

  public void Miss(int bY,int bX) {  //ハズレ

    for(int i = -1; i <= 1; i++) {
      for(int j = -1; j <= 1; j++) {
        sea[bY+i][bX+j].chance = 0;
      }
    }
  }

  public void Sink(int bY,int bX) {  //撃沈

    //sea[bY][bX] = sea(0, 0, 1, 0);
    sea[bY][bX].mikata = 0;
    sea[bY][bX].teki = 0;
    sea[bY][bX].hp0 = 1;
    sea[bY][bX].chance = 0;
  }


//敵陣から攻撃
  public void enHit(int bY,int bX) { //命中
    enAttack(bY,bX);
    /* 味方艦のHP-1
       HPが0になったらSink
        else{ str= "命中しました" } */
  }

  /*public void enNamitakashi(int bY,int bX) { //波高し
    enAttack(bY,bX);
    str = "波高し";
  }

  public void enMiss(int bY,int bX) {  //ハズレ
    enAttack(bY,bX);
    str = "ハズレです";
  }

  public void enSink(int bY,int bX) {  //撃沈
    enAttack(bY,bX);

    //sea[bY][bX] = sea(0, 0, 1, 0);
    sea[bY][bX].mikata = 0;
    sea[bY][bX].teki = 0;
    sea[bY][bX].hp0 = 1;
    sea[bY][bX].chance = 0;

    str = "沈没しました";
  }*/

  public String enNamitakashi(int bY,int bX) { //波高し
    enAttack(bY,bX);
    return "波高し";
  }

  public String enMiss(int bY,int bX) {  //ハズレ
    enAttack(bY,bX);
    return  "ハズレです";
  }

  public String enSink(int bY,int bX) {  //撃沈
    enAttack(bY,bX);

    //sea[bY][bX] = sea(0, 0, 1, 0);
    sea[bY][bX].mikata = 0;
    sea[bY][bX].teki = 0;
    sea[bY][bX].hp0 = 1;
    sea[bY][bX].chance = 0;

    return "沈没しました";
  }


  public void enAttack(int bY,int bX) {  //敵からの攻撃による居場所特定

    for(int i = -1; i <= 1; i++) {
      for(int j = -1; j <= 1; j++) {
        sea[bY+i][bX+j].chance++;
      }
    }
    sea[bY][bX].chance = 0;
  }

}
Kohei Arai UVa 12392 - Guess the Numbers
Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

	static int[] dx = {0, 1, 0, -1};
	static int[] dy = {-1, 0, 1, 0};
	static long MOD = (long) (1e9 + 7);
	  
	static boolean isAnswerFound = false;
	
	public static void main(String[] args) {
		FastReader in = new FastReader();
		
		while (true) {
			int N = in.nextInt();
			
			int[] nums = new int[N];
			for (int i = 0; i < N; i++) {
				nums[i] = in.nextInt();
			}
			
			int M = in.nextInt();
			if (N == 0 && M == 0) {
				break;
			}
			
			
			String s = in.nextLine();
			isAnswerFound = false;
			System.out.println(solve(nums, M, s) ? "YES" : "NO");
		}
	}
	
	public static boolean solve(int[] nums, int M, String s) {
		int[] newnums = new int[nums.length];
		rec(nums, newnums, 0, s, M);
		return isAnswerFound;
	}
	
	public static void rec(int[] nums, int[] newnums, int index, String s, int M) {
		if (isAnswerFound) {
			return;
		}
		if (index == nums.length) {
			if (isValid(newnums, s, M)) {
				isAnswerFound = true;
			}
		} else {
			for (int i = 0; i < nums.length; i++) {
				if (nums[i] >= 0) {
					int tmp = nums[i];
					nums[i] = -1;
					newnums[index] = tmp;
					rec(nums, newnums, index + 1, s, M);
					nums[i] = tmp;
				}
			}
		}
	}
	
	public static boolean isValid(int[] nums, String s, int M) {
//		printNumArray(nums);
		HashMap<Character, Long> unknownMap = new HashMap<>();
		Stack<CustomClass> stack = new Stack<CustomClass>();
		// 1 => number, 2 => op, 3 => parenthesis 
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			// No number in string, so just look at character by character
			if (c == '(') {
				CustomClass cc = new CustomClass(3);
				stack.add(cc);
			} else if (c == ')') {
				CustomClass keep = stack.pop();
				CustomClass tmp = stack.pop();
				// If it's an opening parenthesis, just replace it with the result of the expression
				if (tmp.type == 3) {
					stack.add(keep);
				}
				// It was an op
				else if (tmp.type == 2) {
					keep.n = exp(stack.pop().n, keep.n, tmp.op);
					// Remove the starting parenthesis
					stack.pop();
					stack.add(keep);
				} else {
					// Should not reach here
					out("This is unexpected");
				}
			} else if (c == '+' || c == '-' || c == '*') {
				CustomClass cc = new CustomClass(2);
				cc.op = c;
				stack.add(cc);
			} else {
				long n = -1;
				if (unknownMap.containsKey(c)) {
					n = unknownMap.get(c);
				} else {
					n = nums[unknownMap.size()];
					unknownMap.put(c, n);
				}
				
				// If we can compute the result, compute the result
				if (stack.size() > 0 && stack.peek().type == 2) {
					CustomClass op = stack.pop();
					n = exp(stack.pop().n, n, op.op);
					// Add the result of expression back to the result
					CustomClass cc = new CustomClass(1);
					cc.n = n;
					stack.add(cc);
				} else {
					CustomClass cc = new CustomClass(1);
					cc.n = n;
					stack.add(cc);
				}
			}
		}
		
		return stack.pop().n == M;
	}
	
	public static long exp(long a, long b, char op) {
		if (op == '+') {
			return a + b;
		} else if (op == '-') {
			return a - b;
		} else if (op == '*') {
			return a * b;
		} else {
			out("Unknown operation");
			return a;
		}
	}
	
	public static int maxSideLength(int[][] mat, int threshold) {
		if (mat == null || mat.length == 0 || mat[0].length == 0) {
			return 0;
		}
		
		int M = mat.length;
		int N = mat[0].length;
		
		// Precompute the sum
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				mat[i][j] = getAt(mat, i, j) + getAt(mat, i - 1, j) + getAt(mat, i, j - 1) - getAt(mat, i - 1, j - 1);
			}
		}
		
		int ans = 0;
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 1; i + k < M && j + k < N; k++) {
					int area = getAt(mat, i + k, j + k) - getAt(mat, i + k, j - 1) - getAt(mat, i - 1, j + k) + getAt(mat, i - 1, j - 1);
					if (area <= threshold) {
						ans = Math.max(ans, k + 1);
					}
				}
			}
		}
		
		return ans;
	}
	
	public static int getAt(int[][] mat, int i, int j) {
		if (i < 0 || j < 0) return 0;
		return mat[i][j];
	}
	
    public static List<Integer> findAnagrams(String s, String p) {
    	List<Integer> ans = new ArrayList<Integer>();
        
    	int[] pfreq = new int[26];
        for (int i = 0; i < p.length(); i++) {
            pfreq[p.charAt(i) - 'a']++;
        }
        
        int[] sfreq = new int[26];
        for (int i = 0; i < p.length() && i < s.length(); i++) {
        	sfreq[s.charAt(i) - 'a']++;
        }
        
        // key is in the format character###,
        String pkey = "";
        String skey = "";
        
        for (int i = 0; i < 26; i++) {
        	pkey += String.format("%c%d,", i + 'a', pfreq[i]);
        	skey += String.format("%c%d,", i + 'a', sfreq[i]);
        }
        
        for (int i = p.length(); i < s.length(); i++) {
        	char removed = s.charAt(i - p.length());
        	char added = s.charAt(i);
        	
        	
        }
        
        return ans;
    }

	public static int count(String[] arr, Map<String, Map<Character, TreeSet<Integer>>> map, String s) {
		int count = 0;
		for (int i = 0; i < arr.length; i++) {
			if (subsequence(s, map.get(arr[i]))) {
				count++;
			}
		}
		return count;
	}
	
	public static boolean subsequence(String s, Map<Character, TreeSet<Integer>> map) {
		char f = s.charAt(0);
		char m = s.charAt(1);
		char e = s.charAt(2);
		if (!map.containsKey(f) || !map.containsKey(m) || !map.containsKey(e)) {
			return false;
		}
		
		Iterator<Integer> it = map.get(m).iterator();
		while (it.hasNext()) {
			int index = it.next();
			if (map.get(f).lower(index) != null && map.get(e).higher(index) != null) {
				return true;
			}
		}
		
		return false;
	}
	
	public static String str(int i, int j, int k) {
		return String.format("%c%c%c", c(i), c(j), c(k));
	}
	
	public static char c(int i) {
		if (i < 26) {
			return (char) ('A' + i);
		} else {
			i -= 26;
			return (char) ('a' + i);
		}
	}
	
	public static int sol(int N, int k) {
		if (N == 1 && k == 1) return 1;
		int parent = sol(N - 1, (k + 1) / 2);
		if (k % 2 == 0) {
			return (parent + 1) % 2;
		} else {
			return parent;
		}
	}
	
	public static double calculate(double base, double n) {
        return Math.pow(Math.E, Math.log(base)/n);
    }
	
	public static int partition(int[] nums, int low, int high) { // [1,2], 0, 1
		// Pick the first element as pivot
		// int pivot = nums[low]; // 1
		//
		// int left = low + 1; // 2
		// int right = high; // 1
		//
		//
		// while (left <= right) { // This equal to is important to move right
		// cursor left cursor correct position
		// if (nums[left] <= pivot) {
		// left++;
		// continue;
		// }
		// if (pivot <= nums[right]) {
		// right--;
		// continue;
		// }
		// int tmp = nums[left];
		// nums[left] = nums[right];
		// nums[right] = tmp;
		// }
		// int tmp = nums[low];
		// nums[low] = nums[right];
		// nums[right] = tmp;
		//
		// return right;

		// Pick the last element as pivot
		int pivot = nums[high];

		int left = low;
		int right = high - 1;

		while (left <= right) {
			if (nums[left] <= pivot) {
				
				left++;
				continue;
			}
			if (pivot <= nums[right]) {
				right--;
				continue;
			}
			int tmp = nums[left];
			nums[left] = nums[right];
			nums[right] = tmp;
		}
		int tmp = nums[high];
		nums[high] = nums[left];
		nums[left] = tmp;

		return left;
	}

	// Pivot is the first element
	public static int partitionFront(int[] nums, int low, int high) {
		int pivot = nums[low];

		int left = low + 1;

		while (left <= high) {
			// Increment left until it reaches the element greater than pivot
			while (left <= high && nums[left] <= pivot)
				left++;
			while (left <= high && nums[high] >= pivot)
				high--;

			if (left < high) {
				int tmp = nums[left];
				nums[left] = nums[high];
				nums[high] = tmp;
			}
		}
		int tmp = nums[low];
		nums[low] = nums[high];
		nums[high] = tmp;

		return high;
	}

	// Pivot is the last element
	public static int partitionBack(int[] nums, int low, int high) {
		int pivot = nums[high];

		int right = high - 1;

		while (low <= right) {
			// Increment low until it is greater than pivot
			while (low <= right && nums[low] <= pivot)
				low++;
			// Decrement right until it is less than pivot
			while (low <= right && nums[right] >= pivot)
				right--;

			if (low < right) {
				int tmp = nums[low];
				nums[low] = nums[right];
				nums[right] = tmp;
			}
		}

		int tmp = nums[low];
		nums[low] = nums[high];
		nums[high] = tmp;

		return low;
	}

	public static void out(Object o) {
		System.out.println(o);
	}

	public static void print(Object o) {
		System.out.print(o);
	}

	public static void printNumArray(int[] nums) {
		System.out.printf("[");
		for (int i = 0; i < nums.length; i++) {
			System.out.printf("%d%s", nums[i], i != nums.length - 1 ? ", " : "");
		}
		System.out.println("]");
	}

	public static void printNumArray(long[] nums) {
		System.out.printf("[");
		for (int i = 0; i < nums.length; i++) {
			System.out.printf("%d%s", nums[i], i != nums.length - 1 ? ", " : "");
		}
		System.out.println("]");
	}

	public static void printDoubleArray(double[] nums) {
		System.out.printf("[");
		for (int i = 0; i < nums.length; i++) {
			System.out.printf("%f%s", nums[i], i != nums.length - 1 ? ", " : "");
		}
		System.out.println("]");
	}

	public static void printDoubleList(List<List<Integer>> nums) {
		for (int i = 0; i < nums.size(); i++) {
			printNumList(nums.get(i));
		}
	}

	public static void printNumList(List<Integer> nums) {
		System.out.printf("[");
		for (int i = 0; i < nums.size(); i++) {
			System.out.printf("%d%s", nums.get(i), i != nums.size() - 1 ? ", " : "");
		}
		System.out.println("]");
	}

	public static void printStringList(List<String> list) {
		System.out.printf("[");
		for (int i = 0; i < list.size(); i++) {
			System.out.printf("%s%s", list.get(i), i != list.size() - 1 ? ", " : "");
		}
		System.out.println("]");
	}

	public static void printStringArray(String[] arr) {
		print("[");
		for (int i = 0; i < arr.length; i++) {
			print(String.format("%s%s", arr[i], i != arr.length - 1 ? ", " : ""));
		}
		out("]");
	}

	public static void printStringListOfStringList(List<List<String>> list) {
		for (int i = 0; i < list.size(); i++) {
			printStringList(list.get(i));
		}
	}

	public static void printNumListOfNumList(List<List<Integer>> num) {
		for (int i = 0; i < num.size(); i++) {
			printNumList(num.get(i));
		}
	}
	
	public static void printNumListOfNumArray(List<int[]> list) {
		for (int i = 0; i < list.size(); i++) {
			printNumArray(list.get(i));
		}
	}

	public static void printNum2DArray(int[][] map) {
		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[i].length; j++) {
				System.out.printf("%2d ", map[i][j]);
			}
			System.out.println();
		}
	}

	public static void printNum2DArray(long[][] map) {
		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[i].length; j++) {
				System.out.printf("%2d ", map[i][j]);
			}
			System.out.println();
		}
	}
	
	public static void printCharArray(char[] arr) {
		print("[");
		for (int i = 0; i < arr.length; i++) {
			System.out.printf("%c%s", arr[i], i == arr.length - 1 ? "" : ", ");
		}
		out("]");
	}

	public static void printChar2DArray(char[][] map) {
		for (char[] arr : map) {
			for (char c : arr) {
				print(String.format("%c ", c));
			}
			out("");
		}
	}

	public static void printBoolean2DArray(boolean[][] map) {
		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[0].length; j++) {
				print(map[i][j] ? "T " : "F ");
			}
			out("");
		}
	}

	public static void printListNode(ListNode node) {
		boolean first = true;
		while (node != null) {
			if (!first) {
				print("->");
			}
			print(node.val);
			node = node.next;
			first = false;
		}
	}

	public static void printStringSet(Set<String> set) {
		for (String s : set) {
			out(s);
		}
	}

	/**
	 * Receives an integer and print in numBits from the right
	 * 
	 * @param n
	 * @param numBits
	 */
	public static void printBinary(int n, int numBitsFromRight) {
		String s = "";
		for (int i = numBitsFromRight - 1; i >= 0; i--) {
			s += (n & (1 << i)) > 0 ? "1" : "0";
		}
		out(s);
	}

	// Taken from
	// https://www.geeksforgeeks.org/c-program-find-gcd-hcf-two-numbers/
	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}
	
	public static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
	
	public static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}
}

class TreeNode {
	int val;
	TreeNode left;
	TreeNode right;

	TreeNode(int x) {
		val = x;
	}
}

class CustomClass {
	int type; // 1 => number, 2 => op, 3 => parenthesis
	// parenthesis will be stored in op
	char op;
	long n;
	
	public CustomClass(int type) {
		this.type = type;
	}
}

class TreeDrawer {
	public static String treeNodeToString(TreeNode root) {
		if (root == null) {
			return "[]";
		}

		String output = "";
		Queue<TreeNode> nodeQueue = new LinkedList<>();
		nodeQueue.add(root);
		while (!nodeQueue.isEmpty()) {
			TreeNode node = nodeQueue.remove();

			if (node == null) {
				output += "null, ";
				continue;
			}

			output += String.valueOf(node.val) + ", ";
			nodeQueue.add(node.left);
			nodeQueue.add(node.right);
		}
		return "[" + output.substring(0, output.length() - 2) + "]";
	}

	public static TreeNode stringToTreeNode(String input) {
		input = input.trim();
		input = input.substring(1, input.length() - 1);
		if (input.length() == 0) {
			return null;
		}

		String[] parts = input.split(",");
		String item = parts[0];
		TreeNode root = new TreeNode(Integer.parseInt(item));
		Queue<TreeNode> nodeQueue = new LinkedList<>();
		nodeQueue.add(root);

		int index = 1;
		while (!nodeQueue.isEmpty()) {
			TreeNode node = nodeQueue.remove();

			if (index == parts.length) {
				break;
			}

			item = parts[index++];
			item = item.trim();
			if (!item.equals("null")) {
				int leftNumber = Integer.parseInt(item);
				node.left = new TreeNode(leftNumber);
				nodeQueue.add(node.left);
			}

			if (index == parts.length) {
				break;
			}

			item = parts[index++];
			item = item.trim();
			if (!item.equals("null")) {
				int rightNumber = Integer.parseInt(item);
				node.right = new TreeNode(rightNumber);
				nodeQueue.add(node.right);
			}
		}
		return root;
	}

	public static void prettyPrintTree(TreeNode node, String prefix, boolean isLeft) {
		if (node == null) {
			System.out.println("Empty tree");
			return;
		}

		if (node.right != null) {
			prettyPrintTree(node.right, prefix + (isLeft ? "│   " : "    "), false);
		}

		System.out.println(prefix + (isLeft ? "└── " : "┌── ") + node.val);

		if (node.left != null) {
			prettyPrintTree(node.left, prefix + (isLeft ? "    " : "│   "), true);
		}
	}

	public static void draw(TreeNode node) {
		prettyPrintTree(node, "", true);
	}
}

class Interval {
	int start;
	int end;

	Interval() {
		start = 0;
		end = 0;
	}

	Interval(int s, int e) {
		start = s;
		end = e;
	}
}

class ListNode {
	int val;
	ListNode next;

	ListNode(int x) {
		val = x;
	}
}

class FastReader { 
    BufferedReader br; 
    StringTokenizer st; 

    public FastReader() 
    { 
        br = new BufferedReader(new
                 InputStreamReader(System.in)); 
    } 

    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 

    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 

    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 

    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 

    String nextLine() 
    { 
        String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
} 
Kohei Arai LeetCode 1292 Maximum Side Length of a Square with Sum Less than or Equal to Threshold
Java
class Solution {
    public int maxSideLength(int[][] mat, int threshold) {
		if (mat == null || mat.length == 0 || mat[0].length == 0) {
			return 0;
		}
		
		int M = mat.length;
		int N = mat[0].length;
		
		// Precompute the sum
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				mat[i][j] = getAt(mat, i, j) + getAt(mat, i - 1, j) + getAt(mat, i, j - 1) - getAt(mat, i - 1, j - 1);
			}
		}
		
		int ans = 0;
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 1; i + k < M && j + k < N; k++) {
					int area = getAt(mat, i + k, j + k) - getAt(mat, i + k, j - 1) - getAt(mat, i - 1, j + k) + getAt(mat, i - 1, j - 1);
					if (area <= threshold) {
						ans = Math.max(ans, k + 1);
					}
				}
			}
		}
		
		return ans;
    }

	public int getAt(int[][] mat, int i, int j) {
		if (i < 0 || j < 0) return 0;
		return mat[i][j];
	}

}
Kohei Arai No title
Java
class Solution {
    public static int kthGrammar(int N, int K) {
    	return sol(N, K - 1);
    }
    
    public static int sol(int N, int K) {
        if (N == 1) return 0;
        int prev = sol(N - 1, K / 2);
        if (prev == 0) {
            return K % 2;
        } else {
            return (K % 2 + 1) % 2;
        }
    }
}
anonymous No title
Java
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
  public int countNodes(TreeNode root) {
    if (root == null) {
      return 0;
    }

    int level = getLevel(root);
    int ok = 1 << (level - 1);
    int ng = 1 << level;

    // binary search between low and high
    while (ng - ok > 1) {
      int mid = (ng + ok) / 2;
      if (doesExist(root, mid)) {
        ok = mid;
      } else {
        ng = mid;
      }
    }

    return ok;
  }

  public boolean doesExist(TreeNode root, int n) {
    List<Integer> order = new ArrayList<Integer>();
    while (n > 1) {
      if (n % 2 == 0) {
        order.add(0, 0);
      } else {
        order.add(0, 1);
      }
      n /= 2;
    }
    for (int i = 0; i < order.size(); i++) {
      if (order.get(i) == 0) {
        root = root.left;
      } else {
        root = root.right;
      }
    }
    return root != null;
  }

  public int getLevel(TreeNode root) {
    int level = 0;
    while (root != null) {
      level++;
      root = root.left;
    }

    return level;
  }
    
}
anonymous No title
Java
class Test extends StatelessWidget {
  final void Function(String value) callback;

  Test(this.callback);
  @override
  Widget build(BuildContext context) {
    return TextField(
      onChanged: callback,
    );
  }
}
anonymous No title
Java
class Test extends StatelessWidget {
  void Function(String value) callback;
  @override
  Widget build(BuildContext context) {
    return TextField(
      onChanged: callback,
    );
  }
}
Don't you submit code?
Submit