In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.

We will consider an extremely simplified subset of Python with only two types of statements.

Simple statements are written in a single line, one per line. An example of a simple statement is assignment.

For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.

You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.


-----Input-----

The first line contains a single integer N (1 ≤ N ≤ 5000) — the number of commands in the program. N lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.


-----Output-----

Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 10^9 + 7. 


-----Examples-----
Input
4
s
f
f
s

Output
1

Input
4
f
s
f
s

Output
2



-----Note-----

In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.

simple statement

for statement

    for statement

        simple statement



In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.

for statement

    simple statement

    for statement

        simple statement



or

for statement

    simple statement

for statement

    simple statement

Difficulty: interview

Starter code:

Solutions:
n = int(input())
dp = [0] * (n + 1)
maxlev = 0
mod = 1000000007
lst = "s"
dp[0] = 1
for i in range(n):
  s = input()
  if lst == "f":
    for j in reversed(range(1, maxlev+2)):
      dp[j] = dp[j-1]
    maxlev += 1
    dp[0] = 0
  else:
    sum = 0
    for j in reversed(range(0, maxlev+1)):
      sum = (sum + dp[j]) % mod
      dp[j] = sum
  lst = s
res = 0
for i in range(0, maxlev + 1):
  res = (res + dp[i]) % mod
print(res)

n = int(input())

MODULO = 10 ** 9 + 7
i = 0
dp = [[0 for i in range(n + 2)] for j in range(n + 2)]
dp[0][0] = 1

new_array = [0] * (n + 2)
old_array = [0] * (n + 2)
new_array[0] = 1

for i in range(n):
    c = input()[0]
    old_array = new_array
    new_array = [0] * (n + 2)
    if c == 'f':
        for j in range(n):
            new_array[j + 1] = old_array[j]
    else:
        j = i + 1
        tmp = 0
        while j >= 0:
            tmp = (tmp + old_array[j]) % MODULO
            new_array[j] = tmp % MODULO
            j -= 1
    #print(old_array)

tmp = 0



for i in range(n):
    tmp = (tmp + old_array[i]) % MODULO
print(tmp)


import sys
sys.setrecursionlimit(1000000)
read = sys.stdin.readline

MOD = 1000000007

N = int(read())
sts = [read().strip() for _ in range(N)]

ind = [0 for _ in range(N)]
ind[0] = 1
indent = 0
last = 'f'
for st in sts:
    if last != 'f':
        for i in range(indent, -1, -1):
            ind[i] += ind[i+1]
            ind[i] %= MOD
    if st == 'f':
        indent += 1
        for i in range(indent, 0, -1):
            ind[i] += ind[i-1]
            ind[i-1] = 0
    last = st
    # print(ind)

ans = 0
for i in range(indent+1):
    ans += ind[i]
    ans %= MOD
print(ans)

n = int(input())
a = [input() for _ in range(n)]

MOD = int(1e9+7)
const = 5001
levels = [0]*const
levels[0] = 1

for i in range(n-1):
    if a[i]=='f':
        for j in range(const-2,-1,-1):
            levels[j+1]=levels[j]
        levels[0]=0
    else:
        cumsum = 0
        for j in range(const-1,-1,-1):
            cumsum += levels[j]
            cumsum%=MOD
            levels[j]=cumsum
print(sum(levels)%MOD)


# standard library# {{{
import sys
import time
import re
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
# }}}

# input
N = int(input())

def solve():
    A = []
    for n in range(N):
        A.append(input())

    dp = [[0]*(N+1) for n in range(N+1)]
    dp[0][0] = 1
    pre_a = A[0]
    for i, a in enumerate(A):
        if i == 0: continue
        # print(i, pre_a, a)
        if pre_a == 'f':
            for j in reversed(list(range(i+1))):
                dp[i][j] = dp[i-1][j-1]
        else:
            s = 0
            for j in reversed(list(range(i))):
                s += dp[i-1][j]
                s %= mod
                dp[i][j] = s

        pre_a = a
        # print(np.array(dp))

    res = 0
    for v in dp[N-1]:
        res += v
        res = res % mod
    print(res)

def __starting_point():
    solve()


__starting_point()

n=int(input())
L=[0]*5000
L[0]=1
f=1
for i in range(n) :
    C=input()
    if C=='f' :
        f=f+1
    else :
        for j in range(1,f) :
            L[j]=(L[j]+L[j-1])%1000000007
print(L[f-1])
        
            
        
    


from sys import stdin, stdout

n = int(stdin.readline())
dp = [[0 for i in range(n + 10)] for j in range(n + 10)]

MOD = 10 ** 9 + 7
dp[-1][0] = 1
previous = []

for i in range(n):
    s = stdin.readline().strip()
    
    if not previous or previous[-1] != 'f':
        cnt = 0
            
        for j in range(n, -1, -1):
            cnt = (cnt + dp[i - 1][j]) % MOD
            dp[i][j] = cnt
    else:
        cnt = 0
            
        for j in range(n + 1, -1, -1):
            cnt = dp[i - 1][j - 1]
            dp[i][j] = cnt
    
    previous.append(s)

