Problem:


平面上の図形

縦 8、横 8 のマスからなる図 1 のような平面があります。

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

図１

この平面上に、以下の A から G の図形のどれかが一つだけ置かれています。

	

A

	

		
■■

		
■■

		

		

	

	

B

	

		
■

		
■

		
■

		
■

	

	

C

	

		
■■■■

		

		

		

	

	

D

	

		
■

		
■■

		
■

		

	

	

E

	

		
■■

		
■■

		

		

	

	

F

	

		
■

		
■■

		
■

		

	

	

G

	

		
■■

		
■■

		

		

	

		

たとえば、次の図 2 の例では E の図形が置かれています。

□□□□□□□□

□□□□□□□□

□■■□□□□□

□□■■□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

図２

平面の中で図形が占めているマスを 1、占めていないマスを 0 で表現した数字の列を読み込んで、置かれている図形の種類（A〜G）を出力するプログラムを作成してください。

ただし、ひとつの平面に置かれている図形は必ず１つで、複数の図形が置かれていることはありません。また、A〜G で表される図形以外のものが置かれていることはありません。

Input

入力は複数のデータセットからなります。

１つのデータセットとして、平面の中で図形が占めているマスを 1、占めていないマスを 0 で表現した 8 文字からなる 8 つの文字列が与えられます。例えば、図 2 に対応する文字列の並びは次のようになります。

00000000

00000000

01100000

00110000

00000000

00000000

00000000

00000000

データセットの間は１つの空行で区切られています。データセットの数は 50 を超えません。

Output

各データセットごとに、平面に与えられた図形の種類（A〜G のいずれか）を１行に出力してください。

Sample Input

00000000
00000000
01100000
00110000
00000000
00000000
00000000
00000000

00011110
00000000
00000000
00000000
00000000
00000000
00000000
00000000

00000000
00000000
00110000
00110000
00000000
00000000
00000000
00000000

Output for the Sample Input

E
C
A



Sample input:
00000000
00000000
01100000
00110000
00000000
00000000
00000000
00000000

00011110
00000000
00000000
00000000
00000000
00000000
00000000
00000000

00000000
00000000
00110000
00110000
00000000
00000000
00000000
00000000


Sample output:
E
C
A

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        for i in range(8):
            tmp = raw_input()
            if int(tmp) != 0:
                a[h] = tmp
                h += 1
        if h == 4:
            print "B"
        elif h == 1:
            print "C"
        elif h == 2:
            c = int(a[0])/int(a[1])
            if c == 1:
                print "A"
            elif c == 8:
                print "E"
            else:
                print "G"
        else:
            c = int(a[0])/int(a[2])
            if c == 8:
                print "F"
            else:
                print "D"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        for i in range(8):
            tmp = raw_input()
            if int(tmp) != 0:
                a[h] = tmp
                h += 1
        if h == 1:
            print "C"
        elif h == 2:
            c = a[0].index(1) - a[1].index(1)
            if c == 0:
                print "A"
            elif c == 1:
                print "E"
            else:
                print "G"
        elif h == 3:
            c = a[0].index(1) - a[2].index(1)
            print "D" if c == 0 else "F"
        else:
            print "B"

    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        for i in range(8):
            tmp = raw_input()
            if int(tmp) != 0:
                a[h] = tmp
                h += 1
        if h == 1:
            print "C"
        elif h == 2:
            c = a[0].index(1) - a[1].index(1)
            if c == 0:
                print "A"
            elif c == 1:
                print "E"
            else:
                print "G"
        elif h == 3:
            c = a[0].index(1) - a[2].index(1)
            print "D" if c == -1 else "F"
        else:
            print "B"

    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        for i in range(8):
            tmp = raw_input()
            if tmp.count(1) != 0:
                a[h] = tmp
                h += 1
        if h == 1:
            print "C"
        elif h == 2:
            c = a[0].index(1) - a[1].index(1)
            if c == 0:
                print "A"
            elif c == 1:
                print "E"
            else:
                print "G"
        elif h == 3:
            c = a[0].index(1) - a[2].index(1)
            print "D" if c == -1 else "F"
        else:
            print "B"

    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        a=["","","",""]
        for i in range(8):
            tmp = raw_input()
            if int(tmp) != 0:
                a[h] = tmp
                h += 1
        if h == 1:
            print "C"
        elif h == 2:
            c = a[0].index("1") - a[1].index("1")
            if c == 0:
                print "A"
            elif c == -1:
                print "E"
            else:
                print "G"
        elif h == 3:
            c = a[0].index("1") - a[2].index("1")
            print "D" if c == 1 else "F"
        else:
            print "B"

    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        a=["","","",""]
        for i in range(8):
            tmp = raw_input()
            if int(tmp) != 0:
                a[h] = tmp
                h += 1
        if h == 1:
            print "C"
        elif h == 2:
            c = a[0].index("1") - a[1].index("1")
            if c == 0:
                print "A"
            elif c == -1:
                print "E"
            else:
                print "G"
        elif h == 3:
            c = a[0].index("1") - a[2].index("1")
            print "D" if c == 1 else "F"
        else:
            print "B"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        a=["","","",""]
        for i in range(9):
            tmp = raw_input()
            if int(tmp) != 0:
                a[h] = tmp
                h += 1
        if h == 1:
            print "C"
        elif h == 2:
            c = a[0].index("1") - a[1].index("1")
            if c == 0:
                print "A"
            elif c == -1:
                print "E"
            else:
                print "G"
        elif h == 3:
            c = a[0].index("1") - a[2].index("1")
            print "D" if c == 1 else "F"
        else:
            print "B"
    except:
        break

