Problem:


Mysterious Gems

宇宙暦 1603〜1867 年，人々はその時代のことを EDO 時代と呼ぶ．EDO とは当時最先端の宇宙航行技術，Enhanced Driving Operation のことであり、1603 年に Dr.Izy によって開発された．

あなたは宇宙冒険家であり，宇宙を飛び回って様々な惑星を冒険していた．その冒険の途中で，あなたはとても不思議な惑星を発見した．その惑星には，至るところに七色に輝く不思議な宝石が落ちていた．あなたはその惑星への降下を試みようと考えたが，重大な問題のためにそれは不可能であることがわかった．その惑星の空気には，人間が触れただけで即死してしまうような猛毒の成分が含まれていたのだ．

そこで，あなたはロボットを使って宝石を回収することを考えついた．あなたはその惑星の周回軌道にて待機する．そして，降下させたロボットを遠隔操作することによって宝石を回収するのだ．あなたは，ロボットに「移動する方向」と「移動する距離」の組からなる命令の列によってロボットを遠隔操作する．ロボットは移動経路上（到達点を含む）に宝石を見つけると，それらを全て回収する．

あなたの仕事は，ロボットが与えられた全ての命令の実行を終えたときに，全ての宝石を回収することができたかどうかを判定するプログラムを書くことである．

なお，ロボットが不思議な宝石を回収する範囲はそれほど広くない．そのため，ロボットが移動する範囲は全て 2 次元の平面で表すことができる．そして，ロボットが移動する範囲は (0,0) および (20,20) をそれぞれ左下隅および右上隅とする正方形の内部（境界線を含む）である．ロボットは常に範囲の中央，すなわち (10,10) の座標に降下する．また，全ての宝石は中央以外の格子点上にあることが保証されている．

Input

入力は複数のデータセットにより構成される．

それぞれのデータセットの先頭行には，単一の正の整数 N (1 <= N <= 20) が含まれる。これはロボットが移動可能な範囲内にある不思議な宝石の個数を表す．次の N 行には，それぞれ xi および yi (0 <= xi , yi <= 20) が含まれ，これは i 番目の不思議な宝石の落ちている座標を表す．なお，1 つの場所に複数の宝石が落ちていることはない．

次の行には単一の整数 M (1 <= M <= 30) が含まれ，これはロボットに与えた命令の個数を表す．この後の M 行にはそれぞれ dj とひとつの正の整数 lj が含まれる．これは j 番目の命令における方向および移動量を表す．ただし，方向は N，E，S，W のいずれかの文字であり，順に北，東，南，西を表す（北は y 軸の正方向，東は x 軸の正方向）．なお，ロボットが移動可能な範囲を超えるような命令は与えられないことが保証されている．

入力は N = 0 のときに終了し，これはデータセットに含まれない．

Output

それぞれのデータセットについて，ロボットが全ての宝石を収集できるときは「Yes」と，そうでないときは「No」と 1 行に出力しなさい．

Sample Input

2
10 11
11 12
2
N 2
E 1
2
10 11
11 12
2
N 2
W 1
3
0 15
5 10
5 15
5
W 10
S 10
N 20
E 10
S 10
0

Output for the Sample Input

Yes
No
No



Sample input:
2
10 11
11 12
2
N 2
E 1
2
10 11
11 12
2
N 2
W 1
3
0 15
5 10
5 15
5
W 10
S 10
N 20
E 10
S 10
0


