//Name        :   Alex Conway
//School      :   Kalmazoo AMSC
//Division    :   Intermediate - 5
//Program     :   Number Transformation
//Contest     :   Round 1
//Date        :   6 December 2019

#include 
#include 
#include 
using namespace std;

//checks if a number is prime
bool isPrime(long long p)
{	
	if (p % 2 == 0)
	{
		return false;
	}
	long long len = sqrt(p * 1.0);

	for (long long i = 3; i <= len; i += 2)
	{
		if (p % i == 0)
		{
			return false;
		}
	}
	return true;
}

int main() 
{

  //signature
  cout << "Alex Conway\nAPCS\nACSL Intermediate-5 Number Transformation\n\n";
  long long N; 
  long long P, counter;
  string str, revStr, newStr;

  for(int dataSet = 0; dataSet < 5; dataSet++)
  {
    //initialize variables
    str = "";
    revStr = "";
    newStr = "";
    counter = 0;

    cout << "Input a number and an index: ";
    cin >> N >> P;
    str = to_string(N);
    
    //does the addition
    for(long long i = 0; i < str.length() - P; i++)
    {
      newStr += to_string(((str[i] - 48) + (str[str.length() - P] - 48))%10);
      
    }

    //makes the P index the same
    newStr += to_string(str[str.length() - P] - 48);

    //does the subtraction
    for(long long i = str.length() - P + 1; i < str.length(); i++)
    {
      newStr += to_string(abs((str[i] - 48) - (str[str.length()-P] - 48)));
    }

    //output the data
    cout << newStr << endl << endl;
  }
}