Submission status: Wrong Answer

Solution code:
h = 0
a=["","","",""]
for i in range(8):
    tmp = raw_input()
    if int(tmp) != 0:
        a[h] = tmp
        h += 1
    if h == 1:
        print "C"
    elif h == 2:
        c = a[0].index("1") - a[1].index("1")
        if c == 0:
            print "A"
        elif c == -1:
            print "E"
        else:
            print "G"
    elif h == 3:
        c = a[0].index("1") - a[2].index("1")
        print "D" if c == 1 else "F"
    else:
        print "B"
while True:
    try:
        tmp = raw_input()
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
	h = 0
        a=["","","",""]
	for i in range(8):
    	    tmp = raw_input()
    	if int(tmp) != 0:
            a[h] = tmp
            h += 1
            if h == 1:
                print "C"
    	    elif h == 2:
        	c = a[0].index("1") - a[1].index("1")
                if c == 0:
                    print "A"
                elif c == -1:
                    print "E"
                else:
                    print "G"
    	    elif h == 3:
        	c = a[0].index("1") - a[2].index("1")
        	print "D" if c == 1 else "F"
            else:
                print "B"
    	tmp = raw_input()
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        h = 0
        a=["","","",""]
        for i in range(8):
            tmp = raw_input()
        if int(tmp) != 0:
            a[h] = tmp
            h += 1
            if h == 1:
                print "C"
            elif h == 2:
                c = a[0].index("1") - a[1].index("1")
                if c == 0:
                    print "A"
                elif c == -1:
                    print "E"
                else:
                    print "G"
            elif h == 3:
                c = a[0].index("1") - a[2].index("1")
                print "D" if c == 1 else "F"
            else:
                print "B"
    	raw_input()
    except:
	break

Submission status: Wrong Answer

Solution code:
p = ['0'+raw_input()+'000' for i in range(8)]
p.extend(['0'*12 for i in range(3)])

for i in range(len(p)):
	if '1' in p[i]:
		index = p[i].index('1')
		if p[i][index+1] == '1':
			if p[i+1][index] == '1':
				if p[i+1][index+1] == '1':
					print "A"
				else:
					print "G"
			else:
				if p[i][index+2] == '1':
					print "C"
				else:
					print "E"
		else:
			if p[i+2][index] == '1':
				print "B"
			else:
				if p[i-1][index] == '1':
					print "D"
				else:
					print "F"
		break

Submission status: Wrong Answer

Solution code:
p = ['0'+raw_input()+'000' for i in range(8)]
p.extend(['0'*12 for i in range(3)])

