Help me in solving ADIGIT problem

My issue

Why am in getting Runtime Exception while submitting assignment
while its running sucessfully for single case
Ealry help will be much appreciated as i am not able to understand whats wrong with code

My code

# cook your dish here

def calculate_score():
    for x_index,x in enumerate(digits):
        sum=0
        y=0
        step_index=x_index+1
        step_value=int(x)
        for y_index in range(step_index):
            y=int(digits[y_index])
            sum +=abs(step_value-y) 
        d[x_index+1]=sum

        
    
total_digits ,steps = map(int,input().split())
digits = input()
d = dict()
current_step = [] 


for _ in range(steps):
    current_step.append(int(input()))

calculate_score()

for item in current_step:
    print(d[item])


Problem Link: Chef and Digits Practice Coding Problem - CodeChef

@vivek508005
plzz refer my c++ code for better understanding of the logic

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	long long int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	map<long long int,vector<long long int>> mp;
	vector<long long int> freq(10,0);
	mp[-1]=freq;
	for(long long int i=0;i<s.size();i++)
	{
	    freq[s[i]-'0']++;
	    mp[i]=freq;
	}
	//return 0;
	while(m--)
	{
	    long long int x;
	    cin>>x;
	    long long int ans=0;
	    for(long long int i=0;i<10;i++)
	    {
	       ans+=(abs((s[x-1]-'0'-i))*(mp[x-2][i]));
	    }
	    cout<<ans<<endl;
	}
	return 0;
}