{"problem":{"name":"Kaprekar Number","description":{"content":"For an integer $x$ not less than $0$, we define $g_1(x), g_2(x), f(x)$ as follows: *   $g_1(x)=$ the integer obtained by rearranging the digits in the decimal notation of $x$ in descending order *   ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc192_c"},"statements":[{"statement_type":"Markdown","content":"For an integer $x$ not less than $0$, we define $g_1(x), g_2(x), f(x)$ as follows:\n\n*   $g_1(x)=$ the integer obtained by rearranging the digits in the decimal notation of $x$ in descending order\n*   $g_2(x)=$ the integer obtained by rearranging the digits in the decimal notation of $x$ in ascending order\n*   $f(x)=g_1(x)-g_2(x)$\n\nFor example, we have $g_1(314)=431$, $g_2(3021)=123$, $f(271)=721-127=594$. Note that the leading zeros are ignored.\nGiven integers $N, K$, find $a_K$ in the sequence defined by $a_0=N$, $a_{i+1}=f(a_i)\\ (i\\geq 0)$.\n\n## Constraints\n\n*   $0 \\leq N \\leq 10^9$\n*   $0 \\leq K \\leq 10^5$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $K$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc192_c","tags":[],"sample_group":[["314 2","693\n\nWe have:\n\n*   $a_0=314$\n*   $a_1=f(314)=431-134=297$\n*   $a_2=f(297)=972-279=693$"],["1000000000 100","0\n\nWe have:\n\n*   $a_0=1000000000$\n*   $a_1=f(1000000000)=1000000000-1=999999999$\n*   $a_2=f(999999999)=999999999-999999999=0$\n*   $a_3=f(0)=0-0=0$\n*   $\\vdots$"],["6174 100000","6174"]],"created_at":"2026-03-03 11:01:14"}}