#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e8;
priority_queue<ll, vector<ll>, greater<ll> > minh;
priority_queue<ll> maxh;
ll dp[202][101][101][2];
ll gcdExtended(ll a, ll b, ll* x, ll* y)
{
if (a == 0) {
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
ll modInverse(long long int A, long long int M)
{
ll x, y;
ll g = gcdExtended(A, M, &x, &y);
if (g != 1)
return -1;
else {
ll res = (x % M + M) % M;
return res;
}
}
ll check(string s,string t,ll n)
{
for(int i=0;i<n;i++)
{
if(t[i]>s[i])
return 1;
else if(t[i]==s[i])
continue;
else
return 0;
}
return 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,k;
cin>>n>>k;
string s;
cin>>s;
string t=s;
for(int i=k;i<n;i++)
{
t[i] = t[i%k];
}
if(check(s,t,n))
{
cout<<t.length()<<endl;
cout<<t<<endl;
}
else
{
ll j=k-1;
for(j = k-1;j>=0;j--)
{
if(t[j]=='9')
continue;
else
break;
}
for(int i = j+1;i<=k-1;i++)
t[i] = '0';
t[j] = char((t[j]-'0')+1 + '0');
for(int i=k;i<n;i++)
{
t[i] = t[i%k];
}
cout<<t.length()<<endl;
cout<<t<<endl;
}
}
3. Longest Substring Without Repeating Characters | 1312. Minimum Insertion Steps to Make a String Palindrome |
1092. Shortest Common Supersequence | 1044. Longest Duplicate Substring |
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |