marut-vs-devil-in-hunger-games-1
Source: hackerearth
Difficulty: EASY

As you know, there is a furious battle going on between Marut and Devil. They are fighting with strings. Marut's strings are denoted by M and Devil's strings are denoted by D. Both of them are throwing strings on each other in order to get points. Their strings collide in air and one occurrence of some character in one string cancels out(character gets deleted) one occurrence of same character in another string. Then, points are allocated to them based on their remaining characters of strings. There are some points associated to each character of strings. Total points of any string is calculated by doing sum of points associated to each character. The total points of string M are given to Marut and total points of string D are given to Devil at the end of each round. Total score of an individual is summation of scores of all individual rounds. In the end, whosoever has greater number of points, will win the Hunger Games.

Your task is to find the winner and print his name. Initially, both of them have zero points.

Input:
First line of the input contains 26 space separated integers denoting points associated to each lowercase English alphabets. First integer denotes points associated to 'a' , second integer to 'b' and so on.
Second line contains an integer Q, denoting number of times game is played.
Then, follow 2*Q lines.
For each game, first line contains string M.
second line contains string D.

Output:
Print "Marut" if Marut wins or "Devil" if Devil wins.
If no one wins i.e they both end up with same scores, print "Draw" (without quotes).

Constraints:
1 ≤ Points associated to each character ≤ 100 
String M and D contains only lowercase english alphabets.
1 ≤ |M| , |D| ≤ 10^4
1 ≤ Q ≤ 1000
|M| = |D|

Note:
Large Input Files. Use Fast input/output.

SAMPLE INPUT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
2
abcd
aabb
abc
xyz

SAMPLE OUTPUT
Devil

Explanation

In the first round,  one occurrence of 'a' and 'b' is cancelled out in both strings M and D, so final string of Marut would be cd and final string of Devil would be ab. Total points of string M are 3+4 = 7  and string D are 1+2=3. For this round , Marut gets 7 points and Devil gets 3 points.
In the second round, no character of both the strings are common. Total points of string M are 1+2+3=6  and string D are 24+25+26=75.  For this round Marut gets 6 points and Devil gets 75 points.
Total final scores are: Marut has 13 points and Devil has 78 points. Hence Devil won the game.


a = input()
b = a.split(' ')
alpha_list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] 

points = dict(list(zip(alpha_list, b)))


rounds = eval(input())
marut_points = 0
devil_points = 0
for i in range(rounds):
	marut = ""
	devil = ""
	marut = input()
	devil = input()
	try :
		[devil.pop(devil.index(i)) for i in marut]
		[ marut.pop(marut.index(i)) for i in devil]	
	except Exception as e:
		pass
	
	
	# check for the points
	for i in marut:
		marut_points +=   int(points[i])	
	for i in devil:
		devil_points +=   int(points[i])	
if marut_points > devil_points:
	print("Marut")
elif marut_points < devil_points:
	print("Devil")
elif marut_points == devil_points:
	print("Draw")


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
s=list(map(int,input().split()))
#print s
n=int(input())
f=0
mc=0
dc=0
for i in range(n):
	m=input()
	d=input()
	
	for j in m:
		#print j,ord(j)
		mc=mc+s[ord(j)-97]
	for j in d:
		#print j,ord(j),'a'
		dc=dc+s[ord(j)-97]
if mc>dc:
	print("Marut")
elif mc<dc:
	print("Devil")
else:
	print("Draw")
#print mc,dc,f


def find_score(string,mapped_list):
	score = 0 
	for character in string:
		score += int(mapped_list[ord(character)%97])
	return score


input_values = input(" ")
mapped_list = input_values.split()
times = input(" ")
M_score = 0
D_score = 0
for i in range(0, int(times)):
	M = input("")
	D = input("")
	M_score +=find_score(M,mapped_list)
	D_score +=find_score(D,mapped_list)

if M_score > D_score:
	print("Marut")
elif D_score > M_score:
	print("Devil")
else:
	print("Draw")



'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
inpt_integer=input()
array_values=inpt_integer.split(" ")
for x in range(len(array_values)):
	array_values[x]=int(array_values[x])
	