for i in range(len(p)):
	if '1' in p[i]:
		index = p[i].index('1')
		if p[i][index+1] == '1':
			if p[i+1][index] == '1':
				if p[i+1][index+1] == '1':
					print "A"
				else:
					print "G"
			else:
				if p[i][index+2] == '1':
					print "C"
				else:
					print "E"
		else:
			if p[i+2][index] == '1':
				print "B"
			else:
				if p[i+1][index] == '1':
					print "D"
				else:
					print "F"
		break

Submission status: Wrong Answer

Solution code:
p = ['0'+raw_input()+'000' for i in range(8)]
p.extend(['0'*12 for i in range(3)])

for i in range(len(p)):
	if '1' in p[i]:
		index = p[i].index('1')
		if p[i][index+1] == '1':
			if p[i+1][index] == '1':
				if p[i+1][index+1] == '1':
					print "A"
				else:
					print "G"
			else:
				if p[i][index+2] == '1':
					print "C"
				else:
					print "E"
		else:
			if p[i+2][index] == '1':
				print "B"
			else:
				if p[i+1][index-1] == '1':
					print "D"
				else:
					print "F"
		break

Submission status: Time Limit Exceeded

Solution code:
def trim():
    num=[]
    N=[input() for _ in range(8)]
    for x in range(8):
        for y in range(8):
            if N[y][x]=="1":
                if not num:
                    refer=(x,y)
                num.append((x,y))
    num=[(x-refer[0],y-refer[1]) for x,y in num]
    return num
def point(point):
    if point==[(0,0),(0,1),(1,0),(1,1)]:print("A")
    if point==[(0,0),(0,1),(0,2),(0,3)]:print("B")
    if point==[(1,0),(2,0),(3,0),(4,0)]:print("C")
    if point==[(0,0),(0,1),(1,-1),(1,0)]:print("D")
    if point==[(0,0),(1,0),(1,1),(2,1)]:print("E")
    if point==[(0,0),(0,1),(1,1),(1,2)]:print("F")
    if point==[(0,0),(1,-1),(1,0),(2,-1)]:print("G")
while True:
    try:
        point(trim)
    except:break

Submission status: Accepted

Solution code:
ans = [0,0,0,"C",0,0,0,0,"G","A","E",0,0,0,0,"D",0,"F",0,0,0,0,0,0,"B"]
while(True):
    h = ""
    for _ in range(8):
        h +=input()
    print(ans[h.rfind("1")-h.find("1")])
    try:
        b =input()
    except:
        break

Submission status: Accepted

Solution code:
def trim(N):
    num=[]
    for x in range(8):
        for y in range(8):
            if N[y][x]=="1":
                if not num:
                    refer=(x,y)
                num.append((x,y))
    num=[(x-refer[0],y-refer[1]) for x,y in num]
    return num
def points(point):
    if point==[(0,0),(0,1),(1,0),(1,1)]:print("A")
    if point==[(0,0),(0,1),(0,2),(0,3)]:print("B")
    if point==[(0,0),(1,0),(2,0),(3,0)]:print("C")
    if point==[(0,0),(0,1),(1,-1),(1,0)]:print("D")
    if point==[(0,0),(1,0),(1,1),(2,1)]:print("E")
    if point==[(0,0),(0,1),(1,1),(1,2)]:print("F")
    if point==[(0,0),(1,-1),(1,0),(2,-1)]:print("G")
while True:
    N=[input() for _ in range(8)]
    points(trim(N))
    try:
        input()
    except:break

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
patc = [0,1,2,3]
patg = [0,1,7,8]
pata = [0,1,8,9]
pate = [0,1,9,10]
patd = [0,7,8,15]
patf = [0,8,9,17]
patb = [0,8,16,24]
pats = [patc,patg,pata,pate,patd,patf,patb]
pats.sort(key = lambda x:x[-1])
patsname = ["C","G","A","E","D","F","B"]

def iscomp(data,pat):
  if sum([ 1 for s in pat if data[s] == 1]) == len(pat):
    return True
  else:
    return False

