dx = [-1,-1,0,1,1,1,0,-1]
dy = [0,1,1,1,0,-1,-1,-1]
# ์
๋ ฅ
n, m, k = map(int, input().split())
before_fireballs = [list(map(int, input().split())) for _ in range(m)]
# [ํ, ์ด, ์ง๋, ์๋ ฅ, ๋ฐฉํฅ] + ํ์ด์ด๋ณผ idx
# [0, 1, 2, 3, 4] + 5
## ๋งค ํด๋ง๋ค -> ํฉ์ณ์ง๋ ํ์ด์ด๋ณผ์ ์ ๋ณด๋ฅผ ์์๋ก ์ ์ฅํ ๋ฐฐ์ด์ด ํ์ํจ..
## ์ง๋์ด 0์ธ ํ์ด์ด๋ณผ์ ์๋ฉธ๋์ด ์์ด์ง๋ค => ๋ค์ ํด์์๋ ๊ฒ์์ํ ๋์์ด ์ ๋จ !!!
for turn in range(k):
result = dict()
fireballs = []
# 1 ๋จ๊ณ. ๋ชจ๋ ํ์ด์ด๋ณผ์ ์ด๋
for idx in range(len(before_fireballs)):
r, c, m, s, d = before_fireballs[idx]
####print(r, c)
if m == 0: ## (์์ธ ์ฒ๋ฆฌ : ์ด์ ํด์์ ์๋ฉธ๋ ํ์ด์ด๋ณผ์ pass)
continue
nx, ny = r + (dx[d]*s), c + (dy[d]*s)
nx = (nx + n) % n ###
ny = (ny + n) % n ###
result.setdefault((nx, ny), [])
result[(nx, ny)].append([m, s, d, idx])
# 0, 1, 2, 3
###print(result)
# 2 ๋จ๊ณ. (2๊ฐ ์ด์์ ํ์ด์ด๋ณผ์ด ์๋ ์นธ์์๋) ํ์ด์ด๋ณผ์ ํฉ์ณ์ง + ๋๋ ์ง + ์๋ฉธ
for key, value in result.items():
###print(key)
###print(value)
new_i, new_j = key
fire_lt = value
if len(fire_lt) == 1:
mm, ss, dd, idx = fire_lt[0]
fireballs.append([new_i, new_j, mm, ss, dd])
################# 0, 1, 2, 3, 4
# fireballs[idx][0] = i
# fireballs[idx][1] = j ### ์ด๋ํ ์์น ์ ๋ณด๋ก ์
๋ฐ์ดํธ
continue
m_sum = 0
s_sum = 0
for elem in fire_lt:
mm, ss, dd, idx = elem
m_sum += mm
s_sum += ss
new_m = m_sum // 5
new_s = s_sum // len(fire_lt)
# (์ง๋์ด 0์ธ ํ์ด์ด๋ณผ์ ์๋ฉธ๋์ด ์์ด์ง๋ค.)
if new_m == 0:
continue
# 4๊ฐ์ ํ์ด์ด๋ณผ๋ก ํ์ด๋จ๋ฆฌ๊ธฐ
### 1) ๋ชจ๋ ํ์ ์ด๊ฑฐ๋ 2) ๋ชจ๋ ์ง์์ด๋ฉด
if all( (elem[2]%2 == 1) for elem in fire_lt) == True or all( (elem[2]%2 == 0) for elem in fire_lt) == True:
for new_d in [0, 2, 4, 6]:
fireballs.append([new_i, new_j, new_m, new_s, new_d])
else:
for new_d in [1, 3, 5, 7]:
fireballs.append([new_i, new_j, new_m, new_s, new_d])
before_fireballs = fireballs[:] # ๋ฐฐ์ด ์ ๋ณด ์
๋ฐ์ดํธ
# ๋จ์ ์๋ ํ์ด์ด๋ณผ์ ์ง๋์ ํฉ ๊ณ์ฐ
score = 0
for elem in fireballs:
score += elem[2]
print(score)