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: Accepted

Solution code:
import operator as O
c = {"N": (1, O.add), "E": (0, O.add), "W": (0, O.sub), "S": (1, O.sub)}
while True:
    N = int(input())
    if N == 0:
        break
    pos = [10, 10]
    nums = [tuple(map(int, input().split())) for _ in range(N)]
    M = int(input())
    ans = 0
    for _ in range(M):
        d, l = input().split()
        index = c[d][0]
        func = c[d][1]
        tx, ty = pos
        pos[index] = func(pos[index], int(l))
        x, y = pos
        if index:
            if d == "N":
                tmp = [(tx, i) for i in range(ty, y+1)][1:]
            elif d == "S":
                tmp = [(tx,  i) for i in range(y, ty+1)][:-1]
        else:
            if d == "E":
                tmp = [(i, ty) for i in range(tx, x+1)][1:]
            elif d == "W":
                tmp = [(i, ty) for i in range(x, tx+1)][:-1]
        hoge = list(filter(lambda n: n in tmp, nums))
        for h in hoge:
            nums.remove(h)
    print("No" if nums else "Yes")

Submission status: Accepted

Solution code:
d = {'N':(0,1), 'E':(1,0), 'S':(0,-1), 'W':(-1,0)}
while True:
    N = int(input())
    if N == 0: break
    field = [[0 for i in range(21)] for j in range(21)]
    for i in range(N):
        x,y = map(int,input().split())
        field[x][y] = 1
    x = y = 10
    got = 0
    M = int(input())
    for i in range(M):
        dj,lj = input().split()
        dx,dy = d[dj]
        for k in range(int(lj)):
            x,y = x+dx, y+dy
            if field[x][y]:
                got += 1
                field[x][y] = 0
    print('Yes' if got == N else 'No')

Submission status: Accepted

Solution code:
D = {'N': (0, 1), 'S': (0, -1), 'E': (1, 0), 'W': (-1, 0)}
while True:
    n = int(input())
    if n == 0:
        break
    f = [[False for x in range(21)] for y in range(21)]
    for i in range(n):
        x, y = map(int, input().split(' '))
        f[y][x] = True
    m = int(input())
    rx, ry = 10, 10
    p = 0
    if f[ry][rx]:
        f[ry][rx] = False
        p += 1
    for i in range(m):
        d, l = input().split(' ')
        dx, dy = D[d]
        for j in range(int(l)):
            rx += dx
            ry += dy
            if f[ry][rx]:
                f[ry][rx] = False
                p += 1
    print('Yes' if p == n else 'No')

Submission status: Accepted

Solution code:
N=int (input())
while N != 0:
    Jcou = 0
    JUE=[]
    for i in range(N):
        JUE.append(list(map(int, input().split())))
    M=int(input())
    RO=[10,10]
    for j in range(M):
        m1=list(map( str,input().split()))
        if(m1[0]=="N"):
            for k in range(int(m1[1])):
                RO[1]+=1
                if RO in JUE:
                    JUE.remove(RO)
                    Jcou+=1
        elif(m1[0]=="S"):
            for k in range(int(m1[1])):
                RO[1]-=1
                if RO in JUE:
                    JUE.remove(RO)
                    Jcou+=1
        elif(m1[0]=="E"):
            for k in range(int(m1[1])):
                RO[0]+=1
                if RO in JUE:
                    JUE.remove(RO)
                    Jcou+=1
        elif(m1[0]=="W"):
            for k in range(int(m1[1])):
                RO[0]-=1
                if RO in JUE:
                    JUE.remove(RO)
                    Jcou+=1
    if (Jcou == N):
        print("Yes")
    else :
        print("No")


    
    N=int(input())

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    gem_points = [list(map(int, input().split())) for i in range(n)]
    m = int(input())
    operations = [input().split() for i in range(m)]
    robot_pos = [10, 10]
    for operation in operations:
        move_dir = operation[0]
        move_amount = int(operation[1])

        for move in range(move_amount):
            if move_dir == 'N':
                robot_pos[1] += 1
            elif move_dir == 'E':
                robot_pos[0] += 1
            elif move_dir == 'S':
                robot_pos[1] -= 1
            elif move_dir == 'W':
                robot_pos[0] -= 1

            if robot_pos in gem_points:
                gem_points.pop(gem_points.index(robot_pos))

    if gem_points:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