def whichpat(data):
  for i in xrange(len(pats)):
    if iscomp(data,pats[i]):
      return i

d = []
b = []
i = 0
for s in sys.stdin:
  if i != -1:
    d.append( [ 1 if e == "1" else 0 for e in  map(str,s)[:-1]])
  i += 1
  if i == 8:
    b.append( [ c for e in d for c in e] )
    d = []
    i = -1
for c in b:
  print patsname[whichpat(c[c.index(1):])]

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

figures = {'A':['11','11'],
'B':['1','1','1','1'],
'C':['1111'],
'D':['01','11','10'],
'E':['110','011'],
'F':['10','11','01'],
'G':['011','110']}

def figure_in_board(figure, board):
    for i in range(len(board)):
        index = board[i].find(figure[0])
        if index != -1 and i + len(figure) <= len(board):
            for j in range(1, len(figure)):
                if index != board[i + j].find(figure[j]):
                    return False
            return True
    return False

while True:
    board = [f.readline().strip() for _ in range(8)]
    for k, v in figures.items():
        if figure_in_board(v, board):
            print(k)
            break
    
    if f.readline() == '':
        break

Submission status: Accepted

Solution code:
def hantei(bit):
    list=[]
    for i in range(8):
        for j in range(8):
            if bit[i*8+j]=='1':
                list.append(i*8+j) 
    second=list[1]-list[0]
    third=list[2]-list[0]
    fourth=list[3]-list[0]
    sum=second+third+fourth
    return sum


while True:
    try:
        bit=[0]*64
        for i in range(8):
            line=raw_input()
            for j in range(8):
                bit[i*8+j]=line[j]
        result=hantei(bit)
        if result==18:
            print "A"
        elif result==48:
            print "B"
        elif result==6:
            print "C"
        elif result==30:
            print "D"
        elif result==20:
            print "E"
        elif result==34:
            print "F"
        else:
            print "G"
        raw_input()
    except:
        break

Submission status: Accepted

Solution code:
import sys
s=p=0
for l in sys.stdin:
	if l.strip()=="":
		s=p=0
		continue
	if s==5:continue
	t=int(l)
	c=l.count("1")
	if c==4:
		s=5
		print"C"
	if s==1:
		if c==1:print"B"
		elif t/p==1:print"F"
		else: print"D"
		s=5
	elif s==2:
		if p>t:print"E"
		elif p==t:print"A"
		else: print"G"
		s=5
	else:
		p=t
		s=c

Submission status: Accepted

Solution code:
import sys,re
for i in sys.stdin.read().split("\n\n"):print"CD F GAE  B"[(len(re.findall("1.+1",i.replace("\n",""))[0])-4)%11]

Submission status: Accepted

Solution code:
def university(xxx, pattern):
    tate = 0
    yoko = 1
    for current_tate in range(8-xxx[tate]+1):
        for current_yoko in range(8-xxx[yoko]+1):
            if absolutely_fantastic(current_tate, current_yoko):
                return True

def absolutely_fantastic(current_tate, current_yoko):
    tate = 0
    yoko = 1
    run = []
    for add_tate in range(xxx[tate]):
        for add_yoko in range(xxx[yoko]):
            run.append(mapppp[current_tate+add_tate][current_yoko+add_yoko])
    if run == pattern:
        print xxx[2]
        return True

A = {(2,2,'A'):[1,1,1,1]}
B = {(4,1,'B'):[1,1,1,1]}
C = {(1,4,'C'):[1,1,1,1]}
D = {(3,2,'D'):[0,1,1,1,1,0]}
E = {(2,3,'E'):[1,1,0,0,1,1]}
F = {(3,2,'F'):[1,0,1,1,0,1]}
G = {(2,3,'G'):[0,1,1,1,1,0]}
lis = [A,B,C,D,E,F,G]
mapppp = []
count = 0
while True:
    try:
        input_line = raw_input()
        if input_line:
            yoko = [int(char) for char in input_line]
            mapppp.append(yoko)
            count += 1
        if count == 8:
            for XXX in lis:
                flag = False
                for xxx, pattern in XXX.items():
                    if university(xxx, pattern):
                        flag = True
                        break
                if flag == True:
                    break
            count = 0
            mapppp = []
    except EOFError:
        break

