1. 
/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: ad hoc
* Problem: 201 - Squares
* Accepted: 1.932
* @author Evgeni Pavlidis
*
*/
import java.util.*;
import java.io.*;

public class Main {

// horizontal/vertical constants
private static int H = 0;
private static int V = 1;

// saves the horizontal/vertical connections between:
// x y and x+1 y if horizontal
// x y and x y + 1 if vertical
private static boolean[][][] square;
private static int n;

private static boolean check(int y, int x, int size)
{
// check horizontal
for(int s = 0; s < size; s++)
if(!square[H][y][x+s] || !square[H][y+size][x+s])
return false;

// check vertical
for(int s = 0; s < size; s++)
if(!square[V][x][y+s] || !square[V][x+size][y+s])
return false;

return true;
}

public static void main(String...args)
{
Scanner sc = new Scanner(System.in);
int problemNumber = 1;
boolean found;

while(sc.hasNextInt())
{
if(problemNumber > 1)
System.out.println("\n**********************************\n");
System.out.println("Problem #" + problemNumber++ + "\n");

n = sc.nextInt();
square = new boolean[2][n+1][n+1];
int inputs = sc.nextInt();
String orientation;
int counter, a, b;


for(int i = 0; i < inputs; i++)
{
orientation = sc.next();
a = sc.nextInt();
b = sc.nextInt();
if(orientation.equals("H"))
square[H][a][b] = true;
else
square[V][a][b] = true;
}


found = false;
for(int size = 1; size <= n; size++)
{
counter = 0;

for(int y = 1; y <= n-size; y++)
for(int x = 1; x <= n-size; x++)
if(check(y,x,size))
counter++;

if(counter > 0)
{
found = true;
System.out.printf("%d square (s) of size %d\n", counter, size);
}

}

if(!found)
System.out.println("No completed squares can be found.");
}
}
}