input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
N = int(eval(input()))
I = [[int(i) for i in input().split()] for j in range(N)]
current, time = (0, 0), 0
for i in range(N):
dist = abs(current[0] - I[i][1]) + abs(current[1] - I[i][2])
if dist > I[i][0] - time or (I[i][0]- time - dist) % 2 == 1:
print("No")
break
current, time = ... | import sys
def solve():
N = int(eval(input()))
cx, cy = 0, 0
nt = 0
for _ in range(N):
t, x, y = list(map(int, input().split()))
rem = t - nt - abs(x - cx) - abs(y - cy)
if rem < 0 or rem % 2 > 0:
print("No")
break
cx, cy = x, y
... | p03457 |
# -*- coding: utf-8 -*-
def compare(x):
return x[0]
def find(x, lst):
for value in lst:
if value[0] == x:
return True
return False
n = int(input())
lst = [[0, 0, 0]]
for i in range(n):
lst.append(list(map(int, input().split())))
lst.sort(key=compare)
x = lst[len(lst) - 1][0]
for ... | # -*- coding: utf-8 -*-
n = int(input())
points = []
for i in range(n):
points.append(list(map(int, input().split())))
flg = False
for point in points:
flg = (point[0] >= (point[1] + point[2])) and ((point[0] % 2 == 1) and ((point[1] + point[2]) % 2 == 1) or (point[0] % 2 == 0) and ((point[1] + point[2]) %... | p03457 |
import sys
can = True; eval(input())
e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]
for a, b in zip(e[1:], e):
t = a[0] - b[0] - abs(a[1] - b[1]) - abs(a[2] - b[2])
if t < 0 or t % 2 == 1: can = False; break
print((['No', 'Yes'][can])) | import sys
ans = 'Yes'; eval(input())
for e in sys.stdin:
t, x, y = list(map(int, e.split()))
t = t - x - y
if t < 0 or t % 2 == 1: ans = 'No'; break
print(ans) | p03457 |
N = int(eval(input()))
T = 0
X = 0
Y = 0
ans = 'Yes'
for i in range(N):
t, x, y = list(map(int, input().split()))
if abs(X-x)+abs(Y-y)>abs(T-t) or (((X-x)+(Y-y))-(T - t))%2==1:
ans = 'No'
else:
T = t
X = x
Y = y
print(ans) | N = int(eval(input()))
xc, yc, tc = 0, 0, 0
ans = 'Yes'
for i in range(N):
t, x, y = list(map(int, input().split()))
if (t - tc - abs(x-xc) - abs(y-yc)) % 2 == 0 and t - tc - abs(x-xc) - abs(y-yc) >= 0:
xc, yc, tc = x, y, t
else:
ans = 'No'
break
print(ans)
| p03457 |
N = int(eval(input()))
txys = [list(map(int, input().split())) for _ in range(N) ]
txys.insert(0, [0, 0, 0])
for i in range(N):
t1, x1, y1 = txys[i]
t2, x2, y2 = txys[i+1]
dt = t2 - t1
tIsEven = dt % 2 == 0
dist = abs(x1 - x2) + abs(y1 - y2)
xyIsEven = dist % 2 == 0
if tIsEven !=... | N = int(eval(input()))
txys = [list(map(int, input().split())) for _ in range(N) ]
txys.insert(0, [0, 0, 0])
for i in range(N):
t1, x1, y1 = txys[i]
t2, x2, y2 = txys[i+1]
dt = t2 - t1
dist = abs(x1 - x2) + abs(y1 - y2)
if dt % 2 != dist % 2 or dist > dt:
print("No")
exit... | p03457 |
n = int(eval(input()))
l = []
for i in range(n):
t,x,y = list(map(int,input().split()))
l.append([t,x,y])
for i in range(n):
t,x,y = l[i][0],l[i][1],l[i][2]
if x+y > t or (t-(x+y))%2 != 0:
print('No')
exit()
l.sort()
for i in range(n-1):
t,x,y = l[i][0],l[i][1],l[i][2... | n = int(eval(input()))
l = [[0,0,0]]
for i in range(n):
t,x,y = list(map(int,input().split()))
l.append([t,x,y])
for i in range(n):
t,x,y = l[i][0],l[i][1],l[i][2]
t_,x_,y_ = l[i+1][0],l[i+1][1],l[i+1][2]
if t_ - t < (abs(x-x_)+abs(y-y_)) or (t_-t-(abs(x-x_)+abs(y-y_)))%2 != 0:
prin... | p03457 |
def dist(x,y):
return abs(x[0]-y[0])+abs(x[1]-y[1])
N = int(eval(input()))
X = [list(map(int,input().split())) for _ in range(N)]
flag = 0
t1,x1,y1 = 0,0,0
for i in range(N):
t2,x2,y2 = X[i]
d = dist((x1,y1),(x2,y2))
dt = t2-t1
if dt>=d and (dt-d)%2==0:
t1,x1,y1 = X[i]
else:
... | def dist(x,y):
return abs(x[0]-y[0])+abs(x[1]-y[1])
N = int(eval(input()))
X = [list(map(int,input().split())) for _ in range(N)]
flag = 0
t1 = 0
x1,y1 = 0,0
for i in range(N):
t2,x2,y2 = X[i]
dt = t2-t1
d = dist((x1,y1),(x2,y2))
if dt>=d and (dt-d)%2==0:
t1,x1,y1 = t2,x2,y2
... | p03457 |
N = int(eval(input()))
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(N):
t[i+1], x[i+1], y[i+1] = list(map(int, input().split()))
f = True
for i in range(N):
dt = t[i+1] - t[i]
dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
if dt < dist:
f = False
if dist%2 != dt%2... | n = int(eval(input()))
for i in range(n):
t,x,y=list(map(int,input().split()))
if (x + y) > t or (x + y + t) % 2:
print("No")
exit()
print("Yes")
| p03457 |
n = int(eval(input()))
x = 0
y = 0
time = 0
for i in range(n):
m = list(map(int,input().split()))
if (m[0]-time)>=abs(m[1]-x)+abs(m[2]-y):
if ((m[0]-time) -(abs(m[1]-x) + abs(m[2]-y)))%2 ==0:
x = m[1]
y = m[2]
time = m[0]
if i == n-1:
... | a = int(eval(input()))
x = 0
y = 0
time = 0
for i in range(a):
aa,b,c = list(map(int,input().split()))
if (abs(b-x) + abs(c-y)) %2 == (aa - time)%2 and abs(b-x) + abs(c-y) <= aa - time:
x = b
y = c
time = aa
else:
print("No")
break
if i == a-1:
... | p03457 |
n,*l=list(map(int,open(0).read().split()));print(("YNeos"[any((i+j+k)%2+(i<j+k)for i,j,k in zip(*[iter([abs(i-j)for i,j in zip([0,0,0]+l,l)])]*3))::2])) | _,*l=list(map(int,open(0).read().split()));print(("YNeos"[any((t+x+y)%2+(t<x+y)for t,x,y in zip(*[iter(l)]*3))::2])) | p03457 |
class Coodinate (object):
"""Coodinate object
This class contains infomation about the coodinates.
Each instance can have up to 3-dimensional(x,y,z) space coodinates.
params
------------------------------
x : int or floot ,default 0
y : int or floot ,default 0
z : int or fl... | # AtCoder Beginner Contest 086
# C - Traveling
N=int(eval(input()))
T=0
X,Y=0,0
for i in range (N):
t, x, y =list(map(int,input().split()))
time =t-T
distance=abs((x+y)-(X+Y))
if time >= distance and time%2==distance%2:
T=t
X,Y=x,y
else :
print("No")
... | p03457 |
N = int(eval(input()))
All = [list(map(int, input().split())) for _ in range(N)]
t = [row[0] for row in All]
x = [row[1] for row in All]
y = [row[2] for row in All]
pre_x = 0
pre_y = 0
pre_t = 0
can = True
for n in range(N):
can2 = False
T = abs(t[n] - pre_t)
dx = abs(x[n] - pre_x)
dy = ... | N = int(eval(input()))
All = [list(map(int, input().split())) for _ in range(N)]
pre_x = 0
pre_y = 0
pre_t = 0
can = True
for n in range(N):
can2 = False
T = All[n][0] - pre_t
d = abs(All[n][1] - pre_x) + abs(All[n][2] - pre_y)
# print(T, d)
if d <= T and T % 2 == d % 2:
can2 ... | p03457 |
N=int(eval(input()))
T=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
t=T[i][0]
j=T[i][1]+T[i][2]
if t<j or (t+j)%2:
print("No")
exit()
print("Yes") | N=int(eval(input()))
for i in range(N):
t,x,y=list(map(int, input().split()))
j=x+y
if t<j or (t+j)%2:
print("No")
exit()
print("Yes") | p03457 |
#入力受け取り
n = int(eval(input()))
tourList = []
for i in range(n):
array = list(map(int, input().strip().split()))
tourList.append(array)
#DebugPrint
currentTime = 0
currentX = 0
currentY = 0
loop=0
for i in range(len(tourList)) :
Time = tourList[i][0]
X = tourList[i][1]
Y = tou... |
#入力受け取り
n = int(eval(input()))
tourList = []
for i in range(n):
array = list(map(int, input().strip().split()))
tourList.append(array)
#DebugPrint
currentTime = 0
currentX = 0
currentY = 0
for i in range(len(tourList)) :
Time = tourList[i][0]
X = tourList[i][1]
Y = tourList[i][2]
... | p03457 |
import unittest
def is_ある時刻での判定(t, d):
# 時刻t >= d でないと実現不可能
if t < d:
return True
# 偶奇が一致しないと実現不可能
if not (t % 2 == d % 2):
return True
return False
def can_not_realize(N, t_list, x_list, y_list) -> bool:
# 各時刻ごとの判定
for t, x, y in zip(t_list, x_list, y_... | def can_not_realize(N, t_list, x_list, y_list) -> bool:
# t_n と t_n+1 間 での移動判定
for i in range(N):
diff_t = t_list[i + 1] - t_list[i]
diff_x = abs(x_list[i + 1] - x_list[i])
diff_y = abs(y_list[i + 1] - y_list[i])
sum_of_moving = diff_x + diff_y
# 時刻t >= sum_of_... | p03457 |
n=int(eval(input()))
nowx, nowy, nowt = 0, 0, 0
for i in range(n):
t,x,y = list(map(int,input().split()))
k = t-nowt-abs(nowx-x)-abs(nowy-y)
if k >= 0 and k % 2 == 0:
nowx, nowy, nowt = x, y, t
else:
print("No")
exit()
print("Yes")
| n = int(eval(input()))
t = 0
x = 0
y = 0
for _ in range(n):
nt, nx, ny = list(map(int,input().split()))
sa = nt-t
t = nt
kyori = abs(nx-x) + abs(ny-y)
x = nx
y = ny
if kyori > sa or (sa-kyori) % 2 == 1:
print("No")
exit()
print("Yes") | p03457 |
def is_reachable(dept, dest):
distance = abs(dest[1] - dept[1]) + abs(dest[2] - dept[2])
time = dest[0] - dept[0]
if (time - distance >= 0) and ((time - distance) % 2 == 0):
return True
else:
return False
N = int(eval(input()))
itin = [(0, 0, 0)]
itin_append = itin.append
f... | import sys
N = int(eval(input()))
t, x, y = 0, 0, 0
ans = 'No'
for s in sys.stdin.readlines():
nt, nx, ny = list(map(int, s.split()))
T = nt - t
D = abs(nx - x) + abs(ny - y)
if T < D or T % 2 != D % 2:
break
t, x, y = nt, nx, ny
else:
ans = 'Yes'
print(ans)
| p03457 |
n = int(eval(input()))
points = []
for i in range(n):
points.append(list(map(int, input().split(" "))))
t_pre, x_pre, y_pre = 0, 0, 0
reachable = True
for point in points:
t, x, y = list(map(int, point))
diff_t = t - t_pre
p = x + y
p_pre = x_pre + y_pre
move = 0
for _ in range... | n = int(eval(input()))
t = [0]
x = [0]
y = [0]
for _ in range(n):
t_tmp, x_tmp, y_tmp = list(map(int, input().split(" ")))
t.append(t_tmp)
x.append(x_tmp)
y.append(y_tmp)
reachable = True
for j in range(1, n + 1):
dt = t[j] - t[j - 1]
dist = abs(x[j] - x[j - 1]) + abs(y[j] - y[j - ... | p03457 |
# coding: utf-8
import math
n = int(eval(input()))
t = 0
x = 0
y = 0
txy = []
for i in range(n):
ti, xi, yi = list(map(int, input().split()))
txy.append((ti, xi, yi))
for ti, xi, yi in txy:
if abs(xi - x) + abs(yi - y) > abs(ti - t):
print("No")
exit()
elif (abs(xi - x) +... | # coding: utf-8
import math
n = int(eval(input()))
t = 0
x = 0
y = 0
# txy = []
# for i in range(n):
# ti, xi, yi = list(map(int, input().split()))
# txy.append((ti, xi, yi))
for i in range(n):
ti, xi, yi = list(map(int, input().split()))
if abs(xi - x) + abs(yi - y) > abs(ti - t):
... | p03457 |
N = int(eval(input()))
TXY = [tuple(map(int,input().split())) for i in range(N)]
ct = cx = cy = 0
for t,x,y in TXY:
dt = t-ct
d = abs(cx-x)+abs(cy-y)
if dt < d or dt%2 != d%2:
print('No')
exit()
ct,cx,cy = t,x,y
print('Yes') | N = int(eval(input()))
TXY = [tuple(map(int,input().split())) for i in range(N)]
ct = cx = cy = 0
for t,x,y in TXY:
d = abs(cx-x) + abs(cy-y)
if d > t-ct or d%2 != (t-ct)%2:
print('No')
exit()
ct,cx,cy = t,x,y
print('Yes') | p03457 |
def validation(l1, l2):
dif_t = abs(l2[0] - l1[0])
dif_x = abs(l2[1] - l1[1])
dif_y = l2[2] - l1[2]
if dif_x + dif_y > dif_t:
return False
elif dif_t % 2 == 0:
if (dif_x + dif_y) % 2 != 0:
return False
else:
return True
elif dif_t % 2 != 0:
if (dif_x + dif_y) % 2 ==... | n = int(eval(input()))
current_time = 0
current_pos = 0
ans = True
for _ in range(n):
t, x, y = list(map(int, input().split()))
time_dif = t - current_time # 3
pos_dif = (x+y) - current_pos # 3
if time_dif % 2 == 1 and pos_dif % 2 == 1 and pos_dif <= time_dif:
current_time += time_dif
... | p03457 |
from sys import stdin
input = stdin.readline
N = int(eval(input()))
txy = [[int(j) for j in input().split()] for i in range(N)]
def main():
pt = 0
px = 0
py = 0
flg = False
for t, x, y in txy:
# 到達 あるいは 通過
if abs(x - px) + abs(y - py) <= t - pt:
... | from sys import stdin
input = stdin.readline
N = int(eval(input()))
txy = [[int(j) for j in input().split()] for i in range(N)]
def main():
pt = 0
px = 0
py = 0
flg = False
for t, x, y in txy:
d = abs(x - px) + abs(y - py)
dt = t - pt
# 到達 あるいは 通過
... | p03457 |
from sys import stdin
input = stdin.readline
N = int(eval(input()))
txy = [[int(j) for j in input().split()] for i in range(N)]
def main():
pt = 0
px = 0
py = 0
flg = False
for t, x, y in txy:
dt = t - pt - abs(x - px) - abs(y - py)
# 余った時間が奇数 戻れない
i... | from sys import stdin
input = stdin.readline
lines = stdin.readlines
N = int(eval(input()))
txy = ((list(map(int, line.split()))) for line in lines())
def main():
pt = 0
px = 0
py = 0
flg = False
for t, x, y in txy:
dt = t - pt - abs(x - px) - abs(y - py)
# ... | p03457 |
N = int(eval(input()))
t,x,y = 0,0,0
for i in range(N):
T,X,Y = list(map(int,input().split()))
d = abs(x-X)+abs(y-Y)
if (T-t)-d >= 0 and ((T-t)-d)%2 == 0:
t,x,y = T,X,Y
continue
else:
print('No')
exit()
print('Yes') | import sys
input = sys.stdin.readline
N = int(eval(input()))
t,x,y = 0,0,0
for i in range(N):
T,X,Y = list(map(int,input().split()))
d = abs(x-X)+abs(y-Y)
if (T-t)-d >= 0 and ((T-t)-d)%2 == 0:
t,x,y = T,X,Y
continue
else:
print('No')
exit()
print('Yes') | p03457 |
n = int(eval(input()))
TXY = [[0,0,0]] + [list(map(int, input().split())) for _ in range(n)]
diff = [[t2 - t1, abs(x2 - x1), abs(y2 - y1)] for (t1, x1, y1), (t2, x2, y2) in zip(TXY, TXY[1:])]
for t, x, y in diff:
if x + y > t or (t - (x + y)) % 2 == 1:
print("No")
exit()
print("Yes") | n = int(eval(input()))
TXY = [[0,0,0]] + [list(map(int, input().split())) for _ in range(n)]
diff = [[t2 - t1, abs(x2 - x1), abs(y2 - y1)] for (t1, x1, y1), (t2, x2, y2) in zip(TXY, TXY[1:])]
if all([x + y <= t and (t - (x + y)) % 2 == 0 for t, x, y in diff]):
print("Yes")
else:
print("No") | p03457 |
r = 1
t = 0
m = 0
N = int(eval(input()))
txy = []
for i in range(N):
txy.append([int(x) for x in input().split()])
for i in txy:
t = i[0] - t
m = abs((i[1] + i[2]) - m)
if i[0] % 2 == 0:
if (i[1] + i[2]) % 2 != 0:
print("No")
break
elif... |
r = 1
t = 0
m = 0
N = int(eval(input()))
txy = []
for i in range(N):
txy.append([int(x) for x in input().split()])
for i in txy:
t = i[0] - t
m = abs((i[1] + i[2]) - m)
if t < m:
print("No")
break
elif (t - m) % 2 != 0:
print("No")
break
... | p03457 |
import sys
default_x = 0
default_y = 0
n = int(eval(input()))
a = []
#標準入力をN分読み込み
for i in range(n):
a.append(list(map(int,input().split())))
times = 0
for i in range(n):
for j in range(a[i][0]+times):
if default_x < a[i][1]:
default_x += 1
elif default_x >... | n = int(eval(input()))
travel = list()
#start point
travel.append((0,0,0))
for i in range(n):
travel.append(tuple(map(int,input().split())))
for j in range(n):
dist = abs(travel[j][0]-travel[j+1][0])
dd = abs(travel[j][1]-travel[j+1][1])+abs(travel[j][2]-travel[j+1][2])
#fail
if dist < d... | p03457 |
import sys
N = int(sys.stdin.readline())
TXY = [
tuple(map(int, sys.stdin.readline().split())) for _ in range(N)
]
def check(st, sx, sy, et, ex, ey):
if abs(sx - ex) + abs(sy - ey) > et - st:
return False
points = [(sx, sy)]
for _ in range(et - st):
new_points = set()
... | import sys
N = int(sys.stdin.readline())
TXY = [
tuple(map(int, sys.stdin.readline().split())) for _ in range(N)
]
def check(st, sx, sy, et, ex, ey):
timespan = et - st
diff = abs(sx - ex) + abs(sy - ey)
if diff > timespan:
return False
if (timespan - diff) % 2 == 0:
r... | p03457 |
n = int(eval(input()))
a0 = [0,0,0]
ans = "Yes"
for i in range(n):
ai = list(map(int,input().split()))
t = ai[0] - a0[0]
d = abs(ai[1] - a0[1])+ abs(ai[2] - a0[2])
if t < d or t%2 != d%2:
ans = "No"
a0 = ai
print(ans) | n = int(eval(input()))
t0,x0,y0 = 0,0,0
for i in range(n):
t,x,y = list(map(int, input().split()))
if abs(t0-t)%2 != (abs(x0-x)+abs(y0-y))%2 or (abs(x0-x)+abs(y0-y)) > abs(t0-t):
print("No")
exit()
t0,x0,y0, = t,x,y
else:
print("Yes") | p03457 |
N=int(eval(input()))
txy=[list(map(int,input().split())) for i in range(N)]
ans=0
for i in range(N):
t,x,y=txy[i][0],txy[i][1],txy[i][2]
if x+y<=t and t%2==(x+y)%2:ans+=1
print(("Yes" if ans==N else "No")) | n = int(eval(input()))
txy = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
t, x, y = txy[i]
if x + y > t or (t - x - y) % 2:
print("No")
exit()
print("Yes")
| p03457 |
def difference(two_lists):
return [abs(two_lists[1][i] - two_lists[0][i]) for i in range(3)]
n = int(eval(input()))
txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]
dtxy = list(map(difference, list(zip(txy, txy[1:]))))
for i in range(n):
dt, dx, dy = dtxy[i]
if dx + dy... | n = int(eval(input()))
for _ in range(n):
t, x, y = list(map(int, input().split()))
if x + y > t or (t - x - y) % 2:
print("No")
exit()
print("Yes") | p03457 |
n = int(eval(input()))
pretime, prex, prey = 0, 0, 0
for i in range(n):
nowtime, nowx, nowy = list(map(int, input().split()))
time = nowtime - pretime
x = abs(nowx - prex)
y = abs(nowy - prey)
if x+y > time:
print("No")
exit()
if (x+y) % 2 != time % 2:
print("N... | n = int(eval(input()))
for i in range(n):
t,x,y=list(map(int,input().split()))
if(not((x+y)<=t and (x+y)%2 == t%2)):
print("No")
exit()
print("Yes") | p03457 |
n=int(eval(input()))
t,x,y=[0],[0],[0]
for i in range(n):
T,X,Y=list(map(int,input().split()))
t.append(T)
x.append(X)
y.append(Y)
#print(t,x,y)
for i in range(n):
time=t[i+1]-t[i]
dx=abs(x[i+1]-x[i])
dy=abs(y[i+1]-y[i])
if time<dx+dy or (time+dx+dy)%2!=0:
print('N... | n=int(eval(input()))
t,x,y=[],[],[]
for i in range(n):
a,b,c=list(map(int,input().split()))
t.append(a)
x.append(b)
y.append(c)
current=[0,0]
for i in range(n):
next=[x[i]-current[0],y[i]-current[1]]
if abs(sum(next))>t[i] or (abs(sum(next))+t[i])%2!=0:
print('No')
... | p03457 |
N = int(eval(input()))
D = [input().split() for i in range(N)]
DD = []
for i in range(N):
DD.append([int(D[i][0]),int(D[i][1]),int(D[i][2])])
diff = [[0,0,0],[DD[0][0]-0,DD[0][1]-0,DD[0][2]-0]]
for i in range(N-1):
diff.append([DD[i+1][0]-DD[i][0],DD[i+1][1]-DD[i][1],DD[i+1][2]-DD[i][2]])
def ... | N = int(eval(input()))
for _ in range(N):
t, x, y = list(map(int, input().split()))
if x + y > t or (t + x + y)%2 != 0:
print("No")
quit()
print("Yes") | p03457 |
N=int(eval(input()))
clear_flag=0
tmp=0
tmp_x=0
tmp_y=0
for i in range(N):
txy=list(map(int,input().split()))
x=0
y=0
next_flag=0
for x_plus in range(txy[0]-tmp+1):
if next_flag==1:
break
for x_minus in range(txy[0]-tmp+1-x_plus):
if next_flag==1:
break
for ... | N=int(eval(input()))
clear_flag=0
for i in range(N):
txy=list(map(int,input().split()))
if txy[0]>=(txy[1]+txy[2]) and (txy[0]+txy[1]+txy[2])%2==0:
clear_flag+=1
else:
break
if clear_flag==N:
print("Yes")
else:
print("No") | p03457 |
N = int(eval(input()))
x = [list(map(int, input().split())) for i in range(N)]
cnt = 0
sum = 0
flag = 0
T = X = Y = 0
for i in range(N):
cnt = x[i][0] - T
sum = abs(x[i][1]- X) + abs(x[i][2]- Y)
T = x[i][0]
X = x[i][1]
Y = x[i][2]
if cnt < sum or cnt % 2 != sum % 2:
flag = 1... | N = int(eval(input()))
x = [list(map(int, input().split())) for i in range(N)]
cnt = 0
sum = 0
flag = 0
for i in range(N):
if i == 0:
cnt = x[i][0]
sum = x[i][1] + x[i][2]
else:
cnt = x[i][0] - x[i-1][0]
sum = abs(x[i][1]-x[i-1][1]) + abs(x[i][2]-x[i-1][2])
if cnt... | p03457 |
# -*- coding: utf-8 -*-
option = {(0, 0)}
def main():
global option
last_list = [0, 0, 0]
N = int(eval(input()))
for i in range(N):
this_list = list(map(int, input().split()))
add_option(this_list[0] - last_list[0], (this_list[1], this_list[2]))
if (this_list[1], t... | # -*- coding: utf-8 -*-
judge = 'Yes'
N = int(eval(input()))
for i in range(N):
t, x, y = list(map(int, input().split()))
if t < (x + y) or t % 2 != (x + y) % 2:
judge = 'No'
print(judge)
| p03457 |
n = int(eval(input()))
for i in range(n):
t, x, y = list(map(int, input().split()))
if x + y > t or (x + y) % 2 != t % 2:
print('No')
exit()
print("Yes") | n = int(eval(input()))
for i in range(n):
t, x, y = list(map(int, input().split()))
if t < x + y or t % 2 != (x + y) % 2:
print("No")
exit()
print("Yes") | p03457 |
n = int(input())
txy = [list(map(int, input().split())) for i in range(n)]
loc_x=0
loc_y=0
judge=0
for i in range(n):
if txy[i][0]%2==0:
if (txy[i][1]+txy[i][2])%2!=0:
judge+=1
elif (txy[i][1]+txy[i][2])%2==0:
judge+=1
temp = abs(loc_x-txy[i][1])+abs(loc_y-txy[i][2])
... | n = int(input())
txy = [list(map(int, input().split())) for i in range(n)]
loc_x=0
loc_y=0
judge=0
for i in range(n):
if judge!=0:
break
if txy[i][0]%2==0:
if (txy[i][1]+txy[i][2])%2!=0:
judge+=1
elif (txy[i][1]+txy[i][2])%2==0:
judge+=1
temp = abs(loc_x-... | p03457 |
N=int(eval(input()))
t0=0
x0=0
y0=0
for i in range(N):
t,x,y=list(map(int,input().split()))
d=abs(x-x0)+abs(y-y0)
if d>t-t0:
print("No")
exit()
else:
if ((t-t0)-d)%2!=0:
print("No")
exit()
t0=t
x0=x
y0=y
print("Yes") | N=int(eval(input()))
t0=0
x0=0
y0=0
ans="Yes"
for i in range(N):
t,x,y=list(map(int,input().split()))
d=abs(x-x0)+abs(y-y0)
dt=t-t0
if d>dt:
ans="No"
else:
if (dt-d)%2!=0:
ans="No"
t0=t
x0=x
y0=y
print(ans) | p03457 |
def c_Traveling(N, P):
t_old = x_old = y_old = 0
for t, x, y in P:
t1 = t - t_old
x1 = x - x_old
y1 = y - y_old
cond1 = abs(x1) + abs(y1)
cond2 = t1 % 2
cond3 = cond1 % 2
if t1 >= cond1 and cond2 == cond3:
pass
else:
... | def c_traveling(N, P):
t = x = y = 0 # 初期時刻には原点にいる
for t_next, x_next, y_next in P:
dt = t_next - t
dd = abs(x_next - x) + abs(y_next - y)
if dt >= dd and dt % 2 == dd % 2:
# 制限時間は次の座標へのマンハッタン距離以上持っていないとたどり着けない
# 制限時間と距離の偶奇が一致していないと次の座標で止まることができない
... | p03457 |
import sys
input = sys.stdin.readline
class Deer:
def __init__(self):
self.x = 0
self.y = 0
self.t = 0
def move(self, ti, xi, yi):
time_interval = ti - self.t
manhattan_distance = abs(xi - self.x) + abs(yi - self.y)
val = time_interval - manhattan_di... | import sys
input = sys.stdin.readline
N = int(eval(input()))
flag = True
for _ in range(N):
t, x, y = list(map(int, input().split()))
if (t < x + y) or (x + y + t) % 2:
flag = False
if flag:
print('Yes')
else:
print('No')
| p03457 |
import sys
N = int(eval(input()))
t, x, y = 0, 0, 0
for i in range(N):
in_t, in_x, in_y = list(map(int, input().split()))
t = in_t - t
x = abs(in_x - x)
y = abs(in_y - y)
if (t >= x + y) & ((t - (x + y)) % 2 == 0):
continue
print('No')
sys.exit()
print('Yes') | import sys
N = int(eval(input()))
for _ in range(N):
t, x, y = list(map(int, input().split()))
if (t >= x + y) & ((t - (x + y)) % 2 == 0):
continue
print('No')
sys.exit()
print('Yes') | p03457 |
n = int(eval(input()))
info = [list(map(int, input().split())) for i in range(n)]
info.insert(0, [0, 0, 0])
x_diff, y_diff = 0, 0
for i in range(n):
dt = info[i+1][0] - info[i][0]
x_diff = abs(info[i+1][1] - info[i][1])
y_diff = abs(info[i+1][2] - info[i][2])
if dt < x_diff + y_diff:
... | n = int(eval(input()))
for i in range(n):
t,x,y=list(map(int,input().split()))
if (x + y) > t or (x + y + t) % 2:
print("No")
exit()
print("Yes")
| p03457 |
N = int(eval(input()))
T = [[0, 0]]
for _ in range(N):
t, x, y = list(map(int, input().split()))
T.append((t, x + y))
for i in range(N):
dt = T[i+1][0] - T[i][0]
dxy = abs(T[i+1][1] - T[i][1])
if dt < dxy or dt % 2 != dxy % 2:
print("No")
break
else:
print("Yes") | T = [[0, 0]]
for i in range(int(eval(input()))):
t, x, y = list(map(int, input().split()))
T.append((t, x + y))
dt = T[i+1][0] - T[i][0]
dxy = abs(T[i+1][1] - T[i][1])
if dt < dxy or dt % 2 != dxy % 2:
print("No")
break
else:
print("Yes") | p03457 |
import math
import sys
n = int(eval(input()))
for i in range(n):
t,x,y = list(map(int, input().split()))
d = abs(x)+abs(y)
if d > t or (d - t) % 2 != 0:
print('No')
exit()
print('Yes')
| import math
import sys
n = int(eval(input()))
for i in range(n):
t,x,y = list(map(int, sys.stdin.readline().split()))
d = abs(x)+abs(y)
if d > t or (d - t) % 2 != 0:
print('No')
exit()
print('Yes')
| p03457 |
N = int(eval(input()))
now_x = 0
now_y = 0
now_t = 0
Flag = False
for i in range(N):
t , x, y = list(map(int,input().split()))
dx = abs(x - now_x)
dy = abs(y - now_y)
dt = abs(t - now_t)
if (dt - (dx + dy)) % 2 != 0 or dt < (dx + dy):
Flag = True
now_x = x
now_y = y
... | N = int(eval(input()))
now_t, now_x, now_y = 0, 0, 0
for i in range(N):
next_t, next_x, next_y = list(map(int, input().split()))
distance = abs(next_x - now_x) + abs(next_y - now_y)
spent_time = next_t - now_t
if spent_time < distance or distance % 2 != spent_time % 2:
print('No')
... | p03457 |
n = int(eval(input()))
t = 0
x = 0
y = 0
judge = True
for i in range(n):
t1, x1, y1 = list(map(int, input().split()))
if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1 or (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:
judge = False
x = x1
y = y1
t = t1
if judge == True:
print("Y... | import sys
input = sys.stdin.readline
n = int(eval(input()))
t = 0
x = 0
y = 0
judge = True
for i in range(n):
t1, x1, y1 = list(map(int, input().split()))
if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1 or (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:
judge = False
x = x1
y = y1
... | p03457 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
t = 0
x = 0
y = 0
judge = True
l = [list(map(int, input().split())) for _ in range(n)]
for t1, x1, y1 in l:
if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1 or (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:
print("No")
exit()
... | import sys
input = sys.stdin.readline
n = int(eval(input()))
t = 0
x = 0
y = 0
judge = True
l = [tuple(map(int, input().split())) for _ in range(n)]
for t1, x1, y1 in l:
if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1 or (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:
print("No")
exit()
... | p03457 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
t = 0
x = 0
y = 0
l = [tuple(map(int, input().split())) for _ in range(n)]
for t1, x1, y1 in l:
if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1:
print("No")
exit()
if (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:
p... | import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
t = 0
x = 0
y = 0
l = [tuple(map(int, input().split())) for _ in range(n)]
for t1, x1, y1 in l:
if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1:
print("No")
exit()
if (a... | p03457 |
n=int(input())
txy=[]
for _ in range(n):
t,x,y=map(int, input().split())
txy.append((t,x,y))
def isOk(txy):
now_pos=0
now_t=0
for t,x,y in txy:
move=x+y-now_pos
time=t-now_t
if time>=move and time%2==move%2:
continue
else:
ret... | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(eval(input()))
TXY = [list(map(int, input().split())) for _ in range(N)]
nx, ny = 0, 0
time = 0
ans = "Yes"
for i in range(N):
t, x, y = TXY[i]
dt = t - time
move = abs(nx - x) + abs(ny - y)
if move > d... | p03457 |
def solve():
def measurement(a, b, w):
a_root = root[a]
b_root = root[b]
if a_root != b_root:
a_member = member[a_root]
b_member = member[b_root]
offset = w - (weight[b] - weight[a])
if len(a_member) > len(b_member):
a_... | def solve():
def measurement(a, b, w):
a_root = root[a]
b_root = root[b]
if a_root != b_root:
a_member = member[a_root]
b_member = member[b_root]
offset = w - (weight[b] - weight[a])
if len(a_member) > len(b_member):
a_... | p00909 |
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq
# decimal.getcontext().prec = 50
sys.setrecursionlimit(100000)
MOD = 10**9 + 7
def dijkstra(g, v_size, st):
"""Dijkstra method"""
d = [float('inf')] * v_size
d[st] = ... | #!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq
# decimal.getcontext().prec = 50
sys.setrecursionlimit(100000)
MOD = 10**9 + 7
def dijkstra(g, v_size, st):
"""Dijkstra method"""
d = [float('inf')] * v_size
d[st] = ... | p03453 |
from heapq import heappush, heappop
import sys
#input = sys.stdin.readline
INF = 10**18
mod = 10**9+7
def dijkstra(start, n, graph):
route_cnt = [start] * n
route_cnt[start] = 1
que = [(0, start)]
dist = [INF] * n
dist[start] = 0
while que:
min_dist, u = heappop(que)
... | from heapq import heappush, heappop
import sys
input = sys.stdin.readline
INF = 10**18
mod = 10**9+7
def dijkstra(start, n, graph):
route_cnt = [start] * n
route_cnt[start] = 1
que = [(0, start)]
dist = [INF] * n
dist[start] = 0
while que:
min_dist, u = heappop(que)
... | p03453 |
from collections import defaultdict
from functools import reduce
import heapq as hq
from sys import stdin
MOD = 10**9+7
N,M = list(map(int,stdin.readline().split()))
S,T = list(map(int,stdin.readline().split()))
S,T = S-1,T-1
E = defaultdict(list)
lines = stdin.readlines()
for line in lines:
u,v,d = ... | from functools import reduce
import heapq as hq
from sys import stdin
MOD = 10**9+7
N,M = list(map(int,stdin.readline().split()))
S,T = list(map(int,stdin.readline().split()))
S,T = S-1,T-1
inf = float('inf')
E = [[] for _ in range(N)]
lines = stdin.readlines()
for line in lines:
u,v,d = list(map(i... | p03453 |
from collections import defaultdict
from heapq import heappop, heappush
import sys
sys.setrecursionlimit(200000)
MOD, INF = 1000000007, float('inf')
def get_patterns_func(s, ancestors):
cache = {s: 1}
def get_patterns(v):
if v in cache:
return cache[v]
return sum(ge... | from heapq import heappop, heappush
import sys
MOD, INF = 1000000007, float('inf')
def solve(s, t, links):
q = [(0, 0, s, -1, 0), (0, 0, t, -1, 1)]
visited_fwd, visited_bwd = [INF] * n, [INF] * n
patterns_fwd, patterns_bwd = [0] * (n + 1), [0] * (n + 1)
patterns_fwd[-1] = patterns_bwd[-1] =... | p03453 |
from heapq import *
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def main():
md = 10 ** 9 + 7
inf = 10 ** 15
to = defaultdict(list)
n, m = map(int, input().split())
... | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readlin... | p03453 |
import sys
readline = sys.stdin.readline
from heapq import heappop as hpp, heappush as hp
def dijkstra(N, s, Edge):
inf = geta
dist = [inf] * N
dist[s] = 0
Q = [s]
dp = [0]*N
dp[s] = 1
while Q:
k = hpp(Q)
dn, vn = divmod(k, geta)
if dn > dist[vn]:
... | import sys
readline = sys.stdin.readline
from heapq import heappop as hpp, heappush as hp
def dijkstra(N, s, Edge):
inf = geta
dist = [inf] * N
dist[s] = 0
Q = [(0, s)]
dp = [0]*N
dp[s] = 1
while Q:
dn, vn = hpp(Q)
if dn > dist[vn]:
continue
... | p03453 |
mod=10**9+7
class Dijkstra():
""" ダイクストラ法
重み付きグラフにおける単一始点最短路アルゴリズム
* 使用条件
- 負のコストがないこと
- 有向グラフ、無向グラフともにOK
* 計算量はO(E*log(V))
* ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
"""
class Edge():
""" 重み付き有向辺 """
def __init__(self, _to, _cost):
... | mod=10**9+7
class Dijkstra():
""" ダイクストラ法
重み付きグラフにおける単一始点最短路アルゴリズム
* 使用条件
- 負のコストがないこと
- 有向グラフ、無向グラフともにOK
* 計算量はO(E*log(V))
* ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
"""
class Edge():
""" 重み付き有向辺 """
def __init__(self, _to, _cost):
... | p03453 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, ... | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, ... | p03453 |
# ARC090E
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
n, m = list(map(int, input().split()))
s, t = list(map(int, input().split()))
s -= 1
t -= 1
from collections import defaultdict
ns = defaultdict(set)
ds = [None] * m
es = {}
for i in range(m)... | # ARC090E
def hoge():
M = 10**9 + 7
import sys
input = lambda : sys.stdin.readline().rstrip()
n, m = list(map(int, input().split()))
s, t = list(map(int, input().split()))
s -= 1
t -= 1
from collections import defaultdict
ns = defaultdict(set)
for i in range(m):
... | p03453 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | p03453 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | p03453 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | p03453 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in s... | p03453 |
import heapq
def dijkstra(start: int, graph: list) -> list:
"""dijkstra法: 始点startから各頂点への最短距離を求める
計算量: O((E+V)logV)
"""
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = len(graph)
dist = [INF] * n
ptn = [0] * n
dist[start] = 0
ptn[start] = 1
q = [(0, start)] # q = [(star... | import heapq
import sys
input = sys.stdin.buffer.readline
def dijkstra(start: int, graph: list) -> list:
"""dijkstra法: 始点startから各頂点への最短距離を求める
計算量: O((E+V)logV)
"""
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = len(graph)
dist = [INF] * n
ptn = [0] * n
dist[start] = 0
ptn[s... | p03453 |
# 写経
# https://atcoder.jp/contests/agc011/submissions/1157055
class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)]
def find(self, x):
if self.v[x] < 0:
return x
else:
self.v[x] = self.find(self.v[x])
return self.v[x]
... | '''
写経
https://youtu.be/cJ-WjtA34GQ?t=1899
https://atcoder.jp/contests/agc011/submissions/1157055
http://noshi91.hatenablog.com/entry/2018/04/17/183132
https://camypaper.bitbucket.io/2016/12/18/adc2016/
'''
class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 *... | p03787 |
import queue
n,m=list(map(int,input().split()))
vis,ci,cb,cc=[0]*(n+1),0,0,0
g=[[] for i in range(n+1)]
def dfs(x):
stk,flag=queue.LifoQueue(),True
stk.put((x,1))
while not stk.empty():
u,col=stk.get()
if vis[u]:
flag&=(vis[u]==col)
continue
vis[u]=col
for i in g[u]:
stk.put((i,3-col))... | n,m=list(map(int,input().split()))
vis,ci,cb,cc=[0]*(n+1),0,0,0
g=[[] for i in range(n+1)]
for i in range(m):
u,v=list(map(int,input().split()))
g[u]+=[v]
g[v]+=[u]
for i in range(1,n+1):
if vis[i]==0:
if len(g[i])==0:
ci+=1
else:
s,f=[(i,1)],True
while len(s):
u,col=s.pop()
if... | p03787 |
print((2*input().count('+')-4)) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = read().rstrip().decode('utf-8')
answer = 4-2*S.count('-')
print(answer) | p03315 |
import sys
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
S = LS2()
a = S.count('+')
b = S.count('-')
print((a-b)) | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def ... | p03315 |
print((-4+2*input().count('+')))
| print((2*input().count('+')-4))
| p03315 |
from bisect import bisect_left as bl
def search_left(in_ind, alst, outs, doors):
tmp = bl(outs, in_ind)
if tmp == 0:
return 0
out_ind = outs[tmp - 1]
right_door = bl(doors, in_ind) - 1
if right_door < 0:
return alst[in_ind]
left_door = bl(doors, out_ind)
ret = alst[in_ind]
for... | w = int(eval(input()))
alst = list(map(int, input().split()))
INF = 10 ** 20
acc = -INF
left = []
for i in range(w):
a = alst[i]
if a == 0:
acc = INF
elif a > 0:
acc -= 1
elif a < 0:
acc = min(acc - 1, -a)
left.append(acc)
acc = -INF
right = []
for i in range(w):
a = alst[w - ... | p01713 |
from queue import PriorityQueue
class State:
def __init__(self,index,time):
self.index=index
self.time=time
def __lt__(self,state):
return self.time>state.time
while 1:
try: n=int(eval(input()))
except: break
a=list(map(int,input().split()))
ts=[float("inf")]*n
vis=[False]*... | n=int(eval(input()))
a=list(map(int,input().split()))
ts=[0]*n
for indices in list(range(n)),reversed(list(range(n))):
t=0
for i in indices:
if a[i]==0: t=float("inf")
if a[i]<0: t=min(t,-a[i])
if a[i]>0: ts[i]=max(ts[i],min(a[i],t))
t-=1
print((sum(ts))) | p01713 |
N = int(eval(input()))
A = list(map(int, input().split()))
x = []
y = []
P = sorted((a for a in A if a >= 0), reverse=True)
Q = sorted(a for a in A if a < 0)
if not Q:
M = sum(P[:-2]) + (P[-2] - P[-1])
for _ in range(N - 2):
X = P.pop()
Y = P.pop()
x.append(X)
y.app... | # 入力
N = int(eval(input()))
A = list(map(int, input().split()))
# 正-負をなるべく多く達成するように操作する
P = sorted((a for a in A if a >= 0), reverse=True)
Q = sorted(a for a in A if a < 0)
x, y = [], []
if len(P) == 2 and not Q:
Y, X = P.pop(), P.pop()
x.append(X)
y.append(Y)
P.append(X - Y)
if len(P) >... | p03007 |
from collections import deque
N = int(eval(input()))
A = (list(map(int, input().split())))
A = sorted(A)
A = deque(A)
l = []
for i in range(N - 1):
if i == N - 2:
ans = A[1] - A[0]
l.append("{} {}".format(A[1], A[0]))
elif i == N - 3:
left = A.popleft()
right = A.pop(... | N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A)
leftest_val = A[0]
rightest_val = A[-1]
left_idx = 1
right_idx = N - 2
history = []
for i in range(N - 1):
left_val = A[left_idx]
right_val = A[right_idx]
if i == N - 2:
history.append("{} {}".format(rightest_val,... | p03007 |
S = input()[::-1]
word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
judge = [True, True, True, True]
count = 0
while any(judge):
for i in range(len(word)):
if S[:len(word[i])] == word[i]:
S = S[len(word[i]):]
else:
count += 1
if S == '':
print('YES')
... | a,b,c,d=[i[::-1] for i in ['dream','dreamer','erase','eraser']]
s,j=input()[::-1],True
while j:
j=False
for i in [a,b,c,d]:
if s.startswith(i): s=s[len(i):];j=True
print(('YNEOS'[len(s)>0::2])) | p03854 |
#!/usr/bin/env python3
import sys
YES = "YES" # type: str
NO = "NO" # type: str
def solve(S: str):
while len(S)>4:
if S[:11]=="dreameraser":
S=S[11:]
elif S[:10] == "dreamerase":
S= S[10:]
elif S[:6]=="eraser":
S= S[6:]
elif S[:5]... | #!/usr/bin/env python3
import sys
YES = "YES" # type: str
NO = "NO" # type: str
def solve(S: str):
S = S[::-1]
while len(S)>4:
if S[:6]=="resare":
S= S[6:]
elif S[:5] == "esare" or S[:5]== "maerd":
S=S[5:]
elif S[:7] == "remaerd":
S=S... | p03854 |
S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list([s[::-1] for s in day_dream_word])
T = ""
res = False
partial_res = True
while not res and partial_res:
partial_res = False
for add_word in day_dream_word:
nextT = T
nextT += add_word
if S == next... | S = input()[::-1]
day_dream_word = ["dreamer", "dream", "eraser", "erase"]
day_dream_word = list([s[::-1] for s in day_dream_word])
T = ""
Tindex = 0
res = False
partial_res = True
while not res and partial_res:
partial_res = False
for add_word in day_dream_word:
nextTindex = Tindex + len(add_word)
... | p03854 |
A = ["dream", "dreamer", "erase", "eraser"]
for i in range(4):
A[i] = A[i][::-1]
S = input()[::-1]
idx = 0
while idx < len(S):
flag = False
for i in range(4):
if len(S) - idx < len(A[i]):
continue
else:
if S[idx:idx+len(A[i])] == A[i]:
fl... | A = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(A)):
A[i] = A[i][::-1]
s = input()[::-1]
i = 0
while True:
f = True
for a in A:
if len(a) > len(s) - i:
continue
if s[i:i+len(a)] == a:
i += len(a)
f = False
break
... | p03854 |
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
print(("YES" if s=="" else "NO")) | s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s in "":
print("YES")
else:
print("NO") | p03854 |
# coding: utf-8
"""this is python work script"""
CHECK_WORDS = ['dream', 'dreamer', 'erase', 'eraser']
def check_word(word, check_word_list):
find_word = False
# print(word, check_word_list)
for i, cw in enumerate(check_word_list):
find_result = word.find(cw)
# print(i, cw, fin... | # coding: utf-8
"""this is python work script"""
def solver(word):
"""solve this problem"""
check_result = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
answer = 'YES'
if check_result:
answer = 'NO'
return answer
def main():
... | p03854 |
s = input()[::-1]
s = s.replace("eraser"[::-1], "")
s = s.replace("erase"[::-1], "")
s = s.replace("dreamer"[::-1], "")
s = s.replace("dream"[::-1], "")
if s == "":
print("YES")
else:
print("NO") | s = input()[::-1]
words = ["eraser","erase","dreamer","dream"]
for i in words:
s = s.replace(i[::-1], "")
if s == "": print("YES")
else: print("NO") | p03854 |
S = input()[::-1]
devide = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
devide[i] = devide[i] [::-1]
flag = True
i = 0
while i < len(S):
flag2 = False
for j in range(4):
if devide[j] == S[i : i+len(devide[j])]:
flag2 = True
i += len(devide[j])
... | S = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
print(('YES' if len(S) == 0 else 'NO')) | p03854 |
def main():
S = input()[::-1]
tar = {'maerd', 'remaerd', 'esare', 'resare'}
i = 0
while i < len(S):
if S[i] == 'm':
if S[i:i+5] == 'maerd':
i += 5
else:
return print("NO")
elif S[i] == 'e':
if S[i:i+5] == 'esa... | def main():
S = input()
S = S[::-1]
ans = ["maerd", "remaerd", "esare", "resare"]
while S:
for a in ans:
if S[:5] in ans:
S = S.replace(S[:5], "", 1)
break
elif S[:6] in ans:
S = S.replace(S[:6], "", 1)
... | p03854 |
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
W.append(w[::-1])
while 1:
flg = False
for w in W:
if S.startswith(w):
S = S[len(w):]
flg = True
if not flg:
print('NO')
exit()
if not S:
break
print(... | S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
W.append(w[::-1])
idx = 0
while 1:
flg = False
for w in W:
if S.startswith(w, idx):
idx += len(w)
flg = True
if not flg:
print('NO')
exit()
if len(S) <= idx:
... | p03854 |
import sys
input = sys.stdin.readline
S = list(input().rstrip())
while S:
if S[-1] == "m":
if S[-5:] == ["d", "r", "e", "a", "m"]:
S = S[:-5]
else:
print("NO")
sys.exit()
elif S[-1] == "e":
if S[-5:] == ["e", "r", "a", "s", "e"]:
... | import sys
input = sys.stdin.readline
S = input().rstrip()
while S:
if S[-5:] == "dream":
S = S[:-5]
elif S[-5:] == "erase":
S = S[:-5]
elif S[-6:] == "eraser":
S = S[:-6]
elif S[-7:] == "dreamer":
S = S[:-7]
else:
print("NO")
sys.exit(... | p03854 |
import sys
S=input()
judge=["dream","dreamer","erase","eraser"]
S_pointer=0
V=set()
V.add(0)
cnt=0
while cnt<len(S)/5+1:
tmp=set()
for i in V:
for j in judge:
if S[i:i+7].find(j)==0:
if i+len(j)==len(S):
tmp.add(i+len(j))
print("YES")
sys.exit()
else:
tmp.add(i+... | import sys
S=input()
judge=["dream","dreamer","erase","eraser"]
V=set()
V.add(0)
cnt=0
while cnt<len(S):
tmp=set()
for i in V:
for j in judge:
if S[i:i+7].find(j)==0:
tmp.add(i+len(j))
if i+len(j)==len(S):
print("YES")
sys.exit()
V=tmp
cnt+=1
else:
print("NO")
| p03854 |
s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
if s[:5]==p[0]:s=s.replace(p[0],"",1)
elif s[:5]==p[3]:s=s.replace(p[3],"",1)
elif s[:7]==p[1]:s=s.replace(p[1],"",1)
elif s[:6]==p[2]:s=s.replace(p[2],"",1)
else:
if s=="":print("YES");break
else:print("NO");break
| s=input()[::-1]
p=["maerd","remaerd","resare","esare"]
while True:
if s[:5]==p[0]:s=s[5:]
elif s[:5]==p[3]:s=s[5:]
elif s[:7]==p[1]:s=s[7:]
elif s[:6]==p[2]:s=s[6:]
else:
if s=="":print("YES");break
else:print("NO");break
| p03854 |
from re import sub
dest = input().rstrip("\n")
suffixes = ["dream$", "dreamer$", "erase$", "eraser$"]
while True:
len_before = len(dest)
for suffix in suffixes:
dest = sub(suffix, "", dest)
if len(dest) == len_before:
break
print(("YES" if not dest else "NO"))
| dest = input().rstrip("\n")
suffixes = ["dream", "dreamer", "erase", "eraser"]
cut_lens = [-5, -7, -5, -6]
while True:
for suffix, cut_len in zip(suffixes, cut_lens):
if dest.endswith(suffix):
dest = dest[:cut_len]
break
else:
break
print(("YES" if not des... | p03854 |
def examA():
S = SI()
T = SI()
N = len(S)
ans = "No"
for i in range(N):
cur = S[i:] + S[:i]
#print(cur)
if cur==T:
ans = "Yes"
print(ans)
return
def examB():
H, W = LI()
S = [SI()for _ in range(H)]
flag = True
ans = 0
... | def examA():
S = SI()
T = SI()
N = len(S)
ans = "No"
for i in range(N):
cur = S[i:] + S[:i]
#print(cur)
if cur==T:
ans = "Yes"
print(ans)
return
def examB():
H, W = LI()
S = [SI()for _ in range(H)]
flag = True
ans = 0
... | p03854 |
S = input().strip()
cur = 0
flag = 0
while cur<len(S):
if S[cur:cur+11]=="dreameraser":
cur += 11
elif S[cur:cur+10]=="dreamerase":
cur += 10
elif S[cur:cur+7]=="dreamer":
cur += 7
elif S[cur:cur+6]=="eraser":
cur += 6
elif S[cur:cur+5]=="dream" or S[cur:c... | S = input().strip()
N = len(S)
if N<5:
print("NO")
else:
flag = 0
cur = N
while cur>0:
if cur>=7 and S[cur-7:cur]=="dreamer":
cur -= 7
elif cur>=6 and S[cur-6:cur]=="eraser":
cur -= 6
elif cur>=5 and S[cur-5:cur] in ["dream","erase"]:
... | p03854 |
S = input().strip()
N = len(S)
cur = 0
flag = 0
while cur<N:
if S[cur:cur+5]=="dream":
if cur+5==N:
cur += 5
elif cur+5<N and S[cur+5]=="d":
cur += 5
elif S[cur:cur+7]=="dreamer":
if cur+7==N:
cur += 7
elif S[cur+7]... | S = input().strip()
N = len(S)
cur = 0
flag = 0
while cur<N:
if S[cur:cur+5]=="dream":
if cur+5==N:
cur += 5
elif cur+5<N and S[cur+5]=="d":
cur += 5
elif S[cur:cur+7]=="dreamer":
if cur+7==N:
cur += 7
elif S[cur+7]... | p03854 |
S = input()
words = ("dream", "dreamer", "erase", "eraser")
for _ in range((len(S) + 4) // 5):
for word in words:
if S.endswith(word):
S = S[: -len(word)]
print("NO") if S else print("YES")
| S = input()
for w in ("eraser", "erase", "dreamer", "dream"):
S = S.replace(w, "")
print("NO") if S else print("YES")
| p03854 |
s=input()[::-1]
words=["dreamer","eraser","dream","erase"]
add=0
while add!=len(s):
cnt=0
for i in words:
length=len(i)
word=s[add:add+length][::-1]
if word==i:
add +=length
break
else:cnt +=1
if cnt==4:print("NO");exit()
print("YES") | s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)
while l!=n:
flag=0
for i in T:
word=i[::-1]
if s[l:l+len(word)]==word:
l +=len(word)
flag=1
break
if flag==0:print("NO");exit()
print("YES") | p03854 |
s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)
while l!=n:
flag=0
for i in T:
word=i[::-1]
if s[l:l+len(word)]==word:
l +=len(word)
flag=1
break
if flag==0:print("NO");exit()
print("YES") | s=input()[::-1]
T=["dream","dreamer","erase","eraser"]
l,n=0,len(s)
while l!=n:
flag=0
for i in T:
word=i[::-1]
if s[l:l+len(word)]==word:
l +=len(word)
flag=1
if flag==0:print("NO");exit()
print("YES") | p03854 |
def c_daydream(S):
import re
# Sを逆にしたものから該当する文字を除いていき、空文字列にできるか?
s = S[::-1]
dict = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
n = len(s)
while n > 0:
for d in dict:
if s.startswith(d):
s = re.sub('^' + d, '', s)
... | def c_daydream(S):
# Sを逆にしたものから文字列を除いていき、空文字にできるか?
s = S[::-1]
n = len(s)
while True:
if n == 0:
return 'YES'
elif n >= 5 and s[:5] == 'maerd':
s = s[5:]
elif n >= 7 and s[:7] == 'remaerd':
s = s[7:]
elif n >= 5 and s[:5] == ... | p03854 |
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
print("NO")
else:
print("YES") | s = input().replace("eraser", "") .replace("erase", "").replace("dreamer", "").replace("dream", "")
print(("NO" if s else "YES")) | p03854 |
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7
def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): r... | import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7
def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): r... | p02716 |
import sys
sys.setrecursionlimit(2*1000000)
N = int(eval(input()))
A = list(map(int, input().split(" ")))
dp_dict = {}
inf = -1*1000000000
def dp(i, j):
if j == 1:
return A[i]
if i+2 >= N:
return inf
if N//2-j < i//2-1:
return inf
temp = max([dp(i+2, j-1)... | N = int(eval(input()))
A = [0]+list(map(int, input().split(" ")))
dp_list = [{0, 0}, {0: 0, 1: A[1]}, {0: 0, 1: A[1] if A[1] > A[2] else A[2]}]
for i in range(3, N+1):
b = (i-1)//2
f = (i+1)//2
dp_list.append({})
for j in range(b, f+1):
if j in dp_list[i-1]:
dp_list[i][j... | p02716 |
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
# dp[(i, x, flg)] := i番目までみてx個選んでいる時の最大値。flgは最後の1つをとったかどうか。
dp = defaultdict(lambda: -float('inf'))
dp[(0, 0, 0)] = 0
for i, a in enumerate(A, start=1):
j = i // 2
for x in range(j - 1, j + 2):
dp... | from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
# dp[(i, x, flg)] := i番目までみてx個選んでいる時の最大値。flgは最後の1つをとったかどうか。
dp = defaultdict(lambda: -float('inf'))
dp[(0, 0, 0)] = 0
for i, a in enumerate(A, start=1):
for x in range((i - 1) // 2, (i + 1) // 2 + 1):
... | p02716 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.