Submission status: Accepted

Solution code:
def university(xxx, pattern):
    tate = 0
    yoko = 1
    for current_tate in range(8-xxx[tate]+1):
        for current_yoko in range(8-xxx[yoko]+1):
            if absolutely_fantastic(current_tate, current_yoko):
                return True

def absolutely_fantastic(current_tate, current_yoko):
    tate = 0
    yoko = 1
    run = []
    for add_tate in range(xxx[tate]):
        for add_yoko in range(xxx[yoko]):
            run.append(mapppp[current_tate+add_tate][current_yoko+add_yoko])
    if run == pattern:
        print xxx[2]
        return True

A = {(2,2,'A'):[1,1,1,1]}
B = {(4,1,'B'):[1,1,1,1]}
C = {(1,4,'C'):[1,1,1,1]}
D = {(3,2,'D'):[0,1,1,1,1,0]}
E = {(2,3,'E'):[1,1,0,0,1,1]}
F = {(3,2,'F'):[1,0,1,1,0,1]}
G = {(2,3,'G'):[0,1,1,1,1,0]}
lis = [A,B,C,D,E,F,G]
mapppp = []
while True:
    try:
        for i in range(8):
            input_line = raw_input()
            yoko = [int(char) for char in input_line]
            mapppp.append(yoko)
        for XXX in lis:
            flag = False
            for xxx, pattern in XXX.items():
                if university(xxx, pattern):
                    flag = True
                    break
            if flag == True:
                break
        mapppp = []
        raw_input()
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys

while True:
	sur = []

	for _ in range(8):
		sur.append(list(map(int, input().strip())))
		if 1 not in sur[-1]:
			sur.pop()

	if len(sur) == 1:
		print("C")
	elif len(sur) == 2:
		if sur[0].index(1) == sur[1].index(1):
			print("A")
		elif sur[0].index(1) < sur[1].index(1):
			print("E")
		else:
			print("G")
	elif len(sur) == 3:
		if sur[0].index(1) > sur[2].index(1):
			print("D")
		else:
			print("F")
	elif len(sur) == 4:
		print("B")

	try:
		line = input()
	except:
		break

Submission status: Accepted

Solution code:
ans=['A','B','C','D','E','F','G']
def sol(x):
    for i in range(8):
        for j in range(8):
            if i<7 and j<7:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i][j+1]=='1' and x[i+1][j+1]=='1':
                    return 0
            if i<5:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+2][j]=='1' and x[i+3][j]=='1':
                    return 1
            if j<5:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i][j+2]=='1' and x[i][j+3]=='1':
                    return 2
            if i<6 and 0<j:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+1][j-1]=='1' and x[i+2][j-1]=='1':
                    return 3
            if i<7 and j<6:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i+1][j+1]=='1' and x[i+1][j+2]=='1':
                    return 4
            if i<6 and j<7:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+1][j+1]=='1' and x[i+2][j+1]=='1':
                    return 5
            if i<7 and 0<j<7:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i+1][j]=='1' and x[i+1][j-1]=='1':
                    return 6


while 1:
    l=[]
    try:
        for i in range(8):
            l.append(raw_input())
        print ans[sol(l)]
        raw_input()
    except:
        break

Submission status: Accepted

Solution code:
while True:
	surface = [list(raw_input()) for _ in range(0, 8)]

	surf = []
	for i in range(0, 8):
		if "1" in surface[i]:
			surf.append(surface[i])
	
	if len(surf) == 1 : print "C"
	else:
		if len(surf) == 2:
			x = surf[0].index("1")
			y = surf[1].index("1")
			if x - y == 0 : print "A"
			elif x - y == -1 : print "E"
			elif x - y ==  1 : print "G"
		elif len(surf) == 3:
			x = surf[0].index("1")
			y = surf[1].index("1")
			if x - y ==   1 : print "D"
			elif x - y == 0 : print "F"
		elif len(surf) == 4 : print "B"
		
	try:
		raw_input()
	except EOFError:
		break