dic=dict(list(zip(alpha,array_values)))
test_inputs=int(input())
m=z=0
for x in range(test_inputs):
	str_marut=input()
	str_devil=input()
	#convert string input to list to fetch common words
	str_marut_array=[x for x in str_marut]
	str_devil_array=[x for x in str_devil]
	common=list(set(str_marut_array).intersection(str_devil_array))
	for x in common:
		str_marut_array.remove(x)
		str_devil_array.remove(x)
	
	del(common)
	for x in str_marut_array:
		val=dic.get(x)
		m=m+val
	
	for x in str_devil_array:
		val=dic.get(x)
		z=z+val
	
if(m>z):
	print("Marut")
elif(m<z):
	print("Devil")
else:
	print("Draw")
		
	
	
	


def calculate_points(alpha, s):
	score = 0
	for x in s:
		score += alpha[ord(x)-ord('a')]
	return score


def main():
	alpha = list(map(int, input().split()))
	marut, devil = 0, 0
	for g in range(eval(input())):
		marut += calculate_points(alpha, input())
		devil += calculate_points(alpha, input())
	# print marut, devil
	if marut > devil:
		print('Marut')
	elif marut < devil:
		print('Devil')
	else:
		print('Draw')

main()


score=list()
score+=input().split(' ')

for i in range(0,len(score)) :
	score[i]=int(score[i])
	
q=int(input())

devil,marut=int(0),int(0)

while q :
	q-=1
	
	m=input()
	d=input()
	
	mcnt=[0]*26
	dcnt=[0]*26
	
	for i in m :
		mcnt[ord(i)-ord('a')]+=1
		
	for i in d :
		dcnt[ord(i)-ord('a')]+=1
		
	for i in range(0,26) :
		mn=min(mcnt[i],dcnt[i])
		devil+=(dcnt[i]-mn)*score[i]
		marut+=(mcnt[i]-mn)*score[i]
		


#print devil,' ',marut

if devil ==  marut :
	print('Draw')
elif devil > marut :
	print('Devil')
else :
	print('Marut')


numstr = input()
Q=input()
mcount=0
dcount=0
numarr=numstr.split()
numhash={}
for i in range(26):
	numhash[i]=int(numarr[i])
for j in range(int(Q)):
	M=input()
	D=input()
	mhash={}
	dhash={}
	for i in range(26):
		mhash[i]=0
		dhash[i]=0
	for s in M:
		mhash[ord(s)-97]=mhash.get(ord(s)-97)+1
	for t in D:
		dhash[ord(t)-97]=dhash.get(ord(t)-97)+1
	for i in range(26):
		if mhash[i]>0 and dhash[i]>0:
			mhash[i]=mhash.get(i)-1
			dhash[i]=dhash.get(i)-1
	for k in range(26):
		mcount+=mhash.get(k)*numhash.get(k)
		dcount+=dhash.get(k)*numhash.get(k)
if mcount > dcount:
	print('Marut')
elif dcount>mcount:
	print('Devil')
else:
	print('Draw')


vals = [int (val) for val in input().split(' ')]
Q = int (input())
sum_M, sum_D = 0, 0
for i in range(Q):
	M = input()
	D = input()
	M_cnt = [ 0 for i in range(26)]
	D_cnt = [ 0 for i in range(26)]
	for val in M:
		a = int(ord(val) - ord('a'))
		M_cnt[a] += 1
	for val in D:
		a = int(ord(val) - ord('a'))
		D_cnt[a] += 1
	for i in range(26):
		sum_M += ( max(0, M_cnt[i] - D_cnt[i])*vals[i])
		sum_D += ( max(0, D_cnt[i] - M_cnt[i])*vals[i])

if sum_M > sum_D:
	print('Marut')
elif sum_D > sum_M:
	print('Devil')
else:
	print('Draw')


lists=[_ for _ in input().split()]
init=97
dicit={}
for key_add in range(26):
	key=init+key_add
	dicit.update({chr(key):lists[key_add]})
T=int(input())
tot_m=0
tot_d=0
for _ in range(0,T):
	lists=list(input())
	sum_m=0
	for i in lists:
		sum_m=sum_m+int(dicit[i])
	lists=list(input())
	sum_d=0
	for i in lists:
		sum_d=sum_d+int(dicit[i])
	tot_d=tot_d+sum_d
	tot_m=tot_m+sum_m
if(tot_m==tot_d):
	print("Draw")
else:
	if(tot_m>tot_d):
		print("Marut")
	else:
		print("Devil")