ans = 0
for i in range(n + 1):
    ans = (ans + dp[n - 1][i]) % MOD

stdout.write(str(ans))

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# read = lambda: map(int, input().split())


L = int(1e9 + 7)
N = int(input())
dp = [0 for _ in range(N)]
dp[0] = 1
index = 0
for _ in range(N):
    s = input()
    if s == 'f':
        index += 1
    if s == 's':
        for i in range(1, index + 1):
            dp[i] = (dp[i - 1] + dp[i]) % L
print(dp[index])


n=int(input())
L=[0]*5000
L[0]=1
f=1
for i in range(n) :
    C=input()
    if C=='f' :
        f=f+1
    else :
        for j in range(1,f) :
            L[j]=(L[j]+L[j-1])%1000000007
print(L[f-1])

n = int(input())

ar = []

dp = [0] * 5005
cum = [0] * 5005

mod = int( 1e9 + 7 )

for i in range( n ):
        s = input()
        ar.append( s )
        
for i in range( 5000 ):
        dp[i] = 1
        cum[i] = dp[i] + ( cum[i - 1] if i > 0 else 0 )
        cum[i] = cum[i] - mod if cum[i] >= mod else cum[i]
        
for i in range( n -  2, -1, - 1 ):
        for j in range( 5000 ):
                dp[j] = dp[j + 1] if ar[i] == "f" else cum[j]
                dp[j] = dp[j] - mod if dp[j] >= mod else dp[j]
                cum[j] = dp[j] + ( cum[j - 1] if j > 0 else 0 )
                cum[j] = cum[j] - mod if cum[j] >= mod else cum[j]

print( dp[0] )

n = int(input())
a = [1]
flag = False
for i in range(n):
    if flag:
        a.append(0)
        flag = False
    else:
        s = 0
        for i in range(len(a)):
            t = a[i]
            a[i] += s
            s += t
            a[i] %= 10**9 + 7
            s %= 10**9 + 7
    if input() == 'f':
        flag = True

##    print(a)
print(sum(a) % (10**9 + 7))
    


n = int(input())
dp = [1]
for IND in range(n):
    c = input()
    if c == "f":
        dp.insert(0,0)
    else:
        for i in range(len(dp)-2, -1, -1): dp[i] = (dp[i] + dp[i+1]) % 1000000007
print(dp[0])

MOD=int(1e9+7)
n=int(input())
a=[]
for i in range(n):
    a.append(input())
a="".join(a)
dp,s=[],[]
for i in range(n+1):
    dp.append([0]*(n+1))
    s.append([0]*(n+1))
dp[0][0]=1
s[0][0]=1
for i in range(1,n):
    for j in range(0,n):
        if a[i-1]=='f':
            dp[i][j+1]=dp[i-1][j]%MOD
        elif a[i-1]=='s':
            dp[i][j]=s[i-1][j]%MOD
    
    for j in reversed(list(range(n))):
        s[i][j]+=(dp[i][j]+s[i][j+1])%MOD
print(s[n-1][0]%MOD)
#sum from all levels



import sys
input = sys.stdin.readlines()
n = int(input[0].strip())
m = 10**9 + 7
curr = [0] * (n+20)
last = [0] * (n+20)
curr[0] = 1
for s in range(1,n):
    last, curr = curr, last
    if input[s]=='f\n':
        curr[0] = 0
        for i in range(len(last)-1):
            curr[i+1] = last[i]
    elif input[s]=='s\n':
        curr[-1] = 0
        for i in range(len(last)-2, -1, -1):
            curr[i] = (curr[i+1] + last[i]) % m
s = 0
for x in curr:
    s = (s + x) % m
print(s)

def add(a,b):
	a = a%(1000000000+7)
	b=b%(1000000000+7)
	return (a+b)%(1000000000+7)



n  =int(input())
i=1
statements = []
dp = [[0 for i in range(n)] for i in range(n)]
prefix = [[0 for i in range(n)] for i in range(n)]
while(i<=n):
	s = input()
	statements.append(s)
	i+=1

dp[0][0]=1
prefix[0][0]=1
j=1
while(j<n):
	dp[0][j]=0
	prefix[0][j] = dp[0][j] + prefix[0][j-1]
	j+=1

i=1
while(i<n):
	if(statements[i-1]=='f'):
		j=1
		while(j<n):
			dp[i][0]=0
			prefix[i][0]=0
			dp[i][j] = dp[i-1][j-1]
			prefix[i][j] = add(prefix[i][j-1],dp[i][j])

			j+=1
	else:
		j=0
		while(j<n):
			if(j==0):
				dp[i][j] = prefix[i-1][n-1]
			else:
				dp[i][j] = prefix[i-1][n-1] - prefix[i-1][j-1]
			prefix[i][j] = add(prefix[i][j-1],dp[i][j])
			j+=1
	# print(prefix)
	i+=1

# i=0
# while(i<n):
# 	j=0
# 	while(j<n):
# 		print(dp[i][j])
# 		j+=1
# 	i+=1

# print(dp)

ans = 0
j=0
while(j<n):
	ans=add(ans,dp[n-1][j])
	j+=1