Submission status: Accepted

Solution code:
while True:
	surface = [list(raw_input()) for _ in range(0, 8)]

	surf = []
	for i in range(0, 8):
		if "1" in surface[i]:
			surf.append(surface[i])
	
	if len(surf) == 1 : print "C"
	else:
		if len(surf) == 2:
			x = surf[0].index("1")
			y = surf[1].index("1")
			if x - y == 0    : print "A"
			elif x - y == -1 : print "E"
			elif x - y ==  1 : print "G"
		elif len(surf) == 3:
			x = surf[0].index("1")
			y = surf[1].index("1")
			if x - y ==   1 : print "D"
			elif x - y == 0 : print "F"
		elif len(surf) == 4 : print "B"
		
	try:
		raw_input()
	except EOFError:
		break

Submission status: Accepted

Solution code:
from math import *
PI = 3.1415926535898
pool = []
pool.append("1100000011")
pool.append("1000000010000000100000001")
pool.append("1111")
pool.append("1000000110000001")
pool.append("11000000011")
pool.append("100000001100000001")
pool.append("110000011")
while True:
	try:
		pat = ""
		for i in range(8):
			s = str(raw_input())
			while len(s) == 0:
				s = str(raw_input())
			pat += s
		flag = False
		tp = ""
		for x in pat:
			if x != '0':
				flag = True
			if flag:
				tp += x
		pat = reversed(tp)
		flag = False
		tp = ""
		for x in pat:
			if x != '0':
				flag = True
			if flag:
				tp += x
		pat = tp
		print chr(pool.index(pat) + ord('A'))
	except EOFError:
		break

Submission status: Accepted

Solution code:
#encoding=utf-8
import sys

def inp():
    fe, fe1 = [], []
    for line in sys.stdin:
        fe += line.split()
        
    i,j = 0,8
    while True:
        fe1 = fe[i:j]
        if a(fe1):
            if b(fe1):
                if c(fe1):
                    if d(fe1):
                        if e(fe1):
                            if f(fe1):
                                if g(fe1):
                                    pass

        i, j =i + 8,j + 8
        if j > len(fe): break

def a(fe1):
    for i in xrange(8):
        for j in xrange(8):
            if fe1[i][j] == "1":
                try:
                    if fe1[i][j+1]==fe1[i+1][j]==fe1[i+1][j+1]=="1":
                        print "A"
                        return False
                except:
                    pass
    return True

def b(fe1):
    for i in xrange(8):
        for j in xrange(8):
            if fe1[i][j] == "1":
                try:
                    if fe1[i+1][j]==fe1[i+2][j]==fe1[i+3][j]=="1":
                        print "B"
                        return False
                except:
                    pass
    return True

def c(fe1):
    for i in xrange(8):
        for j in xrange(8):
            if fe1[i][j] == "1":
                try:
                    if fe1[i][j+1]==fe1[i][j+2]==fe1[i][j+3]=="1":
                        print "C"
                        return False
                except:
                    pass
    return True

def d(fe1):
    for i in xrange(8):
        for j in xrange(8):
            if fe1[i][j] == "1":
                try:
                    if fe1[i+1][j-1]==fe1[i+1][j]==fe1[i+2][j-1]=="1":
                        print "D"
                        return False
                except:
                    pass
    return True

def e(fe1):
    for i in xrange(8):
        for j in xrange(8):
            if fe1[i][j] == "1":
                try:
                    if fe1[i][j+1]==fe1[i+1][j+1]==fe1[i+1][j+2]=="1":
                        print "E"
                        return False
                except:
                    pass
    return True

def f(fe1):
    for i in xrange(8):
        for j in xrange(8):
            if fe1[i][j] == "1":
                try:
                    if fe1[i+1][j]==fe1[i+1][j+1]==fe1[i+2][j+1]=="1":
                        print "F"
                        return False
                except:
                    pass
    return True

def g(fe1):
    for i in xrange(8):
        for j in xrange(8):
            if fe1[i][j] == "1":
                try:
                    if fe1[i][j+1]==fe1[i+1][j-1]==fe1[i+1][j]=="1":
                        print "G"
                        return False
                except:
                    pass
    return True