while True:
    N = int(raw_input())

    if N == 0:
        break

    xy = [map(int, raw_input().split()) for _ in range(N)]

    M = int(raw_input())

    table = [[False for _ in range(21)] for _ in range(21)]
    table[10][10] = True
    cur = [10, 10]

    for i in range(M):
        d, l = raw_input().split()
        l = int(l)
        if d == 'N':
            for i in range(l):
                cur[1] += 1
                table[cur[0]][cur[1]] = True
        if d == 'E':
            for i in range(l):
                cur[0] += 1
                table[cur[0]][cur[1]] = True
        if d == 'S':
            for i in range(l):
                cur[1] -= 1
                table[cur[0]][cur[1]] = True
        if d == 'W':
            for i in range(l):
                cur[0] -= 1
                table[cur[0]][cur[1]] = True

    flag = True

    for (x, y) in xy:
        if not table[x][y]:
            flag = False
            break

    print 'Yes' if flag else 'No'

Submission status: Accepted

Solution code:
while True:
    N = int(raw_input())

    if N == 0:
        break

    xy = [map(int, raw_input().split()) for _ in range(N)]

    table = [[False for _ in range(21)] for _ in range(21)]
    table[10][10] = True

    cur = [10, 10]

    M = int(raw_input())

    for _ in range(M):
        d, l = raw_input().split()
        l = int(l)
        if d == 'N':
            for i in range(l):
                cur[1] += 1
                table[cur[0]][cur[1]] = True
        if d == 'E':
            for i in range(l):
                cur[0] += 1
                table[cur[0]][cur[1]] = True
        if d == 'S':
            for i in range(l):
                cur[1] -= 1
                table[cur[0]][cur[1]] = True
        if d == 'W':
            for i in range(l):
                cur[0] -= 1
                table[cur[0]][cur[1]] = True

    flag = True

    for (x, y) in xy:
        if not table[x][y]:
            flag = False
            break

    print 'Yes' if flag else 'No'

Submission status: Accepted

Solution code:
dx = {"N": 0, "E": 1, "W": -1, "S": 0}
dy = {"N": 1, "E": 0, "W": 0, "S": -1}

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

    jewel = [[False for x in range(21)] for y in range(21)]
    for i in range(n):
        x, y = map(int, input().split())
        jewel[x][y] = True

    m = int(input())
    x = 10
    y = 10
    for i in range(m):
        li = input().split()
        d = li[0]
        l = int(li[1])
        for j in range(l):
            x += dx[d]
            y += dy[d]
            jewel[x][y] = False

    flag = True
    for x in range(21):
        for y in range(21):
            if jewel[x][y]:
                flag = False
        if not flag:
            break

    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n = I()
        if n == 0:
            break
        xy = [LI() for _ in range(n)]
        m = I()
        d = []
        for _ in range(m):
            s,t = S().split()
            d.append((s,int(t)))
        b = collections.defaultdict(bool)
        for x,y in xy:
            b[(x,y)] = True
        x = y = 10
        for s,t in d:
            if s == 'N':
                for _ in range(t):
                    y += 1
                    b[(x,y)] = False
            elif s == 'S':
                for _ in range(t):
                    y -= 1
                    b[(x,y)] = False
            elif s == 'W':
                for _ in range(t):
                    x -= 1
                    b[(x,y)] = False
            else:
                for _ in range(t):
                    x += 1
                    b[(x,y)] = False
        if any(b.values()):
            rr.append('No')
        else:
            rr.append('Yes')

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
OFFSET = {"N": (0, 1),
          "E": (1, 0),
          "S": (0, -1),
          "W": (-1, 0)}