print(ans%(1000000000+7))



def add(x,j):
	x = x % (1000000000+7)
	j=j % (1000000000+7)
	return (x+j) % (1000000000+7)

statements = []
n  =int(input())
i=1
j=1
temp = [[0 for i in range(n)] for i in range(n)]
earlier = [[0 for i in range(n)] for i in range(n)]
temp[0][0]=1
earlier[0][0]=1

while(i<=n):
	s = input()
	statements.append(s)
	i+=1
while(j<n):
	temp[0][j]=0
	earlier[0][j] = temp[0][j] + earlier[0][j-1]
	j+=1
i=1
while(i<n):
	if(statements[i-1]=='f'):
		j=1
		while(j<n):
			temp[i][0]=0
			earlier[i][0]=0
			temp[i][j] = temp[i-1][j-1]
			earlier[i][j] = add(earlier[i][j-1],temp[i][j])

			j+=1
	else:
		j=0
		while(j<n):
			if(j==0):
				temp[i][j] = earlier[i-1][n-1]
			else:
				temp[i][j] = earlier[i-1][n-1] - earlier[i-1][j-1]
			earlier[i][j] = add(earlier[i][j-1],temp[i][j])
			j+=1
	i+=1

ans = 0
j=0
while(j<n):
	ans=add(ans,temp[n-1][j])
	j+=1

print(ans%(1000000000+7))

n = int(input())
dp = [1]
for IND in range(n):
    c = input()
    if c == "f":
        dp.insert(0,0)
    else:
        for i in range(len(dp)-2, -1, -1): dp[i] = (dp[i] + dp[i+1]) % 1000000007
print(dp[0])

n = int(input())
dp = [1]
for IND in range(n):
    c = input()
    if c == "f":
        dp.insert(0,0)
    else:
        for i in range(len(dp)-2, -1, -1): dp[i] = (dp[i] + dp[i+1]) % 1000000007
print(dp[0])


n = int(input())
A = []

for i in range(n):
    x = input()
    A.append(x)

dp = [[0 for i in range(n+1)] for j in range(n+1)]

mod = 10**9 + 7

for i in range(n+1):
    dp[n-1][i] = 1

for line in range(n-2, -1, -1):
    sum = 0
    if A[line]=='s':
        for indent in range(n):
            sum = (sum + dp[line+1][indent])%mod
            dp[line][indent] = sum
    else:
        for indent in range(n):
            dp[line][indent] = dp[line+1][indent+1]

    
print(dp[0][0])
            


n = int(input())
dp = [1]
for i in range(n):
    c = input()
    if c == "f":
        dp.insert(0,0)
    else:
        for j in range(len(dp) - 2, -1, -1):
            dp[j] = (dp[j] + dp[j + 1]) % 1000000007
print(dp[0])


# DP 1

# n = int(input())
# dp = [1]
# for i in range(n):
#     c = input()
#     if c == "f":
#         dp.insert(0,0)
#     else:
#         for j in range(len(dp) - 2, -1, -1):
#             dp[j] = (dp[j] + dp[j + 1]) % 1000000007
#     print(dp)
# print(dp[0])

n = int(input())
dp = [1]
for i in range(n):
    c = input()
    if c == "f":
        dp.append(0)
    else:
        for j in range(1, len(dp)):
            dp[j] = (dp[j] + dp[j - 1]) % 1000000007
print(dp[-1])


n = int(input())
dp = [0] * 5000
MOD = 10 ** 9 + 7
f = 1
dp[0] = 1
for i in range(n):
    a = input()
    if a == "f":
        f += 1
    else:
        for j in range(1, f):
            dp[j] = dp[j] + dp[j - 1]
            dp[j] %= MOD

print(dp[f - 1])

def solve():
    rd = lambda : list(map(int, input().split()))
    n = int(input())
    p = []
    for i in range(n):
        p.append(input())
    dp = [0 for i in range(n)]
    dp[0] = 1
    indent = 0
    L = int(1e9 + 7)
    for i, val in enumerate(p):
        if val == 'f':
            indent += 1
        else:
            for j in range(1, indent + 1):
                dp[j] = (dp[j - 1] + dp[j]) % L
    print(dp[indent])

solve()

from sys import stdout

m = int(1e9 + 7)
n = int(input())
a = [0]*n
a[0] = 1
k = 0
for _ in range(n):
  s = input()  
  if s == "f":
    k += 1
  elif s == "s":
    for j in range(1, k+1):
      a[j] = (a[j-1]+a[j])%m
print(a[k])


MOD = 1000000007

n = int(input())
p = ''.join([input() for _ in range(n)])

dp = [[0] * 5005 for _ in range(n + 1)]
dp[0][0] = 1

i = 1
for c in p:
    if c == 'f':
        for j in range(n - 1, -1, -1):
            dp[i][j] = dp[i - 1][j - 1] if j - 1 >= 0 else 0
    else:
        for j in range(n - 1, -1, -1):
            dp[i][j] = (dp[i - 1][j] + dp[i][j + 1]) % MOD
    i += 1

print(dp[n][0] % MOD)