# Story

Well, here I am stuck in another traffic jam.


*Damn all those courteous people!*

Cars are trying to enter the main road from side-streets somewhere ahead of me and people keep letting them cut in.

Each time somebody is let in the effect ripples back down the road, so pretty soon I am not moving at all.

(Sigh... late again...)



## Visually

The diagram below shows lots of cars all attempting to go North.
* the `a`,`b`,`c`... cars are on the main road with me (`X`)
* the `B` cars and `C` cars are merging from side streets



          |  a  |   
          |  b  | ↑  
  --------+  c  |  
     BBBBBB  d  |   
  --------+  e  |  
          |  f  | ↑
          |  g  |   
  --------+  h  |
      CCCCC  i  |
  --------+  j  | ↑
          |  k  |
          |  l  |
          |  m  |
          |  X  | 
           


This can be represented as

* `mainRoad` = `"abcdefghijklmX"`
* `sideStreets` = `["","","","BBBBBB","","","","","CCCCC"]`

# Kata Task

Assume every car on the main road will "give way" to 1 car entering from each side street.

Return a string representing the cars (up to and including me) in the order they exit off the top of the diagram.

## Notes

* My car is the only `X`, and I am always on the main road
* Other cars may be any alpha-numeric character (except `X` of course)
* There are no "gaps" between cars
* Assume side streets are always on the left (as in the diagram)
* The `sideStreets` array length may vary but is never more than the length of the main road
* A pre-loaded `Util.display(mainRoad,sideStreets)` method is provided which may help to visualise the data
 * (Util.Display for C#)

## Example
Here are the first few iterations of my example, showing that I am hardly moving at all...


InitialIter 1Iter 2Iter 3Iter 4Iter 5Iter 6Iter 7



      a   
      b
      c  
BBBBBBd   
      e  
      f
      g   
      h
 CCCCCi
      j
      k
      l
      m
      X 



      b   
      c
      d 
 BBBBBB   
      e  
      f
      g   
      h
 CCCCCi
      j
      k
      l
      m
      X



      c   
      d
      B
 BBBBBe
      f  
      g
      h   
      i
  CCCCC
      j
      k
      l
      m
      X



       d
       B
       e
   BBBBB
       f
       g
       h
       i
   CCCCC
       j
       k
       l
       m
       X



     B
     e
     B
 BBBBf
     g
     h
     i
     C
 CCCCj
     k
     l
     m
     X
    



     e
     B
     f
  BBBB
     g
     h
     i
     C
 CCCCj
     k
     l
     m
     X




     B
     f
     B
  BBBg
     h
     i
     C
     j
  CCCC
     k
     l
     m
     X




     f
     B
     g
   BBB
     h
     i
     C
     j
  CCCC
     k
     l
     m
     X





:-) 

DM

```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 = "def traffic_jam(m,S):\n    M=list(m)\n    for i in range(len(S))[::-1]:\n        R=sum(zip(M[i:],S[i][::-1]),())\n        M[i:]=list(R)+M[i+len(R)//2:]\n    return''.join(M)[:M.index('X')+1]"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'traffic_jam'
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: 8160