def find_road_number(S): current_road = 1 increment = 1 for direction in S: if direction == 'L': current_road += increment else: # direction == 'R' current_road += increment + 1 increment = increment * 2 return current_road # ユーザーからの入力の代わりにテスト文字列を使う S = "RLLRLRLRRRLRL" # 結果を出力 print(find_road_number(S))