while True:
    N = int(input().strip())

    if N == 0:
        break

    gem_coords = []
    for _ in range(N):
        x, y = [int(s) for s in input().strip().split()]
        gem_coords.append((x, y))

    

    now_x, now_y = (10, 10)
    M = int(input().strip())
    for _ in range(M):
        direction, dist_str = input().strip().split()

        for _ in range(int(dist_str)):
            now_x += OFFSET[direction][0]
            now_y += OFFSET[direction][1]

            if (now_x, now_y) in gem_coords:
                gem_coords.remove((now_x, now_y))

    if len(gem_coords) == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  targets = [tuple(map(int, input().split())) for _ in range(n)]
  m = int(input())
  x = y = 10
  direct = {"N":(0, 1), "S":(0,-1), "E":(1,0), "W":(-1,0)}
  for _ in range(m):
    d, i = input().split()
    dx, dy = direct[d]
    for dist in range(1, int(i) + 1):
      if (x + dist * dx, y + dist * dy) in targets:
        targets.remove((x + dist * dx, y + dist * dy))
    x += dx * int(i)
    y += dy * int(i)
  if targets:
    print("No")
  else:
    print("Yes")

Submission status: Accepted

Solution code:
while 1:
    N=int(input())
    if not N:break
    cd={tuple(map(int,input().split())) for _ in range(N)}
    c=set()
    x,y=10,10
    M=int(input())
    for _ in range(M):
        d,l=input().split()
        l=int(l)
        if d=="N":
            sc={(x+i,y+j) for i in range(1) for j in range(0,l+1,1)}
            y+=l
        elif d=="S":
            sc={(x+i,y+j) for i in range(1) for j in range(0,-l-1,-1)}
            y-=l
        elif d=="E":
            sc={(x+i,y+j) for i in range(0,l+1,1) for j in range(1)}
            x+=l
        else:
            sc={(x+i,y+j) for i in range(0,-l-1,-1) for j in range(1)}
            x-=l
        c=c|(sc&cd)
    if c==cd:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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, -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, -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: Accepted

Solution code:
import sys
import collections

Gem = collections.namedtuple('Gem', 'x y')

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    gem = set()
    for i in xrange(n):
        x, y = map(int, sys.stdin.readline().split())
        gem.add(Gem(x, y))
    M = int(sys.stdin.readline())
    cur_x = cur_y = 10
    check = set()
    for i in xrange(M):
        d, l = sys.stdin.readline().split()
        l = int(l)
        if d == 'N':
            for g in gem:
                if cur_x == g.x and cur_y <= g.y <= cur_y + l:
                    check.add(g)
            cur_y += l
        elif d == 'S':
            for g in gem:
                if cur_x == g.x and cur_y - l <= g.y <= cur_y:
                    check.add(g)
            cur_y -= l
        elif d == 'E':
            for g in gem:
                if cur_x <= g.x <= cur_x + l and cur_y == g.y:
                    check.add(g)
            cur_x += l
        elif d == 'W':
            for g in gem:
                if cur_x - l <= g.x <= cur_x and cur_y == g.y:
                    check.add(g)
            cur_x -= l
    if len(check) == len(gem):
        print 'Yes'
    else:
        print 'No'

Submission status: Accepted

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,l=raw_input().split()
        if d=="N":
            for j in range(int(l)):
                nowY+=1
                L[nowY][nowX]=0
        elif d=="S":
            for j in range(int(l)):
                nowY-=1
                L[nowY][nowX]=0
        elif d=="W":
            for j in range(int(l)):
                nowX-=1
                L[nowY][nowX]=0
        elif d=="E":
            for j in range(int(l)):
                nowX+=1
                L[nowY][nowX]=0
    print "Yes" if L==init else "No"

Submission status: Accepted

Solution code:
drct={"N":(0,1),"S":(0,-1),"W":(-1,0),"E":(1,0)}
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
    for i in range(M):
        d,l=raw_input().split()
        for j in range(int(l)):
            nowX+=drct[d][0]
            nowY+=drct[d][1]
            L[nowY][nowX]=0
    print "Yes" if L==init else "No"

Submission status: Accepted

Solution code:
def check(f):
        for k in range (n):
                if j[k]==g:
                        j[k]=[-1,-1]
                        f+=1
        return f

while 1:
        n=input()
        if n==0:
                break
        j=[0 for i in range(n)]
        for i in range(n):
                j[i]=map(int,raw_input().split())

        m=input()
        g=[10,10]
        o=[0,0]
        f=0
        for i in range(m):
                o=map(str,raw_input().split())
                for l in range(int(o[1])):
                        if o[0]=="N":
                                g[1]+=1
                                f=check(f)
                        elif o[0]=="S":
                                g[1]-=1
                                f=check(f)
                        elif o[0]=="E":
                                g[0]+=1
                                f=check(f)
                        elif o[0]=="W":
                                g[0]-=1
                                f=check(f)
        if n<=f:
                print("Yes")
        else:
                print("No")

