# Fun fact
Tetris was the first video game played in outer space

In 1993, Russian cosmonaut Aleksandr A. Serebrov spent 196 days on the Mir space station with a very special distraction: a gray Game Boy loaded with Tetris. During that time the game orbited the Earth 3,000 times and became the first video game played in space. The Game Boy was sold in a Bonhams auction for $1,220 during the Space History Sale in 2011.

# Task
Parse the game log and determine how many lines have been cleared through the game. The game ends if all commands from input were interpreted or the maximum field height (30 units) is reached.

A horizontal line, according to the rules of classic Tetris, is considered cleared if it represents a solid line without gaps formed by falling blocks.
When such a line is formed, it disappears and any blocks above it fall down to fill the space.

# Input
```python
['4L2', '3R4', '4L3', '3L4', '4R0', '1L2'] # example
```
As an argument, you are given gamelog - an array of commands which you need to interpret.

Each command has the same form:
* The first character - the type of block (integer from 1 to 4, as in this kata we have only 4 types of blocks). Block types are described below.
* The second - the direction of movement (`"R"` or `"L"` - right or left).
* The third is an offset (integer from 0 to 4, as width of our field 9 units and new block always appears at the center of the field) relative to the starting position. Thus, `L4` means the leftmost position, and `R4` the rightmost, and `L0` is equivalent to `R0`.

# Output
The total number of cleaned horizontal lines (`int`) to the end of the game. Note, if the field height is exceeded, then the game ends immediately.

# Blocks
In this kata we have only 4 types of blocks. Yes, this is not a classic set of shapes, but this is only for simplicity.
```
# and their graphical representation:
             ■
         ■   ■
     ■   ■   ■
 ■   ■   ■   ■
---+---+---+---
#1  #2  #3  #4
```
# Field
Gamefield (a rectangular vertical shaft) has width 9 units and height 30 units.


table, th, td {
  border: 1px solid;
}


Indices can be represented as:


L4
L3
L2
L1
L0/R0
R1
R2
R3
R4



# Example 1
```python
>>> gamelog = ['1R4', '2L3', '3L2', '4L1', '1L0', '2R1', '3R2', '4R3', '1L4']
>>> tetris(gamelog)
1
```
Gamefield before last command (_ means empty space):
```
___■___■_
__■■__■■_
_■■■_■■■_
_■■■■■■■■
```
Gamefield after all commands:
```
___■___■_
__■■__■■_
_■■■_■■■_
```
As you can see, one solid line was cleared. So, answer is 1.

# Example 2
```python
>>> gamelog = ['1L2', '4R2', '3L3', '3L1', '1L4', '1R4']
>>> tetris(gamelog)
0
```
Gamefield after all commands:
```
 _____■__
_■_■__■__
_■_■__■__
■■■■__■_■
```
As you can see, there is no solid lines, so nothing to clear. Our answer is 0, zero cleaned lines.

# Note

Since there is no rotation of blocks in our model and all blocks are very simple, do not overthink the task.

# Other  

If you like the idea: leave feedback, and there will be more katas in the Tetris series.

* 7 kyuTetris Series #1 — Scoring System
* 6 kyuTetris Series #2 — Primitive Gameplay
* 6 kyuTetris Series #3 — Adding Rotation (TBA)
* 5 kyuTetris Series #4 — New Block Types (TBA)
* 4 kyuTetris Series #5 — Complex Block Types (TBA?)

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "class Game():\n\n    def __init__(self, arr):\n        self.comands = arr\n        self.score   = 0\n        self.step    = None\n        self.fild    = [-1]*9 \n        self.over    = lambda x:max(x)>=29\n        \n    def __break__(self):\n        while -1 not in self.fild:\n            self.score +=1\n            self.fild  = [ e-1 for e in self.fild ]\n        return self.over(self.fild)\n        \n    def __values__(self, comand):\n        self.step = 4 + {'R':lambda m: +int(m), \n                         'L':lambda m: -int(m)}[comand[1]](comand[2])\n        return int(comand[0])\n\n    def game(self):\n        for comand in self.comands:\n            block = self.__values__(comand)\n            self.fild[self.step] += block\n            if self.__break__(): \n                break\n        return self.score\n        \ndef tetris(arr) -> int:\n    play = Game(arr)\n    return play.game()\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'tetris'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 7130