Problem:


 0 から 9 までの数字だけで構成された文字列が与えられたとき,その文字列から次の規則に従って新しい文字列を作る操作を考える.与えられた文字列を左端から1文字ずつ順に読んで行き,同じ数字 a が r 個続いていた場合,個数 r と数字a を空白で区切らずにこの順で書き出す.与えられた文字列の右端まで読み,最後の書き出しが終わったところまでを途中何回書き出しがあったとしても全部まとめて操作1回とカウントする.2回目以降の操作は前回の操作により書き出された文字列を与えられた文字列として同様の操作を実施する.例えば “122244” という文字列が与えられた場合には左端から順に1個の1, 3個の2,2個の4なのでこの操作1回で得られる文字列は “113224” であり,“44444444444” (11 個の4)の場合には得られる文字列は “114” となる.

  100 文字以下の与えられた文字列に上の操作を n 回実施した文字列を出力するプログラムを作成せよ.ただし, n ≤ 20 とする.

n, 2 行目に最初の文字列が書かれている.

  出力ファイルのファイル名は “output.txt” である.“output.txt” は 1 行であり, 指定された回数の操作を施した文字列の後に改行を入れること.

-->

  入力データ は 2 行からなり,1 行目に操作回数 n, 2 行目に最初の文字列が書かれている.

 

  入力例
 

  5

11

  　

  出力例

13112221

入力

入力は複数のデータセットからなる．n が 0 のとき入力が終了する．データセットの数は 5 を超えない．

出力

データセットごとに、指定された回数の操作を施した文字列 を１行に出力する．

入力例

5
11
5
11
0

出力例

13112221
13112221

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
5
11
5
11
0


Sample output:
13112221
13112221

Submission status: Wrong Answer

Solution code:

nexts="122244"
nexts="11"

n=int(input())
nexts=input()
nexts=list(nexts)
for n in range(5):
    ss=nexts
    nexts=[]
    ss.append(-11)
    k=1
    for i in range(1,len(ss)):
        if ss[i]!=ss[i-1]:
            nexts.append(str(k))
            nexts.append(ss[i-1])
            k=1
            continue
        k+=1

print("".join(nexts))

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
s=[[]*n for _ in xrange(n+1)]
en=raw_input()
for i in en:
    s[0].append(i)
for j in xrange(n):
    cnt=1
    for i in xrange(len(s[j])):
        if i==len(s[j])-1:
            s[j+1].append(str(cnt))
            s[j+1].append(s[j][i])
            break
        if s[j][i]==s[j][i+1]:
            cnt+=1
        else:
            s[j+1].append(str(cnt))
            s[j+1].append(s[j][i])
            cnt=1
print("".join(s[n]))

Submission status: Wrong Answer

Solution code:
while 1:
    n=int(raw_input())
    if n==0:break
    else:
        s=[[]*n for _ in xrange(n+1)]
        en=raw_input()
        for i in en:
            s[0].append(i)
        for j in xrange(n):
            cnt=1
            for i in xrange(len(s[j])):
                if i==len(s[j])-1:
                    s[j+1].append(str(cnt))
                    s[j+1].append(s[j][i])
                    break
                if s[j][i]==s[j][i+1]:
                    cnt+=1
                else:
                    s[j+1].append(str(cnt))
                    s[j+1].append(s[j][i])
                    cnt=1
        print("".join(s[n]))

Submission status: Wrong Answer

Solution code:
while 1:
    n=int(raw_input())
    if n==0:break
    else:
        s=[[]*n for _ in xrange(n+1)]
        en=raw_input()
        for i in en:
            s[0].append(i)
        for j in xrange(n):
            cnt=1
            for i in xrange(len(s[j])):
                if i==len(s[j])-1:
                    s[j+1].append(str(cnt))
                    s[j+1].append(s[j][i])
                    break
                if s[j][i]==s[j][i+1]:
                    cnt+=1
                else:
                    s[j+1].append(str(cnt))
                    s[j+1].append(s[j][i])
                    cnt=1
        print(''.join(s[n]))

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
if n==0:exit()
s=raw_input()
for i in xrange(n):
    news=""
    cnt=1
    for j in xrange(len(s)-1):
        if s[j]==s[j+1]:
            cnt+=1
        else:
            news+=str(cnt)+s[j]
            cnt=1
    news+=str(cnt)+s[-1]