Arr = list(map(int, input().split(' ')))
t = int(input())
s1 = 0
s2 = 0
for i in range(t):
	i1 = input()
	i2 = input() 
	l = len(i1)
	j = 0
	k = 0
	i1 = sorted(i1)
	i2 = sorted(i2)
	while j < l:
		if i2[j] != i1[j]:
			s1 = s1+Arr[ord(i1[j])-ord('a')]
			s2 = s2++Arr[ord(i2[j])-ord('a')]
		j = j+1	
if s1 > s2:
	print("Marut")
elif s1 < s2:
	print("Devil")
else:
	print("Draw")


val = input().split()
d = {chr(i + 97): int(val[i]) for i in range(0, 26)}
q = input().strip()

mval = 0
dval = 0

for i in range(int(q)):
	marut = {}
	devil = {}
	for j in input():
		if marut.get(j):
			marut[j] += 1
		else:
			marut[j] = 1
	# print marut
	for j in input():
		if devil.get(j):
			devil[j] += 1
		else:
			devil[j] = 1
	# print devil

	for char in marut:
		if devil.get(char):
			marut[char] -= 1
			devil[char] -= 1

	for i in devil:
		dval += d[i] * devil[i]

	for i in marut:
		mval += d[i] * marut[i]
	# print dval, mval

if mval > dval:
	print("Marut")
elif mval == dval:
	print("Draw")
else:
	print("Devil")


import string
import collections

points = input().split()
Q = int(input())

map = {k:int(points[v]) for k,v in zip(string.ascii_lowercase, list(range(0, len(points))))}

mpoints = 0
dpoints = 0
while(Q>0):
	M = input().strip()
	D = input().strip()
	mcounter = collections.Counter(M)
	dcounter = collections.Counter(D)
	mlist = (mcounter - dcounter).elements()
	for mchar in mlist:
		mpoints += map[mchar]
	dlist = (dcounter - mcounter).elements()
	for dchar in dlist:
		dpoints += map[dchar]	
	Q -= 1
	
if(mpoints == dpoints):
	print("Draw")
elif(mpoints > dpoints):
	print("Marut")
else:
	print("Devil")



alphabet = {}


line = input()

a = line.split()



for i in range(26):
	alphabet[chr(ord('a')+i)] = int(a[i])

num = input()

point1 =0
point2 = 0

for i in range(int(num)):
	str1 = input()
	str2 = input()
	for (a,b) in zip(str1,str2):
		if(a != b):
			point1 += alphabet[a]
			point2 += alphabet[b]


if(point1>point2):
	print("Marut")
elif(point2>point1):
	print("Devil")
else:
	print("Draw")






def getPointforRound(s1,score):
	point =0
	for c in s1:
		point  = point + score[ord(c)-ord('a')]
	return point

s =  input()
score = list(map(int, s.split()))
rounds = int(input())
point1 = 0
point2 = 0

for round in range(0,rounds):
	s1 = input()
	s2 =  input()
	point1 = point1 + getPointforRound(s1,score)
	point2 = point2 + getPointforRound(s2,score)


if(point1>point2):
	print("Marut")
elif(point2>point1):
	print("Devil")
else :
	print("Draw")



def getScore(pos1,pos2,i,alpha):
	if pos1==0:
		return 0
	elif pos1-pos2>0:
		return (pos1-pos2)*(alpha[i])
	return 0


alpha = list(map(int,input().split()))

q = int(input())
fcM = 0
fcD = 0
for i in range(q):
	
	m = input()
	d = input()
	
	finalM = [0]*26
	finalD = [0]*26
	
	countM = 0
	countD = 0
	
	for i in range(26):
		ch = chr(i+97)
		tmp1 = m.count(ch)
		tmp2 = d.count(ch)
		
		countM += getScore(tmp1,tmp2,i,alpha)
		countD += getScore(tmp2,tmp1,i,alpha)
		
	
	fcM += countM
	fcD += countD
	
if fcM > fcD:
	print("Marut")
elif fcM < fcD:
	print("Devil")
else:
	print("Draw")
		
		
		


import sys
num_array=[0]*26
#input_length = sys.stdin.readline().rstrip()
#print(input_length);
t=0;
l=0
k=sys.stdin.readline()
v=k.split(' ');
#print(v);
for i in range(0,26):
	num_array[i]=int(v[i]);