Sample output:
Yes
No
No

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
while True:
    n = int(raw_input())
    if n == 0:
        break
    else:
        posi = []
        now = [10,10]
        for i in range(n):
            l = map(int,raw_input().split())
            posi.append(l)
        n = int(raw_input())
        if now in posi:
            posi.remove(now)
        for i in range(n):
            l = raw_input().split()
            if str(l[0]) == 'E':
                for i in range(int(l[1])):
                    now = [now[0] + 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'W':
                for i in range(int(l[1])):
                    now = [now[0] - 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'N':
                for i in range(int(l[1])):
                    now = [now[0], now[1] + 1]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'S':
                for i in range(int(l[1])):
                    now = [now[0], now[1] - 1]
                    if now in posi:
                        posi.remove(now)
        if posi:
            print 'NO'
        else:
            print 'YES'

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
while True:
    n = int(raw_input())
    if n == 0:
        break
    else:
        posi = []
        now = [10,10]
        for i in range(n):
            l = map(int,raw_input().split())
            posi.append(l)
        n = int(raw_input())
        for i in range(n):
            l = raw_input().split()
            if str(l[0]) == 'E':
                for i in range(int(l[1])):
                    print now
                    now = [now[0] + 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'W':
                for i in range(int(l[1])):
                    now = [now[0] - 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'N':
                for i in range(int(l[1])):
                    now = [now[0], now[1] + 1]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'S':
                for i in range(int(l[1])):
                    now = [now[0], now[1] - 1]
                    if now in posi:
                        posi.remove(now)
        if posi:
            print 'No'
        else:
            print 'Yes'

Submission status: Wrong Answer

Solution code:
def move_and_check(position, number_gems, g, number_instruction, instrct, count):
                #start, number_of_gems, gems, number_of_instruction ,instruction, flag_gems

    # move
    for k in range(number_instruction):
        distance = int(instrct[k][1])
        for l in range(distance):
            if instrct[k][0] == "N":
                position[1] = position[1] + 1

            elif instrct[k][0] == "E":
                position[0] = position[0] + 1

            elif instrct[k][0] == "S":
                position[1] = position[1] - 1

            else:
                position[0] = position[0] - 1

            for m in range(number_gems):
                if position == g[m]:
                    count = count + 1
                else:
                    continue

    if count == number_gems:
        print "Yes"

    else:
        print "No"

while True:
    start = [10, 10]
    flag_gems = 0
    number_of_gems = input()

    if number_of_gems != 0:
        # gems
        gems = []
        for i in range(number_of_gems):
            gems.append(map(int, raw_input().split()))

        # instruction
        number_of_instruction = input()
        instruction = []
        for j in range(number_of_instruction):
            instruction.append(map(str, raw_input().split()))

        move_and_check(start, number_of_gems, gems, number_of_instruction, instruction, flag_gems)

    else:
        break

Submission status: Wrong Answer

Solution code:
# seems have got to output the answer AFTER ALL THE INPUT IS COMPLETED.

def move_and_check(position, number_gems, g, number_instruction, instrct, count,answers):
                #start, number_of_gems, gems, number_of_instruction ,instruction, flag_gems

    # move
    for k in range(number_instruction):
        distance = int(instrct[k][1])
        for l in range(distance):
            if instrct[k][0] == "N":
                position[1] = position[1] + 1

            elif instrct[k][0] == "E":
                position[0] = position[0] + 1

            elif instrct[k][0] == "S":
                position[1] = position[1] - 1

            else:
                position[0] = position[0] - 1

            for m in range(number_gems):
                if position == g[m]:
                    count = count + 1
                else:
                    continue

    if count == number_gems:
        answers.append("Yes")

    else:
        answers.append("No")

while True:
    start = [10, 10]
    flag_gems = 0
    answer_list_yes_or_not = []
    number_of_gems = input()

    if number_of_gems != 0:
        # gems
        gems = []
        for i in range(number_of_gems):
            gems.append(map(int, raw_input().split()))

        # instruction
        number_of_instruction = input()
        instruction = []
        for j in range(number_of_instruction):
            instruction.append(map(str, raw_input().split()))

        move_and_check(start, number_of_gems, gems, number_of_instruction, instruction, flag_gems, answer_list_yes_or_not)

    else:
        break

number_of_answers = len(answer_list_yes_or_not)

for n in range(number_of_answers):
    print answer_list_yes_or_not[n]

Submission status: Wrong Answer

Solution code:
while 1:
  mt=[[0 for _ in range(21)] for _ in range(21)]
  N=int(input())
  if not N:break
  for _ in range(N):
    x,y=map(int,input().split())
    mt[x][y]=1
  M=int(input())
  sx=10
  sy=10
  c=0
  for _ in range(M):
    d,l=input().split()
    st=(0,0)
    if d=="N":
      st=(0,1)
    elif d=="S":
      st=(0,-1)
    elif d=="E":
      st=(1,0)
    elif d=="W":
      st=(-1,0)
    for i in range(int(l)):
      dx,dy=st
      sx+=dx
      sy+=dy
      if mt[sx][sy]==1:
        c+=1
  if c==N:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
while 1:
  mt=[[0 for _ in range(21)] for _ in range(21)]
  N=int(input())
  if not N:break
  for _ in range(N):
    x,y=map(int,input().split())
    mt[x][y]=1
  M=int(input())
  sx=10
  sy=10
  c=0
  if mt[sx][sy]==1:
    c+=1
  for _ in range(M):
    d,l=input().split()
    st=(0,0)
    if d=="N":
      st=(0,1)
    elif d=="S":
      st=(0,-1)
    elif d=="E":
      st=(1,0)
    elif d=="W":
      st=(-1,0)
    for i in range(int(l)):
      dx,dy=st
      sx+=dx
      sy+=dy
      if mt[sx][sy]==1:
        c+=1
  if c==N:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
while 1:
    find = False
    r_pos = [9,9]
    n = int(raw_input())
    if n == 0: break
    planet = [[0 for j in xrange(20)] for i in xrange(20)]
    for i in xrange(n):
        x,y = map(int, raw_input().split())
        planet[y-1][x-1] = 1
    m = int(raw_input())
    for i in xrange(m):
        d,l = raw_input().split()
        l = int(l)
        if d == 'N':
            for j in xrange(r_pos[0], r_pos[0]+l+1):
                planet[j][r_pos[1]] = 0
            r_pos[0] += l
            #print r_pos
        elif d == 'S':
            for j in xrange(r_pos[0], r_pos[0]-l-1):
                planet[j][r_pos[1]] = 0
            r_pos[0] -= l
            #print r_pos
        elif d == 'E':
            for j in xrange(r_pos[1], r_pos[1]+l+1):
                planet[r_pos[0]][j] = 0
            r_pos[1] += l
            #print r_pos
        elif d == 'W':
            for j in xrange(r_pos[1], r_pos[1]-l-1):
                planet[r_pos[0]][j] = 0
            r_pos[1] -= l
            #print r_pos
    for i in xrange(20):
        for j in xrange(20):
            if planet[j][i] == 1:
                find = True
    if find is True: print 'NO'
    else: print 'YES'

Submission status: Wrong Answer

Solution code:
while 1:
    find = False
    r_pos = [10,10]
    n = int(raw_input())
    if n == 0: break
    planet = [[0 for j in xrange(21)] for i in xrange(21)]
    for i in xrange(n):
        x,y = map(int, raw_input().split())
        planet[y][x] = 1
    m = int(raw_input())
    for i in xrange(m):
        d,l = raw_input().split()
        l = int(l)
        if d == 'N':
            for j in xrange(r_pos[0], r_pos[0]+l+1):
                planet[j][r_pos[1]] = 0
            r_pos[0] += l
            #print r_pos
        elif d == 'S':
            for j in xrange(r_pos[0], r_pos[0]-l-1):
                planet[j][r_pos[1]] = 0
            r_pos[0] -= l
            #print r_pos
        elif d == 'E':
            for j in xrange(r_pos[1], r_pos[1]+l+1):
                planet[r_pos[0]][j] = 0
            r_pos[1] += l
            #print r_pos
        elif d == 'W':
            for j in xrange(r_pos[1], r_pos[1]-l-1):
                planet[r_pos[0]][j] = 0
            r_pos[1] -= l
            #print r_pos
    for i in xrange(21):
        for j in xrange(21):
            if planet[j][i] == 1:
                find = True
    if find is True: print 'NO'
    else: print 'YES'

Submission status: Wrong Answer

Solution code:
while 1:
    find = False
    r_pos = [10,10]
    n = int(raw_input())
    if n == 0: break
    planet = [[0 for j in xrange(21)] for i in xrange(21)]
    for i in xrange(n):
        x,y = map(int, raw_input().split())
        planet[y][x] = 1
    m = int(raw_input())
    for i in xrange(m):
        d,l = raw_input().split()
        l = int(l)
        if d == 'N':
            for j in xrange(r_pos[0], r_pos[0]+l+1):
                planet[j][r_pos[1]] = 0
            r_pos[0] += l
            #print r_pos
        elif d == 'S':
            for j in xrange(r_pos[0], r_pos[0]-l-1):
                planet[j][r_pos[1]] = 0
            r_pos[0] -= l
            #print r_pos
        elif d == 'E':
            for j in xrange(r_pos[1], r_pos[1]+l+1):
                planet[r_pos[0]][j] = 0
            r_pos[1] += l
            #print r_pos
        elif d == 'W':
            for j in xrange(r_pos[1], r_pos[1]-l-1):
                planet[r_pos[0]][j] = 0
            r_pos[1] -= l
            #print r_pos
    for i in xrange(21):
        for j in xrange(21):
            if planet[j][i] == 1:
                find = True
    if find is True: print 'No'
    else: print 'Yes'

Submission status: Wrong Answer

Solution code:
while True:
    N=input()
    if N==0:break
    L=[[0]*21 for i in range(21)]
    for i in range(N):
        x,y=map(int,raw_input().split())
        L[y][x]=1
    M=input()
    cnt=0
    nowX,nowY=10,10
    for i in range(M):
        d,I=raw_input().split()
        if d=="N":
            for j in range(1,int(I)+1):
                nowY+=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
        elif d=="S":
            for j in range(1,int(I)+1):
                nowY-=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
        elif d=="W":
            for j in range(1,int(I)+1):
                nowX-=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
        elif d=="E":
            for j in range(1,int(I)+1):
                nowX+=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
    print "YES" if cnt==N else "NO"

Submission status: Wrong Answer

Solution code:
while True:
    N=input()
    if N==0:break
    L=[[0]*21 for i in range(21)]
    for i in range(N):
        x,y=map(int,raw_input().split())
        L[y][x]=1
    M=input()
    cnt=0
    nowX,nowY=10,10
    for i in range(M):
        d,I=raw_input().split()
        if d=="N":
            for j in range(int(I)):
                nowY+=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
        elif d=="S":
            for j in range(int(I)):
                nowY-=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
        elif d=="W":
            for j in range(int(I)):
                nowX-=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
        elif d=="E":
            for j in range(int(I)):
                nowX+=1
                if L[nowY][nowX]==1:
                    L[nowY][nowX]=0
                    cnt+=1
    print "YES" if cnt==N else "NO"

Submission status: Wrong Answer

Solution code:
while True:
    N=input()
    if N==0:break
    L=[[0]*21 for i in range(21)]
    init=[[0]*21 for i in range(21)]
    for i in range(N):
        x,y=map(int,raw_input().split())
        L[y][x]=1
    M=input()
    nowX,nowY=10,10
    for i in range(M):
        d,I=raw_input().split()
        if d=="N":
            for j in range(int(I)):
                nowY+=1
                L[nowY][nowX]=0
        elif d=="S":
            for j in range(int(I)):
                nowY-=1
                L[nowY][nowX]=0
        elif d=="W":
            for j in range(int(I)):
                nowX-=1
                L[nowY][nowX]=0
        elif d=="E":
            for j in range(int(I)):
                nowX+=1
                L[nowY][nowX]=0
    print "YES" if L==init else "NO"

Submission status: Wrong Answer

Solution code:
while True:
    N=input()
    if N==0:break
    L=[[0]*21 for i in range(21)]
    init=[[0]*21 for i in range(21)]
    for i in range(N):
        x,y=map(int,raw_input().split())
        L[y][x]=1
    M=input()
    nowX,nowY=10,10
    L[nowY][nowX]=0
    for i in range(M):
        d,I=raw_input().split()
        if d=="N":
            for j in range(int(I)):
                nowY+=1
                L[nowY][nowX]=0
        elif d=="S":
            for j in range(int(I)):
                nowY-=1
                L[nowY][nowX]=0
        elif d=="W":
            for j in range(int(I)):
                nowX-=1
                L[nowY][nowX]=0
        elif d=="E":
            for j in range(int(I)):
                nowX+=1
                L[nowY][nowX]=0
    print "YES" if L==init else "NO"

Submission status: Wrong Answer

Solution code:
while True:
    N=input()
    if N==0:break
    L=[[0]*21 for i in range(21)]
    init=[[0]*21 for i in range(21)]
    for i in range(N):
        x,y=map(int,raw_input().split())
        L[y][x]=1
    M=input()
    nowX,nowY=10,10
    L[nowY][nowX]=0
    for i in range(M):
        d,I=raw_input().split()
        if d=="N":
            for j in range(int(I)):
                L[nowY][nowX]=0
                nowY+=1
        elif d=="S":
            for j in range(int(I)):
                L[nowY][nowX]=0
                nowY-=1
        elif d=="W":
            for j in range(int(I)):
                L[nowY][nowX]=0
                nowX-=1
        elif d=="E":
            for j in range(int(I)):
                L[nowY][nowX]=0
                nowX+=1
        L[nowY][nowX]=0
    print "YES" if L==init else "NO"

Submission status: Wrong Answer

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    field = [[0 for i in range(21)] for i in range(21)]
    for i in range(n):
        x, y = map(int, raw_input().split())
        field[y][x] = 1

    n = int(raw_input())
    x,y = 10, 10
    for i in range(n):
        c, d = map(str, raw_input().split())
        d = int(d)
        if c == "N":
            for j in range(d+1):
                field[y+j][x] = 0
            y += d
        elif c == "E":
            for j in range(d+1):
                field[y][x+j] = 0
            x += d
        elif c == "S":
            for j in range(d+1):
                field[y-j][x] = 0
            y -=d
        else:
            for j in range(d+1):
                field[y][x-j] = 0
            x -= d
    print field
    for i in range(20):
        if 1 in field[i][:]:
            print "NO"
            break
        if i == 19:
            print "YES"

Submission status: Wrong Answer

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    field = [[0 for i in range(21)] for i in range(21)]
    for i in range(n):
        x, y = map(int, raw_input().split())
        field[y][x] = 1

    n = int(raw_input())
    x,y = 10, 10
    for i in range(n):
        c, d = map(str, raw_input().split())
        d = int(d)
        if c == "N":
            for j in range(d+1):
                field[y+j][x] = 0
            y += d
        elif c == "E":
            for j in range(d+1):
                field[y][x+j] = 0
            x += d
        elif c == "S":
            for j in range(d+1):
                field[y-j][x] = 0
            y -=d
        else:
            for j in range(d+1):
                field[y][x-j] = 0
            x -= d
    for i in range(20):
        if 1 in field[i][:]:
            print "NO"
            break
        if i == 19:
            print "YES"

Submission status: Wrong Answer

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    f = [[0 for i in range(21)] for i in range(21)]
    for i in range(n):
        x, y = map(int, raw_input().split())
        f[y][x] = 1

    n = int(raw_input())
    x,y = 10, 10
    for i in range(n):
        c, d = map(str, raw_input().split())
        d = int(d)
        if c == "N":
            for j in range(1,d+1):
                f[y+j][x] = 0
            y += d
        elif c == "E":
            for j in range(1,d+1):
                f[y][x+j] = 0
            x += d
        elif c == "S":
            for j in range(1,d+1):
                f[y-j][x] = 0
            y -= d
        else:
            for j in range(1,d+1):
                f[y][x-j] = 0
            x -= d
    for i in range(20):
        if 1 in f[i][:]:
            print "NO"
            break
        if i == 19:
            print "YES"

Submission status: Accepted

Solution code:
import sys

def move(cmd, gems):
    n = 0
    x = y = 10
    for c in cmd:
        d = c[0]
        l = c[1]
        for s in range(0, l):
            if d == "N":
                y += 1
            elif d == "E":
                x += 1
            elif d == "S":
                y -= 1
            elif d == "W":
                x -= 1
            if gems[y][x] == 1:
                n += 1
                gems[y][x] = 0
    return n

gems = []
cmd = []
att = "gemsN"
for line in sys.stdin:
    if att =="gemsN":
        n = w_n = int(line)
        if n == 0:
            break
        att = "gemsXY"
        gems = [[0 for i in range(0,21)] for j in range(0,21)]
    elif att == "gemsXY" and w_n > 0:
        xy = list(map(int, line.strip().split(" ")))
        gems[xy[1]][xy[0]] = 1
        w_n -= 1
    elif att == "gemsXY" and w_n == 0:
        att = "cmd"
        cmd = []
        m = int(line)
    elif att == "cmd" and m > 0:
        dl = line.strip().split(" ")
        cmd.append([dl[0], int(dl[1])])
        m -= 1
        if m == 0:
            a = move(cmd, gems)
            ans = "Yes" if a == n else "No"
            print(ans)
            att = "gemsN"

Submission status: Accepted

Solution code:
def move(hougaku, zahyo):
    if hougaku == "N":
        zahyo[1] += 1
    elif hougaku == "E":
        zahyo[0] += 1
    elif hougaku == "S":
        zahyo[1] -= 1
    elif hougaku == "W":
        zahyo[0] -= 1


while True:
    N = int(input())
    if N == 0:
        break
    jewelry = [list(map(int, input().split())) for _ in range(N)]
    M = int(input())
    default = [10, 10]
    for _ in range(M):
        get_jewelry = 0
        d, l = input().split()
        for i in range(int(l)):
            move(d, default)
            # with open("./log.txt", "a") as f:
            #     f.write(
            #         "default: {}, jewelry: {}, get_jewelry: {}\n".format(
            #             default, jewelry, get_jewelry
            #         )
            #     )
            if default in jewelry:
                jewelry.remove(default)
    if len(jewelry) == 0:
        # with open("./log.txt", "a") as f:
        #     f.write("----------Yes----------\n")
        print("Yes")
    else:
        # with open("./log.txt", "a") as f:
        #     f.write("----------No----------\n")
        print("No")

Submission status: Accepted

Solution code:
while True:
    num_hoseki=input()
    if num_hoseki==0:
        break
    
    hoseki_list=[]
    for i in range(num_hoseki):
        hoseki_list.append(map(int,raw_input().split()))
        
    num_meirei=input()
    
    keiro=[]
    x,y=[10,10]
    for i in range(num_meirei):
        meirei=raw_input()
        
        d, l=meirei.split()
        l=int(l)
        if d=='N':
            dx,dy=0,1
        elif d=='S':
            dx,dy=0,-1
        elif d=='W':
            dx,dy=-1,0
        elif d=='E':
            dx,dy=1,0

        for j in range(l):
            keiro.append([x+(j+1)*dx,y+(j+1)*dy])
        x,y=keiro[-1]
    flag=True
    for hoseki in hoseki_list:
        if not hoseki in keiro:
            flag=False
            break
    if flag:
        print 'Yes'
    else:
        print 'No'

Submission status: Accepted

Solution code:
# coding: utf-8

class Mission:
  def __init__(self):
    self.field = [[0]*21 for i in range(21)]
    self.x = 10
    self.y = 10

  def get_gem(self, x, y):
    self.field[x][y] = 0

  def put_gem(self, x, y):
    self.field[x][y] = 1

  def move_x(self, step, sign=1):
    for i in range(1,step+1): self.get_gem(self.x+(i*sign), self.y)
    self.x += step * sign

  def move_y(self, step, sign=1):
    for j in range(1,step+1): self.get_gem(self.x, self.y+(j*sign))
    self.y += step * sign

  def command(self, direction, step):
    if direction == 'N': self.move_y(step)
    elif direction == 'E': self.move_x(step)
    elif direction == 'S': self.move_y(step, -1)
    elif direction == 'W': self.move_x(step, -1)

def main():
  while True:
    n_gems = input()
    if n_gems == 0: break

    m = Mission()
    for i in range(n_gems):
      x, y = map(int, raw_input().split(' '))
      m.put_gem(x, y)

    n_commands = input()
    for i in range(n_commands):
      direction, step = raw_input().split(' ')
      m.command(direction, int(step))

    if m.field == [[0]*21 for i in range(21)]: print 'Yes'
    else: print 'No'

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
while True:
    rx = 10
    ry = 10
    n = int(input())
    if n == 0:
        exit()
    gems = [[0 for j in range(21)] for i in range(21)]
    for _ in range(n):
        (x, y) = [int(x) for x in input().split()]
        gems[x][y] = 1
    m = int(input())
    for _ in range(m):
        (d, l) = input().split()
        if d=='N':
            for i in range(1, int(l)+1):
                gems[rx][ry+i] = 0
            ry = ry+int(l)
        elif d=='W':
            for i in range(1, int(l)+1):
                gems[rx-i][ry] = 0
            rx = rx-int(l)
        elif d=='E':
            for i in range(1, int(l)+1):
                gems[rx+i][ry] = 0
            rx = rx+int(l)
        elif d=='S':
            for i in range(1, int(l)+1):
                gems[rx][ry-i] = 0
            ry = ry-int(l)
    if sum([sum(gems[i]) for i in range(21)])==0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            board = [[None for j in range(21)] for i in range(21)]
            gems = []
            for i in range(n):
                x, y = map(int, raw_input().split())
                board[y][x] = 1
                gems.append((x, y))
            m = input()
            route = [(10, 10)]
            for i in range(m):
                d, l = raw_input().split()
                l = int(l)
                init = route[-1]
                if d == 'N':
                    for j in range(1, l+1):
                        route.append((init[0], init[1] + j))
                elif d == 'E':
                    for j in range(1, l+1):
                        route.append((init[0] + j, init[1]))
                elif d == 'S':
                    for j in range(1, l+1):
                        route.append((init[0], init[1] - j))
                elif d == 'W':
                    for j in range(1, l+1):
                        route.append((init[0] - j, init[1]))
            if set(gems) <= set(route):
                print 'Yes'
            else:
                print 'No'
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

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

while True:
    n = int(input())
    if n == 0:
        break
    gem = [tuple(map(int,input().split(" "))) for i in range(0,n)]
    robot = (10,10)
    direct = {'N' : 0,'E' : 1,'W' : 2, 'S' : 3}
    dxdy = [(0,1),(1,0),(-1,0),(0,-1)]
    for i in range(int(input())):
        head,step = input().split()
        for j in range(int(step)):
            robot = (robot[0] + dxdy[direct[head]][0],robot[1] + dxdy[direct[head]][1])
            if robot in gem:
                gem.remove(robot)
    if gem == []:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

N = int(raw_input())
while N != 0:
	p = []
	a = []
	for i in range(N):
		p.append(map(int, raw_input().split()))
	M = int(raw_input())
	for i in range(M):
		a.append(raw_input().split())
	cnt = 0
	used = [False]*N
	cur = [10, 10]
	for i in range(M):
		for j in range(int(a[i][1])):
			if a[i][0] == 'N':
				cur[1] += 1
			elif a[i][0] == 'E':
				cur[0] += 1
			elif a[i][0] == 'S':
				cur[1] -= 1
			elif a[i][0] == 'W':
				cur[0] -= 1
			for k in range(N):
				if cur == p[k] and used[k] == False:
					used[k] = True
					cnt += 1
	if cnt == N:
		print "Yes"
	else:
		print "No"
		
	N = int(raw_input())

Submission status: Accepted

Solution code:
while 1:	
	n = int(raw_input())
	if n == 0:
		break
	search_map = [[0 for i in range(21)] for i in range(21)]

	for i in range(n):
		x, y = map(int,raw_input().split(" "))
		search_map[y][x] = 1

	here = [10,10]
	m = int(raw_input())
	for i in range(m):
		d, l = raw_input().split(" ")
		l = int(l)
		l_sign = 1 if d == "N" or d == "E" else -1 
		if d == "N" or d == "S":
			next = [here[0], here[1]+l_sign*l]
			for j in range(1,l+1):
				search_map[here[1] + l_sign*j][here[0]] = 0
		else :
			next = [here[0]+l_sign*l, here[1]]
			for j in range(1,l+1):
				search_map[here[1]][here[0] + l_sign * j] = 0
		here = next
	rest_gem = sum([sum(line) for line in search_map])
	print "Yes" if rest_gem == 0 else "No"

Submission status: Accepted

Solution code:
while(1):
    N=int(raw_input())
    if N==0:
        break
    else:
        gems=[]
        okflag=0
        loc=[10,10]
        for i in range(N):
            [gemx,gemy]=[int(x) for x in raw_input().split()]
            gems.append([gemx,gemy])
        M=int(raw_input())
        for i in range(M):
            com=raw_input().split()
            com[1]=int(com[1])
            if com[0]=="N":
                for j in range(com[1]):
                    loc[1]=loc[1]+1
                    if loc in gems:
                        gems.remove(loc)
                #loc[1]=loc[1]+com[1]
            elif com[0]=="S":
                for j in range(com[1]):
                    loc[1]=loc[1]-1
                    if loc in gems:
                        gems.remove(loc)
                #loc[1]=loc[1]-com[1]
            elif com[0]=="E":
                for j in range(com[1]):
                    loc[0]=loc[0]+1
                    if loc in gems:
                        gems.remove(loc)
                #loc[0]=loc[0]+com[1]
            else:
                for j in range(com[1]):
                    loc[0]=loc[0]-1
                    if loc in gems:
                        gems.remove(loc)
                #loc[0]=loc[0]-com[1]
            if len(gems)==0:
                okflag=1
        if okflag:
            print "Yes"
        else:
            print "No"

Submission status: Accepted

Solution code:
#!/usr/bin/python3

while True:
    n = int(input())
    if n == 0 : break

    gems = []
    for i in range(n):
        gem = tuple(map(int, input().split()))
        gems.append(gem)
    
    m = int(input())
    bot = [10, 10]
    history = [(10, 10)]
    for j in range(m):
        move = list(input().split())
        move[1] = int(move[1])
        if move[0] == 'N':
            index = 1 #y
            direc = 1 # pos
        elif move[0] == 'S':
            index = 1
            direc = -1 # neg
        elif move[0] == 'E':
            index = 0 #x
            direc = 1
        else: #W
            index = 0
            direc = -1
        for j in range(abs(move[1])):
            bot[index] += direc
            history.append(tuple(bot))
    f = True
    for g in gems:
        if g not in history:
            f = False
            break
    print("Yes" if f else "No")