Submission status: Accepted

Solution code:
def check(f):
        if g[l[1]][l[0]]==1:
                f+=1
        g[l[1]][l[0]]=2
        return f
while 1:
        g=[[0 for i in range(21)]for j in range(21)]
        n,g[10][10],l,f=input(),2,[10,10],0
        if n==0 : break
        for i in range(n):
                j=map(int,raw_input().split())
                g[j[1]][j[0]]=1
        m=input()
        for i in range(m):
                o=map(str,raw_input().split())
                for k in range(int(o[1])):
                        if o[0]=="N":
                                l[1]+=1
                                f=int(check(f))
                        if o[0]=="S":
                                l[1]-=1
                                f=int(check(f))
                        if o[0]=="E":
                                l[0]+=1
                                f=int(check(f))
                        if o[0]=="W":
                                l[0]-=1
                                f=int(check(f))
        if n<=f: print "Yes"
        else: print "No"

Submission status: Accepted

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
readline = sys.stdin.readline

D = {
	"N": (0, 1),
	"E": (1, 0),
	"S": (0, -1),
	"W": (-1, 0),
}

while True:
	n = int(readline())
	if n == 0: break
	gems = {tuple(int(x) for x in readline().split()) for i in xrange(n)}
	x = 10
	y = 10
	try:
		gems.remove((x, y))
	except KeyError:
		pass
	for i in xrange(int(readline())):
		c, cnt = readline().split()
		dx, dy = D[c]
		for j in xrange(int(cnt)):
			x += dx
			y += dy
			try:
				gems.remove((x, y))
			except KeyError:
				pass
	print "No" if gems else "Yes"

Submission status: Accepted

Solution code:
def moveRobot(d,l,robotPosition,square):
    get_gems = 0
    for i in range(0,l):
        if d == "N":
            robotPosition["y"] = min(20, robotPosition["y"]+1) 
        elif d == "S":
            robotPosition["y"] = max(0, robotPosition["y"]-1) 
        elif d == "E":
            robotPosition["x"] = min(20, robotPosition["x"]+1) 
        elif d == "W":
            robotPosition["x"] = max(0, robotPosition["x"]-1)
        if square[robotPosition["x"]][robotPosition["y"]] == 1:
            square[robotPosition["x"]][robotPosition["y"]] = 0
            get_gems += 1
    return robotPosition,square,get_gems

while True:
    N = int(input())
    if N == 0: break
    square = [[0] * 21 for i in range(21)]

    #Set gems
    total_gems = 0
    for i in range(0,N):
        position = input().split()
        square[int(position[0])][int(position[1])] = 1
        total_gems += 1

    M = int(input())
    robotPosition = {"x":10, "y":10}
    sum_gems = 0
    for i in range(0,M):
        operation = input().split()
        d,l = operation[0],int(operation[1])
        robotPosition,square,get_gems = moveRobot(d,l,robotPosition,square)
        sum_gems += get_gems
    if total_gems == sum_gems:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def get_input_data():
    input_data = int(input())
    return input_data

def get_two_data():
    two_data = input().split()
    for i in range(2):
        two_data[i] = int(two_data[i])
    return two_data

def make_gem_map(gem_num):
    gem_map = set()
    for i in range(gem_num):
        gem_map.add(tuple(get_two_data()))
    return gem_map

def make_order(order_num):
    order = [None] * order_num
    for i in range(order_num):
        order[i] = input().split()
        order[i][1] = int(order[i][1])
    return order

class Robot:

    def __init__(self, gem_map, order):
        self.x, self.y = (10, 10)
        self.gem_map = gem_map
        self.order = order

    def move_and_catch_gems(self):
        self.gem_map.discard((self.x, self.y))
        for i in range(len(order)):
            direction, vector = order[i]
            for j in range(vector):
                if direction == "N":
                    self.y += 1
                elif direction == "S":
                    self.y -= 1
                elif direction == "E":
                    self.x += 1
                else:
                    self.x -= 1
                self.gem_map.discard((self.x, self.y))