#print(num_array);
p=sys.stdin.readline().rstrip()
#print(p);
for i in range(0,int(p)):
	 c1=sys.stdin.readline().rstrip()
	 c2=sys.stdin.readline().rstrip()
	 d=[0]*26;
	 e=[0]*26;
	 #print(c1[0]);
	 #print(d);
	 for j in c1:
		  #print(ord(j));
		  m=ord(j)-97
		  d[m]=d[m]+1;
	 for j in c2:
		  #print(ord(j));
		  m=ord(j)-97
		  e[m]=e[m]+1;
	 #print(e);
	 #print(d);
	 for i in range(0,26):
		  if e[i]>=d[i]:
			  e[i]=e[i]-d[i];
			  d[i]=0;
		  else:
				d[i]=d[i]-e[i];
				e[i]=0;
	 
	 #print(e);
	 #print(d);
	 for p in range(0,26):
		  t=t+num_array[p]*e[p];
		  l=l+num_array[p]*d[p];
#print(l)
#print(t)
if l>t:
	 print("Marut");
elif t>l:
	 print("Devil");
else:
	 print("Draw");
	 
			  
	 
	 


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from functools import reduce

def main():
	import sys

	f = sys.stdin
	#f = open("Marut_V_Devil_Hunger_Games.txt")
	
	score_M, score_D = 0, 0
	
	char_val = list(map(int, f.readline().strip().split()))
	char_count_M = [0 for dummy_i in range(26)]
	char_count_D = [0 for dummy_i in range(26)]
	
	Q = int(f.readline().strip())
	for i in range(Q):
		M = f.readline().strip()
		D = f.readline().strip()
		
		# increment the character count for Marut
		for j in range(len(M)):
			char_count_M[ord(M[j])-97] += 1
			
		# increment the character count for Devil
		for j in range(len(D)):
			char_count_D[ord(D[j])-97] += 1
			
	score_M = reduce(lambda x, y: x + y, list(map(lambda x, y: x * y , char_val, char_count_M)))
	score_D = reduce(lambda x, y: x + y, list(map(lambda x, y: x * y , char_val, char_count_D)))
	
	if score_D > score_M:
		print("Devil")
	elif score_M > score_D:
		print("Marut")
	else:
		print("Draw")
		
	
main()


arr=list(map(int,input().split()))
#arr=[x+1 for x in range(0,26)]
#print arr
q=eval(input())
ansm=ansd=0
for _ in range(0,q):
	marut = input()
	devil = input()
	casem = [0 for _ in range(0,26)]
	cased = [0 for _ in range(0,26)]
	for x in range(0, len(marut)):
		casem[ord(marut[x])-97]+=1
	for x in range(0, len(devil)):
		cased[ord(devil[x])-97]+=1
	for x in range(0,26):
		temp=casem[x]-cased[x]
		if temp>0:
			ansm+=arr[x]*temp
		elif temp<0:
			ansd+=arr[x]*abs(temp)
if ansm>ansd:
	print('Marut')
elif ansm<ansd:
	print('Devil')
else:
	print('Draw')


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from functools import reduce
val = input('\n')
val = [int(i) for i in val.split(' ')]
game_no = eval(input('\n')) 
m=0
d=0
for i in range(game_no):
	ms = input('\n')
	ds = input('\n')

	ms_ar = ms.split()
	for j in ms_ar:
		try:
			if ds.index(j)!=-1:
				ds.replace(j,'',1)
				ms.replace(j,'',1)
		except:
			pass
	m += reduce(lambda x,y: x+y, [val[ord(k)-97] for k in ms])
	d += reduce(lambda x,y: x+y, [val[ord(k)-97] for k in ds])
	
if m>d:
	print('Marut')
elif m<d:
	print('Devil')
else:
	print('Draw')



x = input()
nums = [int(n) for n in x.split()]
N = input()
N_int = int(N)

def calculate(A, B):
	n = 0
	for i in range(97,123):
		n += nums[i-97]*((A.count(chr(i)) - B.count(chr(i))))
	return n
 

res = 0
for i in range(1,N_int+1):
	A = input()
	B = input() 
	res += calculate(A,B)

if(res > 0):
	print("Marut")
elif (res <0):
	print("Devil")
else:
	print("Draw")






val = input().split()
d = {chr(i + 97): int(val[i]) for i in range(0, 26)}
q = input().strip()

