anchor.diff:  -module(main).
   -export([main/1]).
  --import(string,[concat/2,copies/2]).
  +-import(string,[copies/2,concat/2,tokens/2]).
  +-import(io,[get_chars/2,format/2]).
  +-import(lists,[reverse/1]).
  +-import(init,[stop/0]).
   
   main(_) ->
  -    io:format("~s",[palindrome(getwords())]),
  +    [N|W] = tokens(get_chars("",20000)," \n"),
  +    format("~s",[solve(W)]),
       halt().
   
  -palindrome(W) -> palindrome(map_data(mapping(W)),"","","").
  -palindrome([{W,{N,symmetry}}|T], L, C, R) ->
  -    NC = if (N rem 2 == 1) and ((C == "") or (W < C)) -> W; true -> C end,
  -    P = copies(W, N div 2),
  -    palindrome(T, concat(L, P), NC, concat(P, R));
  -palindrome([{_,{N,_}}|T], L, C, R) when N < 2 ->
  -    palindrome(T, L, C,R);
  -palindrome([{W,{N,WR}}|T], L, C, R) ->
  -    P = copies(W, N div 2),
  -    PR = copies(WR, N div 2),
  -    palindrome(T, concat(L, P), C, concat(PR, R));
  -palindrome([], L, C, R) -> concat(L, concat(C, R)).
  -    
  +solve(W) ->
  +    M = mapping(W),
  +    palindrome(M, map_data(M)).
  +
  +palindrome(M, W) -> palindrome(M, W, "", "", "").
  +
  +palindrome(_, [], L, C, R) -> concat(L, concat(C, R));
  +palindrome(M, [{H, V}|T], L, C, R) ->
  +    HR = reverse(H),
  +    case comp(H, HR) of
  +        gt -> palindrome(M, T, L, C, R);
  +        eq -> NC = if (V rem 2 == 1) andalso (C == "") -> H; true -> C end,
  +              P = copies(H, V div 2),
  +              palindrome(M, T, concat(L, P), NC, concat(P, R));
  +        lt -> case map_get(HR, M) of
  +                  nothing -> palindrome(M, T, L, C, R);
  +                  {ok, U} -> X = if V < U -> V; true -> U end,
  +                             P = copies(H, X),
  +                             PR = copies(HR, X),
  +                             palindrome(M, T, concat(L, P), C, concat(PR, R))
  +              end
  +    end.
   
   mapping(W) -> mapping(W, map_new()).
   mapping([], M) -> M;
   mapping([H|T], M) ->
  -    R = lists:reverse(H),
  -    {K, KR} = case comp(H, R) of
  -            eq -> {H, symmetry};
  -            lt -> {H, R};
  -            gt -> {R, H}
  -        end,
  -    X = case map_get(K,M) of
  -            {ok, {V, _}} -> V + 1;
  +    X = case map_get(H,M) of
  +            {ok, V} -> V + 1;
               nothing -> 1
           end,
  -    mapping(T, map_put(K,{X, KR},M)).
  +    mapping(T, map_put(H, X, M)).
  +
  +%===========================================
  +% 以下はマップ実装部(AVL木による実装)
  +%===========================================
  +% キーはリスト(文字列)限定
  +% 値は何でもOK
  +% 機能は空マップ生成、キーによる値の配置と参照、
  +% および全データの取得のみ
  +%  空マップ生成 map_new()
  +%  配置         map_put( key, value, map )
  +%  参照         map_get( key, map )
  +%  全データ取得 map_data( map )
   
   comp([],[]) -> eq;
   comp(_,[]) -> gt;
  
positive.code:     case LD - RD of
          X when X > 1 ->
              {_, KVL, LL, RL, _} = L,
              {map, KVL, LL, {map, KV, RL, R, RD + 1}, LD};
          Y when Y < -1 ->
              {_, KVR, LR, RR, _} = R,
              {map, KVR, {map, KV, L, LR, LD + 1}, RR, RD};
          _Else ->
              D = if LD > RD -> LD; true -> RD end,
              {map, KV, L, R, D + 1}
  
negative.code: 
  map_new() -> emptymap.
  
  map_get(FK, {map, {K,V}, L, R, D}) ->
      case comp(FK, K) of
          eq -> {ok, V};
          lt -> map_get(FK, L);
  