if __name__ == "__main__":
    while True:
        gem_num = get_input_data()
        if gem_num == 0:
            break
        gem_map = make_gem_map(gem_num)
        order_num = get_input_data()
        order = make_order(order_num)
        robot = Robot(gem_map, order)
        robot.move_and_catch_gems()
        if robot.gem_map:
            print("No")
        else:
            print("Yes")

Submission status: Accepted

Solution code:

# ロボットのXY座標
_robotXY = []

def RobotMove(dir, amt, stPoint):
    global _robotXY

    isXMove = True

    orgX, orgY = _robotXY
    if dir == "N":
        isXMove = False
        _robotXY[1] += amt
    elif dir == "E":
        _robotXY[0] += amt
    elif dir == "S":
        isXMove = False
        _robotXY[1] -= amt
    elif dir == "W":
        _robotXY[0] -= amt

    # X軸移動
    if isXMove:
        startX = min(orgX, _robotXY[0])
        endX = max(orgX, _robotXY[0])
        for i in range(startX, endX + 1):
            if [i, _robotXY[1]] in stPoint:
                stPoint.remove([i, _robotXY[1]])
    
    # Y軸移動
    else:
        startY = min(orgY, _robotXY[1])
        endY = max(orgY, _robotXY[1])
        for i in range(startY, endY + 1):
            if [_robotXY[0], i] in stPoint:
                stPoint.remove([_robotXY[0], i])



while True:
    _robotXY = [10, 10]

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

    # 不思議な宝石の落ちている座標
    stPoint = [list(map(int, input().split())) for _ in range(n)]

    m = int(input())
    for _ in range(m):
        # ロボットを移動・チェック
        dir, amt = input().split()
        RobotMove(dir, int(amt), stPoint)

    if stPoint:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
def f():
    N = int(input())
    if N == 0:
        return -1
    J = []
    for i in range(N):
        x, y = map(int, input().split())
        J.append((y, x))

    C = [[False for j in range(21)] for i in range(21)]
    C[10][10] = True
    y, x = 10, 10
    dic = {'N':(1, 0), 'W':(0, -1), 'S':(-1, 0), 'E':(0, 1)}

    M = int(input())
    for i in range(M):
        direct, value = input().split()
        value = int(value)
        dy, dx = dic[direct]
        for j in range(value):
            y += dy
            x += dx
            C[y][x] = True

    for j in J:
        if not C[j[0]][j[1]]:
            return 0

    return 1

def main():
    while True:
        ret = f()
        if ret == -1:
            return
        elif ret == 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while True:
    num = int(input())
    if num == 0:
        break
    G = set()
    for _ in range(num):
        i, j = [int(x) for x in input().split()]
        G.add((i,j))
    m = int(input())
    x, y = 10, 10
    if (x,y) in G:
        G.remove((x,y))

    for _ in range(m):
        d, c = input().split()
        c = int(c)
        for i in range(c):
            if d == "N":
                y += 1
            elif d == "S":
                y -= 1
            elif d== "E":
                x += 1
            else:
                x -= 1
            if (x,y) in G:
                G.remove((x,y))
                
    if G:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    while(1):
        N = int(input())
        if N == 0:
            break
        p = [10,10]
        g = set()
        for _ in range(N):
            g.add(tuple([int(n) for n in input().split()]))
        M = int(input())
        if tuple(p) in g:
            g.remove(p)
        for _ in range(M):
            d, l = input().split()
            l = int(l)
            if d == "N":
                b = [0,1]
            elif d == "E":
                b = [1,0]
            elif d == "S":
                b = [0,-1]
            else:
                b = [-1, 0]
            while(l > 0):
                p[0] += b[0]
                p[1] += b[1]
                if tuple(p) in g:
                    g.remove(tuple(p))
                l -= 1
        # print(g)
        print("Yes" if len(g) == 0 else "No")
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def between(sx,sy,mx,my,ex,ey):
    # y軸方向への移動
    if sx == mx and mx == ex:
        if sy <= my and my <= ey:
            return True
        elif ey <= my and my <= sy:
            return True
    elif sy == my and my == ey:
        if sx <= mx and mx <= ex:
            return True
        elif ex <= mx and mx <= sx:
            return True
    return False