mval = 0
dval = 0

for i in range(int(q)):
	marut = {}
	devil = {}
	for j in input():
		if marut.get(j):
			marut[j] += 1
		else:
			marut[j] = 1
	# print marut
	for j in input():
		if devil.get(j):
			devil[j] += 1
		else:
			devil[j] = 1
	# print devil

	for char in marut:
		if devil.get(char):
			marut[char] -= 1
			devil[char] -= 1

	for i in devil:
		dval += d[i] * devil[i]

	for i in marut:
		mval += d[i] * marut[i]
	# print dval, mval

if mval > dval:
	print("Marut")
elif mval == dval:
	print("Draw")
else:
	print("Devil")


val = input().split()
d = {chr(i + 97): int(val[i]) for i in range(0, 26)}
q = input().strip()

mval = 0
dval = 0

for i in range(int(q)):
	marut = {}
	devil = {}
	for j in input():
		if marut.get(j):
			marut[j] += 1
		else:
			marut[j] = 1
	# print marut
	for j in input():
		if devil.get(j):
			devil[j] += 1
		else:
			devil[j] = 1
	# print devil

	for char in marut:
		if devil.get(char):
			marut[char] -= 1
			devil[char] -= 1

	for i in devil:
		dval += d[i] * devil[i]

	for i in marut:
		mval += d[i] * marut[i]
	# print dval, mval

if mval > dval:
	print("Marut")
elif mval == dval:
	print("Draw")
else:
	print("Devil")


a = list(map(int,input().split()))
q = eval(input())
off = ord('a')
sm = sd = 0
for xx in range(0,q):
	m = input()
	d = input()
	n = len(m)
	x = [0]*26
	y = [0]*26
	for i in range(0,n):
		x[ord(m[i])-off] += 1
	for i in range(0,n):
		y[ord(d[i])-off] += 1
	for i in range(0,26):
		if(x[i] > y[i]):
			sm += (x[i]-y[i])*a[i]
		if(y[i] > x[i]):
			sd += (y[i]-x[i])*a[i]
if(sm > sd):
	print("Marut")
elif(sd > sm):
	print("Devil")
else:
	print("Draw")


weight = [int(x) for x in input().split(" ")];
no = int(input());
msum = 0;
dsum = 0;
for i in range(0,no):
	m = input();
	d = input();
	marr = list(range(26));
	darr = list(range(26));
	for j in range(0,len(m)):
		marr[ord(m[j])-97] = marr[ord(m[j])-97] + 1;
	for j in range(0,len(d)):
		darr[ord(d[j])-97] = darr[ord(d[j])-97] + 1;
	for k in range(0,26):
		if marr[k] != 0 and darr[k] != 0:
			if marr[k] > darr[k]:
				marr[k] = marr[k] - darr[k];
				darr[k] = 0;
			elif marr[k] < darr[k]:
				darr[k] = darr[k] - marr[k];
				marr[k] = 0;
			else:
				darr[k] = marr[k] = 0;
			msum = msum + marr[k] * weight[k];
			dsum = dsum + darr[k] * weight[k];
if msum > dsum:
	print("Marut");
elif msum < dsum:
	print("Devil");
elif msum == dsum:
	print("Draw");


scores = list(map(int,input().split()))
m=0
d=0
t=eval(input())
score_m = 0
score_d = 0
for _ in range(t):
	count_letter_m=[0]*26
	count_letter_d=[0]*26
	string_m=list(input())
	string_d=list(input())
	
	for char in string_m:
		count_letter_m[ord(char)-97]+=1
		
	for char in string_d:
		count_letter_d[ord(char)-97]+=1	
		
		
		
	for i in range(26):
		mini = min(count_letter_m[i], count_letter_d[i])
	        count_letter_m[i]-=mini
	        count_letter_d[i]-=mini
	
	for i in range(26):
		score_m+=(scores[i]*count_letter_m[i])
		score_d+=(scores[i]*count_letter_d[i])

if score_m>score_d:
	print('Marut')
elif score_m<score_d:
	print('Devil')
else:
	print('Draw')
	    
		


a = input()
b = a.split(' ')
alpha_list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] 

points = dict(list(zip(alpha_list, b)))


