function solution(enroll, referral, seller, amount) {
var answer = [];
let refer={}
let profit={}
let current
for(let index in enroll){
refer[enroll[index]]=referral[index]
profit[enroll[index]]=0
}
for(let sellerIndex in seller){
profit[seller[sellerIndex]]+=amount[sellerIndex]*100
let currPerson=seller[sellerIndex]
let currProfit=amount[sellerIndex]*100
while(refer[currPerson]){
profit[refer[currPerson]]+=Math.floor(currProfit*0.1)
profit[currPerson]-=Math.floor(currProfit*0.1)
currPerson=refer[currPerson]
currProfit=Math.floor(currProfit*0.1)
if(currProfit<=0){
break;
}
}
}
for(let person of enroll){
answer.push(profit[person])
}
return answer;
}