while True:
    n = int(input())
    if n == 0: break
    stones = []
    picked = [False for i in range(n)]
    for i in range(n):
        tx, ty = map(int, input().split())
        stones.append([tx, ty])

    """
    print("stones::")
    for i in range(n):
        print(stones[i])
    print("------------")
    """
    m = int(input())

    cx = 10
    cy = 10
    for i in range(m):
        hoge, foo = map(str, input().split())
        drc = hoge
        dist = int(foo)

        if drc == 'N':
            ex = cx
            ey = cy + dist
        elif drc == 'E':
            ex = cx + dist
            ey = cy
        elif drc == 'W':
            ex = cx - dist
            ey = cy
        else:
            ex = cx
            ey = cy - dist

        #print("moving from {},{} to {},{}".format(cx, cy, ex, ey))

        for j in range(len(stones)):
            if between(cx, cy, stones[j][0], stones[j][1], ex, ey):
                picked[j] = True
                #print("stone {} picked".format(j))

        cx = ex
        cy = ey

    """
    print("picked???")
    for i in picked:
        print(i)
    print("----------")
    """
        
    for i in picked:
        if i == False:
            print("No")
            break
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import sys
while True:
    n = int(input())
    if n != 0:
        jewels = [[int(i) for i in input().split()] for j in range(n)]

        n = int(input())
        moves = [[i for i in input().split()] for k in range(n)]

        for i, j in enumerate(moves):
            moves[i][1] = int(moves[i][1])

        coodinates = [[10, 10]]
        current_cell = [10, 10]

        for i, k in enumerate(moves):
            direction = moves[i][0]
            vector = moves[i][1]
            if direction == 'N':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0], current_cell[1] + j])
                current_cell[1] = current_cell[1] + vector
            elif direction == 'S':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0], current_cell[1] - j])
                current_cell[1] = current_cell[1] - vector
            elif direction == 'W':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0] - j, current_cell[1]])
                current_cell[0] = current_cell[0] - vector
            elif direction == 'E':
                for j in range(1, vector + 1):
                    coodinates.append([current_cell[0] + j, current_cell[1]])
                current_cell[0] = current_cell[0] + vector

        flag = True
        for i in jewels:
            if i not in coodinates:
                flag = False
                break

        if flag:
            print('Yes')
        else:
            print('No')
    else:
        sys.exit()

Submission status: Accepted

Solution code:
commands = {"W": (-1, 0), "E": (1, 0), "S": (0, -1), "N": (0, 1)}

while True:
    n = int(input())
    if n == 0:
        break
    gems = []
    ans = "No"
    for i in range(n):
        gems.append(list(map(int, input().split())))
    m = int(input())
    pos = [10, 10]
    for i in range(m):
        direction, step = input().split()
        for j in range(int(step)):
            pos[0] += commands[direction][0]
            pos[1] += commands[direction][1]
            if pos in gems:
                gems.remove(pos)
    if not gems:
        ans = "Yes"
    print(ans)

Submission status: Accepted

Solution code:
while True:
  N=int(input())
  if N==0:
    break
  houseki=[]
  for i in range(N):
    a=list(map(int,input().split()))
    houseki.append(a)
  
  M=int(input())
  houkou=[]
  kyori=[]
  for i in range(M):
    d,l=map(str,input().split())
    houkou.append(d)
    kyori.append(int(l))
  
  x=10
  y=10
  get=0
  robo=[]
  for i in range(len(houkou)):
    if houkou[i]=="N":
      for j in range(kyori[i]):
        y+=1
        robo.append([x,y])
    elif houkou[i]=="E":
      for j in range(kyori[i]):
        x+=1
        robo.append([x,y])
    elif houkou[i]=="S":
      for j in range(kyori[i]):
        y-=1
        robo.append([x,y])
    elif houkou[i]=="W":
      for j in range(kyori[i]):
        x-=1
        robo.append([x,y])
  for i in range(len(houseki)):
    for j in range(len(robo)):
      if robo[j]==houseki[i]:
        get+=1
        break
  #print(houseki)
  #print(robo)
  if get==N:
    print("Yes")
  else:
    print("No")