import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder standardInput = new StringBuilder();
String line;
while (!(line = sc.nextLine()).equals("EOF")) {
standardInput.append(line).append("\n");
}
StringBuilder actualInput = new StringBuilder();
while (!(line = sc.nextLine()).equals("EOF")) {
actualInput.append(line).append("\n");
}
int time = Integer.parseInt(sc.nextLine());
String expectedText = processWithStack(standardInput.toString());
String userText = processWithStack(actualInput.toString());
int matchCount = countMatchingCharacters(expectedText, userText);
int kpm = (int)(matchCount * 60.0 / time+0.5);
System.out.println(kpm);
}
private static String processWithStack(String input) {
Stack<Character> stack = new Stack<>();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c == '<') {
if (!stack.isEmpty() && stack.peek() != '\n') {
stack.pop();
}
} else {
stack.push(c);
}
}
char[] result = new char[stack.size()];
for (int i = 0; i < result.length; i++) {
result[i] = stack.get(i);
}
return new String(result);
}
private static int countMatchingCharacters(String expected, String actual) {
int count = 0;
int minLength = Math.min(expected.length(), actual.length());
for (int i = 0, j = 0; i < minLength && j < actual.length(); i++, j++) {
if (expected.charAt(i) == actual.charAt(j)) {
if (expected.charAt(i) != '\n')
count++;
} else {
if (expected.charAt(i) == '\n') {
while (actual.charAt(j) != '\n') {
j++;
}
continue;
}
if (actual.charAt(j) == '\n') {
while (expected.charAt(i) != '\n') {
i++;
}
continue;
}
}
}
return count;
}
}