rounds = eval(input())
marut_points = 0
devil_points = 0
for i in range(rounds):
	marut = ""
	devil = ""
	marut = input()
	devil = input()
	
	devil_newlist = [i  for i in devil ]

	try :
		[devil.pop(devil.index(i)) for i in marut]
		[ marut.pop(marut.index(i)) for i in devil]	
	except Exception as e:
		pass
	
	
	# check for the points
	for i in marut:
		marut_points +=   int(points[i])	
	for i in devil:
		devil_points +=   int(points[i])	
if marut_points > devil_points:
	print("Marut")
elif marut_points < devil_points:
	print("Devil")
elif marut_points == devil_points:
	print("Draw")


val = input().split()
d = {chr(i + 97): int(val[i]) for i in range(0, 26)}
q = input().strip()

mval = 0
dval = 0

for i in range(int(q)):
	marut = {}
	devil = {}
	for j in input():
		if marut.get(j):
			marut[j] += 1
		else:
			marut[j] = 1
	# print marut
	for j in input():
		if devil.get(j):
			devil[j] += 1
		else:
			devil[j] = 1
	# print devil

	for char in marut:
		if devil.get(char):
			marut[char] -= 1
			devil[char] -= 1

	for i in devil:
		dval += d[i] * devil[i]

	for i in marut:
		mval += d[i] * marut[i]
	# print dval, mval

if mval > dval:
	print("Marut")
elif mval == dval:
	print("Draw")
else:
	print("Devil")


def result(lst):
	ans = 0
	for i in lst:
		ans += (alpha[ord(i)-ord('a')]*lst[i])
	return ans

alpha = list(map(int,input().split()))
q = int(input())
M = {}
N = {}
for _ in range(q):
	m = list(input())
	n = list(input())
	both = set(set(m).intersection(set(n)))
	for i in both:
		m.remove(i)
		n.remove(i)
	for i in range(len(m)):
		if m[i] not in M:
			M[m[i]] = 1
		else:
			M[m[i]] += 1
		if n[i] not in N:
			N[n[i]] = 1
		else:
			N[n[i]] += 1


score1 = result(M)
score2 = result(N)

if score1>score2:
	print("Marut")
elif score1<score2:
	print("Devil")
else:
	print("Draw")


from string import ascii_lowercase
array = [int(x) for x in input().split()]
t=int(input())
dic = {}
for i in range(26):
	dic[ascii_lowercase[i]]=array[i]

total_poinst_m=0
total_poinst_d=0

for i in range(t):
	m = list(input())
	d = list(input())
	round_points_m = sum([dic[x] for x in m])
	round_points_d= sum([dic[x] for x in d])
	dic_d = {}
	dic_m = {}
	
	for i in range(len(m)):
		if d[i] in dic_d:
			dic_d[d[i]] += 1
		else:
			dic_d[d[i]] = 1
			
		if m[i] in dic_m:
			dic_m[m[i]] += 1
		else:
			dic_m[m[i]] = 1
			
	for k,valor in dic_d.items():
		if k in dic_m:
			round_points_m -= dic[k]*abs(valor-dic_m[k])
			round_points_d -= dic[k]*abs(valor-dic_m[k])
		
	total_poinst_m += round_points_m
	total_poinst_d += round_points_d         
	
if total_poinst_m > total_poinst_d:
	print('Marut')
elif total_poinst_d > total_poinst_m:
	print('Devil')
else:
	print('Draw')
				
			
			
			
			 


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
if __name__ == "__main__":
	line1 = input()
	vals = [int(x) for x in line1.split()]
	times = int(input())
	marut_points = 0
	devil_points = 0
	for i in range(0,times):
		marut = input()
		marut_mod = marut
		devil = input()
		devil_mod = devil
		intr = set(marut).intersection(set(devil))
		for i in intr:
			difr = marut.count(i) - devil.count(i)
			if difr < 0:
				marut_mod = marut.replace(i,'')
				devil_mod = devil.replace(i,'')
				devil_mod = devil_mod + (0 - difr)*i
			else:
				devil_mod = devil.replace(i,'')
				marut_mod = marut.replace(i,'')
				marut_mod = marut_mod + (difr)*i
		for i in marut_mod:
			marut_points = marut_points + vals[ord(i) - 97]
		for i in devil_mod:
			devil_points = devil_points + vals[ord(i) - 97]
			
	if devil_points > marut_points:
		print("Devil")
	elif marut_points > devil_points:
		print("Marut")
	else:
		print("Draw")