if __name__ == "__main__":
    inp()

Submission status: Accepted

Solution code:
A = [[1, 1], [1, 1]]
B = [[1], [1], [1], [1]]
C = [[1, 1, 1, 1]]
D = [[0, 1], [1, 1], [1, 0]]
E = [[1, 1, 0], [0, 1, 1]]
F = [[1, 0], [1, 1], [0, 1]]
G = [[0, 1, 1], [1, 1, 0]]


def f(_h, _w, flg):
    for h in range(8-_h+1):
        for w in range(8-_w+1):
            big = f1(h, w, _h, _w)
            if f2(big, flg):
                return True


def f1(s_h, s_w, _h, _w):
    big = []
    for h in range(_h):
        w_line = []
        for w in range(_w):
            w_line.append(maps[s_h+h][s_w+w])
        big.append(w_line)
    return big


def f2(big, flg):
    if flg == 'A':
        return bool(big == A)
    elif flg == 'B':
        return bool(big == B)
    elif flg == 'C':
        return bool(big == C)
    elif flg == 'D':
        return bool(big == D)
    elif flg == 'E':
        return bool(big == E)
    elif flg == 'F':
        return bool(big == F)
    elif flg == 'G':
        return bool(big == G)


def display():
    if f(2, 2, 'A'):
        print('A')
    elif f(4, 1, 'B'):
        print('B')
    elif f(1, 4, 'C'):
        print('C')
    elif f(3, 2, 'D'):
        print('D')
    elif f(2, 3, 'E'):
        print('E')
    elif f(3, 2, 'F'):
        print('F')
    elif f(2, 3, 'G'):
        print('G')

while True:
    try:
        maps = []
        for _ in range(8):
            maps.append(list(map(int, input())))
        display()
        input()
    except EOFError:
        break

Submission status: Accepted

Solution code:
def block(b):
    for i in range(8):
        for j in range(8):
            if b[i][j] == 1:
                if sum(b[i]) == 4:
                    return 'C'
                if sum([b[t][j] for t in range(8)]) == 4:
                    return 'B'
                if sum(b[i]) == 2:
                    if b[i + 1][j] == 0:
                        return 'E'
                    if b[i + 1][j + 1] == 0:
                        return 'G'
                    return 'A'
                if j > 0 and b[i + 1][j - 1] == 1:
                    return 'D'
                return 'F'

while True:
    try:
        b = 8 * [8 * [0]]
        for i in range(8):
            b[i] = list(map(int, input()))
        print(block(b))
        input()
    except:
        break

Submission status: Accepted

Solution code:
ans = ['A','B','C','D','E','F','G']
def get(x):
    for i in range(8):
        for j in range(8):
            if i < 7 and j < 7:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i][j+1]=='1' and x[i+1][j+1]=='1':
                    return 0
            if i<5:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+2][j]=='1' and x[i+3][j]=='1':
                    return 1
            if j<5:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i][j+2]=='1' and x[i][j+3]=='1':
                    return 2
            if i<6 and 0<j:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+1][j-1]=='1' and x[i+2][j-1]=='1':
                    return 3
            if i<7 and j<6:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i+1][j+1]=='1' and x[i+1][j+2]=='1':
                    return 4
            if i<6 and j<7:
                if x[i][j]=='1' and x[i+1][j]=='1' and x[i+1][j+1]=='1' and x[i+2][j+1]=='1':
                    return 5
            if i<7 and 0<j<7:
                if x[i][j]=='1' and x[i][j+1]=='1' and x[i+1][j]=='1' and x[i+1][j-1]=='1':
                    return 6
while 1:
    try:
        l = []
        for i in range(8):
            l.append(raw_input())
        print ans[get(l)]
        raw_input()
    except: break

Submission status: Accepted