print(s)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def solve(li):
    cnt = 1
    ans = []
    for i in range(len(li)-1):
        tar = int(li[i])
        if tar==int(li[i+1]):
            cnt+=1
        else:
            ans.append(cnt)
            ans.append(tar)
            cnt = 1
    tar = int(li[i+1])
    ans.append(cnt)
    ans.append(tar)
    return ans

while True:
    n = int(input())
    if n ==0: break
    a = input()
    la = list(a)
    i=0
    while i<n:
        la = solve(la)
        i+=1
    for x in la:
        print(x, end='')
    print()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def solve(li):
    cnt = 1
    ans = []
    for i in range(len(li)-1):
        tar = int(li[i])
        if tar==int(li[i+1]):
            cnt+=1
        else:
            ans.append(cnt)
            ans.append(tar)
            cnt = 1
    tar = int(li[i+1])
    ans.append(cnt)
    ans.append(tar)
    return ans

while True:
    n = int(input())
    if n ==0: break
    a = input()
    la = list(a)
    i=0
    while i<n:
        la = solve(la)
        i+=1
    for x in la:
        print(x, end='')
    print() 
    
print()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def solve(li):
    cnt = 1
    ans = []
    for i in range(len(li)-1):
        tar = int(li[i])
        if tar==int(li[i+1]):
            if cnt>=10:
                ans.append(cnt//10)
                cnt = cnt%10
            cnt+=1
        else:
            if cnt>=10:
                print('a')
                ans.append(cnt//10)
                ans.append(cnt%10)
            else:
                print('b')
                ans.append(cnt)
            ans.append(tar)
            cnt = 1
    tar = int(li[i+1])
    ans.append(cnt)
    ans.append(tar)
    return ans

while True:
    n = int(input())
    if n ==0: break
    a = input()
    la = list(a)
    i=0
    while i<n:
        la = solve(la)
        i+=1
    for x in la:
        print(x, end='')
    print()

Submission status: Wrong Answer

Solution code:
while True:
  n = int(input())
  if not n:
    break
  ss = [s for s in input()[::-1]]
  for i in range(n):
    new = []
    last = ss.pop()
    count = 1
    while ss:
      a = ss.pop()
      if a == last:
        count += 1
      else:
        new.append(last)
        new.append(str(count))
        last = a
        count = 1
    else:
      new.append(last)
      new.append(str(count))
    ss = [s for s in new[::-1]]
  print("".join(ss))

Submission status: Wrong Answer

Solution code:
while True:
  n = int(input())
  if not n:
    break
  ss = [s for s in input()[::-1]]
  for i in range(n):
    new = []
    app = new.append
    last = ss.pop()
    count = 1
    while ss:
      a = ss.pop()
      if a == last:
        count += 1
      else:
        app(str(count))
        app(last)
        last = a
        count = 1
    else:
      app(str(count))
      app(last)
    ss = [s for s in new[::-1]]
  print("".join(new))

Submission status: Wrong Answer

Solution code:
while True:
  n = int(input())
  if not n:
    break
  ss = [s for s in input()[::-1]]
  for i in range(n):
    new = []
    app = new.append
    last = ss.pop()
    count = 1
    while ss:
      a = ss.pop()
      if a == last:
        count += 1
      else:
        app(str(count))
        app(last)
        last = a
        count = 1

    app(str(count))
    app(last)
    ss = [s for s in new[::-1]]

  print("".join(new))

Submission status: Wrong Answer

Solution code:
while 1:
    n=input()
    if n==0: break
    ar=raw_input()+' '
    for i in range(n):
        print i
        cnt=1
        tmp=''
        for i in range(len(ar)-1):
            if ar[i]==ar[i+1]:
                cnt+=1
            else:
                tmp+="%d%s"%(cnt,ar[i])
                cnt=1
        ar=tmp+' '
    print ar

Submission status: Wrong Answer

Solution code:
while 1:
    n=input()
    if n==0: break
    ar=raw_input()+' '
    for i in range(n):
        print i
        cnt=1
        tmp=''
        for i in range(len(ar)-1):
            if ar[i]==ar[i+1]:
                cnt+=1
            else:
                tmp+="%d%s"%(cnt,ar[i])
                cnt=1
        ar=tmp+' '
    print ar.strip()

Submission status: Wrong Answer

Solution code:
while 1:
    n=input()
    if n==0: break
    ar=raw_input()+' '
    for i in range(n):
        print i
        cnt=1
        tmp=''
        for i in range(len(ar)-1):
            if ar[i]==ar[i+1]:
                cnt+=1
            else:
                tmp+="%d%s"%(cnt,ar[i])
                cnt=1
        ar=tmp+' '
    print ar.rstrip()

Submission status: Wrong Answer

Solution code:
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

def operate(li):
    count = 0
    prev = 0
    ret = []
    for i in xrange(len(li)):
        if i == 0 or li[i] == prev:
            count += 1
        else:
            ret.append(count)
            ret.append(prev)
            count = 1
        prev = li[i]
    ret.append(count)
    ret.append(li[i])
    print ret
    return ret
            

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    orig = map(int, list(fp.readline()[:-1]))

    for i in xrange(n):
        orig = operate(orig)

    print "".join(map(str, orig))

Submission status: Accepted

Solution code:
def rename(st):
    letnow=st[0]
    letnum=0
    retst=""
    for letter in range(len(st)):
        if letnow==st[letter]:
            letnum=letnum+1
        else:
            retst=retst+str(letnum)+letnow
            letnow=st[letter]
            letnum=1
    retst=retst+str(letnum)+letnow
    return retst

while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        st=raw_input() #type str
        for i in range(n):
            st=rename(st)
        print st

Submission status: Accepted

Solution code:
while True:
    n = raw_input(); n = int(n);
    if n==0: break
    s = raw_input()
    for i in range(n):
        ns = ""
        cnt = 1
        for j in range(len(s)-1):
            if s[j+1]==s[j]: cnt += 1
            else:
                ns += str(cnt) + s[j]
                cnt = 1
        ns += str(cnt) + s[len(s)-1]
        s = ns
    print s

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if not n:
        break
    s = input().strip()

    while n:
        prev, cnt, new = s[0], 1, ''
        for c in s[1:]:
            if c == prev:
                cnt += 1
            else:
                new += str(cnt) + prev
                prev, cnt = c, 1
        new += str(cnt) + prev
        s = new
        n -= 1
    print(s)

Submission status: Accepted

Solution code:
def f(a,n):
    for j in range(n):
        aa = ""
        s = a[0]
        c = 1
        for i in range(1,len(a)):
            if a[i] == s:
                c += 1
            else:
                aa += str(c) + s
                s = a[i]
                c = 1
        a = aa + str(c) + s
    return a
     
while 1:
    n = input()
    if n == 0: break
    a = raw_input()
    print f(a,n)

Submission status: Accepted

Solution code:
while 1:
    n=int(raw_input())
    if n==0:break
    s=raw_input()
    for i in xrange(n):
        news=""
        cnt=1
        for j in xrange(len(s)-1):
            if s[j]==s[j+1]:
                cnt+=1
            else:
                news+=str(cnt)+s[j]
                cnt=1
        news+=str(cnt)+s[-1]
        s=news
    print(s)

Submission status: Accepted

Solution code:
def compress(digits):
  compressed_list = list()
  for digit in digits:
    if compressed_list == [] or compressed_list[-1][1] != digit:
      compressed_list.append([1, digit])
    else:
      compressed_list[-1][0] += 1

  return compressed_list


def decompress(compressed_list):
  new_digits = ""
  for pair in compressed_list:
    new_digits += "{}{}".format(*pair)

  return new_digits


while 1:
  proc_num = int(input())
  if proc_num == 0:
    break
  digits = input().strip()

  for i in range(proc_num):
    compressed_list = compress(digits)
    digits = decompress(compressed_list)
  print(digits)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:break
    s = input()

    for _ in range(n):
        i, cnt = 0, 1
        pre=s[i]
        tmp=""
        while i+1<len(s):
            while i+1<len(s) and pre==s[i+1]: cnt, i = cnt+1, i+1
            tmp += str(cnt)+pre
            cnt=0
            if i+1!=len(s): pre=s[i+1]
        s = tmp
    print(s)

Submission status: Accepted

Solution code:
# coding: utf-8
def solve(li):
    cnt = 1
    ans = []
    for i in range(len(li)-1):
        tar = int(li[i])
        if tar==int(li[i+1]):
            if cnt>=10:
                ans.append(cnt//10)
                cnt = cnt%10
            cnt+=1
        else:
            if cnt>=10:
                ans.append(cnt//10)
                ans.append(cnt%10)
            else:
                ans.append(cnt)
            ans.append(tar)
            cnt = 1
    tar = int(li[i+1])
    ans.append(cnt)
    ans.append(tar)
    return ans

while True:
    n = int(input())
    if n ==0: break
    a = input()
    la = list(a)
    i=0
    while i<n:
        la = solve(la)
        i+=1
    for x in la:
        print(x, end='')
    print()

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:break
    s=input()
    conv=""
    for _ in range(n):
        seq=1
        pr=s[0]
        for i in range(1,len(s)):
            if pr==s[i]:seq+=1
            else:
                conv+=str(seq)+pr
                pr=s[i]
                seq=1
        conv+=str(seq)+pr
        s=conv
        conv=""
    print(s)

Submission status: Accepted

Solution code:
# coding: utf-8

while True:
	n = int(raw_input())
	if n == 0:
		break
	else:
		char = raw_input()
		for _ in range(n):
			result = ""
			for i in range(len(char)):
#				print("i = {:}".format(i))
				if i == 0:
					c_now = char[0]
					cnt = 1
#					print("** 0 **")
				elif char[i] == c_now:
					cnt += 1
#					print("** 1 **")
				else: #char[i] != c_now
					result += str(cnt) + c_now
#					print(result)
					c_now = char[i]
					cnt = 1
#					print("** 2 **")
			result += str(cnt) + c_now
			char = result
#			print(result)
#			print("###########################")
		print(result)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if not n:
    break
  ss = [s for s in input()[::-1]]
  for i in range(n):
    new = []
    app = new.append
    last = ss.pop()
    count = 1
    while ss:
      a = ss.pop()
      if a == last:
        count += 1
      else:
        app(str(count))
        app(last)
        last = a
        count = 1
    app(str(count))
    app(last)
    new = "".join(new)
    ss = [s for s in new[::-1]]
#    print("".join(new))
  print("".join(new))

Submission status: Accepted

Solution code:
def main():
  while True:
    n = int(input())
    if not n:
      break
    ss = [s for s in input()[::-1]]
    for i in range(n):
      new = []
      app = new.append
      last = ss.pop()
      count = 1
      while ss:
        a = ss.pop()
        if a == last:
          count += 1
        else:
          app(str(count))
          app(last)
          last = a
          count = 1
      app(str(count))
      app(last)
      new = "".join(new)
      ss = [s for s in new[::-1]]
  #    print("".join(new))
    print("".join(new))

main()

Submission status: Accepted

Solution code:
def main():
  while True:
    n = int(input())
    if not n:
      break
    ss = [s for s in reversed(input())]
    for i in range(n):
      new = []
      app = new.append
      last = ss.pop()
      count = 1
      while ss:
        a = ss.pop()
        if a == last:
          count += 1
        else:
          app(str(count))
          app(last)
          last = a
          count = 1
      app(str(count))
      app(last)
      new = "".join(new)
      ss = [s for s in reversed(new)]
    print(new)

main()

Submission status: Accepted

Solution code:
def main():
  while True:
    n = int(input())
    if not n:
      break
    ss = [s for s in input()[::-1]]
    for i in range(n):
      new = []
      ext = new.extend
      last = ss.pop()
      count = 1
      while ss:
        a = ss.pop()
        if a == last:
          count += 1
        else:
          ext([str(count),last])
          last = a
          count = 1
      ext([str(count), last])
      new = "".join(new)
      ss = [s for s in new[::-1]]
    print(new)

main()

Submission status: Accepted

Solution code:
# AOJ 0506: String
# Python3 2018.6.29 bal4u

while True:
	n = int(input())
	if n == 0: break
	s = ['']*2
	s[0] = input().strip()
	for i in range(n):
		k, j = 1, 0
		s[1-(i&1)] = ''
		while True:
			j += 1
			if j == len(s[i&1]):
				if k > 0: s[1-(i&1)] += str(k) + s[i&1][j-1]
				break
			if s[i&1][j] == s[i&1][j-1]: k += 1
			else:
				s[1-(i&1)] += str(k) + s[i&1][j-1]
				k = 1
	print(s[1-(i&1)])

Submission status: Accepted

Solution code:
while 1:
    n=input()
    if n==0:
        break
    s=raw_input()
    for i in range(n):
        cnt=0
        prev=" "
        ns=""
        for c in s:
            if c==prev:
                cnt+=1
            else:
                if prev!=" ":
                    ns+=str(cnt)+prev
                cnt=1
            prev=c
        if prev!=" ":
            ns+=str(cnt)+prev
        cnt=0
        s=ns
    print s

Submission status: Accepted

Solution code:
while 1:
        n = input()
        if n == 0: break
        ns=""
        for i in range(n):
                if i == 0: ns = raw_input()
                temp = ''
                count = 1
                for j in range(len(ns)-1):
                        if ns[j] == ns[j+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[j]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Submission status: Accepted

Solution code:
while 1:
        n = input()
        if n == 0: break
        for j in range(n):
                if j == 0: ns = raw_input()
                temp = ''
                count = 1
                for i in range(len(ns)-1):
                        if ns[i] == ns[i+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[i]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Submission status: Accepted

Solution code:
def op(xs):
    """
    >>> op("122244")
    '113224'
    >>> op("44444444444")
    '114'
    """
    ys = ''
    last = 0
    r = 0
    for i, x in enumerate(xs):
        if xs[last]== x:
            r+=1
        else:
            ys = ys + "%d%s"%(r, xs[last])
            r = 1
            last = i
    ys = ys + "%d%s"%(r, xs[last])
    return ys

def mut(n, xs):
    """
    >>> mut(5, '11')
    '13112221'
    """
    for i in xrange(n):
        xs = op(xs)
    return xs
def chunk(f):
    """
    """
    while True:
        line = f.readline()
        n = line.strip()
        n = int(n)
        if n == 0:
            raise StopIteration
        line = f.readline()
        xs = line.strip()
        yield mut(n, xs)

import sys
for c in chunk(sys.stdin):
    print c

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    s=raw_input()
    for i in range(n):
        t=""
        r=0
        a=s[0]
        for c in s:
            if c==a:
                r+=1
            else:
                t+=str(r)+a
                r=1
                a=c
        t+=str(r)+a
        s=t
    print t

Submission status: Accepted

Solution code:
while 1:
    n=input()
    if n==0: break
    ar=raw_input()+' '
    for i in range(n):
        cnt=1
        tmp=''
        for i in range(len(ar)-1):
            if ar[i]==ar[i+1]:
                cnt+=1
            else:
                tmp+="%d%s"%(cnt,ar[i])
                cnt=1
        ar=tmp+' '
    print ar.rstrip()

Submission status: Accepted

Solution code:
def foo(n):
    ret = ""
    cnt = 1
    for i in range(1, len(n)):
        if n[i - 1] == n[i]:
            cnt += 1
            continue
        else:
            ret += str(cnt) + n[i - 1]
            cnt = 1

    ret += str(cnt) + n[-1]

    return ret


while 1:
    n = input()
    if n == 0:
        break
    m = raw_input().strip()
    for i in range(n):
        m = foo(m)
    print m

Submission status: Accepted

Solution code:
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

def operate(string):
    count = 0
    prev = ""
    ret = ""
    flg = True
    for c in string:
        if flg or c == prev:
            flg = False
            count += 1
        else:
            ret += str(count) + prev
            count = 1
        prev = c
    ret += str(count) + prev
    #print ret
    return ret
            

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    orig = fp.readline()[:-1]

    for i in xrange(n):
        orig = operate(orig)

    print orig

Submission status: Accepted

Solution code:
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

def operate(string):
    count = 1
    prev = string[0]
    ret = ""
    for c in string[1:]:
        if c == prev:
            count += 1
        else:
            ret += str(count) + prev
            count = 1
        prev = c
    ret += str(count) + prev
    #print ret
    return ret
            

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    orig = fp.readline()[:-1]

    for i in xrange(n):
        orig = operate(orig)

    print orig

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    s = raw_input()
    for _ in range(n):
        l = s[0]
        count = 0
        r = ''
        for c in s:
            if c == l:
                count += 1
            else:
                r += str(count) + l
                count = 1
                l = c
        r += str(count) + l
        s = r
    print s

Submission status: Accepted

Solution code:
while 1:
	n=input()
	if n==0:break
	a=raw_input()
	for r in range(n):
		aa=""
		s=a[0]
		count=1
		for i in range(len(a)-1):
			if a[i]==a[i+1]:
				count+=1
			else:
				aa+=str(count)+s
				count=1
				s=a[i+1]
		aa+=str(count)+s
		a=aa
	print a

Submission status: Accepted

Solution code:
def f(a):
	ans = ""
	s = a[0]
	c = 1
	for i in range(1,len(a)):
		if a[i] == s:
			c += 1
		else:
			ans += str(c) + s
			s = a[i]
			c = 1
	ans += str(c) + s
	return ans
	
while 1:
	n = input()
	if n == 0: break
	a = raw_input()
	for i in range(n):
		a = f(a)
	print a

Submission status: Accepted

Solution code:
def f(a,n):
	for j in range(n):
		aa = ""
		s = a[0]
		c = 1
		for i in range(1,len(a)):
			if a[i] == s:
				c += 1
			else:
				aa += str(c) + s
				s = a[i]
				c = 1
		a = aa + str(c) + s
	return a
	
while 1:
	n = input()
	if n == 0: break
	a = raw_input()
	print f(a,n)

Submission status: Accepted

Solution code:
def change(x) :
    i = 0
    ans = []
    while True :
        if i >= len(x) : break
        cnt = 1
        j = 1
        while True :
            if i+j >= len(x) or x[i+j] != x[i] :
                ans = ans + list(str(cnt))
                ans.append(x[i])
                i += cnt
                break
            else :
                cnt += 1
                j += 1
    return ans
    

while True :
    n = int(input())
    if n == 0 :
        break
    
    lst = list(input())

    for i in range(n) :
        lst = change(lst)
    print(*lst, sep='')

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:
        break
    t = input()
    
    for i in range(n):
        s = list(t)
        S = []
        for i in range(len(s)):
            S.append(int(s[i]))
        i = 1
        c = 0
        r = []
        a = [S[0]]
        while True:
            if S[i-1]==S[i]:
                c += 1
            else:
                r.append(c+1)
                a.append(S[i])
                c = 0
            i += 1
            if i==len(S):
                r.append(c+1)
                break
        
        S.clear()
        for j in range(len(r)):
            S.append(str(r[j]))
            S.append(str(a[j]))
        t = ''.join(S)
    
    print(t)

Submission status: Accepted

Solution code:
def convert(s):
    convertStr = ""
    l = len(s)
    i = 0
    while i < l:
        if i + 1 < l:
            word = s[i]
            sequenceNum = 1
            j = i + 1
            while j < l:
                if(word == s[j]):
                    sequenceNum += 1
                else:
                    break
                j += 1
            convertStr += str(sequenceNum) + word
            i = i + sequenceNum - 1
        else:
            convertStr += "1" + str(s[i])
        i += 1
    return convertStr

while True:
    try:
        n = int(input())
        s = input()
        for i in range(0,n):
            s = convert(s)
        print(s)
    except:
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
String
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0506

"""
import sys
import re


def solve(n, s):
    for _ in range(n):
        s = re.sub(r'(\d)\1*', lambda m: f'{len(m.group(0))}{m.group(1)}', s)
    return s


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        s = input()
        ans = solve(n, s)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
def runlen(a):
    n = len(a)
    result = []
    count = 1
    for i in range(n):
        if i == n - 1 or a[i] != a[i + 1]:
            result.append((count, a[i]))
            count = 1
        else:
            count += 1
    return result

def f(s):
    rl = runlen(s)
    result = ""
    for (count, c) in rl:
        result += str(count)
        result += c
    return result

def apply(f, n, x):
    for _ in range(n):
        x = f(x)
    return x

while True:
    n = int(input())
    if n == 0:
        break
    s = input().strip()
    print(apply(f, n, s))

Submission status: Accepted

Solution code:
def change(n):
    x=n[0]
    count=1
    ans=""
    for i in n[1:]:
        if i==x:count+=1
        else:
            ans+=str(count)
            ans+=x
            x=i
            count=1
    ans+=str(count)
    ans+=x
    return(ans)
while 1:
    n=int(input())
    if n==0:break
    word=input()
    for i in range(n):
        word=change(word)
    print(word)

Submission status: Runtime Error

Solution code:
def hoge(numbers):
  count = 1
  answer = []
  prev_number = number[0]
  for i, number in enumerate(numbers):
      if number == numbers[i-1] or count == 0:
        count += 1
      elif number != numbers[i-1]:
        asnwer.append(count)
        answer.append(number)
        count = 0
  return answer

while 1:
  N = input()
  number_list = hoge(map(int, raw_input().split()))
  for n in range(N - 1):
    number_list = hoge(number_list)
  for number in number_list:
    print number,

Submission status: Runtime Error

Solution code:
while 1:
        n = input()
        if n == 0: break
        for i in range(n):
                if i == 0: ns = str(input())
                else: pass
                temp = ''
                count = 1
                for i in range(len(ns)-1):
                        if ns[i] == ns[i+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[i]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Submission status: Runtime Error

Solution code:
while 1:
        n = input()
        if n == 0: break
        for i in range(n):
                if i == 0: ns = str(input())
                temp = ''
                count = 1
                for i in range(len(ns)-1):
                        if ns[i] == ns[i+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[i]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Submission status: Runtime Error

Solution code:
while 1:
        n = input()
        if n == 0: break
        for j in range(n):
                if j == 0: ns = str(input())
                temp = ''
                count = 1
                for i in range(len(ns)-1):
                        if ns[i] == ns[i+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[i]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Submission status: Runtime Error

Solution code:
while 1:
        n = input()
        if n == 0: break
        ns=""
        for i in range(n):
                if i == 0: ns = str(input())
                temp = ''
                count = 1
                for j in range(len(ns)-1):
                        if ns[j] == ns[j+1]:
                                count += 1
                        else:
                                temp += str(count)+ns[j]
                                count = 1
                temp += str(count)+ns[-1]
                ns = temp
        print ns

Submission status: Runtime Error

Solution code:
def foo(n):
    ret = ""
    n = str(n)
    cnt = 1
    for i in range(1, len(n)):
        if n[i - 1] == n[i]:
            cnt += 1
            continue
        else:
            ret += str(cnt) + n[i - 1]
            cnt = 1

    ret += str(cnt) + n[-1]

    return long(ret)


while 1:
    n = input()
    if n == 0:
        break
    m = input()
    for i in range(n):
        m = foo(m)
    print m

Submission status: Runtime Error

Solution code:
import sys

fp = open("input.txt", "r")
#fp = sys.stdin

def operate(string):
    count = 1
    prev = string[0]
    ret = ""
    for c in string[1:]:
        if c == prev:
            count += 1
        else:
            ret += str(count) + prev
            count = 1
        prev = c
    ret += str(count) + prev
    #print ret
    return ret
            

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    orig = fp.readline()[:-1]

    for i in xrange(n):
        orig = operate(orig)

    print orig