alexjercan/bugnet huggingface dataset:
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

#ifndef LOCAL
#define fprintf                                                                \\
  if (false)                                                                   \\
  fprintf
#endif
#define debug_int(x) fprintf(stderr, "%s = %d\\n", #x, x)
#define debug_double(x) fprintf(stderr, "%s = %llf\\n", #x, x)
#define debug_array(v, n)                                                      \\
  fprintf(stderr, "%s = [ ", #v);                                              \\
  for (int i = 0; i < n; i++)                                                  \\
    fprintf(stderr, "%d ", v[i]);                                              \\
  fprintf(stderr, "]\\n")
#define forr(i, start, end) for (int i = start; i < end; i++)

using lli = long long int;
using ii = pair<int, int>;

const int MAXN = 100010;

int main() {
  int k;
  char s[128];
  scanf("%d %s", &k, s);
  int n = strlen(s);
  if (n <= k) {
    printf("%s\\n", s);
  } else {
    s[k] = 0;
    printf("%s...\\n", s);
  }
}


Error: -11

Fixed submission:

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

#ifndef LOCAL
#define fprintf                                                                \\
  if (false)                                                                   \\
  fprintf
#endif
#define debug_int(x) fprintf(stderr, "%s = %d\\n", #x, x)
#define debug_double(x) fprintf(stderr, "%s = %llf\\n", #x, x)
#define debug_array(v, n)                                                      \\
  fprintf(stderr, "%s = [ ", #v);                                              \\
  for (int i = 0; i < n; i++)                                                  \\
    fprintf(stderr, "%d ", v[i]);                                              \\
  fprintf(stderr, "]\\n")
#define forr(i, start, end) for (int i = start; i < end; i++)

using lli = long long int;
using ii = pair<int, int>;

const int MAXN = 100010;

int main() {
  int k;
  char s[128];
  scanf("%d %s", k, s);
  int n = strlen(s);
  if (n <= k) {
    printf("%s\\n", s);
  } else {
    s[k] = 0;
    printf("%s...\\n", s);
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  string t = "";
  // cout << s.size() << endl;
  if (s.size() > k) {
    rep(i, k) { t += s[i]; }
    t += "...";
  } else {
    t = s;
  }
  cout << t << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  string t = "";
  if (s.size() < k) {
    rep(i, k) { t[i] = s[i]; }
  } else {
    t = s;
  }
  t += "...";
  cout << t << endl;

  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>

int main() {
  int k;
  std::cin >> k;
  std::string s;
  std::cin >> s;
  std::string ans;
  std::vector<char> vec;
  if ((int)s.length() <= k) {
    std::cout << s << std::endl;
  } else {
    for (int i = 0; i < k; ++i) {
      vec.push_back(s[i]);
    }
    vec.push_back('.');
    vec.push_back('.');
    vec.push_back('.');
    for (int i = 0; i < vec.size(); ++i) {
      std::cout << vec[i];
    }
    std::cout << "" << std::endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
int main() {
  int k;
  std::cin >> k;
  std::string s;
  std::cin >> s;
  std::string ans;
  if ((int)s.length() <= k) {
    std::cout << s << std::endl;
  } else {
    for (int i = 0; i < k; ++i) {
      ans[i] = s[i];
    }
    ans[k] = '.';
    ans[k + 1] = '.';
    ans[k + 2] = '.';
    for (int i = 0; i < k + 3; ++i) {
      std::cout << ans[i];
    }
    std::cout << "" << std::endl;
  }
  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  string S;
  cin >> K >> S;

  if (S.size() > K) {
    for (int i = 0; i < K; i++) {
      cout << S.at(i);
    }
    cout << "...";
  } else {
    cout << S;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  string S;
  cin >> K >> S;
  for (int i = 0; i < K; i++) {
    cout << S.at(i);
  }
  cout << "...";
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>
using namespace std;
int main() {
  int k, i = 0, n;
  char str[103], substr[103], s[] = "...";
  cin >> k;
  cin >> str;
  n = strlen(str);
  if (k >= n) {
    cout << str;
  } else {
    while (str[i] != '\\0' && i < k) {
      for (; i < k; i++) {
        substr[i] = str[i];
      }
      substr[i] = '\\0';
    }
    cout << strcat(substr, s);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;
int main() {
  long int k, i, n;
  char str[103], substr[103], s[] = "...";
  cin >> k;
  cin >> str;
  n = strlen(str);
  if (k >= n) {
    cout << str;
  } else {
    for (i = 0; i < k; i++) {
      substr[i] = str[i];
    }
    cout << strcat(substr, s);
  }
  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int k, n;
  string s;
  cin >> k >> s;

  n = s.length();

  if (n <= k) {
    cout << s << endl;
  } else {
    for (int i = 0; i < k; i++) {
      cout << s[i];
    }
    cout << "..." << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
/*
 *    coder :: ATUL_PANDEY_2608
 *        >>> INDIA <<<
 */
using namespace std;

// #define  part ..
#define listi vector<int>
#define listll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define heap priority_queue<long long>

#define pb(a) push_back(a)
#define mod 998244353
#define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL), cin.tie(0);
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// #define test int t;cin>>t;while(t--)
// end of #define

// define globals ...

// write function from here ...

int Main() {

  int k;
  cin >> k;
  string s;
  cin >> s;

  for (int i = 0; i < min(k, int(s.length())); i++) {
    cout << s[i];
  }

  if (int(s.length()) > k) {
    cout << "...";
  }
}

// main function..
int main() {
  quick;

  Main();
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define plskz                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long
using namespace std;

int main() {
  plskz

      int k;
  string s;
  cin >> k >> s;

  if (s.size() <= k)
    cout << s;
  else {
    for (int i = 0; i < k; ++i) {
      cout << s[i];
    }
    cout << "...";
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define plskz                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long
using namespace std;

int main() {
  plskz

      int k;
  string s;

  cin >> k >> s;
  int asd = s.size() - k - 1;

  if (k <= s.size()) {
    cout << s.erase(asd) << "...";
  } else {
    cout << s;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main()

{
  int k;
  string s;
  cin >> k;
  cin >> s;
  if (s.size() > k) {
    s = s.substr(0, k) + "...";
  }
  cout << s << endl;
  return 0;
}


Error: WA

Fixed submission:

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

int main()

{
  int n, i = 0, j;
  char ara[200], b;
  cin >> n;
  cin >> b;
  while (1) {
    cin >> ara[i];
    if (ara[i] == '\\n') {
      i--;
      break;
    }
    i++;
  }
  if (n <= i) {
    for (j = 0; j < i; j++)
      cout << ara[j];
    cout << endl;
  } else {
    for (j = 0; j < n; j++)
      cout << ara[j];
    cout << "..." << endl;
  }
  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
  int K;
  string S;

  cin >> K >> S;
  int A = S.size();
  string B = S.substr(0, K);
  if (A <= K) {
    cout << S << endl;
  }

  else {
    cout << B << "..." << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
  int K;
  string S;

  cin >> K >> S;
  int A = S.size();
  string B = S.substr(K - 1);
  if (A <= K) {
    cout << S << endl;
  }

  else {
    cout << B << "..." << endl;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  if (S.size() <= K) {
    cout << S << endl;
  }

  else {
    for (int i = 0; i < K; i++) {
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  unsigned int K;
  string S;
  string new1;
  cin >> K;
  cin >> S;
  vector<string> vec;

  if (S.size() <= K) {
    cout << S << endl;
  } else {
    for (unsigned int i = 0; i < K; i++) {
      vec.at(i) = S.at(i);
    }

    for (unsigned int i = 0; i < K; i++) {
      cout << vec.at(i);
    }
    cout << "..." << endl;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (k >= s.size())
    cout << s;
  else
    cout << s.substr(0, k) << "...";
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (k < s.size())
    cout << s;
  else
    cout << s.substr(k) << "...";
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  for (int i = 0; N > i; i++) {
    cout << S.at(i);
    if (i >= (S.size() - 1))
      break;
  }
  if (S.size() > N) {
    cout << "...";
  }
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  for (int i = 0; N > i; i++) {
    cout << S.at(i);
    if (i > (S.size() - 2))
      break;
  }
  if (S.size() > N) {
    cout << "..." << endl;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int64_t K;
  string S;
  cin >> K >> S;
  int64_t s_size = S.size();
  if (s_size <= K) {
    cout << S << endl;
  } else {
    cout << S.erase(K) << "..." << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int64_t K;
  string S;
  cin >> K >> S;
  int64_t s_size = S.size();
  if (s_size <= K) {
    cout << S << endl;
  } else {
    cout << S.erase(7) << "..." << endl;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int K;
  string S;
  cin >> K >> S;
  if (S.size() > K) {
    cout << S.erase(K) << "..." << endl;
  } else {
    cout << S << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int K;
  string S;
  cin >> K >> S;
  if (S.size() > 7) {
    cout << S.erase(K) << "..." << endl;
  } else {
    cout << S << endl;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

int main() {
  int K;
  std::string S;
  std::cin >> K >> S;

  if (K < S.size()) {
    for (int i = 0; i < K; ++i) {
      std::cout << S.at(i);
    }
    std::cout << "...\\n";
  } else {
    std::cout << S << "\\n";
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>

int main() {
  int K;
  std::string S;
  std::cin >> K >> S;

  if (K > S.size()) {
    for (int i = 0; i < K; ++i) {
      std::cout << S.at(i);
    }
    std::cout << "...\\n";
  } else {
    std::cout << S << "\\n";
  }

  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;

  if (s.size() <= k) {
    cout << s << endl;
  } else {
    for (int i = 0; i < k; i++) {
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;

  if (s.size() == k) {
    cout << s << endl;
  } else {
    string ns;
    for (int i = 0; i < k; i++) {
      ns.push_back(s.at(i));
    }
    cout << ns << "..." << endl;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main() {
  int K;
  string S;

  cin >> K;
  cin >> S;

  if (K >= S.length()) {
    cout << S << endl;
  } else {
    S = S.erase(K);
    S = S + "...";
    cout << S << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  int K;
  string S;

  cin >> K;
  cin >> S;

  if (K >= sizeof(S)) {
    cout << S << endl;
  } else {
    S = S.erase(K);
    S = S + "...";
    cout << S << endl;
  }

  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {

  long unsigned int k;
  cin >> k;

  string s;
  cin >> s;

  if (s.size() > k) {
    s.erase(s.begin() + k, s.end());
    cout << s << "..." << endl;

  } else {

    cout << s << endl;
    //::system("pause");
  }

  // ::system("pause");
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {

  int k;
  cin >> k;

  string s;
  cin >> s;

  if (s.size() >= k) {
    s.erase(s.size() - k - 1);
    cout << s << "..." << endl;

  } else {

    cout << s << endl;
    //::system("pause");
  }

  //::system("pause");
  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int ABC_168_B() {

  int k;
  string s;
  string s_r;
  cin >> k;
  cin >> s;

  if (s.size() <= k) {
    cout << s << endl;
  } else {
    s_r = s.erase(k);
    cout << s_r << "..." << endl;
  }
  return 0;
}

int main() {
  ABC_168_B();

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int ABC_168_B() {

  int k;
  string s;
  string s_r;
  cin >> k;
  cin >> s;

  if (s.size() <= k) {
    cout << s << endl;
  } else {
    s_r = s.erase(7);
    cout << s_r << "..." << endl;
  }
  return 0;
}

int main() {
  ABC_168_B();

  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void) {
  int N = 0;
  string S;
  cin >> N;
  cin >> S;
  int A = S.size();
  int R = min(A, N);
  for (int i = 0; i < R; i++) {
    cout << S.at(i);
  }
  if (S.size() > N) {
    cout << "...";
  }
}

Error: WA

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void) {
  int N = 0;
  string S;
  cin >> N;
  cin >> S;
  for (int i = 0; i < N; i++) {
    cout << S.at(i);
  }
  if (S.size() > N) {
    cout << "...";
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (k >= s.length()) {
    cout << s;
    return 0;
  }
  s += " ";
  for (int i = 0; i < k; i++) {
    if (s[i] == ' ')
      break;
    cout << s[i];
  }
  cout << "...";
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int k;
  string s;
  cin >> k >> s;
  int r = k;
  s.erase(r, s.length() - k);
  s += "...";
  cout << s;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int n;
  cin >> n;
  string s;
  cin >> s;

  int k = s.length();

  if (n >= k)
    cout << s;
  else {

    for (int i = 0; i < n; i++) {
      cout << s.at(i);
    }
    cout << "...";
  }

  return 0;
}

Error: WA

Fixed submission:

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

int main() {

  int n;
  cin >> n;
  string s;
  cin >> s;

  int k = s.length();

  if (n == k)
    cout << s;
  else {
    k = n;
    for (int i = 0; i < k; i++)
      cout << s.at(i);
  }
  cout << "...";

  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int k;
  string s;
  cin >> k >> s;
  string ans;
  char add;
  rep(i, k) {
    try {
      add = s.at(i);
    } catch (out_of_range) {
      break;
    }
    ans += add;
  }
  if (s.size() > k)
    ans += "...";
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int k;
  string s;
  cin >> k >> s;
  string ans;
  char add;
  rep(i, k) {
    add = s.at(i);
    ans += add;
  }
  if (s.size() > k)
    ans += "...";
  cout << ans << endl;
  return 0;
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
#define ar array

void solve() {}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int K;
  cin >> K;
  string S;
  cin >> S;

  if (S.length() > K) {
    cout << S.substr(0, K);
    cout << "...";
  } else {
    cout << S;
  }
  cout << "\\n";
}


Error: 0

Fixed submission:

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

#define ll long long
#define ar array

void solve() {}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int K;
  cin >> K;
  char S[K + 1];
  cin >> S;
  bool longer = true;
  for (int i = 0; i < K; i++) {
    if (S[i] == '\\0') {
      longer = false;
      break;
    }
    cout << S[i];
  }
  if (longer) {
    cout << "...";
  }
  cout << "\\n";
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int K, M;
  string S, H;
  cin >> K >> S;
  M = S.size();
  H = "...";
  if (M <= K) {
    cout << S << endl;
  }
  if (M > K) {
    S = S.erase(K);
    cout << S + H << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int K, M;
  string S;
  cin >> K >> S;
  M = S.size();
  if (M <= K) {
    cout << S << endl;
  }
  if (M > K) {
    for (int i = 0; i < M - K; i++) {
      if (i < 3) {
        S.at(i + K) = '.';
      }
      if (i >= 3) {
        S.at(i + K) = ' ';
      }
    }
    cout << S.erase(K + 3) << endl;
  }
}
Problem p02676 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int K;

  string S;
  cin >> K >> S;

  string N = S.substr(0, K);
  N += "...";

  if (S.size() <= K) {
    cout << S << endl;
  }

  else {
    cout << N << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  int K;
  cin >> K;

  string S;
  cin >> S;

  int M = S.size();

  string N;
  for (int j = 0; j < K; j++) {
    N.at(j) = S.at(j);
  }

  if (M <= K) {
    cout << S << endl;
  }

  else {
    cout << N << "..." << endl;
  }
}