Solution code:
while 1:
	try:
		pos=[]
		for i in xrange(8):
			s=raw_input()
			for j in xrange(8):
				if int(s[j])==1:
					pos.append([i,j])
		if pos[0][0]+1==pos[3][0] and pos[0][1]+1==pos[3][1]:
			print('A')
		elif pos[0][0]+3==pos[3][0]:
			print('B')
		elif pos[0][1]+3==pos[3][1]:
			print('C')
		elif pos[0][1]==pos[3][1]+1:
			print('D')
		elif pos[0][0]+1==pos[3][0] and pos[0][1]+2==pos[3][1]:
			print('E')
		elif pos[0][0]+2==pos[3][0]:
			print('F')
		else:
			print('G')
		raw_input()
	except:
		break

Submission status: Accepted

Solution code:
maxl = 8

offsetV = ('A', 'B', 'C', 'D', 'E', 'F', 'G')
offset = (((0, 1), (1, 0), (1, 1)),
          ((0, 1), (0, 2), (0, 3)),
          ((1, 0), (2, 0), (3, 0)),
          ((0, 1), (-1, 1), (-1, 2)),
          ((1, 0), (1, 1), (2, 1)),
          ((0, 1), (1, 1), (1, 2)),
          ((1, 0), (-1, 1), (0, 1)),
          )


def match(l, x, y, oi):
    for offX, offY in [a for a in offset[oi]]:
        if 0 <= x + offX < maxl and 0 <= y + offY < maxl:
            pass
        else:
            return False

        if l[y + offY][x + offX] == '0':
            return False
    return True


def solve():
    l = [input() for i in range(8)]
    for y in range(8):
        for x in range(8):
            if l[y][x] == '1':
                for o in range(7):
                    if match(l, x, y, o):
                        return offsetV[o]



try:
    while 1:
        print(solve())
        l = input()
except:
    pass

Submission status: Accepted

Solution code:
while True:
    squares = [list(input()) for _ in range(8)]
    for i in range(8)[::-1]:
        if not squares[i].count('1'):
            del squares[i]
    for i in range(8)[::-1]:
        if not [line[i] for line in squares].count('1'):
            for j in range(len(squares)):
                del squares[j][i]
    if len(squares) == len(squares[0]):
        print('A')
    elif len(squares) == 4:
        print('B')
    elif len(squares) == 1:
        print('C')
    elif squares[0] == ['0', '1']:
        print('D')
    elif squares[0] == ['1', '1', '0']:
        print('E')
    elif squares[0] == ['1', '0']:
        print('F')
    elif squares[0] == ['0', '1', '1']:
        print('G')
    try:
        input()
    except:
        break

Submission status: Accepted

Solution code:
import sys
dic={"A":["11","11"],"B":["1","1","1","1"],"C":["1111"],"D":["01","11","10"],
		"E":["110","011"],"F":["10","11","01"],"G":["011","110"]}
s=[]
linecnt=0
for line in sys.stdin:
	if line=="\n" or line=="":
		continue
	linecnt+=1
	if linecnt<8:
		s.append(line.rstrip("\n"))
	else:
		s.append(line.rstrip("\n"))
		while s[0]=="00000000":
			del(s[0])
		while s[len(s)-1]=="00000000":
			del(s[len(s)-1])
		i=len(s[0])-1
		while i>=0:
			for l in xrange(len(s)):
				if s[l][i]=="1":
					break
			else:
				for l in xrange(len(s)):
					s[l]=s[l][0:i]+s[l][i+1:len(s[l])]
			i-=1
		for d in dic.keys():
			if dic[d]==s:
				print d
				break
		while len(s)>0:
			del(s[0])
		linecnt=0

Submission status: Accepted

Solution code:
import sys

counter = 0
block = []
for line in sys.stdin:
  if line == "\n":
    counter = -1
    block = []
  else:
    counter += 1
    for i in line:
      if i == "1":
        block.append([counter,line.index(i)])
  if counter == 7:
    if block[0][0] == block[1][0]:
      if block[1][0] == block[2][0]:
        print("C")
      elif block[0][1] == block[2][1]:
        print("A")
      elif block[0][1] < block[2][1]:
        print("E")
      else:
        print("G")
    else:
      if block[0][1] == block[3][1]:
        print("B")
      elif block[0][1] < block[3][1]:
        print("F")
      else:
        print("D")